@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/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"","names":[],"sources":["../../src/eval/protocol.ts"],"version":3,"sourcesContent":["import type {\n EvalResolverKind,\n EvalWarning,\n FeatureFlags,\n ImportOverrides,\n} from '@wyw-in-js/shared';\n\nimport type { SerializedError, SerializedValue } from './serialize';\n\nexport type EvalRunnerInitPayload = {\n evalOptions: {\n
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../src/eval/protocol.ts"],"version":3,"sourcesContent":["import type {\n EvalResolverKind,\n EvalWarning,\n FeatureFlags,\n ImportOverrides,\n} from '@wyw-in-js/shared';\n\nimport type { SerializedError, SerializedValue } from './serialize';\n\nexport type EvalRunnerInitPayload = {\n evalOptions: {\n errors: 'strict' | 'loose';\n require: 'warn-and-run' | 'error' | 'off';\n globals: Record<string, unknown>;\n importOverrides?: ImportOverrides;\n root?: string;\n extensions?: string[];\n };\n features: FeatureFlags<'happyDOM'>;\n debugEvalFiles?: boolean;\n entrypoint: string;\n reuseModules?: boolean;\n};\n\nexport type EvalRequest = {\n id: string;\n};\n\nexport type EvalResultPayload = {\n values: Record<string, SerializedValue> | null;\n modules?: Record<string, Record<string, SerializedValue>>;\n debugEvalFiles?: Record<string, DebugEvalFileValues>;\n};\n\nexport type DebugEvalFileValue =\n | {\n serialized: SerializedValue;\n status: 'serialized';\n }\n | {\n reason: string;\n status: 'stringified';\n stringified: string;\n };\n\nexport type DebugEvalFileValues = {\n exports?: Record<string, DebugEvalFileValue>;\n preval?: Record<string, DebugEvalFileValue>;\n};\n\nexport type ResolveRequestPayload = {\n specifier: string;\n importerId: string;\n kind: EvalResolverKind;\n};\n\nexport type ResolveResultPayload = {\n resolvedId: string | null;\n external?: boolean;\n error?: SerializedError;\n};\n\nexport type LoadRequestPayload = {\n id: string;\n importerId?: string | null;\n request?: string | null;\n};\n\nexport type LoadResultPayload = {\n id: string;\n code?: string;\n codeChunk?: string;\n chunkIndex?: number;\n chunkCount?: number;\n map?: unknown;\n hash?: string;\n only?: string[];\n exports?: Record<string, SerializedValue>;\n error?: SerializedError;\n};\n\nexport type InitMessage = {\n type: 'INIT';\n id: string;\n payload: EvalRunnerInitPayload;\n};\n\nexport type InitAckMessage = {\n type: 'INIT_ACK';\n id: string;\n error?: SerializedError;\n // Set by the runner when it just reset its moduleCache during INIT (full\n // reset on context rebuild, or `reuseModules: false`). The broker uses\n // this to invalidate its \"what runner has\" mirror without doing any\n // payload hashing or stringification on its own hot path.\n modulesReset?: boolean;\n};\n\nexport type EvalMessage = {\n type: 'EVAL';\n id: string;\n payload: EvalRequest;\n};\n\nexport type EvalResultMessage = {\n type: 'EVAL_RESULT';\n id: string;\n payload: EvalResultPayload;\n error?: SerializedError;\n};\n\nexport type ResolveMessage = {\n type: 'RESOLVE';\n id: string;\n payload: ResolveRequestPayload;\n};\n\nexport type ResolveResultMessage = {\n type: 'RESOLVE_RESULT';\n id: string;\n payload: ResolveResultPayload;\n};\n\nexport type LoadMessage = {\n type: 'LOAD';\n id: string;\n payload: LoadRequestPayload;\n};\n\nexport type LoadResultMessage = {\n type: 'LOAD_RESULT';\n id: string;\n payload: LoadResultPayload;\n};\n\nexport type WarnMessage = {\n type: 'WARN';\n payload: EvalWarning;\n};\n\nexport type RunnerToMainMessage =\n | ResolveMessage\n | LoadMessage\n | WarnMessage\n | InitAckMessage\n | EvalResultMessage;\n\nexport type MainToRunnerMessage =\n | InitMessage\n | EvalMessage\n | ResolveResultMessage\n | LoadResultMessage;\n"],"file":"protocol.js"}
|
package/esm/eval/runner.js
CHANGED
|
@@ -706,7 +706,7 @@ const state = {
|
|
|
706
706
|
happyDomEnabled: null,
|
|
707
707
|
globalsSignature: null,
|
|
708
708
|
evalOptions: {
|
|
709
|
-
|
|
709
|
+
errors: "strict",
|
|
710
710
|
require: "warn-and-run",
|
|
711
711
|
globals: {},
|
|
712
712
|
importOverrides: undefined,
|
|
@@ -714,6 +714,7 @@ const state = {
|
|
|
714
714
|
extensions: []
|
|
715
715
|
},
|
|
716
716
|
features: {},
|
|
717
|
+
debugEvalFiles: false,
|
|
717
718
|
entrypoint: "eval-runner"
|
|
718
719
|
};
|
|
719
720
|
const moduleCache = new LruCache(LOAD_CACHE_SIZE);
|
|
@@ -729,12 +730,23 @@ const resolveCache = new LruCache(RESOLVE_CACHE_SIZE);
|
|
|
729
730
|
const resolveInFlight = new Map();
|
|
730
731
|
const pending = new Map();
|
|
731
732
|
const loadResultChunks = new Map();
|
|
733
|
+
// Ids evicted during the in-flight EVAL session via resetSingleModuleState.
|
|
734
|
+
// Surfaced in EVAL_RESULT so the broker can drop matching entries from its
|
|
735
|
+
// "what runner has" mirror (lastSentLoadByModule) — otherwise the broker would
|
|
736
|
+
// keep short-circuiting subsequent LOADs with empty `code` and the runner
|
|
737
|
+
// would have no way to obtain fresh source.
|
|
738
|
+
const evictedThisSession = new Set();
|
|
732
739
|
let nextId = 0;
|
|
733
740
|
const stdoutWriteQueue = [];
|
|
734
741
|
let stdoutWriteInFlight = false;
|
|
735
742
|
let stdoutWriteFailed = null;
|
|
736
743
|
let shutdownRequested = false;
|
|
737
744
|
let shutdownFinished = false;
|
|
745
|
+
// Tracks the SourceTextModule identifier (versioned with hash) that was last
|
|
746
|
+
// included in an EVAL_RESULT for each id. Reused module variants don't need
|
|
747
|
+
// re-serialization across eval sessions — same variant = same namespace =
|
|
748
|
+
// same exports the broker already has cached.
|
|
749
|
+
const sentNamespaceIdentifiers = new Map();
|
|
738
750
|
const resetModuleState = () => {
|
|
739
751
|
moduleCache.clear();
|
|
740
752
|
moduleHashes.clear();
|
|
@@ -749,11 +761,6 @@ const resetModuleState = () => {
|
|
|
749
761
|
resolveCache.clear();
|
|
750
762
|
sentNamespaceIdentifiers.clear();
|
|
751
763
|
};
|
|
752
|
-
// Tracks the SourceTextModule identifier (versioned with hash) that was last
|
|
753
|
-
// included in an EVAL_RESULT for each id. Reused module variants don't need
|
|
754
|
-
// re-serialization across eval sessions — same variant = same namespace =
|
|
755
|
-
// same exports the broker already has cached.
|
|
756
|
-
const sentNamespaceIdentifiers = new Map();
|
|
757
764
|
const resetSingleModuleState = (id, cachedModule = moduleCache.get(id)) => {
|
|
758
765
|
if (cachedModule) {
|
|
759
766
|
linkPromises.delete(cachedModule);
|
|
@@ -767,6 +774,16 @@ const resetSingleModuleState = (id, cachedModule = moduleCache.get(id)) => {
|
|
|
767
774
|
moduleData.delete(id);
|
|
768
775
|
moduleVariants.delete(id);
|
|
769
776
|
moduleLastVariant.delete(id);
|
|
777
|
+
sentNamespaceIdentifiers.delete(id);
|
|
778
|
+
};
|
|
779
|
+
// Stronger reset for error paths: clears moduleOnly too and records the id so
|
|
780
|
+
// the broker can drop its lastSentLoadByModule entry. Used when a module's
|
|
781
|
+
// SourceTextModule has reached an unrecoverable state (e.g. link errored
|
|
782
|
+
// against a transient missing import) and should not be reused.
|
|
783
|
+
const evictPoisonedModule = (id) => {
|
|
784
|
+
resetSingleModuleState(id);
|
|
785
|
+
moduleOnly.delete(id);
|
|
786
|
+
evictedThisSession.add(id);
|
|
770
787
|
};
|
|
771
788
|
const isFullModuleLoad = (loaded) => !loaded.only || loaded.only.length === 1 && loaded.only[0] === "*";
|
|
772
789
|
const getModuleVariant = (id, hash) => moduleVariants.get(id)?.get(hash);
|
|
@@ -924,6 +941,22 @@ const sendWarn = (warning) => {
|
|
|
924
941
|
payload: warning
|
|
925
942
|
});
|
|
926
943
|
};
|
|
944
|
+
const reviveSerializedError = (error) => {
|
|
945
|
+
if (error instanceof Error) {
|
|
946
|
+
return error;
|
|
947
|
+
}
|
|
948
|
+
const revived = new Error(error?.message ?? String(error));
|
|
949
|
+
if (error?.name) {
|
|
950
|
+
revived.name = error.name;
|
|
951
|
+
}
|
|
952
|
+
if (error?.stack) {
|
|
953
|
+
revived.stack = error.stack;
|
|
954
|
+
}
|
|
955
|
+
if (error?.cause) {
|
|
956
|
+
revived.cause = reviveSerializedError(error.cause);
|
|
957
|
+
}
|
|
958
|
+
return revived;
|
|
959
|
+
};
|
|
927
960
|
const serializeError = (error) => {
|
|
928
961
|
const result = {
|
|
929
962
|
message: error?.message ?? String(error),
|
|
@@ -1022,12 +1055,12 @@ const createRequireFn = (importer) => {
|
|
|
1022
1055
|
throw new Error(`[wyw-in-js] require() fallback is disabled by eval.require: 'off'.`);
|
|
1023
1056
|
}
|
|
1024
1057
|
if (nonLiteral || typeof specifier !== "string") {
|
|
1025
|
-
if (state.evalOptions.
|
|
1058
|
+
if (state.evalOptions.errors === "strict") {
|
|
1026
1059
|
throw new Error(`[wyw-in-js] Non-literal require() is not supported during eval.\n` + `importer: ${importerFile}\n` + `hint: make it a string literal or mock the import via importOverrides.`);
|
|
1027
1060
|
}
|
|
1028
1061
|
sendWarn({
|
|
1029
1062
|
code: "require-error",
|
|
1030
|
-
message: "[wyw-in-js] Non-literal require() reached during eval (loose
|
|
1063
|
+
message: "[wyw-in-js] Non-literal require() reached during eval (eval.errors: \"loose\").",
|
|
1031
1064
|
importer: importerFile
|
|
1032
1065
|
});
|
|
1033
1066
|
return {};
|
|
@@ -1225,6 +1258,16 @@ const linkModule = async (module) => {
|
|
|
1225
1258
|
await module.link((specifier, referencingModule) => resolveModule(specifier, referencingModule.identifier, "import"));
|
|
1226
1259
|
return module;
|
|
1227
1260
|
} catch (error) {
|
|
1261
|
+
// The vm SourceTextModule is now in 'errored' (or partially-linked)
|
|
1262
|
+
// state and can never be re-linked. With reuseModules:true the cached
|
|
1263
|
+
// module would otherwise stick around and short-circuit linkModule's
|
|
1264
|
+
// status guard above on the next session — surfacing the original
|
|
1265
|
+
// failure forever even after the user fixes the underlying problem.
|
|
1266
|
+
// Drop it so the next LOAD rebuilds a fresh SourceTextModule.
|
|
1267
|
+
const identifier = typeof module.identifier === "string" ? module.identifier : null;
|
|
1268
|
+
if (identifier) {
|
|
1269
|
+
evictPoisonedModule(toSourceModuleId(identifier));
|
|
1270
|
+
}
|
|
1228
1271
|
// ERR_VM_MODULE_LINK_FAILURE means a dependency is in "errored" state.
|
|
1229
1272
|
// Node chains .cause through the link failure hierarchy. Walk to the
|
|
1230
1273
|
// deepest cause to surface the original evaluation error (e.g. a
|
|
@@ -1267,7 +1310,7 @@ resolveModule = async (specifier, importer, kind) => {
|
|
|
1267
1310
|
const cached = resolveCache.get(key);
|
|
1268
1311
|
if (cached) {
|
|
1269
1312
|
if (!cached.resolvedId) {
|
|
1270
|
-
if (state.evalOptions.
|
|
1313
|
+
if (state.evalOptions.errors === "loose") {
|
|
1271
1314
|
return createSyntheticModule(specifier, { default: undefined });
|
|
1272
1315
|
}
|
|
1273
1316
|
throw new Error([
|
|
@@ -1312,7 +1355,7 @@ resolveModule = async (specifier, importer, kind) => {
|
|
|
1312
1355
|
external: Boolean(resolved.external)
|
|
1313
1356
|
});
|
|
1314
1357
|
if (!normalized) {
|
|
1315
|
-
if (state.evalOptions.
|
|
1358
|
+
if (state.evalOptions.errors === "loose") {
|
|
1316
1359
|
return createSyntheticModule(specifier, { default: undefined });
|
|
1317
1360
|
}
|
|
1318
1361
|
throw new Error([
|
|
@@ -1355,7 +1398,29 @@ loadModule = async (id, importer, requestSpec) => {
|
|
|
1355
1398
|
durationMs: Date.now() - loadStart
|
|
1356
1399
|
});
|
|
1357
1400
|
if (loaded.error) {
|
|
1358
|
-
|
|
1401
|
+
// Surface the importer + specifier alongside the broker's message.
|
|
1402
|
+
// Without this, ENOENT and similar load failures bubble up as a bare
|
|
1403
|
+
// path (or, after Node's VM wraps them, as the opaque
|
|
1404
|
+
// ERR_VM_MODULE_STATUS) leaving no clue which file's import is broken.
|
|
1405
|
+
const detail = [
|
|
1406
|
+
`[wyw-in-js] Failed to load module during evaluation.`,
|
|
1407
|
+
` importer: ${importer ?? "(unknown)"}`,
|
|
1408
|
+
` request: ${requestSpec ?? id}`,
|
|
1409
|
+
` resolved: ${id}`,
|
|
1410
|
+
` cause: ${loaded.error.message}`
|
|
1411
|
+
].join("\n");
|
|
1412
|
+
// The importer's SourceTextModule (if it was already created and
|
|
1413
|
+
// cached) compiled this `import` against `id`; reusing it next session
|
|
1414
|
+
// would link against the same id and either re-trigger the failure or
|
|
1415
|
+
// skip linking via the status guard. Drop both so the next session
|
|
1416
|
+
// pulls fresh code for both ends of the broken edge.
|
|
1417
|
+
if (importer && importer !== id) {
|
|
1418
|
+
evictPoisonedModule(toSourceModuleId(importer));
|
|
1419
|
+
}
|
|
1420
|
+
evictPoisonedModule(id);
|
|
1421
|
+
const enhanced = new Error(detail);
|
|
1422
|
+
enhanced.cause = reviveSerializedError(loaded.error);
|
|
1423
|
+
throw enhanced;
|
|
1359
1424
|
}
|
|
1360
1425
|
if (loaded.only) {
|
|
1361
1426
|
const current = moduleOnly.get(id) ?? [];
|
|
@@ -1379,12 +1444,7 @@ loadModule = async (id, importer, requestSpec) => {
|
|
|
1379
1444
|
if (!evaluated) {
|
|
1380
1445
|
const variants = moduleVariants.get(id);
|
|
1381
1446
|
if (variants) {
|
|
1382
|
-
|
|
1383
|
-
if (variant.status === "evaluated" && coversKeys(variant)) {
|
|
1384
|
-
evaluated = variant;
|
|
1385
|
-
break;
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1447
|
+
evaluated = Array.from(variants.values()).find((variant) => variant.status === "evaluated" && coversKeys(variant));
|
|
1388
1448
|
}
|
|
1389
1449
|
}
|
|
1390
1450
|
if (evaluated) {
|
|
@@ -1467,7 +1527,7 @@ const createDynamicImportFn = (importer) => {
|
|
|
1467
1527
|
message: "[wyw-in-js] Dynamic import with non-string specifier during eval.",
|
|
1468
1528
|
importer
|
|
1469
1529
|
});
|
|
1470
|
-
if (state.evalOptions.
|
|
1530
|
+
if (state.evalOptions.errors === "strict") {
|
|
1471
1531
|
throw new Error(`[wyw-in-js] Dynamic import with non-string specifier is not supported during eval.\n` + `importer: ${importer}\n` + `hint: make it a string literal or mock the import via importOverrides.`);
|
|
1472
1532
|
}
|
|
1473
1533
|
return createSyntheticModule(`dynamic:${String(specifier)}`, { default: undefined });
|
|
@@ -1518,8 +1578,21 @@ const resolveExportValue = (source, key) => {
|
|
|
1518
1578
|
}
|
|
1519
1579
|
return undefined;
|
|
1520
1580
|
};
|
|
1581
|
+
const stringifyDebugValue = (value) => {
|
|
1582
|
+
try {
|
|
1583
|
+
const json = JSON.stringify(value);
|
|
1584
|
+
if (json !== undefined) return json;
|
|
1585
|
+
} catch {}
|
|
1586
|
+
try {
|
|
1587
|
+
return String(value);
|
|
1588
|
+
} catch {
|
|
1589
|
+
return Object.prototype.toString.call(value);
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
const serializeDebugReason = (error) => error instanceof Error ? error.message : String(error);
|
|
1521
1593
|
const collectModuleExports = () => {
|
|
1522
1594
|
const exportsByModule = {};
|
|
1595
|
+
const debugEvalFiles = state.debugEvalFiles ? {} : undefined;
|
|
1523
1596
|
moduleOnly.forEach((only, id) => {
|
|
1524
1597
|
if (!only || only.length === 0) return;
|
|
1525
1598
|
const module = moduleCache.get(id) ?? moduleLastVariant.get(id);
|
|
@@ -1551,6 +1624,7 @@ const collectModuleExports = () => {
|
|
|
1551
1624
|
const keys = Array.from(new Set([...requestedKeys, ...discoveredKeys]));
|
|
1552
1625
|
if (keys.length === 0) return;
|
|
1553
1626
|
const serialized = {};
|
|
1627
|
+
const debugExports = state.debugEvalFiles ? {} : undefined;
|
|
1554
1628
|
keys.forEach((key) => {
|
|
1555
1629
|
const value = resolveExportValue(source, key);
|
|
1556
1630
|
try {
|
|
@@ -1558,14 +1632,34 @@ const collectModuleExports = () => {
|
|
|
1558
1632
|
rootLabel: "module exports",
|
|
1559
1633
|
path: [id, key]
|
|
1560
1634
|
});
|
|
1561
|
-
|
|
1635
|
+
if (debugExports) {
|
|
1636
|
+
debugExports[key] = {
|
|
1637
|
+
serialized: serialized[key],
|
|
1638
|
+
status: "serialized"
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
} catch (error) {
|
|
1642
|
+
if (debugExports) {
|
|
1643
|
+
debugExports[key] = {
|
|
1644
|
+
reason: serializeDebugReason(error),
|
|
1645
|
+
status: "stringified",
|
|
1646
|
+
stringified: stringifyDebugValue(value)
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1562
1650
|
});
|
|
1651
|
+
if (debugEvalFiles && debugExports && Object.keys(debugExports).length) {
|
|
1652
|
+
debugEvalFiles[id] = { exports: debugExports };
|
|
1653
|
+
}
|
|
1563
1654
|
if (Object.keys(serialized).length) {
|
|
1564
1655
|
exportsByModule[id] = serialized;
|
|
1565
1656
|
sentNamespaceIdentifiers.set(id, moduleIdentifier);
|
|
1566
1657
|
}
|
|
1567
1658
|
});
|
|
1568
|
-
return
|
|
1659
|
+
return {
|
|
1660
|
+
debugEvalFiles,
|
|
1661
|
+
modules: exportsByModule
|
|
1662
|
+
};
|
|
1569
1663
|
};
|
|
1570
1664
|
async function evaluateEntrypoint(id) {
|
|
1571
1665
|
const evalStart = Date.now();
|
|
@@ -1590,9 +1684,10 @@ async function evaluateEntrypoint(id) {
|
|
|
1590
1684
|
const hasPrevalExport = exportsValue && typeof exportsValue === "object" && "__wywPreval" in exportsValue;
|
|
1591
1685
|
const { namespace } = module;
|
|
1592
1686
|
const hasPrevalNamespace = namespace && typeof namespace === "object" && "__wywPreval" in namespace;
|
|
1593
|
-
const modules = collectModuleExports();
|
|
1687
|
+
const { debugEvalFiles, modules } = collectModuleExports();
|
|
1594
1688
|
if (!hasPrevalExport && !hasPrevalNamespace) {
|
|
1595
1689
|
return {
|
|
1690
|
+
debugEvalFiles,
|
|
1596
1691
|
values: null,
|
|
1597
1692
|
modules
|
|
1598
1693
|
};
|
|
@@ -1600,11 +1695,13 @@ async function evaluateEntrypoint(id) {
|
|
|
1600
1695
|
const preval = hasPrevalExport ? exportsValue.__wywPreval : namespace.__wywPreval;
|
|
1601
1696
|
if (!preval || typeof preval !== "object") {
|
|
1602
1697
|
return {
|
|
1698
|
+
debugEvalFiles,
|
|
1603
1699
|
values: null,
|
|
1604
1700
|
modules
|
|
1605
1701
|
};
|
|
1606
1702
|
}
|
|
1607
1703
|
const values = {};
|
|
1704
|
+
const debugPreval = state.debugEvalFiles ? {} : undefined;
|
|
1608
1705
|
Object.entries(preval).forEach(([key, lazy]) => {
|
|
1609
1706
|
let value;
|
|
1610
1707
|
try {
|
|
@@ -1618,8 +1715,21 @@ async function evaluateEntrypoint(id) {
|
|
|
1618
1715
|
rootLabel: "__wywPreval",
|
|
1619
1716
|
path: [key]
|
|
1620
1717
|
});
|
|
1718
|
+
if (debugPreval) {
|
|
1719
|
+
debugPreval[key] = {
|
|
1720
|
+
serialized: values[key],
|
|
1721
|
+
status: "serialized"
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1621
1724
|
});
|
|
1725
|
+
if (debugEvalFiles && debugPreval && Object.keys(debugPreval).length) {
|
|
1726
|
+
debugEvalFiles[id] = {
|
|
1727
|
+
...debugEvalFiles[id] ?? {},
|
|
1728
|
+
preval: debugPreval
|
|
1729
|
+
};
|
|
1730
|
+
}
|
|
1622
1731
|
return {
|
|
1732
|
+
debugEvalFiles,
|
|
1623
1733
|
values,
|
|
1624
1734
|
modules
|
|
1625
1735
|
};
|
|
@@ -1633,6 +1743,7 @@ const handleMessage = async (message) => {
|
|
|
1633
1743
|
const encodedGlobals = message.payload.evalOptions.globals ?? {};
|
|
1634
1744
|
const nextGlobalsSignature = JSON.stringify(canonicalizeForSignature(encodedGlobals));
|
|
1635
1745
|
const nextFeatures = message.payload.features ?? {};
|
|
1746
|
+
const nextDebugEvalFiles = Boolean(message.payload.debugEvalFiles);
|
|
1636
1747
|
const nextEntrypoint = message.payload.entrypoint ?? "eval-runner";
|
|
1637
1748
|
const nextHappyDomEnabled = isFeatureEnabled(nextFeatures, "happyDOM", nextEntrypoint);
|
|
1638
1749
|
const globalsChanged = state.globalsSignature !== null && state.globalsSignature !== nextGlobalsSignature;
|
|
@@ -1663,6 +1774,7 @@ const handleMessage = async (message) => {
|
|
|
1663
1774
|
}
|
|
1664
1775
|
state.evalOptions = nextEvalOptions;
|
|
1665
1776
|
state.features = nextFeatures;
|
|
1777
|
+
state.debugEvalFiles = nextDebugEvalFiles;
|
|
1666
1778
|
state.entrypoint = nextEntrypoint;
|
|
1667
1779
|
Object.assign(state.context, {
|
|
1668
1780
|
__dirname: path.dirname(nextEntrypoint),
|
|
@@ -1682,6 +1794,7 @@ const handleMessage = async (message) => {
|
|
|
1682
1794
|
resetEvaluationState();
|
|
1683
1795
|
state.evalOptions = nextEvalOptions;
|
|
1684
1796
|
state.features = nextFeatures;
|
|
1797
|
+
state.debugEvalFiles = nextDebugEvalFiles;
|
|
1685
1798
|
state.entrypoint = nextEntrypoint;
|
|
1686
1799
|
debug("init:globals", Date.now() - initStart);
|
|
1687
1800
|
const windowStart = Date.now();
|
|
@@ -1711,21 +1824,27 @@ const handleMessage = async (message) => {
|
|
|
1711
1824
|
break;
|
|
1712
1825
|
}
|
|
1713
1826
|
case "EVAL": {
|
|
1827
|
+
evictedThisSession.clear();
|
|
1714
1828
|
try {
|
|
1715
|
-
const { values, modules } = await evaluateEntrypoint(message.payload.id);
|
|
1829
|
+
const { debugEvalFiles, values, modules } = await evaluateEntrypoint(message.payload.id);
|
|
1716
1830
|
sendMessage({
|
|
1717
1831
|
type: "EVAL_RESULT",
|
|
1718
1832
|
id: message.id,
|
|
1719
1833
|
payload: {
|
|
1834
|
+
...debugEvalFiles ? { debugEvalFiles } : {},
|
|
1720
1835
|
values,
|
|
1721
|
-
modules
|
|
1836
|
+
modules,
|
|
1837
|
+
evictedIds: Array.from(evictedThisSession)
|
|
1722
1838
|
}
|
|
1723
1839
|
});
|
|
1724
1840
|
} catch (error) {
|
|
1725
1841
|
sendMessage({
|
|
1726
1842
|
type: "EVAL_RESULT",
|
|
1727
1843
|
id: message.id,
|
|
1728
|
-
payload: {
|
|
1844
|
+
payload: {
|
|
1845
|
+
values: null,
|
|
1846
|
+
evictedIds: Array.from(evictedThisSession)
|
|
1847
|
+
},
|
|
1729
1848
|
error: serializeError(error)
|
|
1730
1849
|
});
|
|
1731
1850
|
}
|