From dd6d7471a1c6ee6b2f441cfd98060727654048f1 Mon Sep 17 00:00:00 2001 From: shulaoda <165626830+shulaoda@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:03:00 +0800 Subject: [PATCH 1/6] test(import-glob): cover absolute base resolving to files outside root --- .../__tests__/glob-import-base.spec.ts | 16 ++++++++++++++++ playground/glob-import-base/external/x.js | 1 + playground/glob-import-base/external/y.js | 1 + playground/glob-import-base/package.json | 11 +++++++++++ playground/glob-import-base/root/index.html | 2 ++ playground/glob-import-base/root/src/main.js | 10 ++++++++++ playground/glob-import-base/vite.config.ts | 6 ++++++ 7 files changed, 47 insertions(+) create mode 100644 playground/glob-import-base/__tests__/glob-import-base.spec.ts create mode 100644 playground/glob-import-base/external/x.js create mode 100644 playground/glob-import-base/external/y.js create mode 100644 playground/glob-import-base/package.json create mode 100644 playground/glob-import-base/root/index.html create mode 100644 playground/glob-import-base/root/src/main.js create mode 100644 playground/glob-import-base/vite.config.ts diff --git a/playground/glob-import-base/__tests__/glob-import-base.spec.ts b/playground/glob-import-base/__tests__/glob-import-base.spec.ts new file mode 100644 index 00000000000000..be58b55d1de865 --- /dev/null +++ b/playground/glob-import-base/__tests__/glob-import-base.spec.ts @@ -0,0 +1,16 @@ +import { expect, test } from 'vitest' +import { page } from '~utils' + +// Regression test for https://github.com/rolldown/rolldown/issues/9144: +// `import.meta.glob` with `base: '/'` matching files outside of vite's root +// must still build and resolve correctly. The plugin must emit a +// root-relative import path (prefixed with `/`) so the bundler does not +// resolve it against the importer and land on a non-existent file. +test('absolute base with files outside of root', async () => { + await expect + .poll(async () => JSON.parse(await page.textContent('.result'))) + .toStrictEqual({ + '../external/x.js': 'hello from x', + '../external/y.js': 'hello from y', + }) +}) diff --git a/playground/glob-import-base/external/x.js b/playground/glob-import-base/external/x.js new file mode 100644 index 00000000000000..129881f202004a --- /dev/null +++ b/playground/glob-import-base/external/x.js @@ -0,0 +1 @@ +export const msg = 'hello from x' diff --git a/playground/glob-import-base/external/y.js b/playground/glob-import-base/external/y.js new file mode 100644 index 00000000000000..493ed577a33c85 --- /dev/null +++ b/playground/glob-import-base/external/y.js @@ -0,0 +1 @@ +export const msg = 'hello from y' diff --git a/playground/glob-import-base/package.json b/playground/glob-import-base/package.json new file mode 100644 index 00000000000000..e6e1a831aaf816 --- /dev/null +++ b/playground/glob-import-base/package.json @@ -0,0 +1,11 @@ +{ + "name": "@vitejs/test-glob-import-base", + "private": true, + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", + "preview": "vite preview" + } +} diff --git a/playground/glob-import-base/root/index.html b/playground/glob-import-base/root/index.html new file mode 100644 index 00000000000000..2e28d0bd38c786 --- /dev/null +++ b/playground/glob-import-base/root/index.html @@ -0,0 +1,2 @@ +

+
diff --git a/playground/glob-import-base/root/src/main.js b/playground/glob-import-base/root/src/main.js
new file mode 100644
index 00000000000000..cc1abecb9b0815
--- /dev/null
+++ b/playground/glob-import-base/root/src/main.js
@@ -0,0 +1,10 @@
+const modules = import.meta.glob('../external/*.js', {
+  eager: true,
+  base: '/',
+})
+
+document.querySelector('.result').textContent = JSON.stringify(
+  Object.fromEntries(Object.entries(modules).map(([k, v]) => [k, v.msg])),
+  null,
+  2,
+)
diff --git a/playground/glob-import-base/vite.config.ts b/playground/glob-import-base/vite.config.ts
new file mode 100644
index 00000000000000..0170945efc5ade
--- /dev/null
+++ b/playground/glob-import-base/vite.config.ts
@@ -0,0 +1,6 @@
+import path from 'node:path'
+import { defineConfig } from 'vite'
+
+export default defineConfig({
+  root: path.join(import.meta.dirname, './root'),
+})

