Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ CLI поддерживает флаги:
| Флаг | Описание |
| - | - |
| **--retain-non-ascii-characters** | Декодирует не ASCII символы после транспиляции |
| **--retain-imports-as-comments** | Оставляет импорты в комментариях |

## Основные особенности

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wshcmx/cli",
"version": "3.1.0",
"version": "3.2.0",
"main": "dist/index.js",
"type": "module",
"repository": "github:wshcmx/cli",
Expand Down
1 change: 0 additions & 1 deletion src/core/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class ArgsParser {
help: { type: 'boolean', short: 'h', default: false },
version: { type: 'boolean', short: 'v', default: false },
project: { type: 'string', short: 'p', default: 'tsconfig.json' },
'retain-imports-as-comments': { type: 'boolean', default: false },
'retain-non-ascii-characters': { type: 'boolean', default: false },
},
allowPositionals: true
Expand Down
15 changes: 1 addition & 14 deletions src/transformers/remove_exports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import ts from 'typescript';

import { args } from '../core/args.js';

export function removeExports(): ts.TransformerFactory<ts.SourceFile> {
return (context) => (sourceFile: ts.SourceFile) => {
function visit(node: ts.Node): ts.Node {
Expand Down Expand Up @@ -30,18 +28,7 @@ export function removeExports(): ts.TransformerFactory<ts.SourceFile> {
}

if (ts.isImportDeclaration(node)) {
if (args['retain-imports-as-comments']) {
const commentedStatement = ts.factory.createNotEmittedStatement(node);
ts.addSyntheticLeadingComment(
commentedStatement,
ts.SyntaxKind.SingleLineCommentTrivia,
` ${node.getFullText()}`,
false
);
node = commentedStatement;
} else {
return ts.factory.createNotEmittedStatement(node);
}
return ts.factory.createNotEmittedStatement(node);
}

if (ts.isTypeAliasDeclaration(node) && node.modifiers) {
Expand Down
14 changes: 0 additions & 14 deletions test/commands/build-args.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,6 @@ suite('build command arguments', () => {
strictEqual(hasBuiltIndex(shortOptionProjectPath, 'dist-default'), false);
});

test('--retain-imports-as-comments preserves imports as commented lines in the emitted file', (t) => {
const withoutFlagProjectPath = createProject(t);
const withFlagProjectPath = createProject(t);

runBuild(withoutFlagProjectPath);
runBuild(withFlagProjectPath, ['--retain-imports-as-comments']);

const withoutFlagOutput = readFileSync(getBuiltIndexPath(withoutFlagProjectPath, 'dist-default'), 'utf-8');
const withFlagOutput = readFileSync(getBuiltIndexPath(withFlagProjectPath, 'dist-default'), 'utf-8');

strictEqual(withoutFlagOutput.includes("import { value } from './submodule';"), false);
ok(withFlagOutput.includes("// import { value } from './submodule';"));
});

test('--retain-non-ascii-characters keeps unicode escapes in emitted output', (t) => {
const withoutFlagProjectPath = createProject(t);
const withFlagProjectPath = createProject(t);
Expand Down
3 changes: 0 additions & 3 deletions test/core/args/args.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ suite('args parser', () => {
strictEqual(args.help, false);
strictEqual(args.version, false);
strictEqual(args.project, 'tsconfig.json');
strictEqual(args['retain-imports-as-comments'], false);
strictEqual(args['retain-non-ascii-characters'], false);
});

Expand Down Expand Up @@ -96,11 +95,9 @@ suite('args parser', () => {
'node',
'wshcmx',
'build',
'--retain-imports-as-comments',
'--retain-non-ascii-characters',
]);

strictEqual(args['retain-imports-as-comments'], true);
strictEqual(args['retain-non-ascii-characters'], true);
});
});
2 changes: 1 addition & 1 deletion test/project/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "node ../../dist/index.js build --retain-imports-as-comments",
"build": "node ../../dist/index.js build",
"start": "node ../../dist/index.js watch",
"pretest": "node ./scripts/test-project.mjs clean && npm install",
"test": "npm run build",
Expand Down