chore(ttypescript): self implement import-path-rewrite

Co-authored-by: Shahar Dawn Or <mightyiampresence@gmail.com>
pull/799/head
patomation 4 years ago committed by Shahar Dawn Or
parent 60605a8f8f
commit 749ec6299d

@ -19,6 +19,7 @@
"package", "package",
"relic", "relic",
"style", "style",
"ttypescript",
"typescript", "typescript",
"vscode" "vscode"
]] ]]

9
package-lock.json generated

@ -14211,15 +14211,6 @@
"integrity": "sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA==", "integrity": "sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA==",
"dev": true "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": { "tsconfig-paths": {
"version": "3.9.0", "version": "3.9.0",
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz",

@ -71,7 +71,6 @@
"remark-cli": "8.0.1", "remark-cli": "8.0.1",
"remark-toc": "7.0.0", "remark-toc": "7.0.0",
"standard-version": "9.0.0", "standard-version": "9.0.0",
"ts-transform-import-path-rewrite": "0.2.1",
"tsconfigs": "5.0.0", "tsconfigs": "5.0.0",
"tty-table": "4.1.3", "tty-table": "4.1.3",
"ttypescript": "1.5.11", "ttypescript": "1.5.11",

@ -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)
})

@ -7,13 +7,10 @@
"outDir": "../../build/package", "outDir": "../../build/package",
"plugins": [ "plugins": [
{ {
"transform": "ts-transform-import-path-rewrite", "transform": "./ts-transform-js-extension.cjs",
"import": "transform", "import": "transform",
"alias": {
"^(\\..*)(?<!\\.js)$": "$1.js"
},
"after": true, "after": true,
"type": "config" "type": "raw"
} }
] ]
}, },

Loading…
Cancel
Save