@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
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export const unknownProcessorStaticValue = Symbol("unknownProcessorStaticValue");
|
|
2
|
+
export const createProcessorStaticContext = (processor) => {
|
|
3
|
+
const processorWithInternals = processor;
|
|
4
|
+
return {
|
|
5
|
+
addDependency: () => {},
|
|
6
|
+
debug: () => {},
|
|
7
|
+
fileContext: processorWithInternals.context ?? {},
|
|
8
|
+
metadata: {
|
|
9
|
+
className: processor.className,
|
|
10
|
+
displayName: processor.displayName,
|
|
11
|
+
isReferenced: processor.isReferenced,
|
|
12
|
+
location: processor.location,
|
|
13
|
+
slug: processor.slug,
|
|
14
|
+
tagSource: processor.tagSource
|
|
15
|
+
},
|
|
16
|
+
options: processorWithInternals.options ?? {},
|
|
17
|
+
unresolved: (reason, details) => ({
|
|
18
|
+
...details ? { details } : {},
|
|
19
|
+
kind: "unresolved",
|
|
20
|
+
reason
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const isProcessorStaticValue = (value) => {
|
|
25
|
+
if (typeof value !== "object" || value === null || !("kind" in value)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const candidate = value;
|
|
29
|
+
switch (candidate.kind) {
|
|
30
|
+
case "class-name": return typeof candidate.className === "string";
|
|
31
|
+
case "opaque-component": return candidate.className === undefined || typeof candidate.className === "string";
|
|
32
|
+
case "runtime-callback":
|
|
33
|
+
case "serializable": return true;
|
|
34
|
+
case "selector-chain": return typeof candidate.className === "string" && Array.isArray(candidate.selectors) && candidate.selectors.every((selector) => typeof selector === "string");
|
|
35
|
+
case "unresolved": return typeof candidate.reason === "string";
|
|
36
|
+
default: return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const getProcessorStaticValue = (processor) => {
|
|
40
|
+
if (!processor.getStaticValue) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const value = processor.getStaticValue(createProcessorStaticContext(processor));
|
|
45
|
+
return isProcessorStaticValue(value) ? value : null;
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export const processorStaticValueToRuntimeValue = (value) => {
|
|
51
|
+
switch (value.kind) {
|
|
52
|
+
case "class-name": return value.value === undefined ? value.className : value.value;
|
|
53
|
+
case "opaque-component":
|
|
54
|
+
case "runtime-callback": return value.value === undefined ? unknownProcessorStaticValue : value.value;
|
|
55
|
+
case "selector-chain":
|
|
56
|
+
case "serializable": return value.value;
|
|
57
|
+
case "unresolved": return unknownProcessorStaticValue;
|
|
58
|
+
default: return unknownProcessorStaticValue;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export const resolveProcessorStaticRuntimeValue = (processor) => {
|
|
62
|
+
const staticValue = getProcessorStaticValue(processor);
|
|
63
|
+
return staticValue ? processorStaticValueToRuntimeValue(staticValue) : unknownProcessorStaticValue;
|
|
64
|
+
};
|
|
65
|
+
export const resolveProcessorStaticClassName = (processor) => {
|
|
66
|
+
const staticValue = getProcessorStaticValue(processor);
|
|
67
|
+
if (staticValue?.kind !== "class-name") {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const runtimeValue = processorStaticValueToRuntimeValue(staticValue);
|
|
71
|
+
return typeof runtimeValue === "string" ? runtimeValue : staticValue.className;
|
|
72
|
+
};
|
|
73
|
+
export const processorLiteralValue = (expression) => {
|
|
74
|
+
const expressionWithValue = expression;
|
|
75
|
+
if (expression.type === "StringLiteral" || expression.type === "NumericLiteral" || expression.type === "BooleanLiteral" || expression.type === "Literal") {
|
|
76
|
+
return expressionWithValue.value;
|
|
77
|
+
}
|
|
78
|
+
if (expression.type === "NullLiteral") {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return unknownProcessorStaticValue;
|
|
82
|
+
};
|
|
83
|
+
export const processorPropertyKeyName = (key) => {
|
|
84
|
+
if (key.type === "Identifier") {
|
|
85
|
+
return key.name;
|
|
86
|
+
}
|
|
87
|
+
const value = processorLiteralValue(key);
|
|
88
|
+
return typeof value === "string" ? value : null;
|
|
89
|
+
};
|
|
90
|
+
export const processorObjectPropertyValue = (expression, name) => {
|
|
91
|
+
if (expression.type !== "ObjectExpression") {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const { properties } = expression;
|
|
95
|
+
if (!properties) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
for (const property of properties) {
|
|
99
|
+
if ((property.type === "ObjectProperty" || property.type === "Property") && property.key && processorPropertyKeyName(property.key) === name) {
|
|
100
|
+
return property.value ?? null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
export const processorExpressionToStaticValue = (expression, resolveHelperCall) => {
|
|
106
|
+
const literal = processorLiteralValue(expression);
|
|
107
|
+
if (literal !== unknownProcessorStaticValue) {
|
|
108
|
+
return literal;
|
|
109
|
+
}
|
|
110
|
+
if (expression.type === "ArrayExpression") {
|
|
111
|
+
const { elements } = expression;
|
|
112
|
+
if (!elements) {
|
|
113
|
+
return unknownProcessorStaticValue;
|
|
114
|
+
}
|
|
115
|
+
const result = [];
|
|
116
|
+
for (const element of elements) {
|
|
117
|
+
if (element === null) {
|
|
118
|
+
result.push(null);
|
|
119
|
+
} else {
|
|
120
|
+
const value = processorExpressionToStaticValue(element, resolveHelperCall);
|
|
121
|
+
if (value === unknownProcessorStaticValue) {
|
|
122
|
+
return unknownProcessorStaticValue;
|
|
123
|
+
}
|
|
124
|
+
result.push(value);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
if (expression.type === "ObjectExpression") {
|
|
130
|
+
const metaExpression = processorObjectPropertyValue(expression, "__wyw_meta");
|
|
131
|
+
if (!metaExpression || metaExpression.type !== "ObjectExpression") {
|
|
132
|
+
return unknownProcessorStaticValue;
|
|
133
|
+
}
|
|
134
|
+
const classNameExpression = processorObjectPropertyValue(metaExpression, "className");
|
|
135
|
+
const className = classNameExpression ? processorLiteralValue(classNameExpression) : unknownProcessorStaticValue;
|
|
136
|
+
if (typeof className !== "string") {
|
|
137
|
+
return unknownProcessorStaticValue;
|
|
138
|
+
}
|
|
139
|
+
const extendsExpression = processorObjectPropertyValue(metaExpression, "extends");
|
|
140
|
+
const extended = extendsExpression ? processorExpressionToStaticValue(extendsExpression, resolveHelperCall) : null;
|
|
141
|
+
if (extended === unknownProcessorStaticValue) {
|
|
142
|
+
return unknownProcessorStaticValue;
|
|
143
|
+
}
|
|
144
|
+
return { __wyw_meta: {
|
|
145
|
+
className,
|
|
146
|
+
extends: extended
|
|
147
|
+
} };
|
|
148
|
+
}
|
|
149
|
+
if (expression.type === "CallExpression") {
|
|
150
|
+
const call = expression;
|
|
151
|
+
if (call.arguments?.length === 0 && call.callee?.type === "Identifier") {
|
|
152
|
+
return resolveHelperCall(call.callee.name);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return unknownProcessorStaticValue;
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=processorStaticSemantics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAOA,OAAO,MAAM,8BAA8B,OACzC,8BACD;AASD,OAAO,MAAM,gCACX,cAC2B;CAC3B,MAAM,yBAAyB;AAE/B,QAAO;EACL,qBAAqB;EACrB,aAAa;EACb,aACE,uBAAuB,WACtB,EAAE;EACL,UAAU;GACR,WAAW,UAAU;GACrB,aAAa,UAAU;GACvB,cAAc,UAAU;GACxB,UAAU,UAAU;GACpB,MAAM,UAAU;GAChB,WAAW,UAAU;GACtB;EACD,SACE,uBAAuB,WACtB,EAAE;EACL,aAAa,QAAQ,aAAa;GAChC,GAAI,UAAU,EAAE,SAAS,GAAG,EAAE;GAC9B,MAAM;GACN;GACD;EACF;;AAGH,OAAO,MAAM,0BACX,UACkC;AAClC,KAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,UAAU,QAAQ;AACrE,SAAO;;CAGT,MAAM,YAAY;AAClB,SAAQ,UAAU,MAAlB;EACE,KAAK,aACH,QAAO,OAAO,UAAU,cAAc;EACxC,KAAK,mBACH,QACE,UAAU,cAAc,aACxB,OAAO,UAAU,cAAc;EAEnC,KAAK;EACL,KAAK,eACH,QAAO;EACT,KAAK,iBACH,QACE,OAAO,UAAU,cAAc,YAC/B,MAAM,QAAQ,UAAU,UAAU,IAClC,UAAU,UAAU,OAAO,aAAa,OAAO,aAAa,SAAS;EAEzE,KAAK,aACH,QAAO,OAAO,UAAU,WAAW;EACrC,QACE,QAAO;;;AAIb,OAAO,MAAM,2BACX,cACgC;AAChC,KAAI,CAAC,UAAU,gBAAgB;AAC7B,SAAO;;AAGT,KAAI;EACF,MAAM,QAAQ,UAAU,eACtB,6BAA6B,UAAU,CACxC;AACD,SAAO,uBAAuB,MAAM,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,UAAO,SAAS,SAAS;;;AAI7B,QAAO;;AAGT,OAAO,MAAM,oCACX,YACA,sBAC0C;CAC1C,MAAM,UAAU,sBAAsB,WAAW;AACjD,KAAI,YAAY,6BAA6B;AAC3C,SAAO;;AAGT,KAAI,WAAW,SAAS,mBAAmB;EACzC,MAAM,EAAE,aAAa;AAGrB,MAAI,CAAC,UAAU;AACb,UAAO;;EAGT,MAAM,SAAoB,EAAE;AAC5B,OAAK,MAAM,WAAW,UAAU;AAC9B,OAAI,YAAY,MAAM;AACpB,WAAO,KAAK,KAAK;UACZ;IACL,MAAM,QAAQ,iCACZ,SACA,kBACD;AACD,QAAI,UAAU,6BAA6B;AACzC,YAAO;;AAGT,WAAO,KAAK,MAAM;;;AAItB,SAAO;;AAGT,KAAI,WAAW,SAAS,oBAAoB;EAC1C,MAAM,iBAAiB,6BACrB,YACA,aACD;AACD,MAAI,CAAC,kBAAkB,eAAe,SAAS,oBAAoB;AACjE,UAAO;;EAGT,MAAM,sBAAsB,6BAC1B,gBACA,YACD;EACD,MAAM,YAAY,sBACd,sBAAsB,oBAAoB,GAC1C;AACJ,MAAI,OAAO,cAAc,UAAU;AACjC,UAAO;;EAGT,MAAM,oBAAoB,6BACxB,gBACA,UACD;EACD,MAAM,WAAW,oBACb,iCAAiC,mBAAmB,kBAAkB,GACtE;AACJ,MAAI,aAAa,6BAA6B;AAC5C,UAAO;;AAGT,SAAO,EACL,YAAY;GACV;GACA,SAAS;GACV,EACF;;AAGH,KAAI,WAAW,SAAS,kBAAkB;EACxC,MAAM,OAAO;AAIb,MAAI,KAAK,WAAW,WAAW,KAAK,KAAK,QAAQ,SAAS,cAAc;AACtE,UAAO,kBACJ,KAAK,OAAkD,KACzD;;;AAIL,QAAO","names":[],"sources":["../../src/utils/processorStaticSemantics.ts"],"version":3,"sourcesContent":["import type {\n BaseProcessor,\n Expression as ProcessorExpression,\n ProcessorStaticContext,\n ProcessorStaticValue,\n} from '@wyw-in-js/processor-utils';\n\nexport const unknownProcessorStaticValue = Symbol(\n 'unknownProcessorStaticValue'\n);\n\nexport type UnknownProcessorStaticValue = typeof unknownProcessorStaticValue;\n\ntype ProcessorWithStaticInternals = BaseProcessor & {\n context?: ProcessorStaticContext['fileContext'];\n options?: ProcessorStaticContext['options'];\n};\n\nexport const createProcessorStaticContext = (\n processor: BaseProcessor\n): ProcessorStaticContext => {\n const processorWithInternals = processor as ProcessorWithStaticInternals;\n\n return {\n addDependency: () => {},\n debug: () => {},\n fileContext:\n processorWithInternals.context ??\n ({} as ProcessorStaticContext['fileContext']),\n metadata: {\n className: processor.className,\n displayName: processor.displayName,\n isReferenced: processor.isReferenced,\n location: processor.location,\n slug: processor.slug,\n tagSource: processor.tagSource,\n },\n options:\n processorWithInternals.options ??\n ({} as ProcessorStaticContext['options']),\n unresolved: (reason, details) => ({\n ...(details ? { details } : {}),\n kind: 'unresolved',\n reason,\n }),\n };\n};\n\nexport const isProcessorStaticValue = (\n value: unknown\n): value is ProcessorStaticValue => {\n if (typeof value !== 'object' || value === null || !('kind' in value)) {\n return false;\n }\n\n const candidate = value as ProcessorStaticValue;\n switch (candidate.kind) {\n case 'class-name':\n return typeof candidate.className === 'string';\n case 'opaque-component':\n return (\n candidate.className === undefined ||\n typeof candidate.className === 'string'\n );\n case 'runtime-callback':\n case 'serializable':\n return true;\n case 'selector-chain':\n return (\n typeof candidate.className === 'string' &&\n Array.isArray(candidate.selectors) &&\n candidate.selectors.every((selector) => typeof selector === 'string')\n );\n case 'unresolved':\n return typeof candidate.reason === 'string';\n default:\n return false;\n }\n};\n\nexport const getProcessorStaticValue = (\n processor: BaseProcessor\n): ProcessorStaticValue | null => {\n if (!processor.getStaticValue) {\n return null;\n }\n\n try {\n const value = processor.getStaticValue(\n createProcessorStaticContext(processor)\n );\n return isProcessorStaticValue(value) ? value : null;\n } catch {\n return null;\n }\n};\n\nexport const processorStaticValueToRuntimeValue = (\n value: ProcessorStaticValue\n): unknown | UnknownProcessorStaticValue => {\n switch (value.kind) {\n case 'class-name':\n return value.value === undefined ? value.className : value.value;\n case 'opaque-component':\n case 'runtime-callback':\n return value.value === undefined\n ? unknownProcessorStaticValue\n : value.value;\n case 'selector-chain':\n case 'serializable':\n return value.value;\n case 'unresolved':\n return unknownProcessorStaticValue;\n default:\n return unknownProcessorStaticValue;\n }\n};\n\nexport const resolveProcessorStaticRuntimeValue = (\n processor: BaseProcessor\n): unknown | UnknownProcessorStaticValue => {\n const staticValue = getProcessorStaticValue(processor);\n return staticValue\n ? processorStaticValueToRuntimeValue(staticValue)\n : unknownProcessorStaticValue;\n};\n\nexport const resolveProcessorStaticClassName = (\n processor: BaseProcessor\n): string | null => {\n const staticValue = getProcessorStaticValue(processor);\n if (staticValue?.kind !== 'class-name') {\n return null;\n }\n\n const runtimeValue = processorStaticValueToRuntimeValue(staticValue);\n return typeof runtimeValue === 'string'\n ? runtimeValue\n : staticValue.className;\n};\n\nexport const processorLiteralValue = (\n expression: ProcessorExpression\n): unknown | UnknownProcessorStaticValue => {\n const expressionWithValue = expression as ProcessorExpression & {\n value?: unknown;\n };\n\n if (\n expression.type === 'StringLiteral' ||\n expression.type === 'NumericLiteral' ||\n expression.type === 'BooleanLiteral' ||\n expression.type === 'Literal'\n ) {\n return expressionWithValue.value;\n }\n\n if (expression.type === 'NullLiteral') {\n return null;\n }\n\n return unknownProcessorStaticValue;\n};\n\nexport const processorPropertyKeyName = (\n key: ProcessorExpression\n): string | null => {\n if (key.type === 'Identifier') {\n return (key as ProcessorExpression & { name: string }).name;\n }\n\n const value = processorLiteralValue(key);\n return typeof value === 'string' ? value : null;\n};\n\nexport const processorObjectPropertyValue = (\n expression: ProcessorExpression,\n name: string\n): ProcessorExpression | null => {\n if (expression.type !== 'ObjectExpression') {\n return null;\n }\n\n const { properties } = expression as ProcessorExpression & {\n properties?: Array<\n ProcessorExpression & {\n key?: ProcessorExpression;\n type: string;\n value?: ProcessorExpression;\n }\n >;\n };\n if (!properties) {\n return null;\n }\n\n for (const property of properties) {\n if (\n (property.type === 'ObjectProperty' || property.type === 'Property') &&\n property.key &&\n processorPropertyKeyName(property.key) === name\n ) {\n return property.value ?? null;\n }\n }\n\n return null;\n};\n\nexport const processorExpressionToStaticValue = (\n expression: ProcessorExpression,\n resolveHelperCall: (name: string) => unknown | UnknownProcessorStaticValue\n): unknown | UnknownProcessorStaticValue => {\n const literal = processorLiteralValue(expression);\n if (literal !== unknownProcessorStaticValue) {\n return literal;\n }\n\n if (expression.type === 'ArrayExpression') {\n const { elements } = expression as ProcessorExpression & {\n elements?: Array<ProcessorExpression | null>;\n };\n if (!elements) {\n return unknownProcessorStaticValue;\n }\n\n const result: unknown[] = [];\n for (const element of elements) {\n if (element === null) {\n result.push(null);\n } else {\n const value = processorExpressionToStaticValue(\n element,\n resolveHelperCall\n );\n if (value === unknownProcessorStaticValue) {\n return unknownProcessorStaticValue;\n }\n\n result.push(value);\n }\n }\n\n return result;\n }\n\n if (expression.type === 'ObjectExpression') {\n const metaExpression = processorObjectPropertyValue(\n expression,\n '__wyw_meta'\n );\n if (!metaExpression || metaExpression.type !== 'ObjectExpression') {\n return unknownProcessorStaticValue;\n }\n\n const classNameExpression = processorObjectPropertyValue(\n metaExpression,\n 'className'\n );\n const className = classNameExpression\n ? processorLiteralValue(classNameExpression)\n : unknownProcessorStaticValue;\n if (typeof className !== 'string') {\n return unknownProcessorStaticValue;\n }\n\n const extendsExpression = processorObjectPropertyValue(\n metaExpression,\n 'extends'\n );\n const extended = extendsExpression\n ? processorExpressionToStaticValue(extendsExpression, resolveHelperCall)\n : null;\n if (extended === unknownProcessorStaticValue) {\n return unknownProcessorStaticValue;\n }\n\n return {\n __wyw_meta: {\n className,\n extends: extended,\n },\n };\n }\n\n if (expression.type === 'CallExpression') {\n const call = expression as ProcessorExpression & {\n arguments?: ProcessorExpression[];\n callee?: ProcessorExpression;\n };\n if (call.arguments?.length === 0 && call.callee?.type === 'Identifier') {\n return resolveHelperCall(\n (call.callee as ProcessorExpression & { name: string }).name\n );\n }\n }\n\n return unknownProcessorStaticValue;\n};\n"],"file":"processorStaticSemantics.js"}
|
|
@@ -53,7 +53,7 @@ const resolveWithNodeProcess = (id, parent, conditions) => {
|
|
|
53
53
|
parsed = JSON.parse(stdout);
|
|
54
54
|
} catch {
|
|
55
55
|
throw new Error([
|
|
56
|
-
"[wyw-in-js] Failed to parse
|
|
56
|
+
"[wyw-in-js] Failed to parse custom module resolver output.",
|
|
57
57
|
`stdout: ${stdout}`,
|
|
58
58
|
result.stderr ? `stderr: ${result.stderr.trim()}` : ""
|
|
59
59
|
].filter(Boolean).join("\n"));
|
|
@@ -66,7 +66,7 @@ const resolveWithNodeProcess = (id, parent, conditions) => {
|
|
|
66
66
|
}
|
|
67
67
|
if (result.status !== 0 || !parsed?.resolved) {
|
|
68
68
|
throw new Error([
|
|
69
|
-
"[wyw-in-js]
|
|
69
|
+
"[wyw-in-js] Custom module resolver fallback failed.",
|
|
70
70
|
`status: ${result.status ?? "null"}`,
|
|
71
71
|
result.stderr ? `stderr: ${result.stderr.trim()}` : ""
|
|
72
72
|
].filter(Boolean).join("\n"));
|
|
@@ -82,7 +82,7 @@ export const resolveFilenameWithConditions = (moduleImpl, id, parent, conditions
|
|
|
82
82
|
// Bun crashes on macOS/Silicon in this exact path:
|
|
83
83
|
// Module._resolveFilename(specifier, parent, false, { conditions })
|
|
84
84
|
// We reproduced it both with a tiny standalone script and through the
|
|
85
|
-
// `EvalBroker > passes conditionNames to
|
|
85
|
+
// `EvalBroker > passes conditionNames to native fallback resolution` test,
|
|
86
86
|
// including on Bun 1.3.13. Keep this fallback narrow: only conditioned
|
|
87
87
|
// resolution under Bun goes through a short-lived Node subprocess.
|
|
88
88
|
//
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,iBAAiB;AAC1B,OAAO,kBAAkB;AAsBzB,MAAM,kCAAkC,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BlD,MAAM,qBAAqB,QAAQ,SAAS,SAA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],"version":3,"sourcesContent":["import { spawnSync } from 'child_process';\nimport NativeModule from 'module';\n\ntype ResolveFilenameParent = {\n filename: string;\n id: string;\n paths: string[];\n};\n\ntype ResolveFilenameModuleImplementation = {\n _resolveFilename: (\n id: string,\n options: ResolveFilenameParent,\n isMain?: boolean,\n resolveOptions?: { conditions?: Set<string> }\n ) => string;\n};\n\ntype NodeConditionalResolveResult = {\n error?: { code?: string; message: string };\n resolved?: string;\n};\n\nconst NODE_CONDITIONAL_RESOLVE_SCRIPT = String.raw`\nconst fs = require('node:fs');\nconst Module = require('node:module');\n\nconst input = JSON.parse(fs.readFileSync(0, 'utf8'));\n\ntry {\n const resolved = Module._resolveFilename(\n input.id,\n input.parent,\n false,\n input.conditions ? { conditions: new Set(input.conditions) } : undefined\n );\n fs.writeFileSync(1, JSON.stringify({ resolved }));\n} catch (error) {\n fs.writeFileSync(\n 1,\n JSON.stringify({\n error: {\n code:\n error && typeof error === 'object' && 'code' in error\n ? error.code\n : undefined,\n message: error instanceof Error ? error.message : String(error),\n },\n })\n );\n process.exitCode = 1;\n}\n`;\n\nconst isBunRuntime = () => process.execPath.includes('bun');\n\nconst nativeResolveFilename = (\n NativeModule as unknown as ResolveFilenameModuleImplementation\n)._resolveFilename;\n\nconst resolveWithNodeProcess = (\n id: string,\n parent: ResolveFilenameParent,\n conditions: Set<string>\n): string => {\n const nodeBinary = process.env.WYW_NODE_BINARY || 'node';\n const result = spawnSync(\n nodeBinary,\n ['-e', NODE_CONDITIONAL_RESOLVE_SCRIPT],\n {\n encoding: 'utf8',\n input: JSON.stringify({\n conditions: [...conditions],\n id,\n parent,\n }),\n maxBuffer: 1024 * 1024,\n }\n );\n\n if (result.error) {\n throw result.error;\n }\n\n let parsed: NodeConditionalResolveResult | null = null;\n const stdout = result.stdout.trim();\n if (stdout) {\n try {\n parsed = JSON.parse(stdout) as NodeConditionalResolveResult;\n } catch {\n throw new Error(\n [\n '[wyw-in-js] Failed to parse
|
|
1
|
+
{"mappings":"AAA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;AACzD,SAAO,WAAW,iBAAiB,IAAI,QAAQ,OAAO,eAAe;;;;;;;;;;;;;;;;;AAkBvE,QAAO,uBAAuB,IAAI,QAAQ,WAAW","names":[],"sources":["../../src/utils/resolveWithConditions.ts"],"version":3,"sourcesContent":["import { spawnSync } from 'child_process';\nimport NativeModule from 'module';\n\ntype ResolveFilenameParent = {\n filename: string;\n id: string;\n paths: string[];\n};\n\ntype ResolveFilenameModuleImplementation = {\n _resolveFilename: (\n id: string,\n options: ResolveFilenameParent,\n isMain?: boolean,\n resolveOptions?: { conditions?: Set<string> }\n ) => string;\n};\n\ntype NodeConditionalResolveResult = {\n error?: { code?: string; message: string };\n resolved?: string;\n};\n\nconst NODE_CONDITIONAL_RESOLVE_SCRIPT = String.raw`\nconst fs = require('node:fs');\nconst Module = require('node:module');\n\nconst input = JSON.parse(fs.readFileSync(0, 'utf8'));\n\ntry {\n const resolved = Module._resolveFilename(\n input.id,\n input.parent,\n false,\n input.conditions ? { conditions: new Set(input.conditions) } : undefined\n );\n fs.writeFileSync(1, JSON.stringify({ resolved }));\n} catch (error) {\n fs.writeFileSync(\n 1,\n JSON.stringify({\n error: {\n code:\n error && typeof error === 'object' && 'code' in error\n ? error.code\n : undefined,\n message: error instanceof Error ? error.message : String(error),\n },\n })\n );\n process.exitCode = 1;\n}\n`;\n\nconst isBunRuntime = () => process.execPath.includes('bun');\n\nconst nativeResolveFilename = (\n NativeModule as unknown as ResolveFilenameModuleImplementation\n)._resolveFilename;\n\nconst resolveWithNodeProcess = (\n id: string,\n parent: ResolveFilenameParent,\n conditions: Set<string>\n): string => {\n const nodeBinary = process.env.WYW_NODE_BINARY || 'node';\n const result = spawnSync(\n nodeBinary,\n ['-e', NODE_CONDITIONAL_RESOLVE_SCRIPT],\n {\n encoding: 'utf8',\n input: JSON.stringify({\n conditions: [...conditions],\n id,\n parent,\n }),\n maxBuffer: 1024 * 1024,\n }\n );\n\n if (result.error) {\n throw result.error;\n }\n\n let parsed: NodeConditionalResolveResult | null = null;\n const stdout = result.stdout.trim();\n if (stdout) {\n try {\n parsed = JSON.parse(stdout) as NodeConditionalResolveResult;\n } catch {\n throw new Error(\n [\n '[wyw-in-js] Failed to parse custom module resolver output.',\n `stdout: ${stdout}`,\n result.stderr ? `stderr: ${result.stderr.trim()}` : '',\n ]\n .filter(Boolean)\n .join('\\n')\n );\n }\n }\n\n if (parsed?.error) {\n const error = new Error(parsed.error.message) as NodeJS.ErrnoException;\n error.code = parsed.error.code;\n throw error;\n }\n\n if (result.status !== 0 || !parsed?.resolved) {\n throw new Error(\n [\n '[wyw-in-js] Custom module resolver fallback failed.',\n `status: ${result.status ?? 'null'}`,\n result.stderr ? `stderr: ${result.stderr.trim()}` : '',\n ]\n .filter(Boolean)\n .join('\\n')\n );\n }\n\n return parsed.resolved;\n};\n\nexport const resolveFilenameWithConditions = (\n moduleImpl: ResolveFilenameModuleImplementation,\n id: string,\n parent: ResolveFilenameParent,\n conditions?: Set<string>\n): string => {\n const resolveOptions = conditions ? { conditions } : undefined;\n const usesNativeResolver =\n moduleImpl._resolveFilename === nativeResolveFilename;\n\n if (!conditions || !isBunRuntime() || !usesNativeResolver) {\n return moduleImpl._resolveFilename(id, parent, false, resolveOptions);\n }\n\n // Bun crashes on macOS/Silicon in this exact path:\n // Module._resolveFilename(specifier, parent, false, { conditions })\n // We reproduced it both with a tiny standalone script and through the\n // `EvalBroker > passes conditionNames to native fallback resolution` test,\n // including on Bun 1.3.13. Keep this fallback narrow: only conditioned\n // resolution under Bun goes through a short-lived Node subprocess.\n //\n // Cleanup criteria:\n // 1. Bun passes the minimal local `_resolveFilename(..., { conditions })`\n // repro on macOS without segfaulting.\n // 2. The conditionNames runner path passes without this fallback.\n //\n // As of 2026-04-20 we did not find an exact open upstream Bun issue for this\n // `_resolveFilename(..., { conditions })` crash, so keep the comment factual\n // and the workaround self-contained.\n return resolveWithNodeProcess(id, parent, conditions);\n};\n"],"file":"resolveWithConditions.js"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/transform",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@jridgewell/remapping": "^2.3.5",
|
|
7
|
-
"@wyw-in-js/processor-utils": "2.0.0-alpha.
|
|
8
|
-
"@wyw-in-js/shared": "2.0.0-alpha.
|
|
7
|
+
"@wyw-in-js/processor-utils": "2.0.0-alpha.1",
|
|
8
|
+
"@wyw-in-js/shared": "2.0.0-alpha.1",
|
|
9
9
|
"cosmiconfig": "^8.0.0",
|
|
10
10
|
"happy-dom": "^20.1.0",
|
|
11
11
|
"minimatch": "^9.0.5",
|
|
12
12
|
"oxc-parser": "0.127.0",
|
|
13
|
+
"oxc-resolver": "11.19.1",
|
|
13
14
|
"oxc-transform": "0.127.0",
|
|
14
15
|
"source-map": "^0.7.4",
|
|
15
16
|
"stylis": "^4.3.0",
|
package/types/cache.js
CHANGED
|
@@ -298,7 +298,15 @@ export class TransformCacheCollection {
|
|
|
298
298
|
return true;
|
|
299
299
|
}
|
|
300
300
|
// A cached file without a cached entrypoint was invalidated earlier.
|
|
301
|
+
// If the caller forced a content check and the content hash is stable,
|
|
302
|
+
// the missing entrypoint is only cache churn and must not invalidate
|
|
303
|
+
// output-dependent parents.
|
|
301
304
|
if (!cachedEntrypoint && nestedDependencies.size === 0) {
|
|
305
|
+
if (forceContentCheck &&
|
|
306
|
+
this.contentHashes.get(dependencyFilename)?.fs !== undefined) {
|
|
307
|
+
dependencyChangeMemo.set(dependencyFilename, false);
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
302
310
|
dependencyChangeMemo.set(dependencyFilename, true);
|
|
303
311
|
return true;
|
|
304
312
|
}
|
|
@@ -4,6 +4,13 @@ import path from 'path';
|
|
|
4
4
|
import { EventEmitter, isOnActionStartArgs } from '../utils/EventEmitter';
|
|
5
5
|
const workingDir = process.cwd();
|
|
6
6
|
function replacer(_key, value) {
|
|
7
|
+
if (value instanceof Error) {
|
|
8
|
+
return {
|
|
9
|
+
message: value.message,
|
|
10
|
+
name: value.name,
|
|
11
|
+
stack: value.stack,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
7
14
|
if (typeof value === 'string' && path.isAbsolute(value)) {
|
|
8
15
|
return path.relative(workingDir, value);
|
|
9
16
|
}
|
|
@@ -41,6 +48,29 @@ function printTimings(timings, startedAt, sourceRoot) {
|
|
|
41
48
|
const writeJSONl = (stream, data) => {
|
|
42
49
|
stream.write(`${JSON.stringify(data, replacer)}\n`);
|
|
43
50
|
};
|
|
51
|
+
const isPerfFinishEvent = (event) => {
|
|
52
|
+
if (!event || typeof event !== 'object') {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return ('type' in event &&
|
|
56
|
+
event.type === 'perf-span' &&
|
|
57
|
+
'method' in event &&
|
|
58
|
+
typeof event.method === 'string' &&
|
|
59
|
+
'spanId' in event &&
|
|
60
|
+
typeof event.spanId === 'number' &&
|
|
61
|
+
'startedAt' in event &&
|
|
62
|
+
typeof event.startedAt === 'number' &&
|
|
63
|
+
'finishedAt' in event &&
|
|
64
|
+
typeof event.finishedAt === 'number' &&
|
|
65
|
+
'durationMs' in event &&
|
|
66
|
+
typeof event.durationMs === 'number');
|
|
67
|
+
};
|
|
68
|
+
const isPerfStartEvent = (event) => {
|
|
69
|
+
if (!event || typeof event !== 'object') {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return 'type' in event && event.type === 'perf-span-start';
|
|
73
|
+
};
|
|
44
74
|
export const createFileReporter = (options = false) => {
|
|
45
75
|
if (!options || !options.dir) {
|
|
46
76
|
return {
|
|
@@ -60,6 +90,8 @@ export const createFileReporter = (options = false) => {
|
|
|
60
90
|
const dependenciesStream = createWriteStream(path.join(options.dir, 'dependencies.jsonl'));
|
|
61
91
|
const entrypointStream = createWriteStream(path.join(options.dir, 'entrypoints.jsonl'));
|
|
62
92
|
const staticResolveStream = createWriteStream(path.join(options.dir, 'static-resolve.jsonl'));
|
|
93
|
+
const perfSpanStream = createWriteStream(path.join(options.dir, 'perf-spans.jsonl'));
|
|
94
|
+
const evalFilesStream = createWriteStream(path.join(options.dir, 'eval-files.jsonl'));
|
|
63
95
|
const startedAt = performance.now();
|
|
64
96
|
const timings = new Map();
|
|
65
97
|
const addTiming = (label, key, value) => {
|
|
@@ -85,13 +117,24 @@ export const createFileReporter = (options = false) => {
|
|
|
85
117
|
if (meta.type === 'staticResolve') {
|
|
86
118
|
writeJSONl(staticResolveStream, meta);
|
|
87
119
|
}
|
|
120
|
+
if (meta.type === 'eval-file') {
|
|
121
|
+
writeJSONl(evalFilesStream, meta);
|
|
122
|
+
}
|
|
88
123
|
};
|
|
89
124
|
const startTimes = new Map();
|
|
90
|
-
const onEvent = (meta, type) => {
|
|
125
|
+
const onEvent = (meta, type, event) => {
|
|
91
126
|
if (type === 'single') {
|
|
92
127
|
processSingleEvent(meta);
|
|
93
128
|
return;
|
|
94
129
|
}
|
|
130
|
+
if (type === 'finish' && isPerfFinishEvent(event)) {
|
|
131
|
+
addTiming('method', event.method, event.durationMs);
|
|
132
|
+
writeJSONl(perfSpanStream, event);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (type === 'start' && isPerfStartEvent(event)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
95
138
|
if (type === 'start') {
|
|
96
139
|
Object.entries(meta).forEach(([label, value]) => {
|
|
97
140
|
startTimes.set(`${label}\0${value}`, performance.now());
|
|
@@ -145,6 +188,8 @@ export const createFileReporter = (options = false) => {
|
|
|
145
188
|
dependenciesStream.end();
|
|
146
189
|
entrypointStream.end();
|
|
147
190
|
staticResolveStream.end();
|
|
191
|
+
perfSpanStream.end();
|
|
192
|
+
evalFilesStream.end();
|
|
148
193
|
timings.clear();
|
|
149
194
|
},
|
|
150
195
|
};
|
package/types/eval/broker.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class EvalBroker {
|
|
|
22
22
|
private readonly loadInFlight;
|
|
23
23
|
private readonly importsByModule;
|
|
24
24
|
private readonly onlyByModule;
|
|
25
|
+
private readonly sessionLinkGraph;
|
|
25
26
|
private readonly runtimeDependenciesByModule;
|
|
26
27
|
private readonly emittedDependencies;
|
|
27
28
|
private readonly lastSentLoadByModule;
|
|
@@ -29,6 +30,7 @@ export declare class EvalBroker {
|
|
|
29
30
|
private evalFlushScheduled;
|
|
30
31
|
private stableInitHashCache;
|
|
31
32
|
private evalSeq;
|
|
33
|
+
private evalFileDebugLines;
|
|
32
34
|
private happyDomDisabled;
|
|
33
35
|
private happyDomDisableWarned;
|
|
34
36
|
private activeResolveRootId;
|
|
@@ -41,6 +43,8 @@ export declare class EvalBroker {
|
|
|
41
43
|
private scheduleEvalFlush;
|
|
42
44
|
private runEvalBatch;
|
|
43
45
|
private runOneEntrypoint;
|
|
46
|
+
private recordEvalFileDebugLine;
|
|
47
|
+
private flushEvalFileDebugLines;
|
|
44
48
|
private resetPerEntrypointState;
|
|
45
49
|
private applyModuleExports;
|
|
46
50
|
dispose(): void;
|
|
@@ -69,8 +73,8 @@ export declare class EvalBroker {
|
|
|
69
73
|
private trackImporterDependency;
|
|
70
74
|
private collectEntrypointDependencies;
|
|
71
75
|
private applyImportOverrides;
|
|
72
|
-
private
|
|
73
|
-
private
|
|
76
|
+
private resolveWithNativeFallback;
|
|
77
|
+
private maybeWarnNativeFallback;
|
|
74
78
|
private handleLoad;
|
|
75
79
|
private loadModule;
|
|
76
80
|
private loadModuleImpl;
|