1
1
import type { ViteHotContext } from 'types/hot'
2
2
import { HMRClient , HMRContext , type HMRLogger } from '../shared/hmr'
3
- import { cleanUrl , isPrimitive , isWindows } from '../shared/utils'
3
+ import { cleanUrl , isPrimitive } from '../shared/utils'
4
4
import { analyzeImportedModDifference } from '../shared/ssrTransform'
5
5
import {
6
6
type NormalizedModuleRunnerTransport ,
@@ -11,17 +11,11 @@ import { EvaluatedModules } from './evaluatedModules'
11
11
import type {
12
12
ModuleEvaluator ,
13
13
ModuleRunnerContext ,
14
- ModuleRunnerImportMeta ,
15
14
ModuleRunnerOptions ,
16
15
ResolvedResult ,
17
16
SSRImportMetadata ,
18
17
} from './types'
19
- import {
20
- posixDirname ,
21
- posixPathToFileHref ,
22
- posixResolve ,
23
- toWindowsPath ,
24
- } from './utils'
18
+ import { posixDirname , posixPathToFileHref , posixResolve } from './utils'
25
19
import {
26
20
ssrDynamicImportKey ,
27
21
ssrExportAllKey ,
@@ -34,6 +28,7 @@ import { hmrLogger, silentConsole } from './hmrLogger'
34
28
import { createHMRHandlerForRunner } from './hmrHandler'
35
29
import { enableSourceMapSupport } from './sourcemap/index'
36
30
import { ESModulesEvaluator } from './esmEvaluator'
31
+ import { createDefaultImportMeta } from './createImportMeta'
37
32
38
33
interface ModuleRunnerDebugger {
39
34
( formatter : unknown , ...args : unknown [ ] ) : void
@@ -43,13 +38,6 @@ export class ModuleRunner {
43
38
public evaluatedModules : EvaluatedModules
44
39
public hmrClient ?: HMRClient
45
40
46
- private readonly envProxy = new Proxy ( { } as any , {
47
- get ( _ , p ) {
48
- throw new Error (
49
- `[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${ String ( p ) } " instead.` ,
50
- )
51
- } ,
52
- } )
53
41
private readonly transport : NormalizedModuleRunnerTransport
54
42
private readonly resetSourceMapSupport ?: ( ) => void
55
43
private readonly concurrentModuleNodePromises = new Map <
@@ -351,29 +339,13 @@ export class ModuleRunner {
351
339
)
352
340
}
353
341
342
+ const createImportMeta =
343
+ this . options . createImportMeta ?? createDefaultImportMeta
344
+
354
345
const modulePath = cleanUrl ( file || moduleId )
355
346
// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
356
347
const href = posixPathToFileHref ( modulePath )
357
- const filename = modulePath
358
- const dirname = posixDirname ( modulePath )
359
- const meta : ModuleRunnerImportMeta = {
360
- filename : isWindows ? toWindowsPath ( filename ) : filename ,
361
- dirname : isWindows ? toWindowsPath ( dirname ) : dirname ,
362
- url : href ,
363
- env : this . envProxy ,
364
- resolve ( _id , _parent ?) {
365
- throw new Error (
366
- '[module runner] "import.meta.resolve" is not supported.' ,
367
- )
368
- } ,
369
- // should be replaced during transformation
370
- glob ( ) {
371
- throw new Error (
372
- `[module runner] "import.meta.glob" is statically replaced during ` +
373
- `file transformation. Make sure to reference it by the full name.` ,
374
- )
375
- } ,
376
- }
348
+ const meta = await createImportMeta ( modulePath )
377
349
const exports = Object . create ( null )
378
350
Object . defineProperty ( exports , Symbol . toStringTag , {
379
351
value : 'Module' ,
0 commit comments