@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/shaker.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { Evaluator, EvaluatorConfig } from '@wyw-in-js/shared';
|
|
4
|
-
type ShakerStageResult = [
|
|
5
|
-
ast: File,
|
|
6
|
-
code: string,
|
|
7
|
-
imports: Map<string, string[]> | null
|
|
8
|
-
];
|
|
9
|
-
export declare const shakeToESM: (evalConfig: TransformOptions, ast: File, code: string, config: EvaluatorConfig, babel: Parameters<Evaluator>[4]) => ShakerStageResult;
|
|
10
|
-
export declare const emitCommonJS: (evalConfig: TransformOptions, ast: File, code: string, babel: Parameters<Evaluator>[4]) => [ast: File, code: string];
|
|
1
|
+
import type { Evaluator } from '@wyw-in-js/shared';
|
|
2
|
+
export declare const oxcShaker: Evaluator;
|
|
11
3
|
export declare const shaker: Evaluator;
|
|
12
4
|
export default shaker;
|
package/types/shaker.js
CHANGED
|
@@ -1,100 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const pluginKey = (0, getPluginKey_1.getPluginKey)(plugin);
|
|
12
|
-
return pluginKey ? list.some((i) => pluginKey.includes(i)) : false;
|
|
13
|
-
};
|
|
14
|
-
const isCommonJSPlugin = (plugin) => (0, getPluginKey_1.getPluginKey)(plugin) === 'transform-modules-commonjs';
|
|
15
|
-
const safeResolve = (id, paths) => {
|
|
16
|
-
try {
|
|
17
|
-
return require.resolve(id, {
|
|
18
|
-
paths: paths.filter((i) => i !== null),
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const ensureTypescriptPlugin = (plugins, evalConfig) => {
|
|
26
|
-
if (!evalConfig.filename?.endsWith('.ts') &&
|
|
27
|
-
!evalConfig.filename?.endsWith('.tsx') &&
|
|
28
|
-
!evalConfig.filename?.endsWith('.mts') &&
|
|
29
|
-
!evalConfig.filename?.endsWith('.cts')) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const hasTypescriptPlugin = plugins.some((i) => (0, getPluginKey_1.getPluginKey)(i) === 'transform-typescript');
|
|
33
|
-
if (hasTypescriptPlugin) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const preset = safeResolve('@babel/preset-typescript', [evalConfig.filename]);
|
|
37
|
-
const plugin = safeResolve('@babel/plugin-transform-typescript', [
|
|
38
|
-
evalConfig.filename,
|
|
39
|
-
preset,
|
|
40
|
-
]);
|
|
41
|
-
if (plugin) {
|
|
42
|
-
plugins.push([plugin, { allowDeclareFields: true }]);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const createShakerPlugins = (evalConfig, config, includeCommonJS) => {
|
|
46
|
-
const { highPriorityPlugins, ...shakerConfig } = config;
|
|
47
|
-
const preShakePlugins = evalConfig.plugins?.filter((i) => hasKeyInList(i, highPriorityPlugins)) ??
|
|
48
|
-
[];
|
|
49
|
-
const plugins = [
|
|
50
|
-
...preShakePlugins,
|
|
51
|
-
[shaker_1.default, shakerConfig],
|
|
52
|
-
...(evalConfig.plugins ?? []).filter((i) => !hasKeyInList(i, highPriorityPlugins) && !isCommonJSPlugin(i)),
|
|
53
|
-
];
|
|
54
|
-
ensureTypescriptPlugin(plugins, evalConfig);
|
|
55
|
-
if (includeCommonJS) {
|
|
56
|
-
plugins.push(require.resolve('@babel/plugin-transform-modules-commonjs'));
|
|
57
|
-
}
|
|
58
|
-
return plugins;
|
|
59
|
-
};
|
|
60
|
-
const shakeToESM = (evalConfig, ast, code, config, babel) => {
|
|
61
|
-
const transformed = babel.transformFromAstSync(ast, code, {
|
|
62
|
-
...evalConfig,
|
|
63
|
-
ast: true,
|
|
64
|
-
caller: {
|
|
65
|
-
name: 'wyw-in-js',
|
|
66
|
-
},
|
|
67
|
-
plugins: createShakerPlugins(evalConfig, config, false),
|
|
68
|
-
});
|
|
69
|
-
if (!transformed || !(0, ShakerMetadata_1.hasShakerMetadata)(transformed.metadata)) {
|
|
70
|
-
throw new Error(`${evalConfig.filename} has no shaker metadata`);
|
|
71
|
-
}
|
|
72
|
-
return [
|
|
73
|
-
transformed.ast,
|
|
74
|
-
transformed.code ?? '',
|
|
75
|
-
transformed.metadata.wywEvaluator.imports,
|
|
76
|
-
];
|
|
77
|
-
};
|
|
78
|
-
exports.shakeToESM = shakeToESM;
|
|
79
|
-
const emitCommonJS = (evalConfig, ast, code, babel) => {
|
|
80
|
-
const transformed = babel.transformFromAstSync(ast, code, {
|
|
81
|
-
...evalConfig,
|
|
82
|
-
ast: true,
|
|
83
|
-
caller: {
|
|
84
|
-
name: 'wyw-in-js',
|
|
85
|
-
},
|
|
86
|
-
plugins: [require.resolve('@babel/plugin-transform-modules-commonjs')],
|
|
87
|
-
});
|
|
88
|
-
if (!transformed?.ast) {
|
|
89
|
-
throw new Error('Babel transform failed');
|
|
90
|
-
}
|
|
91
|
-
return [transformed.ast, transformed.code ?? ''];
|
|
92
|
-
};
|
|
93
|
-
exports.emitCommonJS = emitCommonJS;
|
|
94
|
-
const shaker = (evalConfig, ast, code, config, babel) => {
|
|
95
|
-
const [esmAst, esmCode, imports] = (0, exports.shakeToESM)(evalConfig, ast, code, config, babel);
|
|
96
|
-
const [, commonJSCode] = (0, exports.emitCommonJS)(evalConfig, esmAst, esmCode, babel);
|
|
97
|
-
return [esmAst, commonJSCode, imports];
|
|
98
|
-
};
|
|
99
|
-
exports.shaker = shaker;
|
|
100
|
-
exports.default = exports.shaker;
|
|
1
|
+
import { emitOxcCommonJS } from './utils/oxcEmit';
|
|
2
|
+
import { shakeOxcToESM } from './utils/oxcShaker';
|
|
3
|
+
export const oxcShaker = (evalConfig, ast, code, config) => {
|
|
4
|
+
const filename = evalConfig.filename ?? 'unknown.js';
|
|
5
|
+
const shaken = shakeOxcToESM(code, filename, config);
|
|
6
|
+
const emitted = emitOxcCommonJS(shaken.code, filename);
|
|
7
|
+
return [ast, emitted.code, shaken.imports];
|
|
8
|
+
};
|
|
9
|
+
export const shaker = oxcShaker;
|
|
10
|
+
export default shaker;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseEntrypoint = exports.createExports = void 0;
|
|
4
|
-
const getFileIdx_1 = require("../utils/getFileIdx");
|
|
1
|
+
import { getFileIdx } from '../utils/getFileIdx';
|
|
5
2
|
const hasKey = (obj, key) => (typeof obj === 'object' || typeof obj === 'function') &&
|
|
6
3
|
obj !== null &&
|
|
7
4
|
key in obj;
|
|
8
5
|
const VALUES = Symbol('values');
|
|
9
6
|
const isProxy = (obj) => typeof obj === 'object' && obj !== null && VALUES in obj;
|
|
10
|
-
const createExports = (log) => {
|
|
7
|
+
export const createExports = (log) => {
|
|
11
8
|
let exports = {};
|
|
12
9
|
const lazyFields = new Set();
|
|
13
10
|
return new Proxy(exports, {
|
|
@@ -105,10 +102,9 @@ const createExports = (log) => {
|
|
|
105
102
|
},
|
|
106
103
|
});
|
|
107
104
|
};
|
|
108
|
-
exports.createExports = createExports;
|
|
109
105
|
const EXPORTS = Symbol('exports');
|
|
110
106
|
let entrypointSeqId = 0;
|
|
111
|
-
class BaseEntrypoint {
|
|
107
|
+
export class BaseEntrypoint {
|
|
112
108
|
services;
|
|
113
109
|
evaluatedOnly;
|
|
114
110
|
generation;
|
|
@@ -118,7 +114,7 @@ class BaseEntrypoint {
|
|
|
118
114
|
dependencies;
|
|
119
115
|
invalidationDependencies;
|
|
120
116
|
invalidateOnDependencyChange;
|
|
121
|
-
static createExports =
|
|
117
|
+
static createExports = createExports;
|
|
122
118
|
idx;
|
|
123
119
|
log;
|
|
124
120
|
// eslint-disable-next-line no-plusplus
|
|
@@ -134,7 +130,7 @@ class BaseEntrypoint {
|
|
|
134
130
|
this.dependencies = dependencies;
|
|
135
131
|
this.invalidationDependencies = invalidationDependencies;
|
|
136
132
|
this.invalidateOnDependencyChange = invalidateOnDependencyChange;
|
|
137
|
-
this.idx =
|
|
133
|
+
this.idx = getFileIdx(name);
|
|
138
134
|
this.log =
|
|
139
135
|
parents[0]?.log.extend(this.ref, '->') ?? services.log.extend(this.ref);
|
|
140
136
|
this.dependencies = dependencies;
|
|
@@ -145,7 +141,7 @@ class BaseEntrypoint {
|
|
|
145
141
|
isExportsInherited = true;
|
|
146
142
|
}
|
|
147
143
|
else {
|
|
148
|
-
this.#exports =
|
|
144
|
+
this.#exports = createExports(this.log);
|
|
149
145
|
this.#exports[EXPORTS] = exports;
|
|
150
146
|
}
|
|
151
147
|
this.exports = exports;
|
|
@@ -186,4 +182,3 @@ class BaseEntrypoint {
|
|
|
186
182
|
return this.#exports;
|
|
187
183
|
}
|
|
188
184
|
}
|
|
189
|
-
exports.BaseEntrypoint = BaseEntrypoint;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { ParentEntrypoint, ITransformFileResult } from '../types';
|
|
2
2
|
import { BaseEntrypoint } from './BaseEntrypoint';
|
|
3
|
-
import type { IEntrypointCode, IEntrypointDependency, IIgnoredEntrypoint } from './Entrypoint.types';
|
|
3
|
+
import type { IEntrypointCode, IEntrypointDependency, IIgnoredEntrypoint, IPreevalResult } from './Entrypoint.types';
|
|
4
4
|
import { EvaluatedEntrypoint } from './EvaluatedEntrypoint';
|
|
5
5
|
import type { ActionByType } from './actions/BaseAction';
|
|
6
6
|
import { BaseAction } from './actions/BaseAction';
|
|
7
7
|
import type { Services, ActionTypes } from './types';
|
|
8
|
+
type CreateEntrypointOptions = {
|
|
9
|
+
mergeCachedOnly?: boolean;
|
|
10
|
+
};
|
|
8
11
|
export declare class Entrypoint extends BaseEntrypoint {
|
|
9
12
|
#private;
|
|
10
13
|
readonly initialCode: string | undefined;
|
|
@@ -12,29 +15,21 @@ export declare class Entrypoint extends BaseEntrypoint {
|
|
|
12
15
|
readonly dependencies: Map<string, IEntrypointDependency>;
|
|
13
16
|
readonly invalidationDependencies: Map<string, IEntrypointDependency>;
|
|
14
17
|
readonly invalidateOnDependencyChange: Set<string>;
|
|
18
|
+
private readonly skipCacheInvalidation;
|
|
15
19
|
readonly evaluated = false;
|
|
16
20
|
readonly loadedAndParsed: IEntrypointCode | IIgnoredEntrypoint;
|
|
17
21
|
protected onSupersedeHandlers: Array<(newEntrypoint: Entrypoint) => void>;
|
|
18
22
|
private actionsCache;
|
|
23
|
+
private static readonly RESOLVE_TASK_MAX_NULL_ATTEMPTS;
|
|
19
24
|
private constructor();
|
|
20
25
|
get ignored(): boolean;
|
|
21
26
|
get originalCode(): string | undefined;
|
|
22
27
|
get supersededWith(): Entrypoint | null;
|
|
23
28
|
get transformedCode(): string | null;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* 1. If `loadedCode` is specified and is different from the one that was used to create the existing entrypoint,
|
|
29
|
-
* the existing entrypoint will be superseded by a new one and all cached results for it will be invalidated.
|
|
30
|
-
* It can happen if the file was changed and the watcher notified us about it, or we received a new version
|
|
31
|
-
* of the file from a loader whereas the previous one was loaded from the filesystem.
|
|
32
|
-
* The new entrypoint will be returned.
|
|
33
|
-
* 2. If `only` is subset of the existing entrypoint's `only`, the existing entrypoint will be returned.
|
|
34
|
-
* 3. If `only` is superset of the existing entrypoint's `only`, the existing entrypoint will be superseded and the new one will be returned.
|
|
35
|
-
* 4. If a loop is detected, 'ignored' will be returned, the existing entrypoint will be superseded or not depending on the `only` value.
|
|
36
|
-
*/
|
|
37
|
-
protected static create(services: Services, parent: ParentEntrypoint | null, name: string, only: string[], loadedCode: string | undefined): Entrypoint | 'loop';
|
|
29
|
+
get transformed(): boolean;
|
|
30
|
+
get isProcessing(): boolean;
|
|
31
|
+
static createRoot(services: Services, name: string, only: string[], loadedCode: string | undefined, options?: CreateEntrypointOptions): Entrypoint;
|
|
32
|
+
protected static create(services: Services, parent: ParentEntrypoint | null, name: string, only: string[], loadedCode: string | undefined, options?: CreateEntrypointOptions): Entrypoint | 'loop';
|
|
38
33
|
private static innerCreate;
|
|
39
34
|
addDependency(dependency: IEntrypointDependency): void;
|
|
40
35
|
addInvalidationDependency(dependency: IEntrypointDependency): void;
|
|
@@ -48,12 +43,17 @@ export declare class Entrypoint extends BaseEntrypoint {
|
|
|
48
43
|
createEvaluated(): EvaluatedEntrypoint;
|
|
49
44
|
endProcessing(): void;
|
|
50
45
|
getDependency(name: string): IEntrypointDependency | undefined;
|
|
46
|
+
getPreevalResult(): IPreevalResult | null;
|
|
51
47
|
getInvalidationDependency(name: string): IEntrypointDependency | undefined;
|
|
52
48
|
markInvalidateOnDependencyChange(filename: string): void;
|
|
53
49
|
getResolveTask(name: string): Promise<IEntrypointDependency> | undefined;
|
|
54
50
|
hasWywMetadata(): boolean;
|
|
51
|
+
waitForProcessing(): Promise<void>;
|
|
52
|
+
reuseTransformResult(code: string | null, hasWywMetadata: boolean): void;
|
|
55
53
|
onSupersede(callback: (newEntrypoint: Entrypoint) => void): () => void;
|
|
56
54
|
setTransformResult(res: ITransformFileResult | null): void;
|
|
55
|
+
setPreevalResult(result: IPreevalResult): void;
|
|
57
56
|
private deferOnlySupersede;
|
|
58
57
|
private supersede;
|
|
59
58
|
}
|
|
59
|
+
export {};
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type { TransformOptions } from '@babel/core';
|
|
2
|
-
import type { File } from '@babel/types';
|
|
3
1
|
import type { Debugger, EvalRule } from '@wyw-in-js/shared';
|
|
4
|
-
import type { Core } from '../babel';
|
|
5
2
|
import type { ParentEntrypoint } from '../types';
|
|
6
|
-
import type { IEntrypointCode, IIgnoredEntrypoint } from './Entrypoint.types';
|
|
3
|
+
import type { IEntrypointCode, IIgnoredEntrypoint, ParsedAst } from './Entrypoint.types';
|
|
7
4
|
import type { Services } from './types';
|
|
8
5
|
export declare function getMatchedRule(rules: EvalRule[], filename: string, code: string): EvalRule;
|
|
9
|
-
export declare function parseFile(
|
|
6
|
+
export declare function parseFile(_runtime: unknown, filename: string, originalCode: string): ParsedAst;
|
|
10
7
|
export declare function loadAndParse(services: Services, name: string, loadedCode: string | undefined, log: Debugger): IEntrypointCode | IIgnoredEntrypoint;
|
|
11
8
|
export declare function getStack(entrypoint: ParentEntrypoint): string[];
|
|
12
9
|
export declare function mergeOnly(a: string[], b: string[]): string[];
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const shared_1 = require("@wyw-in-js/shared");
|
|
12
|
-
const buildOptions_1 = require("../options/buildOptions");
|
|
13
|
-
const loadBabelOptions_1 = require("../options/loadBabelOptions");
|
|
14
|
-
const getFileIdx_1 = require("../utils/getFileIdx");
|
|
15
|
-
const getPluginKey_1 = require("../utils/getPluginKey");
|
|
16
|
-
const parseRequest_1 = require("../utils/parseRequest");
|
|
17
|
-
function getMatchedRule(rules, filename, code) {
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { dirname, extname, isAbsolute } from 'path';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { parseSync } from 'oxc-parser';
|
|
5
|
+
import { logger } from '@wyw-in-js/shared';
|
|
6
|
+
import { oxcShaker } from '../shaker';
|
|
7
|
+
import { getFileIdx } from '../utils/getFileIdx';
|
|
8
|
+
import { stripQueryAndHash } from '../utils/parseRequest';
|
|
9
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
10
|
+
export function getMatchedRule(rules, filename, code) {
|
|
18
11
|
for (let i = rules.length - 1; i >= 0; i--) {
|
|
19
12
|
const rule = rules[i];
|
|
20
13
|
if (!rule.test) {
|
|
@@ -29,177 +22,28 @@ function getMatchedRule(rules, filename, code) {
|
|
|
29
22
|
}
|
|
30
23
|
return { action: 'ignore' };
|
|
31
24
|
}
|
|
32
|
-
function parseFile(
|
|
33
|
-
const log =
|
|
34
|
-
const parseResult =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
log('stage-1', `${filename} has been parsed`);
|
|
39
|
-
return parseResult;
|
|
40
|
-
}
|
|
41
|
-
const isModuleResolver = (plugin) => {
|
|
42
|
-
const key = (0, getPluginKey_1.getPluginKey)(plugin);
|
|
43
|
-
if (!key)
|
|
44
|
-
return false;
|
|
45
|
-
if (['module-resolver', 'babel-plugin-module-resolver'].includes(key)) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
return /([\\/])babel-plugin-module-resolver\1/.test(key);
|
|
49
|
-
};
|
|
50
|
-
let moduleResolverWarned = false;
|
|
51
|
-
const normalizeBabelKey = (key) => key.replace(/\\/g, '/');
|
|
52
|
-
const isBabelPresetTypescript = (key) => {
|
|
53
|
-
const normalized = normalizeBabelKey(key);
|
|
54
|
-
if (normalized === 'typescript')
|
|
55
|
-
return true;
|
|
56
|
-
return normalized.includes('preset-typescript');
|
|
57
|
-
};
|
|
58
|
-
const isBabelTransformTypescriptPlugin = (key) => {
|
|
59
|
-
const normalized = normalizeBabelKey(key);
|
|
60
|
-
if (normalized === 'transform-typescript')
|
|
61
|
-
return true;
|
|
62
|
-
return normalized.includes('plugin-transform-typescript');
|
|
63
|
-
};
|
|
64
|
-
const withAllowDeclareFields = (item) => {
|
|
65
|
-
if (!Array.isArray(item)) {
|
|
66
|
-
return [item, { allowDeclareFields: true }];
|
|
67
|
-
}
|
|
68
|
-
const [target, rawOptions, ...rest] = item;
|
|
69
|
-
const options = typeof rawOptions === 'object' &&
|
|
70
|
-
rawOptions !== null &&
|
|
71
|
-
!Array.isArray(rawOptions)
|
|
72
|
-
? rawOptions
|
|
73
|
-
: {};
|
|
74
|
-
if ('allowDeclareFields' in options) {
|
|
75
|
-
return item;
|
|
76
|
-
}
|
|
77
|
-
return [target, { ...options, allowDeclareFields: true }, ...rest];
|
|
78
|
-
};
|
|
79
|
-
const ensureAllowDeclareFieldsInBabelOptions = (babelOptions, scope = 'top') => {
|
|
80
|
-
let presetsChanged = false;
|
|
81
|
-
let pluginsChanged = false;
|
|
82
|
-
let overridesChanged = false;
|
|
83
|
-
let envChanged = false;
|
|
84
|
-
const presets = babelOptions.presets?.map((item) => {
|
|
85
|
-
const key = (0, getPluginKey_1.getPluginKey)(item);
|
|
86
|
-
if (!key || !isBabelPresetTypescript(key)) {
|
|
87
|
-
return item;
|
|
88
|
-
}
|
|
89
|
-
presetsChanged = true;
|
|
90
|
-
return withAllowDeclareFields(item);
|
|
91
|
-
});
|
|
92
|
-
const plugins = babelOptions.plugins?.map((item) => {
|
|
93
|
-
const key = (0, getPluginKey_1.getPluginKey)(item);
|
|
94
|
-
if (!key || !isBabelTransformTypescriptPlugin(key)) {
|
|
95
|
-
return item;
|
|
96
|
-
}
|
|
97
|
-
pluginsChanged = true;
|
|
98
|
-
return withAllowDeclareFields(item);
|
|
99
|
-
});
|
|
100
|
-
const { overrides: baseOverrides } = babelOptions;
|
|
101
|
-
let overrides = baseOverrides;
|
|
102
|
-
if (scope === 'top' && baseOverrides) {
|
|
103
|
-
const patchedOverrides = baseOverrides.map((override) => ensureAllowDeclareFieldsInBabelOptions(override, 'override'));
|
|
104
|
-
if (patchedOverrides.some((patchedOverride, idx) => patchedOverride !== baseOverrides[idx])) {
|
|
105
|
-
overridesChanged = true;
|
|
106
|
-
overrides = patchedOverrides;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const { env: baseEnv } = babelOptions;
|
|
110
|
-
let env = baseEnv;
|
|
111
|
-
if (scope === 'top' && baseEnv) {
|
|
112
|
-
const entries = Object.entries(baseEnv);
|
|
113
|
-
const patchedEntries = entries.map(([envName, envOptions]) => [
|
|
114
|
-
envName,
|
|
115
|
-
envOptions
|
|
116
|
-
? ensureAllowDeclareFieldsInBabelOptions(envOptions, 'env')
|
|
117
|
-
: envOptions,
|
|
118
|
-
]);
|
|
119
|
-
if (patchedEntries.some(([, patched], idx) => patched !== entries[idx][1])) {
|
|
120
|
-
envChanged = true;
|
|
121
|
-
env = Object.fromEntries(patchedEntries);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (!presetsChanged && !pluginsChanged && !overridesChanged && !envChanged) {
|
|
125
|
-
return babelOptions;
|
|
126
|
-
}
|
|
127
|
-
const next = { ...babelOptions };
|
|
128
|
-
if (presetsChanged)
|
|
129
|
-
next.presets = presets;
|
|
130
|
-
if (pluginsChanged)
|
|
131
|
-
next.plugins = plugins;
|
|
132
|
-
if (overridesChanged)
|
|
133
|
-
next.overrides = overrides;
|
|
134
|
-
if (envChanged)
|
|
135
|
-
next.env = env;
|
|
136
|
-
return next;
|
|
137
|
-
};
|
|
138
|
-
function buildConfigs(services, name, pluginOptions, babelOptions) {
|
|
139
|
-
const { babel, options } = services;
|
|
140
|
-
const commonOptions = {
|
|
141
|
-
ast: true,
|
|
142
|
-
filename: name,
|
|
143
|
-
inputSourceMap: options.inputSourceMap,
|
|
144
|
-
root: options.root,
|
|
145
|
-
sourceFileName: name,
|
|
146
|
-
sourceMaps: true,
|
|
147
|
-
};
|
|
148
|
-
const isTypescriptFile = name.endsWith('.ts') ||
|
|
149
|
-
name.endsWith('.tsx') ||
|
|
150
|
-
name.endsWith('.mts') ||
|
|
151
|
-
name.endsWith('.cts');
|
|
152
|
-
let rawConfig = (0, buildOptions_1.buildOptions)(pluginOptions?.babelOptions, babelOptions, commonOptions);
|
|
153
|
-
if (isTypescriptFile) {
|
|
154
|
-
rawConfig = ensureAllowDeclareFieldsInBabelOptions(rawConfig);
|
|
155
|
-
}
|
|
156
|
-
const useBabelConfigs = (0, shared_1.isFeatureEnabled)(pluginOptions.features, 'useBabelConfigs', name);
|
|
157
|
-
if (!useBabelConfigs) {
|
|
158
|
-
rawConfig = {
|
|
159
|
-
...rawConfig,
|
|
160
|
-
configFile: false,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
const parseConfig = (0, loadBabelOptions_1.loadBabelOptions)(babel, name, {
|
|
164
|
-
babelrc: useBabelConfigs,
|
|
165
|
-
...rawConfig,
|
|
25
|
+
export function parseFile(_runtime, filename, originalCode) {
|
|
26
|
+
const log = logger.extend('transform:parse').extend(getFileIdx(filename));
|
|
27
|
+
const parseResult = parseSync(filename, originalCode, {
|
|
28
|
+
astType: filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js',
|
|
29
|
+
range: true,
|
|
30
|
+
sourceType: 'module',
|
|
166
31
|
});
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (!moduleResolverWarned) {
|
|
171
|
-
// eslint-disable-next-line no-console
|
|
172
|
-
console.warn(`[wyw-in-js] ${name} has a module-resolver plugin in its babelrc, but it is not present ` +
|
|
173
|
-
`in the babelOptions for the wyw-in-js plugin. This works for now but will be an error in the future. ` +
|
|
174
|
-
`Please add the module-resolver plugin to the babelOptions for the wyw-in-js plugin.`);
|
|
175
|
-
moduleResolverWarned = true;
|
|
176
|
-
}
|
|
177
|
-
rawConfig = {
|
|
178
|
-
...rawConfig,
|
|
179
|
-
plugins: [
|
|
180
|
-
...(parseConfig.plugins?.filter((plugin) => isModuleResolver(plugin)) ??
|
|
181
|
-
[]),
|
|
182
|
-
...(rawConfig.plugins ?? []),
|
|
183
|
-
],
|
|
184
|
-
};
|
|
32
|
+
const fatalError = parseResult.errors.find((error) => error.severity === 'Error');
|
|
33
|
+
if (fatalError) {
|
|
34
|
+
throw new Error(fatalError.message);
|
|
185
35
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
...rawConfig,
|
|
189
|
-
});
|
|
190
|
-
return {
|
|
191
|
-
evalConfig,
|
|
192
|
-
parseConfig,
|
|
193
|
-
};
|
|
36
|
+
log('stage-1', `${filename} has been parsed`);
|
|
37
|
+
return parseResult.program;
|
|
194
38
|
}
|
|
195
|
-
function loadAndParse(services, name, loadedCode, log) {
|
|
196
|
-
const {
|
|
197
|
-
const filename =
|
|
198
|
-
const extension =
|
|
39
|
+
export function loadAndParse(services, name, loadedCode, log) {
|
|
40
|
+
const { options: { pluginOptions }, } = services;
|
|
41
|
+
const filename = stripQueryAndHash(name);
|
|
42
|
+
const extension = extname(filename);
|
|
199
43
|
if (!pluginOptions.extensions.includes(extension)) {
|
|
200
44
|
log('[createEntrypoint] %s is ignored. If you want it to be processed, you should add \'%s\' to the "extensions" option.', filename, extension);
|
|
201
45
|
return {
|
|
202
|
-
code:
|
|
46
|
+
code: isAbsolute(filename) ? loadedCode : '',
|
|
203
47
|
evaluator: 'ignored',
|
|
204
48
|
reason: 'extension',
|
|
205
49
|
};
|
|
@@ -213,22 +57,11 @@ function loadAndParse(services, name, loadedCode, log) {
|
|
|
213
57
|
code = cachedEntrypoint.initialCode;
|
|
214
58
|
}
|
|
215
59
|
}
|
|
216
|
-
code ??=
|
|
217
|
-
const { action
|
|
218
|
-
let ast;
|
|
219
|
-
const { evalConfig, parseConfig } = buildConfigs(services, filename, pluginOptions, babelOptions);
|
|
220
|
-
const getOrParse = () => {
|
|
221
|
-
if (ast)
|
|
222
|
-
return ast;
|
|
223
|
-
ast = eventEmitter.perf('parseFile', () => parseFile(babel, name, code, parseConfig));
|
|
224
|
-
return ast;
|
|
225
|
-
};
|
|
60
|
+
code ??= readFileSync(filename, 'utf-8');
|
|
61
|
+
const { action } = getMatchedRule(pluginOptions.rules, filename, code);
|
|
226
62
|
if (action === 'ignore') {
|
|
227
63
|
log('[createEntrypoint] %s is ignored by rule', name);
|
|
228
64
|
return {
|
|
229
|
-
get ast() {
|
|
230
|
-
return getOrParse();
|
|
231
|
-
},
|
|
232
65
|
code,
|
|
233
66
|
evaluator: 'ignored',
|
|
234
67
|
reason: 'rule',
|
|
@@ -236,19 +69,27 @@ function loadAndParse(services, name, loadedCode, log) {
|
|
|
236
69
|
}
|
|
237
70
|
const evaluator = typeof action === 'function'
|
|
238
71
|
? action
|
|
239
|
-
:
|
|
240
|
-
paths: [
|
|
72
|
+
: nodeRequire(nodeRequire.resolve(action, {
|
|
73
|
+
paths: [dirname(filename)],
|
|
241
74
|
})).default;
|
|
75
|
+
if (evaluator !== oxcShaker) {
|
|
76
|
+
throw new Error(`[wyw-in-js] ${filename} matched a legacy evaluator. The Oxc runtime path supports only the default Oxc evaluator.`);
|
|
77
|
+
}
|
|
242
78
|
return {
|
|
243
79
|
get ast() {
|
|
244
|
-
return
|
|
80
|
+
return null;
|
|
245
81
|
},
|
|
246
82
|
code,
|
|
247
83
|
evaluator,
|
|
248
|
-
evalConfig
|
|
84
|
+
evalConfig: {
|
|
85
|
+
ast: false,
|
|
86
|
+
configFile: false,
|
|
87
|
+
filename,
|
|
88
|
+
root: services.options.root ?? process.cwd(),
|
|
89
|
+
},
|
|
249
90
|
};
|
|
250
91
|
}
|
|
251
|
-
function getStack(entrypoint) {
|
|
92
|
+
export function getStack(entrypoint) {
|
|
252
93
|
if (!entrypoint)
|
|
253
94
|
return [];
|
|
254
95
|
const stack = [entrypoint.name];
|
|
@@ -259,12 +100,12 @@ function getStack(entrypoint) {
|
|
|
259
100
|
}
|
|
260
101
|
return stack;
|
|
261
102
|
}
|
|
262
|
-
function mergeOnly(a, b) {
|
|
103
|
+
export function mergeOnly(a, b) {
|
|
263
104
|
const result = new Set(a);
|
|
264
105
|
b.forEach((item) => result.add(item));
|
|
265
106
|
return [...result].filter((i) => i).sort();
|
|
266
107
|
}
|
|
267
|
-
const isSuperSet = (a, b) => {
|
|
108
|
+
export const isSuperSet = (a, b) => {
|
|
268
109
|
if (a.includes('*'))
|
|
269
110
|
return true;
|
|
270
111
|
if (b.length === 0)
|
|
@@ -272,4 +113,3 @@ const isSuperSet = (a, b) => {
|
|
|
272
113
|
const aSet = new Set(a);
|
|
273
114
|
return b.every((item) => aSet.has(item));
|
|
274
115
|
};
|
|
275
|
-
exports.isSuperSet = isSuperSet;
|