@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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getSource } from './getSource';
|
|
2
|
+
import { isSerializable } from './isSerializable';
|
|
3
|
+
export function valueToLiteral(value, ex) {
|
|
4
|
+
if (value === undefined) {
|
|
5
|
+
return {
|
|
6
|
+
type: 'Identifier',
|
|
7
|
+
name: 'undefined'
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
if (isSerializable(value)) {
|
|
11
|
+
if (value === null) {
|
|
12
|
+
return {
|
|
13
|
+
type: 'NullLiteral'
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
return {
|
|
18
|
+
type: 'StringLiteral',
|
|
19
|
+
value
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'number') {
|
|
23
|
+
return {
|
|
24
|
+
type: 'NumericLiteral',
|
|
25
|
+
value
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'boolean') {
|
|
29
|
+
return {
|
|
30
|
+
type: 'BooleanLiteral',
|
|
31
|
+
value
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
return {
|
|
36
|
+
type: 'ArrayExpression',
|
|
37
|
+
elements: value.map(v => valueToLiteral(v, ex))
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
type: 'ObjectExpression',
|
|
42
|
+
properties: Object.entries(value).map(([key, v]) => ({
|
|
43
|
+
type: 'ObjectProperty',
|
|
44
|
+
key: key.match(/^[a-zA-Z]\w*$/) ? {
|
|
45
|
+
type: 'Identifier',
|
|
46
|
+
name: key
|
|
47
|
+
} : {
|
|
48
|
+
type: 'StringLiteral',
|
|
49
|
+
value: key
|
|
50
|
+
},
|
|
51
|
+
value: valueToLiteral(v, ex),
|
|
52
|
+
computed: false,
|
|
53
|
+
shorthand: false
|
|
54
|
+
}))
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
throw ex.buildCodeFrameError(`The expression evaluated to '${value}', which is probably a mistake. If you want it to be inserted into CSS, explicitly cast or transform the value to a string, e.g. - 'String(${getSource(ex)})'.`);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=valueToLiteral.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valueToLiteral.js","names":["getSource","isSerializable","valueToLiteral","value","ex","undefined","type","name","Array","isArray","elements","map","v","properties","Object","entries","key","match","computed","shorthand","buildCodeFrameError"],"sources":["../../src/utils/valueToLiteral.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { Expression } from '@babel/types';\n\nimport { getSource } from './getSource';\nimport { isSerializable } from './isSerializable';\n\nexport function valueToLiteral(value: unknown, ex: NodePath): Expression {\n if (value === undefined) {\n return {\n type: 'Identifier',\n name: 'undefined',\n };\n }\n\n if (isSerializable(value)) {\n if (value === null) {\n return {\n type: 'NullLiteral',\n };\n }\n\n if (typeof value === 'string') {\n return {\n type: 'StringLiteral',\n value,\n };\n }\n\n if (typeof value === 'number') {\n return {\n type: 'NumericLiteral',\n value,\n };\n }\n\n if (typeof value === 'boolean') {\n return {\n type: 'BooleanLiteral',\n value,\n };\n }\n\n if (Array.isArray(value)) {\n return {\n type: 'ArrayExpression',\n elements: value.map((v) => valueToLiteral(v, ex)),\n };\n }\n\n return {\n type: 'ObjectExpression',\n properties: Object.entries(value).map(([key, v]) => ({\n type: 'ObjectProperty',\n key: key.match(/^[a-zA-Z]\\w*$/)\n ? {\n type: 'Identifier',\n name: key,\n }\n : {\n type: 'StringLiteral',\n value: key,\n },\n value: valueToLiteral(v, ex),\n computed: false,\n shorthand: false,\n })),\n };\n }\n\n throw ex.buildCodeFrameError(\n `The expression evaluated to '${value}', which is probably a mistake. If you want it to be inserted into CSS, explicitly cast or transform the value to a string, e.g. - 'String(${getSource(\n ex\n )})'.`\n );\n}\n"],"mappings":"AAGA,SAASA,SAAS,QAAQ,aAAa;AACvC,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,OAAO,SAASC,cAAcA,CAACC,KAAc,EAAEC,EAAY,EAAc;EACvE,IAAID,KAAK,KAAKE,SAAS,EAAE;IACvB,OAAO;MACLC,IAAI,EAAE,YAAY;MAClBC,IAAI,EAAE;IACR,CAAC;EACH;EAEA,IAAIN,cAAc,CAACE,KAAK,CAAC,EAAE;IACzB,IAAIA,KAAK,KAAK,IAAI,EAAE;MAClB,OAAO;QACLG,IAAI,EAAE;MACR,CAAC;IACH;IAEA,IAAI,OAAOH,KAAK,KAAK,QAAQ,EAAE;MAC7B,OAAO;QACLG,IAAI,EAAE,eAAe;QACrBH;MACF,CAAC;IACH;IAEA,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B,OAAO;QACLG,IAAI,EAAE,gBAAgB;QACtBH;MACF,CAAC;IACH;IAEA,IAAI,OAAOA,KAAK,KAAK,SAAS,EAAE;MAC9B,OAAO;QACLG,IAAI,EAAE,gBAAgB;QACtBH;MACF,CAAC;IACH;IAEA,IAAIK,KAAK,CAACC,OAAO,CAACN,KAAK,CAAC,EAAE;MACxB,OAAO;QACLG,IAAI,EAAE,iBAAiB;QACvBI,QAAQ,EAAEP,KAAK,CAACQ,GAAG,CAAEC,CAAC,IAAKV,cAAc,CAACU,CAAC,EAAER,EAAE,CAAC;MAClD,CAAC;IACH;IAEA,OAAO;MACLE,IAAI,EAAE,kBAAkB;MACxBO,UAAU,EAAEC,MAAM,CAACC,OAAO,CAACZ,KAAK,CAAC,CAACQ,GAAG,CAAC,CAAC,CAACK,GAAG,EAAEJ,CAAC,CAAC,MAAM;QACnDN,IAAI,EAAE,gBAAgB;QACtBU,GAAG,EAAEA,GAAG,CAACC,KAAK,CAAC,eAAe,CAAC,GAC3B;UACEX,IAAI,EAAE,YAAY;UAClBC,IAAI,EAAES;QACR,CAAC,GACD;UACEV,IAAI,EAAE,eAAe;UACrBH,KAAK,EAAEa;QACT,CAAC;QACLb,KAAK,EAAED,cAAc,CAACU,CAAC,EAAER,EAAE,CAAC;QAC5Bc,QAAQ,EAAE,KAAK;QACfC,SAAS,EAAE;MACb,CAAC,CAAC;IACJ,CAAC;EACH;EAEA,MAAMf,EAAE,CAACgB,mBAAmB,CACzB,gCAA+BjB,KAAM,8IAA6IH,SAAS,CAC1LI,EACF,CAAE,KACJ,CAAC;AACH"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { types as t } from '@babel/core';
|
|
2
|
+
import { getScope } from '../getScope';
|
|
3
|
+
import { mutate } from '../scopeHelpers';
|
|
4
|
+
function getFunctionName(path) {
|
|
5
|
+
if (path.isClassMethod() && t.isIdentifier(path.node.key)) {
|
|
6
|
+
return path.node.key.name;
|
|
7
|
+
}
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
export function JSXElementsRemover(path) {
|
|
11
|
+
// JSX can be safely replaced with null because it is unnecessary for styles
|
|
12
|
+
const nullLiteral = t.nullLiteral();
|
|
13
|
+
|
|
14
|
+
// We can do even more
|
|
15
|
+
// If that JSX is a result of a function, we can replace the function body.
|
|
16
|
+
const functionScope = getScope(path).getFunctionParent();
|
|
17
|
+
const scopePath = functionScope?.path;
|
|
18
|
+
if (scopePath?.isFunction()) {
|
|
19
|
+
const emptyBody = t.blockStatement([t.returnStatement(nullLiteral)]);
|
|
20
|
+
|
|
21
|
+
// Is it not just a function, but a method `render`?
|
|
22
|
+
if (getFunctionName(scopePath) === 'render') {
|
|
23
|
+
const decl = scopePath.findParent(p => p.isClassDeclaration());
|
|
24
|
+
|
|
25
|
+
// Replace the whole component
|
|
26
|
+
if (decl?.isClassDeclaration()) {
|
|
27
|
+
mutate(decl, p => {
|
|
28
|
+
p.replaceWith(t.functionDeclaration(decl.node.id, [], emptyBody));
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const body = scopePath.get('body');
|
|
34
|
+
if (Array.isArray(body)) {
|
|
35
|
+
throw new Error("A body of a function is expected to be a single element but an array was returned. It's possible if JS syntax has been changed since that code was written.");
|
|
36
|
+
}
|
|
37
|
+
const node = {
|
|
38
|
+
...scopePath.node,
|
|
39
|
+
body: emptyBody,
|
|
40
|
+
params: []
|
|
41
|
+
};
|
|
42
|
+
mutate(scopePath, p => {
|
|
43
|
+
p.replaceWith(node);
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
mutate(path, p => {
|
|
47
|
+
p.replaceWith(nullLiteral);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=JSXElementsRemover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSXElementsRemover.js","names":["types","t","getScope","mutate","getFunctionName","path","isClassMethod","isIdentifier","node","key","name","JSXElementsRemover","nullLiteral","functionScope","getFunctionParent","scopePath","isFunction","emptyBody","blockStatement","returnStatement","decl","findParent","p","isClassDeclaration","replaceWith","functionDeclaration","id","body","get","Array","isArray","Error","params"],"sources":["../../../src/utils/visitors/JSXElementsRemover.ts"],"sourcesContent":["import { types as t } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n CallExpression,\n Function as FunctionNode,\n JSX,\n} from '@babel/types';\n\nimport { getScope } from '../getScope';\nimport { mutate } from '../scopeHelpers';\n\nfunction getFunctionName(path: NodePath<FunctionNode>): string | null {\n if (path.isClassMethod() && t.isIdentifier(path.node.key)) {\n return path.node.key.name;\n }\n\n return null;\n}\n\nexport function JSXElementsRemover(path: NodePath<JSX | CallExpression>) {\n // JSX can be safely replaced with null because it is unnecessary for styles\n const nullLiteral = t.nullLiteral();\n\n // We can do even more\n // If that JSX is a result of a function, we can replace the function body.\n const functionScope = getScope(path).getFunctionParent();\n const scopePath = functionScope?.path;\n if (scopePath?.isFunction()) {\n const emptyBody = t.blockStatement([t.returnStatement(nullLiteral)]);\n\n // Is it not just a function, but a method `render`?\n if (getFunctionName(scopePath) === 'render') {\n const decl = scopePath.findParent((p) => p.isClassDeclaration());\n\n // Replace the whole component\n if (decl?.isClassDeclaration()) {\n mutate(decl, (p) => {\n p.replaceWith(t.functionDeclaration(decl.node.id, [], emptyBody));\n });\n\n return;\n }\n }\n\n const body = scopePath.get('body');\n if (Array.isArray(body)) {\n throw new Error(\n \"A body of a function is expected to be a single element but an array was returned. It's possible if JS syntax has been changed since that code was written.\"\n );\n }\n\n const node: typeof scopePath.node = {\n ...scopePath.node,\n body: emptyBody,\n params: [],\n };\n\n mutate(scopePath, (p) => {\n p.replaceWith(node);\n });\n } else {\n mutate(path, (p) => {\n p.replaceWith(nullLiteral);\n });\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,IAAIC,CAAC,QAAQ,aAAa;AAQxC,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,MAAM,QAAQ,iBAAiB;AAExC,SAASC,eAAeA,CAACC,IAA4B,EAAiB;EACpE,IAAIA,IAAI,CAACC,aAAa,CAAC,CAAC,IAAIL,CAAC,CAACM,YAAY,CAACF,IAAI,CAACG,IAAI,CAACC,GAAG,CAAC,EAAE;IACzD,OAAOJ,IAAI,CAACG,IAAI,CAACC,GAAG,CAACC,IAAI;EAC3B;EAEA,OAAO,IAAI;AACb;AAEA,OAAO,SAASC,kBAAkBA,CAACN,IAAoC,EAAE;EACvE;EACA,MAAMO,WAAW,GAAGX,CAAC,CAACW,WAAW,CAAC,CAAC;;EAEnC;EACA;EACA,MAAMC,aAAa,GAAGX,QAAQ,CAACG,IAAI,CAAC,CAACS,iBAAiB,CAAC,CAAC;EACxD,MAAMC,SAA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led } from '@wyw-in-js/shared';
|
|
3
|
+
import * as process from './process';
|
|
4
|
+
const NOOP = () => {};
|
|
5
|
+
function createWindow() {
|
|
6
|
+
const {
|
|
7
|
+
Window,
|
|
8
|
+
GlobalWindow
|
|
9
|
+
} = require('happy-dom');
|
|
10
|
+
const HappyWindow = GlobalWindow || Window;
|
|
11
|
+
const win = new HappyWindow();
|
|
12
|
+
|
|
13
|
+
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
|
|
14
|
+
win.Buffer = Buffer;
|
|
15
|
+
win.Uint8Array = Uint8Array;
|
|
16
|
+
return win;
|
|
17
|
+
}
|
|
18
|
+
function createBaseContext(win, additionalContext) {
|
|
19
|
+
const baseContext = win ?? {};
|
|
20
|
+
baseContext.document = win?.document;
|
|
21
|
+
baseContext.window = win;
|
|
22
|
+
baseContext.self = win;
|
|
23
|
+
baseContext.top = win;
|
|
24
|
+
baseContext.parent = win;
|
|
25
|
+
baseContext.global = win;
|
|
26
|
+
baseContext.process = process;
|
|
27
|
+
baseContext.clearImmediate = NOOP;
|
|
28
|
+
baseContext.clearInterval = NOOP;
|
|
29
|
+
baseContext.clearTimeout = NOOP;
|
|
30
|
+
baseContext.setImmediate = NOOP;
|
|
31
|
+
baseContext.requestAnimationFrame = NOOP;
|
|
32
|
+
baseContext.setInterval = NOOP;
|
|
33
|
+
baseContext.setTimeout = NOOP;
|
|
34
|
+
|
|
35
|
+
// eslint-disable-next-line guard-for-in,no-restricted-syntax
|
|
36
|
+
for (const key in additionalContext) {
|
|
37
|
+
baseContext[key] = additionalContext[key];
|
|
38
|
+
}
|
|
39
|
+
return baseContext;
|
|
40
|
+
}
|
|
41
|
+
function createHappyDOMWindow() {
|
|
42
|
+
const win = createWindow();
|
|
43
|
+
return {
|
|
44
|
+
teardown: () => {
|
|
45
|
+
win.happyDOM.cancelAsync();
|
|
46
|
+
},
|
|
47
|
+
window: win
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createNothing() {
|
|
51
|
+
return {
|
|
52
|
+
teardown: () => {},
|
|
53
|
+
window: undefined
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function createVmContext(filename, features, additionalContext, overrideContext = i => i) {
|
|
57
|
+
const isHappyDOMEnabled = isFeatureEnabled(features, 'happyDOM', filename);
|
|
58
|
+
const {
|
|
59
|
+
teardown,
|
|
60
|
+
window
|
|
61
|
+
} = isHappyDOMEnabled ? createHappyDOMWindow() : createNothing();
|
|
62
|
+
const baseContext = createBaseContext(window, overrideContext({
|
|
63
|
+
__filename: filename,
|
|
64
|
+
...additionalContext
|
|
65
|
+
}, filename));
|
|
66
|
+
const context = vm.createContext(baseContext);
|
|
67
|
+
return {
|
|
68
|
+
context,
|
|
69
|
+
teardown
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=createVmContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVmContext.js","names":["vm","isFeatureEnabled","process","NOOP","createWindow","Window","GlobalWindow","require","HappyWindow","win","Buffer","Uint8Array","createBaseContext","additionalContext","baseContext","document","window","self","top","parent","global","clearImmediate","clearInterval","clearTimeout","setImmediate","requestAnimationFrame","setInterval","setTimeout","key","createHappyDOMWindow","teardown","happyDOM","cancelAsync","createNothing","undefined","createVmContext","filename","features","overrideContext","i","isHappyDOMEnabled","__filename","context","createContext"],"sources":["../../src/vm/createVmContext.ts"],"sourcesContent":["import * as vm from 'vm';\n\nimport type { Window } from 'happy-dom';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\nimport { isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport * as process from './process';\n\nconst NOOP = () => {};\n\nfunction createWindow(): Window {\n const { Window, GlobalWindow } = require('happy-dom');\n const HappyWindow = GlobalWindow || Window;\n const win = new HappyWindow();\n\n // TODO: browser doesn't expose Buffer, but a lot of dependencies use it\n win.Buffer = Buffer;\n win.Uint8Array = Uint8Array;\n\n return win;\n}\n\nfunction createBaseContext(\n win: Window | undefined,\n additionalContext: Partial<vm.Context>\n): Partial<vm.Context> {\n const baseContext: vm.Context = win ?? {};\n\n baseContext.document = win?.document;\n baseContext.window = win;\n baseContext.self = win;\n baseContext.top = win;\n baseContext.parent = win;\n baseContext.global = win;\n\n baseContext.process = process;\n\n baseContext.clearImmediate = NOOP;\n baseContext.clearInterval = NOOP;\n baseContext.clearTimeout = NOOP;\n baseContext.setImmediate = NOOP;\n baseContext.requestAnimationFrame = NOOP;\n baseContext.setInterval = NOOP;\n baseContext.setTimeout = NOOP;\n\n // eslint-disable-next-line guard-for-in,no-restricted-syntax\n for (const key in additionalContext) {\n baseContext[key] = additionalContext[key];\n }\n\n return baseContext;\n}\n\nfunction createHappyDOMWindow() {\n const win = createWindow();\n\n return {\n teardown: () => {\n win.happyDOM.cancelAsync();\n },\n window: win,\n };\n}\n\nfunction createNothing() {\n return {\n teardown: () => {},\n window: undefined,\n };\n}\n\nexport function createVmContext(\n filename: string,\n features: FeatureFlags<'happyDOM'>,\n additionalContext: Partial<vm.Context>,\n overrideContext: StrictOptions['overrideContext'] = (i) => i\n) {\n const isHappyDOMEnabled = isFeatureEnabled(features, 'happyDOM', filename);\n\n const { teardown, window } = isHappyDOMEnabled\n ? createHappyDOMWindow()\n : createNothing();\n const baseContext = createBaseContext(\n window,\n overrideContext(\n {\n __filename: filename,\n ...additionalContext,\n },\n filename\n )\n );\n\n const context = vm.createContext(baseContext);\n\n return {\n context,\n teardown,\n };\n}\n"],"mappings":"AAAA,OAAO,KAAKA,EAAE,MAAM,IAAI;AAKxB,SAASC,gBAAgB,QAAQ,mBAAmB;AAEpD,OAAO,KAAKC,OAAO,MAAM,WAAW;AAEpC,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAErB,SAASC,YAAYA,CAAA,EAAW;EAC9B,MAAM;IAAEC,MAAM;IAAEC;EAAa,CAAC,GAAGC,OAAO,CAAC,WAAW,CAAC;EACrD,MAAMC,WAAW,GAAGF,YAAY,I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AACH;AAEA,SAASwB,aAAaA,CAAA,EAAG;EACvB,OAAO;IACLH,QAAQ,EAAEA,CAAA,KAAM,CAAC,CAAC;IAClBd,MAAM,EAAEkB;EACV,CAAC;AACH;AAEA,OAAO,SAASC,eAAeA,CAC7BC,QAAgB,EAChBC,QAAkC,EAClCxB,iBAAsC,EACtCyB,eAAiD,GAAIC,CAAC,IAAKA,CAAC,EAC5D;EACA,MAAMC,iBAAiB,GAAGvC,gBAAgB,CAACoC,QAAQ,EAAE,UAAU,EAAED,QAAQ,CAAC;EAE1E,MAAM;IAAEN,QAAQ;IAAEd;EAAO,CAAC,GAAGwB,iBAAiB,GAC1CX,oBAAoB,CAAC,CAAC,GACtBI,aAAa,CAAC,CAAC;EACnB,MAAMnB,WAAW,GAAGF,iBAAiB,CACnCI,MAAM,EACNsB,eAAe,CACb;IACEG,UAAU,EAAEL,QAAQ;IACpB,GAAGvB;EACL,CAAC,EACDuB,QACF,CACF,CAAC;EAED,MAAMM,OAAO,GAAG1C,EAAE,CAAC2C,aAAa,CAAC7B,WAAW,CAAC;EAE7C,OAAO;IACL4B,OAAO;IACPZ;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* It contains API for mocked process variable available in node environment used to evaluate scripts with node's `vm` in ./module.ts
|
|
3
|
+
*/
|
|
4
|
+
export const nextTick = fn => setTimeout(fn, 0);
|
|
5
|
+
export const platform = 'browser';
|
|
6
|
+
export const arch = 'browser';
|
|
7
|
+
export const execPath = 'browser';
|
|
8
|
+
export const title = 'browser';
|
|
9
|
+
export const pid = 1;
|
|
10
|
+
export const browser = true;
|
|
11
|
+
export const argv = [];
|
|
12
|
+
export const binding = function binding() {
|
|
13
|
+
throw new Error('No such module. (Possibly not yet loaded)');
|
|
14
|
+
};
|
|
15
|
+
export const cwd = () => '/';
|
|
16
|
+
const noop = () => {};
|
|
17
|
+
export const exit = noop;
|
|
18
|
+
export const kill = noop;
|
|
19
|
+
export const chdir = noop;
|
|
20
|
+
export const umask = noop;
|
|
21
|
+
export const dlopen = noop;
|
|
22
|
+
export const uptime = noop;
|
|
23
|
+
export const memoryUsage = noop;
|
|
24
|
+
export const uvCounters = noop;
|
|
25
|
+
export const features = {};
|
|
26
|
+
export const {
|
|
27
|
+
env
|
|
28
|
+
} = process;
|
|
29
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","names":["nextTick","fn","setTimeout","platform","arch","execPath","title","pid","browser","argv","binding","Error","cwd","noop","exit","kill","chdir","umask","dlopen","uptime","memoryUsage","uvCounters","features","env","process"],"sources":["../../src/vm/process.ts"],"sourcesContent":["/**\n * It contains API for mocked process variable available in node environment used to evaluate scripts with node's `vm` in ./module.ts\n */\nexport const nextTick = (fn: (...args: unknown[]) => void) => setTimeout(fn, 0);\n\nexport const platform = 'browser';\nexport const arch = 'browser';\nexport const execPath = 'browser';\nexport const title = 'browser';\nexport const pid = 1;\nexport const browser = true;\nexport const argv = [];\n\nexport const binding = function binding() {\n throw new Error('No such module. (Possibly not yet loaded)');\n};\n\nexport const cwd = () => '/';\n\nconst noop = () => {};\nexport const exit = noop;\nexport const kill = noop;\nexport const chdir = noop;\nexport const umask = noop;\nexport const dlopen = noop;\nexport const uptime = noop;\nexport const memoryUsage = noop;\nexport const uvCounters = noop;\nexport const features = {};\n\nexport const { env } = process;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,GAAIC,EAAgC,IAAKC,UAAU,CAACD,EAAE,EAAE,CAAC,CAAC;AAE/E,OAAO,MAAME,QAAQ,GAAG,SAAS;AACjC,OAAO,MAAMC,IAAI,GAAG,SAAS;AAC7B,OAAO,MAAMC,QAAQ,GAAG,SAAS;AACjC,OAAO,MAAMC,KAAK,GAAG,SAAS;AAC9B,OAAO,MAAMC,GAAG,GAAG,CAAC;AACpB,OAAO,MAAMC,OAAO,GAAG,IAAI;AAC3B,OAAO,MAAMC,IAAI,GAAG,EAAE;AAEtB,OAAO,MAAMC,OAAO,GAAG,SAASA,OAAOA,CAAA,EAAG;EACxC,MAAM,IAAIC,KAAK,CAAC,2CAA2C,CAAC;AAC9D,CAAC;AAED,OAAO,MAAMC,GAAG,GAAGA,CAAA,KAAM,GAAG;AAE5B,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB,OAAO,MAAMC,IAAI,GAAGD,IAAI;AACxB,OAAO,MAAME,IAAI,GAAGF,IAAI;AACxB,OAAO,MAAMG,KAAK,GAAGH,IAAI;AACzB,OAAO,MAAMI,KAAK,GAAGJ,IAAI;AACzB,OAAO,MAAMK,MAAM,GAAGL,IAAI;AAC1B,OAAO,MAAMM,MAAM,GAAGN,IAAI;AAC1B,OAAO,MAAMO,WAAW,GAAGP,IAAI;AAC/B,OAAO,MAAMQ,UAAU,GAAGR,IAAI;AAC9B,OAAO,MAAMS,QAAQ,GAAG,CAAC,CAAC;AAE1B,OAAO,MAAM;EAAEC;AAAI,CAAC,GAAGC,OAAO"}
|
package/lib/babel.js
ADDED
package/lib/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/lib/cache.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TransformCacheCollection = void 0;
|
|
7
|
+
var _crypto = require("crypto");
|
|
8
|
+
var _shared = require("@wyw-in-js/shared");
|
|
9
|
+
var _getFileIdx = require("./utils/getFileIdx");
|
|
10
|
+
function hashContent(content) {
|
|
11
|
+
return (0, _crypto.createHash)('sha256').update(content).digest('hex');
|
|
12
|
+
}
|
|
13
|
+
const cacheLogger = _shared.logger.extend('cache');
|
|
14
|
+
const cacheNames = ['entrypoints', 'exports'];
|
|
15
|
+
const loggers = cacheNames.reduce((acc, key) => ({
|
|
16
|
+
...acc,
|
|
17
|
+
[key]: cacheLogger.extend(key)
|
|
18
|
+
}), {});
|
|
19
|
+
class TransformCacheCollection {
|
|
20
|
+
contentHashes = new Map();
|
|
21
|
+
constructor(caches = {}) {
|
|
22
|
+
this.entrypoints = caches.entrypoints || new Map();
|
|
23
|
+
this.exports = caches.exports || new Map();
|
|
24
|
+
}
|
|
25
|
+
add(cacheName, key, value) {
|
|
26
|
+
const cache = this[cacheName];
|
|
27
|
+
loggers[cacheName]('%s:add %s %f', (0, _getFileIdx.getFileIdx)(key), key, () => {
|
|
28
|
+
if (!cache.has(key)) {
|
|
29
|
+
return 'added';
|
|
30
|
+
}
|
|
31
|
+
return cache.get(key) === value ? 'unchanged' : 'updated';
|
|
32
|
+
});
|
|
33
|
+
cache.set(key, value);
|
|
34
|
+
}
|
|
35
|
+
clear(cacheName) {
|
|
36
|
+
if (cacheName === 'all') {
|
|
37
|
+
cacheNames.forEach(name => {
|
|
38
|
+
this.clear(name);
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
loggers[cacheName]('clear');
|
|
43
|
+
const cache = this[cacheName];
|
|
44
|
+
cache.clear();
|
|
45
|
+
}
|
|
46
|
+
delete(cacheName, key) {
|
|
47
|
+
this.invalidate(cacheName, key);
|
|
48
|
+
}
|
|
49
|
+
get(cacheName, key) {
|
|
50
|
+
const cache = this[cacheName];
|
|
51
|
+
const res = cache.get(key);
|
|
52
|
+
loggers[cacheName]('get', key, res === undefined ? 'miss' : 'hit');
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
has(cacheName, key) {
|
|
56
|
+
const cache = this[cacheName];
|
|
57
|
+
const res = cache.has(key);
|
|
58
|
+
loggers[cacheName]('has', key, res);
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
invalidate(cacheName, key) {
|
|
62
|
+
const cache = this[cacheName];
|
|
63
|
+
if (!cache.has(key)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
loggers[cacheName]('invalidate', key);
|
|
67
|
+
cache.delete(key);
|
|
68
|
+
}
|
|
69
|
+
invalidateForFile(filename) {
|
|
70
|
+
cacheNames.forEach(cacheName => {
|
|
71
|
+
this.invalidate(cacheName, filename);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
invalidateIfChanged(filename, content) {
|
|
75
|
+
const hash = this.contentHashes.get(filename);
|
|
76
|
+
const newHash = hashContent(content);
|
|
77
|
+
if (hash !== newHash) {
|
|
78
|
+
cacheLogger('content has changed, invalidate all for %s', filename);
|
|
79
|
+
this.contentHashes.set(filename, newHash);
|
|
80
|
+
this.invalidateForFile(filename);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.TransformCacheCollection = TransformCacheCollection;
|
|
87
|
+
//# sourceMappingURL=cache.js.map
|
package/lib/cache.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","names":["_crypto","require","_shared","_getFileIdx","hashContent","content","createHash","update","digest","cacheLogger","logger","extend","cacheNames","loggers","reduce","acc","key","TransformCacheCollection","contentHashes","Map","constructor","caches","entrypoints","exports","add","cacheName","value","cache","getFileIdx","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,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAIA,IAAAE,WAAA,GAAAF,OAAA;AAEA,SAASG,WAAWA,CAACC,OAAe,EAAE;EACpC,OAAO,IAAAC,kBAAU,EAAC,QAAQ,CAAC,CAACC,MAAM,CAACF,OAAO,CAAC,CAACG,MAAM,CAAC,KAAK,CAAC;AAC3D;AASA,MAAMC,WAAW,GAAGC,cAAM,CAACC,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,GAAGP,WAAW,CAACE,MAAM,CAACK,GAAG;AAC/B,CAAC,CAAC,EACF,CAAC,CACH,CAAC;AAEM,MAAMC,wBAAwB,CAAC;EAK5BC,aAAa,GAAG,IAAIC,GAAG,CAAiB,CAAC;EAEjDC,WAAWA,CAACC,MAAwB,GAAG,CAAC,CAAC,EAAE;IACzC,IAAI,CAACC,WAAW,GAAGD,MAAM,CAACC,WAAW,IAAI,IAAIH,GAAG,CAAC,CAAC;IAClD,IAAI,CAACI,OAAO,GAAGF,MAAM,CAACE,OAAO,IAAI,IAAIJ,GAAG,CAAC,CAAC;EAC5C;EAEOK,GAAGA,CAGRC,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defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFileReporter = void 0;
|
|
7
|
+
var _fs = require("fs");
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _EventEmitter = require("../utils/EventEmitter");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
/* eslint-disable no-console */
|
|
12
|
+
|
|
13
|
+
const workingDir = process.cwd();
|
|
14
|
+
function replacer(_key, value) {
|
|
15
|
+
if (typeof value === 'string' && _path.default.isAbsolute(value)) {
|
|
16
|
+
return _path.default.relative(workingDir, value);
|
|
17
|
+
}
|
|
18
|
+
if (value instanceof Map) {
|
|
19
|
+
return Array.from(value.entries()).reduce((obj, [k, v]) => {
|
|
20
|
+
const key = replacer(k, k);
|
|
21
|
+
return {
|
|
22
|
+
...obj,
|
|
23
|
+
[key]: replacer(key, v)
|
|
24
|
+
};
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function printTimings(timings, startedAt, sourceRoot) {
|
|
30
|
+
if (timings.size === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
console.log(`\nTimings:`);
|
|
34
|
+
console.log(` Total: ${(performance.now() - startedAt).toFixed()}ms`);
|
|
35
|
+
Array.from(timings.entries()).forEach(([label, byLabel]) => {
|
|
36
|
+
console.log(`\n By ${label}:`);
|
|
37
|
+
const array = Array.from(byLabel.entries());
|
|
38
|
+
// array.sort(([, a], [, b]) => b - a);
|
|
39
|
+
array.sort(([a], [b]) => a.localeCompare(b)).forEach(([value, time]) => {
|
|
40
|
+
const name = value.startsWith(sourceRoot) ? _path.default.relative(sourceRoot, value) : value;
|
|
41
|
+
console.log(` ${name}: ${time}ms`);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const writeJSONl = (stream, data) => {
|
|
46
|
+
stream.write(`${JSON.stringify(data, replacer)}\n`);
|
|
47
|
+
};
|
|
48
|
+
const createFileReporter = (options = false) => {
|
|
49
|
+
if (!options || !options.dir) {
|
|
50
|
+
return {
|
|
51
|
+
emitter: _EventEmitter.EventEmitter.dummy,
|
|
52
|
+
onDone: () => {}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const reportFolder = (0, _fs.existsSync)(options.dir) ? options.dir : (0, _fs.mkdirSync)(options.dir, {
|
|
56
|
+
recursive: true
|
|
57
|
+
});
|
|
58
|
+
if (!reportFolder) {
|
|
59
|
+
throw new Error(`Could not create directory ${options.dir}`);
|
|
60
|
+
}
|
|
61
|
+
const actionStream = (0, _fs.createWriteStream)(_path.default.join(options.dir, 'actions.jsonl'));
|
|
62
|
+
const dependenciesStream = (0, _fs.createWriteStream)(_path.default.join(options.dir, 'dependencies.jsonl'));
|
|
63
|
+
const entrypointStream = (0, _fs.createWriteStream)(_path.default.join(options.dir, 'entrypoints.jsonl'));
|
|
64
|
+
const startedAt = performance.now();
|
|
65
|
+
const timings = new Map();
|
|
66
|
+
const addTiming = (label, key, value) => {
|
|
67
|
+
if (!timings.has(label)) {
|
|
68
|
+
timings.set(label, new Map());
|
|
69
|
+
}
|
|
70
|
+
const forLabel = timings.get(label);
|
|
71
|
+
forLabel.set(key, Math.round((forLabel.get(key) || 0) + value));
|
|
72
|
+
};
|
|
73
|
+
const processDependencyEvent = ({
|
|
74
|
+
file,
|
|
75
|
+
only,
|
|
76
|
+
imports,
|
|
77
|
+
fileIdx
|
|
78
|
+
}) => {
|
|
79
|
+
writeJSONl(dependenciesStream, {
|
|
80
|
+
file,
|
|
81
|
+
only,
|
|
82
|
+
imports,
|
|
83
|
+
fileIdx
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const processSingleEvent = meta => {
|
|
87
|
+
if (meta.type === 'dependency') {
|
|
88
|
+
processDependencyEvent(meta);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const startTimes = new Map();
|
|
92
|
+
const onEvent = (meta, type) => {
|
|
93
|
+
if (type === 'single') {
|
|
94
|
+
processSingleEvent(meta);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (type === 'start') {
|
|
98
|
+
Object.entries(meta).forEach(([label, value]) => {
|
|
99
|
+
startTimes.set(`${label}\0${value}`, performance.now());
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
Object.entries(meta).forEach(([label, value]) => {
|
|
103
|
+
const startTime = startTimes.get(`${label}\0${value}`);
|
|
104
|
+
if (startTime) {
|
|
105
|
+
addTiming(label, String(value), performance.now() - startTime);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
let actionId = 0;
|
|
111
|
+
const onAction = (...args) => {
|
|
112
|
+
if ((0, _EventEmitter.isOnActionStartArgs)(args)) {
|
|
113
|
+
const [, timestamp, type, idx, entrypointRef] = args;
|
|
114
|
+
writeJSONl(actionStream, {
|
|
115
|
+
actionId,
|
|
116
|
+
entrypointRef,
|
|
117
|
+
idx,
|
|
118
|
+
startedAt: timestamp,
|
|
119
|
+
type
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// eslint-disable-next-line no-plusplus
|
|
123
|
+
return actionId++;
|
|
124
|
+
}
|
|
125
|
+
const [result, timestamp, id, isAsync, error] = args;
|
|
126
|
+
writeJSONl(actionStream, {
|
|
127
|
+
actionId: id,
|
|
128
|
+
error,
|
|
129
|
+
finishedAt: timestamp,
|
|
130
|
+
isAsync,
|
|
131
|
+
result: `${result}ed`
|
|
132
|
+
});
|
|
133
|
+
return id;
|
|
134
|
+
};
|
|
135
|
+
const onEntrypointEvent = (emitterId, timestamp, event) => {
|
|
136
|
+
entrypointStream.write(`${JSON.stringify([emitterId, timestamp, event])}\n`);
|
|
137
|
+
};
|
|
138
|
+
const emitter = new _EventEmitter.EventEmitter(onEvent, onAction, onEntrypointEvent);
|
|
139
|
+
return {
|
|
140
|
+
emitter,
|
|
141
|
+
onDone: sourceRoot => {
|
|
142
|
+
if (options.print) {
|
|
143
|
+
printTimings(timings, startedAt, sourceRoot);
|
|
144
|
+
console.log('\nMemory usage:', process.memoryUsage());
|
|
145
|
+
}
|
|
146
|
+
actionStream.end();
|
|
147
|
+
dependenciesStream.end();
|
|
148
|
+
timings.clear();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
exports.createFileReporter = createFileReporter;
|
|
153
|
+
//# sourceMappingURL=fileReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileReporter.js","names":["_fs","require","_path","_interopRequireDefault","_EventEmitter","obj","__esModule","default","workingDir","process","cwd","replacer","_key","value","path","isAbsolute","relative","Map","Array","from","entries","reduce","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","EventEmitter","dummy","onDone","reportFolder","existsSync","mkdirSync","recursive","Error","actionStream","createWriteStream","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","isOnActionStartArgs","timestamp","idx","entrypointRef","result","id","isAsync","error","finishedAt","onEntrypointEvent","emitterId","event","print","memoryUsage","end","clear","exports"],"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"],"mappings":";;;;;;AACA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AASA,IAAAG,aAAA,GAAAH,OAAA;AAA0E,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAX1E;;AAqCA,MAAMG,UAAU,GAAGC,OAAO,CAACC,GAAG,CAAC,CAAC;AAEhC,SAASC,QAAQA,CAACC,IAAY,EAAEC,KAAc,EAAW;EACvD,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIC,aAAI,CAACC,UAAU,CAACF,KAAK,CAAC,EAAE;IACvD,OAAOC,aAAI,CAACE,QAAQ,CAACR,UAAU,EAAEK,KAAK,CAAC;EACzC;EAEA,IAAIA,KAAK,YAAYI,GAAG,EAAE;IACxB,OAAOC,KAAK,CAACC,IAAI,CAACN,KAAK,CAACO,OAAO,CAAC,CAAC,CAAC,CAACC,MAAM,CAAC,CAAChB,GAAG,EAAE,CAACiB,CAAC,EAAEC,CAAC,CAAC,KAAK;MACzD,MAAMC,GAAG,GAAGb,QAAQ,CAACW,CAAC,EAAEA,CAAC,CAAW;MACpC,OAAO;QACL,GAAGjB,GAAG;QACN,CAACmB,GAAG,GAAGb,QAAQ,CAACa,GAAG,EAAED,CAAC;MACxB,CAAC;IACH,CAAC,EAAE,CAAC,CAAC,CAAC;EACR;EAEA,OAAOV,KAAK;AACd;AAEA,SAASY,YAAYA,CAACC,OAAgB,EAAEC,SAAiB,EAAEC,UAAkB,EAAE;EAC7E,IAAIF,OAAO,CAACG,IAAI,KAAK,CAAC,EAAE;IACtB;EACF;EAEAC,OAAO,CAACC,GAAG,CAAE,YAAW,CAAC;EACzBD,OAAO,CAACC,GAA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,GAAG,CAAC,CAAC;MAClBvC,kBAAkB,CAACuC,GAAG,CAAC,CAAC;MACxBhF,OAAO,CAACiF,KAAK,CAAC,CAAC;IACjB;EACF,CAAC;AACH,CAAC;AAACC,OAAA,CAAAxD,kBAAA,GAAAA,kBAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = evaluate;
|
|
7
|
+
var _module = require("../module");
|
|
8
|
+
/**
|
|
9
|
+
* This file is an entry point for module evaluation for getting lazy dependencies.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function evaluate(services, entrypoint) {
|
|
13
|
+
const m = new _module.Module(services, entrypoint);
|
|
14
|
+
m.evaluate();
|
|
15
|
+
return {
|
|
16
|
+
value: entrypoint.exports,
|
|
17
|
+
dependencies: m.dependencies
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_module","require","evaluate","services","entrypoint","m","Module","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":";;;;;;AAIA,IAAAA,OAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAWe,SAASC,QAAQA,CAC9BC,QAAkB,EAClBC,UAAsB,EACL;EACjB,MAAMC,CAAC,GAAG,IAAIC,cAAM,CAACH,QAAQ,EAAEC,UAAU,CAAC;EAE1CC,CAAC,CAACH,QAAQ,CAAC,CAAC;EAEZ,OAAO;IACLK,KAAK,EAAEH,UAAU,CAACI,OAAO;IACzBC,YAAY,EAAEJ,CAAC,CAACI;EAClB,CAAC;AACH"}
|