@wyw-in-js/transform 1.0.8 → 1.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/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/esm/transform/actions/types.js.map +1 -1
- package/esm/transform/generators/workflow.js +11 -0
- package/esm/transform/generators/workflow.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +1 -0
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/TransformDiagnostics.js +10 -0
- package/esm/utils/TransformDiagnostics.js.map +1 -0
- package/esm/utils/TransformMetadata.js +20 -0
- package/esm/utils/TransformMetadata.js.map +1 -1
- package/lib/index.js +29 -0
- package/lib/index.js.map +1 -1
- package/lib/transform/actions/types.js.map +1 -1
- package/lib/transform/generators/workflow.js +10 -0
- package/lib/transform/generators/workflow.js.map +1 -1
- package/lib/transform/helpers/loadWywOptions.js +1 -0
- package/lib/transform/helpers/loadWywOptions.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/TransformDiagnostics.js +20 -0
- package/lib/utils/TransformDiagnostics.js.map +1 -0
- package/lib/utils/TransformMetadata.js +27 -1
- package/lib/utils/TransformMetadata.js.map +1 -1
- package/package.json +3 -3
- package/types/index.d.ts +4 -2
- package/types/index.js +6 -1
- package/types/plugins/collector.d.ts +4 -1
- package/types/transform/actions/types.d.ts +4 -0
- package/types/transform/generators/workflow.js +8 -0
- package/types/transform/helpers/loadWywOptions.js +1 -0
- package/types/types.d.ts +4 -1
- package/types/utils/TransformDiagnostics.d.ts +9 -0
- package/types/utils/TransformDiagnostics.js +15 -0
- package/types/utils/TransformMetadata.d.ts +22 -4
- package/types/utils/TransformMetadata.js +24 -1
package/esm/index.js
CHANGED
|
@@ -2,7 +2,8 @@ export { slugify } from '@wyw-in-js/shared';
|
|
|
2
2
|
export { createFileReporter } from './debug/fileReporter';
|
|
3
3
|
export { default as babelTransformPlugin } from './plugins/babel-transform';
|
|
4
4
|
export { default as preeval } from './plugins/preeval';
|
|
5
|
-
export { getTransformMetadata, withTransformMetadata } from './utils/TransformMetadata';
|
|
5
|
+
export { createTransformManifest, getTransformMetadata, stringifyTransformManifest, toTransformResultMetadata, withTransformMetadata } from './utils/TransformMetadata';
|
|
6
|
+
export { collectTransformDiagnostics } from './utils/TransformDiagnostics';
|
|
6
7
|
export { Module, DefaultModuleImplementation } from './module';
|
|
7
8
|
export { default as shaker } from './shaker';
|
|
8
9
|
export { transform } from './transform';
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["slugify","createFileReporter","default","babelTransformPlugin","preeval","getTransformMetadata","withTransformMetadata","Module","DefaultModuleImplementation","shaker","transform","isUnprocessedEntrypointError","UnprocessedEntrypointError","EvaluatedEntrypoint","parseFile","baseHandlers","prepareCode","Entrypoint","transformUrl","asyncResolveImports","syncResolveImports","loadWywOptions","withDefaultServices","EventEmitter","isNode","getFileIdx","applyProcessors","getVisitorKeys","peek","TransformCacheCollection","findIdentifiers"],"sources":["../src/index.ts"],"sourcesContent":["export { slugify } from '@wyw-in-js/shared';\n\nexport { createFileReporter } from './debug/fileReporter';\nexport type { IFileReporterOptions } from './debug/fileReporter';\nexport { default as babelTransformPlugin } from './plugins/babel-transform';\nexport { default as preeval } from './plugins/preeval';\nexport {\n getTransformMetadata,\n withTransformMetadata,\n} from './utils/TransformMetadata';\nexport type {
|
|
1
|
+
{"version":3,"file":"index.js","names":["slugify","createFileReporter","default","babelTransformPlugin","preeval","createTransformManifest","getTransformMetadata","stringifyTransformManifest","toTransformResultMetadata","withTransformMetadata","collectTransformDiagnostics","Module","DefaultModuleImplementation","shaker","transform","isUnprocessedEntrypointError","UnprocessedEntrypointError","EvaluatedEntrypoint","parseFile","baseHandlers","prepareCode","Entrypoint","transformUrl","asyncResolveImports","syncResolveImports","loadWywOptions","withDefaultServices","EventEmitter","isNode","getFileIdx","applyProcessors","getVisitorKeys","peek","TransformCacheCollection","findIdentifiers"],"sources":["../src/index.ts"],"sourcesContent":["export { slugify } from '@wyw-in-js/shared';\n\nexport { createFileReporter } from './debug/fileReporter';\nexport type { IFileReporterOptions } from './debug/fileReporter';\nexport { default as babelTransformPlugin } from './plugins/babel-transform';\nexport { default as preeval } from './plugins/preeval';\nexport {\n createTransformManifest,\n getTransformMetadata,\n stringifyTransformManifest,\n toTransformResultMetadata,\n withTransformMetadata,\n} from './utils/TransformMetadata';\nexport type {\n WYWTransformManifest,\n WYWTransformMetadata,\n WYWTransformProcessorMetadata,\n WYWTransformResultMetadata,\n} from './utils/TransformMetadata';\nexport { collectTransformDiagnostics } from './utils/TransformDiagnostics';\nexport type { WYWTransformDiagnostic } from './utils/TransformDiagnostics';\nexport { Module, DefaultModuleImplementation } from './module';\nexport { default as shaker } from './shaker';\nexport { transform } from './transform';\nexport {\n isUnprocessedEntrypointError,\n UnprocessedEntrypointError,\n} from './transform/actions/UnprocessedEntrypointError';\nexport * from './types';\nexport { EvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nexport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nexport { parseFile } from './transform/Entrypoint.helpers';\nexport type { LoadAndParseFn } from './transform/Entrypoint.types';\nexport { baseHandlers } from './transform/generators';\nexport { prepareCode } from './transform/generators/transform';\nexport { Entrypoint } from './transform/Entrypoint';\nexport { transformUrl } from './transform/generators/createStylisPreprocessor';\nexport {\n asyncResolveImports,\n syncResolveImports,\n} from './transform/generators/resolveImports';\nexport { loadWywOptions } from './transform/helpers/loadWywOptions';\nexport { withDefaultServices } from './transform/helpers/withDefaultServices';\nexport type { Services } from './transform/types';\nexport { EventEmitter } from './utils/EventEmitter';\nexport type {\n EntrypointEvent,\n OnEvent,\n OnActionStartArgs,\n OnActionFinishArgs,\n} from './utils/EventEmitter';\nexport { isNode } from './utils/isNode';\nexport { getFileIdx } from './utils/getFileIdx';\nexport { applyProcessors } from './utils/getTagProcessor';\nexport { getVisitorKeys } from './utils/getVisitorKeys';\nexport type { VisitorKeys } from './utils/getVisitorKeys';\nexport { peek } from './utils/peek';\nexport { TransformCacheCollection } from './cache';\nexport { findIdentifiers } from './utils/findIdentifiers';\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAE3C,SAASC,kBAAkB,QAAQ,sBAAsB;AAEzD,SAASC,OAAO,IAAIC,oBAAoB,QAAQ,2BAA2B;AAC3E,SAASD,OAAO,IAAIE,OAAO,QAAQ,mBAAmB;AACtD,SACEC,uBAAuB,EACvBC,oBAAoB,EACpBC,0BAA0B,EAC1BC,yBAAyB,EACzBC,qBAAqB,QAChB,2BAA2B;AAOlC,SAASC,2BAA2B,QAAQ,8BAA8B;AAE1E,SAASC,MAAM,EAAEC,2BAA2B,QAAQ,UAAU;AAC9D,SAASV,OAAO,IAAIW,MAAM,QAAQ,UAAU;AAC5C,SAASC,SAAS,QAAQ,aAAa;AACvC,SACEC,4BAA4B,EAC5BC,0BAA0B,QACrB,gDAAgD;AACvD,cAAc,SAAS;AACvB,SAASC,mBAAmB,QAAQ,iCAAiC;AAErE,SAASC,SAAS,QAAQ,gCAAgC;AAE1D,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,WAAW,QAAQ,kCAAkC;AAC9D,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,YAAY,QAAQ,iDAAiD;AAC9E,SACEC,mBAAmB,EACnBC,kBAAkB,QACb,uCAAuC;AAC9C,SAASC,cAAc,QAAQ,oCAAoC;AACnE,SAASC,mBAAmB,QAAQ,yCAAyC;AAE7E,SAASC,YAAY,QAAQ,sBAAsB;AAOnD,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,SAASC,IAAI,QAAQ,cAAc;AACnC,SAASC,wBAAwB,QAAQ,SAAS;AAClD,SAASC,eAAe,QAAQ,yBAAyB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/transform/actions/types.ts"],"sourcesContent":["import type { BabelFileResult } from '@babel/core';\n\nimport type { Replacements, Rules } from '@wyw-in-js/shared';\n\nexport interface IExtracted {\n cssSourceMapText: string;\n cssText: string;\n replacements: Replacements;\n rules: Rules;\n}\n\nexport interface IWorkflowActionNonLinariaResult {\n code: string;\n sourceMap: BabelFileResult['map'];\n}\n\nexport interface IWorkflowActionLinariaResult\n extends IExtracted,\n IWorkflowActionNonLinariaResult {\n dependencies: string[];\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/transform/actions/types.ts"],"sourcesContent":["import type { BabelFileResult } from '@babel/core';\n\nimport type { Replacements, Rules } from '@wyw-in-js/shared';\n\nimport type { WYWTransformDiagnostic } from '../../utils/TransformDiagnostics';\nimport type { WYWTransformResultMetadata } from '../../utils/TransformMetadata';\n\nexport interface IExtracted {\n cssSourceMapText: string;\n cssText: string;\n replacements: Replacements;\n rules: Rules;\n}\n\nexport interface IWorkflowActionNonLinariaResult {\n code: string;\n sourceMap: BabelFileResult['map'];\n}\n\nexport interface IWorkflowActionLinariaResult\n extends IExtracted,\n IWorkflowActionNonLinariaResult {\n dependencies: string[];\n diagnostics?: WYWTransformDiagnostic[];\n metadata?: WYWTransformResultMetadata;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { isAborted } from '../actions/AbortError';
|
|
2
|
+
import { collectTransformDiagnostics } from '../../utils/TransformDiagnostics';
|
|
3
|
+
import { toTransformResultMetadata } from '../../utils/TransformMetadata';
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* The entry point for file processing. Sequentially calls `processEntrypoint`,
|
|
4
7
|
* `evalFile`, `collect`, and `extract`. Returns the result of transforming
|
|
@@ -65,6 +68,8 @@ export function* workflow() {
|
|
|
65
68
|
sourceMap: collectStageResult.map
|
|
66
69
|
};
|
|
67
70
|
}
|
|
71
|
+
const metadata = options.pluginOptions.outputMetadata ? toTransformResultMetadata(collectStageResult.metadata, dependencies) : null;
|
|
72
|
+
const diagnostics = collectTransformDiagnostics(entrypoint.name, collectStageResult.metadata.processors);
|
|
68
73
|
|
|
69
74
|
// *** 4th stage
|
|
70
75
|
|
|
@@ -75,6 +80,12 @@ export function* workflow() {
|
|
|
75
80
|
...extractStageResult,
|
|
76
81
|
code: collectStageResult.code ?? '',
|
|
77
82
|
dependencies,
|
|
83
|
+
...(diagnostics.length > 0 ? {
|
|
84
|
+
diagnostics
|
|
85
|
+
} : {}),
|
|
86
|
+
...(metadata ? {
|
|
87
|
+
metadata
|
|
88
|
+
} : {}),
|
|
78
89
|
replacements: [...extractStageResult.replacements, ...collectStageResult.metadata.replacements],
|
|
79
90
|
sourceMap: collectStageResult.map
|
|
80
91
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.js","names":["isAborted","workflow","cache","options","services","entrypoint","ignored","code","loadedAndParsed","sourceMap","inputSourceMap","getNext","undefined","assertNotSuperseded","e","supersededWith","log","originalCode","hasWywMetadata","generation","delete","name","evalStageResult","valueCache","dependencies","collectStageResult","metadata","map","
|
|
1
|
+
{"version":3,"file":"workflow.js","names":["isAborted","collectTransformDiagnostics","toTransformResultMetadata","workflow","cache","options","services","entrypoint","ignored","code","loadedAndParsed","sourceMap","inputSourceMap","getNext","undefined","assertNotSuperseded","e","supersededWith","log","originalCode","hasWywMetadata","generation","delete","name","evalStageResult","valueCache","dependencies","collectStageResult","metadata","map","pluginOptions","outputMetadata","diagnostics","processors","extractStageResult","length","replacements"],"sources":["../../../src/transform/generators/workflow.ts"],"sourcesContent":["import { isAborted } from '../actions/AbortError';\nimport type { IWorkflowAction, SyncScenarioForAction } from '../types';\nimport { collectTransformDiagnostics } from '../../utils/TransformDiagnostics';\nimport { toTransformResultMetadata } from '../../utils/TransformMetadata';\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 const metadata = options.pluginOptions.outputMetadata\n ? toTransformResultMetadata(collectStageResult.metadata, dependencies)\n : null;\n const diagnostics = collectTransformDiagnostics(\n entrypoint.name,\n collectStageResult.metadata.processors\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 ...(diagnostics.length > 0 ? { diagnostics } : {}),\n ...(metadata ? { metadata } : {}),\n replacements: [\n ...extractStageResult.replacements,\n ...collectStageResult.metadata.replacements,\n ],\n sourceMap: collectStageResult.map,\n };\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,uBAAuB;AAEjD,SAASC,2BAA2B,QAAQ,kCAAkC;AAC9E,SAASC,yBAAyB,QAAQ,+BAA+B;;AAEzE;AACA;AACA;AACA;AACA;AACA,OAAO,UAAUC,QAAQA,CAAA,EAEiB;EACxC,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAI,CAACC,QAAQ;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI;EAE3B,IAAIA,UAAU,CAACC,OAAO,EAAE;IACtB,OAAO;MACLC,IAAI,EAAEF,UAAU,CAACG,eAAe,CAACD,IAAI,IAAI,EAAE;MAC3CE,SAAS,EAAEN,OAAO,CAACO;IACrB,CAAC;EACH;EAEA,IAAI;IACF,OAAO,IAAI,CAACC,OAAO,CAAC,mBAAmB,EAAEN,UAAU,EAAEO,SAAS,EAAE,IAAI,CAAC;IACrEP,UAAU,CAACQ,mBAAmB,CAAC,CAAC;EAClC,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,IAAIhB,SAAS,CAACgB,CAAC,CAAC,IAAIT,UAAU,CAACU,cAAc,EAAE;MAC7CV,UAAU,CAACW,GAAG,CAAC,6CAA6C,CAAC;MAC7D,OAAO,OAAO,IAAI,CAACL,OAAO,CACxB,UAAU,EACVN,UAAU,CAACU,cAAc,EACzBH,SAAS,EACT,IACF,CAAC;IACH;IAEA,MAAME,CAAC;EACT;EAEA,MAAMG,YAAY,GAAGZ,UAAU,CAACG,eAAe,CAACD,IAAI,IAAI,EAAE;;E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CAACK;EAC1C,CAAC,EACD,IACF,CAAC;EAED,OAAO;IACL,GAAGC,kBAAkB;IACrBzB,IAAI,EAAEkB,kBAAkB,CAAClB,IAAI,IAAI,EAAE;IACnCiB,YAAY;IACZ,IAAIM,WAAW,CAACG,MAAM,GAAG,CAAC,GAAG;MAAEH;IAAY,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,IAAIJ,QAAQ,GAAG;MAAEA;IAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IACjCQ,YAAY,EAAE,CACZ,GAAGF,kBAAkB,CAACE,YAAY,EAClC,GAAGT,kBAAkB,CAACC,QAAQ,CAACQ,YAAY,CAC5C;IACDzB,SAAS,EAAEgB,kBAAkB,CAACE;EAChC,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadWywOptions.js","names":["cosmiconfigSync","shaker","searchPlaces","explorerSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","defaultImportLoaders","raw","url","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","importLoaders","overridesImportLoaders","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","useWeakRefInEval","config","configImportLoaders","configFeatures","features","options","displayName","evaluate","extensions","action","test","filename","code","highPriorityPlugins","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type {\n FeatureFlags,\n ImportLoaders,\n StrictOptions,\n} 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[\\\\/]/;\nconst defaultImportLoaders: ImportLoaders = {\n raw: 'raw',\n url: 'url',\n};\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const {\n configFile,\n ignore,\n rules,\n babelOptions = {},\n importLoaders: overridesImportLoaders,\n ...rest\n } = 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 useWeakRefInEval: true,\n };\n\n const config = (result?.config ?? {}) as Partial<StrictOptions>;\n const configImportLoaders = config.importLoaders;\n const configFeatures = config.features;\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 ...config,\n ...rest,\n importLoaders: {\n ...defaultImportLoaders,\n ...(configImportLoaders ?? {}),\n ...(overridesImportLoaders ?? {}),\n },\n features: {\n ...defaultFeatures,\n ...(configFeatures ?? {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAQ7C,SAASC,MAAM,QAAQ,cAAc;AAGrC,MAAMC,YAAY,GAAG,CACnB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,CACvB;AAED,MAAMC,YAAY,GAAGH,eAAe,CAAC,WAAW,EAAE;EAAEE;AAAa,CAAC,CAAC;AAMnE,MAAME,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAClD,MAAMC,oBAAmC,GAAG;EAC1CC,GAAG,EAAE,KAAK;EACVC,GAAG,EAAE;AACP,CAAC;AAED,OAAO,SAASC,cAAcA,CAC5BC,SAAyB,GAAGN,gBAAgB,EAC7B;EACf,IAAIF,KAAK,CAACS,GAAG,CAACD,SAAS,CAAC,EAAE;IACxB,OAAOR,KAAK,CAACU,GAAG,CAACF,SAAS,CAAC;EAC7B;EAEA,MAAM;IACJG,UAAU;IACVC,MAAM;IACNC,KAAK;IACLC,YAAY,GAAG,CAAC,CAAC;IACjBC,aAAa,EAAEC,sBAAsB;IACrC,GAAGC;EACL,CAAC,GAAGT,SAAS;EAEb,MAAMU,MAAM;EACV;EACAP,UAAU,KAAK,KAAK,GAChBQ,SAAS,GACTR,UAAU,KAAKQ,SAAS,GACxBpB,YAAY,CAACqB,IAAI,CAACT,UAAU,CAAC,GAC7BZ,YAAY,CAACsB,MAAM,CAAC,CAAC;EAE3B,MAAMC,eAA6B,GAAG;IACpCC,oBAAoB,EAAE,IAAI;IAC1BC,WAAW,EAAE,IAAI;IACjBC,QAAQ,EAAE,IAAI;IACdC,UAAU,EAAE,KAAK;IACjBC,eAAe,EAAE,IAAI;IACrBC,gBAAgB,EAAE;EACpB,CAAC;EAED,MAAMC,MAAM,GAAIX,MAAM,EAAEW,MAAM,IAAI,CAAC,CAA4B;EAC/D,MAAMC,mBAAmB,GAAGD,MAAM,CAACd,aAAa;EAChD,MAAMgB,cAAc,GAAGF,MAAM,CAACG,QAAQ;EAEtC,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;
|
|
1
|
+
{"version":3,"file":"loadWywOptions.js","names":["cosmiconfigSync","shaker","searchPlaces","explorerSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","defaultImportLoaders","raw","url","loadWywOptions","overrides","has","get","configFile","ignore","rules","babelOptions","importLoaders","overridesImportLoaders","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","useWeakRefInEval","config","configImportLoaders","configFeatures","features","options","displayName","evaluate","extensions","outputMetadata","action","test","filename","code","highPriorityPlugins","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type {\n FeatureFlags,\n ImportLoaders,\n StrictOptions,\n} 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[\\\\/]/;\nconst defaultImportLoaders: ImportLoaders = {\n raw: 'raw',\n url: 'url',\n};\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const {\n configFile,\n ignore,\n rules,\n babelOptions = {},\n importLoaders: overridesImportLoaders,\n ...rest\n } = 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 useWeakRefInEval: true,\n };\n\n const config = (result?.config ?? {}) as Partial<StrictOptions>;\n const configImportLoaders = config.importLoaders;\n const configFeatures = config.features;\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n outputMetadata: false,\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 ...config,\n ...rest,\n importLoaders: {\n ...defaultImportLoaders,\n ...(configImportLoaders ?? {}),\n ...(overridesImportLoaders ?? {}),\n },\n features: {\n ...defaultFeatures,\n ...(configFeatures ?? {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAQ7C,SAASC,MAAM,QAAQ,cAAc;AAGrC,MAAMC,YAAY,GAAG,CACnB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,CACvB;AAED,MAAMC,YAAY,GAAGH,eAAe,CAAC,WAAW,EAAE;EAAEE;AAAa,CAAC,CAAC;AAMnE,MAAME,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAClD,MAAMC,oBAAmC,GAAG;EAC1CC,GAAG,EAAE,KAAK;EACVC,GAAG,EAAE;AACP,CAAC;AAED,OAAO,SAASC,cAAcA,CAC5BC,SAAyB,GAAGN,gBAAgB,EAC7B;EACf,IAAIF,KAAK,CAACS,GAAG,CAACD,SAAS,CAAC,EAAE;IACxB,OAAOR,KAAK,CAACU,GAAG,CAACF,SAAS,CAAC;EAC7B;EAEA,MAAM;IACJG,UAAU;IACVC,MAAM;IACNC,KAAK;IACLC,YAAY,GAAG,CAAC,CAAC;IACj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B,YAAY;IACZ4B,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,GAAGb,MAAM;IACT,GAAGZ,IAAI;IACPF,aAAa,EAAE;MACb,GAAGX,oBAAoB;MACvB,IAAI0B,mBAAmB,IAAI,CAAC,CAAC,CAAC;MAC9B,IAAId,sBAAsB,IAAI,CAAC,CAAC;IAClC,CAAC;IACDgB,QAAQ,EAAE;MACR,GAAGV,eAAe;MAClB,IAAIS,cAAc,IAAI,CAAC,CAAC,CAAC;MACzB,GAAGd,IAAI,CAACe;IACV;EACF,CAAC;EAEDhC,KAAK,CAAC2C,GAAG,CAACnC,SAAS,EAAEyB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB","ignoreList":[]}
|
package/esm/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 {
|
|
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 {\n WYWTransformMetadata,\n WYWTransformResultMetadata,\n} from './utils/TransformMetadata';\nimport type { WYWTransformDiagnostic } from './utils/TransformDiagnostics';\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 diagnostics?: WYWTransformDiagnostic[];\n metadata?: WYWTransformResultMetadata;\n replacements?: Replacement[];\n rules?: Rules;\n sourceMap?: RawSourceMap | null;\n};\n\nexport type Options = {\n filename: string;\n inputSourceMap?: RawSourceMap;\n keepComments?: boolean | RegExp;\n outputFilename?: string;\n pluginOptions?: Partial<PluginOptions>;\n prefixer?: boolean;\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":"","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isProcessorDiagnosticArtifact } from '@wyw-in-js/processor-utils';
|
|
2
|
+
export const collectTransformDiagnostics = (filename, processors) => processors.flatMap(processor => processor.artifacts.filter(isProcessorDiagnosticArtifact).map(([, diagnostic]) => ({
|
|
3
|
+
...diagnostic,
|
|
4
|
+
className: processor.className,
|
|
5
|
+
displayName: processor.displayName,
|
|
6
|
+
end: diagnostic.end ?? null,
|
|
7
|
+
filename,
|
|
8
|
+
start: diagnostic.start ?? null
|
|
9
|
+
})));
|
|
10
|
+
//# sourceMappingURL=TransformDiagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransformDiagnostics.js","names":["isProcessorDiagnosticArtifact","collectTransformDiagnostics","filename","processors","flatMap","processor","artifacts","filter","map","diagnostic","className","displayName","end","start"],"sources":["../../src/utils/TransformDiagnostics.ts"],"sourcesContent":["import type {\n BaseProcessor,\n ProcessorDiagnostic,\n} from '@wyw-in-js/processor-utils';\nimport { isProcessorDiagnosticArtifact } from '@wyw-in-js/processor-utils';\n\ntype DiagnosticProcessor = Pick<\n BaseProcessor,\n 'artifacts' | 'className' | 'displayName'\n>;\n\nexport type WYWTransformDiagnostic = ProcessorDiagnostic & {\n className: string;\n displayName: string;\n filename: string;\n};\n\nexport const collectTransformDiagnostics = (\n filename: string,\n processors: DiagnosticProcessor[]\n): WYWTransformDiagnostic[] =>\n processors.flatMap((processor) =>\n processor.artifacts\n .filter(isProcessorDiagnosticArtifact)\n .map(([, diagnostic]) => ({\n ...diagnostic,\n className: processor.className,\n displayName: processor.displayName,\n end: diagnostic.end ?? null,\n filename,\n start: diagnostic.start ?? null,\n }))\n );\n"],"mappings":"AAIA,SAASA,6BAA6B,QAAQ,4BAA4B;AAa1E,OAAO,MAAMC,2BAA2B,GAAGA,CACzCC,QAAgB,EAChBC,UAAiC,KAEjCA,UAAU,CAACC,OAAO,CAAEC,SAAS,IAC3BA,SAAS,CAACC,SAAS,CAChBC,MAAM,CAACP,6BAA6B,CAAC,CACrCQ,GAAG,CAAC,CAAC,GAAGC,UAAU,CAAC,MAAM;EACxB,GAAGA,UAAU;EACbC,SAAS,EAAEL,SAAS,CAACK,SAAS;EAC9BC,WAAW,EAAEN,SAAS,CAACM,WAAW;EAClCC,GAAG,EAAEH,UAAU,CAACG,GAAG,IAAI,IAAI;EAC3BV,QAAQ;EACRW,KAAK,EAAEJ,UAAU,CAACI,KAAK,IAAI;AAC7B,CAAC,CAAC,CACN,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isProcessorDiagnosticArtifact } from '@wyw-in-js/processor-utils';
|
|
1
2
|
export const withTransformMetadata = value => typeof value === 'object' && value !== null && typeof value.wywInJS === 'object';
|
|
2
3
|
export const getTransformMetadata = value => {
|
|
3
4
|
if (withTransformMetadata(value) && value.wywInJS !== null) {
|
|
@@ -8,4 +9,23 @@ export const getTransformMetadata = value => {
|
|
|
8
9
|
}
|
|
9
10
|
return undefined;
|
|
10
11
|
};
|
|
12
|
+
export const toTransformResultMetadata = (metadata, dependencies) => ({
|
|
13
|
+
dependencies,
|
|
14
|
+
processors: metadata.processors.map(processor => ({
|
|
15
|
+
artifacts: processor.artifacts.filter(artifact => !isProcessorDiagnosticArtifact(artifact)).map(([type, data]) => [type, data]),
|
|
16
|
+
className: processor.className,
|
|
17
|
+
displayName: processor.displayName,
|
|
18
|
+
start: processor.location?.start ?? null
|
|
19
|
+
})),
|
|
20
|
+
replacements: [...metadata.replacements],
|
|
21
|
+
rules: {
|
|
22
|
+
...metadata.rules
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
export const createTransformManifest = (metadata, context) => ({
|
|
26
|
+
...metadata,
|
|
27
|
+
...context,
|
|
28
|
+
version: 1
|
|
29
|
+
});
|
|
30
|
+
export const stringifyTransformManifest = manifest => `${JSON.stringify(manifest, null, 2)}\n`;
|
|
11
31
|
//# sourceMappingURL=TransformMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransformMetadata.js","names":["withTransformMetadata","value","wywInJS","getTransformMetadata","metadata","undefined"],"sources":["../../src/utils/TransformMetadata.ts"],"sourcesContent":["import type { Artifact, Replacement, Rules } from '@wyw-in-js/shared';\n\nexport type WYWTransformMetadata = {\n dependencies: string[];\n processors: {
|
|
1
|
+
{"version":3,"file":"TransformMetadata.js","names":["isProcessorDiagnosticArtifact","withTransformMetadata","value","wywInJS","getTransformMetadata","metadata","undefined","toTransformResultMetadata","dependencies","processors","map","processor","artifacts","filter","artifact","type","data","className","displayName","start","location","replacements","rules","createTransformManifest","context","version","stringifyTransformManifest","manifest","JSON","stringify"],"sources":["../../src/utils/TransformMetadata.ts"],"sourcesContent":["import type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport { isProcessorDiagnosticArtifact } from '@wyw-in-js/processor-utils';\nimport type { Artifact, Location, Replacement, Rules } from '@wyw-in-js/shared';\n\ntype TransformMetadataProcessor = Pick<\n BaseProcessor,\n 'artifacts' | 'className' | 'displayName' | 'location'\n>;\n\nexport type WYWTransformMetadata = {\n dependencies: string[];\n processors: TransformMetadataProcessor[];\n replacements: Replacement[];\n rules: Rules;\n};\n\nexport type WYWTransformProcessorMetadata = {\n artifacts: Artifact[];\n className: string;\n displayName: string;\n start: Location | null | undefined;\n};\n\nexport type WYWTransformResultMetadata = Omit<\n WYWTransformMetadata,\n 'processors'\n> & {\n processors: WYWTransformProcessorMetadata[];\n};\n\nexport type WYWTransformManifest = WYWTransformResultMetadata & {\n cssFile?: string;\n source: string;\n version: 1;\n};\n\nexport const withTransformMetadata = (\n value: unknown\n): value is { wywInJS: WYWTransformMetadata } =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { wywInJS: unknown }).wywInJS === 'object';\n\nexport const getTransformMetadata = (\n value: unknown\n): WYWTransformMetadata | undefined => {\n if (withTransformMetadata(value) && value.wywInJS !== null) {\n const metadata = value.wywInJS;\n // eslint-disable-next-line no-param-reassign\n delete (value as { wywInJS: unknown }).wywInJS;\n return metadata;\n }\n\n return undefined;\n};\n\nexport const toTransformResultMetadata = (\n metadata: WYWTransformMetadata,\n dependencies: string[]\n): WYWTransformResultMetadata => ({\n dependencies,\n processors: metadata.processors.map((processor) => ({\n artifacts: processor.artifacts\n .filter((artifact) => !isProcessorDiagnosticArtifact(artifact))\n .map(([type, data]) => [type, data] as Artifact),\n className: processor.className,\n displayName: processor.displayName,\n start: processor.location?.start ?? null,\n })),\n replacements: [...metadata.replacements],\n rules: { ...metadata.rules },\n});\n\nexport const createTransformManifest = (\n metadata: WYWTransformResultMetadata,\n context: Pick<WYWTransformManifest, 'cssFile' | 'source'>\n): WYWTransformManifest => ({\n ...metadata,\n ...context,\n version: 1,\n});\n\nexport const stringifyTransformManifest = (\n manifest: WYWTransformManifest\n): string => `${JSON.stringify(manifest, null, 2)}\\n`;\n"],"mappings":"AACA,SAASA,6BAA6B,QAAQ,4BAA4B;AAmC1E,OAAO,MAAMC,qBAAqB,GAChCC,KAAc,IAEd,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAA0BC,OAAO,KAAK,QAAQ;AAE7D,OAAO,MAAMC,oBAAoB,GAC/BF,KAAc,IACuB;EACrC,IAAID,qBAAqB,CAACC,KAAK,CAAC,IAAIA,KAAK,CAACC,OAAO,KAAK,IAAI,EAAE;IAC1D,MAAME,QAAQ,GAAGH,KAAK,CAACC,OAAO;IAC9B;IACA,OAAQD,KAAK,CAA0BC,OAAO;IAC9C,OAAOE,QAAQ;EACjB;EAEA,OAAOC,SAAS;AAClB,CAAC;AAED,OAAO,MAAMC,yBAAyB,GAAGA,CACvCF,QAA8B,EAC9BG,YAAsB,MACU;EAChCA,YAAY;EACZC,UAAU,EAAEJ,QAAQ,CAACI,UAAU,CAACC,GAAG,CAAEC,SAAS,KAAM;IAClDC,SAAS,EAAED,SAAS,CAACC,SAAS,CAC3BC,MAAM,CAAEC,QAAQ,IAAK,CAACd,6BAA6B,CAACc,QAAQ,CAAC,CAAC,CAC9DJ,GAAG,CAAC,CAAC,CAACK,IAAI,EAAEC,IAAI,CAAC,KAAK,CAACD,IAAI,EAAEC,IAAI,CAAa,CAAC;IAClDC,SAAS,EAAEN,SAAS,CAACM,SAAS;IAC9BC,WAAW,EAAEP,SAAS,CAACO,WAAW;IAClCC,KAAK,EAAER,SAAS,CAACS,QAAQ,EAAED,KAAK,IAAI;EACtC,CAAC,CAAC,CAAC;EACHE,YAAY,EAAE,CAAC,GAAGhB,QAAQ,CAACgB,YAAY,CAAC;EACxCC,KAAK,EAAE;IAAE,GAAGjB,QAAQ,CAACiB;EAAM;AAC7B,CAAC,CAAC;AAEF,OAAO,MAAMC,uBAAuB,GAAGA,CACrClB,QAAoC,EACpCmB,OAAyD,MAC/B;EAC1B,GAAGnB,QAAQ;EACX,GAAGmB,OAAO;EACVC,OAAO,EAAE;AACX,CAAC,CAAC;AAEF,OAAO,MAAMC,0BAA0B,GACrCC,QAA8B,IACnB,GAAGC,IAAI,CAACC,SAAS,CAACF,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI","ignoreList":[]}
|
package/lib/index.js
CHANGED
|
@@ -8,8 +8,12 @@ var _exportNames = {
|
|
|
8
8
|
createFileReporter: true,
|
|
9
9
|
babelTransformPlugin: true,
|
|
10
10
|
preeval: true,
|
|
11
|
+
createTransformManifest: true,
|
|
11
12
|
getTransformMetadata: true,
|
|
13
|
+
stringifyTransformManifest: true,
|
|
14
|
+
toTransformResultMetadata: true,
|
|
12
15
|
withTransformMetadata: true,
|
|
16
|
+
collectTransformDiagnostics: true,
|
|
13
17
|
Module: true,
|
|
14
18
|
DefaultModuleImplementation: true,
|
|
15
19
|
shaker: true,
|
|
@@ -101,12 +105,24 @@ Object.defineProperty(exports, "baseHandlers", {
|
|
|
101
105
|
return _generators.baseHandlers;
|
|
102
106
|
}
|
|
103
107
|
});
|
|
108
|
+
Object.defineProperty(exports, "collectTransformDiagnostics", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () {
|
|
111
|
+
return _TransformDiagnostics.collectTransformDiagnostics;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
104
114
|
Object.defineProperty(exports, "createFileReporter", {
|
|
105
115
|
enumerable: true,
|
|
106
116
|
get: function () {
|
|
107
117
|
return _fileReporter.createFileReporter;
|
|
108
118
|
}
|
|
109
119
|
});
|
|
120
|
+
Object.defineProperty(exports, "createTransformManifest", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _TransformMetadata.createTransformManifest;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
110
126
|
Object.defineProperty(exports, "findIdentifiers", {
|
|
111
127
|
enumerable: true,
|
|
112
128
|
get: function () {
|
|
@@ -185,12 +201,24 @@ Object.defineProperty(exports, "slugify", {
|
|
|
185
201
|
return _shared.slugify;
|
|
186
202
|
}
|
|
187
203
|
});
|
|
204
|
+
Object.defineProperty(exports, "stringifyTransformManifest", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function () {
|
|
207
|
+
return _TransformMetadata.stringifyTransformManifest;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
188
210
|
Object.defineProperty(exports, "syncResolveImports", {
|
|
189
211
|
enumerable: true,
|
|
190
212
|
get: function () {
|
|
191
213
|
return _resolveImports.syncResolveImports;
|
|
192
214
|
}
|
|
193
215
|
});
|
|
216
|
+
Object.defineProperty(exports, "toTransformResultMetadata", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function () {
|
|
219
|
+
return _TransformMetadata.toTransformResultMetadata;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
194
222
|
Object.defineProperty(exports, "transform", {
|
|
195
223
|
enumerable: true,
|
|
196
224
|
get: function () {
|
|
@@ -220,6 +248,7 @@ var _fileReporter = require("./debug/fileReporter");
|
|
|
220
248
|
var _babelTransform = _interopRequireDefault(require("./plugins/babel-transform"));
|
|
221
249
|
var _preeval = _interopRequireDefault(require("./plugins/preeval"));
|
|
222
250
|
var _TransformMetadata = require("./utils/TransformMetadata");
|
|
251
|
+
var _TransformDiagnostics = require("./utils/TransformDiagnostics");
|
|
223
252
|
var _module = require("./module");
|
|
224
253
|
var _shaker = _interopRequireDefault(require("./shaker"));
|
|
225
254
|
var _transform = require("./transform");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_shared","require","_fileReporter","_babelTransform","_interopRequireDefault","_preeval","_TransformMetadata","_module","_shaker","_transform","_UnprocessedEntrypointError","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_EvaluatedEntrypoint","_Entrypoint","_generators","_transform2","_Entrypoint2","_createStylisPreprocessor","_resolveImports","_loadWywOptions","_withDefaultServices","_EventEmitter","_isNode","_getFileIdx","_getTagProcessor","_getVisitorKeys","_peek","_cache","_findIdentifiers","e","__esModule","default"],"sources":["../src/index.ts"],"sourcesContent":["export { slugify } from '@wyw-in-js/shared';\n\nexport { createFileReporter } from './debug/fileReporter';\nexport type { IFileReporterOptions } from './debug/fileReporter';\nexport { default as babelTransformPlugin } from './plugins/babel-transform';\nexport { default as preeval } from './plugins/preeval';\nexport {\n getTransformMetadata,\n withTransformMetadata,\n} from './utils/TransformMetadata';\nexport type {
|
|
1
|
+
{"version":3,"file":"index.js","names":["_shared","require","_fileReporter","_babelTransform","_interopRequireDefault","_preeval","_TransformMetadata","_TransformDiagnostics","_module","_shaker","_transform","_UnprocessedEntrypointError","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_EvaluatedEntrypoint","_Entrypoint","_generators","_transform2","_Entrypoint2","_createStylisPreprocessor","_resolveImports","_loadWywOptions","_withDefaultServices","_EventEmitter","_isNode","_getFileIdx","_getTagProcessor","_getVisitorKeys","_peek","_cache","_findIdentifiers","e","__esModule","default"],"sources":["../src/index.ts"],"sourcesContent":["export { slugify } from '@wyw-in-js/shared';\n\nexport { createFileReporter } from './debug/fileReporter';\nexport type { IFileReporterOptions } from './debug/fileReporter';\nexport { default as babelTransformPlugin } from './plugins/babel-transform';\nexport { default as preeval } from './plugins/preeval';\nexport {\n createTransformManifest,\n getTransformMetadata,\n stringifyTransformManifest,\n toTransformResultMetadata,\n withTransformMetadata,\n} from './utils/TransformMetadata';\nexport type {\n WYWTransformManifest,\n WYWTransformMetadata,\n WYWTransformProcessorMetadata,\n WYWTransformResultMetadata,\n} from './utils/TransformMetadata';\nexport { collectTransformDiagnostics } from './utils/TransformDiagnostics';\nexport type { WYWTransformDiagnostic } from './utils/TransformDiagnostics';\nexport { Module, DefaultModuleImplementation } from './module';\nexport { default as shaker } from './shaker';\nexport { transform } from './transform';\nexport {\n isUnprocessedEntrypointError,\n UnprocessedEntrypointError,\n} from './transform/actions/UnprocessedEntrypointError';\nexport * from './types';\nexport { EvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nexport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nexport { parseFile } from './transform/Entrypoint.helpers';\nexport type { LoadAndParseFn } from './transform/Entrypoint.types';\nexport { baseHandlers } from './transform/generators';\nexport { prepareCode } from './transform/generators/transform';\nexport { Entrypoint } from './transform/Entrypoint';\nexport { transformUrl } from './transform/generators/createStylisPreprocessor';\nexport {\n asyncResolveImports,\n syncResolveImports,\n} from './transform/generators/resolveImports';\nexport { loadWywOptions } from './transform/helpers/loadWywOptions';\nexport { withDefaultServices } from './transform/helpers/withDefaultServices';\nexport type { Services } from './transform/types';\nexport { EventEmitter } from './utils/EventEmitter';\nexport type {\n EntrypointEvent,\n OnEvent,\n OnActionStartArgs,\n OnActionFinishArgs,\n} from './utils/EventEmitter';\nexport { isNode } from './utils/isNode';\nexport { getFileIdx } from './utils/getFileIdx';\nexport { applyProcessors } from './utils/getTagProcessor';\nexport { getVisitorKeys } from './utils/getVisitorKeys';\nexport type { VisitorKeys } from './utils/getVisitorKeys';\nexport { peek } from './utils/peek';\nexport { TransformCacheCollection } from './cache';\nexport { findIdentifiers } from './utils/findIdentifiers';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AiC,aAAA,GAAAjC,OAAA;AAOA,IAAAkC,OAAA,GAAAlC,OAAA;AACA,IAAAmC,WAAA,GAAAnC,OAAA;AACA,IAAAoC,gBAAA,GAAApC,OAAA;AACA,IAAAqC,eAAA,GAAArC,OAAA;AAEA,IAAAsC,KAAA,GAAAtC,OAAA;AACA,IAAAuC,MAAA,GAAAvC,OAAA;AACA,IAAAwC,gBAAA,GAAAxC,OAAA;AAA0D,SAAAG,uBAAAsC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/transform/actions/types.ts"],"sourcesContent":["import type { BabelFileResult } from '@babel/core';\n\nimport type { Replacements, Rules } from '@wyw-in-js/shared';\n\nexport interface IExtracted {\n cssSourceMapText: string;\n cssText: string;\n replacements: Replacements;\n rules: Rules;\n}\n\nexport interface IWorkflowActionNonLinariaResult {\n code: string;\n sourceMap: BabelFileResult['map'];\n}\n\nexport interface IWorkflowActionLinariaResult\n extends IExtracted,\n IWorkflowActionNonLinariaResult {\n dependencies: string[];\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/transform/actions/types.ts"],"sourcesContent":["import type { BabelFileResult } from '@babel/core';\n\nimport type { Replacements, Rules } from '@wyw-in-js/shared';\n\nimport type { WYWTransformDiagnostic } from '../../utils/TransformDiagnostics';\nimport type { WYWTransformResultMetadata } from '../../utils/TransformMetadata';\n\nexport interface IExtracted {\n cssSourceMapText: string;\n cssText: string;\n replacements: Replacements;\n rules: Rules;\n}\n\nexport interface IWorkflowActionNonLinariaResult {\n code: string;\n sourceMap: BabelFileResult['map'];\n}\n\nexport interface IWorkflowActionLinariaResult\n extends IExtracted,\n IWorkflowActionNonLinariaResult {\n dependencies: string[];\n diagnostics?: WYWTransformDiagnostic[];\n metadata?: WYWTransformResultMetadata;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.workflow = workflow;
|
|
7
7
|
var _AbortError = require("../actions/AbortError");
|
|
8
|
+
var _TransformDiagnostics = require("../../utils/TransformDiagnostics");
|
|
9
|
+
var _TransformMetadata = require("../../utils/TransformMetadata");
|
|
8
10
|
/**
|
|
9
11
|
* The entry point for file processing. Sequentially calls `processEntrypoint`,
|
|
10
12
|
* `evalFile`, `collect`, and `extract`. Returns the result of transforming
|
|
@@ -73,6 +75,8 @@ function* workflow() {
|
|
|
73
75
|
sourceMap: collectStageResult.map
|
|
74
76
|
};
|
|
75
77
|
}
|
|
78
|
+
const metadata = options.pluginOptions.outputMetadata ? (0, _TransformMetadata.toTransformResultMetadata)(collectStageResult.metadata, dependencies) : null;
|
|
79
|
+
const diagnostics = (0, _TransformDiagnostics.collectTransformDiagnostics)(entrypoint.name, collectStageResult.metadata.processors);
|
|
76
80
|
|
|
77
81
|
// *** 4th stage
|
|
78
82
|
|
|
@@ -83,6 +87,12 @@ function* workflow() {
|
|
|
83
87
|
...extractStageResult,
|
|
84
88
|
code: (_collectStageResult$c = collectStageResult.code) !== null && _collectStageResult$c !== void 0 ? _collectStageResult$c : '',
|
|
85
89
|
dependencies,
|
|
90
|
+
...(diagnostics.length > 0 ? {
|
|
91
|
+
diagnostics
|
|
92
|
+
} : {}),
|
|
93
|
+
...(metadata ? {
|
|
94
|
+
metadata
|
|
95
|
+
} : {}),
|
|
86
96
|
replacements: [...extractStageResult.replacements, ...collectStageResult.metadata.replacements],
|
|
87
97
|
sourceMap: collectStageResult.map
|
|
88
98
|
};
|
|
@@ -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","hasWywMetadata","generation","delete","name","evalStageResult","valueCache","dependencies","collectStageResult","metadata","map","
|
|
1
|
+
{"version":3,"file":"workflow.js","names":["_AbortError","require","_TransformDiagnostics","_TransformMetadata","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","pluginOptions","outputMetadata","toTransformResultMetadata","diagnostics","collectTransformDiagnostics","processors","extractStageResult","length","replacements"],"sources":["../../../src/transform/generators/workflow.ts"],"sourcesContent":["import { isAborted } from '../actions/AbortError';\nimport type { IWorkflowAction, SyncScenarioForAction } from '../types';\nimport { collectTransformDiagnostics } from '../../utils/TransformDiagnostics';\nimport { toTransformResultMetadata } from '../../utils/TransformMetadata';\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 const metadata = options.pluginOptions.outputMetadata\n ? toTransformResultMetadata(collectStageResult.metadata, dependencies)\n : null;\n const diagnostics = collectTransformDiagnostics(\n entrypoint.name,\n collectStageResult.metadata.processors\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 ...(diagnostics.length > 0 ? { diagnostics } : {}),\n ...(metadata ? { metadata } : {}),\n replacements: [\n ...extractStageResult.replacements,\n ...collectStageResult.metadata.replacements,\n ],\n sourceMap: collectStageResult.map,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACO,UAAUG,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,OAA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B,kBAAkB,CAACE;EAChC,CAAC;AACH","ignoreList":[]}
|
|
@@ -48,6 +48,7 @@ function loadWywOptions(overrides = defaultOverrides) {
|
|
|
48
48
|
displayName: false,
|
|
49
49
|
evaluate: true,
|
|
50
50
|
extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],
|
|
51
|
+
outputMetadata: false,
|
|
51
52
|
rules: rules !== null && rules !== void 0 ? rules : [{
|
|
52
53
|
action: _shaker.shaker
|
|
53
54
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadWywOptions.js","names":["_cosmiconfig","require","_shaker","searchPlaces","explorerSync","cosmiconfigSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","defaultImportLoaders","raw","url","loadWywOptions","overrides","_result$config","has","get","configFile","ignore","rules","babelOptions","importLoaders","overridesImportLoaders","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","useWeakRefInEval","config","configImportLoaders","configFeatures","features","options","displayName","evaluate","extensions","action","shaker","test","filename","code","highPriorityPlugins","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type {\n FeatureFlags,\n ImportLoaders,\n StrictOptions,\n} 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[\\\\/]/;\nconst defaultImportLoaders: ImportLoaders = {\n raw: 'raw',\n url: 'url',\n};\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const {\n configFile,\n ignore,\n rules,\n babelOptions = {},\n importLoaders: overridesImportLoaders,\n ...rest\n } = 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 useWeakRefInEval: true,\n };\n\n const config = (result?.config ?? {}) as Partial<StrictOptions>;\n const configImportLoaders = config.importLoaders;\n const configFeatures = config.features;\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 ...config,\n ...rest,\n importLoaders: {\n ...defaultImportLoaders,\n ...(configImportLoaders ?? {}),\n ...(overridesImportLoaders ?? {}),\n },\n features: {\n ...defaultFeatures,\n ...(configFeatures ?? {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAQA,IAAAC,OAAA,GAAAD,OAAA;AAGA,MAAME,YAAY,GAAG,CACnB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,CACvB;AAED,MAAMC,YAAY,GAAG,IAAAC,4BAAe,EAAC,WAAW,EAAE;EAAEF;AAAa,CAAC,CAAC;AAMnE,MAAMG,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAClD,MAAMC,oBAAmC,GAAG;EAC1CC,GAAG,EAAE,KAAK;EACVC,GAAG,EAAE;AACP,CAAC;AAEM,SAASC,cAAcA,CAC5BC,SAAyB,GAAGN,gBAAgB,EAC7B;EAAA,IAAAO,cAAA;EACf,IAAIT,KAAK,CAACU,GAAG,CAACF,SAAS,CAAC,EAAE;IACxB,OAAOR,KAAK,CAACW,GAAG,CAACH,SAAS,CAAC;EAC7B;EAEA,MAAM;IACJI,UAAU;IACVC,MAAM;IACNC,KAAK;IACLC,YAAY,GAAG,CAAC,CAAC;IACjBC,aAAa,EAAEC,sBAAsB;IACrC,GAAGC;EACL,CAAC,GAAGV,SAAS;EAEb,MAAMW,MAAM;EACV;EACAP,UAAU,KAAK,KAAK,GAChBQ,SAAS,GACTR,UAAU,KAAKQ,SAAS,GACxBtB,YAAY,CAACuB,IAAI,CAACT,UAAU,CAAC,GAC7Bd,YAAY,CAACwB,MAAM,CAAC,CAAC;EAE3B,MAAMC,eAA6B,GAAG;IACpCC,oBAAoB,EAAE,IAAI;IAC1BC,WAAW,EAAE,IAAI;IACjBC,QAAQ,EAAE,IAAI;IACdC,UAAU,EAAE,KAAK;IACjBC,eAAe,EAAE,IAAI;IACrBC,gBAAgB,EAAE;EACpB,CAAC;EAED,MAAMC,MAAM,IAAArB,cAAA,GAAIU,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEW,MAAM,cAAArB,cAAA,cAAAA,cAAA,GAAI,CAAC,CAA4B;EAC/D,MAAMsB,mBAAmB,GAAGD,MAAM,CAACd,aAAa;EAChD,MAAMgB,cAAc,GAAGF,MAAM,CAACG,QAAQ;EAEtC,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;
|
|
1
|
+
{"version":3,"file":"loadWywOptions.js","names":["_cosmiconfig","require","_shaker","searchPlaces","explorerSync","cosmiconfigSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","defaultImportLoaders","raw","url","loadWywOptions","overrides","_result$config","has","get","configFile","ignore","rules","babelOptions","importLoaders","overridesImportLoaders","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","useWeakRefInEval","config","configImportLoaders","configFeatures","features","options","displayName","evaluate","extensions","outputMetadata","action","shaker","test","filename","code","highPriorityPlugins","set"],"sources":["../../../src/transform/helpers/loadWywOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type {\n FeatureFlags,\n ImportLoaders,\n StrictOptions,\n} 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[\\\\/]/;\nconst defaultImportLoaders: ImportLoaders = {\n raw: 'raw',\n url: 'url',\n};\n\nexport function loadWywOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const {\n configFile,\n ignore,\n rules,\n babelOptions = {},\n importLoaders: overridesImportLoaders,\n ...rest\n } = 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 useWeakRefInEval: true,\n };\n\n const config = (result?.config ?? {}) as Partial<StrictOptions>;\n const configImportLoaders = config.importLoaders;\n const configFeatures = config.features;\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n outputMetadata: false,\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 ...config,\n ...rest,\n importLoaders: {\n ...defaultImportLoaders,\n ...(configImportLoaders ?? {}),\n ...(overridesImportLoaders ?? {}),\n },\n features: {\n ...defaultFeatures,\n ...(configFeatures ?? {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAQA,IAAAC,OAAA,GAAAD,OAAA;AAGA,MAAME,YAAY,GAAG,CACnB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,CACvB;AAED,MAAMC,YAAY,GAAG,IAAAC,4BAAe,EAAC,WAAW,EAAE;EAAEF;AAAa,CAAC,CAAC;AAMnE,MAAMG,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAClD,MAAMC,oBAAmC,GAAG;EAC1CC,GAAG,EAAE,KAAK;EACVC,GAAG,EAAE;AACP,CAAC;AAEM,SAASC,cAAcA,CAC5BC,SAAyB,GAAGN,gBAAgB,EAC7B;EAAA,IAAAO,cAAA;EACf,IAAIT,KAAK,CAACU,GAAG,CAACF,SAAS,CAAC,EAAE;IACxB,OAAOR,KAAK,CAACW,GAAG,CAACH,SAAS,CAAC;EAC7B;EAEA,MAAM;IACJI,UAAU;IACVC,MAAM;IACNC,KAAK;IACLC,YAAY,GAAG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,OAAO,KAAK;QACd;;QAEA;QACA,OAAO,0CAA0C,CAACD,IAAI,CAACE,IAAI,CAAC;MAC9D,CAAC;MACDJ,MAAM,EAAEC;IACV,CAAC,CACF;IACDzB,YAAY;IACZ6B,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;IACxC,GAAGd,MAAM;IACT,GAAGZ,IAAI;IACPF,aAAa,EAAE;MACb,GAAGZ,oBAAoB;MACvB,IAAI2B,mBAAmB,aAAnBA,mBAAmB,cAAnBA,mBAAmB,GAAI,CAAC,CAAC,CAAC;MAC9B,IAAId,sBAAsB,aAAtBA,sBAAsB,cAAtBA,sBAAsB,GAAI,CAAC,CAAC;IAClC,CAAC;IACDgB,QAAQ,EAAE;MACR,GAAGV,eAAe;MAClB,IAAIS,cAAc,aAAdA,cAAc,cAAdA,cAAc,GAAI,CAAC,CAAC,CAAC;MACzB,GAAGd,IAAI,CAACe;IACV;EACF,CAAC;EAEDjC,KAAK,CAAC6C,GAAG,CAACrC,SAAS,EAAE0B,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB","ignoreList":[]}
|
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 {
|
|
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 {\n WYWTransformMetadata,\n WYWTransformResultMetadata,\n} from './utils/TransformMetadata';\nimport type { WYWTransformDiagnostic } from './utils/TransformDiagnostics';\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 diagnostics?: WYWTransformDiagnostic[];\n metadata?: WYWTransformResultMetadata;\n replacements?: Replacement[];\n rules?: Rules;\n sourceMap?: RawSourceMap | null;\n};\n\nexport type Options = {\n filename: string;\n inputSourceMap?: RawSourceMap;\n keepComments?: boolean | RegExp;\n outputFilename?: string;\n pluginOptions?: Partial<PluginOptions>;\n prefixer?: boolean;\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":"","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.collectTransformDiagnostics = void 0;
|
|
7
|
+
var _processorUtils = require("@wyw-in-js/processor-utils");
|
|
8
|
+
const collectTransformDiagnostics = (filename, processors) => processors.flatMap(processor => processor.artifacts.filter(_processorUtils.isProcessorDiagnosticArtifact).map(([, diagnostic]) => {
|
|
9
|
+
var _diagnostic$end, _diagnostic$start;
|
|
10
|
+
return {
|
|
11
|
+
...diagnostic,
|
|
12
|
+
className: processor.className,
|
|
13
|
+
displayName: processor.displayName,
|
|
14
|
+
end: (_diagnostic$end = diagnostic.end) !== null && _diagnostic$end !== void 0 ? _diagnostic$end : null,
|
|
15
|
+
filename,
|
|
16
|
+
start: (_diagnostic$start = diagnostic.start) !== null && _diagnostic$start !== void 0 ? _diagnostic$start : null
|
|
17
|
+
};
|
|
18
|
+
}));
|
|
19
|
+
exports.collectTransformDiagnostics = collectTransformDiagnostics;
|
|
20
|
+
//# sourceMappingURL=TransformDiagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransformDiagnostics.js","names":["_processorUtils","require","collectTransformDiagnostics","filename","processors","flatMap","processor","artifacts","filter","isProcessorDiagnosticArtifact","map","diagnostic","_diagnostic$end","_diagnostic$start","className","displayName","end","start","exports"],"sources":["../../src/utils/TransformDiagnostics.ts"],"sourcesContent":["import type {\n BaseProcessor,\n ProcessorDiagnostic,\n} from '@wyw-in-js/processor-utils';\nimport { isProcessorDiagnosticArtifact } from '@wyw-in-js/processor-utils';\n\ntype DiagnosticProcessor = Pick<\n BaseProcessor,\n 'artifacts' | 'className' | 'displayName'\n>;\n\nexport type WYWTransformDiagnostic = ProcessorDiagnostic & {\n className: string;\n displayName: string;\n filename: string;\n};\n\nexport const collectTransformDiagnostics = (\n filename: string,\n processors: DiagnosticProcessor[]\n): WYWTransformDiagnostic[] =>\n processors.flatMap((processor) =>\n processor.artifacts\n .filter(isProcessorDiagnosticArtifact)\n .map(([, diagnostic]) => ({\n ...diagnostic,\n className: processor.className,\n displayName: processor.displayName,\n end: diagnostic.end ?? null,\n filename,\n start: diagnostic.start ?? null,\n }))\n );\n"],"mappings":";;;;;;AAIA,IAAAA,eAAA,GAAAC,OAAA;AAaO,MAAMC,2BAA2B,GAAGA,CACzCC,QAAgB,EAChBC,UAAiC,KAEjCA,UAAU,CAACC,OAAO,CAAEC,SAAS,IAC3BA,SAAS,CAACC,SAAS,CAChBC,MAAM,CAACC,6CAA6B,CAAC,CACrCC,GAAG,CAAC,CAAC,GAAGC,UAAU,CAAC;EAAA,IAAAC,eAAA,EAAAC,iBAAA;EAAA,OAAM;IACxB,GAAGF,UAAU;IACbG,SAAS,EAAER,SAAS,CAACQ,SAAS;IAC9BC,WAAW,EAAET,SAAS,CAACS,WAAW;IAClCC,GAAG,GAAAJ,eAAA,GAAED,UAAU,CAACK,GAAG,cAAAJ,eAAA,cAAAA,eAAA,GAAI,IAAI;IAC3BT,QAAQ;IACRc,KAAK,GAAAJ,iBAAA,GAAEF,UAAU,CAACM,KAAK,cAAAJ,iBAAA,cAAAA,iBAAA,GAAI;EAC7B,CAAC;AAAA,CAAC,CACN,CAAC;AAACK,OAAA,CAAAhB,2BAAA,GAAAA,2BAAA","ignoreList":[]}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.withTransformMetadata = exports.getTransformMetadata = void 0;
|
|
6
|
+
exports.withTransformMetadata = exports.toTransformResultMetadata = exports.stringifyTransformManifest = exports.getTransformMetadata = exports.createTransformManifest = void 0;
|
|
7
|
+
var _processorUtils = require("@wyw-in-js/processor-utils");
|
|
7
8
|
const withTransformMetadata = value => typeof value === 'object' && value !== null && typeof value.wywInJS === 'object';
|
|
8
9
|
exports.withTransformMetadata = withTransformMetadata;
|
|
9
10
|
const getTransformMetadata = value => {
|
|
@@ -16,4 +17,29 @@ const getTransformMetadata = value => {
|
|
|
16
17
|
return undefined;
|
|
17
18
|
};
|
|
18
19
|
exports.getTransformMetadata = getTransformMetadata;
|
|
20
|
+
const toTransformResultMetadata = (metadata, dependencies) => ({
|
|
21
|
+
dependencies,
|
|
22
|
+
processors: metadata.processors.map(processor => {
|
|
23
|
+
var _processor$location$s, _processor$location;
|
|
24
|
+
return {
|
|
25
|
+
artifacts: processor.artifacts.filter(artifact => !(0, _processorUtils.isProcessorDiagnosticArtifact)(artifact)).map(([type, data]) => [type, data]),
|
|
26
|
+
className: processor.className,
|
|
27
|
+
displayName: processor.displayName,
|
|
28
|
+
start: (_processor$location$s = (_processor$location = processor.location) === null || _processor$location === void 0 ? void 0 : _processor$location.start) !== null && _processor$location$s !== void 0 ? _processor$location$s : null
|
|
29
|
+
};
|
|
30
|
+
}),
|
|
31
|
+
replacements: [...metadata.replacements],
|
|
32
|
+
rules: {
|
|
33
|
+
...metadata.rules
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
exports.toTransformResultMetadata = toTransformResultMetadata;
|
|
37
|
+
const createTransformManifest = (metadata, context) => ({
|
|
38
|
+
...metadata,
|
|
39
|
+
...context,
|
|
40
|
+
version: 1
|
|
41
|
+
});
|
|
42
|
+
exports.createTransformManifest = createTransformManifest;
|
|
43
|
+
const stringifyTransformManifest = manifest => `${JSON.stringify(manifest, null, 2)}\n`;
|
|
44
|
+
exports.stringifyTransformManifest = stringifyTransformManifest;
|
|
19
45
|
//# sourceMappingURL=TransformMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransformMetadata.js","names":["withTransformMetadata","value","wywInJS","exports","getTransformMetadata","metadata","undefined"],"sources":["../../src/utils/TransformMetadata.ts"],"sourcesContent":["import type { Artifact, Replacement, Rules } from '@wyw-in-js/shared';\n\nexport type WYWTransformMetadata = {\n dependencies: string[];\n processors: {
|
|
1
|
+
{"version":3,"file":"TransformMetadata.js","names":["_processorUtils","require","withTransformMetadata","value","wywInJS","exports","getTransformMetadata","metadata","undefined","toTransformResultMetadata","dependencies","processors","map","processor","_processor$location$s","_processor$location","artifacts","filter","artifact","isProcessorDiagnosticArtifact","type","data","className","displayName","start","location","replacements","rules","createTransformManifest","context","version","stringifyTransformManifest","manifest","JSON","stringify"],"sources":["../../src/utils/TransformMetadata.ts"],"sourcesContent":["import type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport { isProcessorDiagnosticArtifact } from '@wyw-in-js/processor-utils';\nimport type { Artifact, Location, Replacement, Rules } from '@wyw-in-js/shared';\n\ntype TransformMetadataProcessor = Pick<\n BaseProcessor,\n 'artifacts' | 'className' | 'displayName' | 'location'\n>;\n\nexport type WYWTransformMetadata = {\n dependencies: string[];\n processors: TransformMetadataProcessor[];\n replacements: Replacement[];\n rules: Rules;\n};\n\nexport type WYWTransformProcessorMetadata = {\n artifacts: Artifact[];\n className: string;\n displayName: string;\n start: Location | null | undefined;\n};\n\nexport type WYWTransformResultMetadata = Omit<\n WYWTransformMetadata,\n 'processors'\n> & {\n processors: WYWTransformProcessorMetadata[];\n};\n\nexport type WYWTransformManifest = WYWTransformResultMetadata & {\n cssFile?: string;\n source: string;\n version: 1;\n};\n\nexport const withTransformMetadata = (\n value: unknown\n): value is { wywInJS: WYWTransformMetadata } =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { wywInJS: unknown }).wywInJS === 'object';\n\nexport const getTransformMetadata = (\n value: unknown\n): WYWTransformMetadata | undefined => {\n if (withTransformMetadata(value) && value.wywInJS !== null) {\n const metadata = value.wywInJS;\n // eslint-disable-next-line no-param-reassign\n delete (value as { wywInJS: unknown }).wywInJS;\n return metadata;\n }\n\n return undefined;\n};\n\nexport const toTransformResultMetadata = (\n metadata: WYWTransformMetadata,\n dependencies: string[]\n): WYWTransformResultMetadata => ({\n dependencies,\n processors: metadata.processors.map((processor) => ({\n artifacts: processor.artifacts\n .filter((artifact) => !isProcessorDiagnosticArtifact(artifact))\n .map(([type, data]) => [type, data] as Artifact),\n className: processor.className,\n displayName: processor.displayName,\n start: processor.location?.start ?? null,\n })),\n replacements: [...metadata.replacements],\n rules: { ...metadata.rules },\n});\n\nexport const createTransformManifest = (\n metadata: WYWTransformResultMetadata,\n context: Pick<WYWTransformManifest, 'cssFile' | 'source'>\n): WYWTransformManifest => ({\n ...metadata,\n ...context,\n version: 1,\n});\n\nexport const stringifyTransformManifest = (\n manifest: WYWTransformManifest\n): string => `${JSON.stringify(manifest, null, 2)}\\n`;\n"],"mappings":";;;;;;AACA,IAAAA,eAAA,GAAAC,OAAA;AAmCO,MAAMC,qBAAqB,GAChCC,KAAc,IAEd,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAA0BC,OAAO,KAAK,QAAQ;AAACC,OAAA,CAAAH,qBAAA,GAAAA,qBAAA;AAEvD,MAAMI,oBAAoB,GAC/BH,KAAc,IACuB;EACrC,IAAID,qBAAqB,CAACC,KAAK,CAAC,IAAIA,KAAK,CAACC,OAAO,KAAK,IAAI,EAAE;IAC1D,MAAMG,QAAQ,GAAGJ,KAAK,CAACC,OAAO;IAC9B;IACA,OAAQD,KAAK,CAA0BC,OAAO;IAC9C,OAAOG,QAAQ;EACjB;EAEA,OAAOC,SAAS;AAClB,CAAC;AAACH,OAAA,CAAAC,oBAAA,GAAAA,oBAAA;AAEK,MAAMG,yBAAyB,GAAGA,CACvCF,QAA8B,EAC9BG,YAAsB,MACU;EAChCA,YAAY;EACZC,UAAU,EAAEJ,QAAQ,CAACI,UAAU,CAACC,GAAG,CAAEC,SAAS;IAAA,IAAAC,qBAAA,EAAAC,mBAAA;IAAA,OAAM;MAClDC,SAAS,EAAEH,SAAS,CAACG,SAAS,CAC3BC,MAAM,CAAEC,QAAQ,IAAK,CAAC,IAAAC,6CAA6B,EAACD,QAAQ,CAAC,CAAC,CAC9DN,GAAG,CAAC,CAAC,CAACQ,IAAI,EAAEC,IAAI,CAAC,KAAK,CAACD,IAAI,EAAEC,IAAI,CAAa,CAAC;MAClDC,SAAS,EAAET,SAAS,CAACS,SAAS;MAC9BC,WAAW,EAAEV,SAAS,CAACU,WAAW;MAClCC,KAAK,GAAAV,qBAAA,IAAAC,mBAAA,GAAEF,SAAS,CAACY,QAAQ,cAAAV,mBAAA,uBAAlBA,mBAAA,CAAoBS,KAAK,cAAAV,qBAAA,cAAAA,qBAAA,GAAI;IACtC,CAAC;EAAA,CAAC,CAAC;EACHY,YAAY,EAAE,CAAC,GAAGnB,QAAQ,CAACmB,YAAY,CAAC;EACxCC,KAAK,EAAE;IAAE,GAAGpB,QAAQ,CAACoB;EAAM;AAC7B,CAAC,CAAC;AAACtB,OAAA,CAAAI,yBAAA,GAAAA,yBAAA;AAEI,MAAMmB,uBAAuB,GAAGA,CACrCrB,QAAoC,EACpCsB,OAAyD,MAC/B;EAC1B,GAAGtB,QAAQ;EACX,GAAGsB,OAAO;EACVC,OAAO,EAAE;AACX,CAAC,CAAC;AAACzB,OAAA,CAAAuB,uBAAA,GAAAA,uBAAA;AAEI,MAAMG,0BAA0B,GACrCC,QAA8B,IACnB,GAAGC,IAAI,CAACC,SAAS,CAACF,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI;AAAC3B,OAAA,CAAA0B,0BAAA,GAAAA,0BAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/transform",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@babel/core": "^7.23.5",
|
|
6
6
|
"@babel/generator": "^7.23.5",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"@babel/template": "^7.22.15",
|
|
10
10
|
"@babel/traverse": "^7.23.5",
|
|
11
11
|
"@babel/types": "^7.23.5",
|
|
12
|
-
"@wyw-in-js/processor-utils": "1.0
|
|
13
|
-
"@wyw-in-js/shared": "1.0
|
|
12
|
+
"@wyw-in-js/processor-utils": "1.1.0",
|
|
13
|
+
"@wyw-in-js/shared": "1.1.0",
|
|
14
14
|
"cosmiconfig": "^8.0.0",
|
|
15
15
|
"happy-dom": "^20.1.0",
|
|
16
16
|
"minimatch": "^9.0.5",
|
package/types/index.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ export { createFileReporter } from './debug/fileReporter';
|
|
|
3
3
|
export type { IFileReporterOptions } from './debug/fileReporter';
|
|
4
4
|
export { default as babelTransformPlugin } from './plugins/babel-transform';
|
|
5
5
|
export { default as preeval } from './plugins/preeval';
|
|
6
|
-
export { getTransformMetadata, withTransformMetadata, } from './utils/TransformMetadata';
|
|
7
|
-
export type { WYWTransformMetadata } from './utils/TransformMetadata';
|
|
6
|
+
export { createTransformManifest, getTransformMetadata, stringifyTransformManifest, toTransformResultMetadata, withTransformMetadata, } from './utils/TransformMetadata';
|
|
7
|
+
export type { WYWTransformManifest, WYWTransformMetadata, WYWTransformProcessorMetadata, WYWTransformResultMetadata, } from './utils/TransformMetadata';
|
|
8
|
+
export { collectTransformDiagnostics } from './utils/TransformDiagnostics';
|
|
9
|
+
export type { WYWTransformDiagnostic } from './utils/TransformDiagnostics';
|
|
8
10
|
export { Module, DefaultModuleImplementation } from './module';
|
|
9
11
|
export { default as shaker } from './shaker';
|
|
10
12
|
export { transform } from './transform';
|
package/types/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.findIdentifiers = exports.TransformCacheCollection = exports.peek = exports.getVisitorKeys = exports.applyProcessors = exports.getFileIdx = exports.isNode = exports.EventEmitter = exports.withDefaultServices = exports.loadWywOptions = exports.syncResolveImports = exports.asyncResolveImports = exports.transformUrl = exports.Entrypoint = exports.prepareCode = exports.baseHandlers = exports.parseFile = exports.EvaluatedEntrypoint = exports.UnprocessedEntrypointError = exports.isUnprocessedEntrypointError = exports.transform = exports.shaker = exports.DefaultModuleImplementation = exports.Module = exports.withTransformMetadata = exports.getTransformMetadata = exports.preeval = exports.babelTransformPlugin = exports.createFileReporter = exports.slugify = void 0;
|
|
20
|
+
exports.findIdentifiers = exports.TransformCacheCollection = exports.peek = exports.getVisitorKeys = exports.applyProcessors = exports.getFileIdx = exports.isNode = exports.EventEmitter = exports.withDefaultServices = exports.loadWywOptions = exports.syncResolveImports = exports.asyncResolveImports = exports.transformUrl = exports.Entrypoint = exports.prepareCode = exports.baseHandlers = exports.parseFile = exports.EvaluatedEntrypoint = exports.UnprocessedEntrypointError = exports.isUnprocessedEntrypointError = exports.transform = exports.shaker = exports.DefaultModuleImplementation = exports.Module = exports.collectTransformDiagnostics = exports.withTransformMetadata = exports.toTransformResultMetadata = exports.stringifyTransformManifest = exports.getTransformMetadata = exports.createTransformManifest = exports.preeval = exports.babelTransformPlugin = exports.createFileReporter = exports.slugify = void 0;
|
|
21
21
|
var shared_1 = require("@wyw-in-js/shared");
|
|
22
22
|
Object.defineProperty(exports, "slugify", { enumerable: true, get: function () { return shared_1.slugify; } });
|
|
23
23
|
var fileReporter_1 = require("./debug/fileReporter");
|
|
@@ -27,8 +27,13 @@ Object.defineProperty(exports, "babelTransformPlugin", { enumerable: true, get:
|
|
|
27
27
|
var preeval_1 = require("./plugins/preeval");
|
|
28
28
|
Object.defineProperty(exports, "preeval", { enumerable: true, get: function () { return __importDefault(preeval_1).default; } });
|
|
29
29
|
var TransformMetadata_1 = require("./utils/TransformMetadata");
|
|
30
|
+
Object.defineProperty(exports, "createTransformManifest", { enumerable: true, get: function () { return TransformMetadata_1.createTransformManifest; } });
|
|
30
31
|
Object.defineProperty(exports, "getTransformMetadata", { enumerable: true, get: function () { return TransformMetadata_1.getTransformMetadata; } });
|
|
32
|
+
Object.defineProperty(exports, "stringifyTransformManifest", { enumerable: true, get: function () { return TransformMetadata_1.stringifyTransformManifest; } });
|
|
33
|
+
Object.defineProperty(exports, "toTransformResultMetadata", { enumerable: true, get: function () { return TransformMetadata_1.toTransformResultMetadata; } });
|
|
31
34
|
Object.defineProperty(exports, "withTransformMetadata", { enumerable: true, get: function () { return TransformMetadata_1.withTransformMetadata; } });
|
|
35
|
+
var TransformDiagnostics_1 = require("./utils/TransformDiagnostics");
|
|
36
|
+
Object.defineProperty(exports, "collectTransformDiagnostics", { enumerable: true, get: function () { return TransformDiagnostics_1.collectTransformDiagnostics; } });
|
|
32
37
|
var module_1 = require("./module");
|
|
33
38
|
Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return module_1.Module; } });
|
|
34
39
|
Object.defineProperty(exports, "DefaultModuleImplementation", { enumerable: true, get: function () { return module_1.DefaultModuleImplementation; } });
|
|
@@ -12,7 +12,10 @@ export declare const filename: string;
|
|
|
12
12
|
export declare function collector(file: BabelFile, options: Pick<StrictOptions, 'classNameSlug' | 'displayName' | 'extensions' | 'evaluate' | 'tagResolver'> & {
|
|
13
13
|
eventEmitter?: EventEmitter;
|
|
14
14
|
}, values: ValueCache): {
|
|
15
|
-
artifacts: import("@wyw-in-js/shared").Artifact[];
|
|
15
|
+
readonly artifacts: import("@wyw-in-js/shared").Artifact[];
|
|
16
|
+
readonly className: string;
|
|
17
|
+
readonly displayName: string;
|
|
18
|
+
readonly location: import("@babel/types").SourceLocation | null;
|
|
16
19
|
}[];
|
|
17
20
|
export default function collectorPlugin(babel: Core, options: StrictOptions & {
|
|
18
21
|
eventEmitter?: EventEmitter;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { BabelFileResult } from '@babel/core';
|
|
2
2
|
import type { Replacements, Rules } from '@wyw-in-js/shared';
|
|
3
|
+
import type { WYWTransformDiagnostic } from '../../utils/TransformDiagnostics';
|
|
4
|
+
import type { WYWTransformResultMetadata } from '../../utils/TransformMetadata';
|
|
3
5
|
export interface IExtracted {
|
|
4
6
|
cssSourceMapText: string;
|
|
5
7
|
cssText: string;
|
|
@@ -12,4 +14,6 @@ export interface IWorkflowActionNonLinariaResult {
|
|
|
12
14
|
}
|
|
13
15
|
export interface IWorkflowActionLinariaResult extends IExtracted, IWorkflowActionNonLinariaResult {
|
|
14
16
|
dependencies: string[];
|
|
17
|
+
diagnostics?: WYWTransformDiagnostic[];
|
|
18
|
+
metadata?: WYWTransformResultMetadata;
|
|
15
19
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.workflow = workflow;
|
|
4
4
|
const AbortError_1 = require("../actions/AbortError");
|
|
5
|
+
const TransformDiagnostics_1 = require("../../utils/TransformDiagnostics");
|
|
6
|
+
const TransformMetadata_1 = require("../../utils/TransformMetadata");
|
|
5
7
|
/**
|
|
6
8
|
* The entry point for file processing. Sequentially calls `processEntrypoint`,
|
|
7
9
|
* `evalFile`, `collect`, and `extract`. Returns the result of transforming
|
|
@@ -59,6 +61,10 @@ function* workflow() {
|
|
|
59
61
|
sourceMap: collectStageResult.map,
|
|
60
62
|
};
|
|
61
63
|
}
|
|
64
|
+
const metadata = options.pluginOptions.outputMetadata
|
|
65
|
+
? (0, TransformMetadata_1.toTransformResultMetadata)(collectStageResult.metadata, dependencies)
|
|
66
|
+
: null;
|
|
67
|
+
const diagnostics = (0, TransformDiagnostics_1.collectTransformDiagnostics)(entrypoint.name, collectStageResult.metadata.processors);
|
|
62
68
|
// *** 4th stage
|
|
63
69
|
const extractStageResult = yield* this.getNext('extract', entrypoint, {
|
|
64
70
|
processors: collectStageResult.metadata.processors,
|
|
@@ -67,6 +73,8 @@ function* workflow() {
|
|
|
67
73
|
...extractStageResult,
|
|
68
74
|
code: collectStageResult.code ?? '',
|
|
69
75
|
dependencies,
|
|
76
|
+
...(diagnostics.length > 0 ? { diagnostics } : {}),
|
|
77
|
+
...(metadata ? { metadata } : {}),
|
|
70
78
|
replacements: [
|
|
71
79
|
...extractStageResult.replacements,
|
|
72
80
|
...collectStageResult.metadata.replacements,
|
package/types/types.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import type { File, Program } from '@babel/types';
|
|
|
4
4
|
import type { RawSourceMap } from 'source-map';
|
|
5
5
|
import type { BaseProcessor } from '@wyw-in-js/processor-utils';
|
|
6
6
|
import type { Debugger, Replacement, Rules, StrictOptions } from '@wyw-in-js/shared';
|
|
7
|
-
import type { WYWTransformMetadata } from './utils/TransformMetadata';
|
|
7
|
+
import type { WYWTransformMetadata, WYWTransformResultMetadata } from './utils/TransformMetadata';
|
|
8
|
+
import type { WYWTransformDiagnostic } from './utils/TransformDiagnostics';
|
|
8
9
|
export type PluginOptions = StrictOptions & {
|
|
9
10
|
configFile?: string | false;
|
|
10
11
|
stage?: Stage;
|
|
@@ -36,6 +37,8 @@ export type Result = {
|
|
|
36
37
|
cssSourceMapText?: string;
|
|
37
38
|
cssText?: string;
|
|
38
39
|
dependencies?: string[];
|
|
40
|
+
diagnostics?: WYWTransformDiagnostic[];
|
|
41
|
+
metadata?: WYWTransformResultMetadata;
|
|
39
42
|
replacements?: Replacement[];
|
|
40
43
|
rules?: Rules;
|
|
41
44
|
sourceMap?: RawSourceMap | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BaseProcessor, ProcessorDiagnostic } from '@wyw-in-js/processor-utils';
|
|
2
|
+
type DiagnosticProcessor = Pick<BaseProcessor, 'artifacts' | 'className' | 'displayName'>;
|
|
3
|
+
export type WYWTransformDiagnostic = ProcessorDiagnostic & {
|
|
4
|
+
className: string;
|
|
5
|
+
displayName: string;
|
|
6
|
+
filename: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const collectTransformDiagnostics: (filename: string, processors: DiagnosticProcessor[]) => WYWTransformDiagnostic[];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectTransformDiagnostics = void 0;
|
|
4
|
+
const processor_utils_1 = require("@wyw-in-js/processor-utils");
|
|
5
|
+
const collectTransformDiagnostics = (filename, processors) => processors.flatMap((processor) => processor.artifacts
|
|
6
|
+
.filter(processor_utils_1.isProcessorDiagnosticArtifact)
|
|
7
|
+
.map(([, diagnostic]) => ({
|
|
8
|
+
...diagnostic,
|
|
9
|
+
className: processor.className,
|
|
10
|
+
displayName: processor.displayName,
|
|
11
|
+
end: diagnostic.end ?? null,
|
|
12
|
+
filename,
|
|
13
|
+
start: diagnostic.start ?? null,
|
|
14
|
+
})));
|
|
15
|
+
exports.collectTransformDiagnostics = collectTransformDiagnostics;
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BaseProcessor } from '@wyw-in-js/processor-utils';
|
|
2
|
+
import type { Artifact, Location, Replacement, Rules } from '@wyw-in-js/shared';
|
|
3
|
+
type TransformMetadataProcessor = Pick<BaseProcessor, 'artifacts' | 'className' | 'displayName' | 'location'>;
|
|
2
4
|
export type WYWTransformMetadata = {
|
|
3
5
|
dependencies: string[];
|
|
4
|
-
processors:
|
|
5
|
-
artifacts: Artifact[];
|
|
6
|
-
}[];
|
|
6
|
+
processors: TransformMetadataProcessor[];
|
|
7
7
|
replacements: Replacement[];
|
|
8
8
|
rules: Rules;
|
|
9
9
|
};
|
|
10
|
+
export type WYWTransformProcessorMetadata = {
|
|
11
|
+
artifacts: Artifact[];
|
|
12
|
+
className: string;
|
|
13
|
+
displayName: string;
|
|
14
|
+
start: Location | null | undefined;
|
|
15
|
+
};
|
|
16
|
+
export type WYWTransformResultMetadata = Omit<WYWTransformMetadata, 'processors'> & {
|
|
17
|
+
processors: WYWTransformProcessorMetadata[];
|
|
18
|
+
};
|
|
19
|
+
export type WYWTransformManifest = WYWTransformResultMetadata & {
|
|
20
|
+
cssFile?: string;
|
|
21
|
+
source: string;
|
|
22
|
+
version: 1;
|
|
23
|
+
};
|
|
10
24
|
export declare const withTransformMetadata: (value: unknown) => value is {
|
|
11
25
|
wywInJS: WYWTransformMetadata;
|
|
12
26
|
};
|
|
13
27
|
export declare const getTransformMetadata: (value: unknown) => WYWTransformMetadata | undefined;
|
|
28
|
+
export declare const toTransformResultMetadata: (metadata: WYWTransformMetadata, dependencies: string[]) => WYWTransformResultMetadata;
|
|
29
|
+
export declare const createTransformManifest: (metadata: WYWTransformResultMetadata, context: Pick<WYWTransformManifest, "cssFile" | "source">) => WYWTransformManifest;
|
|
30
|
+
export declare const stringifyTransformManifest: (manifest: WYWTransformManifest) => string;
|
|
31
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTransformMetadata = exports.withTransformMetadata = void 0;
|
|
3
|
+
exports.stringifyTransformManifest = exports.createTransformManifest = exports.toTransformResultMetadata = exports.getTransformMetadata = exports.withTransformMetadata = void 0;
|
|
4
|
+
const processor_utils_1 = require("@wyw-in-js/processor-utils");
|
|
4
5
|
const withTransformMetadata = (value) => typeof value === 'object' &&
|
|
5
6
|
value !== null &&
|
|
6
7
|
typeof value.wywInJS === 'object';
|
|
@@ -15,3 +16,25 @@ const getTransformMetadata = (value) => {
|
|
|
15
16
|
return undefined;
|
|
16
17
|
};
|
|
17
18
|
exports.getTransformMetadata = getTransformMetadata;
|
|
19
|
+
const toTransformResultMetadata = (metadata, dependencies) => ({
|
|
20
|
+
dependencies,
|
|
21
|
+
processors: metadata.processors.map((processor) => ({
|
|
22
|
+
artifacts: processor.artifacts
|
|
23
|
+
.filter((artifact) => !(0, processor_utils_1.isProcessorDiagnosticArtifact)(artifact))
|
|
24
|
+
.map(([type, data]) => [type, data]),
|
|
25
|
+
className: processor.className,
|
|
26
|
+
displayName: processor.displayName,
|
|
27
|
+
start: processor.location?.start ?? null,
|
|
28
|
+
})),
|
|
29
|
+
replacements: [...metadata.replacements],
|
|
30
|
+
rules: { ...metadata.rules },
|
|
31
|
+
});
|
|
32
|
+
exports.toTransformResultMetadata = toTransformResultMetadata;
|
|
33
|
+
const createTransformManifest = (metadata, context) => ({
|
|
34
|
+
...metadata,
|
|
35
|
+
...context,
|
|
36
|
+
version: 1,
|
|
37
|
+
});
|
|
38
|
+
exports.createTransformManifest = createTransformManifest;
|
|
39
|
+
const stringifyTransformManifest = (manifest) => `${JSON.stringify(manifest, null, 2)}\n`;
|
|
40
|
+
exports.stringifyTransformManifest = stringifyTransformManifest;
|