From 6b1eebf5b0a7c64e19fa0d8aa10dc5ef5db4a227 Mon Sep 17 00:00:00 2001
From: shulaoda <165626830+shulaoda@users.noreply.github.com>
Date: Fri, 24 Apr 2026 12:05:29 +0800
Subject: [PATCH 2/6] test(import-glob): fold glob-import-base into glob-import
 as variant

---
 playground/glob-import-base/package.json              | 11 -----------
 .../__tests__/base}/glob-import-base.spec.ts          |  0
 .../base-fixture}/external/x.js                       |  0
 .../base-fixture}/external/y.js                       |  0
 .../base-fixture}/root/index.html                     |  0
 .../base-fixture}/root/src/main.js                    |  0
 .../vite.config-base.js}                              |  2 +-
 7 files changed, 1 insertion(+), 12 deletions(-)
 delete mode 100644 playground/glob-import-base/package.json
 rename playground/{glob-import-base/__tests__ => glob-import/__tests__/base}/glob-import-base.spec.ts (100%)
 rename playground/{glob-import-base => glob-import/base-fixture}/external/x.js (100%)
 rename playground/{glob-import-base => glob-import/base-fixture}/external/y.js (100%)
 rename playground/{glob-import-base => glob-import/base-fixture}/root/index.html (100%)
 rename playground/{glob-import-base => glob-import/base-fixture}/root/src/main.js (100%)
 rename playground/{glob-import-base/vite.config.ts => glob-import/vite.config-base.js} (61%)

diff --git a/playground/glob-import-base/package.json b/playground/glob-import-base/package.json
deleted file mode 100644
index e6e1a831aaf816..00000000000000
--- a/playground/glob-import-base/package.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
-  "name": "@vitejs/test-glob-import-base",
-  "private": true,
-  "type": "module",
-  "scripts": {
-    "dev": "vite",
-    "build": "vite build",
-    "debug": "node --inspect-brk ../../packages/vite/bin/vite",
-    "preview": "vite preview"
-  }
-}
diff --git a/playground/glob-import-base/__tests__/glob-import-base.spec.ts b/playground/glob-import/__tests__/base/glob-import-base.spec.ts
similarity index 100%
rename from playground/glob-import-base/__tests__/glob-import-base.spec.ts
rename to playground/glob-import/__tests__/base/glob-import-base.spec.ts
diff --git a/playground/glob-import-base/external/x.js b/playground/glob-import/base-fixture/external/x.js
similarity index 100%
rename from playground/glob-import-base/external/x.js
rename to playground/glob-import/base-fixture/external/x.js
diff --git a/playground/glob-import-base/external/y.js b/playground/glob-import/base-fixture/external/y.js
similarity index 100%
rename from playground/glob-import-base/external/y.js
rename to playground/glob-import/base-fixture/external/y.js
diff --git a/playground/glob-import-base/root/index.html b/playground/glob-import/base-fixture/root/index.html
similarity index 100%
rename from playground/glob-import-base/root/index.html
rename to playground/glob-import/base-fixture/root/index.html
diff --git a/playground/glob-import-base/root/src/main.js b/playground/glob-import/base-fixture/root/src/main.js
similarity index 100%
rename from playground/glob-import-base/root/src/main.js
rename to playground/glob-import/base-fixture/root/src/main.js
diff --git a/playground/glob-import-base/vite.config.ts b/playground/glob-import/vite.config-base.js
similarity index 61%
rename from playground/glob-import-base/vite.config.ts
rename to playground/glob-import/vite.config-base.js
index 0170945efc5ade..9d1c864caf5e8c 100644
--- a/playground/glob-import-base/vite.config.ts
+++ b/playground/glob-import/vite.config-base.js
@@ -2,5 +2,5 @@ import path from 'node:path'
 import { defineConfig } from 'vite'
 
 export default defineConfig({
-  root: path.join(import.meta.dirname, './root'),
+  root: path.join(import.meta.dirname, './base-fixture/root'),
 })

From d47c31e4d57ca22fb0e484bf64d5bf462056a104 Mon Sep 17 00:00:00 2001
From: shulaoda <165626830+shulaoda@users.noreply.github.com>
Date: Fri, 24 Apr 2026 12:06:57 +0800
Subject: [PATCH 3/6] u

