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