@wyw-in-js/transform 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js +4 -1
- package/esm/index.js.map +1 -1
- package/esm/options/loadBabelOptions.js +1 -1
- package/esm/options/loadBabelOptions.js.map +1 -1
- package/esm/plugins/babel-transform.js +2 -2
- package/esm/plugins/babel-transform.js.map +1 -1
- package/esm/plugins/collector.js +4 -4
- package/esm/plugins/collector.js.map +1 -1
- package/esm/plugins/preeval.js +11 -11
- package/esm/plugins/preeval.js.map +1 -1
- package/esm/plugins/shaker.js +5 -5
- package/esm/plugins/shaker.js.map +1 -1
- package/esm/shaker.js +2 -2
- package/esm/shaker.js.map +1 -1
- package/esm/transform/Entrypoint.helpers.js +1 -2
- package/esm/transform/Entrypoint.helpers.js.map +1 -1
- package/esm/transform/Entrypoint.js +4 -4
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/generators/collect.js +3 -2
- package/esm/transform/generators/collect.js.map +1 -1
- package/esm/transform/generators/evalFile.js +6 -6
- package/esm/transform/generators/evalFile.js.map +1 -1
- package/esm/transform/generators/extract.js +18 -14
- package/esm/transform/generators/extract.js.map +1 -1
- package/esm/transform/generators/transform.js +2 -2
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/generators/workflow.js +3 -3
- package/esm/transform/generators/workflow.js.map +1 -1
- package/esm/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +5 -5
- package/esm/transform/helpers/loadWywOptions.js.map +1 -0
- package/esm/transform.js +11 -10
- package/esm/transform.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/ShakerMetadata.js +1 -1
- package/esm/utils/ShakerMetadata.js.map +1 -1
- package/esm/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +10 -10
- package/esm/utils/addIdentifierToWywPreval.js.map +1 -0
- package/esm/utils/collectExportsAndImports.js +141 -53
- package/esm/utils/collectExportsAndImports.js.map +1 -1
- package/esm/utils/collectTemplateDependencies.js +2 -2
- package/esm/utils/collectTemplateDependencies.js.map +1 -1
- package/esm/utils/getTagProcessor.js +1 -1
- package/esm/utils/getTagProcessor.js.map +1 -1
- package/esm/utils/hasWywPreval.js +7 -0
- package/esm/utils/hasWywPreval.js.map +1 -0
- package/lib/index.js +28 -4
- package/lib/index.js.map +1 -1
- package/lib/options/loadBabelOptions.js +1 -1
- package/lib/options/loadBabelOptions.js.map +1 -1
- package/lib/plugins/babel-transform.js +2 -2
- package/lib/plugins/babel-transform.js.map +1 -1
- package/lib/plugins/collector.js +4 -4
- package/lib/plugins/collector.js.map +1 -1
- package/lib/plugins/preeval.js +11 -11
- package/lib/plugins/preeval.js.map +1 -1
- package/lib/plugins/shaker.js +5 -5
- package/lib/plugins/shaker.js.map +1 -1
- package/lib/shaker.js +2 -2
- package/lib/shaker.js.map +1 -1
- package/lib/transform/Entrypoint.helpers.js +1 -2
- package/lib/transform/Entrypoint.helpers.js.map +1 -1
- package/lib/transform/Entrypoint.js +4 -4
- package/lib/transform/Entrypoint.js.map +1 -1
- package/lib/transform/generators/collect.js +1 -1
- package/lib/transform/generators/collect.js.map +1 -1
- package/lib/transform/generators/evalFile.js +6 -6
- package/lib/transform/generators/evalFile.js.map +1 -1
- package/lib/transform/generators/extract.js +18 -14
- package/lib/transform/generators/extract.js.map +1 -1
- package/lib/transform/generators/transform.js +2 -2
- package/lib/transform/generators/transform.js.map +1 -1
- package/lib/transform/generators/workflow.js +3 -3
- package/lib/transform/generators/workflow.js.map +1 -1
- package/lib/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +6 -6
- package/lib/transform/helpers/loadWywOptions.js.map +1 -0
- package/lib/transform/helpers/withDefaultServices.js +2 -2
- package/lib/transform/helpers/withDefaultServices.js.map +1 -1
- package/lib/transform.js +11 -10
- package/lib/transform.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/ShakerMetadata.js +1 -1
- package/lib/utils/ShakerMetadata.js.map +1 -1
- package/lib/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
- package/lib/utils/addIdentifierToWywPreval.js.map +1 -0
- package/lib/utils/collectExportsAndImports.js +141 -53
- package/lib/utils/collectExportsAndImports.js.map +1 -1
- package/lib/utils/collectTemplateDependencies.js +2 -2
- package/lib/utils/collectTemplateDependencies.js.map +1 -1
- package/lib/utils/getTagProcessor.js +2 -2
- package/lib/utils/getTagProcessor.js.map +1 -1
- package/lib/utils/hasWywPreval.js +13 -0
- package/lib/utils/hasWywPreval.js.map +1 -0
- package/lib/vm/createVmContext.js +2 -2
- package/lib/vm/createVmContext.js.map +1 -1
- package/package.json +24 -21
- package/types/index.d.ts +5 -2
- package/types/index.js +9 -3
- package/types/options/loadBabelOptions.js +1 -1
- package/types/plugins/babel-transform.js +2 -2
- package/types/plugins/collector.js +4 -4
- package/types/plugins/preeval.js +11 -11
- package/types/plugins/shaker.js +5 -5
- package/types/shaker.js +2 -2
- package/types/transform/Entrypoint.d.ts +1 -1
- package/types/transform/Entrypoint.helpers.js +3 -3
- package/types/transform/Entrypoint.js +4 -4
- package/types/transform/generators/collect.js +1 -1
- package/types/transform/generators/evalFile.js +7 -7
- package/types/transform/generators/extract.js +21 -12
- package/types/transform/generators/transform.js +2 -4
- package/types/transform/generators/workflow.js +3 -3
- package/types/transform/helpers/{loadLinariaOptions.d.ts → loadWywOptions.d.ts} +1 -1
- package/types/transform/helpers/{loadLinariaOptions.js → loadWywOptions.js} +19 -19
- package/types/transform.d.ts +7 -6
- package/types/transform.js +11 -10
- package/types/types.d.ts +1 -1
- package/types/utils/ShakerMetadata.d.ts +1 -1
- package/types/utils/ShakerMetadata.js +1 -1
- package/types/utils/addIdentifierToWywPreval.d.ts +4 -0
- package/types/utils/{addIdentifierToLinariaPreval.js → addIdentifierToWywPreval.js} +12 -12
- package/types/utils/collectExportsAndImports.js +157 -58
- package/types/utils/collectTemplateDependencies.d.ts +1 -1
- package/types/utils/collectTemplateDependencies.js +2 -2
- package/types/utils/getTagProcessor.js +2 -2
- package/types/utils/hasWywPreval.d.ts +4 -0
- package/types/utils/{hasLinariaPreval.js → hasWywPreval.js} +3 -3
- package/esm/transform/helpers/loadLinariaOptions.js.map +0 -1
- package/esm/utils/addIdentifierToLinariaPreval.js.map +0 -1
- package/esm/utils/findPackageJSON.js +0 -26
- package/esm/utils/findPackageJSON.js.map +0 -1
- package/esm/utils/hasLinariaPreval.js +0 -7
- package/esm/utils/hasLinariaPreval.js.map +0 -1
- package/lib/transform/helpers/loadLinariaOptions.js.map +0 -1
- package/lib/utils/addIdentifierToLinariaPreval.js.map +0 -1
- package/lib/utils/findPackageJSON.js +0 -35
- package/lib/utils/findPackageJSON.js.map +0 -1
- package/lib/utils/hasLinariaPreval.js +0 -13
- package/lib/utils/hasLinariaPreval.js.map +0 -1
- package/types/utils/addIdentifierToLinariaPreval.d.ts +0 -4
- package/types/utils/findPackageJSON.d.ts +0 -1
- package/types/utils/findPackageJSON.js +0 -56
- package/types/utils/hasLinariaPreval.d.ts +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.js","names":["_path","_interopRequireDefault","require","_sourceMap","_stylis","obj","__esModule","default","
|
|
1
|
+
{"version":3,"file":"extract.js","names":["_path","_interopRequireDefault","require","_sourceMap","_stylis","obj","__esModule","default","posixSep","path","posix","sep","transformUrl","url","outputFilename","sourceFilename","platformPath","relative","dirname","resolve","split","join","createStylisPreprocessor","options","stylisPreprocess","selector","text","serialize","compile","middleware","element","type","return","value","replace","match","p1","p2","p3","p4","filename","namespace","prefixer","stringify","extractCssFromAst","rules","originalCode","mappings","cssText","preprocessor","Object","keys","forEach","index","push","generated","line","column","original","start","name","source","atom","cssSourceMapText","length","generator","SourceMapGenerator","file","mapping","addMapping","setSourceContent","toString","extract","services","entrypoint","processors","data","loadedAndParsed","evaluator","Error","allRules","allReplacements","processor","artifacts","artifact","replacements","code"],"sources":["../../../src/transform/generators/extract.ts"],"sourcesContent":["import path from 'path';\n\nimport type { Mapping } from 'source-map';\nimport { SourceMapGenerator } from 'source-map';\nimport {\n compile,\n serialize,\n stringify,\n middleware,\n prefixer,\n namespace,\n} from 'stylis';\n\nimport type { Replacements, Rules } from '@wyw-in-js/shared';\n\nimport type { Options, PreprocessorFn } from '../../types';\nimport type { IExtractAction, SyncScenarioForAction } from '../types';\n\nconst posixSep = path.posix.sep;\n\nexport function transformUrl(\n url: string,\n outputFilename: string,\n sourceFilename: string,\n platformPath: typeof path = path\n) {\n // Replace asset path with new path relative to the output CSS\n const relative = platformPath.relative(\n platformPath.dirname(outputFilename),\n // Get the absolute path to the asset from the path relative to the JS file\n platformPath.resolve(platformPath.dirname(sourceFilename), url)\n );\n\n if (platformPath.sep === posixSep) {\n return relative;\n }\n\n return relative.split(platformPath.sep).join(posixSep);\n}\n\nfunction createStylisPreprocessor(options: Options) {\n function stylisPreprocess(selector: string, text: string): string {\n return serialize(\n compile(`${selector} {${text}}\\n`),\n middleware([\n (element: { return: string; type: string; value: string }) => {\n const { outputFilename } = options;\n if (element.type === 'decl' && outputFilename) {\n // When writing to a file, we need to adjust the relative paths inside url(..) expressions.\n // It'll allow css-loader to resolve an imported asset properly.\n // eslint-disable-next-line no-param-reassign\n element.return = element.value.replace(\n /\\b(url\\(([\"']?))(\\.[^)]+?)(\\2\\))/g,\n (match, p1, p2, p3, p4) =>\n p1 + transformUrl(p3, outputFilename, options.filename) + p4\n );\n }\n },\n namespace,\n prefixer,\n stringify,\n ])\n );\n }\n return stylisPreprocess;\n}\n\nfunction extractCssFromAst(\n rules: Rules,\n originalCode: string,\n options: Pick<Options, 'preprocessor' | 'filename' | 'outputFilename'>\n): { cssSourceMapText: string; cssText: string; rules: Rules } {\n const mappings: Mapping[] = [];\n\n let cssText = '';\n\n let preprocessor: PreprocessorFn;\n if (typeof options.preprocessor === 'function') {\n // eslint-disable-next-line prefer-destructuring\n preprocessor = options.preprocessor;\n } else {\n switch (options.preprocessor) {\n case 'none':\n preprocessor = (selector, text) => `${selector} {${text}}\\n`;\n break;\n case 'stylis':\n default:\n preprocessor = createStylisPreprocessor(options);\n }\n }\n\n Object.keys(rules).forEach((selector, index) => {\n mappings.push({\n generated: {\n line: index + 1,\n column: 0,\n },\n original: rules[selector].start!,\n name: selector,\n source: '',\n });\n\n if (rules[selector].atom) {\n // For atoms, we just directly insert cssText, to give the atomizer full control over the rules\n cssText += `${rules[selector].cssText}\\n`;\n } else {\n // Run each rule through stylis to support nesting\n cssText += `${preprocessor(selector, rules[selector].cssText)}\\n`;\n }\n });\n\n return {\n cssText,\n rules,\n\n get cssSourceMapText() {\n if (mappings?.length) {\n const generator = new SourceMapGenerator({\n file: options.filename.replace(/\\.js$/, '.css'),\n });\n\n mappings.forEach((mapping) =>\n generator.addMapping({ ...mapping, source: options.filename })\n );\n\n generator.setSourceContent(options.filename, originalCode);\n\n return generator.toString();\n }\n\n return '';\n },\n };\n}\n\n/**\n * Extract artifacts (e.g. CSS) from processors\n */\n// eslint-disable-next-line require-yield\nexport function* extract(\n this: IExtractAction\n): SyncScenarioForAction<IExtractAction> {\n const { options } = this.services;\n const { entrypoint } = this;\n const { processors } = this.data;\n const { loadedAndParsed } = entrypoint;\n if (loadedAndParsed.evaluator === 'ignored') {\n throw new Error('entrypoint was ignored');\n }\n\n let allRules: Rules = {};\n const allReplacements: Replacements = [];\n processors.forEach((processor) => {\n processor.artifacts.forEach((artifact) => {\n if (artifact[0] !== 'css') return;\n const [rules, replacements] = artifact[1] as [\n rules: Rules,\n sourceMapReplacements: Replacements,\n ];\n\n allRules = {\n ...allRules,\n ...rules,\n };\n\n allReplacements.push(...replacements);\n });\n });\n\n return {\n ...extractCssFromAst(allRules, loadedAndParsed.code, options),\n replacements: allReplacements,\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAOgB,S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B,MAAM,CAACvC,KAAK,EAAEwC,YAAY,CAAC,GAAGD,QAAQ,CAAC,CAAC,CAGvC;MAEDJ,QAAQ,GAAG;QACT,GAAGA,QAAQ;QACX,GAAGnC;MACL,CAAC;MAEDoC,eAAe,CAAC3B,IAAI,CAAC,GAAG+B,YAAY,CAAC;IACvC,CAAC,CAAC;EACJ,CAAC,CAAC;EAEF,OAAO;IACL,GAAGzC,iBAAiB,CAACoC,QAAQ,EAAEH,eAAe,CAACS,IAAI,EAAE/D,OAAO,CAAC;IAC7D8D,YAAY,EAAEJ;EAChB,CAAC;AACH"}
|
|
@@ -23,7 +23,7 @@ function runPreevalStage(babel, evalConfig, pluginOptions, code, originalAst, ev
|
|
|
23
23
|
}], [require.resolve('../../plugins/dynamic-import')], ...((_evalConfig$plugins2 = evalConfig.plugins) !== null && _evalConfig$plugins2 !== void 0 ? _evalConfig$plugins2 : []).filter(i => !hasKeyInList(i, pluginOptions.highPriorityPlugins))];
|
|
24
24
|
const transformConfig = (0, _buildOptions.buildOptions)({
|
|
25
25
|
...evalConfig,
|
|
26
|
-
envName: '
|
|
26
|
+
envName: 'wyw-in-js',
|
|
27
27
|
plugins
|
|
28
28
|
});
|
|
29
29
|
const result = babel.transformFromAstSync(originalAst, code, transformConfig);
|
|
@@ -58,7 +58,7 @@ const prepareCode = (services, item, originalAst) => {
|
|
|
58
58
|
} = options;
|
|
59
59
|
const preevalStageResult = eventEmitter.perf('transform:preeval', () => runPreevalStage(babel, evalConfig, pluginOptions, code, originalAst, eventEmitter));
|
|
60
60
|
const transformMetadata = (0, _TransformMetadata.getTransformMetadata)(preevalStageResult.metadata);
|
|
61
|
-
if (only.length === 1 && only[0] === '
|
|
61
|
+
if (only.length === 1 && only[0] === '__wywPreval' && !transformMetadata) {
|
|
62
62
|
log('[evaluator:end] no metadata');
|
|
63
63
|
return [preevalStageResult.code, null, null];
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":["_buildOptions","require","_TransformMetadata","_getPluginKey","EMPTY_FILE","hasKeyInList","plugin","list","pluginKey","getPluginKey","some","i","includes","runPreevalStage","babel","evalConfig","pluginOptions","code","originalAst","eventEmitter","_evalConfig$plugins$f","_evalConfig$plugins","_evalConfig$plugins2","_result$ast","preShakePlugins","plugins","filter","highPriorityPlugins","resolve","transformConfig","buildOptions","envName","result","transformFromAstSync","ast","program","Error","prepareCode","services","item","log","only","loadedAndParsed","evaluator","_loadedAndParsed$code","options","preevalStageResult","perf","transformMetadata","getTransformMetadata","metadata","length","name","evaluatorConfig","onlyExports","features","transformedCode","imports","exports","internalTransform","prepareFn","entrypoint","_loadedAndParsed$code2","preparedCode","extend","_loadedAndParsed$code3","size","resolvedImports","getNext","resolved","transform","call"],"sources":["../../../src/transform/generators/transform.ts"],"sourcesContent":["import type {\n BabelFileResult,\n PluginItem,\n TransformOptions,\n} from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type { EvaluatorConfig, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { Core } from '../../babel';\nimport { buildOptions } from '../../options/buildOptions';\nimport type { EventEmitter } from '../../utils/EventEmitter';\nimport type { WYWTransformMetadata } from '../../utils/TransformMetadata';\nimport { getTransformMetadata } from '../../utils/TransformMetadata';\nimport { getPluginKey } from '../../utils/getPluginKey';\nimport type { Entrypoint } from '../Entrypoint';\nimport type {\n ITransformAction,\n Services,\n SyncScenarioForAction,\n} from '../types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nconst hasKeyInList = (plugin: PluginItem, list: string[]): boolean => {\n const pluginKey = getPluginKey(plugin);\n return pluginKey ? list.some((i) => pluginKey.includes(i)) : false;\n};\n\nfunction runPreevalStage(\n babel: Core,\n evalConfig: TransformOptions,\n pluginOptions: StrictOptions,\n code: string,\n originalAst: File,\n eventEmitter: EventEmitter\n): BabelFileResult {\n const preShakePlugins =\n evalConfig.plugins?.filter((i) =>\n hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ) ?? [];\n\n const plugins = [\n ...preShakePlugins,\n [\n require.resolve('../../plugins/preeval'),\n { ...pluginOptions, eventEmitter },\n ],\n [require.resolve('../../plugins/dynamic-import')],\n ...(evalConfig.plugins ?? []).filter(\n (i) => !hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ),\n ];\n\n const transformConfig = buildOptions({\n ...evalConfig,\n envName: 'linaria',\n plugins,\n });\n\n const result = babel.transformFromAstSync(originalAst, code, transformConfig);\n\n if (!result || !result.ast?.program) {\n throw new Error('Babel transform failed');\n }\n\n return result;\n}\n\ntype PrepareCodeFn = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n) => [\n code: string,\n imports: Map<string, string[]> | null,\n metadata: WYWTransformMetadata | null,\n];\n\nexport const prepareCode = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n): ReturnType<PrepareCodeFn> => {\n const { log, only, loadedAndParsed } = item;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return [loadedAndParsed.code ?? '', null, null];\n }\n\n const { code, evalConfig, evaluator } = loadedAndParsed;\n const { options, babel, eventEmitter } = services;\n const { pluginOptions } = options;\n\n const preevalStageResult = eventEmitter.perf('transform:preeval', () =>\n runPreevalStage(\n babel,\n evalConfig,\n pluginOptions,\n code,\n originalAst,\n eventEmitter\n )\n );\n\n const transformMetadata = getTransformMetadata(preevalStageResult.metadata);\n\n if (\n only.length === 1 &&\n only[0] === '__linariaPreval' &&\n !transformMetadata\n ) {\n log('[evaluator:end] no metadata');\n return [preevalStageResult.code!, null, null];\n }\n\n log('[preeval] metadata %O', transformMetadata);\n log('[evaluator:start] using %s', evaluator.name);\n\n const evaluatorConfig: EvaluatorConfig = {\n onlyExports: only,\n highPriorityPlugins: pluginOptions.highPriorityPlugins,\n features: pluginOptions.features,\n };\n\n const [, transformedCode, imports] = eventEmitter.perf(\n 'transform:evaluator',\n () =>\n evaluator(\n evalConfig,\n preevalStageResult.ast!,\n preevalStageResult.code!,\n evaluatorConfig,\n babel\n )\n );\n\n log('[evaluator:end]');\n\n return [transformedCode, imports, transformMetadata ?? null];\n};\n\nexport function* internalTransform(\n this: ITransformAction,\n prepareFn: PrepareCodeFn\n): SyncScenarioForAction<ITransformAction> {\n const { only, loadedAndParsed, log } = this.entrypoint;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n log('>> (%o)', only);\n\n const [preparedCode, imports, metadata] = prepareFn(\n this.services,\n this.entrypoint,\n loadedAndParsed.ast\n );\n\n if (loadedAndParsed.code === preparedCode) {\n log('<< (%o)\\n === no changes ===', only);\n } else {\n log('<< (%o)', only);\n log.extend('source')('%s', preparedCode || EMPTY_FILE);\n }\n\n if (preparedCode === '') {\n log('is skipped');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n if (imports !== null && imports.size > 0) {\n const resolvedImports = yield* this.getNext(\n 'resolveImports',\n this.entrypoint,\n {\n imports,\n }\n );\n\n if (resolvedImports.length !== 0) {\n yield [\n 'processImports',\n this.entrypoint,\n {\n resolved: resolvedImports,\n },\n ];\n }\n }\n\n return {\n code: preparedCode,\n metadata,\n };\n}\n\n/**\n * Prepares the code for evaluation. This includes removing dead and potentially unsafe code.\n * Emits resolveImports and processImports events.\n */\nexport function transform(this: ITransformAction) {\n return internalTransform.call(this, prepareCode);\n}\n"],"mappings":";;;;;;;;AAUA,IAAAA,aAAA,GAAAC,OAAA;AAGA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAQA,MAAMG,UAAU,GAAG,oBAAoB;AAEvC,MAAMC,YAAY,GAAGA,CAACC,MAAkB,EAAEC,IAAc,KAAc;EACpE,MAAMC,SAAS,GAAG,IAAAC,0BAAY,EAACH,MAAM,CAAC;EACtC,OAAOE,SAAS,GAAGD,IAAI,CAACG,IAAI,CAAEC,CAAC,IAAKH,SAAS,CAACI,QAAQ,CAACD,CAAC,CAAC,CAAC,GAAG,KAA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GAAG,CAACwB,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAED,YAAY,IAAI3D,UAAU,CAAC;EACxD;EAEA,IAAI2D,YAAY,KAAK,EAAE,EAAE;IAAA,IAAAE,sBAAA;IACvBzB,GAAG,CAAC,YAAY,CAAC;IACjB,OAAO;MACLvB,IAAI,GAAAgD,sBAAA,GAAEvB,eAAe,CAACzB,IAAI,cAAAgD,sBAAA,cAAAA,sBAAA,GAAI,EAAE;MAChCf,QAAQ,EAAE;IACZ,CAAC;EACH;EAEA,IAAIO,OAAO,KAAK,IAAI,IAAIA,OAAO,CAACS,IAAI,GAAG,CAAC,EAAE;IACxC,MAAMC,eAAe,GAAG,OAAO,IAAI,CAACC,OAAO,CACzC,gBAAgB,EAChB,IAAI,CAACP,UAAU,EACf;MACEJ;IACF,CACF,CAAC;IAED,IAAIU,eAAe,CAAChB,MAAM,KAAK,CAAC,EAAE;MAChC,MAAM,CACJ,gBAAgB,EAChB,IAAI,CAACU,UAAU,EACf;QACEQ,QAAQ,EAAEF;MACZ,CAAC,CACF;IACH;EACF;EAEA,OAAO;IACLlD,IAAI,EAAE8C,YAAY;IAClBb;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACO,SAASoB,SAASA,CAAA,EAAyB;EAChD,OAAOX,iBAAiB,CAACY,IAAI,CAAC,IAAI,EAAElC,WAAW,CAAC;AAClD"}
|
|
1
|
+
{"version":3,"file":"transform.js","names":["_buildOptions","require","_TransformMetadata","_getPluginKey","EMPTY_FILE","hasKeyInList","plugin","list","pluginKey","getPluginKey","some","i","includes","runPreevalStage","babel","evalConfig","pluginOptions","code","originalAst","eventEmitter","_evalConfig$plugins$f","_evalConfig$plugins","_evalConfig$plugins2","_result$ast","preShakePlugins","plugins","filter","highPriorityPlugins","resolve","transformConfig","buildOptions","envName","result","transformFromAstSync","ast","program","Error","prepareCode","services","item","log","only","loadedAndParsed","evaluator","_loadedAndParsed$code","options","preevalStageResult","perf","transformMetadata","getTransformMetadata","metadata","length","name","evaluatorConfig","onlyExports","features","transformedCode","imports","exports","internalTransform","prepareFn","entrypoint","_loadedAndParsed$code2","preparedCode","extend","_loadedAndParsed$code3","size","resolvedImports","getNext","resolved","transform","call"],"sources":["../../../src/transform/generators/transform.ts"],"sourcesContent":["import type {\n BabelFileResult,\n PluginItem,\n TransformOptions,\n} from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type { EvaluatorConfig, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { Core } from '../../babel';\nimport { buildOptions } from '../../options/buildOptions';\nimport type { EventEmitter } from '../../utils/EventEmitter';\nimport type { WYWTransformMetadata } from '../../utils/TransformMetadata';\nimport { getTransformMetadata } from '../../utils/TransformMetadata';\nimport { getPluginKey } from '../../utils/getPluginKey';\nimport type { Entrypoint } from '../Entrypoint';\nimport type {\n ITransformAction,\n Services,\n SyncScenarioForAction,\n} from '../types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nconst hasKeyInList = (plugin: PluginItem, list: string[]): boolean => {\n const pluginKey = getPluginKey(plugin);\n return pluginKey ? list.some((i) => pluginKey.includes(i)) : false;\n};\n\nfunction runPreevalStage(\n babel: Core,\n evalConfig: TransformOptions,\n pluginOptions: StrictOptions,\n code: string,\n originalAst: File,\n eventEmitter: EventEmitter\n): BabelFileResult {\n const preShakePlugins =\n evalConfig.plugins?.filter((i) =>\n hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ) ?? [];\n\n const plugins = [\n ...preShakePlugins,\n [\n require.resolve('../../plugins/preeval'),\n { ...pluginOptions, eventEmitter },\n ],\n [require.resolve('../../plugins/dynamic-import')],\n ...(evalConfig.plugins ?? []).filter(\n (i) => !hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ),\n ];\n\n const transformConfig = buildOptions({\n ...evalConfig,\n envName: 'wyw-in-js',\n plugins,\n });\n\n const result = babel.transformFromAstSync(originalAst, code, transformConfig);\n\n if (!result || !result.ast?.program) {\n throw new Error('Babel transform failed');\n }\n\n return result;\n}\n\ntype PrepareCodeFn = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n) => [\n code: string,\n imports: Map<string, string[]> | null,\n metadata: WYWTransformMetadata | null,\n];\n\nexport const prepareCode = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n): ReturnType<PrepareCodeFn> => {\n const { log, only, loadedAndParsed } = item;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return [loadedAndParsed.code ?? '', null, null];\n }\n\n const { code, evalConfig, evaluator } = loadedAndParsed;\n const { options, babel, eventEmitter } = services;\n const { pluginOptions } = options;\n\n const preevalStageResult = eventEmitter.perf('transform:preeval', () =>\n runPreevalStage(\n babel,\n evalConfig,\n pluginOptions,\n code,\n originalAst,\n eventEmitter\n )\n );\n\n const transformMetadata = getTransformMetadata(preevalStageResult.metadata);\n\n if (only.length === 1 && only[0] === '__wywPreval' && !transformMetadata) {\n log('[evaluator:end] no metadata');\n return [preevalStageResult.code!, null, null];\n }\n\n log('[preeval] metadata %O', transformMetadata);\n log('[evaluator:start] using %s', evaluator.name);\n\n const evaluatorConfig: EvaluatorConfig = {\n onlyExports: only,\n highPriorityPlugins: pluginOptions.highPriorityPlugins,\n features: pluginOptions.features,\n };\n\n const [, transformedCode, imports] = eventEmitter.perf(\n 'transform:evaluator',\n () =>\n evaluator(\n evalConfig,\n preevalStageResult.ast!,\n preevalStageResult.code!,\n evaluatorConfig,\n babel\n )\n );\n\n log('[evaluator:end]');\n\n return [transformedCode, imports, transformMetadata ?? null];\n};\n\nexport function* internalTransform(\n this: ITransformAction,\n prepareFn: PrepareCodeFn\n): SyncScenarioForAction<ITransformAction> {\n const { only, loadedAndParsed, log } = this.entrypoint;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n log('>> (%o)', only);\n\n const [preparedCode, imports, metadata] = prepareFn(\n this.services,\n this.entrypoint,\n loadedAndParsed.ast\n );\n\n if (loadedAndParsed.code === preparedCode) {\n log('<< (%o)\\n === no changes ===', only);\n } else {\n log('<< (%o)', only);\n log.extend('source')('%s', preparedCode || EMPTY_FILE);\n }\n\n if (preparedCode === '') {\n log('is skipped');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n if (imports !== null && imports.size > 0) {\n const resolvedImports = yield* this.getNext(\n 'resolveImports',\n this.entrypoint,\n {\n imports,\n }\n );\n\n if (resolvedImports.length !== 0) {\n yield [\n 'processImports',\n this.entrypoint,\n {\n resolved: resolvedImports,\n },\n ];\n }\n }\n\n return {\n code: preparedCode,\n metadata,\n };\n}\n\n/**\n * Prepares the code for evaluation. This includes removing dead and potentially unsafe code.\n * Emits resolveImports and processImports events.\n */\nexport function transform(this: ITransformAction) {\n return internalTransform.call(this, prepareCode);\n}\n"],"mappings":";;;;;;;;AAUA,IAAAA,aAAA,GAAAC,OAAA;AAGA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAQA,MAAMG,UAAU,GAAG,oBAAoB;AAEvC,MAAMC,YAAY,GAAGA,CAACC,MAAkB,EAAEC,IAAc,KAAc;EACpE,MAAMC,SAAS,GAAG,IAAAC,0BAAY,EAACH,MAAM,CAAC;EACtC,OAAOE,SAAS,GAAGD,IAAI,CAACG,IAAI,CAAEC,CAAC,IAAKH,SAAS,CAACI,QAAQ,CAACD,CAAC,CAAC,CAAC,GAAG,KAAK;AACpE,CAAC;AAED,SAASE,eAAeA,CACtBC,KAAW,EACXC,UAA4B,EAC5BC,aAA4B,EAC5BC,IAAY,EACZC,WAAiB,EACjBC,YAA0B,EACT;EAAA,IAAAC,qBAAA,EAAAC,mBAAA,EAAAC,oBAAA,EAAAC,WAAA;EACjB,MAAMC,eAAe,IAAAJ,qBAAA,IAAAC,mBAAA,GACnBN,UAAU,CAACU,OAAO,cAAAJ,mBAAA,uBAAlBA,mBAAA,CAAoBK,MAAM,CAAEf,CAAC,IAC3BN,YAAY,CAACM,CAAC,E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KAAK,IAAI,IAAIA,OAAO,CAACS,IAAI,GAAG,CAAC,EAAE;IACxC,MAAMC,eAAe,GAAG,OAAO,IAAI,CAACC,OAAO,CACzC,gBAAgB,EAChB,IAAI,CAACP,UAAU,EACf;MACEJ;IACF,CACF,CAAC;IAED,IAAIU,eAAe,CAAChB,MAAM,KAAK,CAAC,EAAE;MAChC,MAAM,CACJ,gBAAgB,EAChB,IAAI,CAACU,UAAU,EACf;QACEQ,QAAQ,EAAEF;MACZ,CAAC,CACF;IACH;EACF;EAEA,OAAO;IACLlD,IAAI,EAAE8C,YAAY;IAClBb;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACO,SAASoB,SAASA,CAAA,EAAyB;EAChD,OAAOX,iBAAiB,CAACY,IAAI,CAAC,IAAI,EAAElC,WAAW,CAAC;AAClD"}
|
|
@@ -39,10 +39,10 @@ function* workflow() {
|
|
|
39
39
|
const originalCode = (_entrypoint$loadedAnd2 = entrypoint.loadedAndParsed.code) !== null && _entrypoint$loadedAnd2 !== void 0 ? _entrypoint$loadedAnd2 : '';
|
|
40
40
|
|
|
41
41
|
// File is ignored or does not contain any tags. Return original code.
|
|
42
|
-
if (!entrypoint.
|
|
42
|
+
if (!entrypoint.hasWywMetadata()) {
|
|
43
43
|
if (entrypoint.generation === 1) {
|
|
44
|
-
// 1st generation here means that it's
|
|
45
|
-
// without
|
|
44
|
+
// 1st generation here means that it's __wywPreval entrypoint
|
|
45
|
+
// without __wywPreval, so we don't need it cached
|
|
46
46
|
cache.delete('entrypoints', entrypoint.name);
|
|
47
47
|
}
|
|
48
48
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.js","names":["_AbortError","require","workflow","_entrypoint$loadedAnd2","_collectStageResult$c","cache","options","services","entrypoint","ignored","_entrypoint$loadedAnd","code","loadedAndParsed","sourceMap","inputSourceMap","getNext","undefined","assertNotSuperseded","e","isAborted","supersededWith","log","originalCode","
|
|
1
|
+
{"version":3,"file":"workflow.js","names":["_AbortError","require","workflow","_entrypoint$loadedAnd2","_collectStageResult$c","cache","options","services","entrypoint","ignored","_entrypoint$loadedAnd","code","loadedAndParsed","sourceMap","inputSourceMap","getNext","undefined","assertNotSuperseded","e","isAborted","supersededWith","log","originalCode","hasWywMetadata","generation","delete","name","evalStageResult","valueCache","dependencies","collectStageResult","metadata","map","extractStageResult","processors","replacements"],"sources":["../../../src/transform/generators/workflow.ts"],"sourcesContent":["import { isAborted } from '../actions/AbortError';\nimport type { IWorkflowAction, SyncScenarioForAction } from '../types';\n\n/**\n * The entry point for file processing. Sequentially calls `processEntrypoint`,\n * `evalFile`, `collect`, and `extract`. Returns the result of transforming\n * the source code as well as all artifacts obtained from code execution.\n */\nexport function* workflow(\n this: IWorkflowAction\n): SyncScenarioForAction<IWorkflowAction> {\n const { cache, options } = this.services;\n const { entrypoint } = this;\n\n if (entrypoint.ignored) {\n return {\n code: entrypoint.loadedAndParsed.code ?? '',\n sourceMap: options.inputSourceMap,\n };\n }\n\n try {\n yield* this.getNext('processEntrypoint', entrypoint, undefined, null);\n entrypoint.assertNotSuperseded();\n } catch (e) {\n if (isAborted(e) && entrypoint.supersededWith) {\n entrypoint.log('workflow aborted, schedule the next attempt');\n return yield* this.getNext(\n 'workflow',\n entrypoint.supersededWith,\n undefined,\n null\n );\n }\n\n throw e;\n }\n\n const originalCode = entrypoint.loadedAndParsed.code ?? '';\n\n // File is ignored or does not contain any tags. Return original code.\n if (!entrypoint.hasWywMetadata()) {\n if (entrypoint.generation === 1) {\n // 1st generation here means that it's __wywPreval entrypoint\n // without __wywPreval, so we don't need it cached\n cache.delete('entrypoints', entrypoint.name);\n }\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n // *** 2nd stage ***\n\n const evalStageResult = yield* this.getNext(\n 'evalFile',\n entrypoint,\n undefined,\n null\n );\n\n if (evalStageResult === null) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const [valueCache, dependencies] = evalStageResult;\n\n // *** 3rd stage ***\n\n const collectStageResult = yield* this.getNext(\n 'collect',\n entrypoint,\n {\n valueCache,\n },\n null\n );\n\n if (!collectStageResult.metadata) {\n return {\n code: collectStageResult.code!,\n sourceMap: collectStageResult.map,\n };\n }\n\n // *** 4th stage\n\n const extractStageResult = yield* this.getNext(\n 'extract',\n entrypoint,\n {\n processors: collectStageResult.metadata.processors,\n },\n null\n );\n\n return {\n ...extractStageResult,\n code: collectStageResult.code ?? '',\n dependencies,\n replacements: [\n ...extractStageResult.replacements,\n ...collectStageResult.metadata.replacements,\n ],\n sourceMap: collectStageResult.map,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;AACA;AACO,UAAUC,QAAQA,CAAA,EAEiB;EAAA,IAAAC,sBAAA,EAAAC,qBAAA;EACxC,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAI,CAACC,QAAQ;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI;EAE3B,IAAIA,UAAU,CAACC,OAAO,EAAE;IAAA,IAAAC,qBAAA;IACtB,OAAO;MACLC,IAAI,GAAAD,qBAAA,GAAEF,UAAU,CAACI,eAAe,CAACD,IAAI,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,EAAE;MAC3CG,SAAS,EAAEP,OAAO,CAACQ;IACrB,CAAC;EACH;EAEA,IAAI;IACF,OAAO,IAAI,CAACC,OAAO,CAAC,mBAAmB,EAAEP,UAAU,EAAEQ,SAAS,EAAE,IAAI,CAAC;IACrER,UAAU,CAACS,mBAAmB,CAAC,CAAC;EAClC,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,IAAI,IAAAC,qBAAS,EAACD,CAAC,CAAC,IAAIV,UAAU,CAACY,cAAc,EAAE;MAC7CZ,UAAU,CAACa,GAAG,CAAC,6CAA6C,CAAC;MAC7D,OAAO,OAAO,IAAI,CAACN,OAAO,CACxB,UAAU,EACVP,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;IACL,GAAGD,kBAAkB;IACrBtB,IAAI,GAAAP,qBAAA,GAAE0B,kBAAkB,CAACnB,IAAI,cAAAP,qBAAA,cAAAA,qBAAA,GAAI,EAAE;IACnCyB,YAAY;IACZM,YAAY,EAAE,CACZ,GAAGF,kBAAkB,CAACE,YAAY,EAClC,GAAGL,kBAAkB,CAACC,QAAQ,CAACI,YAAY,CAC5C;IACDtB,SAAS,EAAEiB,kBAAkB,CAACE;EAChC,CAAC;AACH"}
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.loadWywOptions = loadWywOptions;
|
|
7
7
|
var _cosmiconfig = require("cosmiconfig");
|
|
8
8
|
var _shaker = _interopRequireDefault(require("../../shaker"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
const searchPlaces = [`.
|
|
11
|
-
const explorerSync = (0, _cosmiconfig.cosmiconfigSync)('
|
|
10
|
+
const searchPlaces = [`.wyw-in-jsrc`, `.wyw-in-jsrc.json`, `.wyw-in-jsrc.yaml`, `.wyw-in-jsrc.yml`, `.wyw-in-jsrc.js`, `.wyw-in-jsrc.cjs`, `.config/wyw-in-jsrc`, `.config/wyw-in-jsrc.json`, `.config/wyw-in-jsrc.yaml`, `.config/wyw-in-jsrc.yml`, `.config/wyw-in-jsrc.js`, `.config/wyw-in-jsrc.cjs`, `wyw-in-js.config.js`, `wyw-in-js.config.cjs`];
|
|
11
|
+
const explorerSync = (0, _cosmiconfig.cosmiconfigSync)('wyw-in-js', {
|
|
12
12
|
searchPlaces
|
|
13
13
|
});
|
|
14
14
|
const cache = new WeakMap();
|
|
15
15
|
const defaultOverrides = {};
|
|
16
16
|
const nodeModulesRegExp = /[\\/]node_modules[\\/]/;
|
|
17
|
-
function
|
|
17
|
+
function loadWywOptions(overrides = defaultOverrides) {
|
|
18
18
|
if (cache.has(overrides)) {
|
|
19
19
|
return cache.get(overrides);
|
|
20
20
|
}
|
|
@@ -53,7 +53,7 @@ function loadLinariaOptions(overrides = defaultOverrides) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// If a file contains `export` or `import` keywords, we assume it's an ES-module
|
|
56
|
-
return /(
|
|
56
|
+
return /(?:^|\*\/|;|})\s*(?:export|import)[\s{]/m.test(code);
|
|
57
57
|
},
|
|
58
58
|
action: _shaker.default
|
|
59
59
|
}],
|
|
@@ -70,4 +70,4 @@ function loadLinariaOptions(overrides = defaultOverrides) {
|
|
|
70
70
|
cache.set(overrides, options);
|
|
71
71
|
return options;
|
|
72
72
|
}
|
|
73
|
-
//# sourceMappingURL=
|
|
73
|
+
//# sourceMappingURL=loadWywOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadWywOptions.js","names":["_cosmiconfig","require","_shaker","_interopRequireDefault","obj","__esModule","default","searchPlaces","explorerSync","cosmiconfigSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","options","displayName","evaluate","extensions","action","shaker","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport shaker from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.wyw-in-jsrc`,\n `.wyw-in-jsrc.json`,\n `.wyw-in-jsrc.yaml`,\n `.wyw-in-jsrc.yml`,\n `.wyw-in-jsrc.js`,\n `.wyw-in-jsrc.cjs`,\n `.config/wyw-in-jsrc`,\n `.config/wyw-in-jsrc.json`,\n `.config/wyw-in-jsrc.yaml`,\n `.config/wyw-in-jsrc.yml`,\n `.config/wyw-in-jsrc.js`,\n `.config/wyw-in-jsrc.cjs`,\n `wyw-in-js.config.js`,\n `wyw-in-js.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('wyw-in-js', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;|})\\s*(?:export|import)[\\s{]/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,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;EAED,MAAMC,OAAsB,GAAG;IAC7BC,WAAW,EAAE,KAAK;IAClBC,QAAQ,EAAE,IAAI;IACdC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;IAC1EhB,KAAK,EAAEA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,CACd;MACEiB,MAAM,EAAEC;IACV,CAAC,EACD;MACE;MACAC,IAAI,EAAEpB,MAAM,aAANA,MAAM,cAANA,MAAM,GAAIN,iBAAiB;MACjCwB,MAAM,EAAE;IACV,CAAC,EACD;MACE;MACAE,IAAI,EAAEA,CAACC,QAAQ,EAAEC,IAAI,KAAK;QACxB,IAAI,CAAC5B,iBAAiB,CAAC0B,IAAI,CAACC,QAAQ,CAAC,EAAE;UACrC,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDJ,MAAM,EAAEC;IACV,CAAC,CACF;IACDjB,YAAY;IACZqB,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,IAAInB,MAAM,GAAGA,MAAM,CAACoB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGrB,IAAI;IACPsB,QAAQ,EAAE;MACR,GAAGjB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACoB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGtB,IAAI,CAACsB;IACV;EACF,CAAC;EAEDlC,KAAK,CAACmC,GAAG,CAAC9B,SAAS,EAAEkB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
|
|
@@ -9,8 +9,8 @@ var _cache = require("../../cache");
|
|
|
9
9
|
var _EventEmitter = require("../../utils/EventEmitter");
|
|
10
10
|
var _Entrypoint = require("../Entrypoint.helpers");
|
|
11
11
|
var _rootLog = require("../rootLog");
|
|
12
|
-
function _getRequireWildcardCache(
|
|
13
|
-
function _interopRequireWildcard(
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
const withDefaultServices = ({
|
|
15
15
|
babel = babelCore,
|
|
16
16
|
cache = new _cache.TransformCacheCollection(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withDefaultServices.js","names":["babelCore","_interopRequireWildcard","require","_cache","_EventEmitter","_Entrypoint","_rootLog","_getRequireWildcardCache","
|
|
1
|
+
{"version":3,"file":"withDefaultServices.js","names":["babelCore","_interopRequireWildcard","require","_cache","_EventEmitter","_Entrypoint","_rootLog","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","withDefaultServices","babel","cache","TransformCacheCollection","eventEmitter","EventEmitter","dummy","loadAndParseFn","loadAndParse","log","rootLog","options","exports"],"sources":["../../../src/transform/helpers/withDefaultServices.ts"],"sourcesContent":["import * as babelCore from '@babel/core';\n\nimport { TransformCacheCollection } from '../../cache';\nimport { EventEmitter } from '../../utils/EventEmitter';\nimport { loadAndParse } from '../Entrypoint.helpers';\nimport { rootLog } from '../rootLog';\nimport type { Services } from '../types';\n\ntype RequiredServices = 'options';\nexport type PartialServices = Partial<Omit<Services, RequiredServices>> &\n Pick<Services, RequiredServices>;\n\nexport const withDefaultServices = ({\n babel = babelCore,\n cache = new TransformCacheCollection(),\n eventEmitter = EventEmitter.dummy,\n loadAndParseFn = loadAndParse,\n log = rootLog,\n options,\n}: PartialServices): Services => ({\n babel,\n cache,\n eventEmitter,\n loadAndParseFn,\n log,\n options,\n});\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAAqC,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAO9B,MAAMY,mBAAmB,GAAGA,CAAC;EAClCC,KAAK,GAAG7B,SAAS;EACjB8B,KAAK,GAAG,IAAIC,+BAAwB,CAAC,CAAC;EACtCC,YAAY,GAAGC,0BAAY,CAACC,KAAK;EACjCC,cAAc,GAAGC,wBAAY;EAC7BC,GAAG,GAAGC,gBAAO;EACbC;AACe,CAAC,MAAgB;EAChCV,KAAK;EACLC,KAAK;EACLE,YAAY;EACZG,cAAc;EACdE,GAAG;EACHE;AACF,CAAC,CAAC;AAACC,OAAA,CAAAZ,mBAAA,GAAAA,mBAAA"}
|
package/lib/transform.js
CHANGED
|
@@ -6,27 +6,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.transform = transform;
|
|
7
7
|
exports.transformSync = transformSync;
|
|
8
8
|
var _shared = require("@wyw-in-js/shared");
|
|
9
|
+
var _loadWywOptions = require("./transform/helpers/loadWywOptions");
|
|
9
10
|
var _cache = require("./cache");
|
|
10
11
|
var _Entrypoint = require("./transform/Entrypoint");
|
|
11
12
|
var _actionRunner = require("./transform/actions/actionRunner");
|
|
12
13
|
var _generators = require("./transform/generators");
|
|
13
14
|
var _resolveImports = require("./transform/generators/resolveImports");
|
|
14
|
-
var _loadLinariaOptions = require("./transform/helpers/loadLinariaOptions");
|
|
15
15
|
var _withDefaultServices = require("./transform/helpers/withDefaultServices");
|
|
16
16
|
/**
|
|
17
|
-
* This file exposes transform
|
|
17
|
+
* This file exposes sync and async transform functions that:
|
|
18
18
|
* - parse the passed code to AST
|
|
19
|
-
* -
|
|
20
|
-
* -
|
|
21
|
-
* -
|
|
22
|
-
* -
|
|
19
|
+
* - builds a dependency graph for the file
|
|
20
|
+
* - shakes each dependency and removes unused code
|
|
21
|
+
* - runs generated code in a sandbox
|
|
22
|
+
* - collects artifacts
|
|
23
|
+
* - returns transformed code (without WYW template literals), generated CSS, source maps and babel metadata from transform step.
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
26
|
function transformSync(partialServices, originalCode, syncResolve, customHandlers = {}) {
|
|
26
27
|
const {
|
|
27
28
|
options
|
|
28
29
|
} = partialServices;
|
|
29
|
-
const pluginOptions = (0,
|
|
30
|
+
const pluginOptions = (0, _loadWywOptions.loadWywOptions)(options.pluginOptions);
|
|
30
31
|
const services = (0, _withDefaultServices.withDefaultServices)({
|
|
31
32
|
...partialServices,
|
|
32
33
|
options: {
|
|
@@ -38,7 +39,7 @@ function transformSync(partialServices, originalCode, syncResolve, customHandler
|
|
|
38
39
|
// If global cache is disabled, we need to create a new cache for each file
|
|
39
40
|
services.cache = new _cache.TransformCacheCollection();
|
|
40
41
|
}
|
|
41
|
-
const entrypoint = _Entrypoint.Entrypoint.createRoot(services, options.filename, ['
|
|
42
|
+
const entrypoint = _Entrypoint.Entrypoint.createRoot(services, options.filename, ['__wywPreval'], originalCode);
|
|
42
43
|
if (entrypoint.ignored) {
|
|
43
44
|
return {
|
|
44
45
|
code: originalCode,
|
|
@@ -73,7 +74,7 @@ async function transform(partialServices, originalCode, asyncResolve, customHand
|
|
|
73
74
|
const {
|
|
74
75
|
options
|
|
75
76
|
} = partialServices;
|
|
76
|
-
const pluginOptions = (0,
|
|
77
|
+
const pluginOptions = (0, _loadWywOptions.loadWywOptions)(options.pluginOptions);
|
|
77
78
|
const services = (0, _withDefaultServices.withDefaultServices)({
|
|
78
79
|
...partialServices,
|
|
79
80
|
options: {
|
|
@@ -94,7 +95,7 @@ async function transform(partialServices, originalCode, asyncResolve, customHand
|
|
|
94
95
|
* but the "only" option has changed, the file will be re-processed using
|
|
95
96
|
* the combined "only" option.
|
|
96
97
|
*/
|
|
97
|
-
const entrypoint = _Entrypoint.Entrypoint.createRoot(services, options.filename, ['
|
|
98
|
+
const entrypoint = _Entrypoint.Entrypoint.createRoot(services, options.filename, ['__wywPreval'], originalCode);
|
|
98
99
|
if (entrypoint.ignored) {
|
|
99
100
|
return {
|
|
100
101
|
code: originalCode,
|
package/lib/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":["_shared","require","_cache","_Entrypoint","_actionRunner","_generators","_resolveImports","
|
|
1
|
+
{"version":3,"file":"transform.js","names":["_shared","require","_loadWywOptions","_cache","_Entrypoint","_actionRunner","_generators","_resolveImports","_withDefaultServices","transformSync","partialServices","originalCode","syncResolve","customHandlers","options","pluginOptions","loadWywOptions","services","withDefaultServices","isFeatureEnabled","features","filename","cache","TransformCacheCollection","entrypoint","Entrypoint","createRoot","ignored","code","sourceMap","inputSourceMap","workflowAction","createAction","undefined","result","syncActionRunner","baseHandlers","resolveImports","syncResolveImports","call","log","name","err","console","error","transform","asyncResolve","asyncActionRunner","asyncResolveImports"],"sources":["../src/transform.ts"],"sourcesContent":["/**\n * This file exposes sync and async transform functions that:\n * - parse the passed code to AST\n * - builds a dependency graph for the file\n * - shakes each dependency and removes unused code\n * - runs generated code in a sandbox\n * - collects artifacts\n * - returns transformed code (without WYW template literals), generated CSS, source maps and babel metadata from transform step.\n */\n\nimport { isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport type { PartialOptions } from './transform/helpers/loadWywOptions';\nimport { loadWywOptions } from './transform/helpers/loadWywOptions';\nimport { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport {\n asyncActionRunner,\n syncActionRunner,\n} from './transform/actions/actionRunner';\nimport { baseHandlers } from './transform/generators';\nimport {\n asyncResolveImports,\n syncResolveImports,\n} from './transform/generators/resolveImports';\nimport { withDefaultServices } from './transform/helpers/withDefaultServices';\nimport type {\n Handlers,\n IResolveImportsAction,\n Services,\n} from './transform/types';\nimport type { Result } from './types';\n\ntype PartialServices = Partial<Omit<Services, 'options'>> & {\n options: Omit<Services['options'], 'pluginOptions'> & {\n pluginOptions?: PartialOptions;\n };\n};\n\ntype AllHandlers<TMode extends 'async' | 'sync'> = Handlers<TMode>;\n\nexport function transformSync(\n partialServices: PartialServices,\n originalCode: string,\n syncResolve: (what: string, importer: string, stack: string[]) => string,\n customHandlers: Partial<AllHandlers<'sync'>> = {}\n): Result {\n const { options } = partialServices;\n const pluginOptions = loadWywOptions(options.pluginOptions);\n const services = withDefaultServices({\n ...partialServices,\n options: {\n ...options,\n pluginOptions,\n },\n });\n\n if (\n !isFeatureEnabled(pluginOptions.features, 'globalCache', options.filename)\n ) {\n // If global cache is disabled, we need to create a new cache for each file\n services.cache = new TransformCacheCollection();\n }\n\n const entrypoint = Entrypoint.createRoot(\n services,\n options.filename,\n ['__wywPreval'],\n originalCode\n );\n\n if (entrypoint.ignored) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const workflowAction = entrypoint.createAction('workflow', undefined);\n\n try {\n const result = syncActionRunner(workflowAction, {\n ...baseHandlers,\n ...customHandlers,\n resolveImports() {\n return syncResolveImports.call(this, syncResolve);\n },\n });\n\n entrypoint.log('%s is ready', entrypoint.name);\n\n return result;\n } catch (err) {\n entrypoint.log('Unhandled error %O', err);\n\n if (\n isFeatureEnabled(pluginOptions.features, 'softErrors', options.filename)\n ) {\n // eslint-disable-next-line no-console\n console.error(`Error during transform of ${entrypoint.name}:`, err);\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n throw err;\n }\n}\n\nexport async function transform(\n partialServices: PartialServices,\n originalCode: string,\n asyncResolve: (\n what: string,\n importer: string,\n stack: string[]\n ) => Promise<string | null>,\n customHandlers: Partial<AllHandlers<'sync'>> = {}\n): Promise<Result> {\n const { options } = partialServices;\n const pluginOptions = loadWywOptions(options.pluginOptions);\n const services = withDefaultServices({\n ...partialServices,\n options: {\n ...options,\n pluginOptions,\n },\n });\n\n if (\n !isFeatureEnabled(pluginOptions.features, 'globalCache', options.filename)\n ) {\n // If global cache is disabled, we need to create a new cache for each file\n services.cache = new TransformCacheCollection();\n }\n\n /*\n * This method can be run simultaneously for multiple files.\n * A shared cache is accessible for all runs, but each run has its own queue\n * to maintain the correct processing order. The cache stores the outcome\n * of tree-shaking, and if the result is already stored in the cache\n * but the \"only\" option has changed, the file will be re-processed using\n * the combined \"only\" option.\n */\n const entrypoint = Entrypoint.createRoot(\n services,\n options.filename,\n ['__wywPreval'],\n originalCode\n );\n\n if (entrypoint.ignored) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const workflowAction = entrypoint.createAction('workflow', undefined);\n\n try {\n const result = await asyncActionRunner(workflowAction, {\n ...baseHandlers,\n ...customHandlers,\n resolveImports(this: IResolveImportsAction) {\n return asyncResolveImports.call(this, asyncResolve);\n },\n });\n\n entrypoint.log('%s is ready', entrypoint.name);\n\n return result;\n } catch (err) {\n entrypoint.log('Unhandled error %O', err);\n\n if (\n isFeatureEnabled(pluginOptions.features, 'softErrors', options.filename)\n ) {\n // eslint-disable-next-line no-console\n console.error(`Error during transform of ${entrypoint.name}:`, err);\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n throw err;\n }\n}\n"],"mappings":";;;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAIA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AAIA,IAAAO,oBAAA,GAAAP,OAAA;AAzBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAiCO,SAASQ,aAAaA,CAC3BC,eAAgC,EAChCC,YAAoB,EACpBC,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MAAMC,MAAM,GAAG,MAAM,IAAAa,+BAAiB,EAAChB,cAAc,EAAE;MACrD,GAAGK,wBAAY;MACf,GAAGvB,cAAc;MACjBwB,cAAcA,CAAA,EAA8B;QAC1C,OAAOW,mCAAmB,CAACT,IAAI,CAAC,IAAI,EAAEO,YAAY,CAAC;MACrD;IACF,CAAC,CAAC;IAEFtB,UAAU,CAACgB,GAAG,CAAC,aAAa,EAAEhB,UAAU,CAACiB,IAAI,CAAC;IAE9C,OAAOP,MAAM;EACf,CAAC,CAAC,OAAOQ,GAAG,EAAE;IACZlB,UAAU,CAACgB,GAAG,CAAC,oBAAoB,EAAEE,GAAG,CAAC;IAEzC,IACE,IAAAvB,wBAAgB,EAACJ,aAAa,CAACK,QAAQ,EAAE,YAAY,EAAEN,OAAO,CAACO,QAAQ,CAAC,EACxE;MACA;MACAsB,OAAO,CAACC,KAAK,CAAE,6BAA4BpB,UAAU,CAACiB,IAAK,GAAE,EAAEC,GAAG,CAAC;MAEnE,OAAO;QACLd,IAAI,EAAEjB,YAAY;QAClBkB,SAAS,EAAEf,OAAO,CAACgB;MACrB,CAAC;IACH;IAEA,MAAMY,GAAG;EACX;AACF"}
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { BabelFile, PluginPass } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type { File, Program } from '@babel/types';\nimport type { RawSourceMap } from 'source-map';\n\nimport type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Debugger,\n Replacement,\n Rules,\n StrictOptions,\n} from '@wyw-in-js/shared';\n\nimport type { WYWTransformMetadata } from './utils/TransformMetadata';\n\nexport type PluginOptions = StrictOptions & {\n configFile?: string | false;\n stage?: Stage;\n};\n\nexport type ParentEntrypoint = {\n evaluated: boolean;\n log: Debugger;\n name: string;\n parents: ParentEntrypoint[];\n seqId: number;\n};\n\nexport type Dependencies = string[];\n\nexport interface IPluginState extends PluginPass {\n dependencies: Dependencies;\n file: BabelFile & {\n metadata: {\n
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { BabelFile, PluginPass } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type { File, Program } from '@babel/types';\nimport type { RawSourceMap } from 'source-map';\n\nimport type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Debugger,\n Replacement,\n Rules,\n StrictOptions,\n} from '@wyw-in-js/shared';\n\nimport type { WYWTransformMetadata } from './utils/TransformMetadata';\n\nexport type PluginOptions = StrictOptions & {\n configFile?: string | false;\n stage?: Stage;\n};\n\nexport type ParentEntrypoint = {\n evaluated: boolean;\n log: Debugger;\n name: string;\n parents: ParentEntrypoint[];\n seqId: number;\n};\n\nexport type Dependencies = string[];\n\nexport interface IPluginState extends PluginPass {\n dependencies: Dependencies;\n file: BabelFile & {\n metadata: {\n wywInJS?: WYWTransformMetadata;\n };\n };\n processors: BaseProcessor[];\n}\n\nexport interface ITransformFileResult {\n code: string;\n metadata: WYWTransformMetadata | null;\n}\n\nexport type Stage = 'preeval' | 'collect';\n\nexport type Result = {\n code: string;\n cssSourceMapText?: string;\n cssText?: string;\n dependencies?: string[];\n replacements?: Replacement[];\n rules?: Rules;\n sourceMap?: RawSourceMap | null;\n};\n\nexport type Options = {\n filename: string;\n inputSourceMap?: RawSourceMap;\n outputFilename?: string;\n pluginOptions?: Partial<PluginOptions>;\n preprocessor?: Preprocessor;\n root?: string;\n};\n\nexport type PreprocessorFn = (selector: string, cssText: string) => string;\nexport type Preprocessor = 'none' | 'stylis' | PreprocessorFn | void;\n\nexport type MissedBabelCoreTypes = {\n File: new (\n options: { filename: string },\n file: { ast: File; code: string }\n ) => { path: NodePath<Program> };\n};\n\nexport type JSONValue =\n | null\n | string\n | number\n | boolean\n | JSONObject\n | JSONArray;\n\nexport interface JSONObject {\n [x: string]: JSONValue;\n}\n\nexport type JSONArray = Array<JSONValue>;\n\nexport type Serializable = JSONValue;\n\n/**\n * CSS-related types\n */\n"],"mappings":""}
|
|
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.hasShakerMetadata = void 0;
|
|
7
|
-
const hasShakerMetadata = metadata => metadata !== undefined && '
|
|
7
|
+
const hasShakerMetadata = metadata => metadata !== undefined && 'wywEvaluator' in metadata;
|
|
8
8
|
exports.hasShakerMetadata = hasShakerMetadata;
|
|
9
9
|
//# sourceMappingURL=ShakerMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShakerMetadata.js","names":["hasShakerMetadata","metadata","undefined","exports"],"sources":["../../src/utils/ShakerMetadata.ts"],"sourcesContent":["export interface IShakerMetadata {\n imports: Map<string, string[]>;\n}\n\nexport interface IMetadata {\n
|
|
1
|
+
{"version":3,"file":"ShakerMetadata.js","names":["hasShakerMetadata","metadata","undefined","exports"],"sources":["../../src/utils/ShakerMetadata.ts"],"sourcesContent":["export interface IShakerMetadata {\n imports: Map<string, string[]>;\n}\n\nexport interface IMetadata {\n wywEvaluator: IShakerMetadata;\n}\n\nexport const hasShakerMetadata = (\n metadata: object | undefined\n): metadata is IMetadata =>\n metadata !== undefined && 'wywEvaluator' in metadata;\n"],"mappings":";;;;;;AAQO,MAAMA,iBAAiB,GAC5BC,QAA4B,IAE5BA,QAAQ,KAAKC,SAAS,IAAI,cAAc,IAAID,QAAQ;AAACE,OAAA,CAAAH,iBAAA,GAAAA,iBAAA"}
|
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.addIdentifierToWywPreval = addIdentifierToWywPreval;
|
|
7
|
+
exports.getOrAddWywPreval = getOrAddWywPreval;
|
|
8
8
|
var _createId = require("./createId");
|
|
9
9
|
var _scopeHelpers = require("./scopeHelpers");
|
|
10
|
-
function
|
|
10
|
+
function getOrAddWywPreval(scope) {
|
|
11
11
|
const rootScope = scope.getProgramParent();
|
|
12
12
|
const programPath = rootScope.path;
|
|
13
|
-
let object = programPath.getData('
|
|
13
|
+
let object = programPath.getData('__wywPreval');
|
|
14
14
|
if (object) {
|
|
15
15
|
return object;
|
|
16
16
|
}
|
|
17
17
|
if (programPath.node.sourceType === 'script') {
|
|
18
|
-
// CJS exports.
|
|
18
|
+
// CJS exports.__wywPreval = {};
|
|
19
19
|
const prevalExport = {
|
|
20
20
|
expression: {
|
|
21
21
|
type: 'AssignmentExpression',
|
|
@@ -23,7 +23,7 @@ function getOrAddLinariaPreval(scope) {
|
|
|
23
23
|
left: {
|
|
24
24
|
computed: false,
|
|
25
25
|
object: (0, _createId.createId)('exports'),
|
|
26
|
-
property: (0, _createId.createId)('
|
|
26
|
+
property: (0, _createId.createId)('__wywPreval'),
|
|
27
27
|
type: 'MemberExpression'
|
|
28
28
|
},
|
|
29
29
|
right: {
|
|
@@ -36,11 +36,11 @@ function getOrAddLinariaPreval(scope) {
|
|
|
36
36
|
const [inserted] = programPath.pushContainer('body', [prevalExport]);
|
|
37
37
|
object = inserted.get('expression.right');
|
|
38
38
|
} else {
|
|
39
|
-
// ESM export const
|
|
39
|
+
// ESM export const __wywPreval = {};
|
|
40
40
|
const prevalExport = {
|
|
41
41
|
declaration: {
|
|
42
42
|
declarations: [{
|
|
43
|
-
id: (0, _createId.createId)('
|
|
43
|
+
id: (0, _createId.createId)('__wywPreval'),
|
|
44
44
|
init: {
|
|
45
45
|
properties: [],
|
|
46
46
|
type: 'ObjectExpression'
|
|
@@ -56,12 +56,12 @@ function getOrAddLinariaPreval(scope) {
|
|
|
56
56
|
const [inserted] = programPath.pushContainer('body', [prevalExport]);
|
|
57
57
|
object = inserted.get('declaration.declarations.0.init');
|
|
58
58
|
}
|
|
59
|
-
programPath.setData('
|
|
59
|
+
programPath.setData('__wywPreval', object);
|
|
60
60
|
return object;
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function addIdentifierToWywPreval(scope, name) {
|
|
63
63
|
const rootScope = scope.getProgramParent();
|
|
64
|
-
const object =
|
|
64
|
+
const object = getOrAddWywPreval(rootScope);
|
|
65
65
|
const newProperty = {
|
|
66
66
|
type: 'ObjectProperty',
|
|
67
67
|
key: (0, _createId.createId)(name),
|
|
@@ -72,4 +72,4 @@ function addIdentifierToLinariaPreval(scope, name) {
|
|
|
72
72
|
const [inserted] = object.pushContainer('properties', [newProperty]);
|
|
73
73
|
(0, _scopeHelpers.reference)(inserted.get('value'));
|
|
74
74
|
}
|
|
75
|
-
//# sourceMappingURL=
|
|
75
|
+
//# sourceMappingURL=addIdentifierToWywPreval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addIdentifierToWywPreval.js","names":["_createId","require","_scopeHelpers","getOrAddWywPreval","scope","rootScope","getProgramParent","programPath","path","object","getData","node","sourceType","prevalExport","expression","type","operator","left","computed","createId","property","right","properties","inserted","pushContainer","get","declaration","declarations","id","init","kind","specifiers","setData","addIdentifierToWywPreval","name","newProperty","key","value","shorthand","reference"],"sources":["../../src/utils/addIdentifierToWywPreval.ts"],"sourcesContent":["import type { NodePath, Scope } from '@babel/traverse';\nimport type {\n ExportNamedDeclaration,\n ExpressionStatement,\n Identifier,\n ObjectExpression,\n ObjectProperty,\n Program,\n} from '@babel/types';\n\nimport { createId } from './createId';\nimport { reference } from './scopeHelpers';\n\nexport function getOrAddWywPreval(scope: Scope): NodePath<ObjectExpression> {\n const rootScope = scope.getProgramParent();\n const programPath = rootScope.path as NodePath<Program>;\n\n let object = programPath.getData('__wywPreval');\n if (object) {\n return object;\n }\n\n if (programPath.node.sourceType === 'script') {\n // CJS exports.__wywPreval = {};\n const prevalExport: ExpressionStatement = {\n expression: {\n type: 'AssignmentExpression',\n operator: '=',\n left: {\n computed: false,\n object: createId('exports'),\n property: createId('__wywPreval'),\n type: 'MemberExpression',\n },\n right: {\n properties: [],\n type: 'ObjectExpression',\n },\n },\n type: 'ExpressionStatement',\n };\n\n const [inserted] = programPath.pushContainer('body', [prevalExport]);\n object = inserted.get('expression.right') as NodePath<ObjectExpression>;\n } else {\n // ESM export const __wywPreval = {};\n const prevalExport: ExportNamedDeclaration = {\n declaration: {\n declarations: [\n {\n id: createId('__wywPreval'),\n init: {\n properties: [],\n type: 'ObjectExpression',\n },\n type: 'VariableDeclarator',\n },\n ],\n kind: 'const',\n type: 'VariableDeclaration',\n },\n specifiers: [],\n type: 'ExportNamedDeclaration',\n };\n\n const [inserted] = programPath.pushContainer('body', [prevalExport]);\n object = inserted.get(\n 'declaration.declarations.0.init'\n ) as NodePath<ObjectExpression>;\n }\n\n programPath.setData('__wywPreval', object);\n return object;\n}\n\nexport function addIdentifierToWywPreval(scope: Scope, name: string) {\n const rootScope = scope.getProgramParent();\n const object = getOrAddWywPreval(rootScope);\n const newProperty: ObjectProperty = {\n type: 'ObjectProperty',\n key: createId(name),\n value: createId(name),\n computed: false,\n shorthand: false,\n };\n\n const [inserted] = object.pushContainer('properties', [newProperty]);\n reference(inserted.get('value') as NodePath<Identifier>);\n}\n"],"mappings":";;;;;;;AAUA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEO,SAASE,iBAAiBA,CAACC,KAAY,EAA8B;EAC1E,MAAMC,SAAS,GAAGD,KAAK,CAACE,gBAAgB,CAAC,CAAC;EAC1C,MAAMC,WAAW,GAAGF,SAAS,CAACG,IAAyB;EAEvD,IAAIC,MAAM,GAAGF,WAAW,CAACG,OAAO,CAAC,aAAa,CAAC;EAC/C,IAAID,MAAM,EAAE;IACV,OAAOA,MAAM;EACf;EAEA,IAAIF,WAAW,CAACI,IAAI,CAACC,UAAU,KAAK,QAAQ,EAAE;IAC5C;IACA,MAAMC,YAAiC,GAAG;MACxCC,UAAU,EAAE;QACVC,IAAI,EAAE,sBAAsB;QAC5B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