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