@wyw-in-js/transform 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/cache.js +13 -3
- package/esm/cache.js.map +1 -1
- package/esm/module.js +15 -0
- package/esm/module.js.map +1 -1
- package/lib/cache.js +13 -3
- package/lib/cache.js.map +1 -1
- package/lib/module.js +15 -0
- package/lib/module.js.map +1 -1
- package/package.json +8 -8
- package/types/cache.d.ts +1 -1
- package/types/cache.js +13 -3
- package/types/module.js +15 -0
package/esm/cache.js
CHANGED
|
@@ -20,11 +20,19 @@ export class TransformCacheCollection {
|
|
|
20
20
|
add(cacheName, key, value) {
|
|
21
21
|
const cache = this[cacheName];
|
|
22
22
|
loggers[cacheName]('%s:add %s %f', getFileIdx(key), key, () => {
|
|
23
|
+
if (value === undefined) {
|
|
24
|
+
return cache.has(key) ? 'removed' : 'noop';
|
|
25
|
+
}
|
|
23
26
|
if (!cache.has(key)) {
|
|
24
27
|
return 'added';
|
|
25
28
|
}
|
|
26
29
|
return cache.get(key) === value ? 'unchanged' : 'updated';
|
|
27
30
|
});
|
|
31
|
+
if (value === undefined) {
|
|
32
|
+
cache.delete(key);
|
|
33
|
+
this.contentHashes.delete(key);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
28
36
|
cache.set(key, value);
|
|
29
37
|
if ('initialCode' in value) {
|
|
30
38
|
this.contentHashes.set(key, hashContent(value.initialCode ?? ''));
|
|
@@ -69,17 +77,19 @@ export class TransformCacheCollection {
|
|
|
69
77
|
this.invalidate(cacheName, filename);
|
|
70
78
|
});
|
|
71
79
|
}
|
|
72
|
-
invalidateIfChanged(filename, content) {
|
|
80
|
+
invalidateIfChanged(filename, content, previousVisitedFiles) {
|
|
81
|
+
const visitedFiles = new Set(previousVisitedFiles);
|
|
73
82
|
const fileEntrypoint = this.get('entrypoints', filename);
|
|
74
83
|
|
|
75
84
|
// We need to check all dependencies of the file
|
|
76
85
|
// because they might have changed as well.
|
|
77
|
-
if (fileEntrypoint) {
|
|
86
|
+
if (fileEntrypoint && !visitedFiles.has(filename)) {
|
|
87
|
+
visitedFiles.add(filename);
|
|
78
88
|
for (const [, dependency] of fileEntrypoint.dependencies) {
|
|
79
89
|
const dependencyFilename = dependency.resolved;
|
|
80
90
|
if (dependencyFilename) {
|
|
81
91
|
const dependencyContent = fs.readFileSync(dependencyFilename, 'utf8');
|
|
82
|
-
this.invalidateIfChanged(dependencyFilename, dependencyContent);
|
|
92
|
+
this.invalidateIfChanged(dependencyFilename, dependencyContent, visitedFiles);
|
|
83
93
|
}
|
|
84
94
|
}
|
|
85
95
|
}
|
package/esm/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","names":["createHash","fs","logger","getFileIdx","hashContent","content","update","digest","cacheLogger","extend","cacheNames","loggers","reduce","acc","key","TransformCacheCollection","contentHashes","Map","constructor","caches","entrypoints","exports","add","cacheName","value","cache","has","get","set","initialCode","clear","forEach","name","
|
|
1
|
+
{"version":3,"file":"cache.js","names":["createHash","fs","logger","getFileIdx","hashContent","content","update","digest","cacheLogger","extend","cacheNames","loggers","reduce","acc","key","TransformCacheCollection","contentHashes","Map","constructor","caches","entrypoints","exports","add","cacheName","value","cache","undefined","has","get","delete","set","initialCode","clear","forEach","name","invalidate","res","invalidateForFile","filename","invalidateIfChanged","previousVisitedFiles","visitedFiles","Set","fileEntrypoint","dependency","dependencies","dependencyFilename","resolved","dependencyContent","readFileSync","hash","newHash"],"sources":["../src/cache.ts"],"sourcesContent":["import { createHash } from 'crypto';\nimport fs from 'node:fs';\nimport { logger } from '@wyw-in-js/shared';\n\nimport type { Entrypoint } from './transform/Entrypoint';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { getFileIdx } from './utils/getFileIdx';\n\nfunction hashContent(content: string) {\n return createHash('sha256').update(content).digest('hex');\n}\n\ninterface IBaseCachedEntrypoint {\n dependencies: Map<string, { resolved: string | null }>;\n initialCode?: string;\n}\n\ninterface ICaches<TEntrypoint extends IBaseCachedEntrypoint> {\n entrypoints: Map<string, TEntrypoint>;\n exports: Map<string, string[]>;\n}\n\ntype MapValue<T> = T extends Map<string, infer V> ? V : never;\n\nconst cacheLogger = logger.extend('cache');\n\nconst cacheNames = ['entrypoints', 'exports'] as const;\ntype CacheNames = (typeof cacheNames)[number];\n\nconst loggers = cacheNames.reduce(\n (acc, key) => ({\n ...acc,\n [key]: cacheLogger.extend(key),\n }),\n {} as Record<CacheNames, typeof logger>\n);\n\nexport class TransformCacheCollection<\n TEntrypoint extends IBaseCachedEntrypoint = Entrypoint | IEvaluatedEntrypoint,\n> {\n public readonly entrypoints: Map<string, TEntrypoint>;\n\n public readonly exports: Map<string, string[]>;\n\n private contentHashes = new Map<string, string>();\n\n constructor(caches: Partial<ICaches<TEntrypoint>> = {}) {\n this.entrypoints = caches.entrypoints || new Map();\n this.exports = caches.exports || new Map();\n }\n\n public add<\n TCache extends CacheNames,\n TValue extends MapValue<ICaches<TEntrypoint>[TCache]>,\n >(cacheName: TCache, key: string, value: TValue): void {\n const cache = this[cacheName] as Map<string, TValue>;\n loggers[cacheName]('%s:add %s %f', getFileIdx(key), key, () => {\n if (value === undefined) {\n return cache.has(key) ? 'removed' : 'noop';\n }\n\n if (!cache.has(key)) {\n return 'added';\n }\n\n return cache.get(key) === value ? 'unchanged' : 'updated';\n });\n\n if (value === undefined) {\n cache.delete(key);\n this.contentHashes.delete(key);\n return;\n }\n\n cache.set(key, value);\n\n if ('initialCode' in value) {\n this.contentHashes.set(key, hashContent(value.initialCode ?? ''));\n }\n }\n\n public clear(cacheName: CacheNames | 'all'): void {\n if (cacheName === 'all') {\n cacheNames.forEach((name) => {\n this.clear(name);\n });\n\n return;\n }\n\n loggers[cacheName]('clear');\n const cache = this[cacheName] as Map<string, unknown>;\n\n cache.clear();\n }\n\n public delete(cacheName: CacheNames, key: string): void {\n this.invalidate(cacheName, key);\n }\n\n public get<\n TCache extends CacheNames,\n TValue extends MapValue<ICaches<TEntrypoint>[TCache]>,\n >(cacheName: TCache, key: string): TValue | undefined {\n const cache = this[cacheName] as Map<string, TValue>;\n\n const res = cache.get(key);\n loggers[cacheName]('get', key, res === undefined ? 'miss' : 'hit');\n return res;\n }\n\n public has(cacheName: CacheNames, key: string): boolean {\n const cache = this[cacheName] as Map<string, unknown>;\n\n const res = cache.has(key);\n loggers[cacheName]('has', key, res);\n return res;\n }\n\n public invalidate(cacheName: CacheNames, key: string): void {\n const cache = this[cacheName] as Map<string, unknown>;\n if (!cache.has(key)) {\n return;\n }\n\n loggers[cacheName]('invalidate', key);\n\n cache.delete(key);\n }\n\n public invalidateForFile(filename: string) {\n cacheNames.forEach((cacheName) => {\n this.invalidate(cacheName, filename);\n });\n }\n\n public invalidateIfChanged(\n filename: string,\n content: string,\n previousVisitedFiles?: Set<string>\n ) {\n const visitedFiles = new Set(previousVisitedFiles);\n const fileEntrypoint = this.get('entrypoints', filename);\n\n // We need to check all dependencies of the file\n // because they might have changed as well.\n if (fileEntrypoint && !visitedFiles.has(filename)) {\n visitedFiles.add(filename);\n\n for (const [, dependency] of fileEntrypoint.dependencies) {\n const dependencyFilename = dependency.resolved;\n\n if (dependencyFilename) {\n const dependencyContent = fs.readFileSync(dependencyFilename, 'utf8');\n this.invalidateIfChanged(\n dependencyFilename,\n dependencyContent,\n visitedFiles\n );\n }\n }\n }\n\n const hash = this.contentHashes.get(filename);\n const newHash = hashContent(content);\n\n if (hash !== newHash) {\n cacheLogger('content has changed, invalidate all for %s', filename);\n this.contentHashes.set(filename, newHash);\n this.invalidateForFile(filename);\n\n return true;\n }\n\n return false;\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,QAAQ;AACnC,OAAOC,EAAE,MAAM,SAAS;AACxB,SAASC,MAAM,QAAQ,mBAAmB;AAI1C,SAASC,UAAU,QAAQ,oBAAoB;AAE/C,SAASC,WAAWA,CAACC,OAAe,EAAE;EACpC,OAAOL,UAA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;IACF;IAEA,MAAMS,IAAI,GAAG,IAAI,CAAClC,aAAa,CAACY,GAAG,CAACU,QAAQ,CAAC;IAC7C,MAAMa,OAAO,GAAG/C,WAAW,CAACC,OAAO,CAAC;IAEpC,IAAI6C,IAAI,KAAKC,OAAO,EAAE;MACpB3C,WAAW,CAAC,4CAA4C,EAAE8B,QAAQ,CAAC;MACnE,IAAI,CAACtB,aAAa,CAACc,GAAG,CAACQ,QAAQ,EAAEa,OAAO,CAAC;MACzC,IAAI,CAACd,iBAAiB,CAACC,QAAQ,CAAC;MAEhC,OAAO,IAAI;IACb;IAEA,OAAO,KAAK;EACd;AACF"}
|
package/esm/module.js
CHANGED
|
@@ -61,6 +61,11 @@ const builtins = {
|
|
|
61
61
|
vm: true,
|
|
62
62
|
zlib: true
|
|
63
63
|
};
|
|
64
|
+
const VITE_VIRTUAL_PREFIX = '/@';
|
|
65
|
+
const REACT_REFRESH_VIRTUAL_ID = '/@react-refresh';
|
|
66
|
+
const reactRefreshRuntime = {
|
|
67
|
+
createSignatureFunctionForTransform: () => () => {}
|
|
68
|
+
};
|
|
64
69
|
const NOOP = () => {};
|
|
65
70
|
function getUncached(cached, test) {
|
|
66
71
|
const cachedSet = new Set(typeof cached === 'string' ? cached.split(',') : cached);
|
|
@@ -80,6 +85,16 @@ export class Module {
|
|
|
80
85
|
callstack = [];
|
|
81
86
|
isEvaluated = false;
|
|
82
87
|
require = Object.assign(id => {
|
|
88
|
+
if (id === REACT_REFRESH_VIRTUAL_ID) {
|
|
89
|
+
this.dependencies.push(id);
|
|
90
|
+
this.debug('require', `vite virtual '${id}'`);
|
|
91
|
+
return reactRefreshRuntime;
|
|
92
|
+
}
|
|
93
|
+
if (id.startsWith(VITE_VIRTUAL_PREFIX)) {
|
|
94
|
+
this.dependencies.push(id);
|
|
95
|
+
this.debug('require', `vite virtual '${id}'`);
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
83
98
|
if (id in builtins) {
|
|
84
99
|
// The module is in the allowed list of builtin node modules
|
|
85
100
|
// Ideally we should prevent importing them, but webpack polyfills some
|
package/esm/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","names":["fs","NativeModule","path","vm","invariant","isFeatureEnabled","Entrypoint","getStack","isSuperSet","isUnprocessedEntrypointError","createVmContext","DefaultModuleImplementation","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","http","https","module","net","os","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","zlib","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","Module","callstack","isEvaluated","require","Object","assign","debug","dependency","isAbsolute","Error","source","dependencies","push","entrypoint","getEntrypoint","only","evaluated","evaluatedOnly","exports","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","cache","options","pluginOptions","features","name","WeakRef","idx","filename","log","extend","parentIsIgnored","ignored","extensions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","EvalError","message","join","extension","extname","includes","newEntrypoint","readFileSync","stack","uncachedExports","length","code","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport { isFeatureEnabled, type Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint> | Entrypoint;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = isFeatureEnabled(\n services.options.pluginOptions.features,\n 'useWeakRefInEval',\n entrypoint.name\n )\n ? new WeakRef(entrypoint)\n : entrypoint;\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint =\n this.#entrypointRef instanceof WeakRef\n ? this.#entrypointRef.deref()\n : this.#entrypointRef;\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,YAAY,MAAM,QAAQ;AACjC,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,EAAE,MAAM,IAAI;AAEnB,SAASC,SAAS,QAAQ,cAAc;AAExC,SAASC,gBAAgB,QAAuB,mBAAmB;AAEnE,OAAO,0BAA0B;AAEjC,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,QAAQ,EAAEC,UAAU,QAAQ,gCAAgC;AAGrE,SAASC,4BAA4B,QAAQ,g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AAC8B,UAAU,CAACsD,gBAAgB,CAACrF,EAAE,EAAE;QACpDA,EAAE,EAAEuC,QAAQ;QACZA,QAAQ;QACR+C,KAAK,EAAE,IAAI,CAACvD,UAAU,CAACwD,gBAAgB,CAAC3I,IAAI,CAACgH,OAAO,CAACrB,QAAQ,CAAC;MAChE,CAAC,CAAC;MAEF,OAAO;QACL1B,MAAM,EAAEb,EAAE;QACVkB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXjB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACAiF,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAOxC,UAAU,CAACwC,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAES7D,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAIb,MAAM,CAAC,IAAI,CAAC0B,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF"}
|
|
1
|
+
{"version":3,"file":"module.js","names":["fs","NativeModule","path","vm","invariant","isFeatureEnabled","Entrypoint","getStack","isSuperSet","isUnprocessedEntrypointError","createVmContext","DefaultModuleImplementation","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","http","https","module","net","os","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","zlib","VITE_VIRTUAL_PREFIX","REACT_REFRESH_VIRTUAL_ID","reactRefreshRuntime","createSignatureFunctionForTransform","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","Module","callstack","isEvaluated","require","Object","assign","dependencies","push","debug","startsWith","dependency","isAbsolute","Error","source","entrypoint","getEntrypoint","only","evaluated","evaluatedOnly","exports","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","cache","options","pluginOptions","features","name","WeakRef","idx","filename","log","extend","parentIsIgnored","ignored","extensions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","EvalError","message","join","extension","extname","includes","newEntrypoint","readFileSync","stack","uncachedExports","length","code","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport { isFeatureEnabled, type Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst VITE_VIRTUAL_PREFIX = '/@';\nconst REACT_REFRESH_VIRTUAL_ID = '/@react-refresh';\nconst reactRefreshRuntime = {\n createSignatureFunctionForTransform: () => () => {},\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id === REACT_REFRESH_VIRTUAL_ID) {\n this.dependencies.push(id);\n this.debug('require', `vite virtual '${id}'`);\n return reactRefreshRuntime;\n }\n\n if (id.startsWith(VITE_VIRTUAL_PREFIX)) {\n this.dependencies.push(id);\n this.debug('require', `vite virtual '${id}'`);\n return {};\n }\n\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint> | Entrypoint;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = isFeatureEnabled(\n services.options.pluginOptions.features,\n 'useWeakRefInEval',\n entrypoint.name\n )\n ? new WeakRef(entrypoint)\n : entrypoint;\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint =\n this.#entrypointRef instanceof WeakRef\n ? this.#entrypointRef.deref()\n : this.#entrypointRef;\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,YAAY,MAAM,QAAQ;AACjC,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,EAAE,MAAM,IAAI;AAEnB,SAASC,SAAS,QAAQ,cAAc;AAExC,SAASC,gBAAgB,QAAuB,mBAAmB;AAEnE,OAAO,0BAA0B;AAEjC,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,QAAQ,EAAEC,UAAU,QAAQ,gCAAgC;AAGrE,SAASC,4BAA4B,QAAQ,gDAAgD;AAE7F,SAASC,eAAe,QAAQ,sBAAsB;AAWtD,OAAO,MAAMC,2BAA2B,GAAGV,YACtB;;AAErB;AACA;AACA,MAAMW,QAAQ,GAAG;EACfC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,aAAa,EAAE,KAAK;EACpBC,OAAO,EAAE,KAAK;EACdC,OAAO,EAAE,IAAI;EACbC,SAAS,EAAE,IAAI;EACfC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,KAAK;EACZC,GAAG,EAAE,KAAK;EAC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;UACrB;QACF;;QAEA;QACA;QACA;QACAA,UAAU,CAACwC,GAAG,CAAC,GAAGhG,IAAI;QACtB8F,KAAK,CAACzE,IAAI,CAAC2E,GAAG,CAAC;MACjB,CAAC,CAAC;MAEF,MAAM;QAAE7C;MAAS,CAAC,GAAG,IAAI;MAEzB,MAAMvC,QAAQ,GAAG,IAAI,CAAC+B,UAAU,CAACsD,gBAAgB,CAACtF,EAAE,EAAE;QACpDA,EAAE,EAAEwC,QAAQ;QACZA,QAAQ;QACR+C,KAAK,EAAE,IAAI,CAACvD,UAAU,CAACwD,gBAAgB,CAAChJ,IAAI,CAACqH,OAAO,CAACrB,QAAQ,CAAC;MAChE,CAAC,CAAC;MAEF,OAAO;QACLxB,MAAM,EAAEhB,EAAE;QACVmB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXlB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACAkF,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAOxC,UAAU,CAACwC,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAES7D,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAId,MAAM,CAAC,IAAI,CAAC2B,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF"}
|
package/lib/cache.js
CHANGED
|
@@ -27,11 +27,19 @@ class TransformCacheCollection {
|
|
|
27
27
|
add(cacheName, key, value) {
|
|
28
28
|
const cache = this[cacheName];
|
|
29
29
|
loggers[cacheName]('%s:add %s %f', (0, _getFileIdx.getFileIdx)(key), key, () => {
|
|
30
|
+
if (value === undefined) {
|
|
31
|
+
return cache.has(key) ? 'removed' : 'noop';
|
|
32
|
+
}
|
|
30
33
|
if (!cache.has(key)) {
|
|
31
34
|
return 'added';
|
|
32
35
|
}
|
|
33
36
|
return cache.get(key) === value ? 'unchanged' : 'updated';
|
|
34
37
|
});
|
|
38
|
+
if (value === undefined) {
|
|
39
|
+
cache.delete(key);
|
|
40
|
+
this.contentHashes.delete(key);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
35
43
|
cache.set(key, value);
|
|
36
44
|
if ('initialCode' in value) {
|
|
37
45
|
var _value$initialCode;
|
|
@@ -77,17 +85,19 @@ class TransformCacheCollection {
|
|
|
77
85
|
this.invalidate(cacheName, filename);
|
|
78
86
|
});
|
|
79
87
|
}
|
|
80
|
-
invalidateIfChanged(filename, content) {
|
|
88
|
+
invalidateIfChanged(filename, content, previousVisitedFiles) {
|
|
89
|
+
const visitedFiles = new Set(previousVisitedFiles);
|
|
81
90
|
const fileEntrypoint = this.get('entrypoints', filename);
|
|
82
91
|
|
|
83
92
|
// We need to check all dependencies of the file
|
|
84
93
|
// because they might have changed as well.
|
|
85
|
-
if (fileEntrypoint) {
|
|
94
|
+
if (fileEntrypoint && !visitedFiles.has(filename)) {
|
|
95
|
+
visitedFiles.add(filename);
|
|
86
96
|
for (const [, dependency] of fileEntrypoint.dependencies) {
|
|
87
97
|
const dependencyFilename = dependency.resolved;
|
|
88
98
|
if (dependencyFilename) {
|
|
89
99
|
const dependencyContent = _nodeFs.default.readFileSync(dependencyFilename, 'utf8');
|
|
90
|
-
this.invalidateIfChanged(dependencyFilename, dependencyContent);
|
|
100
|
+
this.invalidateIfChanged(dependencyFilename, dependencyContent, visitedFiles);
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
103
|
}
|
package/lib/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","names":["_crypto","require","_nodeFs","_interopRequireDefault","_shared","_getFileIdx","obj","__esModule","default","hashContent","content","createHash","update","digest","cacheLogger","logger","extend","cacheNames","loggers","reduce","acc","key","TransformCacheCollection","contentHashes","Map","constructor","caches","entrypoints","exports","add","cacheName","value","cache","getFileIdx","has","get","set","_value$initialCode","initialCode","clear","forEach","name","
|
|
1
|
+
{"version":3,"file":"cache.js","names":["_crypto","require","_nodeFs","_interopRequireDefault","_shared","_getFileIdx","obj","__esModule","default","hashContent","content","createHash","update","digest","cacheLogger","logger","extend","cacheNames","loggers","reduce","acc","key","TransformCacheCollection","contentHashes","Map","constructor","caches","entrypoints","exports","add","cacheName","value","cache","getFileIdx","undefined","has","get","delete","set","_value$initialCode","initialCode","clear","forEach","name","invalidate","res","invalidateForFile","filename","invalidateIfChanged","previousVisitedFiles","visitedFiles","Set","fileEntrypoint","dependency","dependencies","dependencyFilename","resolved","dependencyContent","fs","readFileSync","hash","newHash"],"sources":["../src/cache.ts"],"sourcesContent":["import { createHash } from 'crypto';\nimport fs from 'node:fs';\nimport { logger } from '@wyw-in-js/shared';\n\nimport type { Entrypoint } from './transform/Entrypoint';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { getFileIdx } from './utils/getFileIdx';\n\nfunction hashContent(content: string) {\n return createHash('sha256').update(content).digest('hex');\n}\n\ninterface IBaseCachedEntrypoint {\n dependencies: Map<string, { resolved: string | null }>;\n initialCode?: string;\n}\n\ninterface ICaches<TEntrypoint extends IBaseCachedEntrypoint> {\n entrypoints: Map<string, TEntrypoint>;\n exports: Map<string, string[]>;\n}\n\ntype MapValue<T> = T extends Map<string, infer V> ? V : never;\n\nconst cacheLogger = logger.extend('cache');\n\nconst cacheNames = ['entrypoints', 'exports'] as const;\ntype CacheNames = (typeof cacheNames)[number];\n\nconst loggers = cacheNames.reduce(\n (acc, key) => ({\n ...acc,\n [key]: cacheLogger.extend(key),\n }),\n {} as Record<CacheNames, typeof logger>\n);\n\nexport class TransformCacheCollection<\n TEntrypoint extends IBaseCachedEntrypoint = Entrypoint | IEvaluatedEntrypoint,\n> {\n public readonly entrypoints: Map<string, TEntrypoint>;\n\n public readonly exports: Map<string, string[]>;\n\n private contentHashes = new Map<string, string>();\n\n constructor(caches: Partial<ICaches<TEntrypoint>> = {}) {\n this.entrypoints = caches.entrypoints || new Map();\n this.exports = caches.exports || new Map();\n }\n\n public add<\n TCache extends CacheNames,\n TValue extends MapValue<ICaches<TEntrypoint>[TCache]>,\n >(cacheName: TCache, key: string, value: TValue): void {\n const cache = this[cacheName] as Map<string, TValue>;\n loggers[cacheName]('%s:add %s %f', getFileIdx(key), key, () => {\n if (value === undefined) {\n return cache.has(key) ? 'removed' : 'noop';\n }\n\n if (!cache.has(key)) {\n return 'added';\n }\n\n return cache.get(key) === value ? 'unchanged' : 'updated';\n });\n\n if (value === undefined) {\n cache.delete(key);\n this.contentHashes.delete(key);\n return;\n }\n\n cache.set(key, value);\n\n if ('initialCode' in value) {\n this.contentHashes.set(key, hashContent(value.initialCode ?? ''));\n }\n }\n\n public clear(cacheName: CacheNames | 'all'): void {\n if (cacheName === 'all') {\n cacheNames.forEach((name) => {\n this.clear(name);\n });\n\n return;\n }\n\n loggers[cacheName]('clear');\n const cache = this[cacheName] as Map<string, unknown>;\n\n cache.clear();\n }\n\n public delete(cacheName: CacheNames, key: string): void {\n this.invalidate(cacheName, key);\n }\n\n public get<\n TCache extends CacheNames,\n TValue extends MapValue<ICaches<TEntrypoint>[TCache]>,\n >(cacheName: TCache, key: string): TValue | undefined {\n const cache = this[cacheName] as Map<string, TValue>;\n\n const res = cache.get(key);\n loggers[cacheName]('get', key, res === undefined ? 'miss' : 'hit');\n return res;\n }\n\n public has(cacheName: CacheNames, key: string): boolean {\n const cache = this[cacheName] as Map<string, unknown>;\n\n const res = cache.has(key);\n loggers[cacheName]('has', key, res);\n return res;\n }\n\n public invalidate(cacheName: CacheNames, key: string): void {\n const cache = this[cacheName] as Map<string, unknown>;\n if (!cache.has(key)) {\n return;\n }\n\n loggers[cacheName]('invalidate', key);\n\n cache.delete(key);\n }\n\n public invalidateForFile(filename: string) {\n cacheNames.forEach((cacheName) => {\n this.invalidate(cacheName, filename);\n });\n }\n\n public invalidateIfChanged(\n filename: string,\n content: string,\n previousVisitedFiles?: Set<string>\n ) {\n const visitedFiles = new Set(previousVisitedFiles);\n const fileEntrypoint = this.get('entrypoints', filename);\n\n // We need to check all dependencies of the file\n // because they might have changed as well.\n if (fileEntrypoint && !visitedFiles.has(filename)) {\n visitedFiles.add(filename);\n\n for (const [, dependency] of fileEntrypoint.dependencies) {\n const dependencyFilename = dependency.resolved;\n\n if (dependencyFilename) {\n const dependencyContent = fs.readFileSync(dependencyFilename, 'utf8');\n this.invalidateIfChanged(\n dependencyFilename,\n dependencyContent,\n visitedFiles\n );\n }\n }\n }\n\n const hash = this.contentHashes.get(filename);\n const newHash = hashContent(content);\n\n if (hash !== newHash) {\n cacheLogger('content has changed, invalidate all for %s', filename);\n this.contentHashes.set(filename, newHash);\n this.invalidateForFile(filename);\n\n return true;\n }\n\n return false;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAIA,IAAAI,WAAA,GAAAJ,OAAA;AAAgD,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEhD,SAASG,WAAWA,CAACC,OAAe,EAAE;EACpC,OAAO,IAAAC,kBAAU,EAAC,QAAQ,CAAC,CAACC,MAAM,CAACF,OAAO,CAAC,CAACG,MAAM,CAAC,KAAK,CAAC;AAC3D;AAcA,MAAMC,WAAW,GAAGC,cAAM,CAACC,MAAM,CAAC,OAAO,CAAC;AAE1C,MAAMC,UAAU,GAAG,CAAC,aAAa,EAAE,SAAS,CAAU;AAGtD,MAAMC,OAAO,GAAGD,UAAU,CAACE,MAAM,CAC/B,CAACC,GAAG,EAAEC,GAAG,MAAM;EACb,GAAGD,GAAG;EACN,CAACC,GAAG,GAAGP,WAAW,CAACE,MAAM,CAACK,GAAG;AAC/B,CAAC,CAAC,EACF,CAAC,CACH,CAAC;AAEM,MAAMC,wBAAwB,CAEnC;EAKQC,aAAa,GAAG,IAAIC,GAAG,CAAiB,CAAC;EAEjDC,WAAWA,CAACC,MAAqC,GAAG,C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ib/module.js
CHANGED
|
@@ -68,6 +68,11 @@ const builtins = {
|
|
|
68
68
|
vm: true,
|
|
69
69
|
zlib: true
|
|
70
70
|
};
|
|
71
|
+
const VITE_VIRTUAL_PREFIX = '/@';
|
|
72
|
+
const REACT_REFRESH_VIRTUAL_ID = '/@react-refresh';
|
|
73
|
+
const reactRefreshRuntime = {
|
|
74
|
+
createSignatureFunctionForTransform: () => () => {}
|
|
75
|
+
};
|
|
71
76
|
const NOOP = () => {};
|
|
72
77
|
function getUncached(cached, test) {
|
|
73
78
|
const cachedSet = new Set(typeof cached === 'string' ? cached.split(',') : cached);
|
|
@@ -87,6 +92,16 @@ class Module {
|
|
|
87
92
|
callstack = [];
|
|
88
93
|
isEvaluated = false;
|
|
89
94
|
require = Object.assign(id => {
|
|
95
|
+
if (id === REACT_REFRESH_VIRTUAL_ID) {
|
|
96
|
+
this.dependencies.push(id);
|
|
97
|
+
this.debug('require', `vite virtual '${id}'`);
|
|
98
|
+
return reactRefreshRuntime;
|
|
99
|
+
}
|
|
100
|
+
if (id.startsWith(VITE_VIRTUAL_PREFIX)) {
|
|
101
|
+
this.dependencies.push(id);
|
|
102
|
+
this.debug('require', `vite virtual '${id}'`);
|
|
103
|
+
return {};
|
|
104
|
+
}
|
|
90
105
|
if (id in builtins) {
|
|
91
106
|
// The module is in the allowed list of builtin node modules
|
|
92
107
|
// Ideally we should prevent importing them, but webpack polyfills some
|
package/lib/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","names":["_fs","_interopRequireDefault","require","_module","_path","_vm","_tsInvariant","_shared","_Entrypoint","_Entrypoint2","_UnprocessedEntrypointError","_createVmContext","obj","__esModule","default","DefaultModuleImplementation","exports","NativeModule","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","fs","http","https","module","net","os","path","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","vm","zlib","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","invariant","Module","callstack","isEvaluated","Object","assign","debug","dependency","isAbsolute","Error","source","dependencies","push","entrypoint","getEntrypoint","only","evaluated","isSuperSet","evaluatedOnly","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","_parentModule$ignored","_entrypoint$ignored","cache","isFeatureEnabled","options","pluginOptions","features","name","WeakRef","idx","filename","log","extend","parentIsIgnored","ignored","extensions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","createVmContext","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","isUnprocessedEntrypointError","EvalError","message","join","_entrypoint$evaluated","extension","extname","includes","newEntrypoint","readFileSync","stack","getStack","_entrypoint$only","uncachedExports","length","code","Entrypoint","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport { isFeatureEnabled, type Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint> | Entrypoint;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = isFeatureEnabled(\n services.options.pluginOptions.features,\n 'useWeakRefInEval',\n entrypoint.name\n )\n ? new WeakRef(entrypoint)\n : entrypoint;\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint =\n this.#entrypointRef instanceof WeakRef\n ? this.#entrypointRef.deref()\n : this.#entrypointRef;\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":";;;;;;AAaA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,GAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEA,IAAAI,YAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AAEAA,OAAA;AAEA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AAGA,IAAAQ,2BAAA,GAAAR,OAAA;AAEA,IAAAS,gBAAA,GAAAT,OAAA;AAAuD,SAAAD,uBAAAW,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AA9BvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA8BO,MAAMG,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAGE,eACtB;;AAEr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OAAO,CAAEC,GAAG,IAAK;QAC/B,IAAIA,GAAG,IAAI9C,UAAU,EAAE;UACrB;QACF;;QAEA;QACA;QACA;QACAA,UAAU,CAAC8C,GAAG,CAAC,GAAGxG,IAAI;QACtBsG,KAAK,CAAC5E,IAAI,CAAC8E,GAAG,CAAC;MACjB,CAAC,CAAC;MAEF,MAAM;QAAEnD;MAAS,CAAC,GAAG,IAAI;MAEzB,MAAMzC,QAAQ,GAAG,IAAI,CAAC8B,UAAU,CAAC+D,gBAAgB,CAAC9F,EAAE,EAAE;QACpDA,EAAE,EAAE0C,QAAQ;QACZA,QAAQ;QACRqD,KAAK,EAAE,IAAI,CAAChE,UAAU,CAACiE,gBAAgB,CAAC3H,aAAI,CAAC2F,OAAO,CAACtB,QAAQ,CAAC;MAChE,CAAC,CAAC;MAEF,OAAO;QACL7B,MAAM,EAAEb,EAAE;QACVkB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXjB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACA0F,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAO9C,UAAU,CAAC8C,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAEStE,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAIZ,MAAM,CAAC,IAAI,CAACyB,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF;AAAC9E,OAAA,CAAAmD,MAAA,GAAAA,MAAA"}
|
|
1
|
+
{"version":3,"file":"module.js","names":["_fs","_interopRequireDefault","require","_module","_path","_vm","_tsInvariant","_shared","_Entrypoint","_Entrypoint2","_UnprocessedEntrypointError","_createVmContext","obj","__esModule","default","DefaultModuleImplementation","exports","NativeModule","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","fs","http","https","module","net","os","path","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","vm","zlib","VITE_VIRTUAL_PREFIX","REACT_REFRESH_VIRTUAL_ID","reactRefreshRuntime","createSignatureFunctionForTransform","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","invariant","Module","callstack","isEvaluated","Object","assign","dependencies","push","debug","startsWith","dependency","isAbsolute","Error","source","entrypoint","getEntrypoint","only","evaluated","isSuperSet","evaluatedOnly","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","_parentModule$ignored","_entrypoint$ignored","cache","isFeatureEnabled","options","pluginOptions","features","name","WeakRef","idx","filename","log","extend","parentIsIgnored","ignored","extensions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","createVmContext","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","isUnprocessedEntrypointError","EvalError","message","join","_entrypoint$evaluated","extension","extname","includes","newEntrypoint","readFileSync","stack","getStack","_entrypoint$only","uncachedExports","length","code","Entrypoint","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport { isFeatureEnabled, type Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst VITE_VIRTUAL_PREFIX = '/@';\nconst REACT_REFRESH_VIRTUAL_ID = '/@react-refresh';\nconst reactRefreshRuntime = {\n createSignatureFunctionForTransform: () => () => {},\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id === REACT_REFRESH_VIRTUAL_ID) {\n this.dependencies.push(id);\n this.debug('require', `vite virtual '${id}'`);\n return reactRefreshRuntime;\n }\n\n if (id.startsWith(VITE_VIRTUAL_PREFIX)) {\n this.dependencies.push(id);\n this.debug('require', `vite virtual '${id}'`);\n return {};\n }\n\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint> | Entrypoint;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = isFeatureEnabled(\n services.options.pluginOptions.features,\n 'useWeakRefInEval',\n entrypoint.name\n )\n ? new WeakRef(entrypoint)\n : entrypoint;\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint =\n this.#entrypointRef instanceof WeakRef\n ? this.#entrypointRef.deref()\n : this.#entrypointRef;\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":";;;;;;AAaA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,GAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEA,IAAAI,YAAA,GAAAJ,OAAA;AAEA,IAAAK,OAAA,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AQ,GAAG,IAAI,CAAC+B,UAAU,CAAC+D,gBAAgB,CAAC/F,EAAE,EAAE;QACpDA,EAAE,EAAE2C,QAAQ;QACZA,QAAQ;QACRqD,KAAK,EAAE,IAAI,CAAChE,UAAU,CAACiE,gBAAgB,CAAChI,aAAI,CAACgG,OAAO,CAACtB,QAAQ,CAAC;MAChE,CAAC,CAAC;MAEF,OAAO;QACL3B,MAAM,EAAEhB,EAAE;QACVmB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXlB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACA2F,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAO9C,UAAU,CAAC8C,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAEStE,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAIb,MAAM,CAAC,IAAI,CAAC0B,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF;AAACnF,OAAA,CAAAuD,MAAA,GAAAA,MAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/transform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@babel/core": "^7.23.5",
|
|
6
6
|
"@babel/generator": "^7.23.5",
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"@babel/types": "^7.23.5",
|
|
12
12
|
"babel-merge": "^3.0.0",
|
|
13
13
|
"cosmiconfig": "^8.0.0",
|
|
14
|
-
"happy-dom": "^
|
|
14
|
+
"happy-dom": "^20.0.10",
|
|
15
15
|
"source-map": "^0.7.4",
|
|
16
16
|
"stylis": "^4.3.0",
|
|
17
17
|
"ts-invariant": "^0.10.3",
|
|
18
|
-
"@wyw-in-js/processor-utils": "0.
|
|
19
|
-
"@wyw-in-js/shared": "0.
|
|
18
|
+
"@wyw-in-js/processor-utils": "0.8.1",
|
|
19
|
+
"@wyw-in-js/shared": "0.8.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/plugin-syntax-typescript": "^7.23.3",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"glob": "^10.3.10",
|
|
38
38
|
"strip-ansi": "^5.2.0",
|
|
39
39
|
"typescript": "^5.2.2",
|
|
40
|
-
"@wyw-in-js/babel-config": "0.
|
|
41
|
-
"@wyw-in-js/eslint-config": "0.
|
|
42
|
-
"@wyw-in-js/jest-preset": "0.
|
|
43
|
-
"@wyw-in-js/ts-config": "0.
|
|
40
|
+
"@wyw-in-js/babel-config": "0.8.1",
|
|
41
|
+
"@wyw-in-js/eslint-config": "0.8.1",
|
|
42
|
+
"@wyw-in-js/jest-preset": "0.8.1",
|
|
43
|
+
"@wyw-in-js/ts-config": "0.8.1"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=16.0.0"
|
package/types/cache.d.ts
CHANGED
|
@@ -25,6 +25,6 @@ export declare class TransformCacheCollection<TEntrypoint extends IBaseCachedEnt
|
|
|
25
25
|
has(cacheName: CacheNames, key: string): boolean;
|
|
26
26
|
invalidate(cacheName: CacheNames, key: string): void;
|
|
27
27
|
invalidateForFile(filename: string): void;
|
|
28
|
-
invalidateIfChanged(filename: string, content: string): boolean;
|
|
28
|
+
invalidateIfChanged(filename: string, content: string, previousVisitedFiles?: Set<string>): boolean;
|
|
29
29
|
}
|
|
30
30
|
export {};
|
package/types/cache.js
CHANGED
|
@@ -28,11 +28,19 @@ class TransformCacheCollection {
|
|
|
28
28
|
add(cacheName, key, value) {
|
|
29
29
|
const cache = this[cacheName];
|
|
30
30
|
loggers[cacheName]('%s:add %s %f', (0, getFileIdx_1.getFileIdx)(key), key, () => {
|
|
31
|
+
if (value === undefined) {
|
|
32
|
+
return cache.has(key) ? 'removed' : 'noop';
|
|
33
|
+
}
|
|
31
34
|
if (!cache.has(key)) {
|
|
32
35
|
return 'added';
|
|
33
36
|
}
|
|
34
37
|
return cache.get(key) === value ? 'unchanged' : 'updated';
|
|
35
38
|
});
|
|
39
|
+
if (value === undefined) {
|
|
40
|
+
cache.delete(key);
|
|
41
|
+
this.contentHashes.delete(key);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
36
44
|
cache.set(key, value);
|
|
37
45
|
if ('initialCode' in value) {
|
|
38
46
|
this.contentHashes.set(key, hashContent(value.initialCode ?? ''));
|
|
@@ -77,16 +85,18 @@ class TransformCacheCollection {
|
|
|
77
85
|
this.invalidate(cacheName, filename);
|
|
78
86
|
});
|
|
79
87
|
}
|
|
80
|
-
invalidateIfChanged(filename, content) {
|
|
88
|
+
invalidateIfChanged(filename, content, previousVisitedFiles) {
|
|
89
|
+
const visitedFiles = new Set(previousVisitedFiles);
|
|
81
90
|
const fileEntrypoint = this.get('entrypoints', filename);
|
|
82
91
|
// We need to check all dependencies of the file
|
|
83
92
|
// because they might have changed as well.
|
|
84
|
-
if (fileEntrypoint) {
|
|
93
|
+
if (fileEntrypoint && !visitedFiles.has(filename)) {
|
|
94
|
+
visitedFiles.add(filename);
|
|
85
95
|
for (const [, dependency] of fileEntrypoint.dependencies) {
|
|
86
96
|
const dependencyFilename = dependency.resolved;
|
|
87
97
|
if (dependencyFilename) {
|
|
88
98
|
const dependencyContent = node_fs_1.default.readFileSync(dependencyFilename, 'utf8');
|
|
89
|
-
this.invalidateIfChanged(dependencyFilename, dependencyContent);
|
|
99
|
+
this.invalidateIfChanged(dependencyFilename, dependencyContent, visitedFiles);
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
}
|
package/types/module.js
CHANGED
|
@@ -65,6 +65,11 @@ const builtins = {
|
|
|
65
65
|
vm: true,
|
|
66
66
|
zlib: true,
|
|
67
67
|
};
|
|
68
|
+
const VITE_VIRTUAL_PREFIX = '/@';
|
|
69
|
+
const REACT_REFRESH_VIRTUAL_ID = '/@react-refresh';
|
|
70
|
+
const reactRefreshRuntime = {
|
|
71
|
+
createSignatureFunctionForTransform: () => () => { },
|
|
72
|
+
};
|
|
68
73
|
const NOOP = () => { };
|
|
69
74
|
function getUncached(cached, test) {
|
|
70
75
|
const cachedSet = new Set(typeof cached === 'string' ? cached.split(',') : cached);
|
|
@@ -92,6 +97,16 @@ class Module {
|
|
|
92
97
|
isEvaluated = false;
|
|
93
98
|
parentIsIgnored;
|
|
94
99
|
require = Object.assign((id) => {
|
|
100
|
+
if (id === REACT_REFRESH_VIRTUAL_ID) {
|
|
101
|
+
this.dependencies.push(id);
|
|
102
|
+
this.debug('require', `vite virtual '${id}'`);
|
|
103
|
+
return reactRefreshRuntime;
|
|
104
|
+
}
|
|
105
|
+
if (id.startsWith(VITE_VIRTUAL_PREFIX)) {
|
|
106
|
+
this.dependencies.push(id);
|
|
107
|
+
this.debug('require', `vite virtual '${id}'`);
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
95
110
|
if (id in builtins) {
|
|
96
111
|
// The module is in the allowed list of builtin node modules
|
|
97
112
|
// Ideally we should prevent importing them, but webpack polyfills some
|