MCPcopy
hub / github.com/vitejs/vite / runnerImport

Function runnerImport

packages/vite/src/node/ssr/runnerImport.ts:15–76  ·  view source on GitHub ↗
(
  moduleId: string,
  inlineConfig?: InlineConfig,
)

Source from the content-addressed store, hash-verified

13 * @experimental
14 */
15export async function runnerImport<T>(
16 moduleId: string,
17 inlineConfig?: InlineConfig,
18): Promise<RunnerImportResult<T>> {
19 const isModuleSyncConditionEnabled = (await import('#module-sync-enabled'))
20 .default
21 const config = await resolveConfig(
22 mergeConfig(inlineConfig || {}, {
23 configFile: false,
24 envDir: false,
25 cacheDir: process.cwd(),
26 environments: {
27 inline: {
28 consumer: 'server',
29 dev: {
30 moduleRunnerTransform: true,
31 },
32 resolve: {
33 external: true,
34 mainFields: [],
35 conditions: [
36 'node',
37 ...(isModuleSyncConditionEnabled ? ['module-sync'] : []),
38 ],
39 },
40 },
41 },
42 } satisfies InlineConfig),
43 'serve',
44 )
45 const environment = createRunnableDevEnvironment('inline', config, {
46 runnerOptions: {
47 hmr: {
48 logger: false,
49 },
50 },
51 hot: false,
52 })
53 await environment.init()
54 try {
55 const module = await environment.runner.import(moduleId)
56 const modules = [
57 ...environment.runner.evaluatedModules.urlToIdModuleMap.values(),
58 ]
59 const dependencies = modules
60 .filter((m) => {
61 // ignore all externalized modules
62 if (!m.meta || 'externalize' in m.meta) {
63 return false
64 }
65 // ignore the current module
66 return m.exports !== module
67 })
68 .map((m) => m.file)
69 return {
70 module,
71 dependencies,
72 }

Callers

nothing calls this directly

Calls 6

resolveConfigFunction · 0.90
mergeConfigFunction · 0.90
importMethod · 0.80
closeMethod · 0.65
initMethod · 0.45

Tested by

no test coverage detected