@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0-alpha.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 +7 -0
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js +35 -1
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/eval/broker.js +230 -89
- package/esm/eval/broker.js.map +1 -1
- package/esm/eval/protocol.js.map +1 -1
- package/esm/eval/runner.js +143 -24
- package/esm/eval/runner.js.map +1 -1
- package/esm/module.js +70 -43
- package/esm/module.js.map +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +35 -20
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +48 -2
- package/esm/transform/generators/resolveImports.js.map +1 -1
- package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
- package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
- package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
- package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
- package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
- package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
- package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues.js +1 -2910
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
- package/esm/transform/generators/transform.js +57 -45
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +33 -4
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform.js +3 -1
- package/esm/transform.js.map +1 -1
- package/esm/utils/EventEmitter.js +42 -9
- package/esm/utils/EventEmitter.js.map +1 -1
- package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
- package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
- package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
- package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
- package/esm/utils/applyOxcProcessors/displayName.js +93 -0
- package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/shared.js +29 -0
- package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
- package/esm/utils/applyOxcProcessors/types.js +2 -0
- package/esm/utils/applyOxcProcessors/types.js.map +1 -0
- package/esm/utils/applyOxcProcessors.js +1 -1216
- package/esm/utils/applyOxcProcessors.js.map +1 -1
- package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
- package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
- package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
- package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
- package/esm/utils/collectOxcRuntime/types.js +2 -0
- package/esm/utils/collectOxcRuntime/types.js.map +1 -0
- package/esm/utils/collectOxcRuntime.js +5 -193
- package/esm/utils/collectOxcRuntime.js.map +1 -1
- package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
- package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
- package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
- package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
- package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies.js +3 -1397
- package/esm/utils/collectOxcTemplateDependencies.js.map +1 -1
- package/esm/utils/nativeResolver.js +93 -0
- package/esm/utils/nativeResolver.js.map +1 -0
- package/esm/utils/oxc/ast.js +28 -0
- package/esm/utils/oxc/ast.js.map +1 -0
- package/esm/utils/oxc/parse.js +3 -0
- package/esm/utils/oxc/parse.js.map +1 -0
- package/esm/utils/oxc/replacements.js +14 -0
- package/esm/utils/oxc/replacements.js.map +1 -0
- package/esm/utils/oxc/sourceLocations.js +59 -0
- package/esm/utils/oxc/sourceLocations.js.map +1 -0
- package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
- package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
- package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
- package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
- package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
- package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
- package/esm/utils/oxcPreevalStage/processors.js +17 -0
- package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
- package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
- package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
- package/esm/utils/oxcPreevalStage/types.js +2 -0
- package/esm/utils/oxcPreevalStage/types.js.map +1 -0
- package/esm/utils/oxcPreevalStage.js +17 -73
- package/esm/utils/oxcPreevalStage.js.map +1 -1
- package/esm/utils/oxcPreevalTransforms.js +12 -1
- package/esm/utils/oxcPreevalTransforms.js.map +1 -1
- package/esm/utils/processorStaticSemantics.js +157 -0
- package/esm/utils/processorStaticSemantics.js.map +1 -0
- package/esm/utils/resolveWithConditions.js +3 -3
- package/esm/utils/resolveWithConditions.js.map +1 -1
- package/package.json +4 -3
- package/types/cache.js +8 -0
- package/types/debug/fileReporter.js +46 -1
- package/types/eval/broker.d.ts +6 -2
- package/types/eval/broker.js +244 -95
- package/types/eval/protocol.d.ts +15 -1
- package/types/module.d.ts +4 -1
- package/types/module.js +97 -48
- package/types/transform/Entrypoint.types.d.ts +3 -0
- package/types/transform/generators/resolveImports.d.ts +3 -1
- package/types/transform/generators/resolveImports.js +49 -2
- package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
- package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
- package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
- package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
- package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
- package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
- package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
- package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
- package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
- package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
- package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
- package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
- package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
- package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
- package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
- package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
- package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
- package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
- package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
- package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
- package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
- package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -2
- package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
- package/types/transform/generators/transform.js +63 -49
- package/types/transform/helpers/loadWywOptions.js +23 -3
- package/types/transform.js +3 -1
- package/types/utils/EventEmitter.d.ts +16 -1
- package/types/utils/EventEmitter.js +44 -9
- package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
- package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
- package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
- package/types/utils/applyOxcProcessors/displayName.js +113 -0
- package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
- package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
- package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
- package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
- package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
- package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
- package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
- package/types/utils/applyOxcProcessors/shared.js +37 -0
- package/types/utils/applyOxcProcessors/types.d.ts +88 -0
- package/types/utils/applyOxcProcessors/types.js +1 -0
- package/types/utils/applyOxcProcessors.d.ts +1 -16
- package/types/utils/applyOxcProcessors.js +1 -1391
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
- package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
- package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
- package/types/utils/collectOxcRuntime/types.d.ts +16 -0
- package/types/utils/collectOxcRuntime/types.js +1 -0
- package/types/utils/collectOxcRuntime.d.ts +2 -12
- package/types/utils/collectOxcRuntime.js +5 -224
- package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
- package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
- package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
- package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
- package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
- package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
- package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
- package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
- package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
- package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
- package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
- package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
- package/types/utils/collectOxcTemplateDependencies.d.ts +4 -38
- package/types/utils/collectOxcTemplateDependencies.js +3 -1580
- package/types/utils/nativeResolver.d.ts +13 -0
- package/types/utils/nativeResolver.js +91 -0
- package/types/utils/oxc/ast.d.ts +4 -0
- package/types/utils/oxc/ast.js +37 -0
- package/types/utils/oxc/parse.d.ts +3 -0
- package/types/utils/oxc/parse.js +2 -0
- package/types/utils/oxc/replacements.d.ts +12 -0
- package/types/utils/oxc/replacements.js +18 -0
- package/types/utils/oxc/sourceLocations.d.ts +5 -0
- package/types/utils/oxc/sourceLocations.js +63 -0
- package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
- package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
- package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
- package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
- package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
- package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
- package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
- package/types/utils/oxcPreevalStage/processors.js +16 -0
- package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
- package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
- package/types/utils/oxcPreevalStage/types.d.ts +22 -0
- package/types/utils/oxcPreevalStage/types.js +1 -0
- package/types/utils/oxcPreevalStage.d.ts +2 -18
- package/types/utils/oxcPreevalStage.js +17 -79
- package/types/utils/oxcPreevalTransforms.js +14 -1
- package/types/utils/processorStaticSemantics.d.ts +13 -0
- package/types/utils/processorStaticSemantics.js +191 -0
- package/types/utils/resolveWithConditions.js +3 -3
- package/esm/eval/resolverStrategy.js +0 -51
- package/esm/eval/resolverStrategy.js.map +0 -1
- package/types/eval/resolverStrategy.d.ts +0 -13
- package/types/eval/resolverStrategy.js +0 -46
package/esm/eval/broker.js
CHANGED
|
@@ -11,8 +11,8 @@ import { isStaticallyEvaluatableModule } from "../transform/isStaticallyEvaluata
|
|
|
11
11
|
import { applyImportOverrideToOnly, getImportOverride, resolveMockSpecifier, toImportKey } from "../utils/importOverrides.js";
|
|
12
12
|
import { getFileIdx } from "../utils/getFileIdx.js";
|
|
13
13
|
import { collectOxcExportsAndImports } from "../utils/collectOxcExportsAndImports.js";
|
|
14
|
+
import { resolveWithNativeResolver } from "../utils/nativeResolver.js";
|
|
14
15
|
import { parseRequest, stripQueryAndHash } from "../utils/parseRequest.js";
|
|
15
|
-
import { resolveFilenameWithConditions } from "../utils/resolveWithConditions.js";
|
|
16
16
|
import { hasCachedWywPrevalExport } from "../utils/hasCachedWywPrevalExport.js";
|
|
17
17
|
import { isSuperSet, mergeOnly } from "../transform/Entrypoint.helpers.js";
|
|
18
18
|
import { oxcShaker } from "../shaker.js";
|
|
@@ -22,23 +22,6 @@ import { prepareModuleOnDemand } from "./prepareModuleOnDemand.js";
|
|
|
22
22
|
import { deserializeValue, encodeGlobals, serializeValue } from "./serialize.js";
|
|
23
23
|
import { createWriteQueue, writeToStream } from "./writeQueue.js";
|
|
24
24
|
const DefaultModuleImplementation = NativeModule;
|
|
25
|
-
const CJS_DEFAULT_CONDITIONS = [
|
|
26
|
-
"require",
|
|
27
|
-
"node",
|
|
28
|
-
"default"
|
|
29
|
-
];
|
|
30
|
-
const expandConditions = (conditionNames) => {
|
|
31
|
-
const result = new Set();
|
|
32
|
-
conditionNames.forEach((name) => {
|
|
33
|
-
if (name === "...") {
|
|
34
|
-
CJS_DEFAULT_CONDITIONS.forEach((condition) => result.add(condition));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
result.add(name);
|
|
38
|
-
});
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
const NOOP = () => {};
|
|
42
25
|
const isBuiltinSpecifier = (specifier) => {
|
|
43
26
|
const normalized = specifier.startsWith("node:") ? specifier.slice(5) : specifier;
|
|
44
27
|
return DefaultModuleImplementation.builtinModules?.includes(normalized) || DefaultModuleImplementation.builtinModules?.includes(`node:${normalized}`);
|
|
@@ -160,7 +143,7 @@ const getSerializableStaticImportKeys = (services, id, cachedEntrypoint, require
|
|
|
160
143
|
return requiredOnly.includes("*") ? evaluatedOnly : requiredOnly;
|
|
161
144
|
};
|
|
162
145
|
const DEFAULT_EVAL_OPTIONS = {
|
|
163
|
-
|
|
146
|
+
errors: "strict",
|
|
164
147
|
require: "warn-and-run",
|
|
165
148
|
resolver: "bundler"
|
|
166
149
|
};
|
|
@@ -203,6 +186,24 @@ const resolveDebugEvalDir = () => {
|
|
|
203
186
|
};
|
|
204
187
|
const debugEvalDir = resolveDebugEvalDir();
|
|
205
188
|
let debugEvalDirReady = false;
|
|
189
|
+
const toBase64 = (value) => Buffer.from(value, "utf8").toString("base64");
|
|
190
|
+
const toJsonBase64 = (value) => toBase64(JSON.stringify(value));
|
|
191
|
+
const serializedExportsToDebugValues = (serializedExports) => ({ exports: Object.fromEntries(Object.entries(serializedExports).map(([key, serialized]) => [key, {
|
|
192
|
+
serialized,
|
|
193
|
+
status: "serialized"
|
|
194
|
+
}])) });
|
|
195
|
+
const getDebugValuesStatus = (values) => {
|
|
196
|
+
const statuses = [...Object.values(values?.exports ?? {}), ...Object.values(values?.preval ?? {})].map((value) => value.status);
|
|
197
|
+
if (statuses.length === 0) {
|
|
198
|
+
return "none";
|
|
199
|
+
}
|
|
200
|
+
const hasSerialized = statuses.includes("serialized");
|
|
201
|
+
const hasStringified = statuses.includes("stringified");
|
|
202
|
+
if (hasSerialized && hasStringified) {
|
|
203
|
+
return "mixed";
|
|
204
|
+
}
|
|
205
|
+
return hasStringified ? "stringified" : "serialized";
|
|
206
|
+
};
|
|
206
207
|
const ensureDebugEvalDir = () => {
|
|
207
208
|
if (!debugEvalDir || debugEvalDirReady) {
|
|
208
209
|
return;
|
|
@@ -322,7 +323,7 @@ const buildRunnerInitPayload = (services, entrypoint, featuresOverride) => {
|
|
|
322
323
|
evalOptions: {
|
|
323
324
|
globals: encodeGlobalsCached(sanitizedGlobals),
|
|
324
325
|
importOverrides,
|
|
325
|
-
|
|
326
|
+
errors: evalOptions.errors ?? "strict",
|
|
326
327
|
require: evalOptions.require ?? "warn-and-run",
|
|
327
328
|
root,
|
|
328
329
|
extensions
|
|
@@ -657,7 +658,6 @@ const canonicalizeForHash = (value) => {
|
|
|
657
658
|
}
|
|
658
659
|
return value;
|
|
659
660
|
};
|
|
660
|
-
const getInitPayloadKey = (payload) => createHash("sha256").update(JSON.stringify(canonicalizeForHash(payload))).digest("hex");
|
|
661
661
|
// Hash everything in the init payload that affects whether the runner needs
|
|
662
662
|
// a fresh INIT — i.e. everything except `entrypoint` (which only affects
|
|
663
663
|
// __filename/__dirname rebinding, not context reuse). The broker memoizes
|
|
@@ -665,7 +665,8 @@ const getInitPayloadKey = (payload) => createHash("sha256").update(JSON.stringif
|
|
|
665
665
|
// with one SHA-256 of the stable bits + a cheap string concat per
|
|
666
666
|
// entrypoint.
|
|
667
667
|
const getStableInitPayloadHash = (payload) => {
|
|
668
|
-
const { entrypoint
|
|
668
|
+
const { entrypoint, ...stable } = payload;
|
|
669
|
+
void entrypoint;
|
|
669
670
|
return createHash("sha256").update(JSON.stringify(canonicalizeForHash(stable))).digest("hex");
|
|
670
671
|
};
|
|
671
672
|
// Memoize encodeGlobals on input reference. The user's globals object is
|
|
@@ -716,6 +717,12 @@ export class EvalBroker {
|
|
|
716
717
|
loadInFlight = new Map();
|
|
717
718
|
importsByModule = new Map();
|
|
718
719
|
onlyByModule = new Map();
|
|
720
|
+
// Modules that are part of the current eval session's link graph. Used
|
|
721
|
+
// to scope `mergeKnownDependencyOnly` to entrypoints that share the
|
|
722
|
+
// current runner's VM, instead of unioning across every cached
|
|
723
|
+
// entrypoint project-wide. Cleared whenever the runner is killed or
|
|
724
|
+
// respawned (mirrors lastSentLoadByModule).
|
|
725
|
+
sessionLinkGraph = new Set();
|
|
719
726
|
runtimeDependenciesByModule = new Map();
|
|
720
727
|
emittedDependencies = new Set();
|
|
721
728
|
// Mirrors the runner's view: for each module id, the (hash, mergedOnly) of
|
|
@@ -739,6 +746,7 @@ export class EvalBroker {
|
|
|
739
746
|
// re-canonicalizing+stringifying+SHA-256ing the whole payload per call.
|
|
740
747
|
stableInitHashCache = null;
|
|
741
748
|
evalSeq = 0;
|
|
749
|
+
evalFileDebugLines = null;
|
|
742
750
|
happyDomDisabled = false;
|
|
743
751
|
happyDomDisableWarned = false;
|
|
744
752
|
activeResolveRootId = null;
|
|
@@ -845,6 +853,7 @@ export class EvalBroker {
|
|
|
845
853
|
this.activeResolveRootId = resolveRootId;
|
|
846
854
|
this.resetPerEntrypointState(entrypoint);
|
|
847
855
|
this.evalSeq += 1;
|
|
856
|
+
this.evalFileDebugLines = activeServices.eventEmitter.enabled ? [] : null;
|
|
848
857
|
if (debugEvalDir) {
|
|
849
858
|
debugAction({
|
|
850
859
|
type: "eval:start",
|
|
@@ -856,6 +865,7 @@ export class EvalBroker {
|
|
|
856
865
|
try {
|
|
857
866
|
await this.initRunner(entrypoint);
|
|
858
867
|
const payload = await this.request("EVAL", { id: entrypoint.name }, EVAL_TIMEOUT_MS);
|
|
868
|
+
this.flushEvalFileDebugLines(payload.debugEvalFiles);
|
|
859
869
|
if (debugEvalDir) {
|
|
860
870
|
debugAction({
|
|
861
871
|
type: "eval:finish",
|
|
@@ -883,11 +893,62 @@ export class EvalBroker {
|
|
|
883
893
|
dependencies: this.collectEntrypointDependencies(entrypoint.name)
|
|
884
894
|
};
|
|
885
895
|
} finally {
|
|
896
|
+
this.evalFileDebugLines = null;
|
|
886
897
|
if (this.activeResolveRootId === resolveRootId) {
|
|
887
898
|
this.activeResolveRootId = null;
|
|
888
899
|
}
|
|
889
900
|
}
|
|
890
901
|
}
|
|
902
|
+
recordEvalFileDebugLine(payload, prepared, shouldShipCode) {
|
|
903
|
+
if (!this.evalFileDebugLines) {
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
if (shouldShipCode && prepared.code) {
|
|
907
|
+
this.evalFileDebugLines.push({
|
|
908
|
+
contentBase64: toBase64(prepared.code),
|
|
909
|
+
evalSeq: this.evalSeq,
|
|
910
|
+
hash: prepared.hash ?? null,
|
|
911
|
+
id: payload.id,
|
|
912
|
+
importer: payload.importerId ?? null,
|
|
913
|
+
only: prepared.only,
|
|
914
|
+
payloadKind: "code",
|
|
915
|
+
request: payload.request ?? null,
|
|
916
|
+
type: "eval-file",
|
|
917
|
+
valueStatus: "none",
|
|
918
|
+
valuesBase64: null
|
|
919
|
+
});
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
if (prepared.exports) {
|
|
923
|
+
const values = serializedExportsToDebugValues(prepared.exports);
|
|
924
|
+
this.evalFileDebugLines.push({
|
|
925
|
+
contentBase64: null,
|
|
926
|
+
evalSeq: this.evalSeq,
|
|
927
|
+
hash: prepared.hash ?? null,
|
|
928
|
+
id: payload.id,
|
|
929
|
+
importer: payload.importerId ?? null,
|
|
930
|
+
only: prepared.only,
|
|
931
|
+
payloadKind: "serialized-exports",
|
|
932
|
+
request: payload.request ?? null,
|
|
933
|
+
type: "eval-file",
|
|
934
|
+
valueStatus: getDebugValuesStatus(values),
|
|
935
|
+
valuesBase64: toJsonBase64(values)
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
flushEvalFileDebugLines(valuesById) {
|
|
940
|
+
const lines = this.evalFileDebugLines;
|
|
941
|
+
if (!lines) {
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
for (const line of lines) {
|
|
945
|
+
this.currentServices.eventEmitter.single({
|
|
946
|
+
...line,
|
|
947
|
+
valueStatus: line.valueStatus === "none" ? getDebugValuesStatus(valuesById?.[line.id]) : line.valueStatus,
|
|
948
|
+
valuesBase64: line.valuesBase64 ?? toJsonBase64(valuesById?.[line.id] ?? {})
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
}
|
|
891
952
|
resetPerEntrypointState(entrypoint) {
|
|
892
953
|
this.runtimeDependenciesByModule.clear();
|
|
893
954
|
this.emittedDependencies.clear();
|
|
@@ -895,6 +956,8 @@ export class EvalBroker {
|
|
|
895
956
|
this.onlyByModule.clear();
|
|
896
957
|
this.resolveCache.clear();
|
|
897
958
|
this.resolveInFlight.clear();
|
|
959
|
+
this.sessionLinkGraph.clear();
|
|
960
|
+
this.sessionLinkGraph.add(entrypoint.name);
|
|
898
961
|
this.onlyByModule.set(entrypoint.name, ["__wywPreval"]);
|
|
899
962
|
}
|
|
900
963
|
applyModuleExports(modules) {
|
|
@@ -934,6 +997,7 @@ export class EvalBroker {
|
|
|
934
997
|
this.lastInitKey = null;
|
|
935
998
|
this.lastHappyDomEnabled = false;
|
|
936
999
|
this.lastSentLoadByModule.clear();
|
|
1000
|
+
this.sessionLinkGraph.clear();
|
|
937
1001
|
this.stableInitHashCache = null;
|
|
938
1002
|
flushDebugStreams();
|
|
939
1003
|
}
|
|
@@ -973,6 +1037,7 @@ export class EvalBroker {
|
|
|
973
1037
|
this.lastInitKey = null;
|
|
974
1038
|
this.lastHappyDomEnabled = false;
|
|
975
1039
|
this.lastSentLoadByModule.clear();
|
|
1040
|
+
this.sessionLinkGraph.clear();
|
|
976
1041
|
});
|
|
977
1042
|
}
|
|
978
1043
|
async ensureRunner() {
|
|
@@ -1081,6 +1146,7 @@ export class EvalBroker {
|
|
|
1081
1146
|
// New process ⇒ runner's moduleCache/moduleHashes are empty, so our mirror
|
|
1082
1147
|
// of "what we already shipped" is stale.
|
|
1083
1148
|
this.lastSentLoadByModule.clear();
|
|
1149
|
+
this.sessionLinkGraph.clear();
|
|
1084
1150
|
}
|
|
1085
1151
|
getStableInitHash(services, features) {
|
|
1086
1152
|
const pluginOptionsRef = services.options.pluginOptions;
|
|
@@ -1108,13 +1174,18 @@ export class EvalBroker {
|
|
|
1108
1174
|
async initRunner(entrypoint) {
|
|
1109
1175
|
const features = this.getRunnerFeatures();
|
|
1110
1176
|
const stableHash = this.getStableInitHash(this.currentServices, features);
|
|
1111
|
-
const
|
|
1177
|
+
const debugEvalFiles = this.currentServices.eventEmitter.enabled;
|
|
1178
|
+
const debugEvalFilesKeyPart = debugEvalFiles ? "1" : "0";
|
|
1179
|
+
const initKey = `${stableHash}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
|
|
1112
1180
|
if (this.lastInitKey === initKey) {
|
|
1113
1181
|
return;
|
|
1114
1182
|
}
|
|
1115
1183
|
const nextHappyDomEnabled = isFeatureEnabled(features, "happyDOM", entrypoint.name);
|
|
1116
1184
|
const payload = buildRunnerInitPayload(this.services, entrypoint, features);
|
|
1117
1185
|
payload.reuseModules = true;
|
|
1186
|
+
if (debugEvalFiles) {
|
|
1187
|
+
payload.debugEvalFiles = true;
|
|
1188
|
+
}
|
|
1118
1189
|
const timeoutMs = this.getInitTimeoutMs(entrypoint, features);
|
|
1119
1190
|
if (this.runner && this.lastInitKey !== null && nextHappyDomEnabled && !this.lastHappyDomEnabled && !this.happyDomDisabled) {
|
|
1120
1191
|
try {
|
|
@@ -1130,8 +1201,11 @@ export class EvalBroker {
|
|
|
1130
1201
|
const fallbackFeatures = this.getRunnerFeatures();
|
|
1131
1202
|
const fallbackPayload = buildRunnerInitPayload(this.services, entrypoint, fallbackFeatures);
|
|
1132
1203
|
fallbackPayload.reuseModules = true;
|
|
1204
|
+
if (debugEvalFiles) {
|
|
1205
|
+
fallbackPayload.debugEvalFiles = true;
|
|
1206
|
+
}
|
|
1133
1207
|
await this.request("INIT", fallbackPayload, INIT_TIMEOUT_MS);
|
|
1134
|
-
this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}`;
|
|
1208
|
+
this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
|
|
1135
1209
|
this.lastHappyDomEnabled = false;
|
|
1136
1210
|
return;
|
|
1137
1211
|
}
|
|
@@ -1151,8 +1225,11 @@ export class EvalBroker {
|
|
|
1151
1225
|
const fallbackFeatures = this.getRunnerFeatures();
|
|
1152
1226
|
const fallbackPayload = buildRunnerInitPayload(this.services, entrypoint, fallbackFeatures);
|
|
1153
1227
|
fallbackPayload.reuseModules = true;
|
|
1228
|
+
if (debugEvalFiles) {
|
|
1229
|
+
fallbackPayload.debugEvalFiles = true;
|
|
1230
|
+
}
|
|
1154
1231
|
await this.request("INIT", fallbackPayload, INIT_TIMEOUT_MS);
|
|
1155
|
-
this.lastInitKey =
|
|
1232
|
+
this.lastInitKey = `${this.getStableInitHash(this.currentServices, fallbackFeatures)}::${entrypoint.name}::debugEvalFiles:${debugEvalFilesKeyPart}`;
|
|
1156
1233
|
this.lastHappyDomEnabled = false;
|
|
1157
1234
|
return;
|
|
1158
1235
|
}
|
|
@@ -1218,16 +1295,29 @@ export class EvalBroker {
|
|
|
1218
1295
|
// context rebuild or reuseModules:false). Drop our shipped-code
|
|
1219
1296
|
// mirror so handleLoad ships fresh code on the next LOAD.
|
|
1220
1297
|
this.lastSentLoadByModule.clear();
|
|
1298
|
+
this.sessionLinkGraph.clear();
|
|
1221
1299
|
}
|
|
1222
1300
|
this.resolvePending(message.id, {});
|
|
1223
1301
|
return;
|
|
1224
|
-
case "EVAL_RESULT":
|
|
1302
|
+
case "EVAL_RESULT": {
|
|
1303
|
+
// Runner reports any ids it dropped from its caches during this
|
|
1304
|
+
// session (e.g. modules whose link errored after a transient missing
|
|
1305
|
+
// import). Mirror those evictions here — otherwise lastSentLoadByModule
|
|
1306
|
+
// would keep claiming the runner has them and handleLoad would ship
|
|
1307
|
+
// empty `code` on the next session, leaving the runner stuck.
|
|
1308
|
+
const evictedIds = message.payload?.evictedIds;
|
|
1309
|
+
if (evictedIds && evictedIds.length > 0) {
|
|
1310
|
+
for (const evictedId of evictedIds) {
|
|
1311
|
+
this.lastSentLoadByModule.delete(evictedId);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1225
1314
|
if (message.error) {
|
|
1226
1315
|
this.rejectPending(message.id, message.error);
|
|
1227
1316
|
return;
|
|
1228
1317
|
}
|
|
1229
1318
|
this.resolvePending(message.id, message.payload);
|
|
1230
1319
|
return;
|
|
1320
|
+
}
|
|
1231
1321
|
case "RESOLVE":
|
|
1232
1322
|
this.handleResolve(message.id, message.payload).catch((error) => {
|
|
1233
1323
|
void this.sendMessage({
|
|
@@ -1301,7 +1391,7 @@ export class EvalBroker {
|
|
|
1301
1391
|
}
|
|
1302
1392
|
});
|
|
1303
1393
|
}
|
|
1304
|
-
normalizeResolvedId(resolvedId, specifier, importerId) {
|
|
1394
|
+
normalizeResolvedId(resolvedId, specifier, importerId, kind) {
|
|
1305
1395
|
const stripped = stripQueryAndHash(resolvedId);
|
|
1306
1396
|
if (!stripped) return resolvedId;
|
|
1307
1397
|
if (path.extname(stripped)) return resolvedId;
|
|
@@ -1331,15 +1421,29 @@ export class EvalBroker {
|
|
|
1331
1421
|
if (importerId) {
|
|
1332
1422
|
try {
|
|
1333
1423
|
const importerFile = stripQueryAndHash(importerId);
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1424
|
+
const { conditionNames, extensions, oxcOptions } = this.services.options.pluginOptions;
|
|
1425
|
+
const resolved = resolveWithNativeResolver({
|
|
1426
|
+
conditionNames,
|
|
1427
|
+
extensions,
|
|
1428
|
+
importer: importerFile,
|
|
1429
|
+
kind,
|
|
1430
|
+
oxcOptions,
|
|
1431
|
+
specifier: resolvedId
|
|
1338
1432
|
});
|
|
1339
1433
|
if (resolved && resolved !== stripped) {
|
|
1340
|
-
return
|
|
1434
|
+
return resolved;
|
|
1341
1435
|
}
|
|
1342
|
-
} catch {
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
|
|
1438
|
+
// eslint-disable-next-line no-console
|
|
1439
|
+
console.warn("[wyw-eval:resolve:native-normalize-miss]", {
|
|
1440
|
+
specifier,
|
|
1441
|
+
importerId,
|
|
1442
|
+
kind,
|
|
1443
|
+
error
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1343
1447
|
}
|
|
1344
1448
|
return resolvedId;
|
|
1345
1449
|
}
|
|
@@ -1380,7 +1484,7 @@ export class EvalBroker {
|
|
|
1380
1484
|
}
|
|
1381
1485
|
const strippedSpecifier = stripQueryAndHash(specifier);
|
|
1382
1486
|
if (path.isAbsolute(strippedSpecifier)) {
|
|
1383
|
-
const normalized = this.normalizeResolvedId(specifier, specifier, importerId);
|
|
1487
|
+
const normalized = this.normalizeResolvedId(specifier, specifier, importerId, kind);
|
|
1384
1488
|
const overridden = this.applyImportOverrides({
|
|
1385
1489
|
source: specifier,
|
|
1386
1490
|
resolved: normalized,
|
|
@@ -1401,15 +1505,15 @@ export class EvalBroker {
|
|
|
1401
1505
|
only: ["*"]
|
|
1402
1506
|
});
|
|
1403
1507
|
}
|
|
1404
|
-
const normalized = this.normalizeResolvedId(cached.resolvedId, specifier, importerId);
|
|
1508
|
+
const normalized = this.normalizeResolvedId(cached.resolvedId, specifier, importerId, kind);
|
|
1405
1509
|
const overridden = this.applyImportOverrides({
|
|
1406
1510
|
source: specifier,
|
|
1407
1511
|
resolved: normalized,
|
|
1408
1512
|
only,
|
|
1409
1513
|
external: cached.external
|
|
1410
1514
|
}, importerId, stack);
|
|
1411
|
-
if (cached.
|
|
1412
|
-
this.
|
|
1515
|
+
if (cached.usedNativeFallback) {
|
|
1516
|
+
this.maybeWarnNativeFallback({
|
|
1413
1517
|
importerId,
|
|
1414
1518
|
specifier,
|
|
1415
1519
|
resolvedId: normalized,
|
|
@@ -1427,15 +1531,15 @@ export class EvalBroker {
|
|
|
1427
1531
|
only: ["*"]
|
|
1428
1532
|
});
|
|
1429
1533
|
}
|
|
1430
|
-
const normalized = this.normalizeResolvedId(cachedResult.resolvedId, specifier, importerId);
|
|
1534
|
+
const normalized = this.normalizeResolvedId(cachedResult.resolvedId, specifier, importerId, kind);
|
|
1431
1535
|
const overridden = this.applyImportOverrides({
|
|
1432
1536
|
source: specifier,
|
|
1433
1537
|
resolved: normalized,
|
|
1434
1538
|
only,
|
|
1435
1539
|
external: cachedResult.external
|
|
1436
1540
|
}, importerId, stack);
|
|
1437
|
-
if (cachedResult.
|
|
1438
|
-
this.
|
|
1541
|
+
if (cachedResult.usedNativeFallback) {
|
|
1542
|
+
this.maybeWarnNativeFallback({
|
|
1439
1543
|
importerId,
|
|
1440
1544
|
specifier,
|
|
1441
1545
|
resolvedId: normalized,
|
|
@@ -1448,7 +1552,7 @@ export class EvalBroker {
|
|
|
1448
1552
|
if (evalOptions.customResolver) {
|
|
1449
1553
|
const customResolved = await evalOptions.customResolver(specifier, importerId, kind);
|
|
1450
1554
|
if (customResolved) {
|
|
1451
|
-
const normalized = this.normalizeResolvedId(customResolved.id, specifier, importerId);
|
|
1555
|
+
const normalized = this.normalizeResolvedId(customResolved.id, specifier, importerId, kind);
|
|
1452
1556
|
if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
|
|
1453
1557
|
// eslint-disable-next-line no-console
|
|
1454
1558
|
console.warn("[wyw-eval:resolve:custom]", {
|
|
@@ -1468,7 +1572,43 @@ export class EvalBroker {
|
|
|
1468
1572
|
return { resolvedId: null };
|
|
1469
1573
|
}
|
|
1470
1574
|
}
|
|
1471
|
-
if (evalOptions.resolver
|
|
1575
|
+
if (evalOptions.resolver === "hybrid") {
|
|
1576
|
+
try {
|
|
1577
|
+
const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
|
|
1578
|
+
if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
|
|
1579
|
+
// eslint-disable-next-line no-console
|
|
1580
|
+
console.warn("[wyw-eval:resolve:native]", {
|
|
1581
|
+
specifier,
|
|
1582
|
+
importerId,
|
|
1583
|
+
resolved: nativeResolved.resolvedId
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
return nativeResolved;
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
|
|
1589
|
+
// eslint-disable-next-line no-console
|
|
1590
|
+
console.warn("[wyw-eval:resolve:native-miss]", {
|
|
1591
|
+
specifier,
|
|
1592
|
+
importerId,
|
|
1593
|
+
kind,
|
|
1594
|
+
error
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
if (evalOptions.resolver === "native") {
|
|
1600
|
+
const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
|
|
1601
|
+
if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
|
|
1602
|
+
// eslint-disable-next-line no-console
|
|
1603
|
+
console.warn("[wyw-eval:resolve:native]", {
|
|
1604
|
+
specifier,
|
|
1605
|
+
importerId,
|
|
1606
|
+
resolved: nativeResolved.resolvedId
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
return nativeResolved;
|
|
1610
|
+
}
|
|
1611
|
+
if (evalOptions.resolver === "bundler" || evalOptions.resolver === "hybrid") {
|
|
1472
1612
|
let resolved = null;
|
|
1473
1613
|
try {
|
|
1474
1614
|
resolved = await this.asyncResolve(specifier, importerId, stack);
|
|
@@ -1476,7 +1616,7 @@ export class EvalBroker {
|
|
|
1476
1616
|
resolved = null;
|
|
1477
1617
|
}
|
|
1478
1618
|
if (resolved) {
|
|
1479
|
-
const normalized = this.normalizeResolvedId(resolved, specifier, importerId);
|
|
1619
|
+
const normalized = this.normalizeResolvedId(resolved, specifier, importerId, kind);
|
|
1480
1620
|
if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
|
|
1481
1621
|
// eslint-disable-next-line no-console
|
|
1482
1622
|
console.warn("[wyw-eval:resolve:async]", {
|
|
@@ -1489,19 +1629,19 @@ export class EvalBroker {
|
|
|
1489
1629
|
return { resolvedId: normalized };
|
|
1490
1630
|
}
|
|
1491
1631
|
}
|
|
1492
|
-
if (evalOptions.resolver === "
|
|
1493
|
-
const
|
|
1632
|
+
if (evalOptions.resolver === "bundler" && evalOptions.require !== "off") {
|
|
1633
|
+
const nativeResolved = this.resolveWithNativeFallback(specifier, importerId, kind);
|
|
1494
1634
|
if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
|
|
1495
1635
|
// eslint-disable-next-line no-console
|
|
1496
|
-
console.warn("[wyw-eval:resolve:
|
|
1636
|
+
console.warn("[wyw-eval:resolve:native-fallback]", {
|
|
1497
1637
|
specifier,
|
|
1498
1638
|
importerId,
|
|
1499
|
-
resolved:
|
|
1639
|
+
resolved: nativeResolved.resolvedId
|
|
1500
1640
|
});
|
|
1501
1641
|
}
|
|
1502
1642
|
return {
|
|
1503
|
-
...
|
|
1504
|
-
|
|
1643
|
+
...nativeResolved,
|
|
1644
|
+
usedNativeFallback: true
|
|
1505
1645
|
};
|
|
1506
1646
|
}
|
|
1507
1647
|
if (process.env.WYW_DEBUG_EVAL_RESOLVE) {
|
|
@@ -1529,8 +1669,8 @@ export class EvalBroker {
|
|
|
1529
1669
|
only,
|
|
1530
1670
|
external: result.external
|
|
1531
1671
|
}, importerId, stack);
|
|
1532
|
-
if (result.
|
|
1533
|
-
this.
|
|
1672
|
+
if (result.usedNativeFallback && result.resolvedId) {
|
|
1673
|
+
this.maybeWarnNativeFallback({
|
|
1534
1674
|
importerId,
|
|
1535
1675
|
specifier,
|
|
1536
1676
|
resolvedId: result.resolvedId,
|
|
@@ -1632,46 +1772,30 @@ export class EvalBroker {
|
|
|
1632
1772
|
only: nextOnly
|
|
1633
1773
|
};
|
|
1634
1774
|
}
|
|
1635
|
-
|
|
1636
|
-
const extensions =
|
|
1637
|
-
const added = [];
|
|
1638
|
-
const { conditionNames } = this.services.options.pluginOptions;
|
|
1639
|
-
const conditions = conditionNames?.length ? expandConditions(conditionNames) : undefined;
|
|
1775
|
+
resolveWithNativeFallback(specifier, importerId, kind) {
|
|
1776
|
+
const { conditionNames, extensions, oxcOptions } = this.services.options.pluginOptions;
|
|
1640
1777
|
try {
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
extensions
|
|
1644
|
-
|
|
1778
|
+
const resolved = resolveWithNativeResolver({
|
|
1779
|
+
conditionNames,
|
|
1780
|
+
extensions,
|
|
1781
|
+
importer: importerId,
|
|
1782
|
+
kind,
|
|
1783
|
+
oxcOptions,
|
|
1784
|
+
specifier
|
|
1645
1785
|
});
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
throw new Error([
|
|
1657
|
-
`[wyw-in-js] Node resolver failed during eval.`,
|
|
1658
|
-
``,
|
|
1659
|
-
`importer: ${filename}`,
|
|
1660
|
-
`source: ${specifier}`,
|
|
1661
|
-
``,
|
|
1662
|
-
`error: ${error instanceof Error ? error.message : String(error)}`
|
|
1663
|
-
].join("\n"));
|
|
1664
|
-
}
|
|
1665
|
-
const isFileSpecifier = strippedId.startsWith(".") || path.isAbsolute(strippedId);
|
|
1666
|
-
if (isFileSpecifier && path.extname(strippedId) === "" && resolved.endsWith(".cjs") && fs.existsSync(`${resolved.slice(0, -4)}.js`)) {
|
|
1667
|
-
resolved = `${resolved.slice(0, -4)}.js`;
|
|
1668
|
-
}
|
|
1669
|
-
return { resolvedId: this.normalizeResolvedId(resolved, specifier, importerId) };
|
|
1670
|
-
} finally {
|
|
1671
|
-
added.forEach((ext) => delete extensions[ext]);
|
|
1786
|
+
return { resolvedId: this.normalizeResolvedId(resolved, specifier, importerId, kind) };
|
|
1787
|
+
} catch (error) {
|
|
1788
|
+
throw new Error([
|
|
1789
|
+
`[wyw-in-js] Native resolver failed during eval.`,
|
|
1790
|
+
``,
|
|
1791
|
+
`importer: ${importerId}`,
|
|
1792
|
+
`source: ${specifier}`,
|
|
1793
|
+
``,
|
|
1794
|
+
`error: ${error instanceof Error ? error.message : String(error)}`
|
|
1795
|
+
].join("\n"));
|
|
1672
1796
|
}
|
|
1673
1797
|
}
|
|
1674
|
-
|
|
1798
|
+
maybeWarnNativeFallback({ importerId, specifier, resolvedId, kind }) {
|
|
1675
1799
|
const evalOptions = getEvalOptions(this.services);
|
|
1676
1800
|
const { root } = this.services.options;
|
|
1677
1801
|
const keyInfo = toImportKey({
|
|
@@ -1690,7 +1814,7 @@ export class EvalBroker {
|
|
|
1690
1814
|
}
|
|
1691
1815
|
if (policy === "error") {
|
|
1692
1816
|
throw new Error([
|
|
1693
|
-
`[wyw-in-js] Unknown import reached during eval (
|
|
1817
|
+
`[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
|
|
1694
1818
|
``,
|
|
1695
1819
|
`importer: ${importerId}`,
|
|
1696
1820
|
`source: ${specifier}`,
|
|
@@ -1704,7 +1828,7 @@ export class EvalBroker {
|
|
|
1704
1828
|
if (policy === "warn" && !warnedUnknownImports.has(keyInfo.key)) {
|
|
1705
1829
|
warnedUnknownImports.add(keyInfo.key);
|
|
1706
1830
|
const warningMessage = [
|
|
1707
|
-
`[wyw-in-js] Unknown import reached during eval (
|
|
1831
|
+
`[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
|
|
1708
1832
|
``,
|
|
1709
1833
|
`importer: ${importerId}`,
|
|
1710
1834
|
`source: ${specifier}`,
|
|
@@ -1759,6 +1883,7 @@ export class EvalBroker {
|
|
|
1759
1883
|
ts: performance.now()
|
|
1760
1884
|
});
|
|
1761
1885
|
}
|
|
1886
|
+
this.recordEvalFileDebugLine(payload, prepared, shouldShipCode);
|
|
1762
1887
|
await this.sendLoadResult(id, {
|
|
1763
1888
|
id: payload.id,
|
|
1764
1889
|
code: shouldShipCode ? prepared.code : "",
|
|
@@ -1774,6 +1899,14 @@ export class EvalBroker {
|
|
|
1774
1899
|
only: merged
|
|
1775
1900
|
});
|
|
1776
1901
|
}
|
|
1902
|
+
// Session link graph tracks every module that's been admitted into
|
|
1903
|
+
// the current runner's VM. mergeKnownDependencyOnly uses this to
|
|
1904
|
+
// narrow its consumer-set to entrypoints actually linking against
|
|
1905
|
+
// the same module instance.
|
|
1906
|
+
this.sessionLinkGraph.add(payload.id);
|
|
1907
|
+
if (payload.importerId) {
|
|
1908
|
+
this.sessionLinkGraph.add(payload.importerId);
|
|
1909
|
+
}
|
|
1777
1910
|
}
|
|
1778
1911
|
async loadModule({ id, importerId, request }) {
|
|
1779
1912
|
const actionEntrypoint = importerId ?? id;
|
|
@@ -2092,6 +2225,14 @@ export class EvalBroker {
|
|
|
2092
2225
|
}
|
|
2093
2226
|
let mergedOnly = storedOnly;
|
|
2094
2227
|
for (const cachedEntrypoint of this.services.cache.entrypoints.values()) {
|
|
2228
|
+
// Scope the union to entrypoints that are part of the CURRENT
|
|
2229
|
+
// session's link graph. Cached entrypoints from prior transforms
|
|
2230
|
+
// already evaluated against their own VMs; their imports must not
|
|
2231
|
+
// widen this load. Empty session graph (initial load) falls back
|
|
2232
|
+
// to project-wide for safety.
|
|
2233
|
+
if (this.sessionLinkGraph.size > 0 && !this.sessionLinkGraph.has(cachedEntrypoint.name)) {
|
|
2234
|
+
continue;
|
|
2235
|
+
}
|
|
2095
2236
|
const { dependencies } = cachedEntrypoint;
|
|
2096
2237
|
if (!dependencies) {
|
|
2097
2238
|
continue;
|