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