@wyw-in-js/transform 1.1.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 +433 -289
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js +171 -134
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/eval/broker.js +2275 -0
- package/esm/eval/broker.js.map +1 -0
- package/esm/eval/lru.js +36 -0
- package/esm/eval/lru.js.map +1 -0
- package/esm/eval/prepareModuleOnDemand.js +21 -0
- package/esm/eval/prepareModuleOnDemand.js.map +1 -0
- package/esm/eval/protocol.js +2 -0
- package/esm/eval/protocol.js.map +1 -0
- package/esm/eval/runner.js +1878 -0
- package/esm/eval/runner.js.map +1 -0
- package/esm/eval/serialize.js +333 -0
- package/esm/eval/serialize.js.map +1 -0
- package/esm/eval/writeQueue.js +81 -0
- package/esm/eval/writeQueue.js.map +1 -0
- package/esm/evaluators/index.js +11 -12
- package/esm/evaluators/index.js.map +1 -1
- package/esm/index.js +25 -29
- package/esm/index.js.map +1 -1
- package/esm/module.js +923 -520
- package/esm/module.js.map +1 -1
- package/esm/shaker.js +14 -80
- package/esm/shaker.js.map +1 -1
- package/esm/transform/BaseEntrypoint.js +162 -164
- package/esm/transform/BaseEntrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.helpers.js +96 -253
- package/esm/transform/Entrypoint.helpers.js.map +1 -1
- package/esm/transform/Entrypoint.js +336 -270
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.types.js +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/EvaluatedEntrypoint.js +10 -4
- package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
- package/esm/transform/actions/AbortError.js +6 -6
- package/esm/transform/actions/AbortError.js.map +1 -1
- package/esm/transform/actions/BaseAction.js +140 -136
- package/esm/transform/actions/BaseAction.js.map +1 -1
- package/esm/transform/actions/UnprocessedEntrypointError.js +6 -6
- package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -1
- package/esm/transform/actions/actionRunner.js +63 -66
- package/esm/transform/actions/actionRunner.js.map +1 -1
- package/esm/transform/actions/types.js +1 -1
- package/esm/transform/actions/types.js.map +1 -1
- package/esm/transform/barrelManifest.types.js +2 -0
- package/esm/transform/barrelManifest.types.js.map +1 -0
- package/esm/transform/generators/baseProcessingHandlers.js +15 -17
- package/esm/transform/generators/baseProcessingHandlers.js.map +1 -1
- package/esm/transform/generators/collect.js +27 -55
- package/esm/transform/generators/collect.js.map +1 -1
- package/esm/transform/generators/createStylisPreprocessor.js +353 -321
- package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/esm/transform/generators/evalFile.js +48 -47
- package/esm/transform/generators/evalFile.js.map +1 -1
- package/esm/transform/generators/extract.js +78 -90
- package/esm/transform/generators/extract.js.map +1 -1
- package/esm/transform/generators/getExports.js +57 -74
- package/esm/transform/generators/getExports.js.map +1 -1
- package/esm/transform/generators/index.js +11 -11
- package/esm/transform/generators/index.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +93 -67
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/processImports.js +102 -67
- package/esm/transform/generators/processImports.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +212 -197
- 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 +2 -0
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -0
- package/esm/transform/generators/rewriteOxcBarrelImports.js +822 -0
- package/esm/transform/generators/rewriteOxcBarrelImports.js.map +1 -0
- package/esm/transform/generators/transform.js +251 -248
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/generators/workflow.js +87 -90
- package/esm/transform/generators/workflow.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +183 -74
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform/helpers/withDefaultServices.js +13 -22
- package/esm/transform/helpers/withDefaultServices.js.map +1 -1
- package/esm/transform/isStaticallyEvaluatableModule.js +140 -152
- package/esm/transform/isStaticallyEvaluatableModule.js.map +1 -1
- package/esm/transform/oxcBarrelManifest.js +349 -0
- package/esm/transform/oxcBarrelManifest.js.map +1 -0
- package/esm/transform/rootLog.js +3 -3
- package/esm/transform/rootLog.js.map +1 -1
- package/esm/transform/syntax.js +2 -0
- package/esm/transform/syntax.js.map +1 -0
- package/esm/transform/types.js +2 -2
- package/esm/transform/types.js.map +1 -1
- package/esm/transform.js +125 -147
- package/esm/transform.js.map +1 -1
- package/esm/types.js +4 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/EventEmitter.js +79 -48
- package/esm/utils/EventEmitter.js.map +1 -1
- package/esm/utils/ShakerMetadata.js +2 -2
- package/esm/utils/ShakerMetadata.js.map +1 -1
- package/esm/utils/TransformDiagnostics.js +9 -9
- package/esm/utils/TransformDiagnostics.js.map +1 -1
- package/esm/utils/TransformMetadata.js +24 -26
- package/esm/utils/TransformMetadata.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 +2 -0
- package/esm/utils/applyOxcProcessors.js.map +1 -0
- package/esm/utils/collectOxcExportsAndImports.js +934 -0
- package/esm/utils/collectOxcExportsAndImports.js.map +1 -0
- 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 +32 -0
- package/esm/utils/collectOxcRuntime.js.map +1 -0
- 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 +4 -0
- package/esm/utils/collectOxcTemplateDependencies.js.map +1 -0
- package/esm/utils/dispose-polyfill.js +3 -4
- package/esm/utils/dispose-polyfill.js.map +1 -1
- package/esm/utils/getFileIdx.js +6 -6
- package/esm/utils/getFileIdx.js.map +1 -1
- package/esm/utils/getPluginKey.js +12 -12
- package/esm/utils/getPluginKey.js.map +1 -1
- package/esm/utils/getVisitorKeys.js +9 -3
- package/esm/utils/getVisitorKeys.js.map +1 -1
- package/esm/utils/hasCachedWywPrevalExport.js +23 -0
- package/esm/utils/hasCachedWywPrevalExport.js.map +1 -0
- package/esm/utils/hasWywPreval.js +5 -5
- package/esm/utils/hasWywPreval.js.map +1 -1
- package/esm/utils/importOverrides.js +75 -90
- package/esm/utils/importOverrides.js.map +1 -1
- package/esm/utils/isNode.js +2 -2
- package/esm/utils/isNode.js.map +1 -1
- package/esm/utils/isNotNull.js +2 -2
- package/esm/utils/isNotNull.js.map +1 -1
- package/esm/utils/isSerializable.js +11 -11
- package/esm/utils/isSerializable.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/oxcAstService.js +121 -0
- package/esm/utils/oxcAstService.js.map +1 -0
- package/esm/utils/oxcEmit.js +447 -0
- package/esm/utils/oxcEmit.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 +41 -0
- package/esm/utils/oxcPreevalStage.js.map +1 -0
- package/esm/utils/oxcPreevalTransforms.js +1065 -0
- package/esm/utils/oxcPreevalTransforms.js.map +1 -0
- package/esm/utils/oxcShaker.js +662 -0
- package/esm/utils/oxcShaker.js.map +1 -0
- package/esm/utils/parseOxc.js +37 -0
- package/esm/utils/parseOxc.js.map +1 -0
- package/esm/utils/parseRequest.js +27 -27
- package/esm/utils/parseRequest.js.map +1 -1
- package/esm/utils/peek.js +1 -1
- package/esm/utils/peek.js.map +1 -1
- package/esm/utils/processorLookup.js +125 -0
- package/esm/utils/processorLookup.js.map +1 -0
- package/esm/utils/processorStaticSemantics.js +157 -0
- package/esm/utils/processorStaticSemantics.js.map +1 -0
- package/esm/utils/resolveWithConditions.js +99 -0
- package/esm/utils/resolveWithConditions.js.map +1 -0
- package/esm/vm/createVmContext.js +140 -141
- package/esm/vm/createVmContext.js.map +1 -1
- package/esm/vm/process.js +11 -13
- package/esm/vm/process.js.map +1 -1
- package/package.json +19 -26
- package/types/cache.d.ts +17 -8
- package/types/cache.js +245 -95
- package/types/debug/fileReporter.js +68 -23
- package/types/eval/broker.d.ts +92 -0
- package/types/eval/broker.js +2411 -0
- package/types/eval/lru.d.ts +10 -0
- package/types/eval/lru.js +36 -0
- package/types/eval/prepareModuleOnDemand.d.ts +7 -0
- package/types/eval/prepareModuleOnDemand.js +24 -0
- package/types/eval/protocol.d.ts +111 -0
- package/types/eval/protocol.js +1 -0
- package/types/eval/serialize.d.ts +78 -0
- package/types/eval/serialize.js +357 -0
- package/types/eval/writeQueue.d.ts +13 -0
- package/types/eval/writeQueue.js +80 -0
- package/types/evaluators/index.d.ts +2 -2
- package/types/evaluators/index.js +6 -9
- package/types/index.d.ts +3 -6
- package/types/index.js +24 -82
- package/types/module.d.ts +38 -7
- package/types/module.js +613 -192
- package/types/shaker.d.ts +2 -10
- package/types/shaker.js +10 -100
- package/types/transform/BaseEntrypoint.js +6 -11
- package/types/transform/Entrypoint.d.ts +15 -15
- package/types/transform/Entrypoint.helpers.d.ts +2 -5
- package/types/transform/Entrypoint.helpers.js +43 -203
- package/types/transform/Entrypoint.js +130 -53
- package/types/transform/Entrypoint.types.d.ts +31 -6
- package/types/transform/Entrypoint.types.js +1 -2
- package/types/transform/EvaluatedEntrypoint.d.ts +13 -2
- package/types/transform/EvaluatedEntrypoint.js +7 -6
- package/types/transform/actions/AbortError.js +2 -7
- package/types/transform/actions/BaseAction.js +4 -8
- package/types/transform/actions/UnprocessedEntrypointError.js +2 -7
- package/types/transform/actions/actionRunner.js +8 -12
- package/types/transform/actions/types.d.ts +2 -2
- package/types/transform/actions/types.js +1 -2
- package/types/transform/{barrelManifest.d.ts → barrelManifest.types.d.ts} +0 -2
- package/types/transform/barrelManifest.types.js +1 -0
- package/types/transform/generators/baseProcessingHandlers.d.ts +4 -5
- package/types/transform/generators/baseProcessingHandlers.js +10 -14
- package/types/transform/generators/collect.js +13 -39
- package/types/transform/generators/createStylisPreprocessor.js +19 -60
- package/types/transform/generators/evalFile.d.ts +2 -2
- package/types/transform/generators/evalFile.js +26 -28
- package/types/transform/generators/extract.js +5 -8
- package/types/transform/generators/getExports.js +23 -30
- package/types/transform/generators/index.d.ts +2 -2
- package/types/transform/generators/index.js +11 -14
- package/types/transform/generators/processEntrypoint.d.ts +2 -2
- package/types/transform/generators/processEntrypoint.js +60 -26
- package/types/transform/generators/processImports.d.ts +0 -3
- package/types/transform/generators/processImports.js +60 -20
- package/types/transform/generators/resolveImports.d.ts +3 -1
- package/types/transform/generators/resolveImports.js +66 -23
- 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 -0
- package/types/transform/generators/resolveStaticOxcValues.js +1 -0
- package/types/transform/generators/{rewriteBarrelImports.d.ts → rewriteOxcBarrelImports.d.ts} +2 -3
- package/types/transform/generators/{rewriteBarrelImports.js → rewriteOxcBarrelImports.js} +282 -225
- package/types/transform/generators/transform.d.ts +3 -7
- package/types/transform/generators/transform.js +217 -199
- package/types/transform/generators/workflow.js +62 -45
- package/types/transform/helpers/loadWywOptions.js +115 -21
- package/types/transform/helpers/withDefaultServices.d.ts +1 -1
- package/types/transform/helpers/withDefaultServices.js +6 -44
- package/types/transform/isStaticallyEvaluatableModule.d.ts +1 -2
- package/types/transform/isStaticallyEvaluatableModule.js +125 -126
- package/types/transform/oxcBarrelManifest.d.ts +2 -0
- package/types/transform/{barrelManifest.js → oxcBarrelManifest.js} +156 -97
- package/types/transform/rootLog.js +2 -5
- package/types/transform/syntax.d.ts +38 -0
- package/types/transform/syntax.js +1 -0
- package/types/transform/types.d.ts +9 -6
- package/types/transform/types.js +1 -4
- package/types/transform.d.ts +2 -2
- package/types/transform.js +90 -101
- package/types/types.d.ts +0 -23
- package/types/types.js +1 -2
- package/types/utils/EventEmitter.d.ts +16 -1
- package/types/utils/EventEmitter.js +47 -18
- package/types/utils/ShakerMetadata.js +1 -5
- package/types/utils/TransformDiagnostics.js +3 -7
- package/types/utils/TransformMetadata.js +8 -16
- 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 -0
- package/types/utils/applyOxcProcessors.js +1 -0
- package/types/utils/collectOxcExportsAndImports.d.ts +35 -0
- package/types/utils/collectOxcExportsAndImports.js +957 -0
- 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 +4 -0
- package/types/utils/collectOxcRuntime.js +31 -0
- 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 -0
- package/types/utils/collectOxcTemplateDependencies.js +3 -0
- package/types/utils/getFileIdx.js +1 -4
- package/types/utils/getPluginKey.d.ts +5 -2
- package/types/utils/getPluginKey.js +2 -6
- package/types/utils/getVisitorKeys.d.ts +4 -4
- package/types/utils/getVisitorKeys.js +9 -6
- package/types/utils/hasCachedWywPrevalExport.d.ts +14 -0
- package/types/utils/hasCachedWywPrevalExport.js +30 -0
- package/types/utils/hasWywPreval.js +1 -4
- package/types/utils/importOverrides.js +17 -27
- package/types/utils/isNode.d.ts +2 -2
- package/types/utils/isNode.js +2 -6
- package/types/utils/isNotNull.js +1 -4
- package/types/utils/isSerializable.js +3 -6
- 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/oxcAstService.d.ts +11 -0
- package/types/utils/oxcAstService.js +79 -0
- package/types/utils/oxcEmit.d.ts +19 -0
- package/types/utils/oxcEmit.js +506 -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 +4 -0
- package/types/utils/oxcPreevalStage.js +40 -0
- package/types/utils/oxcPreevalTransforms.d.ts +13 -0
- package/types/utils/oxcPreevalTransforms.js +1192 -0
- package/types/utils/oxcShaker.d.ts +13 -0
- package/types/utils/oxcShaker.js +751 -0
- package/types/utils/parseOxc.d.ts +11 -0
- package/types/utils/parseOxc.js +38 -0
- package/types/utils/parseRequest.js +2 -7
- package/types/utils/peek.js +1 -5
- package/types/utils/processorLookup.d.ts +8 -0
- package/types/utils/processorLookup.js +135 -0
- package/types/utils/processorStaticSemantics.d.ts +13 -0
- package/types/utils/processorStaticSemantics.js +191 -0
- package/types/utils/resolveWithConditions.d.ts +12 -0
- package/types/utils/resolveWithConditions.js +103 -0
- package/types/vm/createVmContext.d.ts +2 -2
- package/types/vm/createVmContext.js +25 -62
- package/types/vm/process.js +20 -26
- package/esm/babel.js +0 -2
- package/esm/babel.js.map +0 -1
- package/esm/options/buildOptions.js +0 -168
- package/esm/options/buildOptions.js.map +0 -1
- package/esm/options/buildOptions.test.js +0 -138
- package/esm/options/buildOptions.test.js.map +0 -1
- package/esm/options/loadBabelOptions.js +0 -24
- package/esm/options/loadBabelOptions.js.map +0 -1
- package/esm/plugins/babel-transform.js +0 -53
- package/esm/plugins/babel-transform.js.map +0 -1
- package/esm/plugins/collector.js +0 -60
- package/esm/plugins/collector.js.map +0 -1
- package/esm/plugins/dynamic-import.js +0 -56
- package/esm/plugins/dynamic-import.js.map +0 -1
- package/esm/plugins/preeval.js +0 -73
- package/esm/plugins/preeval.js.map +0 -1
- package/esm/plugins/shaker.js +0 -680
- package/esm/plugins/shaker.js.map +0 -1
- package/esm/transform/barrelManifest.js +0 -291
- package/esm/transform/barrelManifest.js.map +0 -1
- package/esm/transform/generators/explodeReexports.js +0 -64
- package/esm/transform/generators/explodeReexports.js.map +0 -1
- package/esm/transform/generators/rewriteBarrelImports.js +0 -733
- package/esm/transform/generators/rewriteBarrelImports.js.map +0 -1
- package/esm/utils/addIdentifierToWywPreval.js +0 -68
- package/esm/utils/addIdentifierToWywPreval.js.map +0 -1
- package/esm/utils/collectExportsAndImports.js +0 -1157
- package/esm/utils/collectExportsAndImports.js.map +0 -1
- package/esm/utils/collectTemplateDependencies.js +0 -228
- package/esm/utils/collectTemplateDependencies.js.map +0 -1
- package/esm/utils/createId.js +0 -6
- package/esm/utils/createId.js.map +0 -1
- package/esm/utils/findIdentifiers.js +0 -62
- package/esm/utils/findIdentifiers.js.map +0 -1
- package/esm/utils/getConstantStringValue.js +0 -58
- package/esm/utils/getConstantStringValue.js.map +0 -1
- package/esm/utils/getMemberExpressionPropertyName.js +0 -11
- package/esm/utils/getMemberExpressionPropertyName.js.map +0 -1
- package/esm/utils/getScope.js +0 -6
- package/esm/utils/getScope.js.map +0 -1
- package/esm/utils/getSource.js +0 -15
- package/esm/utils/getSource.js.map +0 -1
- package/esm/utils/getTagProcessor.js +0 -404
- package/esm/utils/getTagProcessor.js.map +0 -1
- package/esm/utils/isExports.js +0 -22
- package/esm/utils/isExports.js.map +0 -1
- package/esm/utils/isGlobal.js +0 -6
- package/esm/utils/isGlobal.js.map +0 -1
- package/esm/utils/isNodePath.js +0 -4
- package/esm/utils/isNodePath.js.map +0 -1
- package/esm/utils/isRemoved.js +0 -46
- package/esm/utils/isRemoved.js.map +0 -1
- package/esm/utils/isRequire.js +0 -13
- package/esm/utils/isRequire.js.map +0 -1
- package/esm/utils/isTypedNode.js +0 -6
- package/esm/utils/isTypedNode.js.map +0 -1
- package/esm/utils/isUnnecessaryReactCall.js +0 -72
- package/esm/utils/isUnnecessaryReactCall.js.map +0 -1
- package/esm/utils/removeDangerousCode.js +0 -276
- package/esm/utils/removeDangerousCode.js.map +0 -1
- package/esm/utils/replaceImportMetaEnv.js +0 -44
- package/esm/utils/replaceImportMetaEnv.js.map +0 -1
- package/esm/utils/scopeHelpers.js +0 -527
- package/esm/utils/scopeHelpers.js.map +0 -1
- package/esm/utils/traversalCache.js +0 -23
- package/esm/utils/traversalCache.js.map +0 -1
- package/esm/utils/unwrapExpression.js +0 -18
- package/esm/utils/unwrapExpression.js.map +0 -1
- package/esm/utils/unwrapSequence.js +0 -14
- package/esm/utils/unwrapSequence.js.map +0 -1
- package/esm/utils/valueToLiteral.js +0 -59
- package/esm/utils/valueToLiteral.js.map +0 -1
- package/esm/utils/visitors/JSXElementsRemover.js +0 -51
- package/esm/utils/visitors/JSXElementsRemover.js.map +0 -1
- package/lib/babel.js +0 -2
- package/lib/babel.js.map +0 -1
- package/lib/cache.js +0 -308
- package/lib/cache.js.map +0 -1
- package/lib/debug/fileReporter.js +0 -153
- package/lib/debug/fileReporter.js.map +0 -1
- package/lib/evaluators/index.js +0 -20
- package/lib/evaluators/index.js.map +0 -1
- package/lib/index.js +0 -286
- package/lib/index.js.map +0 -1
- package/lib/module.js +0 -552
- package/lib/module.js.map +0 -1
- package/lib/options/buildOptions.js +0 -176
- package/lib/options/buildOptions.js.map +0 -1
- package/lib/options/buildOptions.test.js +0 -141
- package/lib/options/buildOptions.test.js.map +0 -1
- package/lib/options/loadBabelOptions.js +0 -31
- package/lib/options/loadBabelOptions.js.map +0 -1
- package/lib/plugins/babel-transform.js +0 -60
- package/lib/plugins/babel-transform.js.map +0 -1
- package/lib/plugins/collector.js +0 -70
- package/lib/plugins/collector.js.map +0 -1
- package/lib/plugins/dynamic-import.js +0 -61
- package/lib/plugins/dynamic-import.js.map +0 -1
- package/lib/plugins/preeval.js +0 -81
- package/lib/plugins/preeval.js.map +0 -1
- package/lib/plugins/shaker.js +0 -691
- package/lib/plugins/shaker.js.map +0 -1
- package/lib/shaker.js +0 -95
- package/lib/shaker.js.map +0 -1
- package/lib/transform/BaseEntrypoint.js +0 -179
- package/lib/transform/BaseEntrypoint.js.map +0 -1
- package/lib/transform/Entrypoint.helpers.js +0 -279
- package/lib/transform/Entrypoint.helpers.js.map +0 -1
- package/lib/transform/Entrypoint.js +0 -289
- package/lib/transform/Entrypoint.js.map +0 -1
- package/lib/transform/Entrypoint.types.js +0 -2
- package/lib/transform/Entrypoint.types.js.map +0 -1
- package/lib/transform/EvaluatedEntrypoint.js +0 -13
- package/lib/transform/EvaluatedEntrypoint.js.map +0 -1
- package/lib/transform/actions/AbortError.js +0 -16
- package/lib/transform/actions/AbortError.js.map +0 -1
- package/lib/transform/actions/BaseAction.js +0 -150
- package/lib/transform/actions/BaseAction.js.map +0 -1
- package/lib/transform/actions/UnprocessedEntrypointError.js +0 -16
- package/lib/transform/actions/UnprocessedEntrypointError.js.map +0 -1
- package/lib/transform/actions/actionRunner.js +0 -82
- package/lib/transform/actions/actionRunner.js.map +0 -1
- package/lib/transform/actions/types.js +0 -2
- package/lib/transform/actions/types.js.map +0 -1
- package/lib/transform/barrelManifest.js +0 -300
- package/lib/transform/barrelManifest.js.map +0 -1
- package/lib/transform/generators/baseProcessingHandlers.js +0 -27
- package/lib/transform/generators/baseProcessingHandlers.js.map +0 -1
- package/lib/transform/generators/collect.js +0 -66
- package/lib/transform/generators/collect.js.map +0 -1
- package/lib/transform/generators/createStylisPreprocessor.js +0 -372
- package/lib/transform/generators/createStylisPreprocessor.js.map +0 -1
- package/lib/transform/generators/evalFile.js +0 -57
- package/lib/transform/generators/evalFile.js.map +0 -1
- package/lib/transform/generators/explodeReexports.js +0 -71
- package/lib/transform/generators/explodeReexports.js.map +0 -1
- package/lib/transform/generators/extract.js +0 -102
- package/lib/transform/generators/extract.js.map +0 -1
- package/lib/transform/generators/getExports.js +0 -85
- package/lib/transform/generators/getExports.js.map +0 -1
- package/lib/transform/generators/index.js +0 -19
- package/lib/transform/generators/index.js.map +0 -1
- package/lib/transform/generators/processEntrypoint.js +0 -76
- package/lib/transform/generators/processEntrypoint.js.map +0 -1
- package/lib/transform/generators/processImports.js +0 -82
- package/lib/transform/generators/processImports.js.map +0 -1
- package/lib/transform/generators/resolveImports.js +0 -221
- package/lib/transform/generators/resolveImports.js.map +0 -1
- package/lib/transform/generators/rewriteBarrelImports.js +0 -743
- package/lib/transform/generators/rewriteBarrelImports.js.map +0 -1
- package/lib/transform/generators/transform.js +0 -272
- package/lib/transform/generators/transform.js.map +0 -1
- package/lib/transform/generators/workflow.js +0 -100
- package/lib/transform/generators/workflow.js.map +0 -1
- package/lib/transform/helpers/loadWywOptions.js +0 -88
- package/lib/transform/helpers/loadWywOptions.js.map +0 -1
- package/lib/transform/helpers/withDefaultServices.js +0 -31
- package/lib/transform/helpers/withDefaultServices.js.map +0 -1
- package/lib/transform/isStaticallyEvaluatableModule.js +0 -159
- package/lib/transform/isStaticallyEvaluatableModule.js.map +0 -1
- package/lib/transform/rootLog.js +0 -9
- package/lib/transform/rootLog.js.map +0 -1
- package/lib/transform/types.js +0 -8
- package/lib/transform/types.js.map +0 -1
- package/lib/transform.js +0 -160
- package/lib/transform.js.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/utils/EventEmitter.js +0 -61
- package/lib/utils/EventEmitter.js.map +0 -1
- package/lib/utils/ShakerMetadata.js +0 -9
- package/lib/utils/ShakerMetadata.js.map +0 -1
- package/lib/utils/TransformDiagnostics.js +0 -20
- package/lib/utils/TransformDiagnostics.js.map +0 -1
- package/lib/utils/TransformMetadata.js +0 -45
- package/lib/utils/TransformMetadata.js.map +0 -1
- package/lib/utils/addIdentifierToWywPreval.js +0 -75
- package/lib/utils/addIdentifierToWywPreval.js.map +0 -1
- package/lib/utils/collectExportsAndImports.js +0 -1173
- package/lib/utils/collectExportsAndImports.js.map +0 -1
- package/lib/utils/collectTemplateDependencies.js +0 -242
- package/lib/utils/collectTemplateDependencies.js.map +0 -1
- package/lib/utils/createId.js +0 -13
- package/lib/utils/createId.js.map +0 -1
- package/lib/utils/dispose-polyfill.js +0 -9
- package/lib/utils/dispose-polyfill.js.map +0 -1
- package/lib/utils/findIdentifiers.js +0 -73
- package/lib/utils/findIdentifiers.js.map +0 -1
- package/lib/utils/getConstantStringValue.js +0 -66
- package/lib/utils/getConstantStringValue.js.map +0 -1
- package/lib/utils/getFileIdx.js +0 -16
- package/lib/utils/getFileIdx.js.map +0 -1
- package/lib/utils/getMemberExpressionPropertyName.js +0 -18
- package/lib/utils/getMemberExpressionPropertyName.js.map +0 -1
- package/lib/utils/getPluginKey.js +0 -21
- package/lib/utils/getPluginKey.js.map +0 -1
- package/lib/utils/getScope.js +0 -12
- package/lib/utils/getScope.js.map +0 -1
- package/lib/utils/getSource.js +0 -24
- package/lib/utils/getSource.js.map +0 -1
- package/lib/utils/getTagProcessor.js +0 -424
- package/lib/utils/getTagProcessor.js.map +0 -1
- package/lib/utils/getVisitorKeys.js +0 -11
- package/lib/utils/getVisitorKeys.js.map +0 -1
- package/lib/utils/hasWywPreval.js +0 -13
- package/lib/utils/hasWywPreval.js.map +0 -1
- package/lib/utils/importOverrides.js +0 -119
- package/lib/utils/importOverrides.js.map +0 -1
- package/lib/utils/isExports.js +0 -27
- package/lib/utils/isExports.js.map +0 -1
- package/lib/utils/isGlobal.js +0 -13
- package/lib/utils/isGlobal.js.map +0 -1
- package/lib/utils/isNode.js +0 -9
- package/lib/utils/isNode.js.map +0 -1
- package/lib/utils/isNodePath.js +0 -10
- package/lib/utils/isNodePath.js.map +0 -1
- package/lib/utils/isNotNull.js +0 -10
- package/lib/utils/isNotNull.js.map +0 -1
- package/lib/utils/isRemoved.js +0 -52
- package/lib/utils/isRemoved.js.map +0 -1
- package/lib/utils/isRequire.js +0 -18
- package/lib/utils/isRequire.js.map +0 -1
- package/lib/utils/isSerializable.js +0 -19
- package/lib/utils/isSerializable.js.map +0 -1
- package/lib/utils/isTypedNode.js +0 -13
- package/lib/utils/isTypedNode.js.map +0 -1
- package/lib/utils/isUnnecessaryReactCall.js +0 -81
- package/lib/utils/isUnnecessaryReactCall.js.map +0 -1
- package/lib/utils/parseRequest.js +0 -37
- package/lib/utils/parseRequest.js.map +0 -1
- package/lib/utils/peek.js +0 -9
- package/lib/utils/peek.js.map +0 -1
- package/lib/utils/removeDangerousCode.js +0 -284
- package/lib/utils/removeDangerousCode.js.map +0 -1
- package/lib/utils/replaceImportMetaEnv.js +0 -50
- package/lib/utils/replaceImportMetaEnv.js.map +0 -1
- package/lib/utils/scopeHelpers.js +0 -557
- package/lib/utils/scopeHelpers.js.map +0 -1
- package/lib/utils/traversalCache.js +0 -31
- package/lib/utils/traversalCache.js.map +0 -1
- package/lib/utils/unwrapExpression.js +0 -25
- package/lib/utils/unwrapExpression.js.map +0 -1
- package/lib/utils/unwrapSequence.js +0 -20
- package/lib/utils/unwrapSequence.js.map +0 -1
- package/lib/utils/valueToLiteral.js +0 -65
- package/lib/utils/valueToLiteral.js.map +0 -1
- package/lib/utils/visitors/JSXElementsRemover.js +0 -57
- package/lib/utils/visitors/JSXElementsRemover.js.map +0 -1
- package/lib/vm/createVmContext.js +0 -166
- package/lib/vm/createVmContext.js.map +0 -1
- package/lib/vm/process.js +0 -38
- package/lib/vm/process.js.map +0 -1
- package/types/babel.d.ts +0 -2
- package/types/babel.js +0 -2
- package/types/options/buildOptions.d.ts +0 -6
- package/types/options/buildOptions.js +0 -178
- package/types/options/loadBabelOptions.d.ts +0 -3
- package/types/options/loadBabelOptions.js +0 -26
- package/types/plugins/babel-transform.d.ts +0 -4
- package/types/plugins/babel-transform.js +0 -49
- package/types/plugins/collector.d.ts +0 -23
- package/types/plugins/collector.js +0 -62
- package/types/plugins/dynamic-import.d.ts +0 -6
- package/types/plugins/dynamic-import.js +0 -60
- package/types/plugins/preeval.d.ts +0 -16
- package/types/plugins/preeval.js +0 -69
- package/types/plugins/shaker.d.ts +0 -14
- package/types/plugins/shaker.js +0 -724
- package/types/transform/generators/explodeReexports.d.ts +0 -7
- package/types/transform/generators/explodeReexports.js +0 -65
- package/types/utils/addIdentifierToWywPreval.d.ts +0 -4
- package/types/utils/addIdentifierToWywPreval.js +0 -74
- package/types/utils/collectExportsAndImports.d.ts +0 -31
- package/types/utils/collectExportsAndImports.js +0 -1147
- package/types/utils/collectTemplateDependencies.d.ts +0 -17
- package/types/utils/collectTemplateDependencies.js +0 -220
- package/types/utils/createId.d.ts +0 -2
- package/types/utils/createId.js +0 -9
- package/types/utils/findIdentifiers.d.ts +0 -6
- package/types/utils/findIdentifiers.js +0 -67
- package/types/utils/getConstantStringValue.d.ts +0 -2
- package/types/utils/getConstantStringValue.js +0 -94
- package/types/utils/getMemberExpressionPropertyName.d.ts +0 -2
- package/types/utils/getMemberExpressionPropertyName.js +0 -46
- package/types/utils/getScope.d.ts +0 -2
- package/types/utils/getScope.js +0 -10
- package/types/utils/getSource.d.ts +0 -2
- package/types/utils/getSource.js +0 -22
- package/types/utils/getTagProcessor.d.ts +0 -13
- package/types/utils/getTagProcessor.js +0 -411
- package/types/utils/isExports.d.ts +0 -6
- package/types/utils/isExports.js +0 -19
- package/types/utils/isGlobal.d.ts +0 -2
- package/types/utils/isGlobal.js +0 -9
- package/types/utils/isNodePath.d.ts +0 -3
- package/types/utils/isNodePath.js +0 -6
- package/types/utils/isRemoved.d.ts +0 -5
- package/types/utils/isRemoved.js +0 -41
- package/types/utils/isRequire.d.ts +0 -6
- package/types/utils/isRequire.js +0 -14
- package/types/utils/isTypedNode.d.ts +0 -5
- package/types/utils/isTypedNode.js +0 -9
- package/types/utils/isUnnecessaryReactCall.d.ts +0 -3
- package/types/utils/isUnnecessaryReactCall.js +0 -75
- package/types/utils/removeDangerousCode.d.ts +0 -4
- package/types/utils/removeDangerousCode.js +0 -326
- package/types/utils/replaceImportMetaEnv.d.ts +0 -3
- package/types/utils/replaceImportMetaEnv.js +0 -39
- package/types/utils/scopeHelpers.d.ts +0 -12
- package/types/utils/scopeHelpers.js +0 -580
- package/types/utils/traversalCache.d.ts +0 -4
- package/types/utils/traversalCache.js +0 -27
- package/types/utils/unwrapExpression.d.ts +0 -2
- package/types/utils/unwrapExpression.js +0 -57
- package/types/utils/unwrapSequence.d.ts +0 -8
- package/types/utils/unwrapSequence.js +0 -16
- package/types/utils/valueToLiteral.d.ts +0 -3
- package/types/utils/valueToLiteral.js +0 -63
- package/types/utils/visitors/JSXElementsRemover.d.ts +0 -3
- package/types/utils/visitors/JSXElementsRemover.js +0 -51
package/types/module.js
CHANGED
|
@@ -1,58 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* This is a custom implementation for the module system for evaluating code,
|
|
4
3
|
* used for resolving values for dependencies interpolated in `css` or `styled`.
|
|
5
4
|
*
|
|
6
5
|
* This serves 2 purposes:
|
|
7
|
-
* - Avoid leakage from evaluated code to module cache in current context
|
|
6
|
+
* - Avoid leakage from evaluated code to module cache in current context
|
|
8
7
|
* - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds
|
|
9
8
|
*
|
|
10
|
-
* We also
|
|
9
|
+
* We also store prepared evaluator code in it.
|
|
11
10
|
* We also store source maps for it to provide correct error stacktraces.
|
|
12
11
|
*
|
|
13
12
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const parseRequest_1 = require("./utils/parseRequest");
|
|
31
|
-
const createVmContext_1 = require("./vm/createVmContext");
|
|
13
|
+
import fs from 'fs';
|
|
14
|
+
import NativeModule, { createRequire } from 'module';
|
|
15
|
+
import path from 'path';
|
|
16
|
+
import * as vm from 'vm';
|
|
17
|
+
import { pathToFileURL } from 'url';
|
|
18
|
+
import { invariant } from 'ts-invariant';
|
|
19
|
+
import { isFeatureEnabled } from '@wyw-in-js/shared';
|
|
20
|
+
import './utils/dispose-polyfill';
|
|
21
|
+
import { Entrypoint } from './transform/Entrypoint';
|
|
22
|
+
import { getStack, isSuperSet, mergeOnly, } from './transform/Entrypoint.helpers';
|
|
23
|
+
import { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';
|
|
24
|
+
import { applyImportOverrideToOnly, getImportOverride, resolveMockSpecifier, toImportKey, } from './utils/importOverrides';
|
|
25
|
+
import { resolveWithNativeResolver } from './utils/nativeResolver';
|
|
26
|
+
import { parseRequest, stripQueryAndHash } from './utils/parseRequest';
|
|
27
|
+
import { resolveFilenameWithConditions } from './utils/resolveWithConditions';
|
|
28
|
+
import { createVmContext } from './vm/createVmContext';
|
|
32
29
|
const CJS_DEFAULT_CONDITIONS = ['require', 'node', 'default'];
|
|
33
|
-
|
|
30
|
+
const expandConditions = (conditionNames) => {
|
|
34
31
|
const result = new Set();
|
|
35
|
-
|
|
32
|
+
conditionNames.forEach((name) => {
|
|
36
33
|
if (name === '...') {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
result.add(name);
|
|
34
|
+
CJS_DEFAULT_CONDITIONS.forEach((condition) => result.add(condition));
|
|
35
|
+
return;
|
|
42
36
|
}
|
|
43
|
-
|
|
37
|
+
result.add(name);
|
|
38
|
+
});
|
|
44
39
|
return result;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (id.startsWith('.') ||
|
|
40
|
+
};
|
|
41
|
+
const isBarePackageSubpath = (id) => {
|
|
42
|
+
if (id.startsWith('.') || path.isAbsolute(id)) {
|
|
48
43
|
return false;
|
|
49
44
|
}
|
|
50
45
|
if (id.startsWith('@')) {
|
|
51
46
|
return id.split('/').length > 2;
|
|
52
47
|
}
|
|
53
48
|
return id.includes('/');
|
|
54
|
-
}
|
|
55
|
-
|
|
49
|
+
};
|
|
50
|
+
export const DefaultModuleImplementation = NativeModule;
|
|
56
51
|
// Supported node builtins based on the modules polyfilled by webpack
|
|
57
52
|
// `true` means module is polyfilled, `false` means module is empty
|
|
58
53
|
const builtins = {
|
|
@@ -95,7 +90,14 @@ const REACT_REFRESH_VIRTUAL_ID = '/@react-refresh';
|
|
|
95
90
|
const reactRefreshRuntime = {
|
|
96
91
|
createSignatureFunctionForTransform: () => () => { },
|
|
97
92
|
};
|
|
93
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
98
94
|
const NOOP = () => { };
|
|
95
|
+
const TROUBLESHOOTING_URL = 'https://wyw-in-js.dev/troubleshooting';
|
|
96
|
+
const defaultEvalOptions = {
|
|
97
|
+
errors: 'strict',
|
|
98
|
+
require: 'warn-and-run',
|
|
99
|
+
resolver: 'bundler',
|
|
100
|
+
};
|
|
99
101
|
const browserOnlyEvalHintTriggers = [
|
|
100
102
|
'window is not defined',
|
|
101
103
|
"evaluating 'window",
|
|
@@ -117,9 +119,14 @@ const getBrowserOnlyEvalHint = (error) => {
|
|
|
117
119
|
'This usually means browser-only code ran during build-time evaluation.',
|
|
118
120
|
'Move browser-only initialization out of evaluated modules, or mock the import via `importOverrides`.',
|
|
119
121
|
"Example: importOverrides: { 'msw/browser': { mock: './src/__mocks__/msw-browser.js' } }",
|
|
122
|
+
`Docs: ${TROUBLESHOOTING_URL}`,
|
|
120
123
|
].join('\n');
|
|
121
124
|
};
|
|
122
125
|
const warnedUnknownImportsByServices = new WeakMap();
|
|
126
|
+
const getEvalOptions = (services) => ({
|
|
127
|
+
...defaultEvalOptions,
|
|
128
|
+
...(services.options.pluginOptions.eval ?? {}),
|
|
129
|
+
});
|
|
123
130
|
function emitWarning(services, message) {
|
|
124
131
|
if (services.emitWarning) {
|
|
125
132
|
services.emitWarning(message);
|
|
@@ -128,6 +135,11 @@ function emitWarning(services, message) {
|
|
|
128
135
|
// eslint-disable-next-line no-console
|
|
129
136
|
console.warn(message);
|
|
130
137
|
}
|
|
138
|
+
function emitEvalWarning(services, warning) {
|
|
139
|
+
const { onWarn } = getEvalOptions(services);
|
|
140
|
+
onWarn?.(warning);
|
|
141
|
+
emitWarning(services, warning.message);
|
|
142
|
+
}
|
|
131
143
|
function getWarnedUnknownImports(services) {
|
|
132
144
|
const cached = warnedUnknownImportsByServices.get(services);
|
|
133
145
|
if (cached) {
|
|
@@ -144,16 +156,48 @@ function getUncached(cached, test) {
|
|
|
144
156
|
}
|
|
145
157
|
return test.filter((t) => !cachedSet.has(t));
|
|
146
158
|
}
|
|
147
|
-
function resolve(id) {
|
|
148
|
-
const { resolved } = this.resolveDependency(id);
|
|
149
|
-
(0, ts_invariant_1.invariant)(resolved, `Unable to resolve "${id}"`);
|
|
150
|
-
return resolved;
|
|
151
|
-
}
|
|
152
159
|
const defaultImportLoaders = {
|
|
153
160
|
raw: 'raw',
|
|
154
161
|
url: 'url',
|
|
155
162
|
};
|
|
156
|
-
|
|
163
|
+
const buildModulePreamble = (id) => {
|
|
164
|
+
const payload = JSON.stringify(id);
|
|
165
|
+
return [
|
|
166
|
+
`const __wyw_module = __wyw_getModule(${payload});`,
|
|
167
|
+
`let exports = __wyw_module.exports;`,
|
|
168
|
+
`const module = __wyw_module.module;`,
|
|
169
|
+
`const require = __wyw_module.require;`,
|
|
170
|
+
`const __filename = __wyw_module.filename;`,
|
|
171
|
+
`const __dirname = __wyw_module.dirname;`,
|
|
172
|
+
`const __wyw_dynamic_import = __wyw_module.dynamicImport;`,
|
|
173
|
+
``,
|
|
174
|
+
].join('\n');
|
|
175
|
+
};
|
|
176
|
+
const applyModuleNamespace = (entrypointExports, module, moduleData) => {
|
|
177
|
+
const { namespace } = module;
|
|
178
|
+
const keys = Object.keys(namespace);
|
|
179
|
+
if (keys.length === 0 && moduleData.module.exports !== moduleData.exports) {
|
|
180
|
+
return moduleData.module.exports;
|
|
181
|
+
}
|
|
182
|
+
const nextExports = entrypointExports;
|
|
183
|
+
keys.forEach((key) => {
|
|
184
|
+
nextExports[key] = namespace[key];
|
|
185
|
+
});
|
|
186
|
+
return nextExports;
|
|
187
|
+
};
|
|
188
|
+
const ensureVmModules = () => {
|
|
189
|
+
if (!vm.SourceTextModule || !vm.SyntheticModule) {
|
|
190
|
+
throw new EvalError('[wyw-in-js] vm.SourceTextModule is not available in this runtime. ' +
|
|
191
|
+
'WyW v2 uses a separate eval runner process for ESM evaluation.');
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
const getImporterDependency = (importer, specifier) => {
|
|
195
|
+
if (importer instanceof Entrypoint) {
|
|
196
|
+
return importer.getDependency(specifier);
|
|
197
|
+
}
|
|
198
|
+
return importer.dependencies.get(specifier);
|
|
199
|
+
};
|
|
200
|
+
export class Module {
|
|
157
201
|
services;
|
|
158
202
|
moduleImpl;
|
|
159
203
|
callstack = [];
|
|
@@ -166,65 +210,24 @@ class Module {
|
|
|
166
210
|
ignored;
|
|
167
211
|
isEvaluated = false;
|
|
168
212
|
parentIsIgnored;
|
|
169
|
-
require = Object.assign((id) => {
|
|
170
|
-
if (id === REACT_REFRESH_VIRTUAL_ID) {
|
|
171
|
-
this.dependencies.push(id);
|
|
172
|
-
this.debug('require', `vite virtual '${id}'`);
|
|
173
|
-
return reactRefreshRuntime;
|
|
174
|
-
}
|
|
175
|
-
if (id.startsWith(VITE_VIRTUAL_PREFIX)) {
|
|
176
|
-
this.dependencies.push(id);
|
|
177
|
-
this.debug('require', `vite virtual '${id}'`);
|
|
178
|
-
return {};
|
|
179
|
-
}
|
|
180
|
-
if (id in builtins) {
|
|
181
|
-
// The module is in the allowed list of builtin node modules
|
|
182
|
-
// Ideally we should prevent importing them, but webpack polyfills some
|
|
183
|
-
// So we check for the list of polyfills to determine which ones to support
|
|
184
|
-
if (builtins[id]) {
|
|
185
|
-
this.debug('require', `builtin '${id}'`);
|
|
186
|
-
return require(id);
|
|
187
|
-
}
|
|
188
|
-
return null;
|
|
189
|
-
}
|
|
190
|
-
// Resolve module id (and filename) relatively to parent module
|
|
191
|
-
const dependency = this.resolveDependency(id);
|
|
192
|
-
if (dependency.resolved === id && !path_1.default.isAbsolute(id)) {
|
|
193
|
-
// The module is a builtin node modules, but not in the allowed list
|
|
194
|
-
throw new Error(`Unable to import "${id}". Importing Node builtins is not supported in the sandbox.`);
|
|
195
|
-
}
|
|
196
|
-
(0, ts_invariant_1.invariant)(dependency.resolved, `Dependency ${dependency.source} cannot be resolved`);
|
|
197
|
-
const loaded = this.loadByImportLoaders(id, dependency.resolved);
|
|
198
|
-
if (loaded.handled) {
|
|
199
|
-
this.dependencies.push(id);
|
|
200
|
-
this.debug('require', `${id} -> ${dependency.resolved} (loader)`);
|
|
201
|
-
return loaded.value;
|
|
202
|
-
}
|
|
203
|
-
this.dependencies.push(id);
|
|
204
|
-
this.debug('require', `${id} -> ${dependency.resolved}`);
|
|
205
|
-
const entrypoint = this.getEntrypoint(dependency.resolved, dependency.only, this.debug);
|
|
206
|
-
if (entrypoint === null) {
|
|
207
|
-
return dependency.resolved;
|
|
208
|
-
}
|
|
209
|
-
if (entrypoint.evaluated ||
|
|
210
|
-
(0, Entrypoint_helpers_1.isSuperSet)(entrypoint.evaluatedOnly, dependency.only)) {
|
|
211
|
-
return entrypoint.exports;
|
|
212
|
-
}
|
|
213
|
-
const m = this.createChild(entrypoint);
|
|
214
|
-
m.evaluate();
|
|
215
|
-
return entrypoint.exports;
|
|
216
|
-
}, {
|
|
213
|
+
require = Object.assign((id, nonLiteral) => this.requireWithFallback(id, this.entrypoint, nonLiteral), {
|
|
217
214
|
ensure: NOOP,
|
|
218
|
-
resolve:
|
|
215
|
+
resolve: (id) => this.resolveRequire(id, this.entrypoint).resolved,
|
|
219
216
|
});
|
|
220
|
-
resolve =
|
|
217
|
+
resolve = (id) => this.resolveRequire(id, this.entrypoint).resolved;
|
|
221
218
|
cache;
|
|
219
|
+
context = null;
|
|
220
|
+
teardown = null;
|
|
221
|
+
moduleCache = new Map();
|
|
222
|
+
moduleEntrypoints = new WeakMap();
|
|
223
|
+
moduleLinkPromises = new WeakMap();
|
|
224
|
+
moduleData = new Map();
|
|
222
225
|
#entrypointRef;
|
|
223
|
-
constructor(services, entrypoint, parentModule, moduleImpl =
|
|
226
|
+
constructor(services, entrypoint, parentModule, moduleImpl = DefaultModuleImplementation) {
|
|
224
227
|
this.services = services;
|
|
225
228
|
this.moduleImpl = moduleImpl;
|
|
226
229
|
this.cache = services.cache;
|
|
227
|
-
this.#entrypointRef =
|
|
230
|
+
this.#entrypointRef = isFeatureEnabled(services.options.pluginOptions.features, 'useWeakRefInEval', entrypoint.name)
|
|
228
231
|
? new WeakRef(entrypoint)
|
|
229
232
|
: entrypoint;
|
|
230
233
|
this.idx = entrypoint.idx;
|
|
@@ -254,10 +257,10 @@ class Module {
|
|
|
254
257
|
const entrypoint = this.#entrypointRef instanceof WeakRef
|
|
255
258
|
? this.#entrypointRef.deref()
|
|
256
259
|
: this.#entrypointRef;
|
|
257
|
-
|
|
260
|
+
invariant(entrypoint, `Module ${this.idx} is disposed`);
|
|
258
261
|
return entrypoint;
|
|
259
262
|
}
|
|
260
|
-
evaluate() {
|
|
263
|
+
async evaluate() {
|
|
261
264
|
const { entrypoint } = this;
|
|
262
265
|
entrypoint.assertTransformed();
|
|
263
266
|
const cached = this.cache.get('entrypoints', entrypoint.name);
|
|
@@ -267,7 +270,6 @@ class Module {
|
|
|
267
270
|
evaluatedCreated = true;
|
|
268
271
|
}
|
|
269
272
|
const { transformedCode: source } = entrypoint;
|
|
270
|
-
const { pluginOptions } = this.services.options;
|
|
271
273
|
if (!source) {
|
|
272
274
|
this.debug(`evaluate`, 'there is nothing to evaluate');
|
|
273
275
|
return;
|
|
@@ -279,31 +281,28 @@ class Module {
|
|
|
279
281
|
this.debug('evaluate');
|
|
280
282
|
this.debug.extend('source')('%s', source);
|
|
281
283
|
this.isEvaluated = true;
|
|
282
|
-
const filename =
|
|
284
|
+
const filename = stripQueryAndHash(this.filename);
|
|
283
285
|
if (/\.json$/.test(filename)) {
|
|
284
286
|
// For JSON files, parse it to a JS object similar to Node
|
|
285
287
|
this.exports = JSON.parse(source);
|
|
286
288
|
return;
|
|
287
289
|
}
|
|
288
|
-
const {
|
|
289
|
-
module: this,
|
|
290
|
-
exports: entrypoint.exports,
|
|
291
|
-
require: this.require,
|
|
292
|
-
__wyw_dynamic_import: async (id) => this.require(String(id)),
|
|
293
|
-
__dirname: path_1.default.dirname(filename),
|
|
294
|
-
}, pluginOptions.overrideContext);
|
|
290
|
+
const { teardown } = await this.ensureContext(filename);
|
|
295
291
|
try {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
292
|
+
const module = await this.getModuleForEntrypoint(entrypoint);
|
|
293
|
+
await this.linkModule(module);
|
|
294
|
+
await module.evaluate();
|
|
295
|
+
const exports = applyModuleNamespace(entrypoint.exports, module, this.getModuleData(entrypoint.name));
|
|
296
|
+
if (exports !== entrypoint.exports) {
|
|
297
|
+
entrypoint.exports = exports;
|
|
298
|
+
}
|
|
300
299
|
}
|
|
301
300
|
catch (e) {
|
|
302
301
|
this.isEvaluated = false;
|
|
303
302
|
if (evaluatedCreated) {
|
|
304
303
|
this.cache.add('entrypoints', entrypoint.name, cached);
|
|
305
304
|
}
|
|
306
|
-
if (
|
|
305
|
+
if (isUnprocessedEntrypointError(e)) {
|
|
307
306
|
// It will be handled by evalFile scenario
|
|
308
307
|
throw e;
|
|
309
308
|
}
|
|
@@ -321,13 +320,13 @@ class Module {
|
|
|
321
320
|
}
|
|
322
321
|
}
|
|
323
322
|
getEntrypoint(filename, only, log) {
|
|
324
|
-
const strippedFilename =
|
|
325
|
-
const extension =
|
|
323
|
+
const strippedFilename = stripQueryAndHash(filename);
|
|
324
|
+
const extension = path.extname(strippedFilename);
|
|
326
325
|
if (extension !== '.json' && !this.extensions.includes(extension)) {
|
|
327
326
|
return null;
|
|
328
327
|
}
|
|
329
328
|
let entrypoint = this.cache.get('entrypoints', filename);
|
|
330
|
-
if (entrypoint &&
|
|
329
|
+
if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {
|
|
331
330
|
if (this.cache.checkFreshness(filename, strippedFilename)) {
|
|
332
331
|
entrypoint = undefined;
|
|
333
332
|
}
|
|
@@ -342,15 +341,16 @@ class Module {
|
|
|
342
341
|
}
|
|
343
342
|
if (this.ignored) {
|
|
344
343
|
log('✅ one of the parent files has been ignored during prepare stage. Original code will be used');
|
|
345
|
-
const newEntrypoint = this.entrypoint.createChild(filename, ['*'],
|
|
344
|
+
const newEntrypoint = this.entrypoint.createChild(filename, ['*'], fs.readFileSync(strippedFilename, 'utf-8'));
|
|
346
345
|
if (newEntrypoint === 'loop') {
|
|
347
|
-
const stack =
|
|
346
|
+
const stack = getStack(this.entrypoint);
|
|
348
347
|
throw new Error(`Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`);
|
|
349
348
|
}
|
|
350
349
|
return newEntrypoint;
|
|
351
350
|
}
|
|
352
351
|
let uncachedExports = null;
|
|
353
352
|
let reprocessOnly = only;
|
|
353
|
+
let cachedSource;
|
|
354
354
|
// Requested file can be already prepared for evaluation on the stage 1
|
|
355
355
|
if (only && entrypoint) {
|
|
356
356
|
const evaluatedExports = entrypoint.evaluatedOnly?.length !== 0
|
|
@@ -362,17 +362,30 @@ class Module {
|
|
|
362
362
|
return entrypoint;
|
|
363
363
|
}
|
|
364
364
|
if (entrypoint.evaluatedOnly?.length) {
|
|
365
|
-
|
|
365
|
+
if (this.cache.checkFreshness(filename, strippedFilename)) {
|
|
366
|
+
entrypoint = undefined;
|
|
367
|
+
uncachedExports = null;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
reprocessOnly = mergeOnly(evaluatedExports, only);
|
|
371
|
+
cachedSource =
|
|
372
|
+
entrypoint.loadedAndParsed?.code ?? entrypoint.initialCode;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (entrypoint) {
|
|
376
|
+
log('❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)', uncachedExports, evaluatedExports);
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
log('❌ file has not been processed during prepare stage');
|
|
366
380
|
}
|
|
367
|
-
log('❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)', uncachedExports, evaluatedExports);
|
|
368
381
|
}
|
|
369
382
|
else {
|
|
370
383
|
log('❌ file has not been processed during prepare stage');
|
|
371
384
|
}
|
|
372
385
|
// If code wasn't extracted from cache, it indicates that we were unable
|
|
373
386
|
// to process some of the imports on stage1. Let's try to reprocess.
|
|
374
|
-
const code =
|
|
375
|
-
const newEntrypoint =
|
|
387
|
+
const code = cachedSource ?? fs.readFileSync(strippedFilename, 'utf-8');
|
|
388
|
+
const newEntrypoint = Entrypoint.createRoot(this.services, filename, reprocessOnly, code);
|
|
376
389
|
if (newEntrypoint.evaluated) {
|
|
377
390
|
log('✅ file has been already evaluated');
|
|
378
391
|
return newEntrypoint;
|
|
@@ -383,95 +396,430 @@ class Module {
|
|
|
383
396
|
}
|
|
384
397
|
return newEntrypoint;
|
|
385
398
|
}
|
|
399
|
+
async ensureContext(filename) {
|
|
400
|
+
if (this.context && this.teardown) {
|
|
401
|
+
return { context: this.context, teardown: this.teardown };
|
|
402
|
+
}
|
|
403
|
+
const evalOptions = getEvalOptions(this.services);
|
|
404
|
+
const { context, teardown } = await createVmContext(filename, this.services.options.pluginOptions.features, {
|
|
405
|
+
...(evalOptions.globals ?? {}),
|
|
406
|
+
__wyw_getModule: (id) => this.getModuleData(id),
|
|
407
|
+
}, this.services.options.pluginOptions.overrideContext);
|
|
408
|
+
this.context = context;
|
|
409
|
+
this.teardown = () => {
|
|
410
|
+
teardown();
|
|
411
|
+
this.context = null;
|
|
412
|
+
this.teardown = null;
|
|
413
|
+
};
|
|
414
|
+
return { context: this.context, teardown: this.teardown };
|
|
415
|
+
}
|
|
416
|
+
getModuleData(id) {
|
|
417
|
+
const data = this.moduleData.get(id);
|
|
418
|
+
invariant(data, `Missing module data for ${id}`);
|
|
419
|
+
return data;
|
|
420
|
+
}
|
|
421
|
+
createModuleData(id, entrypoint) {
|
|
422
|
+
const cached = this.moduleData.get(id);
|
|
423
|
+
if (cached)
|
|
424
|
+
return cached;
|
|
425
|
+
const exporter = entrypoint ?? this.entrypoint;
|
|
426
|
+
const exportsProxy = entrypoint && 'exports' in entrypoint
|
|
427
|
+
? entrypoint.exports
|
|
428
|
+
: {};
|
|
429
|
+
const moduleObj = { exports: exportsProxy };
|
|
430
|
+
const requireFn = Object.assign((request) => this.requireWithFallback(request, exporter), {
|
|
431
|
+
ensure: NOOP,
|
|
432
|
+
resolve: (request) => this.resolveRequire(request, exporter).resolved,
|
|
433
|
+
});
|
|
434
|
+
const filename = stripQueryAndHash(id);
|
|
435
|
+
const data = {
|
|
436
|
+
exports: exportsProxy,
|
|
437
|
+
module: moduleObj,
|
|
438
|
+
require: requireFn,
|
|
439
|
+
filename,
|
|
440
|
+
dirname: path.dirname(filename),
|
|
441
|
+
dynamicImport: (request) => this.dynamicImportFrom(exporter, request),
|
|
442
|
+
};
|
|
443
|
+
this.moduleData.set(id, data);
|
|
444
|
+
return data;
|
|
445
|
+
}
|
|
446
|
+
async createSourceTextModule(id, code, entrypoint) {
|
|
447
|
+
ensureVmModules();
|
|
448
|
+
const { context } = await this.ensureContext(stripQueryAndHash(id));
|
|
449
|
+
this.createModuleData(id, entrypoint);
|
|
450
|
+
const module = new vm.SourceTextModule(`${buildModulePreamble(id)}${code}`, {
|
|
451
|
+
context,
|
|
452
|
+
identifier: id,
|
|
453
|
+
initializeImportMeta: (meta, targetModule) => {
|
|
454
|
+
const identifier = typeof targetModule.identifier === 'string'
|
|
455
|
+
? targetModule.identifier
|
|
456
|
+
: id;
|
|
457
|
+
const fileId = stripQueryAndHash(identifier);
|
|
458
|
+
Object.assign(meta, {
|
|
459
|
+
url: path.isAbsolute(fileId) ? pathToFileURL(fileId).href : fileId,
|
|
460
|
+
});
|
|
461
|
+
},
|
|
462
|
+
importModuleDynamically: (specifier, referencingModule) => this.importModuleDynamically(specifier, referencingModule),
|
|
463
|
+
});
|
|
464
|
+
this.moduleCache.set(id, module);
|
|
465
|
+
if (entrypoint) {
|
|
466
|
+
this.moduleEntrypoints.set(module, entrypoint);
|
|
467
|
+
}
|
|
468
|
+
return module;
|
|
469
|
+
}
|
|
470
|
+
async createSyntheticModule(id, exportsValue) {
|
|
471
|
+
ensureVmModules();
|
|
472
|
+
const { context } = await this.ensureContext(stripQueryAndHash(id));
|
|
473
|
+
const exportNames = new Set(Object.keys(exportsValue));
|
|
474
|
+
const hasDefault = Object.prototype.hasOwnProperty.call(exportsValue, 'default');
|
|
475
|
+
if (!exportNames.has('default')) {
|
|
476
|
+
exportNames.add('default');
|
|
477
|
+
}
|
|
478
|
+
const module = new vm.SyntheticModule([...exportNames], function init() {
|
|
479
|
+
exportNames.forEach((key) => {
|
|
480
|
+
const value = key === 'default' && !hasDefault ? exportsValue : exportsValue[key];
|
|
481
|
+
this.setExport(key, value);
|
|
482
|
+
});
|
|
483
|
+
}, { context, identifier: id });
|
|
484
|
+
this.moduleCache.set(id, module);
|
|
485
|
+
return module;
|
|
486
|
+
}
|
|
487
|
+
async getVirtualModule(specifier) {
|
|
488
|
+
if (specifier === REACT_REFRESH_VIRTUAL_ID) {
|
|
489
|
+
return this.createSyntheticModule(specifier, {
|
|
490
|
+
createSignatureFunctionForTransform: reactRefreshRuntime.createSignatureFunctionForTransform,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
if (specifier.startsWith(VITE_VIRTUAL_PREFIX)) {
|
|
494
|
+
return this.createSyntheticModule(specifier, { default: {} });
|
|
495
|
+
}
|
|
496
|
+
if (specifier.startsWith('virtual:')) {
|
|
497
|
+
return this.createSyntheticModule(specifier, { default: {} });
|
|
498
|
+
}
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
async getModuleForEntrypoint(entrypoint) {
|
|
502
|
+
const cached = this.moduleCache.get(entrypoint.name);
|
|
503
|
+
if (cached)
|
|
504
|
+
return cached;
|
|
505
|
+
if (!(entrypoint instanceof Entrypoint)) {
|
|
506
|
+
return this.createSyntheticModule(entrypoint.name, entrypoint.exports);
|
|
507
|
+
}
|
|
508
|
+
entrypoint.assertTransformed();
|
|
509
|
+
const source = entrypoint.transformedCode ?? '';
|
|
510
|
+
return this.createSourceTextModule(entrypoint.name, source, entrypoint);
|
|
511
|
+
}
|
|
512
|
+
async linkModule(module) {
|
|
513
|
+
const cached = this.moduleLinkPromises.get(module);
|
|
514
|
+
if (cached) {
|
|
515
|
+
await cached;
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (module.status !== 'unlinked') {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
const linking = module.link((specifier, referencingModule) => this.getModuleForSpecifier(specifier, referencingModule, 'import'));
|
|
522
|
+
this.moduleLinkPromises.set(module, linking);
|
|
523
|
+
await linking;
|
|
524
|
+
}
|
|
525
|
+
async importModuleDynamically(specifier, referencingModule) {
|
|
526
|
+
const module = await this.getModuleForSpecifier(specifier, referencingModule, 'dynamic-import');
|
|
527
|
+
await this.linkModule(module);
|
|
528
|
+
if (module.status === 'linked') {
|
|
529
|
+
await module.evaluate();
|
|
530
|
+
}
|
|
531
|
+
return module;
|
|
532
|
+
}
|
|
533
|
+
async dynamicImportFrom(importer, id) {
|
|
534
|
+
const specifier = String(id);
|
|
535
|
+
const module = await this.getModuleForSpecifierFromEntrypoint(specifier, importer, 'dynamic-import');
|
|
536
|
+
await this.linkModule(module);
|
|
537
|
+
if (module.status === 'linked') {
|
|
538
|
+
await module.evaluate();
|
|
539
|
+
}
|
|
540
|
+
return module.namespace;
|
|
541
|
+
}
|
|
542
|
+
async getModuleForSpecifier(specifier, referencingModule, kind) {
|
|
543
|
+
const importer = this.moduleEntrypoints.get(referencingModule) ?? this.entrypoint;
|
|
544
|
+
return this.getModuleForSpecifierFromEntrypoint(specifier, importer, kind);
|
|
545
|
+
}
|
|
546
|
+
async getModuleForSpecifierFromEntrypoint(specifier, importer, kind) {
|
|
547
|
+
const virtualModule = await this.getVirtualModule(specifier);
|
|
548
|
+
if (virtualModule) {
|
|
549
|
+
return virtualModule;
|
|
550
|
+
}
|
|
551
|
+
this.dependencies.push(specifier);
|
|
552
|
+
const resolved = await this.resolveImport(specifier, importer, kind);
|
|
553
|
+
const evalOptions = getEvalOptions(this.services);
|
|
554
|
+
if (!resolved) {
|
|
555
|
+
if (evalOptions.errors === 'loose') {
|
|
556
|
+
return this.createSyntheticModule(specifier, { default: undefined });
|
|
557
|
+
}
|
|
558
|
+
throw new Error([
|
|
559
|
+
`[wyw-in-js] Unable to resolve "${specifier}" during evaluation.`,
|
|
560
|
+
``,
|
|
561
|
+
`importer: ${importer.name}`,
|
|
562
|
+
`hint: check eval.resolver/customResolver or add importOverrides for this specifier.`,
|
|
563
|
+
`docs: ${TROUBLESHOOTING_URL}`,
|
|
564
|
+
].join('\n'));
|
|
565
|
+
}
|
|
566
|
+
if (resolved.external) {
|
|
567
|
+
return this.createSyntheticModule(resolved.resolved, {
|
|
568
|
+
default: undefined,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
return this.getModuleForResolved(resolved, importer);
|
|
572
|
+
}
|
|
573
|
+
async resolveImport(specifier, importer, kind) {
|
|
574
|
+
const evalOptions = getEvalOptions(this.services);
|
|
575
|
+
if (evalOptions.customResolver) {
|
|
576
|
+
const customResolved = await evalOptions.customResolver(specifier, importer.name, kind);
|
|
577
|
+
if (customResolved) {
|
|
578
|
+
return this.applyImportOverrides({
|
|
579
|
+
source: specifier,
|
|
580
|
+
resolved: customResolved.id,
|
|
581
|
+
only: ['*'],
|
|
582
|
+
external: customResolved.external,
|
|
583
|
+
}, importer);
|
|
584
|
+
}
|
|
585
|
+
if (evalOptions.resolver === 'custom') {
|
|
586
|
+
return null;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
const resolveBundlerDependency = () => {
|
|
590
|
+
const dependency = getImporterDependency(importer, specifier);
|
|
591
|
+
if (dependency?.resolved) {
|
|
592
|
+
return {
|
|
593
|
+
source: specifier,
|
|
594
|
+
resolved: dependency.resolved,
|
|
595
|
+
only: dependency.only,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
return null;
|
|
599
|
+
};
|
|
600
|
+
if (evalOptions.resolver === 'hybrid') {
|
|
601
|
+
try {
|
|
602
|
+
return this.resolveWithNativeFallback(specifier, importer, kind, {
|
|
603
|
+
warnOnFallback: false,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
catch {
|
|
607
|
+
// Hybrid mode lets the bundler resolver handle aliases, virtual IDs,
|
|
608
|
+
// and other specifiers that the native resolver cannot resolve.
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (evalOptions.resolver === 'native') {
|
|
612
|
+
return this.resolveWithNativeFallback(specifier, importer, kind, {
|
|
613
|
+
warnOnFallback: false,
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
if (evalOptions.resolver === 'bundler' ||
|
|
617
|
+
evalOptions.resolver === 'hybrid') {
|
|
618
|
+
const dependency = resolveBundlerDependency();
|
|
619
|
+
if (dependency)
|
|
620
|
+
return dependency;
|
|
621
|
+
}
|
|
622
|
+
if (evalOptions.resolver === 'bundler' && evalOptions.require !== 'off') {
|
|
623
|
+
return this.resolveWithNativeFallback(specifier, importer, kind, {
|
|
624
|
+
warnOnFallback: true,
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
resolveRequire(specifier, importer) {
|
|
630
|
+
const dependency = getImporterDependency(importer, specifier);
|
|
631
|
+
if (dependency?.resolved) {
|
|
632
|
+
return this.applyImportOverrides({
|
|
633
|
+
source: specifier,
|
|
634
|
+
resolved: dependency.resolved,
|
|
635
|
+
only: dependency.only,
|
|
636
|
+
}, importer);
|
|
637
|
+
}
|
|
638
|
+
return this.resolveWithNativeFallback(specifier, importer, 'require', {
|
|
639
|
+
warnOnFallback: true,
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
applyImportOverrides(resolved, importer) {
|
|
643
|
+
const { root } = this.services.options;
|
|
644
|
+
const keyInfo = toImportKey({
|
|
645
|
+
source: resolved.source,
|
|
646
|
+
resolved: resolved.resolved,
|
|
647
|
+
root,
|
|
648
|
+
});
|
|
649
|
+
const override = getImportOverride(this.services.options.pluginOptions.importOverrides, keyInfo.key);
|
|
650
|
+
if (!override) {
|
|
651
|
+
return resolved;
|
|
652
|
+
}
|
|
653
|
+
let nextResolved = resolved.resolved;
|
|
654
|
+
if (override.mock) {
|
|
655
|
+
nextResolved = resolveMockSpecifier({
|
|
656
|
+
mock: override.mock,
|
|
657
|
+
importer: importer.name,
|
|
658
|
+
root,
|
|
659
|
+
stack: getStack(importer),
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
return {
|
|
663
|
+
...resolved,
|
|
664
|
+
resolved: nextResolved,
|
|
665
|
+
only: applyImportOverrideToOnly(resolved.only, override),
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
async getModuleForResolved(resolved, importer) {
|
|
669
|
+
const cached = this.moduleCache.get(resolved.resolved);
|
|
670
|
+
if (cached)
|
|
671
|
+
return cached;
|
|
672
|
+
const evalOptions = getEvalOptions(this.services);
|
|
673
|
+
if (evalOptions.customLoader) {
|
|
674
|
+
const loaded = await evalOptions.customLoader(resolved.resolved);
|
|
675
|
+
if (loaded) {
|
|
676
|
+
if (loaded.loader === 'json') {
|
|
677
|
+
const jsonValue = JSON.parse(loaded.code);
|
|
678
|
+
return this.createSyntheticModule(resolved.resolved, {
|
|
679
|
+
default: jsonValue,
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
if (loaded.loader === 'raw' || loaded.loader === 'text') {
|
|
683
|
+
return this.createSyntheticModule(resolved.resolved, {
|
|
684
|
+
default: loaded.code,
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
return this.createSourceTextModule(resolved.resolved, loaded.code, importer);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
const loaded = this.loadByImportLoaders(resolved.source, resolved.resolved, importer.name);
|
|
691
|
+
if (loaded.handled) {
|
|
692
|
+
return this.createSyntheticModule(resolved.resolved, {
|
|
693
|
+
default: loaded.value,
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
const stripped = stripQueryAndHash(resolved.resolved);
|
|
697
|
+
if (stripped.endsWith('.json')) {
|
|
698
|
+
const jsonSource = fs.readFileSync(stripped, 'utf-8');
|
|
699
|
+
return this.createSyntheticModule(resolved.resolved, {
|
|
700
|
+
default: JSON.parse(jsonSource),
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
const entrypoint = this.getEntrypoint(resolved.resolved, resolved.only, importer.log);
|
|
704
|
+
if (!entrypoint) {
|
|
705
|
+
return this.createSyntheticModule(resolved.resolved, {
|
|
706
|
+
default: resolved.resolved,
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
if ('evaluated' in entrypoint && entrypoint.evaluated) {
|
|
710
|
+
return this.createSyntheticModule(entrypoint.name, entrypoint.exports);
|
|
711
|
+
}
|
|
712
|
+
return this.getModuleForEntrypoint(entrypoint);
|
|
713
|
+
}
|
|
386
714
|
resolveWithConditions(id, parent, conditions) {
|
|
387
|
-
const resolveOptions = conditions ? { conditions } : undefined;
|
|
388
715
|
const shouldRetryWithExtensions = conditions &&
|
|
389
|
-
|
|
390
|
-
(id.startsWith('.') ||
|
|
716
|
+
path.extname(id) === '' &&
|
|
717
|
+
(id.startsWith('.') || path.isAbsolute(id) || isBarePackageSubpath(id));
|
|
391
718
|
try {
|
|
392
|
-
return this.moduleImpl
|
|
719
|
+
return resolveFilenameWithConditions(this.moduleImpl, id, parent, conditions);
|
|
393
720
|
}
|
|
394
|
-
catch (
|
|
721
|
+
catch (error) {
|
|
395
722
|
if (shouldRetryWithExtensions &&
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
// Extensionless subpath requests (e.g. "pkg/src/*" or "./src/*") may
|
|
399
|
-
// resolve to extensionless targets via conditional exports. Retry with
|
|
400
|
-
// each known extension, but never rewrite already explicit specifiers.
|
|
723
|
+
error instanceof Error &&
|
|
724
|
+
error.code === 'MODULE_NOT_FOUND') {
|
|
401
725
|
for (const ext of this.extensions) {
|
|
402
726
|
try {
|
|
403
|
-
return this.moduleImpl
|
|
727
|
+
return resolveFilenameWithConditions(this.moduleImpl, `${id}${ext}`, parent, conditions);
|
|
404
728
|
}
|
|
405
729
|
catch {
|
|
406
|
-
//
|
|
730
|
+
// Try the next supported extension.
|
|
407
731
|
}
|
|
408
732
|
}
|
|
409
733
|
}
|
|
410
|
-
throw
|
|
734
|
+
throw error;
|
|
411
735
|
}
|
|
412
736
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (cached) {
|
|
417
|
-
return cached;
|
|
418
|
-
}
|
|
419
|
-
if (!this.ignored) {
|
|
420
|
-
this.debug('❌ import has not been resolved during prepare stage. Fallback to Node.js resolver');
|
|
737
|
+
resolveWithNativeFallback = (id, importer, kind, { warnOnFallback } = { warnOnFallback: true }) => {
|
|
738
|
+
if (!this.ignored && warnOnFallback) {
|
|
739
|
+
this.debug('❌ import has not been resolved during prepare stage. Fallback to native resolver');
|
|
421
740
|
}
|
|
422
741
|
const extensions = this.moduleImpl._extensions;
|
|
423
742
|
const added = [];
|
|
424
743
|
try {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
744
|
+
const filename = importer.name;
|
|
745
|
+
const strippedId = stripQueryAndHash(id);
|
|
746
|
+
const { conditionNames, oxcOptions } = this.services.options.pluginOptions;
|
|
747
|
+
let resolved;
|
|
748
|
+
try {
|
|
749
|
+
if (this.moduleImpl === DefaultModuleImplementation) {
|
|
750
|
+
resolved = resolveWithNativeResolver({
|
|
751
|
+
conditionNames,
|
|
752
|
+
extensions: this.extensions,
|
|
753
|
+
importer: filename,
|
|
754
|
+
kind,
|
|
755
|
+
oxcOptions,
|
|
756
|
+
specifier: id,
|
|
757
|
+
});
|
|
429
758
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
759
|
+
else {
|
|
760
|
+
// Preserve the test-only custom module implementation hook.
|
|
761
|
+
this.extensions.forEach((ext) => {
|
|
762
|
+
if (ext === '.cjs' || ext === '.mjs')
|
|
763
|
+
return;
|
|
764
|
+
if (ext in extensions)
|
|
765
|
+
return;
|
|
766
|
+
extensions[ext] = NOOP;
|
|
767
|
+
added.push(ext);
|
|
768
|
+
});
|
|
769
|
+
const parent = {
|
|
770
|
+
id: filename,
|
|
771
|
+
filename,
|
|
772
|
+
paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),
|
|
773
|
+
};
|
|
774
|
+
const conditions = conditionNames?.length
|
|
775
|
+
? expandConditions(conditionNames)
|
|
776
|
+
: undefined;
|
|
777
|
+
resolved = this.resolveWithConditions(strippedId, parent, conditions);
|
|
778
|
+
const isFileSpecifier = strippedId.startsWith('.') || path.isAbsolute(strippedId);
|
|
779
|
+
if (isFileSpecifier &&
|
|
780
|
+
path.extname(strippedId) === '' &&
|
|
781
|
+
resolved.endsWith('.cjs') &&
|
|
782
|
+
fs.existsSync(`${resolved.slice(0, -4)}.js`)) {
|
|
783
|
+
resolved = `${resolved.slice(0, -4)}.js`;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
catch (error) {
|
|
788
|
+
throw new Error([
|
|
789
|
+
`[wyw-in-js] Native resolver failed during eval.`,
|
|
790
|
+
``,
|
|
791
|
+
`importer: ${filename}`,
|
|
792
|
+
`source: ${id}`,
|
|
793
|
+
``,
|
|
794
|
+
`error: ${error instanceof Error ? error.message : String(error)}`,
|
|
795
|
+
].join('\n'));
|
|
457
796
|
}
|
|
458
797
|
const { root } = this.services.options;
|
|
459
|
-
const keyInfo =
|
|
798
|
+
const keyInfo = toImportKey({
|
|
460
799
|
source: id,
|
|
461
800
|
resolved,
|
|
462
801
|
root,
|
|
463
802
|
});
|
|
464
|
-
const override =
|
|
465
|
-
const
|
|
803
|
+
const override = getImportOverride(this.services.options.pluginOptions.importOverrides, keyInfo.key);
|
|
804
|
+
const evalOptions = getEvalOptions(this.services);
|
|
805
|
+
const basePolicy = evalOptions.require === 'warn-and-run' ? 'warn' : 'error';
|
|
806
|
+
let policy = warnOnFallback
|
|
807
|
+
? override?.unknown ?? (override?.mock ? 'allow' : basePolicy)
|
|
808
|
+
: 'allow';
|
|
809
|
+
if (warnOnFallback &&
|
|
810
|
+
evalOptions.require === 'off' &&
|
|
811
|
+
policy !== 'error') {
|
|
812
|
+
policy = 'error';
|
|
813
|
+
}
|
|
466
814
|
const shouldWarn = !this.ignored && policy === 'warn';
|
|
467
815
|
let finalResolved = resolved;
|
|
468
816
|
if (override?.mock) {
|
|
469
817
|
try {
|
|
470
|
-
finalResolved =
|
|
818
|
+
finalResolved = resolveMockSpecifier({
|
|
471
819
|
mock: override.mock,
|
|
472
820
|
importer: filename,
|
|
473
821
|
root,
|
|
474
|
-
stack:
|
|
822
|
+
stack: getStack(importer),
|
|
475
823
|
});
|
|
476
824
|
}
|
|
477
825
|
catch (e) {
|
|
@@ -481,7 +829,7 @@ class Module {
|
|
|
481
829
|
}
|
|
482
830
|
if (policy === 'error') {
|
|
483
831
|
throw new Error([
|
|
484
|
-
`[wyw-in-js] Unknown import reached during eval (
|
|
832
|
+
`[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
|
|
485
833
|
``,
|
|
486
834
|
`importer: ${filename}`,
|
|
487
835
|
`source: ${id}`,
|
|
@@ -491,9 +839,10 @@ class Module {
|
|
|
491
839
|
: ``,
|
|
492
840
|
``,
|
|
493
841
|
`callstack:`,
|
|
494
|
-
...
|
|
842
|
+
...getStack(importer).map((item) => ` ${item}`),
|
|
495
843
|
``,
|
|
496
844
|
`config key: ${keyInfo.key}`,
|
|
845
|
+
`docs: ${TROUBLESHOOTING_URL}`,
|
|
497
846
|
]
|
|
498
847
|
.filter(Boolean)
|
|
499
848
|
.join('\n'));
|
|
@@ -501,8 +850,8 @@ class Module {
|
|
|
501
850
|
const warnedUnknownImports = getWarnedUnknownImports(this.services);
|
|
502
851
|
if (shouldWarn && !warnedUnknownImports.has(keyInfo.key)) {
|
|
503
852
|
warnedUnknownImports.add(keyInfo.key);
|
|
504
|
-
|
|
505
|
-
`[wyw-in-js] Unknown import reached during eval (
|
|
853
|
+
const warningMessage = [
|
|
854
|
+
`[wyw-in-js] Unknown import reached during eval (native resolver fallback)`,
|
|
506
855
|
``,
|
|
507
856
|
`importer: ${filename}`,
|
|
508
857
|
`source: ${id}`,
|
|
@@ -512,17 +861,27 @@ class Module {
|
|
|
512
861
|
: ``,
|
|
513
862
|
``,
|
|
514
863
|
`callstack:`,
|
|
515
|
-
...
|
|
864
|
+
...getStack(importer).map((item) => ` ${item}`),
|
|
516
865
|
``,
|
|
517
866
|
`config key: ${keyInfo.key}`,
|
|
518
867
|
`hint: add { importOverrides: { ${JSON.stringify(keyInfo.key)}: { unknown: 'allow' } } } to silence warnings, or use { mock } / { noShake: true } overrides.`,
|
|
868
|
+
`docs: ${TROUBLESHOOTING_URL}`,
|
|
519
869
|
]
|
|
520
870
|
.filter(Boolean)
|
|
521
|
-
.join('\n')
|
|
871
|
+
.join('\n');
|
|
872
|
+
emitEvalWarning(this.services, {
|
|
873
|
+
code: kind === 'require' ? 'require-fallback' : 'resolve-fallback',
|
|
874
|
+
message: warningMessage,
|
|
875
|
+
importer: filename,
|
|
876
|
+
specifier: id,
|
|
877
|
+
resolved: resolved ?? null,
|
|
878
|
+
callstack: getStack(importer),
|
|
879
|
+
hint: `Use importOverrides or eval.require settings to avoid fallback.`,
|
|
880
|
+
});
|
|
522
881
|
}
|
|
523
882
|
return {
|
|
524
883
|
source: id,
|
|
525
|
-
only:
|
|
884
|
+
only: applyImportOverrideToOnly(['*'], override),
|
|
526
885
|
resolved: finalResolved,
|
|
527
886
|
};
|
|
528
887
|
}
|
|
@@ -531,15 +890,78 @@ class Module {
|
|
|
531
890
|
added.forEach((ext) => delete extensions[ext]);
|
|
532
891
|
}
|
|
533
892
|
};
|
|
893
|
+
requireWithFallback(id, importer, nonLiteral = false) {
|
|
894
|
+
const evalOptions = getEvalOptions(this.services);
|
|
895
|
+
if (nonLiteral || typeof id !== 'string') {
|
|
896
|
+
if (evalOptions.errors === 'strict') {
|
|
897
|
+
throw new Error(`[wyw-in-js] Non-literal require() is not supported during eval.\n` +
|
|
898
|
+
`importer: ${importer.name}\n` +
|
|
899
|
+
`hint: make it a string literal or mock the import via importOverrides.`);
|
|
900
|
+
}
|
|
901
|
+
emitEvalWarning(this.services, {
|
|
902
|
+
code: 'require-error',
|
|
903
|
+
message: '[wyw-in-js] Non-literal require() reached during eval (eval.errors: "loose").',
|
|
904
|
+
importer: importer.name,
|
|
905
|
+
});
|
|
906
|
+
return {};
|
|
907
|
+
}
|
|
908
|
+
const specifier = id;
|
|
909
|
+
if (id === REACT_REFRESH_VIRTUAL_ID) {
|
|
910
|
+
this.dependencies.push(id);
|
|
911
|
+
this.debug('require', `vite virtual '${id}'`);
|
|
912
|
+
return reactRefreshRuntime;
|
|
913
|
+
}
|
|
914
|
+
if (id.startsWith(VITE_VIRTUAL_PREFIX)) {
|
|
915
|
+
this.dependencies.push(id);
|
|
916
|
+
this.debug('require', `vite virtual '${id}'`);
|
|
917
|
+
return {};
|
|
918
|
+
}
|
|
919
|
+
const normalizedId = specifier.startsWith('node:')
|
|
920
|
+
? specifier.slice(5)
|
|
921
|
+
: specifier;
|
|
922
|
+
if (NativeModule.builtinModules?.includes(normalizedId) ||
|
|
923
|
+
NativeModule.builtinModules?.includes(`node:${normalizedId}`)) {
|
|
924
|
+
if (normalizedId in builtins) {
|
|
925
|
+
if (builtins[normalizedId]) {
|
|
926
|
+
this.debug('require', `builtin '${normalizedId}'`);
|
|
927
|
+
return nodeRequire(normalizedId);
|
|
928
|
+
}
|
|
929
|
+
return null;
|
|
930
|
+
}
|
|
931
|
+
throw new Error(`Unable to import "${normalizedId}". Importing Node builtins is not supported in the sandbox.`);
|
|
932
|
+
}
|
|
933
|
+
const dependency = this.resolveRequire(specifier, importer);
|
|
934
|
+
const loaded = this.loadByImportLoaders(specifier, dependency.resolved, importer.name);
|
|
935
|
+
if (loaded.handled) {
|
|
936
|
+
this.dependencies.push(id);
|
|
937
|
+
this.debug('require', `${id} -> ${dependency.resolved} (loader)`);
|
|
938
|
+
return loaded.value;
|
|
939
|
+
}
|
|
940
|
+
const stripped = stripQueryAndHash(dependency.resolved);
|
|
941
|
+
const extension = path.extname(stripped);
|
|
942
|
+
if (extension &&
|
|
943
|
+
extension !== '.json' &&
|
|
944
|
+
!this.extensions.includes(extension)) {
|
|
945
|
+
this.dependencies.push(id);
|
|
946
|
+
this.debug('require', `${id} -> ${dependency.resolved} (asset)`);
|
|
947
|
+
return stripped;
|
|
948
|
+
}
|
|
949
|
+
if (this.services.cache.consumeInvalidation(dependency.resolved)) {
|
|
950
|
+
delete nodeRequire.cache[dependency.resolved];
|
|
951
|
+
}
|
|
952
|
+
this.dependencies.push(id);
|
|
953
|
+
this.debug('require', `${id} -> ${dependency.resolved}`);
|
|
954
|
+
return nodeRequire(dependency.resolved);
|
|
955
|
+
}
|
|
534
956
|
createChild(entrypoint) {
|
|
535
957
|
return new Module(this.services, entrypoint, this, this.moduleImpl);
|
|
536
958
|
}
|
|
537
|
-
loadByImportLoaders(request, resolved) {
|
|
959
|
+
loadByImportLoaders(request, resolved, importer) {
|
|
538
960
|
const { pluginOptions } = this.services.options;
|
|
539
961
|
const importLoaders = pluginOptions.importLoaders === undefined
|
|
540
962
|
? defaultImportLoaders
|
|
541
963
|
: { ...defaultImportLoaders, ...pluginOptions.importLoaders };
|
|
542
|
-
const { query, hash } =
|
|
964
|
+
const { query, hash } = parseRequest(request);
|
|
543
965
|
if (!query)
|
|
544
966
|
return { handled: false, value: undefined };
|
|
545
967
|
const params = new URLSearchParams(query);
|
|
@@ -547,21 +969,21 @@ class Module {
|
|
|
547
969
|
if (!matchedKey)
|
|
548
970
|
return { handled: false, value: undefined };
|
|
549
971
|
const loader = importLoaders[matchedKey];
|
|
550
|
-
const filename =
|
|
551
|
-
const
|
|
552
|
-
const importerDir =
|
|
972
|
+
const filename = stripQueryAndHash(resolved);
|
|
973
|
+
const importerFilename = stripQueryAndHash(importer);
|
|
974
|
+
const importerDir = path.dirname(importerFilename);
|
|
553
975
|
const toUrl = () => {
|
|
554
|
-
const relative =
|
|
976
|
+
const relative = path
|
|
555
977
|
.relative(importerDir, filename)
|
|
556
|
-
.replace(/\\/g,
|
|
557
|
-
if (relative.startsWith('.') ||
|
|
978
|
+
.replace(/\\/g, path.posix.sep);
|
|
979
|
+
if (relative.startsWith('.') || path.isAbsolute(relative)) {
|
|
558
980
|
return relative;
|
|
559
981
|
}
|
|
560
982
|
return `./${relative}`;
|
|
561
983
|
};
|
|
562
|
-
const readFile = () =>
|
|
984
|
+
const readFile = () => fs.readFileSync(filename, 'utf-8');
|
|
563
985
|
const context = {
|
|
564
|
-
importer,
|
|
986
|
+
importer: importerFilename,
|
|
565
987
|
request,
|
|
566
988
|
resolved,
|
|
567
989
|
filename,
|
|
@@ -583,4 +1005,3 @@ class Module {
|
|
|
583
1005
|
return { handled: false, value: undefined };
|
|
584
1006
|
}
|
|
585
1007
|
}
|
|
586
|
-
exports.Module = Module;
|