---
 playground/glob-import/package.json | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/playground/glob-import/package.json b/playground/glob-import/package.json
index aa4cbcb53d3f33..78d5f8f44b5d79 100644
--- a/playground/glob-import/package.json
+++ b/playground/glob-import/package.json
@@ -10,7 +10,10 @@
     "dev": "vite root",
     "build": "vite build root",
     "debug": "node --inspect-brk ../../packages/vite/bin/vite",
-    "preview": "vite preview root"
+    "preview": "vite preview root",
+    "dev:base": "vite --config ./vite.config-base.js dev",
+    "build:base": "vite --config ./vite.config-base.js build",
+    "preview:base": "vite --config ./vite.config-base.js preview"
   },
   "dependencies": {
     "@vitejs/test-import-meta-glob-pkg": "file:./root/import-meta-glob-pkg"

From 30ef10e60973f8fa6a91a5bf4f80f8db79521f99 Mon Sep 17 00:00:00 2001
From: shulaoda <165626830+shulaoda@users.noreply.github.com>
Date: Thu, 21 May 2026 11:55:17 +0800
Subject: [PATCH 4/6] u

---
 .../__tests__/base/glob-import-base.spec.ts   | 16 --------------
 .../glob-import/__tests__/glob-import.spec.ts |  9 ++++++++
 .../glob-import/base-fixture/root/index.html  |  2 --
 .../glob-import/base-fixture/root/src/main.js | 10 ---------
 .../{base-fixture => }/external/x.js          |  0
 .../{base-fixture => }/external/y.js          |  0
 playground/glob-import/package.json           |  5 +----
 playground/glob-import/root/index.html        | 21 +++++++++++++++++++
 playground/glob-import/vite.config-base.js    |  6 ------
 9 files changed, 31 insertions(+), 38 deletions(-)
 delete mode 100644 playground/glob-import/__tests__/base/glob-import-base.spec.ts
 delete mode 100644 playground/glob-import/base-fixture/root/index.html
 delete mode 100644 playground/glob-import/base-fixture/root/src/main.js
 rename playground/glob-import/{base-fixture => }/external/x.js (100%)
 rename playground/glob-import/{base-fixture => }/external/y.js (100%)
 delete mode 100644 playground/glob-import/vite.config-base.js

diff --git a/playground/glob-import/__tests__/base/glob-import-base.spec.ts b/playground/glob-import/__tests__/base/glob-import-base.spec.ts
deleted file mode 100644
index be58b55d1de865..00000000000000
--- a/playground/glob-import/__tests__/base/glob-import-base.spec.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { expect, test } from 'vitest'
-import { page } from '~utils'
-
-// Regression test for https://github.com/rolldown/rolldown/issues/9144:
-// `import.meta.glob` with `base: '/'` matching files outside of vite's root
-// must still build and resolve correctly. The plugin must emit a
-// root-relative import path (prefixed with `/`) so the bundler does not
-// resolve it against the importer and land on a non-existent file.
-test('absolute base with files outside of root', async () => {
-  await expect
-    .poll(async () => JSON.parse(await page.textContent('.result')))
-    .toStrictEqual({
-      '../external/x.js': 'hello from x',
-      '../external/y.js': 'hello from y',
-    })
-})
diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts
index d54d8364fc7c10..829d5747ad95c1 100644
--- a/playground/glob-import/__tests__/glob-import.spec.ts
+++ b/playground/glob-import/__tests__/glob-import.spec.ts
@@ -367,3 +367,12 @@ test('import.meta.glob and dynamic import vars transformations should be visible
       JSON.stringify({ globTransformed: true, dynamicImportTransformed: true }),
     )
 })
+
+test('absolute base with files outside of root', async () => {
+  await expect
+    .poll(async () => JSON.parse(await page.textContent('.absolute-base-outside-root')))
+    .toStrictEqual({
+      '../external/x.js': 'hello from x',
+      '../external/y.js': 'hello from y',
+    })
+})
diff --git a/playground/glob-import/base-fixture/root/index.html b/playground/glob-import/base-fixture/root/index.html
deleted file mode 100644
index 2e28d0bd38c786..00000000000000
--- a/playground/glob-import/base-fixture/root/index.html
+++ /dev/null
@@ -1,2 +0,0 @@
-

