diff --git a/commitlint.config.json b/commitlint.config.json index 766f9e7..f0f38bf 100644 --- a/commitlint.config.json +++ b/commitlint.config.json @@ -19,6 +19,7 @@ "package", "relic", "style", + "ttypescript", "typescript", "vscode" ]] diff --git a/package-lock.json b/package-lock.json index 7980939..848e07e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14211,15 +14211,6 @@ "integrity": "sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA==", "dev": true }, - "ts-transform-import-path-rewrite": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/ts-transform-import-path-rewrite/-/ts-transform-import-path-rewrite-0.2.1.tgz", - "integrity": "sha512-9MJ66a4cSbQLLsY3ZGBXjsFbjm3B/bJ9Or08sDChiN1BQGDFBJGopjtp648rCixlvePovDY5lQRZcoWpJDN4Ww==", - "dev": true, - "requires": { - "typescript": "3" - } - }, "tsconfig-paths": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", diff --git a/package.json b/package.json index e8041f4..6019b1a 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,6 @@ "remark-cli": "8.0.1", "remark-toc": "7.0.0", "standard-version": "9.0.0", - "ts-transform-import-path-rewrite": "0.2.1", "tsconfigs": "5.0.0", "tty-table": "4.1.3", "ttypescript": "1.5.11", diff --git a/src/package/ts-transform-js-extension.cjs b/src/package/ts-transform-js-extension.cjs new file mode 100644 index 0000000..f49b9d7 --- /dev/null +++ b/src/package/ts-transform-js-extension.cjs @@ -0,0 +1,31 @@ +const ts = require('typescript') + +module.exports.transform = (ctx) => (sf) => ts.visitNode(sf, (node) => { + const visitor = (node) => { + const originalPath = ( + ts.isImportDeclaration(node) || + ts.isExportDeclaration(node)) && + node.moduleSpecifier + ? node.moduleSpecifier.getText(sf).slice(1, -1) + : ( + ts.isImportTypeNode(node) && + ts.isLiteralTypeNode(node.argument) && + ts.isStringLiteral(node.argument.literal) + ) + ? node.argument.literal.text + : null + + if (originalPath === null) return node + const pathWithExtension = originalPath.endsWith('.js') + ? originalPath + : originalPath + '.js' + const newNode = ts.getMutableClone(node) + if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) { + newNode.moduleSpecifier = ts.createLiteral(pathWithExtension) + } else if (ts.isImportTypeNode(node)) { + newNode.argument = ts.createLiteralTypeNode(pathWithExtension) + } + return newNode + } + return ts.visitEachChild(node, visitor, ctx) +}) diff --git a/src/package/tsconfig.json b/src/package/tsconfig.json index 1986183..441f1c5 100644 --- a/src/package/tsconfig.json +++ b/src/package/tsconfig.json @@ -7,13 +7,10 @@ "outDir": "../../build/package", "plugins": [ { - "transform": "ts-transform-import-path-rewrite", + "transform": "./ts-transform-js-extension.cjs", "import": "transform", - "alias": { - "^(\\..*)(?