@wyw-in-js/transform 0.5.0 → 0.5.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/module.js CHANGED
@@ -16,6 +16,7 @@ import NativeModule from 'module';
16
16
  import path from 'path';
17
17
  import vm from 'vm';
18
18
  import { invariant } from 'ts-invariant';
19
+ import { isFeatureEnabled } from '@wyw-in-js/shared';
19
20
  import './utils/dispose-polyfill';
20
21
  import { Entrypoint } from './transform/Entrypoint';
21
22
  import { getStack, isSuperSet } from './transform/Entrypoint.helpers';
@@ -119,7 +120,7 @@ export class Module {
119
120
  this.services = services;
120
121
  this.moduleImpl = moduleImpl;
121
122
  this.cache = services.cache;
122
- this.#entrypointRef = new WeakRef(entrypoint);
123
+ this.#entrypointRef = isFeatureEnabled(services.options.pluginOptions.features, 'useWeakRefInEval', entrypoint.name) ? new WeakRef(entrypoint) : entrypoint;
123
124
  this.idx = entrypoint.idx;
124
125
  this.id = entrypoint.name;
125
126
  this.filename = entrypoint.name;
@@ -143,7 +144,7 @@ export class Module {
143
144
  this.debug('the whole exports was overridden with %O', value);
144
145
  }
145
146
  get entrypoint() {
146
- const entrypoint = this.#entrypointRef.deref();
147
+ const entrypoint = this.#entrypointRef instanceof WeakRef ? this.#entrypointRef.deref() : this.#entrypointRef;
147
148
  invariant(entrypoint, `Module ${this.idx} is disposed`);
148
149
  return entrypoint;
149
150
  }
package/esm/module.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","names":["fs","NativeModule","path","vm","invariant","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","WeakRef","idx","name","filename","log","extend","parentIsIgnored","ignored","extensions","options","pluginOptions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","features","__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 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>;\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 = new WeakRef(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 = this.#entrypointRef.deref();\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;AAIxC,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,GAAGT,YACtB;;AAErB;AACA;AACA,MAAMU,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;EACVC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZtB,EAAE,EAAE,KAAK;EACTuB,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE,IAAI;EACXC,MAAM,EAAE,KAAK;EACbC,GAAG,EAAE,KAAK;EACVC,EAAE,EAAE,IAAI;EACRzB,IAAI,EAAE,IAAI;EACV0B,QAAQ,EAAE,IAAI;EACdC,OAAO,E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AEA,MAAMgC,UAAU,GAAG,IAAI,CAACV,UAAU,CAACkD,WAAW;IAC9C,MAAMC,KAAe,GAAG,EAAE;IAE1B,IAAI;MACF;MACA,IAAI,CAACzC,UAAU,CAAC0C,OAAO,CAAEC,GAAG,IAAK;QAC/B,IAAIA,GAAG,IAAI3C,UAAU,EAAE;UACrB;QACF;;QAEA;QACA;QACA;QACAA,UAAU,CAAC2C,GAAG,CAAC,GAAG/F,IAAI;QACtB6F,KAAK,CAACnE,IAAI,CAACqE,GAAG,CAAC;MACjB,CAAC,CAAC;MAEF,MAAM;QAAEhD;MAAS,CAAC,GAAG,IAAI;MAEzB,MAAMnC,QAAQ,GAAG,IAAI,CAAC8B,UAAU,CAACsD,gBAAgB,CAACrF,EAAE,EAAE;QACpDA,EAAE,EAAEoC,QAAQ;QACZA,QAAQ;QACRkD,KAAK,EAAE,IAAI,CAACvD,UAAU,CAACwD,gBAAgB,CAAC1I,IAAI,CAAC+G,OAAO,CAACxB,QAAQ,CAAC;MAChE,CAAC,CAAC;MAEF,OAAO;QACLvB,MAAM,EAAEb,EAAE;QACVkB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXjB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACAiF,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAO3C,UAAU,CAAC2C,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","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,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;EAC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AS;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"}
@@ -26,7 +26,8 @@ export function loadWywOptions(overrides = defaultOverrides) {
26
26
  globalCache: true,
27
27
  happyDOM: true,
28
28
  softErrors: false,
29
- useBabelConfigs: true
29
+ useBabelConfigs: true,
30
+ useWeakRefInEval: true
30
31
  };
31
32
  const options = {
32
33
  displayName: false,
@@ -1 +1 @@
1
- {"version":3,"file":"loadWywOptions.js","names":["cosmiconfigSync","shaker","searchPlaces","explorerSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","options","displayName","evaluate","extensions","action","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport { shaker } from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAI7C,SAASC,MAAM,QAAQ,cAAc;AAGrC,MAAMC,YAAY,GAAG,CAClB,cAAa,EACb,mBAAkB,EAClB,mBAAkB,EAClB,k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MACEiB,MAAM,EAAE9B;IACV,CAAC,EACD;MACE;MACA+B,IAAI,EAAEnB,MAAM,IAAIN,iBAAiB;MACjCwB,MAAM,EAAE;IACV,CAAC,EACD;MACE;MACAC,IAAI,EAAEA,CAACC,QAAQ,EAAEC,IAAI,KAAK;QACxB,IAAI,CAAC3B,iBAAiB,CAACyB,IAAI,CAACC,QAAQ,CAAC,EAAE;UACrC,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDH,MAAM,EAAE9B;IACV,CAAC,CACF;IACDc,YAAY;IACZoB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,IAAIlB,MAAM,GAAGA,MAAM,CAACmB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGpB,IAAI;IACPqB,QAAQ,EAAE;MACR,GAAGhB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACmB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGrB,IAAI,CAACqB;IACV;EACF,CAAC;EAEDjC,KAAK,CAACkC,GAAG,CAAC7B,SAAS,EAAEkB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
1
+ {"version":3,"file":"loadWywOptions.js","names":["cosmiconfigSync","shaker","searchPlaces","explorerSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","useWeakRefInEval","options","displayName","evaluate","extensions","action","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport { shaker } from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n useWeakRefInEval: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAI7C,SAASC,MAAM,QAAQ,cAAc;AAGrC,MAAMC,YAAY,GAAG,CAClB,cAAa,EACb,mBAAkB,EAClB,mBAAkB,EAClB,kBAAiB,EACjB,iBAAgB,EAChB,kBAAiB,EACjB,qBAAoB,EACpB,0BAAyB,EACzB,0BAAyB,EACzB,yBAAwB,EACxB,wBAAuB,EACvB,yBAAwB,EACxB,qBAAoB,EACpB,sBAAqB,CACvB;AAED,MAAMC,YAAY,GAAGH,eAAe,CAAC,WAAW,EAAE;EAAEE;AAAa,CAAC,CAAC;AAMnE,MAAME,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAElD,OAAO,SAASC,cAAcA,CAC5BC,SAAyB,GAAGH,gBAAgB,EAC7B;EACf,IAAIF,KAAK,CAACM,GAAG,CAACD,SAAS,CAAC,EAAE;IACxB,OAAOL,KAAK,CAACO,GAAG,CAACF,SAAS,CAAC;EAC7B;EAEA,MAAM;IAAEG,UAAU;IAAEC,MAAM;IAAEC,KAAK;IAAEC,YAAY,GAAG,CAAC,CAAC;IAAE,GAAGC;EAAK,CAAC,GAAGP,SAAS;EAE3E,MAAMQ,MAAM;EACV;EACAL,UAAU,KAAK,KAAK,GAChBM,SAAS,GACTN,UAAU,KAAKM,SAAS,GACxBf,YAAY,CAACgB,IAAI,CAACP,UAAU,CAAC,GAC7BT,YAAY,CAACiB,MAAM,CAAC,CAAC;EAE3B,MAAMC,eAA6B,GAAG;IACpCC,oBAAoB,EAAE,IAAI;IAC1BC,WAAW,EAAE,IAAI;IACjBC,QAAQ,EAAE,IAAI;IACdC,UAAU,EAAE,KAAK;IACjBC,eAAe,EAAE,IAAI;IACrBC,gBAAgB,EAAE;EACpB,CAAC;EAED,MAAMC,OAAsB,GAAG;IAC7BC,WAAW,EAAE,KAAK;IAClBC,QAAQ,EAAE,IAAI;IACdC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;IAC1EjB,KAAK,EAAEA,KAAK,IAAI,CACd;MACEkB,MAAM,EAAE/B;IACV,CAAC,EACD;MACE;MACAgC,IAAI,EAAEpB,MAAM,IAAIN,iBAAiB;MACjCyB,MAAM,EAAE;IACV,CAAC,EACD;MACE;MACAC,IAAI,EAAEA,CAACC,QAAQ,EAAEC,IAAI,KAAK;QACxB,IAAI,CAAC5B,iBAAiB,CAAC0B,IAAI,CAACC,QAAQ,CAAC,EAAE;UACrC,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDH,MAAM,EAAE/B;IACV,CAAC,CACF;IACDc,YAAY;IACZqB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,IAAInB,MAAM,GAAGA,MAAM,CAACoB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGrB,IAAI;IACPsB,QAAQ,EAAE;MACR,GAAGjB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACoB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGtB,IAAI,CAACsB;IACV;EACF,CAAC;EAEDlC,KAAK,CAACmC,GAAG,CAAC9B,SAAS,EAAEmB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
package/lib/module.js CHANGED
@@ -9,6 +9,7 @@ var _module = _interopRequireDefault(require("module"));
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
  var _vm = _interopRequireDefault(require("vm"));
11
11
  var _tsInvariant = require("ts-invariant");
12
+ var _shared = require("@wyw-in-js/shared");
12
13
  require("./utils/dispose-polyfill");
13
14
  var _Entrypoint = require("./transform/Entrypoint");
14
15
  var _Entrypoint2 = require("./transform/Entrypoint.helpers");
@@ -127,7 +128,7 @@ class Module {
127
128
  this.services = services;
128
129
  this.moduleImpl = moduleImpl;
129
130
  this.cache = services.cache;
130
- this.#entrypointRef = new WeakRef(entrypoint);
131
+ this.#entrypointRef = (0, _shared.isFeatureEnabled)(services.options.pluginOptions.features, 'useWeakRefInEval', entrypoint.name) ? new WeakRef(entrypoint) : entrypoint;
131
132
  this.idx = entrypoint.idx;
132
133
  this.id = entrypoint.name;
133
134
  this.filename = entrypoint.name;
@@ -151,7 +152,7 @@ class Module {
151
152
  this.debug('the whole exports was overridden with %O', value);
152
153
  }
153
154
  get entrypoint() {
154
- const entrypoint = this.#entrypointRef.deref();
155
+ const entrypoint = this.#entrypointRef instanceof WeakRef ? this.#entrypointRef.deref() : this.#entrypointRef;
155
156
  (0, _tsInvariant.invariant)(entrypoint, `Module ${this.idx} is disposed`);
156
157
  return entrypoint;
157
158
  }
package/lib/module.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","names":["_fs","_interopRequireDefault","require","_module","_path","_vm","_tsInvariant","_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","WeakRef","idx","name","filename","log","extend","parentIsIgnored","ignored","extensions","options","pluginOptions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","createVmContext","features","__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 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>;\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 = new WeakRef(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 = this.#entrypointRef.deref();\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;AAIAA,OAAA;AAEA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAGA,IAAAO,2BAAA,GAAAP,OAAA;AAEA,IAAAQ,gBAAA,GAAAR,OAAA;AAAuD,SAAAD,uBAAAU,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;;AAErB;AACA;AACA,MAAMC,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;EACVC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,EAAE,EAAE,KAAK;EACTC,IAAI,EAA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QACVkB,IAAI,EAAE,CAAC,GAAG,CAAC;QACXjB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACAyF,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAOjD,UAAU,CAACiD,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAESrE,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","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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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"}
@@ -32,7 +32,8 @@ function loadWywOptions(overrides = defaultOverrides) {
32
32
  globalCache: true,
33
33
  happyDOM: true,
34
34
  softErrors: false,
35
- useBabelConfigs: true
35
+ useBabelConfigs: true,
36
+ useWeakRefInEval: true
36
37
  };
37
38
  const options = {
38
39
  displayName: false,
@@ -1 +1 @@
1
- {"version":3,"file":"loadWywOptions.js","names":["_cosmiconfig","require","_shaker","searchPlaces","explorerSync","cosmiconfigSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","options","displayName","evaluate","extensions","action","shaker","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport { shaker } from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":";;;;;;AAAA,IA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M,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;IAC1EhB,KAAK,EAAEA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CACd;MACEiB,MAAM,EAAEC;IACV,CAAC,EACD;MACE;MACAC,IAAI,EAAEpB,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIN,iBAAiB;MACjCwB,MAAM,EAAE;IACV,CAAC,EACD;MACE;MACAE,IAAI,EAAEA,CAACC,QAAQ,EAAEC,IAAI,KAAK;QACxB,IAAI,CAAC5B,iBAAiB,CAAC0B,IAAI,CAACC,QAAQ,CAAC,EAAE;UACrC,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDJ,MAAM,EAAEC;IACV,CAAC,CACF;IACDjB,YAAY;IACZqB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,IAAInB,MAAM,GAAGA,MAAM,CAACoB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGrB,IAAI;IACPsB,QAAQ,EAAE;MACR,GAAGjB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACoB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGtB,IAAI,CAACsB;IACV;EACF,CAAC;EAEDlC,KAAK,CAACmC,GAAG,CAAC9B,SAAS,EAAEkB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
1
+ {"version":3,"file":"loadWywOptions.js","names":["_cosmiconfig","require","_shaker","searchPlaces","explorerSync","cosmiconfigSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","useWeakRefInEval","options","displayName","evaluate","extensions","action","shaker","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport { shaker } from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n useWeakRefInEval: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,OAAA,GAAAD,OAAA;AAGA,MAAME,YAAY,GAAG,CAClB,cAAa,EACb,mBAAkB,EAClB,mBAAkB,EAClB,kBAAiB,EACjB,iBAAgB,EAChB,kBAAiB,EACjB,qBAAoB,EACpB,0BAAyB,EACzB,0BAAyB,EACzB,yBAAwB,EACxB,wBAAuB,EACvB,yBAAwB,EACxB,qBAAoB,EACpB,sBAAqB,CACvB;AAED,MAAMC,YAAY,GAAG,IAAAC,4BAAe,EAAC,WAAW,EAAE;EAAEF;AAAa,CAAC,CAAC;AAMnE,MAAMG,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAE3C,SAASC,cAAcA,CAC5BC,SAAyB,GAAGH,gBAAgB,EAC7B;EACf,IAAIF,KAAK,CAACM,GAAG,CAACD,SAAS,CAAC,EAAE;IACxB,OAAOL,KAAK,CAACO,GAAG,CAACF,SAAS,CAAC;EAC7B;EAEA,MAAM;IAAEG,UAAU;IAAEC,MAAM;IAAEC,KAAK;IAAEC,YAAY,GAAG,CAAC,CAAC;IAAE,GAAGC;EAAK,CAAC,GAAGP,SAAS;EAE3E,MAAMQ,MAAM;EACV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CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGvB,IAAI,CAACuB;IACV;EACF,CAAC;EAEDnC,KAAK,CAACoC,GAAG,CAAC/B,SAAS,EAAEmB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wyw-in-js/transform",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "dependencies": {
5
5
  "@babel/core": "^7.23.5",
6
6
  "@babel/generator": "^7.23.5",
@@ -15,8 +15,8 @@
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.5.0",
19
- "@wyw-in-js/shared": "0.5.0"
18
+ "@wyw-in-js/processor-utils": "0.5.1",
19
+ "@wyw-in-js/shared": "0.5.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.5.0",
41
- "@wyw-in-js/eslint-config": "0.5.0",
42
- "@wyw-in-js/jest-preset": "0.5.0",
43
- "@wyw-in-js/ts-config": "0.5.0"
40
+ "@wyw-in-js/babel-config": "0.5.1",
41
+ "@wyw-in-js/eslint-config": "0.5.1",
42
+ "@wyw-in-js/jest-preset": "0.5.1",
43
+ "@wyw-in-js/ts-config": "0.5.1"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=16.0.0"
package/types/module.d.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  /// <reference types="node" />
14
14
  /// <reference types="debug" />
15
15
  import NativeModule from 'module';
16
- import type { Debugger } from '@wyw-in-js/shared';
16
+ import { type Debugger } from '@wyw-in-js/shared';
17
17
  import './utils/dispose-polyfill';
18
18
  import { Entrypoint } from './transform/Entrypoint';
19
19
  import type { IEntrypointDependency } from './transform/Entrypoint.types';
package/types/module.js CHANGED
@@ -21,6 +21,7 @@ const module_1 = __importDefault(require("module"));
21
21
  const path_1 = __importDefault(require("path"));
22
22
  const vm_1 = __importDefault(require("vm"));
23
23
  const ts_invariant_1 = require("ts-invariant");
24
+ const shared_1 = require("@wyw-in-js/shared");
24
25
  require("./utils/dispose-polyfill");
25
26
  const Entrypoint_1 = require("./transform/Entrypoint");
26
27
  const Entrypoint_helpers_1 = require("./transform/Entrypoint.helpers");
@@ -132,7 +133,9 @@ class Module {
132
133
  this.services = services;
133
134
  this.moduleImpl = moduleImpl;
134
135
  this.cache = services.cache;
135
- this.#entrypointRef = new WeakRef(entrypoint);
136
+ this.#entrypointRef = (0, shared_1.isFeatureEnabled)(services.options.pluginOptions.features, 'useWeakRefInEval', entrypoint.name)
137
+ ? new WeakRef(entrypoint)
138
+ : entrypoint;
136
139
  this.idx = entrypoint.idx;
137
140
  this.id = entrypoint.name;
138
141
  this.filename = entrypoint.name;
@@ -157,7 +160,9 @@ class Module {
157
160
  this.debug('the whole exports was overridden with %O', value);
158
161
  }
159
162
  get entrypoint() {
160
- const entrypoint = this.#entrypointRef.deref();
163
+ const entrypoint = this.#entrypointRef instanceof WeakRef
164
+ ? this.#entrypointRef.deref()
165
+ : this.#entrypointRef;
161
166
  (0, ts_invariant_1.invariant)(entrypoint, `Module ${this.idx} is disposed`);
162
167
  return entrypoint;
163
168
  }
@@ -41,6 +41,7 @@ function loadWywOptions(overrides = defaultOverrides) {
41
41
  happyDOM: true,
42
42
  softErrors: false,
43
43
  useBabelConfigs: true,
44
+ useWeakRefInEval: true,
44
45
  };
45
46
  const options = {
46
47
  displayName: false,