Skip to content

Commit 03e5c2e

Browse files
authored
Merge pull request #256 from zWingz/bugfix/import-patterns
fix: add import_patterns to fix import file direct. fix #255
2 parents ebeac2a + c7b0bdc commit 03e5c2e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface PluginOptions {
2727
export type AliasPlugin = (pluginOptions: PluginOptions) => any;
2828

2929
const COMMENTED_PATTERN = /(\/\*(?:(?!\*\/).|[\n\r])*\*\/)|(\/\/[^\n\r]*(?:[\n\r]+|$))/;
30-
const IMPORT_PATTERNS = [/from (["'])(.*?)\1/, /import\((["'])(.*?)\1\)/, /require\((["'])(.*?)\1\)/];
30+
const IMPORT_PATTERNS = [/from (["'])(.*?)\1/, /import\((["'])(.*?)\1\)/, /require\((["'])(.*?)\1\)/, /import\s+(["'])(.*?)\1/];
3131

3232
function parseImports(file: ReadonlyArray<string>, dir: string): FileData[] {
3333
return file

test/index.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,24 @@ import D from "express";
251251
`,
252252
});
253253
});
254+
255+
it('should work with import file direct', async () => {
256+
return run({
257+
pluginOptions: { configuration: compilerOptions },
258+
path: './src/FileFolder/InnerFileFolder/File.ts',
259+
input: `
260+
import "./asdf";
261+
import B from "./MyAlias";
262+
import "MyAlias";
263+
import "MyAlias";
264+
import D from "express";
265+
`,
266+
expected: `
267+
import "./asdf";
268+
import B from "./MyAlias";
269+
import "../../MyAliasFolder/MyAliasClass";
270+
import "../../MyAliasFolder/MyAliasClass";
271+
import D from "express";
272+
`,
273+
});
274+
});

0 commit comments

Comments
 (0)