From 669d7e0f4b6ea4a73d3598ab1473b58c72bf093b Mon Sep 17 00:00:00 2001 From: Fran Dios Date: Wed, 12 Jan 2022 13:37:58 +0100 Subject: [PATCH] feat: allow globs in node_modules when pattern is explicit (#6056) --- .gitignore | 1 + .../glob-import/__tests__/glob-import.spec.ts | 7 ++++ .../glob-import/dir/node_modules/hoge.js | 1 + packages/playground/glob-import/index.html | 39 ++++++++++++------- packages/vite/src/node/importGlob.ts | 3 +- 5 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 packages/playground/glob-import/dir/node_modules/hoge.js diff --git a/.gitignore b/.gitignore index 6a9f8063929462..44abdd7bf563db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store node_modules +!**/glob-import/dir/node_modules dist dist-ssr TODOs.md diff --git a/packages/playground/glob-import/__tests__/glob-import.spec.ts b/packages/playground/glob-import/__tests__/glob-import.spec.ts index 311f94cd00571a..3a2425736548ea 100644 --- a/packages/playground/glob-import/__tests__/glob-import.spec.ts +++ b/packages/playground/glob-import/__tests__/glob-import.spec.ts @@ -45,6 +45,10 @@ const allResult = { } } +const nodeModulesResult = { + '/dir/node_modules/hoge.js': { msg: 'hoge' } +} + const rawResult = { '/dir/baz.json': { msg: 'baz' @@ -55,6 +59,9 @@ test('should work', async () => { expect(await page.textContent('.result')).toBe( JSON.stringify(allResult, null, 2) ) + expect(await page.textContent('.result-node_modules')).toBe( + JSON.stringify(nodeModulesResult, null, 2) + ) }) test('import glob raw', async () => { diff --git a/packages/playground/glob-import/dir/node_modules/hoge.js b/packages/playground/glob-import/dir/node_modules/hoge.js new file mode 100644 index 00000000000000..874eb4312f0dc5 --- /dev/null +++ b/packages/playground/glob-import/dir/node_modules/hoge.js @@ -0,0 +1 @@ +export const msg = 'hoge' diff --git a/packages/playground/glob-import/index.html b/packages/playground/glob-import/index.html index e408ec8adda602..bb5e2f3c18f752 100644 --- a/packages/playground/glob-import/index.html +++ b/packages/playground/glob-import/index.html @@ -1,8 +1,30 @@

+