Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const modules = import.meta.glob('#src/foo/*.ts')
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "scan-subpath-import-glob",
"private": true,
"imports": {
"#src/*": "./src/*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value = 'a'
33 changes: 32 additions & 1 deletion packages/vite/src/node/__tests__/scan.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import path from 'node:path'
import { describe, expect, test } from 'vitest'
import { commentRE, importsRE, scriptRE } from '../optimizer/scan'
import {
commentRE,
devToScanEnvironment,
importsRE,
scanImports,
scriptRE,
} from '../optimizer/scan'
import { multilineCommentsRE, singlelineCommentsRE } from '../utils'
import { createServer, createServerModuleRunner } from '..'

Expand Down Expand Up @@ -168,3 +174,28 @@ test('scan jsx-runtime', async (ctx) => {
expect((globalThis as any).__test_scan_jsx_runtime).toBe(1)
expect(mod1).toBe(mod2)
})

test('scan import.meta.glob package imports patterns', async (ctx) => {
const server = await createServer({
configFile: false,
logLevel: 'error',
root: path.join(
import.meta.dirname,
'fixtures',
'scan-subpath-import-glob',
),
optimizeDeps: {
entries: ['./entry.ts'],
force: true,
noDiscovery: false,
},
})
ctx.onTestFinished(() => server.close())

const { cancel, result } = scanImports(
devToScanEnvironment(server.environments.client),
)
ctx.onTestFinished(cancel)

await expect(result).resolves.toEqual({ deps: {}, missing: {} })
})
17 changes: 13 additions & 4 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,28 @@ function rolldownScanPlugin(
async function resolveId(
id: string,
importer?: string,
options?: Parameters<EnvironmentPluginContainer['resolveId']>[2],
): Promise<PartialResolvedId | null> {
return environment.pluginContainer.resolveId(
id,
importer && normalizePath(importer),
{ scan: true },
{ scan: true, ...options },
)
}
const resolve = async (id: string, importer?: string) => {
const key = id + (importer && path.dirname(importer))
const resolve = async (
id: string,
importer?: string,
options?: Parameters<typeof resolveId>[2],
) => {
const key = JSON.stringify([
id,
importer && path.dirname(importer),
options,
])
if (seen.has(key)) {
return seen.get(key)
}
const resolved = await resolveId(id, importer)
const resolved = await resolveId(id, importer, options)
const res = resolved?.id
seen.set(key, res)
return res
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

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

Loading