-
diff --git a/playground/glob-import/base-fixture/root/src/main.js b/playground/glob-import/base-fixture/root/src/main.js
deleted file mode 100644
index cc1abecb9b0815..00000000000000
--- a/playground/glob-import/base-fixture/root/src/main.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const modules = import.meta.glob('../external/*.js', {
-  eager: true,
-  base: '/',
-})
-
-document.querySelector('.result').textContent = JSON.stringify(
-  Object.fromEntries(Object.entries(modules).map(([k, v]) => [k, v.msg])),
-  null,
-  2,
-)
diff --git a/playground/glob-import/base-fixture/external/x.js b/playground/glob-import/external/x.js
similarity index 100%
rename from playground/glob-import/base-fixture/external/x.js
rename to playground/glob-import/external/x.js
diff --git a/playground/glob-import/base-fixture/external/y.js b/playground/glob-import/external/y.js
similarity index 100%
rename from playground/glob-import/base-fixture/external/y.js
rename to playground/glob-import/external/y.js
diff --git a/playground/glob-import/package.json b/playground/glob-import/package.json
index 78d5f8f44b5d79..aa4cbcb53d3f33 100644
--- a/playground/glob-import/package.json
+++ b/playground/glob-import/package.json
@@ -10,10 +10,7 @@
     "dev": "vite root",
     "build": "vite build root",
     "debug": "node --inspect-brk ../../packages/vite/bin/vite",
-    "preview": "vite preview root",
-    "dev:base": "vite --config ./vite.config-base.js dev",
-    "build:base": "vite --config ./vite.config-base.js build",
-    "preview:base": "vite --config ./vite.config-base.js preview"
+    "preview": "vite preview root"
   },
   "dependencies": {
     "@vitejs/test-import-meta-glob-pkg": "file:./root/import-meta-glob-pkg"
diff --git a/playground/glob-import/root/index.html b/playground/glob-import/root/index.html
index 52efd42debf111..78a109cad47fe6 100644
--- a/playground/glob-import/root/index.html
+++ b/playground/glob-import/root/index.html
@@ -313,3 +313,24 @@ 

Transform visibility

document.querySelector('.transform-visibility').textContent = JSON.stringify(result) + +

Absolute base outside root

+

+
+
diff --git a/playground/glob-import/vite.config-base.js b/playground/glob-import/vite.config-base.js
deleted file mode 100644
index 9d1c864caf5e8c..00000000000000
--- a/playground/glob-import/vite.config-base.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import path from 'node:path'
-import { defineConfig } from 'vite'
-
-export default defineConfig({
-  root: path.join(import.meta.dirname, './base-fixture/root'),
-})

From cb7f6dfd501ca97c59e4d1b6a963d3b99d862ed5 Mon Sep 17 00:00:00 2001
From: shulaoda <165626830+shulaoda@users.noreply.github.com>
Date: Thu, 21 May 2026 11:59:54 +0800
Subject: [PATCH 5/6] u

---
 playground/glob-import/__tests__/glob-import.spec.ts | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts
index 829d5747ad95c1..e2cf1f709fff7f 100644
--- a/playground/glob-import/__tests__/glob-import.spec.ts
+++ b/playground/glob-import/__tests__/glob-import.spec.ts
@@ -370,7 +370,9 @@ test('import.meta.glob and dynamic import vars transformations should be visible
 
 test('absolute base with files outside of root', async () => {
   await expect
-    .poll(async () => JSON.parse(await page.textContent('.absolute-base-outside-root')))
+    .poll(async () =>
+      JSON.parse(await page.textContent('.absolute-base-outside-root')),
+    )
     .toStrictEqual({
       '../external/x.js': 'hello from x',
       '../external/y.js': 'hello from y',

From 20be67bbf212c65e8a1cd71cc757c451f2bd114a Mon Sep 17 00:00:00 2001
From: shulaoda <165626830+shulaoda@users.noreply.github.com>
Date: Thu, 21 May 2026 14:31:00 +0800
Subject: [PATCH 6/6] u

---
 playground/glob-import/root/index.html | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/playground/glob-import/root/index.html b/playground/glob-import/root/index.html
index 78a109cad47fe6..5a155ee4dd072b 100644
--- a/playground/glob-import/root/index.html
+++ b/playground/glob-import/root/index.html
@@ -318,11 +318,6 @@ 

Absolute base outside root