@wyw-in-js/transform 0.1.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/LICENSE +21 -0
- package/esm/babel.js +2 -0
- package/esm/babel.js.map +1 -0
- package/esm/cache.js +80 -0
- package/esm/cache.js.map +1 -0
- package/esm/debug/fileReporter.js +144 -0
- package/esm/debug/fileReporter.js.map +1 -0
- package/esm/evaluators/index.js +14 -0
- package/esm/evaluators/index.js.map +1 -0
- package/esm/index.js +24 -0
- package/esm/index.js.map +1 -0
- package/esm/module.js +316 -0
- package/esm/module.js.map +1 -0
- package/esm/options/babel-merge.d.js +2 -0
- package/esm/options/babel-merge.d.js.map +1 -0
- package/esm/options/buildOptions.js +28 -0
- package/esm/options/buildOptions.js.map +1 -0
- package/esm/options/loadBabelOptions.js +24 -0
- package/esm/options/loadBabelOptions.js.map +1 -0
- package/esm/plugins/babel-transform.js +53 -0
- package/esm/plugins/babel-transform.js.map +1 -0
- package/esm/plugins/collector.js +66 -0
- package/esm/plugins/collector.js.map +1 -0
- package/esm/plugins/dynamic-import.js +28 -0
- package/esm/plugins/dynamic-import.js.map +1 -0
- package/esm/plugins/preeval.js +75 -0
- package/esm/plugins/preeval.js.map +1 -0
- package/esm/plugins/shaker.js +296 -0
- package/esm/plugins/shaker.js.map +1 -0
- package/esm/shaker.js +50 -0
- package/esm/shaker.js.map +1 -0
- package/esm/transform/BaseEntrypoint.js +164 -0
- package/esm/transform/BaseEntrypoint.js.map +1 -0
- package/esm/transform/Entrypoint.helpers.js +168 -0
- package/esm/transform/Entrypoint.helpers.js.map +1 -0
- package/esm/transform/Entrypoint.js +212 -0
- package/esm/transform/Entrypoint.js.map +1 -0
- package/esm/transform/Entrypoint.types.js +2 -0
- package/esm/transform/Entrypoint.types.js.map +1 -0
- package/esm/transform/EvaluatedEntrypoint.js +6 -0
- package/esm/transform/EvaluatedEntrypoint.js.map +1 -0
- package/esm/transform/actions/AbortError.js +8 -0
- package/esm/transform/actions/AbortError.js.map +1 -0
- package/esm/transform/actions/BaseAction.js +134 -0
- package/esm/transform/actions/BaseAction.js.map +1 -0
- package/esm/transform/actions/UnprocessedEntrypointError.js +8 -0
- package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -0
- package/esm/transform/actions/actionRunner.js +73 -0
- package/esm/transform/actions/actionRunner.js.map +1 -0
- package/esm/transform/actions/types.js +2 -0
- package/esm/transform/actions/types.js.map +1 -0
- package/esm/transform/generators/baseProcessingHandlers.js +22 -0
- package/esm/transform/generators/baseProcessingHandlers.js.map +1 -0
- package/esm/transform/generators/collect.js +58 -0
- package/esm/transform/generators/collect.js.map +1 -0
- package/esm/transform/generators/evalFile.js +50 -0
- package/esm/transform/generators/evalFile.js.map +1 -0
- package/esm/transform/generators/explodeReexports.js +63 -0
- package/esm/transform/generators/explodeReexports.js.map +1 -0
- package/esm/transform/generators/extract.js +120 -0
- package/esm/transform/generators/extract.js.map +1 -0
- package/esm/transform/generators/getExports.js +73 -0
- package/esm/transform/generators/getExports.js.map +1 -0
- package/esm/transform/generators/index.js +13 -0
- package/esm/transform/generators/index.js.map +1 -0
- package/esm/transform/generators/processEntrypoint.js +43 -0
- package/esm/transform/generators/processEntrypoint.js.map +1 -0
- package/esm/transform/generators/processImports.js +23 -0
- package/esm/transform/generators/processImports.js.map +1 -0
- package/esm/transform/generators/resolveImports.js +148 -0
- package/esm/transform/generators/resolveImports.js.map +1 -0
- package/esm/transform/generators/transform.js +117 -0
- package/esm/transform/generators/transform.js.map +1 -0
- package/esm/transform/generators/workflow.js +82 -0
- package/esm/transform/generators/workflow.js.map +1 -0
- package/esm/transform/helpers/loadLinariaOptions.js +66 -0
- package/esm/transform/helpers/loadLinariaOptions.js.map +1 -0
- package/esm/transform/helpers/withDefaultServices.js +21 -0
- package/esm/transform/helpers/withDefaultServices.js.map +1 -0
- package/esm/transform/rootLog.js +3 -0
- package/esm/transform/rootLog.js.map +1 -0
- package/esm/transform/types.js +2 -0
- package/esm/transform/types.js.map +1 -0
- package/esm/transform.js +121 -0
- package/esm/transform.js.map +1 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/esm/utils/EventEmitter.js +52 -0
- package/esm/utils/EventEmitter.js.map +1 -0
- package/esm/utils/ShakerMetadata.js +2 -0
- package/esm/utils/ShakerMetadata.js.map +1 -0
- package/esm/utils/TransformMetadata.js +11 -0
- package/esm/utils/TransformMetadata.js.map +1 -0
- package/esm/utils/addIdentifierToLinariaPreval.js +68 -0
- package/esm/utils/addIdentifierToLinariaPreval.js.map +1 -0
- package/esm/utils/collectExportsAndImports.js +974 -0
- package/esm/utils/collectExportsAndImports.js.map +1 -0
- package/esm/utils/collectTemplateDependencies.js +219 -0
- package/esm/utils/collectTemplateDependencies.js.map +1 -0
- package/esm/utils/createId.js +6 -0
- package/esm/utils/createId.js.map +1 -0
- package/esm/utils/dispose-polyfill.js +6 -0
- package/esm/utils/dispose-polyfill.js.map +1 -0
- package/esm/utils/findIdentifiers.js +62 -0
- package/esm/utils/findIdentifiers.js.map +1 -0
- package/esm/utils/findPackageJSON.js +22 -0
- package/esm/utils/findPackageJSON.js.map +1 -0
- package/esm/utils/getFileIdx.js +10 -0
- package/esm/utils/getFileIdx.js.map +1 -0
- package/esm/utils/getPluginKey.js +13 -0
- package/esm/utils/getPluginKey.js.map +1 -0
- package/esm/utils/getScope.js +6 -0
- package/esm/utils/getScope.js.map +1 -0
- package/esm/utils/getSource.js +15 -0
- package/esm/utils/getSource.js.map +1 -0
- package/esm/utils/getTagProcessor.js +304 -0
- package/esm/utils/getTagProcessor.js.map +1 -0
- package/esm/utils/getVisitorKeys.js +5 -0
- package/esm/utils/getVisitorKeys.js.map +1 -0
- package/esm/utils/hasLinariaPreval.js +7 -0
- package/esm/utils/hasLinariaPreval.js.map +1 -0
- package/esm/utils/isExports.js +22 -0
- package/esm/utils/isExports.js.map +1 -0
- package/esm/utils/isGlobal.js +6 -0
- package/esm/utils/isGlobal.js.map +1 -0
- package/esm/utils/isNode.js +2 -0
- package/esm/utils/isNode.js.map +1 -0
- package/esm/utils/isNodePath.js +4 -0
- package/esm/utils/isNodePath.js.map +1 -0
- package/esm/utils/isNotNull.js +4 -0
- package/esm/utils/isNotNull.js.map +1 -0
- package/esm/utils/isRemoved.js +46 -0
- package/esm/utils/isRemoved.js.map +1 -0
- package/esm/utils/isRequire.js +13 -0
- package/esm/utils/isRequire.js.map +1 -0
- package/esm/utils/isSerializable.js +13 -0
- package/esm/utils/isSerializable.js.map +1 -0
- package/esm/utils/isTypedNode.js +6 -0
- package/esm/utils/isTypedNode.js.map +1 -0
- package/esm/utils/isUnnecessaryReactCall.js +72 -0
- package/esm/utils/isUnnecessaryReactCall.js.map +1 -0
- package/esm/utils/peek.js +2 -0
- package/esm/utils/peek.js.map +1 -0
- package/esm/utils/processTemplateExpression.js +11 -0
- package/esm/utils/processTemplateExpression.js.map +1 -0
- package/esm/utils/removeDangerousCode.js +127 -0
- package/esm/utils/removeDangerousCode.js.map +1 -0
- package/esm/utils/scopeHelpers.js +514 -0
- package/esm/utils/scopeHelpers.js.map +1 -0
- package/esm/utils/traversalCache.js +28 -0
- package/esm/utils/traversalCache.js.map +1 -0
- package/esm/utils/unwrapSequence.js +14 -0
- package/esm/utils/unwrapSequence.js.map +1 -0
- package/esm/utils/valueToLiteral.js +59 -0
- package/esm/utils/valueToLiteral.js.map +1 -0
- package/esm/utils/visitors/JSXElementsRemover.js +51 -0
- package/esm/utils/visitors/JSXElementsRemover.js.map +1 -0
- package/esm/vm/createVmContext.js +72 -0
- package/esm/vm/createVmContext.js.map +1 -0
- package/esm/vm/process.js +29 -0
- package/esm/vm/process.js.map +1 -0
- package/lib/babel.js +2 -0
- package/lib/babel.js.map +1 -0
- package/lib/cache.js +87 -0
- package/lib/cache.js.map +1 -0
- package/lib/debug/fileReporter.js +153 -0
- package/lib/debug/fileReporter.js.map +1 -0
- package/lib/evaluators/index.js +20 -0
- package/lib/evaluators/index.js.map +1 -0
- package/lib/index.js +225 -0
- package/lib/index.js.map +1 -0
- package/lib/module.js +327 -0
- package/lib/module.js.map +1 -0
- package/lib/options/babel-merge.d.js +2 -0
- package/lib/options/babel-merge.d.js.map +1 -0
- package/lib/options/buildOptions.js +35 -0
- package/lib/options/buildOptions.js.map +1 -0
- package/lib/options/loadBabelOptions.js +31 -0
- package/lib/options/loadBabelOptions.js.map +1 -0
- package/lib/plugins/babel-transform.js +60 -0
- package/lib/plugins/babel-transform.js.map +1 -0
- package/lib/plugins/collector.js +76 -0
- package/lib/plugins/collector.js.map +1 -0
- package/lib/plugins/dynamic-import.js +34 -0
- package/lib/plugins/dynamic-import.js.map +1 -0
- package/lib/plugins/preeval.js +82 -0
- package/lib/plugins/preeval.js.map +1 -0
- package/lib/plugins/shaker.js +303 -0
- package/lib/plugins/shaker.js.map +1 -0
- package/lib/shaker.js +58 -0
- package/lib/shaker.js.map +1 -0
- package/lib/transform/BaseEntrypoint.js +175 -0
- package/lib/transform/BaseEntrypoint.js.map +1 -0
- package/lib/transform/Entrypoint.helpers.js +182 -0
- package/lib/transform/Entrypoint.helpers.js.map +1 -0
- package/lib/transform/Entrypoint.js +226 -0
- package/lib/transform/Entrypoint.js.map +1 -0
- package/lib/transform/Entrypoint.types.js +2 -0
- package/lib/transform/Entrypoint.types.js.map +1 -0
- package/lib/transform/EvaluatedEntrypoint.js +13 -0
- package/lib/transform/EvaluatedEntrypoint.js.map +1 -0
- package/lib/transform/actions/AbortError.js +16 -0
- package/lib/transform/actions/AbortError.js.map +1 -0
- package/lib/transform/actions/BaseAction.js +144 -0
- package/lib/transform/actions/BaseAction.js.map +1 -0
- package/lib/transform/actions/UnprocessedEntrypointError.js +16 -0
- package/lib/transform/actions/UnprocessedEntrypointError.js.map +1 -0
- package/lib/transform/actions/actionRunner.js +82 -0
- package/lib/transform/actions/actionRunner.js.map +1 -0
- package/lib/transform/actions/types.js +2 -0
- package/lib/transform/actions/types.js.map +1 -0
- package/lib/transform/generators/baseProcessingHandlers.js +27 -0
- package/lib/transform/generators/baseProcessingHandlers.js.map +1 -0
- package/lib/transform/generators/collect.js +66 -0
- package/lib/transform/generators/collect.js.map +1 -0
- package/lib/transform/generators/evalFile.js +57 -0
- package/lib/transform/generators/evalFile.js.map +1 -0
- package/lib/transform/generators/explodeReexports.js +70 -0
- package/lib/transform/generators/explodeReexports.js.map +1 -0
- package/lib/transform/generators/extract.js +128 -0
- package/lib/transform/generators/extract.js.map +1 -0
- package/lib/transform/generators/getExports.js +80 -0
- package/lib/transform/generators/getExports.js.map +1 -0
- package/lib/transform/generators/index.js +19 -0
- package/lib/transform/generators/index.js.map +1 -0
- package/lib/transform/generators/processEntrypoint.js +49 -0
- package/lib/transform/generators/processEntrypoint.js.map +1 -0
- package/lib/transform/generators/processImports.js +29 -0
- package/lib/transform/generators/processImports.js.map +1 -0
- package/lib/transform/generators/resolveImports.js +158 -0
- package/lib/transform/generators/resolveImports.js.map +1 -0
- package/lib/transform/generators/transform.js +130 -0
- package/lib/transform/generators/transform.js.map +1 -0
- package/lib/transform/generators/workflow.js +90 -0
- package/lib/transform/generators/workflow.js.map +1 -0
- package/lib/transform/helpers/loadLinariaOptions.js +73 -0
- package/lib/transform/helpers/loadLinariaOptions.js.map +1 -0
- package/lib/transform/helpers/withDefaultServices.js +30 -0
- package/lib/transform/helpers/withDefaultServices.js.map +1 -0
- package/lib/transform/rootLog.js +9 -0
- package/lib/transform/rootLog.js.map +1 -0
- package/lib/transform/types.js +8 -0
- package/lib/transform/types.js.map +1 -0
- package/lib/transform.js +128 -0
- package/lib/transform.js.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/EventEmitter.js +61 -0
- package/lib/utils/EventEmitter.js.map +1 -0
- package/lib/utils/ShakerMetadata.js +9 -0
- package/lib/utils/ShakerMetadata.js.map +1 -0
- package/lib/utils/TransformMetadata.js +19 -0
- package/lib/utils/TransformMetadata.js.map +1 -0
- package/lib/utils/addIdentifierToLinariaPreval.js +75 -0
- package/lib/utils/addIdentifierToLinariaPreval.js.map +1 -0
- package/lib/utils/collectExportsAndImports.js +990 -0
- package/lib/utils/collectExportsAndImports.js.map +1 -0
- package/lib/utils/collectTemplateDependencies.js +233 -0
- package/lib/utils/collectTemplateDependencies.js.map +1 -0
- package/lib/utils/createId.js +13 -0
- package/lib/utils/createId.js.map +1 -0
- package/lib/utils/dispose-polyfill.js +9 -0
- package/lib/utils/dispose-polyfill.js.map +1 -0
- package/lib/utils/findIdentifiers.js +73 -0
- package/lib/utils/findIdentifiers.js.map +1 -0
- package/lib/utils/findPackageJSON.js +29 -0
- package/lib/utils/findPackageJSON.js.map +1 -0
- package/lib/utils/getFileIdx.js +16 -0
- package/lib/utils/getFileIdx.js.map +1 -0
- package/lib/utils/getPluginKey.js +21 -0
- package/lib/utils/getPluginKey.js.map +1 -0
- package/lib/utils/getScope.js +12 -0
- package/lib/utils/getScope.js.map +1 -0
- package/lib/utils/getSource.js +24 -0
- package/lib/utils/getSource.js.map +1 -0
- package/lib/utils/getTagProcessor.js +318 -0
- package/lib/utils/getTagProcessor.js.map +1 -0
- package/lib/utils/getVisitorKeys.js +11 -0
- package/lib/utils/getVisitorKeys.js.map +1 -0
- package/lib/utils/hasLinariaPreval.js +13 -0
- package/lib/utils/hasLinariaPreval.js.map +1 -0
- package/lib/utils/isExports.js +27 -0
- package/lib/utils/isExports.js.map +1 -0
- package/lib/utils/isGlobal.js +13 -0
- package/lib/utils/isGlobal.js.map +1 -0
- package/lib/utils/isNode.js +9 -0
- package/lib/utils/isNode.js.map +1 -0
- package/lib/utils/isNodePath.js +10 -0
- package/lib/utils/isNodePath.js.map +1 -0
- package/lib/utils/isNotNull.js +10 -0
- package/lib/utils/isNotNull.js.map +1 -0
- package/lib/utils/isRemoved.js +52 -0
- package/lib/utils/isRemoved.js.map +1 -0
- package/lib/utils/isRequire.js +18 -0
- package/lib/utils/isRequire.js.map +1 -0
- package/lib/utils/isSerializable.js +19 -0
- package/lib/utils/isSerializable.js.map +1 -0
- package/lib/utils/isTypedNode.js +13 -0
- package/lib/utils/isTypedNode.js.map +1 -0
- package/lib/utils/isUnnecessaryReactCall.js +81 -0
- package/lib/utils/isUnnecessaryReactCall.js.map +1 -0
- package/lib/utils/peek.js +9 -0
- package/lib/utils/peek.js.map +1 -0
- package/lib/utils/processTemplateExpression.js +18 -0
- package/lib/utils/processTemplateExpression.js.map +1 -0
- package/lib/utils/removeDangerousCode.js +134 -0
- package/lib/utils/removeDangerousCode.js.map +1 -0
- package/lib/utils/scopeHelpers.js +544 -0
- package/lib/utils/scopeHelpers.js.map +1 -0
- package/lib/utils/traversalCache.js +38 -0
- package/lib/utils/traversalCache.js.map +1 -0
- package/lib/utils/unwrapSequence.js +20 -0
- package/lib/utils/unwrapSequence.js.map +1 -0
- package/lib/utils/valueToLiteral.js +65 -0
- package/lib/utils/valueToLiteral.js.map +1 -0
- package/lib/utils/visitors/JSXElementsRemover.js +57 -0
- package/lib/utils/visitors/JSXElementsRemover.js.map +1 -0
- package/lib/vm/createVmContext.js +80 -0
- package/lib/vm/createVmContext.js.map +1 -0
- package/lib/vm/process.js +38 -0
- package/lib/vm/process.js.map +1 -0
- package/package.json +63 -0
- package/types/babel.d.ts +2 -0
- package/types/babel.js +2 -0
- package/types/cache.d.ts +24 -0
- package/types/cache.js +85 -0
- package/types/debug/fileReporter.d.ts +27 -0
- package/types/debug/fileReporter.js +151 -0
- package/types/evaluators/index.d.ts +10 -0
- package/types/evaluators/index.js +15 -0
- package/types/index.d.ts +30 -0
- package/types/index.js +69 -0
- package/types/module.d.ts +62 -0
- package/types/module.js +318 -0
- package/types/options/buildOptions.d.ts +7 -0
- package/types/options/buildOptions.js +35 -0
- package/types/options/loadBabelOptions.d.ts +3 -0
- package/types/options/loadBabelOptions.js +27 -0
- package/types/plugins/babel-transform.d.ts +4 -0
- package/types/plugins/babel-transform.js +49 -0
- package/types/plugins/collector.d.ts +16 -0
- package/types/plugins/collector.js +67 -0
- package/types/plugins/dynamic-import.d.ts +6 -0
- package/types/plugins/dynamic-import.js +32 -0
- package/types/plugins/preeval.d.ts +16 -0
- package/types/plugins/preeval.js +69 -0
- package/types/plugins/shaker.d.ts +11 -0
- package/types/plugins/shaker.js +299 -0
- package/types/shaker.d.ts +3 -0
- package/types/shaker.js +64 -0
- package/types/transform/BaseEntrypoint.d.ts +23 -0
- package/types/transform/BaseEntrypoint.js +182 -0
- package/types/transform/Entrypoint.d.ts +50 -0
- package/types/transform/Entrypoint.helpers.d.ts +14 -0
- package/types/transform/Entrypoint.helpers.js +169 -0
- package/types/transform/Entrypoint.js +223 -0
- package/types/transform/Entrypoint.types.d.ts +23 -0
- package/types/transform/Entrypoint.types.js +2 -0
- package/types/transform/EvaluatedEntrypoint.d.ts +16 -0
- package/types/transform/EvaluatedEntrypoint.js +9 -0
- package/types/transform/actions/AbortError.d.ts +4 -0
- package/types/transform/actions/AbortError.js +12 -0
- package/types/transform/actions/BaseAction.d.ts +40 -0
- package/types/transform/actions/BaseAction.js +149 -0
- package/types/transform/actions/UnprocessedEntrypointError.d.ts +6 -0
- package/types/transform/actions/UnprocessedEntrypointError.js +13 -0
- package/types/transform/actions/actionRunner.d.ts +4 -0
- package/types/transform/actions/actionRunner.js +86 -0
- package/types/transform/actions/types.d.ts +15 -0
- package/types/transform/actions/types.js +2 -0
- package/types/transform/generators/baseProcessingHandlers.d.ts +17 -0
- package/types/transform/generators/baseProcessingHandlers.js +23 -0
- package/types/transform/generators/collect.d.ts +6 -0
- package/types/transform/generators/collect.js +57 -0
- package/types/transform/generators/evalFile.d.ts +6 -0
- package/types/transform/generators/evalFile.js +56 -0
- package/types/transform/generators/explodeReexports.d.ts +7 -0
- package/types/transform/generators/explodeReexports.js +67 -0
- package/types/transform/generators/extract.d.ts +8 -0
- package/types/transform/generators/extract.js +116 -0
- package/types/transform/generators/getExports.d.ts +8 -0
- package/types/transform/generators/getExports.js +65 -0
- package/types/transform/generators/index.d.ts +15 -0
- package/types/transform/generators/index.js +15 -0
- package/types/transform/generators/processEntrypoint.d.ts +9 -0
- package/types/transform/generators/processEntrypoint.js +88 -0
- package/types/transform/generators/processImports.d.ts +5 -0
- package/types/transform/generators/processImports.js +21 -0
- package/types/transform/generators/resolveImports.d.ts +9 -0
- package/types/transform/generators/resolveImports.js +124 -0
- package/types/transform/generators/transform.d.ts +17 -0
- package/types/transform/generators/transform.js +115 -0
- package/types/transform/generators/workflow.d.ts +7 -0
- package/types/transform/generators/workflow.js +77 -0
- package/types/transform/helpers/loadLinariaOptions.d.ts +6 -0
- package/types/transform/helpers/loadLinariaOptions.js +86 -0
- package/types/transform/helpers/withDefaultServices.d.ts +5 -0
- package/types/transform/helpers/withDefaultServices.js +40 -0
- package/types/transform/rootLog.d.ts +3 -0
- package/types/transform/rootLog.js +5 -0
- package/types/transform/types.d.ts +137 -0
- package/types/transform/types.js +4 -0
- package/types/transform.d.ts +20 -0
- package/types/transform.js +121 -0
- package/types/types.d.ts +72 -0
- package/types/types.js +5 -0
- package/types/utils/EventEmitter.d.ts +58 -0
- package/types/utils/EventEmitter.js +61 -0
- package/types/utils/ShakerMetadata.d.ts +7 -0
- package/types/utils/ShakerMetadata.js +5 -0
- package/types/utils/TransformMetadata.d.ts +13 -0
- package/types/utils/TransformMetadata.js +17 -0
- package/types/utils/addIdentifierToLinariaPreval.d.ts +4 -0
- package/types/utils/addIdentifierToLinariaPreval.js +75 -0
- package/types/utils/collectExportsAndImports.d.ts +31 -0
- package/types/utils/collectExportsAndImports.js +962 -0
- package/types/utils/collectTemplateDependencies.d.ts +17 -0
- package/types/utils/collectTemplateDependencies.js +212 -0
- package/types/utils/createId.d.ts +2 -0
- package/types/utils/createId.js +9 -0
- package/types/utils/dispose-polyfill.d.ts +0 -0
- package/types/utils/dispose-polyfill.js +5 -0
- package/types/utils/findIdentifiers.d.ts +6 -0
- package/types/utils/findIdentifiers.js +68 -0
- package/types/utils/findPackageJSON.d.ts +1 -0
- package/types/utils/findPackageJSON.js +29 -0
- package/types/utils/getFileIdx.d.ts +1 -0
- package/types/utils/getFileIdx.js +13 -0
- package/types/utils/getPluginKey.d.ts +2 -0
- package/types/utils/getPluginKey.js +16 -0
- package/types/utils/getScope.d.ts +2 -0
- package/types/utils/getScope.js +11 -0
- package/types/utils/getSource.d.ts +2 -0
- package/types/utils/getSource.js +22 -0
- package/types/utils/getTagProcessor.d.ts +6 -0
- package/types/utils/getTagProcessor.js +315 -0
- package/types/utils/getVisitorKeys.d.ts +5 -0
- package/types/utils/getVisitorKeys.js +8 -0
- package/types/utils/hasLinariaPreval.d.ts +4 -0
- package/types/utils/hasLinariaPreval.js +9 -0
- package/types/utils/isExports.d.ts +6 -0
- package/types/utils/isExports.js +20 -0
- package/types/utils/isGlobal.d.ts +2 -0
- package/types/utils/isGlobal.js +9 -0
- package/types/utils/isNode.d.ts +2 -0
- package/types/utils/isNode.js +7 -0
- package/types/utils/isNodePath.d.ts +3 -0
- package/types/utils/isNodePath.js +7 -0
- package/types/utils/isNotNull.d.ts +1 -0
- package/types/utils/isNotNull.js +7 -0
- package/types/utils/isRemoved.d.ts +5 -0
- package/types/utils/isRemoved.js +42 -0
- package/types/utils/isRequire.d.ts +6 -0
- package/types/utils/isRequire.js +15 -0
- package/types/utils/isSerializable.d.ts +2 -0
- package/types/utils/isSerializable.js +18 -0
- package/types/utils/isTypedNode.d.ts +5 -0
- package/types/utils/isTypedNode.js +9 -0
- package/types/utils/isUnnecessaryReactCall.d.ts +3 -0
- package/types/utils/isUnnecessaryReactCall.js +76 -0
- package/types/utils/peek.d.ts +1 -0
- package/types/utils/peek.js +5 -0
- package/types/utils/processTemplateExpression.d.ts +5 -0
- package/types/utils/processTemplateExpression.js +17 -0
- package/types/utils/removeDangerousCode.d.ts +3 -0
- package/types/utils/removeDangerousCode.js +144 -0
- package/types/utils/scopeHelpers.d.ts +12 -0
- package/types/utils/scopeHelpers.js +568 -0
- package/types/utils/traversalCache.d.ts +5 -0
- package/types/utils/traversalCache.js +36 -0
- package/types/utils/unwrapSequence.d.ts +8 -0
- package/types/utils/unwrapSequence.js +17 -0
- package/types/utils/valueToLiteral.d.ts +3 -0
- package/types/utils/valueToLiteral.js +64 -0
- package/types/utils/visitors/JSXElementsRemover.d.ts +3 -0
- package/types/utils/visitors/JSXElementsRemover.js +52 -0
- package/types/vm/createVmContext.d.ts +7 -0
- package/types/vm/createVmContext.js +92 -0
- package/types/vm/process.d.ts +25 -0
- package/types/vm/process.js +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Anton Evzhakov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/esm/babel.js
ADDED
package/esm/babel.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"babel.js","names":[],"sources":["../src/babel.ts"],"sourcesContent":["import type core from '@babel/core';\n\nexport type Core = typeof core;\n"],"mappings":""}
|
package/esm/cache.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { logger } from '@wyw-in-js/shared';
|
|
3
|
+
import { getFileIdx } from './utils/getFileIdx';
|
|
4
|
+
function hashContent(content) {
|
|
5
|
+
return createHash('sha256').update(content).digest('hex');
|
|
6
|
+
}
|
|
7
|
+
const cacheLogger = logger.extend('cache');
|
|
8
|
+
const cacheNames = ['entrypoints', 'exports'];
|
|
9
|
+
const loggers = cacheNames.reduce((acc, key) => ({
|
|
10
|
+
...acc,
|
|
11
|
+
[key]: cacheLogger.extend(key)
|
|
12
|
+
}), {});
|
|
13
|
+
export class TransformCacheCollection {
|
|
14
|
+
contentHashes = new Map();
|
|
15
|
+
constructor(caches = {}) {
|
|
16
|
+
this.entrypoints = caches.entrypoints || new Map();
|
|
17
|
+
this.exports = caches.exports || new Map();
|
|
18
|
+
}
|
|
19
|
+
add(cacheName, key, value) {
|
|
20
|
+
const cache = this[cacheName];
|
|
21
|
+
loggers[cacheName]('%s:add %s %f', getFileIdx(key), key, () => {
|
|
22
|
+
if (!cache.has(key)) {
|
|
23
|
+
return 'added';
|
|
24
|
+
}
|
|
25
|
+
return cache.get(key) === value ? 'unchanged' : 'updated';
|
|
26
|
+
});
|
|
27
|
+
cache.set(key, value);
|
|
28
|
+
}
|
|
29
|
+
clear(cacheName) {
|
|
30
|
+
if (cacheName === 'all') {
|
|
31
|
+
cacheNames.forEach(name => {
|
|
32
|
+
this.clear(name);
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
loggers[cacheName]('clear');
|
|
37
|
+
const cache = this[cacheName];
|
|
38
|
+
cache.clear();
|
|
39
|
+
}
|
|
40
|
+
delete(cacheName, key) {
|
|
41
|
+
this.invalidate(cacheName, key);
|
|
42
|
+
}
|
|
43
|
+
get(cacheName, key) {
|
|
44
|
+
const cache = this[cacheName];
|
|
45
|
+
const res = cache.get(key);
|
|
46
|
+
loggers[cacheName]('get', key, res === undefined ? 'miss' : 'hit');
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
49
|
+
has(cacheName, key) {
|
|
50
|
+
const cache = this[cacheName];
|
|
51
|
+
const res = cache.has(key);
|
|
52
|
+
loggers[cacheName]('has', key, res);
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
invalidate(cacheName, key) {
|
|
56
|
+
const cache = this[cacheName];
|
|
57
|
+
if (!cache.has(key)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
loggers[cacheName]('invalidate', key);
|
|
61
|
+
cache.delete(key);
|
|
62
|
+
}
|
|
63
|
+
invalidateForFile(filename) {
|
|
64
|
+
cacheNames.forEach(cacheName => {
|
|
65
|
+
this.invalidate(cacheName, filename);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
invalidateIfChanged(filename, content) {
|
|
69
|
+
const hash = this.contentHashes.get(filename);
|
|
70
|
+
const newHash = hashContent(content);
|
|
71
|
+
if (hash !== newHash) {
|
|
72
|
+
cacheLogger('content has changed, invalidate all for %s', filename);
|
|
73
|
+
this.contentHashes.set(filename, newHash);
|
|
74
|
+
this.invalidateForFile(filename);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=cache.js.map
|
package/esm/cache.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","names":["createHash","logger","getFileIdx","hashContent","content","update","digest","cacheLogger","extend","cacheNames","loggers","reduce","acc","key","TransformCacheCollection","contentHashes","Map","constructor","caches","entrypoints","exports","add","cacheName","value","cache","has","get","set","clear","forEach","name","delete","invalidate","res","undefined","invalidateForFile","filename","invalidateIfChanged","hash","newHash"],"sources":["../src/cache.ts"],"sourcesContent":["import { createHash } from 'crypto';\n\nimport { logger } from '@wyw-in-js/shared';\n\nimport type { Entrypoint } from './transform/Entrypoint';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { getFileIdx } from './utils/getFileIdx';\n\nfunction hashContent(content: string) {\n return createHash('sha256').update(content).digest('hex');\n}\n\ninterface ICaches {\n entrypoints: Map<string, Entrypoint | IEvaluatedEntrypoint>;\n exports: Map<string, string[]>;\n}\n\ntype MapValue<T> = T extends Map<string, infer V> ? V : never;\n\nconst cacheLogger = logger.extend('cache');\n\nconst cacheNames = ['entrypoints', 'exports'] as const;\ntype CacheNames = (typeof cacheNames)[number];\n\nconst loggers = cacheNames.reduce(\n (acc, key) => ({\n ...acc,\n [key]: cacheLogger.extend(key),\n }),\n {} as Record<CacheNames, typeof logger>\n);\n\nexport class TransformCacheCollection {\n public readonly entrypoints: Map<string, Entrypoint | IEvaluatedEntrypoint>;\n\n public readonly exports: Map<string, string[]>;\n\n private contentHashes = new Map<string, string>();\n\n constructor(caches: Partial<ICaches> = {}) {\n this.entrypoints = caches.entrypoints || new Map();\n this.exports = caches.exports || new Map();\n }\n\n public add<\n TCache extends CacheNames,\n TValue extends MapValue<ICaches[TCache]>,\n >(cacheName: TCache, key: string, value: TValue): void {\n const cache = this[cacheName] as Map<string, TValue>;\n loggers[cacheName]('%s:add %s %f', getFileIdx(key), key, () => {\n if (!cache.has(key)) {\n return 'added';\n }\n\n return cache.get(key) === value ? 'unchanged' : 'updated';\n });\n\n cache.set(key, value);\n }\n\n public clear(cacheName: CacheNames | 'all'): void {\n if (cacheName === 'all') {\n cacheNames.forEach((name) => {\n this.clear(name);\n });\n\n return;\n }\n\n loggers[cacheName]('clear');\n const cache = this[cacheName] as Map<string, unknown>;\n\n cache.clear();\n }\n\n public delete(cacheName: CacheNames, key: string): void {\n this.invalidate(cacheName, key);\n }\n\n public get<\n TCache extends CacheNames,\n TValue extends MapValue<ICaches[TCache]>,\n >(cacheName: TCache, key: string): TValue | undefined {\n const cache = this[cacheName] as Map<string, TValue>;\n\n const res = cache.get(key);\n loggers[cacheName]('get', key, res === undefined ? 'miss' : 'hit');\n return res;\n }\n\n public has(cacheName: CacheNames, key: string): boolean {\n const cache = this[cacheName] as Map<string, unknown>;\n\n const res = cache.has(key);\n loggers[cacheName]('has', key, res);\n return res;\n }\n\n public invalidate(cacheName: CacheNames, key: string): void {\n const cache = this[cacheName] as Map<string, unknown>;\n if (!cache.has(key)) {\n return;\n }\n\n loggers[cacheName]('invalidate', key);\n\n cache.delete(key);\n }\n\n public invalidateForFile(filename: string) {\n cacheNames.forEach((cacheName) => {\n this.invalidate(cacheName, filename);\n });\n }\n\n public invalidateIfChanged(filename: string, content: string) {\n const hash = this.contentHashes.get(filename);\n const newHash = hashContent(content);\n\n if (hash !== newHash) {\n cacheLogger('content has changed, invalidate all for %s', filename);\n this.contentHashes.set(filename, newHash);\n this.invalidateForFile(filename);\n\n return true;\n }\n\n return false;\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,QAAQ;AAEnC,SAASC,MAAM,QAAQ,mBAAmB;AAI1C,SAASC,UAAU,QAAQ,oBAAoB;AAE/C,SAASC,WAAWA,CAACC,OAAe,EAAE;EACpC,OAAOJ,UAAU,CAAC,QAAQ,CAAC,CAACK,MAAM,CAACD,OAAO,CAAC,CAACE,MAAM,CAAC,KAAK,CAAC;AAC3D;AASA,MAAMC,WAAW,GAAGN,MAAM,CAACO,MAAM,CAAC,OAAO,CAAC;AAE1C,MAAMC,UAAU,GAAG,CAAC,aAAa,EAAE,SAAS,CAAU;AAGtD,MAAMC,OAAO,GAAGD,UAAU,CAACE,MAAM,CAC/B,CAACC,GAAG,EAAEC,GAAG,MAAM;EACb,GAAGD,GAAG;EACN,CAACC,GAAG,GAAGN,WAAW,CAACC,MAAM,CAACK,GAAG;AAC/B,CAAC,CAAC,EACF,CAAC,CACH,CAAC;AAED,OAAO,MAAMC,wBAAwB,CAAC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C;MACnE,IAAI,CAACrB,aAAa,CAACY,GAAG,CAACS,QAAQ,EAAEG,OAAO,CAAC;MACzC,IAAI,CAACJ,iBAAiB,CAACC,QAAQ,CAAC;MAEhC,OAAO,IAAI;IACb;IAEA,OAAO,KAAK;EACd;AACF"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { createWriteStream, existsSync, mkdirSync } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { EventEmitter, isOnActionStartArgs } from '../utils/EventEmitter';
|
|
5
|
+
const workingDir = process.cwd();
|
|
6
|
+
function replacer(_key, value) {
|
|
7
|
+
if (typeof value === 'string' && path.isAbsolute(value)) {
|
|
8
|
+
return path.relative(workingDir, value);
|
|
9
|
+
}
|
|
10
|
+
if (value instanceof Map) {
|
|
11
|
+
return Array.from(value.entries()).reduce((obj, [k, v]) => {
|
|
12
|
+
const key = replacer(k, k);
|
|
13
|
+
return {
|
|
14
|
+
...obj,
|
|
15
|
+
[key]: replacer(key, v)
|
|
16
|
+
};
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function printTimings(timings, startedAt, sourceRoot) {
|
|
22
|
+
if (timings.size === 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
console.log(`\nTimings:`);
|
|
26
|
+
console.log(` Total: ${(performance.now() - startedAt).toFixed()}ms`);
|
|
27
|
+
Array.from(timings.entries()).forEach(([label, byLabel]) => {
|
|
28
|
+
console.log(`\n By ${label}:`);
|
|
29
|
+
const array = Array.from(byLabel.entries());
|
|
30
|
+
// array.sort(([, a], [, b]) => b - a);
|
|
31
|
+
array.sort(([a], [b]) => a.localeCompare(b)).forEach(([value, time]) => {
|
|
32
|
+
const name = value.startsWith(sourceRoot) ? path.relative(sourceRoot, value) : value;
|
|
33
|
+
console.log(` ${name}: ${time}ms`);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const writeJSONl = (stream, data) => {
|
|
38
|
+
stream.write(`${JSON.stringify(data, replacer)}\n`);
|
|
39
|
+
};
|
|
40
|
+
export const createFileReporter = (options = false) => {
|
|
41
|
+
if (!options || !options.dir) {
|
|
42
|
+
return {
|
|
43
|
+
emitter: EventEmitter.dummy,
|
|
44
|
+
onDone: () => {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const reportFolder = existsSync(options.dir) ? options.dir : mkdirSync(options.dir, {
|
|
48
|
+
recursive: true
|
|
49
|
+
});
|
|
50
|
+
if (!reportFolder) {
|
|
51
|
+
throw new Error(`Could not create directory ${options.dir}`);
|
|
52
|
+
}
|
|
53
|
+
const actionStream = createWriteStream(path.join(options.dir, 'actions.jsonl'));
|
|
54
|
+
const dependenciesStream = createWriteStream(path.join(options.dir, 'dependencies.jsonl'));
|
|
55
|
+
const entrypointStream = createWriteStream(path.join(options.dir, 'entrypoints.jsonl'));
|
|
56
|
+
const startedAt = performance.now();
|
|
57
|
+
const timings = new Map();
|
|
58
|
+
const addTiming = (label, key, value) => {
|
|
59
|
+
if (!timings.has(label)) {
|
|
60
|
+
timings.set(label, new Map());
|
|
61
|
+
}
|
|
62
|
+
const forLabel = timings.get(label);
|
|
63
|
+
forLabel.set(key, Math.round((forLabel.get(key) || 0) + value));
|
|
64
|
+
};
|
|
65
|
+
const processDependencyEvent = ({
|
|
66
|
+
file,
|
|
67
|
+
only,
|
|
68
|
+
imports,
|
|
69
|
+
fileIdx
|
|
70
|
+
}) => {
|
|
71
|
+
writeJSONl(dependenciesStream, {
|
|
72
|
+
file,
|
|
73
|
+
only,
|
|
74
|
+
imports,
|
|
75
|
+
fileIdx
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const processSingleEvent = meta => {
|
|
79
|
+
if (meta.type === 'dependency') {
|
|
80
|
+
processDependencyEvent(meta);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const startTimes = new Map();
|
|
84
|
+
const onEvent = (meta, type) => {
|
|
85
|
+
if (type === 'single') {
|
|
86
|
+
processSingleEvent(meta);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (type === 'start') {
|
|
90
|
+
Object.entries(meta).forEach(([label, value]) => {
|
|
91
|
+
startTimes.set(`${label}\0${value}`, performance.now());
|
|
92
|
+
});
|
|
93
|
+
} else {
|
|
94
|
+
Object.entries(meta).forEach(([label, value]) => {
|
|
95
|
+
const startTime = startTimes.get(`${label}\0${value}`);
|
|
96
|
+
if (startTime) {
|
|
97
|
+
addTiming(label, String(value), performance.now() - startTime);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
let actionId = 0;
|
|
103
|
+
const onAction = (...args) => {
|
|
104
|
+
if (isOnActionStartArgs(args)) {
|
|
105
|
+
const [, timestamp, type, idx, entrypointRef] = args;
|
|
106
|
+
writeJSONl(actionStream, {
|
|
107
|
+
actionId,
|
|
108
|
+
entrypointRef,
|
|
109
|
+
idx,
|
|
110
|
+
startedAt: timestamp,
|
|
111
|
+
type
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// eslint-disable-next-line no-plusplus
|
|
115
|
+
return actionId++;
|
|
116
|
+
}
|
|
117
|
+
const [result, timestamp, id, isAsync, error] = args;
|
|
118
|
+
writeJSONl(actionStream, {
|
|
119
|
+
actionId: id,
|
|
120
|
+
error,
|
|
121
|
+
finishedAt: timestamp,
|
|
122
|
+
isAsync,
|
|
123
|
+
result: `${result}ed`
|
|
124
|
+
});
|
|
125
|
+
return id;
|
|
126
|
+
};
|
|
127
|
+
const onEntrypointEvent = (emitterId, timestamp, event) => {
|
|
128
|
+
entrypointStream.write(`${JSON.stringify([emitterId, timestamp, event])}\n`);
|
|
129
|
+
};
|
|
130
|
+
const emitter = new EventEmitter(onEvent, onAction, onEntrypointEvent);
|
|
131
|
+
return {
|
|
132
|
+
emitter,
|
|
133
|
+
onDone: sourceRoot => {
|
|
134
|
+
if (options.print) {
|
|
135
|
+
printTimings(timings, startedAt, sourceRoot);
|
|
136
|
+
console.log('\nMemory usage:', process.memoryUsage());
|
|
137
|
+
}
|
|
138
|
+
actionStream.end();
|
|
139
|
+
dependenciesStream.end();
|
|
140
|
+
timings.clear();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=fileReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileReporter.js","names":["createWriteStream","existsSync","mkdirSync","path","EventEmitter","isOnActionStartArgs","workingDir","process","cwd","replacer","_key","value","isAbsolute","relative","Map","Array","from","entries","reduce","obj","k","v","key","printTimings","timings","startedAt","sourceRoot","size","console","log","performance","now","toFixed","forEach","label","byLabel","array","sort","a","b","localeCompare","time","name","startsWith","writeJSONl","stream","data","write","JSON","stringify","createFileReporter","options","dir","emitter","dummy","onDone","reportFolder","recursive","Error","actionStream","join","dependenciesStream","entrypointStream","addTiming","has","set","forLabel","get","Math","round","processDependencyEvent","file","only","imports","fileIdx","processSingleEvent","meta","type","startTimes","onEvent","Object","startTime","String","actionId","onAction","args","timestamp","idx","entrypointRef","result","id","isAsync","error","finishedAt","onEntrypointEvent","emitterId","event","print","memoryUsage","end","clear"],"sources":["../../src/debug/fileReporter.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { createWriteStream, existsSync, mkdirSync } from 'fs';\nimport path from 'path';\n\nimport type {\n OnAction,\n OnEvent,\n OnActionFinishArgs,\n OnActionStartArgs,\n OnEntrypointEvent,\n} from '../utils/EventEmitter';\nimport { EventEmitter, isOnActionStartArgs } from '../utils/EventEmitter';\n\ntype Timings = Map<string, Map<string, number>>;\n\nexport interface IFileReporterOptions {\n dir?: string;\n print?: boolean;\n}\n\nexport interface IProcessedEvent {\n file: string;\n fileIdx: string;\n imports: { from: string; what: string[] }[];\n only: string[];\n type: 'dependency';\n}\n\nexport interface IQueueActionEvent {\n action: string;\n args?: string[];\n datetime: Date;\n file: string;\n queueIdx: string;\n type: 'queue-action';\n}\n\nconst workingDir = process.cwd();\n\nfunction replacer(_key: string, value: unknown): unknown {\n if (typeof value === 'string' && path.isAbsolute(value)) {\n return path.relative(workingDir, value);\n }\n\n if (value instanceof Map) {\n return Array.from(value.entries()).reduce((obj, [k, v]) => {\n const key = replacer(k, k) as string;\n return {\n ...obj,\n [key]: replacer(key, v),\n };\n }, {});\n }\n\n return value;\n}\n\nfunction printTimings(timings: Timings, startedAt: number, sourceRoot: string) {\n if (timings.size === 0) {\n return;\n }\n\n console.log(`\\nTimings:`);\n console.log(` Total: ${(performance.now() - startedAt).toFixed()}ms`);\n\n Array.from(timings.entries()).forEach(([label, byLabel]) => {\n console.log(`\\n By ${label}:`);\n\n const array = Array.from(byLabel.entries());\n // array.sort(([, a], [, b]) => b - a);\n array\n .sort(([a], [b]) => a.localeCompare(b))\n .forEach(([value, time]) => {\n const name = value.startsWith(sourceRoot)\n ? path.relative(sourceRoot, value)\n : value;\n console.log(` ${name}: ${time}ms`);\n });\n });\n}\n\nconst writeJSONl = (stream: NodeJS.WritableStream, data: unknown) => {\n stream.write(`${JSON.stringify(data, replacer)}\\n`);\n};\n\nexport const createFileReporter = (\n options: IFileReporterOptions | false = false\n) => {\n if (!options || !options.dir) {\n return {\n emitter: EventEmitter.dummy,\n onDone: () => {},\n };\n }\n\n const reportFolder = existsSync(options.dir)\n ? options.dir\n : mkdirSync(options.dir, {\n recursive: true,\n });\n\n if (!reportFolder) {\n throw new Error(`Could not create directory ${options.dir}`);\n }\n\n const actionStream = createWriteStream(\n path.join(options.dir, 'actions.jsonl')\n );\n\n const dependenciesStream = createWriteStream(\n path.join(options.dir, 'dependencies.jsonl')\n );\n\n const entrypointStream = createWriteStream(\n path.join(options.dir, 'entrypoints.jsonl')\n );\n\n const startedAt = performance.now();\n const timings: Timings = new Map();\n const addTiming = (label: string, key: string, value: number) => {\n if (!timings.has(label)) {\n timings.set(label, new Map());\n }\n\n const forLabel = timings.get(label)!;\n forLabel.set(key, Math.round((forLabel.get(key) || 0) + value));\n };\n\n const processDependencyEvent = ({\n file,\n only,\n imports,\n fileIdx,\n }: IProcessedEvent) => {\n writeJSONl(dependenciesStream, {\n file,\n only,\n imports,\n fileIdx,\n });\n };\n\n const processSingleEvent = (\n meta: Record<string, unknown> | IProcessedEvent | IQueueActionEvent\n ) => {\n if (meta.type === 'dependency') {\n processDependencyEvent(meta as IProcessedEvent);\n }\n };\n\n const startTimes = new Map<string, number>();\n\n const onEvent: OnEvent = (meta, type) => {\n if (type === 'single') {\n processSingleEvent(meta);\n return;\n }\n\n if (type === 'start') {\n Object.entries(meta).forEach(([label, value]) => {\n startTimes.set(`${label}\\0${value}`, performance.now());\n });\n } else {\n Object.entries(meta).forEach(([label, value]) => {\n const startTime = startTimes.get(`${label}\\0${value}`);\n if (startTime) {\n addTiming(label, String(value), performance.now() - startTime);\n }\n });\n }\n };\n\n let actionId = 0;\n const onAction: OnAction = (\n ...args: OnActionStartArgs | OnActionFinishArgs\n ) => {\n if (isOnActionStartArgs(args)) {\n const [, timestamp, type, idx, entrypointRef] = args;\n writeJSONl(actionStream, {\n actionId,\n entrypointRef,\n idx,\n startedAt: timestamp,\n type,\n });\n\n // eslint-disable-next-line no-plusplus\n return actionId++;\n }\n\n const [result, timestamp, id, isAsync, error] = args;\n writeJSONl(actionStream, {\n actionId: id,\n error,\n finishedAt: timestamp,\n isAsync,\n result: `${result}ed`,\n });\n\n return id;\n };\n\n const onEntrypointEvent: OnEntrypointEvent = (\n emitterId,\n timestamp,\n event\n ) => {\n entrypointStream.write(\n `${JSON.stringify([emitterId, timestamp, event])}\\n`\n );\n };\n\n const emitter = new EventEmitter(onEvent, onAction, onEntrypointEvent);\n\n return {\n emitter,\n onDone: (sourceRoot: string) => {\n if (options.print) {\n printTimings(timings, startedAt, sourceRoot);\n\n console.log('\\nMemory usage:', process.memoryUsage());\n }\n\n actionStream.end();\n dependenciesStream.end();\n timings.clear();\n },\n };\n};\n"],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
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Module } from '../module';
|
|
6
|
+
export default function evaluate(services, entrypoint) {
|
|
7
|
+
const m = new Module(services, entrypoint);
|
|
8
|
+
m.evaluate();
|
|
9
|
+
return {
|
|
10
|
+
value: entrypoint.exports,
|
|
11
|
+
dependencies: m.dependencies
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["Module","evaluate","services","entrypoint","m","value","exports","dependencies"],"sources":["../../src/evaluators/index.ts"],"sourcesContent":["/**\n * This file is an entry point for module evaluation for getting lazy dependencies.\n */\n\nimport { Module } from '../module';\nimport type { Entrypoint } from '../transform/Entrypoint';\nimport type { Services } from '../transform/types';\n\nexport interface IEvaluateResult {\n dependencies: string[];\n value: Record<string | symbol, unknown>;\n}\n\nexport default function evaluate(\n services: Services,\n entrypoint: Entrypoint\n): IEvaluateResult {\n const m = new Module(services, entrypoint);\n\n m.evaluate();\n\n return {\n value: entrypoint.exports,\n dependencies: m.dependencies,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,MAAM,QAAQ,WAAW;AASlC,eAAe,SAASC,QAAQA,CAC9BC,QAAkB,EAClBC,UAAsB,EACL;EACjB,MAAMC,CAAC,GAAG,IAAIJ,MAAM,CAACE,QAAQ,EAAEC,UAAU,CAAC;EAE1CC,CAAC,CAACH,QAAQ,CAAC,CAAC;EAEZ,OAAO;IACLI,KAAK,EAAEF,UAAU,CAACG,OAAO;IACzBC,YAAY,EAAEH,CAAC,CAACG;EAClB,CAAC;AACH"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { slugify } from '@wyw-in-js/shared';
|
|
2
|
+
export { createFileReporter } from './debug/fileReporter';
|
|
3
|
+
export { default as preeval } from './plugins/preeval';
|
|
4
|
+
export { getTransformMetadata, withTransformMetadata } from './utils/TransformMetadata';
|
|
5
|
+
export { Module, DefaultModuleImplementation } from './module';
|
|
6
|
+
export { transform } from './transform';
|
|
7
|
+
export { isUnprocessedEntrypointError, UnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';
|
|
8
|
+
export * from './types';
|
|
9
|
+
export { EvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';
|
|
10
|
+
export { parseFile } from './transform/Entrypoint.helpers';
|
|
11
|
+
export { baseHandlers } from './transform/generators';
|
|
12
|
+
export { prepareCode } from './transform/generators/transform';
|
|
13
|
+
export { Entrypoint } from './transform/Entrypoint';
|
|
14
|
+
export { transformUrl } from './transform/generators/extract';
|
|
15
|
+
export { asyncResolveImports, syncResolveImports } from './transform/generators/resolveImports';
|
|
16
|
+
export { loadLinariaOptions } from './transform/helpers/loadLinariaOptions';
|
|
17
|
+
export { withDefaultServices } from './transform/helpers/withDefaultServices';
|
|
18
|
+
export { isNode } from './utils/isNode';
|
|
19
|
+
export { getTagProcessor } from './utils/getTagProcessor';
|
|
20
|
+
export { getVisitorKeys } from './utils/getVisitorKeys';
|
|
21
|
+
export { peek } from './utils/peek';
|
|
22
|
+
export { processTemplateExpression } from './utils/processTemplateExpression';
|
|
23
|
+
export { TransformCacheCollection } from './cache';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["slugify","createFileReporter","default","preeval","getTransformMetadata","withTransformMetadata","Module","DefaultModuleImplementation","transform","isUnprocessedEntrypointError","UnprocessedEntrypointError","EvaluatedEntrypoint","parseFile","baseHandlers","prepareCode","Entrypoint","transformUrl","asyncResolveImports","syncResolveImports","loadLinariaOptions","withDefaultServices","isNode","getTagProcessor","getVisitorKeys","peek","processTemplateExpression","TransformCacheCollection"],"sources":["../src/index.ts"],"sourcesContent":["export { slugify } from '@wyw-in-js/shared';\n\nexport { createFileReporter } from './debug/fileReporter';\nexport type { IFileReporterOptions } from './debug/fileReporter';\nexport { default as preeval } from './plugins/preeval';\nexport {\n getTransformMetadata,\n withTransformMetadata,\n} from './utils/TransformMetadata';\nexport type { WYWTransformMetadata } from './utils/TransformMetadata';\nexport { Module, DefaultModuleImplementation } from './module';\nexport { transform } from './transform';\nexport {\n isUnprocessedEntrypointError,\n UnprocessedEntrypointError,\n} from './transform/actions/UnprocessedEntrypointError';\nexport * from './types';\nexport { EvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nexport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nexport { parseFile } from './transform/Entrypoint.helpers';\nexport type { LoadAndParseFn } from './transform/Entrypoint.types';\nexport { baseHandlers } from './transform/generators';\nexport { prepareCode } from './transform/generators/transform';\nexport { Entrypoint } from './transform/Entrypoint';\nexport { transformUrl } from './transform/generators/extract';\nexport {\n asyncResolveImports,\n syncResolveImports,\n} from './transform/generators/resolveImports';\nexport { loadLinariaOptions } from './transform/helpers/loadLinariaOptions';\nexport { withDefaultServices } from './transform/helpers/withDefaultServices';\nexport type { Services } from './transform/types';\nexport type { EventEmitter } from './utils/EventEmitter';\nexport { isNode } from './utils/isNode';\nexport { getTagProcessor } from './utils/getTagProcessor';\nexport { getVisitorKeys } from './utils/getVisitorKeys';\nexport type { VisitorKeys } from './utils/getVisitorKeys';\nexport { peek } from './utils/peek';\nexport { processTemplateExpression } from './utils/processTemplateExpression';\nexport { TransformCacheCollection } from './cache';\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAE3C,SAASC,kBAAkB,QAAQ,sBAAsB;AAEzD,SAASC,OAAO,IAAIC,OAAO,QAAQ,mBAAmB;AACtD,SACEC,oBAAoB,EACpBC,qBAAqB,QAChB,2BAA2B;AAElC,SAASC,MAAM,EAAEC,2BAA2B,QAAQ,UAAU;AAC9D,SAASC,SAAS,QAAQ,aAAa;AACvC,SACEC,4BAA4B,EAC5BC,0BAA0B,QACrB,gDAAgD;AACvD,cAAc,SAAS;AACvB,SAASC,mBAAmB,QAAQ,iCAAiC;AAErE,SAASC,SAAS,QAAQ,gCAAgC;AAE1D,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,WAAW,QAAQ,kCAAkC;AAC9D,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,YAAY,QAAQ,gCAAgC;AAC7D,SACEC,mBAAmB,EACnBC,kBAAkB,QACb,uCAAuC;AAC9C,SAASC,kBAAkB,QAAQ,wCAAwC;AAC3E,SAASC,mBAAmB,QAAQ,yCAAyC;AAG7E,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,SAASC,IAAI,QAAQ,cAAc;AACnC,SAASC,yBAAyB,QAAQ,mCAAmC;AAC7E,SAASC,wBAAwB,QAAQ,SAAS"}
|
package/esm/module.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
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, e.g. `babel-register`
|
|
7
|
+
* - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds
|
|
8
|
+
*
|
|
9
|
+
* We also use it to transpile the code with Babel by default.
|
|
10
|
+
* We also store source maps for it to provide correct error stacktraces.
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from 'fs';
|
|
15
|
+
import NativeModule from 'module';
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import vm from 'vm';
|
|
18
|
+
import { invariant } from 'ts-invariant';
|
|
19
|
+
import './utils/dispose-polyfill';
|
|
20
|
+
import { Entrypoint } from './transform/Entrypoint';
|
|
21
|
+
import { getStack, isSuperSet } from './transform/Entrypoint.helpers';
|
|
22
|
+
import { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';
|
|
23
|
+
import { createVmContext } from './vm/createVmContext';
|
|
24
|
+
export const DefaultModuleImplementation = NativeModule;
|
|
25
|
+
|
|
26
|
+
// Supported node builtins based on the modules polyfilled by webpack
|
|
27
|
+
// `true` means module is polyfilled, `false` means module is empty
|
|
28
|
+
const builtins = {
|
|
29
|
+
assert: true,
|
|
30
|
+
buffer: true,
|
|
31
|
+
child_process: false,
|
|
32
|
+
cluster: false,
|
|
33
|
+
console: true,
|
|
34
|
+
constants: true,
|
|
35
|
+
crypto: true,
|
|
36
|
+
dgram: false,
|
|
37
|
+
dns: false,
|
|
38
|
+
domain: true,
|
|
39
|
+
events: true,
|
|
40
|
+
fs: false,
|
|
41
|
+
http: true,
|
|
42
|
+
https: true,
|
|
43
|
+
module: false,
|
|
44
|
+
net: false,
|
|
45
|
+
os: true,
|
|
46
|
+
path: true,
|
|
47
|
+
punycode: true,
|
|
48
|
+
process: true,
|
|
49
|
+
querystring: true,
|
|
50
|
+
readline: false,
|
|
51
|
+
repl: false,
|
|
52
|
+
stream: true,
|
|
53
|
+
string_decoder: true,
|
|
54
|
+
sys: true,
|
|
55
|
+
timers: true,
|
|
56
|
+
tls: false,
|
|
57
|
+
tty: true,
|
|
58
|
+
url: true,
|
|
59
|
+
util: true,
|
|
60
|
+
vm: true,
|
|
61
|
+
zlib: true
|
|
62
|
+
};
|
|
63
|
+
const NOOP = () => {};
|
|
64
|
+
function getUncached(cached, test) {
|
|
65
|
+
const cachedSet = new Set(typeof cached === 'string' ? cached.split(',') : cached);
|
|
66
|
+
if (cachedSet.has('*')) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return test.filter(t => !cachedSet.has(t));
|
|
70
|
+
}
|
|
71
|
+
function resolve(id) {
|
|
72
|
+
const {
|
|
73
|
+
resolved
|
|
74
|
+
} = this.resolveDependency(id);
|
|
75
|
+
invariant(resolved, `Unable to resolve "${id}"`);
|
|
76
|
+
return resolved;
|
|
77
|
+
}
|
|
78
|
+
export class Module {
|
|
79
|
+
callstack = [];
|
|
80
|
+
isEvaluated = false;
|
|
81
|
+
require = Object.assign(id => {
|
|
82
|
+
if (id in builtins) {
|
|
83
|
+
// The module is in the allowed list of builtin node modules
|
|
84
|
+
// Ideally we should prevent importing them, but webpack polyfills some
|
|
85
|
+
// So we check for the list of polyfills to determine which ones to support
|
|
86
|
+
if (builtins[id]) {
|
|
87
|
+
this.debug('require', `builtin '${id}'`);
|
|
88
|
+
return require(id);
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Resolve module id (and filename) relatively to parent module
|
|
94
|
+
const dependency = this.resolveDependency(id);
|
|
95
|
+
if (dependency.resolved === id && !path.isAbsolute(id)) {
|
|
96
|
+
// The module is a builtin node modules, but not in the allowed list
|
|
97
|
+
throw new Error(`Unable to import "${id}". Importing Node builtins is not supported in the sandbox.`);
|
|
98
|
+
}
|
|
99
|
+
invariant(dependency.resolved, `Dependency ${dependency.source} cannot be resolved`);
|
|
100
|
+
this.dependencies.push(id);
|
|
101
|
+
this.debug('require', `${id} -> ${dependency.resolved}`);
|
|
102
|
+
const entrypoint = this.getEntrypoint(dependency.resolved, dependency.only, this.debug);
|
|
103
|
+
if (entrypoint === null) {
|
|
104
|
+
return dependency.resolved;
|
|
105
|
+
}
|
|
106
|
+
if (entrypoint.evaluated || isSuperSet(entrypoint.evaluatedOnly, dependency.only)) {
|
|
107
|
+
return entrypoint.exports;
|
|
108
|
+
}
|
|
109
|
+
const m = this.createChild(entrypoint);
|
|
110
|
+
m.evaluate();
|
|
111
|
+
return entrypoint.exports;
|
|
112
|
+
}, {
|
|
113
|
+
ensure: NOOP,
|
|
114
|
+
resolve: resolve.bind(this)
|
|
115
|
+
});
|
|
116
|
+
resolve = resolve.bind(this);
|
|
117
|
+
#entrypointRef;
|
|
118
|
+
constructor(services, entrypoint, parentModule, moduleImpl = DefaultModuleImplementation) {
|
|
119
|
+
this.services = services;
|
|
120
|
+
this.moduleImpl = moduleImpl;
|
|
121
|
+
this.cache = services.cache;
|
|
122
|
+
this.#entrypointRef = new WeakRef(entrypoint);
|
|
123
|
+
this.idx = entrypoint.idx;
|
|
124
|
+
this.id = entrypoint.name;
|
|
125
|
+
this.filename = entrypoint.name;
|
|
126
|
+
this.dependencies = [];
|
|
127
|
+
this.debug = entrypoint.log.extend('module');
|
|
128
|
+
this.parentIsIgnored = parentModule?.ignored ?? false;
|
|
129
|
+
this.ignored = entrypoint.ignored ?? this.parentIsIgnored;
|
|
130
|
+
if (parentModule) {
|
|
131
|
+
this.callstack = [entrypoint.name, ...parentModule.callstack];
|
|
132
|
+
} else {
|
|
133
|
+
this.callstack = [entrypoint.name];
|
|
134
|
+
}
|
|
135
|
+
this.extensions = services.options.pluginOptions.extensions;
|
|
136
|
+
this.debug('init', entrypoint.name);
|
|
137
|
+
}
|
|
138
|
+
get exports() {
|
|
139
|
+
return this.entrypoint.exports;
|
|
140
|
+
}
|
|
141
|
+
set exports(value) {
|
|
142
|
+
this.entrypoint.exports = value;
|
|
143
|
+
this.debug('the whole exports was overridden with %O', value);
|
|
144
|
+
}
|
|
145
|
+
get entrypoint() {
|
|
146
|
+
const entrypoint = this.#entrypointRef.deref();
|
|
147
|
+
invariant(entrypoint, `Module ${this.idx} is disposed`);
|
|
148
|
+
return entrypoint;
|
|
149
|
+
}
|
|
150
|
+
evaluate() {
|
|
151
|
+
const {
|
|
152
|
+
entrypoint
|
|
153
|
+
} = this;
|
|
154
|
+
entrypoint.assertTransformed();
|
|
155
|
+
const cached = this.cache.get('entrypoints', entrypoint.name);
|
|
156
|
+
let evaluatedCreated = false;
|
|
157
|
+
if (!entrypoint.supersededWith) {
|
|
158
|
+
this.cache.add('entrypoints', entrypoint.name, entrypoint.createEvaluated());
|
|
159
|
+
evaluatedCreated = true;
|
|
160
|
+
}
|
|
161
|
+
const {
|
|
162
|
+
transformedCode: source
|
|
163
|
+
} = entrypoint;
|
|
164
|
+
const {
|
|
165
|
+
pluginOptions
|
|
166
|
+
} = this.services.options;
|
|
167
|
+
if (!source) {
|
|
168
|
+
this.debug(`evaluate`, 'there is nothing to evaluate');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (this.isEvaluated) {
|
|
172
|
+
this.debug('evaluate', `is already evaluated`);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.debug('evaluate');
|
|
176
|
+
this.debug.extend('source')('%s', source);
|
|
177
|
+
this.isEvaluated = true;
|
|
178
|
+
const {
|
|
179
|
+
filename
|
|
180
|
+
} = this;
|
|
181
|
+
if (/\.json$/.test(filename)) {
|
|
182
|
+
// For JSON files, parse it to a JS object similar to Node
|
|
183
|
+
this.exports = JSON.parse(source);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const {
|
|
187
|
+
context,
|
|
188
|
+
teardown
|
|
189
|
+
} = createVmContext(filename, pluginOptions.features, {
|
|
190
|
+
module: this,
|
|
191
|
+
exports: entrypoint.exports,
|
|
192
|
+
require: this.require,
|
|
193
|
+
__wyw_dynamic_import: async id => this.require(id),
|
|
194
|
+
__dirname: path.dirname(filename)
|
|
195
|
+
}, pluginOptions.overrideContext);
|
|
196
|
+
try {
|
|
197
|
+
const script = new vm.Script(`(function (exports) { ${source}\n})(exports);`, {
|
|
198
|
+
filename
|
|
199
|
+
});
|
|
200
|
+
script.runInContext(context);
|
|
201
|
+
} catch (e) {
|
|
202
|
+
this.isEvaluated = false;
|
|
203
|
+
if (evaluatedCreated) {
|
|
204
|
+
this.cache.add('entrypoints', entrypoint.name, cached);
|
|
205
|
+
}
|
|
206
|
+
if (isUnprocessedEntrypointError(e)) {
|
|
207
|
+
// It will be handled by evalFile scenario
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
210
|
+
if (e instanceof EvalError) {
|
|
211
|
+
this.debug('%O', e);
|
|
212
|
+
throw e;
|
|
213
|
+
}
|
|
214
|
+
this.debug('%O\n%O', e, this.callstack);
|
|
215
|
+
throw new EvalError(`${e.message} in${this.callstack.join('\n| ')}\n`);
|
|
216
|
+
} finally {
|
|
217
|
+
teardown();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
getEntrypoint(filename, only, log) {
|
|
221
|
+
const extension = path.extname(filename);
|
|
222
|
+
if (extension !== '.json' && !this.extensions.includes(extension)) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
const entrypoint = this.cache.get('entrypoints', filename);
|
|
226
|
+
if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {
|
|
227
|
+
log('✅ file has been already evaluated');
|
|
228
|
+
return entrypoint;
|
|
229
|
+
}
|
|
230
|
+
if (entrypoint?.ignored) {
|
|
231
|
+
log('✅ file has been ignored during prepare stage. Original code will be used');
|
|
232
|
+
return entrypoint;
|
|
233
|
+
}
|
|
234
|
+
if (this.ignored) {
|
|
235
|
+
log('✅ one of the parent files has been ignored during prepare stage. Original code will be used');
|
|
236
|
+
const newEntrypoint = this.entrypoint.createChild(filename, ['*'], fs.readFileSync(filename, 'utf-8'));
|
|
237
|
+
if (newEntrypoint === 'loop') {
|
|
238
|
+
const stack = getStack(this.entrypoint);
|
|
239
|
+
throw new Error(`Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`);
|
|
240
|
+
}
|
|
241
|
+
return newEntrypoint;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Requested file can be already prepared for evaluation on the stage 1
|
|
245
|
+
if (only && entrypoint) {
|
|
246
|
+
const uncachedExports = getUncached(entrypoint.only ?? [], only);
|
|
247
|
+
if (uncachedExports.length === 0) {
|
|
248
|
+
log('✅ ready for evaluation');
|
|
249
|
+
return entrypoint;
|
|
250
|
+
}
|
|
251
|
+
log('❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)', uncachedExports, entrypoint.only);
|
|
252
|
+
} else {
|
|
253
|
+
log('❌ file has not been processed during prepare stage');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// If code wasn't extracted from cache, it indicates that we were unable
|
|
257
|
+
// to process some of the imports on stage1. Let's try to reprocess.
|
|
258
|
+
const code = fs.readFileSync(filename, 'utf-8');
|
|
259
|
+
const newEntrypoint = Entrypoint.createRoot(this.services, filename, only, code);
|
|
260
|
+
if (newEntrypoint.evaluated) {
|
|
261
|
+
log('✅ file has been already evaluated');
|
|
262
|
+
return newEntrypoint;
|
|
263
|
+
}
|
|
264
|
+
if (newEntrypoint.ignored) {
|
|
265
|
+
log('✅ file has been ignored during prepare stage. Original code will be used');
|
|
266
|
+
return newEntrypoint;
|
|
267
|
+
}
|
|
268
|
+
return newEntrypoint;
|
|
269
|
+
}
|
|
270
|
+
resolveDependency = id => {
|
|
271
|
+
const cached = this.entrypoint.getDependency(id);
|
|
272
|
+
invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');
|
|
273
|
+
if (cached) {
|
|
274
|
+
return cached;
|
|
275
|
+
}
|
|
276
|
+
if (!this.ignored) {
|
|
277
|
+
this.debug('❌ import has not been resolved during prepare stage. Fallback to Node.js resolver');
|
|
278
|
+
}
|
|
279
|
+
const extensions = this.moduleImpl._extensions;
|
|
280
|
+
const added = [];
|
|
281
|
+
try {
|
|
282
|
+
// Check for supported extensions
|
|
283
|
+
this.extensions.forEach(ext => {
|
|
284
|
+
if (ext in extensions) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// When an extension is not supported, add it
|
|
289
|
+
// And keep track of it to clean it up after resolving
|
|
290
|
+
// Use noop for the transform function since we handle it
|
|
291
|
+
extensions[ext] = NOOP;
|
|
292
|
+
added.push(ext);
|
|
293
|
+
});
|
|
294
|
+
const {
|
|
295
|
+
filename
|
|
296
|
+
} = this;
|
|
297
|
+
const resolved = this.moduleImpl._resolveFilename(id, {
|
|
298
|
+
id: filename,
|
|
299
|
+
filename,
|
|
300
|
+
paths: this.moduleImpl._nodeModulePaths(path.dirname(filename))
|
|
301
|
+
});
|
|
302
|
+
return {
|
|
303
|
+
source: id,
|
|
304
|
+
only: ['*'],
|
|
305
|
+
resolved
|
|
306
|
+
};
|
|
307
|
+
} finally {
|
|
308
|
+
// Cleanup the extensions we added to restore previous behaviour
|
|
309
|
+
added.forEach(ext => delete extensions[ext]);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
createChild(entrypoint) {
|
|
313
|
+
return new Module(this.services, entrypoint, this, this.moduleImpl);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=module.js.map
|