Skip to content

Commit 71cedc8

Browse files
committed
fix scan imports don't understand aliases
1 parent 2a37d45 commit 71cedc8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-imported-component",
3-
"version": "6.0.0-beta.1",
3+
"version": "6.0.0-beta.2",
44
"description": "I will import your component, and help to handle it",
55
"main": "dist/es5/index.js",
66
"jsnext:main": "dist/es2015/index.js",

src/scanners/scanForImports.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ export const getDynamicImports = getImportString(`import[\\s]?\\((([^)])+['"]?)\
4545
const mapImports = (file: string, imports: MappedImport[]) => (
4646
imports
4747
.map(dep => {
48-
const {name, comment} = dep;
48+
const {name} = dep;
4949
if (name && name.charAt(0) === '.') {
5050
return {
51+
...dep,
5152
name: resolve(dirname(file), name),
52-
comment
53+
doNotTransform: false,
5354
}
5455
}
55-
return dep;
56+
return {
57+
...dep,
58+
doNotTransform: true,
59+
};
5660
})
5761
);
5862

@@ -63,8 +67,8 @@ const rejectSystemFiles = (file: string, stats: Stats) => (
6367
export const remapImports = (data: FileContent[], root: string, targetDir: string, getRelative: (a: string, b: string) => string, imports: Record<string, string>) => (
6468
data
6569
.map(({file, content}) => mapImports(file, getDynamicImports(content)))
66-
.forEach(importBlock => importBlock.forEach(({name, comment}) => {
67-
imports[getRelative(root, name)] = `() => import(${comment}'${getRelative(targetDir, name)}')`
70+
.forEach(importBlock => importBlock.forEach(({name, comment, doNotTransform}) => {
71+
imports[getRelative(root, name)] = `() => import(${comment}'${doNotTransform ? name : getRelative(targetDir, name)}')`
6872
}))
6973
);
7074

0 commit comments

Comments
 (0)