Skip to content

Commit 63cd28d

Browse files
committed
Update fix imports script
1 parent 5b9f11d commit 63cd28d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

config/fix-imports.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ const generateTransformer = (sourceFile) => {
4141
// Node is the relative path of an import or export
4242
if (parentNodeIsExportOrImport && isStringLiteral(node)) {
4343
const relativePathWithQuotes = node.getFullText(sourceFile).trimStart()
44-
const relativePathWithoutQuotes = relativePathWithQuotes.substring(1, relativePathWithQuotes.length - 1)
44+
let relativePathWithoutQuotes = relativePathWithQuotes.substring(1, relativePathWithQuotes.length - 1)
4545

4646
if (relativePathWithoutQuotes.includes(".js")) {
4747
return node
4848
}
4949

50+
// "./" -> "."
51+
if (relativePathWithoutQuotes.endsWith(`/`)) {
52+
relativePathWithoutQuotes = relativePathWithoutQuotes.substring(0, relativePathWithoutQuotes.length - 1)
53+
}
54+
5055
const fullImportPath = join(pathWithoutFileName, relativePathWithoutQuotes);
5156

5257
// Append .js or index.js to all imports
@@ -55,10 +60,17 @@ const generateTransformer = (sourceFile) => {
5560
}
5661
else if (existsDtsOrJs(fullImportPath, "index")) {
5762
node = context.factory.createStringLiteral(`${relativePathWithoutQuotes}/index.js`)
63+
5864
}
5965
else {
6066
throw new Error(`Can't fix TypeScript paths: ${node.getFullText(sourceFile)}`)
6167
}
68+
69+
const text =/** @type {ts.StringLiteral} */(node).text
70+
if (text.includes(`//`)) {
71+
throw new Error(`Error "${text}"`)
72+
}
73+
6274
}
6375

6476
return node

0 commit comments

Comments
 (0)