@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 @@
|
|
|
1
|
+
{"version":3,"file":"traversalCache.js","names":["_traverse","_interopRequireDefault","require","obj","__esModule","default","caches","WeakMap","getTraversalCache","path","name","programPath","find","p","isProgram","Error","node","type","has","set","Map","cache","get","exports","traverseCache","traverse","clearBabelTraversalCache","clear","invalidateTraversalCache","delete"],"sources":["../../src/utils/traversalCache.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport traverse from '@babel/traverse';\nimport type { Node } from '@babel/types';\n\nconst caches = new WeakMap<\n NodePath,\n Map<string, WeakMap<NodePath | Node, unknown>>\n>();\n\nexport const getTraversalCache = <\n TValue,\n TKey extends NodePath | Node = NodePath,\n>(\n path: NodePath,\n name: string\n) => {\n const programPath = path.find((p) => p.isProgram());\n if (!programPath) {\n throw new Error(`Could not find program for ${path.node.type}`);\n }\n\n if (!caches.has(programPath)) {\n caches.set(programPath, new Map());\n }\n\n const cache = caches.get(programPath)!;\n if (!cache.has(name)) {\n cache.set(name, new WeakMap());\n }\n\n return cache.get(name) as WeakMap<TKey, TValue>;\n};\n\nconst traverseCache = (traverse as unknown as { cache: unknown }).cache;\nexport const clearBabelTraversalCache = () => {\n (traverseCache as { clear: () => void }).clear();\n};\n\nexport const invalidateTraversalCache = (path: NodePath) => {\n const programPath = path.find((p) => p.isProgram());\n if (!programPath) {\n throw new Error(`Could not find program for ${path.node.type}`);\n }\n\n caches.delete(programPath);\n};\n"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAE,GA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M,IAAII,KAAK,CAAE,8BAA6BN,IAAI,CAACO,IAAI,CAACC,IAAK,EAAC,CAAC;EACjE;EAEAX,MAAM,CAACuB,MAAM,CAAClB,WAAW,CAAC;AAC5B,CAAC;AAACY,OAAA,CAAAK,wBAAA,GAAAA,wBAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unwrapSequence = unwrapSequence;
|
|
7
|
+
/**
|
|
8
|
+
* If expression is a sequence like `(a, b, c)`, returns `c`
|
|
9
|
+
* otherwise returns an original expression
|
|
10
|
+
* @param path
|
|
11
|
+
*/
|
|
12
|
+
function unwrapSequence(path) {
|
|
13
|
+
if (path.isSequenceExpression()) {
|
|
14
|
+
const [...expressions] = path.get('expressions');
|
|
15
|
+
const lastExpression = expressions.pop();
|
|
16
|
+
return lastExpression ? unwrapSequence(lastExpression) : undefined;
|
|
17
|
+
}
|
|
18
|
+
return path;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=unwrapSequence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrapSequence.js","names":["unwrapSequence","path","isSequenceExpression","expressions","get","lastExpression","pop","undefined"],"sources":["../../src/utils/unwrapSequence.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { Expression, V8IntrinsicIdentifier } from '@babel/types';\n\n/**\n * If expression is a sequence like `(a, b, c)`, returns `c`\n * otherwise returns an original expression\n * @param path\n */\nexport function unwrapSequence(\n path: NodePath<Expression | V8IntrinsicIdentifier>\n): NodePath<Expression | V8IntrinsicIdentifier> | undefined {\n if (path.isSequenceExpression()) {\n const [...expressions] = path.get('expressions');\n const lastExpression = expressions.pop();\n return lastExpression ? unwrapSequence(lastExpression) : undefined;\n }\n\n return path;\n}\n"],"mappings":";;;;;;AAGA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAcA,CAC5BC,IAAkD,EACQ;EAC1D,IAAIA,IAAI,CAACC,oBAAoB,CAAC,CAAC,EAAE;IAC/B,MAAM,CAAC,GAAGC,WAAW,CAAC,GAAGF,IAAI,CAACG,GAAG,CAAC,aAAa,CAAC;IAChD,MAAMC,cAAc,GAAGF,WAAW,CAACG,GAAG,CAAC,CAAC;IACxC,OAAOD,cAAc,GAAGL,cAAc,CAACK,cAAc,CAAC,GAAGE,SAAS;EACpE;EAEA,OAAON,IAAI;AACb"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.valueToLiteral = valueToLiteral;
|
|
7
|
+
var _getSource = require("./getSource");
|
|
8
|
+
var _isSerializable = require("./isSerializable");
|
|
9
|
+
function valueToLiteral(value, ex) {
|
|
10
|
+
if (value === undefined) {
|
|
11
|
+
return {
|
|
12
|
+
type: 'Identifier',
|
|
13
|
+
name: 'undefined'
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if ((0, _isSerializable.isSerializable)(value)) {
|
|
17
|
+
if (value === null) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'NullLiteral'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
return {
|
|
24
|
+
type: 'StringLiteral',
|
|
25
|
+
value
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (typeof value === 'number') {
|
|
29
|
+
return {
|
|
30
|
+
type: 'NumericLiteral',
|
|
31
|
+
value
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (typeof value === 'boolean') {
|
|
35
|
+
return {
|
|
36
|
+
type: 'BooleanLiteral',
|
|
37
|
+
value
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
return {
|
|
42
|
+
type: 'ArrayExpression',
|
|
43
|
+
elements: value.map(v => valueToLiteral(v, ex))
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
type: 'ObjectExpression',
|
|
48
|
+
properties: Object.entries(value).map(([key, v]) => ({
|
|
49
|
+
type: 'ObjectProperty',
|
|
50
|
+
key: key.match(/^[a-zA-Z]\w*$/) ? {
|
|
51
|
+
type: 'Identifier',
|
|
52
|
+
name: key
|
|
53
|
+
} : {
|
|
54
|
+
type: 'StringLiteral',
|
|
55
|
+
value: key
|
|
56
|
+
},
|
|
57
|
+
value: valueToLiteral(v, ex),
|
|
58
|
+
computed: false,
|
|
59
|
+
shorthand: false
|
|
60
|
+
}))
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
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(${(0, _getSource.getSource)(ex)})'.`);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=valueToLiteral.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"valueToLiteral.js","names":["_getSource","require","_isSerializable","valueToLiteral","value","ex","undefined","type","name","isSerializable","Array","isArray","elements","map","v","properties","Object","entries","key","match","computed","shorthand","buildCodeFrameError","getSource"],"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,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEO,SAASE,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,IAAI,IAAAC,8BAAc,EAACL,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,IAAIM,KAAK,CAACC,OAAO,CAACP,KAAK,CAAC,EAAE;MACxB,OAAO;QACLG,IAAI,EAAE,iBAAiB;QACvBK,QAAQ,EAAER,KAAK,CAACS,GAAG,CAAEC,CAAC,IAAKX,cAAc,CAACW,CAAC,EAAET,EAAE,CAAC;MAClD,CAAC;IACH;IAEA,OAAO;MACLE,IAAI,EAAE,kBAAkB;MACxBQ,UAAU,EAAEC,MAAM,CAACC,OAAO,CAACb,KAAK,CAAC,CAACS,GAAG,CAAC,CAAC,CAACK,GAAG,EAAEJ,CAAC,CAAC,MAAM;QACnDP,IAAI,EAAE,gBAAgB;QACtBW,GAAG,EAAEA,GAAG,CAACC,KAAK,CAAC,eAAe,CAAC,GAC3B;UACEZ,IAAI,EAAE,YAAY;UAClBC,IAAI,EAAEU;QACR,CAAC,GACD;UACEX,IAAI,EAAE,eAAe;UACrBH,KAAK,EAAEc;QACT,CAAC;QACLd,KAAK,EAAED,cAAc,CAACW,CAAC,EAAET,EAAE,CAAC;QAC5Be,QAAQ,EAAE,KAAK;QACfC,SAAS,EAAE;MACb,CAAC,CAAC;IACJ,CAAC;EACH;EAEA,MAAMhB,EAAE,CAACiB,mBAAmB,CACzB,gCAA+BlB,KAAM,8IAA6I,IAAAmB,oBAAS,EAC1LlB,EACF,CAAE,KACJ,CAAC;AACH"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.JSXElementsRemover = JSXElementsRemover;
|
|
7
|
+
var _core = require("@babel/core");
|
|
8
|
+
var _getScope = require("../getScope");
|
|
9
|
+
var _scopeHelpers = require("../scopeHelpers");
|
|
10
|
+
function getFunctionName(path) {
|
|
11
|
+
if (path.isClassMethod() && _core.types.isIdentifier(path.node.key)) {
|
|
12
|
+
return path.node.key.name;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
function JSXElementsRemover(path) {
|
|
17
|
+
// JSX can be safely replaced with null because it is unnecessary for styles
|
|
18
|
+
const nullLiteral = _core.types.nullLiteral();
|
|
19
|
+
|
|
20
|
+
// We can do even more
|
|
21
|
+
// If that JSX is a result of a function, we can replace the function body.
|
|
22
|
+
const functionScope = (0, _getScope.getScope)(path).getFunctionParent();
|
|
23
|
+
const scopePath = functionScope === null || functionScope === void 0 ? void 0 : functionScope.path;
|
|
24
|
+
if (scopePath !== null && scopePath !== void 0 && scopePath.isFunction()) {
|
|
25
|
+
const emptyBody = _core.types.blockStatement([_core.types.returnStatement(nullLiteral)]);
|
|
26
|
+
|
|
27
|
+
// Is it not just a function, but a method `render`?
|
|
28
|
+
if (getFunctionName(scopePath) === 'render') {
|
|
29
|
+
const decl = scopePath.findParent(p => p.isClassDeclaration());
|
|
30
|
+
|
|
31
|
+
// Replace the whole component
|
|
32
|
+
if (decl !== null && decl !== void 0 && decl.isClassDeclaration()) {
|
|
33
|
+
(0, _scopeHelpers.mutate)(decl, p => {
|
|
34
|
+
p.replaceWith(_core.types.functionDeclaration(decl.node.id, [], emptyBody));
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const body = scopePath.get('body');
|
|
40
|
+
if (Array.isArray(body)) {
|
|
41
|
+
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.");
|
|
42
|
+
}
|
|
43
|
+
const node = {
|
|
44
|
+
...scopePath.node,
|
|
45
|
+
body: emptyBody,
|
|
46
|
+
params: []
|
|
47
|
+
};
|
|
48
|
+
(0, _scopeHelpers.mutate)(scopePath, p => {
|
|
49
|
+
p.replaceWith(node);
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
(0, _scopeHelpers.mutate)(path, p => {
|
|
53
|
+
p.replaceWith(nullLiteral);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=JSXElementsRemover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSXElementsRemover.js","names":["_core","require","_getScope","_scopeHelpers","getFunctionName","path","isClassMethod","t","isIdentifier","node","key","name","JSXElementsRemover","nullLiteral","functionScope","getScope","getFunctionParent","scopePath","isFunction","emptyBody","blockStatement","returnStatement","decl","findParent","p","isClassDeclaration","mutate","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,I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AC,CAAC;QAEF;MACF;IACF;IAEA,MAAMW,IAAI,GAAGb,SAAS,CAACc,GAAG,CAAC,MAAM,CAAC;IAClC,IAAIC,KAAK,CAACC,OAAO,CAACH,IAAI,CAAC,EAAE;MACvB,MAAM,IAAII,KAAK,CACb,6JACF,CAAC;IACH;IAEA,MAAMzB,IAA2B,GAAG;MAClC,GAAGQ,SAAS,CAACR,IAAI;MACjBqB,IAAI,EAAEX,SAAS;MACfgB,MAAM,EAAE;IACV,CAAC;IAED,IAAAT,oBAAM,EAACT,SAAS,EAAGO,CAAC,IAAK;MACvBA,CAAC,CAACG,WAAW,CAAClB,IAAI,CAAC;IACrB,CAAC,CAAC;EACJ,CAAC,MAAM;IACL,IAAAiB,oBAAM,EAACrB,IAAI,EAAGmB,CAAC,IAAK;MAClBA,CAAC,CAACG,WAAW,CAACd,WAAW,CAAC;IAC5B,CAAC,CAAC;EACJ;AACF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createVmContext = createVmContext;
|
|
7
|
+
var vm = _interopRequireWildcard(require("vm"));
|
|
8
|
+
var _shared = require("@wyw-in-js/shared");
|
|
9
|
+
var process = _interopRequireWildcard(require("./process"));
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
+
const NOOP = () => {};
|
|
13
|
+
function createWindow() {
|
|
14
|
+
const {
|
|
15
|
+
Window,
|
|
16
|
+
GlobalWindow
|
|
17
|
+
} = require('happy-dom');
|
|
18
|
+
const HappyWindow = GlobalWindow || Window;
|
|
19
|
+
const win = new HappyWindow();
|
|
20
|
+
|
|
21
|
+
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
|
|
22
|
+
win.Buffer = Buffer;
|
|
23
|
+
win.Uint8Array = Uint8Array;
|
|
24
|
+
return win;
|
|
25
|
+
}
|
|
26
|
+
function createBaseContext(win, additionalContext) {
|
|
27
|
+
const baseContext = win !== null && win !== void 0 ? win : {};
|
|
28
|
+
baseContext.document = win === null || win === void 0 ? void 0 : win.document;
|
|
29
|
+
baseContext.window = win;
|
|
30
|
+
baseContext.self = win;
|
|
31
|
+
baseContext.top = win;
|
|
32
|
+
baseContext.parent = win;
|
|
33
|
+
baseContext.global = win;
|
|
34
|
+
baseContext.process = process;
|
|
35
|
+
baseContext.clearImmediate = NOOP;
|
|
36
|
+
baseContext.clearInterval = NOOP;
|
|
37
|
+
baseContext.clearTimeout = NOOP;
|
|
38
|
+
baseContext.setImmediate = NOOP;
|
|
39
|
+
baseContext.requestAnimationFrame = NOOP;
|
|
40
|
+
baseContext.setInterval = NOOP;
|
|
41
|
+
baseContext.setTimeout = NOOP;
|
|
42
|
+
|
|
43
|
+
// eslint-disable-next-line guard-for-in,no-restricted-syntax
|
|
44
|
+
for (const key in additionalContext) {
|
|
45
|
+
baseContext[key] = additionalContext[key];
|
|
46
|
+
}
|
|
47
|
+
return baseContext;
|
|
48
|
+
}
|
|
49
|
+
function createHappyDOMWindow() {
|
|
50
|
+
const win = createWindow();
|
|
51
|
+
return {
|
|
52
|
+
teardown: () => {
|
|
53
|
+
win.happyDOM.cancelAsync();
|
|
54
|
+
},
|
|
55
|
+
window: win
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function createNothing() {
|
|
59
|
+
return {
|
|
60
|
+
teardown: () => {},
|
|
61
|
+
window: undefined
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function createVmContext(filename, features, additionalContext, overrideContext = i => i) {
|
|
65
|
+
const isHappyDOMEnabled = (0, _shared.isFeatureEnabled)(features, 'happyDOM', filename);
|
|
66
|
+
const {
|
|
67
|
+
teardown,
|
|
68
|
+
window
|
|
69
|
+
} = isHappyDOMEnabled ? createHappyDOMWindow() : createNothing();
|
|
70
|
+
const baseContext = createBaseContext(window, overrideContext({
|
|
71
|
+
__filename: filename,
|
|
72
|
+
...additionalContext
|
|
73
|
+
}, filename));
|
|
74
|
+
const context = vm.createContext(baseContext);
|
|
75
|
+
return {
|
|
76
|
+
context,
|
|
77
|
+
teardown
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=createVmContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createVmContext.js","names":["vm","_interopRequireWildcard","require","_shared","process","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","NOOP","createWindow","Window","GlobalWindow","HappyWindow","win","Buffer","Uint8Array","createBaseContext","additionalContext","baseContext","document","window","self","top","parent","global","clearImmediate","clearInterval","clearTimeout","setImmediate","requestAnimationFrame","setInterval","setTimeout","createHappyDOMWindow","teardown","happyDOM","cancelAsync","createNothing","undefined","createVmContext","filename","features","overrideContext","i","isHappyDOMEnabled","isFeatureEnabled","__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 ...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AAE;IACnCC,WAAW,CAAChB,GAAG,CAAC,GAAGe,iBAAiB,CAACf,GAAG,CAAC;EAC3C;EAEA,OAAOgB,WAAW;AACpB;AAEA,SAASc,oBAAoBA,CAAA,EAAG;EAC9B,MAAMnB,GAAG,GAAGJ,YAAY,CAAC,CAAC;EAE1B,OAAO;IACLwB,QAAQ,EAAEA,CAAA,KAAM;MACdpB,GAAG,CAACqB,QAAQ,CAACC,WAAW,CAAC,CAAC;IAC5B,CAAC;IACDf,MAAM,EAAEP;EACV,CAAC;AACH;AAEA,SAASuB,aAAaA,CAAA,EAAG;EACvB,OAAO;IACLH,QAAQ,EAAEA,CAAA,KAAM,CAAC,CAAC;IAClBb,MAAM,EAAEiB;EACV,CAAC;AACH;AAEO,SAASC,eAAeA,CAC7BC,QAAgB,EAChBC,QAAkC,EAClCvB,iBAAsC,EACtCwB,eAAiD,GAAIC,CAAC,IAAKA,CAAC,EAC5D;EACA,MAAMC,iBAAiB,GAAG,IAAAC,wBAAgB,EAACJ,QAAQ,EAAE,UAAU,EAAED,QAAQ,CAAC;EAE1E,MAAM;IAAEN,QAAQ;IAAEb;EAAO,CAAC,GAAGuB,iBAAiB,GAC1CX,oBAAoB,CAAC,CAAC,GACtBI,aAAa,CAAC,CAAC;EACnB,MAAMlB,WAAW,GAAGF,iBAAiB,CACnCI,MAAM,EACNqB,eAAe,CACb;IACEI,UAAU,EAAEN,QAAQ;IACpB,GAAGtB;EACL,CAAC,EACDsB,QACF,CACF,CAAC;EAED,MAAMO,OAAO,GAAGjE,EAAE,CAACkE,aAAa,CAAC7B,WAAW,CAAC;EAE7C,OAAO;IACL4B,OAAO;IACPb;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.uvCounters = exports.uptime = exports.umask = exports.title = exports.platform = exports.pid = exports.nextTick = exports.memoryUsage = exports.kill = exports.features = exports.exit = exports.execPath = exports.env = exports.dlopen = exports.cwd = exports.chdir = exports.browser = exports.binding = exports.argv = exports.arch = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* It contains API for mocked process variable available in node environment used to evaluate scripts with node's `vm` in ./module.ts
|
|
9
|
+
*/
|
|
10
|
+
const nextTick = fn => setTimeout(fn, 0);
|
|
11
|
+
exports.nextTick = nextTick;
|
|
12
|
+
const platform = exports.platform = 'browser';
|
|
13
|
+
const arch = exports.arch = 'browser';
|
|
14
|
+
const execPath = exports.execPath = 'browser';
|
|
15
|
+
const title = exports.title = 'browser';
|
|
16
|
+
const pid = exports.pid = 1;
|
|
17
|
+
const browser = exports.browser = true;
|
|
18
|
+
const argv = exports.argv = [];
|
|
19
|
+
const binding = exports.binding = function binding() {
|
|
20
|
+
throw new Error('No such module. (Possibly not yet loaded)');
|
|
21
|
+
};
|
|
22
|
+
const cwd = () => '/';
|
|
23
|
+
exports.cwd = cwd;
|
|
24
|
+
const noop = () => {};
|
|
25
|
+
const exit = exports.exit = noop;
|
|
26
|
+
const kill = exports.kill = noop;
|
|
27
|
+
const chdir = exports.chdir = noop;
|
|
28
|
+
const umask = exports.umask = noop;
|
|
29
|
+
const dlopen = exports.dlopen = noop;
|
|
30
|
+
const uptime = exports.uptime = noop;
|
|
31
|
+
const memoryUsage = exports.memoryUsage = noop;
|
|
32
|
+
const uvCounters = exports.uvCounters = noop;
|
|
33
|
+
const features = exports.features = {};
|
|
34
|
+
const {
|
|
35
|
+
env
|
|
36
|
+
} = process;
|
|
37
|
+
exports.env = env;
|
|
38
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","names":["nextTick","fn","setTimeout","exports","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;AACO,MAAMA,QAAQ,GAAIC,EAAgC,IAAKC,UAAU,CAACD,EAAE,EAAE,CAAC,CAAC;AAACE,OAAA,CAAAH,QAAA,GAAAA,QAAA;AAEzE,MAAMI,QAAQ,GAAAD,OAAA,CAAAC,QAAA,GAAG,SAAS;AAC1B,MAAMC,IAAI,GAAAF,OAAA,CAAAE,IAAA,GAAG,SAAS;AACtB,MAAMC,QAAQ,GAAAH,OAAA,CAAAG,QAAA,GAAG,SAAS;AAC1B,MAAMC,KAAK,GAAAJ,OAAA,CAAAI,KAAA,GAAG,SAAS;AACvB,MAAMC,GAAG,GAAAL,OAAA,CAAAK,GAAA,GAAG,CAAC;AACb,MAAMC,OAAO,GAAAN,OAAA,CAAAM,OAAA,GAAG,IAAI;AACpB,MAAMC,IAAI,GAAAP,OAAA,CAAAO,IAAA,GAAG,EAAE;AAEf,MAAMC,OAAO,GAAAR,OAAA,CAAAQ,OAAA,GAAG,SAASA,OAAOA,CAAA,EAAG;EACxC,MAAM,IAAIC,KAAK,CAAC,2CAA2C,CAAC;AAC9D,CAAC;AAEM,MAAMC,GAAG,GAAGA,CAAA,KAAM,GAAG;AAACV,OAAA,CAAAU,GAAA,GAAAA,GAAA;AAE7B,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AACd,MAAMC,IAAI,GAAAZ,OAAA,CAAAY,IAAA,GAAGD,IAAI;AACjB,MAAME,IAAI,GAAAb,OAAA,CAAAa,IAAA,GAAGF,IAAI;AACjB,MAAMG,KAAK,GAAAd,OAAA,CAAAc,KAAA,GAAGH,IAAI;AAClB,MAAMI,KAAK,GAAAf,OAAA,CAAAe,KAAA,GAAGJ,IAAI;AAClB,MAAMK,MAAM,GAAAhB,OAAA,CAAAgB,MAAA,GAAGL,IAAI;AACnB,MAAMM,MAAM,GAAAjB,OAAA,CAAAiB,MAAA,GAAGN,IAAI;AACnB,MAAMO,WAAW,GAAAlB,OAAA,CAAAkB,WAAA,GAAGP,IAAI;AACxB,MAAMQ,UAAU,GAAAnB,OAAA,CAAAmB,UAAA,GAAGR,IAAI;AACvB,MAAMS,QAAQ,GAAApB,OAAA,CAAAoB,QAAA,GAAG,CAAC,CAAC;AAEnB,MAAM;EAAEC;AAAI,CAAC,GAAGC,OAAO;AAACtB,OAAA,CAAAqB,GAAA,GAAAA,GAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wyw-in-js/transform",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@babel/core": "^7.23.0",
|
|
6
|
+
"@babel/generator": "^7.23.0",
|
|
7
|
+
"@babel/helper-module-imports": "^7.22.15",
|
|
8
|
+
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
|
|
9
|
+
"@babel/template": "^7.22.15",
|
|
10
|
+
"@babel/traverse": "^7.23.0",
|
|
11
|
+
"@babel/types": "^7.23.0",
|
|
12
|
+
"babel-merge": "^3.0.0",
|
|
13
|
+
"cosmiconfig": "^8.0.0",
|
|
14
|
+
"find-up": "^5.0.0",
|
|
15
|
+
"happy-dom": "^12.5.0",
|
|
16
|
+
"source-map": "^0.7.4",
|
|
17
|
+
"stylis": "^3.5.4",
|
|
18
|
+
"ts-invariant": "^0.10.3",
|
|
19
|
+
"@wyw-in-js/processor-utils": "0.1.0",
|
|
20
|
+
"@wyw-in-js/shared": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/plugin-syntax-typescript": "^7.22.5",
|
|
24
|
+
"@babel/types": "^7.23.0",
|
|
25
|
+
"@swc/core": "1.3.20",
|
|
26
|
+
"@types/babel__core": "^7.20.2",
|
|
27
|
+
"@types/babel__generator": "^7.6.5",
|
|
28
|
+
"@types/babel__helper-module-imports": "^7.18.1",
|
|
29
|
+
"@types/babel__template": "^7.4.2",
|
|
30
|
+
"@types/babel__traverse": "^7.20.2",
|
|
31
|
+
"@types/debug": "^4.1.9",
|
|
32
|
+
"@types/node": "^16.18.55",
|
|
33
|
+
"dedent": "^1.5.1",
|
|
34
|
+
"esbuild": "^0.15.16",
|
|
35
|
+
"strip-ansi": "^5.2.0",
|
|
36
|
+
"typescript": "^5.2.2",
|
|
37
|
+
"@wyw-in-js/babel-config": "0.1.0",
|
|
38
|
+
"@wyw-in-js/eslint-config": "0.1.0",
|
|
39
|
+
"@wyw-in-js/ts-config": "0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=16.0.0"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"esm/",
|
|
46
|
+
"lib/",
|
|
47
|
+
"types/"
|
|
48
|
+
],
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"main": "lib/index.js",
|
|
51
|
+
"module": "esm/index.js",
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"types": "types/index.d.ts",
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
58
|
+
"build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
59
|
+
"build:types": "tsc --project ./tsconfig.lib.json --baseUrl . --rootDir ./src",
|
|
60
|
+
"lint": "eslint --ext .js,.ts .",
|
|
61
|
+
"test": "jest --config ./jest.config.js --rootDir src"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/types/babel.d.ts
ADDED
package/types/babel.js
ADDED
package/types/cache.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Entrypoint } from './transform/Entrypoint';
|
|
2
|
+
import type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';
|
|
3
|
+
interface ICaches {
|
|
4
|
+
entrypoints: Map<string, Entrypoint | IEvaluatedEntrypoint>;
|
|
5
|
+
exports: Map<string, string[]>;
|
|
6
|
+
}
|
|
7
|
+
type MapValue<T> = T extends Map<string, infer V> ? V : never;
|
|
8
|
+
declare const cacheNames: readonly ["entrypoints", "exports"];
|
|
9
|
+
type CacheNames = (typeof cacheNames)[number];
|
|
10
|
+
export declare class TransformCacheCollection {
|
|
11
|
+
readonly entrypoints: Map<string, Entrypoint | IEvaluatedEntrypoint>;
|
|
12
|
+
readonly exports: Map<string, string[]>;
|
|
13
|
+
private contentHashes;
|
|
14
|
+
constructor(caches?: Partial<ICaches>);
|
|
15
|
+
add<TCache extends CacheNames, TValue extends MapValue<ICaches[TCache]>>(cacheName: TCache, key: string, value: TValue): void;
|
|
16
|
+
clear(cacheName: CacheNames | 'all'): void;
|
|
17
|
+
delete(cacheName: CacheNames, key: string): void;
|
|
18
|
+
get<TCache extends CacheNames, TValue extends MapValue<ICaches[TCache]>>(cacheName: TCache, key: string): TValue | undefined;
|
|
19
|
+
has(cacheName: CacheNames, key: string): boolean;
|
|
20
|
+
invalidate(cacheName: CacheNames, key: string): void;
|
|
21
|
+
invalidateForFile(filename: string): void;
|
|
22
|
+
invalidateIfChanged(filename: string, content: string): boolean;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
package/types/cache.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransformCacheCollection = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const shared_1 = require("@wyw-in-js/shared");
|
|
6
|
+
const getFileIdx_1 = require("./utils/getFileIdx");
|
|
7
|
+
function hashContent(content) {
|
|
8
|
+
return (0, crypto_1.createHash)('sha256').update(content).digest('hex');
|
|
9
|
+
}
|
|
10
|
+
const cacheLogger = shared_1.logger.extend('cache');
|
|
11
|
+
const cacheNames = ['entrypoints', 'exports'];
|
|
12
|
+
const loggers = cacheNames.reduce((acc, key) => ({
|
|
13
|
+
...acc,
|
|
14
|
+
[key]: cacheLogger.extend(key),
|
|
15
|
+
}), {});
|
|
16
|
+
class TransformCacheCollection {
|
|
17
|
+
entrypoints;
|
|
18
|
+
exports;
|
|
19
|
+
contentHashes = new Map();
|
|
20
|
+
constructor(caches = {}) {
|
|
21
|
+
this.entrypoints = caches.entrypoints || new Map();
|
|
22
|
+
this.exports = caches.exports || new Map();
|
|
23
|
+
}
|
|
24
|
+
add(cacheName, key, value) {
|
|
25
|
+
const cache = this[cacheName];
|
|
26
|
+
loggers[cacheName]('%s:add %s %f', (0, getFileIdx_1.getFileIdx)(key), key, () => {
|
|
27
|
+
if (!cache.has(key)) {
|
|
28
|
+
return 'added';
|
|
29
|
+
}
|
|
30
|
+
return cache.get(key) === value ? 'unchanged' : 'updated';
|
|
31
|
+
});
|
|
32
|
+
cache.set(key, value);
|
|
33
|
+
}
|
|
34
|
+
clear(cacheName) {
|
|
35
|
+
if (cacheName === 'all') {
|
|
36
|
+
cacheNames.forEach((name) => {
|
|
37
|
+
this.clear(name);
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
loggers[cacheName]('clear');
|
|
42
|
+
const cache = this[cacheName];
|
|
43
|
+
cache.clear();
|
|
44
|
+
}
|
|
45
|
+
delete(cacheName, key) {
|
|
46
|
+
this.invalidate(cacheName, key);
|
|
47
|
+
}
|
|
48
|
+
get(cacheName, key) {
|
|
49
|
+
const cache = this[cacheName];
|
|
50
|
+
const res = cache.get(key);
|
|
51
|
+
loggers[cacheName]('get', key, res === undefined ? 'miss' : 'hit');
|
|
52
|
+
return res;
|
|
53
|
+
}
|
|
54
|
+
has(cacheName, key) {
|
|
55
|
+
const cache = this[cacheName];
|
|
56
|
+
const res = cache.has(key);
|
|
57
|
+
loggers[cacheName]('has', key, res);
|
|
58
|
+
return res;
|
|
59
|
+
}
|
|
60
|
+
invalidate(cacheName, key) {
|
|
61
|
+
const cache = this[cacheName];
|
|
62
|
+
if (!cache.has(key)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
loggers[cacheName]('invalidate', key);
|
|
66
|
+
cache.delete(key);
|
|
67
|
+
}
|
|
68
|
+
invalidateForFile(filename) {
|
|
69
|
+
cacheNames.forEach((cacheName) => {
|
|
70
|
+
this.invalidate(cacheName, filename);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
invalidateIfChanged(filename, content) {
|
|
74
|
+
const hash = this.contentHashes.get(filename);
|
|
75
|
+
const newHash = hashContent(content);
|
|
76
|
+
if (hash !== newHash) {
|
|
77
|
+
cacheLogger('content has changed, invalidate all for %s', filename);
|
|
78
|
+
this.contentHashes.set(filename, newHash);
|
|
79
|
+
this.invalidateForFile(filename);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.TransformCacheCollection = TransformCacheCollection;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EventEmitter } from '../utils/EventEmitter';
|
|
2
|
+
export interface IFileReporterOptions {
|
|
3
|
+
dir?: string;
|
|
4
|
+
print?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface IProcessedEvent {
|
|
7
|
+
file: string;
|
|
8
|
+
fileIdx: string;
|
|
9
|
+
imports: {
|
|
10
|
+
from: string;
|
|
11
|
+
what: string[];
|
|
12
|
+
}[];
|
|
13
|
+
only: string[];
|
|
14
|
+
type: 'dependency';
|
|
15
|
+
}
|
|
16
|
+
export interface IQueueActionEvent {
|
|
17
|
+
action: string;
|
|
18
|
+
args?: string[];
|
|
19
|
+
datetime: Date;
|
|
20
|
+
file: string;
|
|
21
|
+
queueIdx: string;
|
|
22
|
+
type: 'queue-action';
|
|
23
|
+
}
|
|
24
|
+
export declare const createFileReporter: (options?: IFileReporterOptions | false) => {
|
|
25
|
+
emitter: EventEmitter;
|
|
26
|
+
onDone: (sourceRoot: string) => void;
|
|
27
|
+
};
|