Skip to content

Commit

Permalink
improve ESM import scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Jun 1, 2020
1 parent 3c10d00 commit 265418e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/scan-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const WEB_MODULES_TOKEN_LENGTH = WEB_MODULES_TOKEN.length;
// (?!.*(:\/\/)) - Ignore if previous match was a protocol (ex: http://)
const BARE_SPECIFIER_REGEX = /^[@\w](?!.*(:\/\/))/;

const ESM_IMPORT_REGEX = /import(?:["'\s]*([\w*${}\n\r\t, ]+)["'\s]from\s*)?["'\s]["'\s](.*?)["'\s].*(;?)$/gm;
const ESM_IMPORT_REGEX = /import(?:["'\s]*([\w*${}\n\r\t, ]+)\s*from\s*)?\s*["'](.*?)["']/gm;
const ESM_DYNAMIC_IMPORT_REGEX = /import\((?:['"].+['"]|`[^$]+`)\)/gm;
const HAS_NAMED_IMPORTS_REGEX = /^[\w\s\,]*\{(.*)\}/s;
const SPLIT_NAMED_IMPORTS_REGEX = /\bas\s+\w+|,/s;
Expand Down
2 changes: 2 additions & 0 deletions test/integration/include/dir/h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// test 8: Work even if no semicolons
import * as pkg from 'package-02'
1 change: 1 addition & 0 deletions test/integration/include/expected-install/import-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"array-flatten": "./array-flatten.js",
"http-vue-loader/src/httpVueLoader.js": "./http-vue-loader/src/httpVueLoader.js",
"package-01": "./package-01.js",
"package-02": "./package-02.js",
"vue-router": "./vue-router.js",
"vue/dist/vue.esm.browser.js": "./vue/dist/vue.esm.browser.js"
}
Expand Down
3 changes: 3 additions & 0 deletions test/integration/include/expected-install/package-02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function test() {}

export { test };
1 change: 1 addition & 0 deletions test/integration/include/expected-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
├─ array-flatten.js XXXX KB XXXX KB XXXX KB
├─ http-vue-loader/src/httpVueLoader.js XXXX KB XXXX KB XXXX KB
├─ package-01.js XXXX KB XXXX KB XXXX KB
├─ package-02.js XXXX KB XXXX KB XXXX KB
├─ vue-router.js XXXX KB XXXX KB XXXX KB
└─ vue/dist/vue.esm.browser.js XXXX KB XXXX KB XXXX KB
43 changes: 43 additions & 0 deletions test/integration/include/node_modules/package-02/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/integration/include/node_modules/package-02/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/integration/include/node_modules/package-02/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 265418e

Please sign in to comment.