@wyw-in-js/transform 0.3.0 → 0.4.1
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 +1 -2
- package/esm/index.js.map +1 -1
- package/esm/plugins/collector.js +5 -11
- package/esm/plugins/collector.js.map +1 -1
- package/esm/plugins/preeval.js +11 -17
- package/esm/plugins/preeval.js.map +1 -1
- package/esm/transform/Entrypoint.js +2 -1
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/generators/createStylisPreprocessor.js +171 -51
- package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/esm/utils/getTagProcessor.js +113 -51
- package/esm/utils/getTagProcessor.js.map +1 -1
- package/lib/index.js +7 -15
- package/lib/index.js.map +1 -1
- package/lib/plugins/collector.js +6 -12
- package/lib/plugins/collector.js.map +1 -1
- package/lib/plugins/preeval.js +12 -17
- package/lib/plugins/preeval.js.map +1 -1
- package/lib/transform/Entrypoint.js +2 -1
- package/lib/transform/Entrypoint.js.map +1 -1
- package/lib/transform/generators/createStylisPreprocessor.js +176 -51
- package/lib/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/lib/utils/getTagProcessor.js +122 -53
- package/lib/utils/getTagProcessor.js.map +1 -1
- package/package.json +7 -7
- package/types/index.d.ts +1 -2
- package/types/index.js +2 -4
- package/types/plugins/collector.d.ts +5 -1
- package/types/plugins/collector.js +5 -10
- package/types/plugins/preeval.d.ts +3 -3
- package/types/plugins/preeval.js +11 -14
- package/types/transform/Entrypoint.js +4 -1
- package/types/transform/generators/createStylisPreprocessor.d.ts +4 -1
- package/types/transform/generators/createStylisPreprocessor.js +187 -59
- package/types/utils/getTagProcessor.d.ts +10 -3
- package/types/utils/getTagProcessor.js +108 -53
- package/esm/utils/processTemplateExpression.js +0 -11
- package/esm/utils/processTemplateExpression.js.map +0 -1
- package/lib/utils/processTemplateExpression.js +0 -18
- package/lib/utils/processTemplateExpression.js.map +0 -1
- package/types/utils/processTemplateExpression.d.ts +0 -5
- package/types/utils/processTemplateExpression.js +0 -17
package/esm/index.js
CHANGED
|
@@ -20,10 +20,9 @@ export { withDefaultServices } from './transform/helpers/withDefaultServices';
|
|
|
20
20
|
export { EventEmitter } from './utils/EventEmitter';
|
|
21
21
|
export { isNode } from './utils/isNode';
|
|
22
22
|
export { getFileIdx } from './utils/getFileIdx';
|
|
23
|
-
export {
|
|
23
|
+
export { applyProcessors } from './utils/getTagProcessor';
|
|
24
24
|
export { getVisitorKeys } from './utils/getVisitorKeys';
|
|
25
25
|
export { peek } from './utils/peek';
|
|
26
|
-
export { processTemplateExpression } from './utils/processTemplateExpression';
|
|
27
26
|
export { TransformCacheCollection } from './cache';
|
|
28
27
|
export { findIdentifiers } from './utils/findIdentifiers';
|
|
29
28
|
//# sourceMappingURL=index.js.map
|
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","
|
|
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 { WYWTransformMetadata } from './utils/TransformMetadata';\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,oBAAoB,EACpBC,qBAAqB,QAChB,2BAA2B;AAElC,SAASC,MAAM,EAAEC,2BAA2B,QAAQ,UAAU;AAC9D,SAASN,OAAO,IAAIO,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"}
|
package/esm/plugins/collector.js
CHANGED
|
@@ -4,22 +4,16 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { logger } from '@wyw-in-js/shared';
|
|
7
|
-
import {
|
|
7
|
+
import { EventEmitter } from '../utils/EventEmitter';
|
|
8
|
+
import { applyProcessors } from '../utils/getTagProcessor';
|
|
8
9
|
import { removeWithRelated } from '../utils/scopeHelpers';
|
|
9
10
|
import { invalidateTraversalCache } from '../utils/traversalCache';
|
|
10
11
|
export const filename = __filename;
|
|
11
12
|
export function collector(file, options, values) {
|
|
13
|
+
const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;
|
|
12
14
|
const processors = [];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Identifier: p => {
|
|
16
|
-
identifiers.push(p);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// TODO: process transformed literals
|
|
21
|
-
identifiers.forEach(p => {
|
|
22
|
-
processTemplateExpression(p, file.opts, options, processor => {
|
|
15
|
+
eventEmitter.perf('transform:collector:processTemplate', () => {
|
|
16
|
+
applyProcessors(file.path, file.opts, options, processor => {
|
|
23
17
|
processor.build(values);
|
|
24
18
|
processor.doRuntimeReplacement();
|
|
25
19
|
processors.push(processor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collector.js","names":["logger","
|
|
1
|
+
{"version":3,"file":"collector.js","names":["logger","EventEmitter","applyProcessors","removeWithRelated","invalidateTraversalCache","filename","__filename","collector","file","options","values","eventEmitter","dummy","processors","perf","path","opts","processor","build","doRuntimeReplacement","push","length","prevalExport","scope","getData","findParent","p","isExpressionStatement","collectorPlugin","babel","Map","debug","extend","name","pre","metadata","wywInJS","replacements","rules","dependencies","visitor","post"],"sources":["../../src/plugins/collector.ts"],"sourcesContent":["/**\n * Collector traverses the AST and collects information about imports and\n * all usages of WYW-processors.\n */\n\nimport type { BabelFile, PluginObj } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\n\nimport type { ValueCache } from '@wyw-in-js/processor-utils';\nimport { logger } from '@wyw-in-js/shared';\nimport type { StrictOptions } from '@wyw-in-js/shared';\n\nimport { EventEmitter } from '../utils/EventEmitter';\nimport { applyProcessors } from '../utils/getTagProcessor';\nimport type { Core } from '../babel';\nimport type { IPluginState } from '../types';\nimport type { WYWTransformMetadata } from '../utils/TransformMetadata';\nimport { removeWithRelated } from '../utils/scopeHelpers';\nimport { invalidateTraversalCache } from '../utils/traversalCache';\n\nexport const filename = __filename;\n\nexport function collector(\n file: BabelFile,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n > & { eventEmitter?: EventEmitter },\n values: ValueCache\n) {\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n const processors: WYWTransformMetadata['processors'] = [];\n\n eventEmitter.perf('transform:collector:processTemplate', () => {\n applyProcessors(file.path, file.opts, options, (processor) => {\n processor.build(values);\n processor.doRuntimeReplacement();\n processors.push(processor);\n });\n });\n\n if (processors.length === 0) {\n // We didn't find any processors.\n return processors;\n }\n\n // We can remove __wywPreval export and all related code\n const prevalExport = (\n file.path.scope.getData('__wywPreval') as NodePath | undefined\n )?.findParent((p) => p.isExpressionStatement());\n if (prevalExport) {\n removeWithRelated([prevalExport]);\n }\n\n return processors;\n}\n\nexport default function collectorPlugin(\n babel: Core,\n options: StrictOptions & { eventEmitter?: EventEmitter; values?: ValueCache }\n): PluginObj<IPluginState> {\n const values = options.values ?? new Map<string, unknown>();\n const debug = logger.extend('collector');\n return {\n name: '@wyw-in-js/transform/collector',\n pre(file: BabelFile) {\n debug('start %s', file.opts.filename);\n\n const processors = collector(file, options, values);\n\n if (processors.length === 0) {\n // We didn't find any wyw-in-js template literals.\n return;\n }\n\n this.file.metadata.wywInJS = {\n processors,\n replacements: [],\n rules: {},\n dependencies: [],\n };\n\n debug('end %s', file.opts.filename);\n },\n visitor: {},\n post(file: BabelFile) {\n invalidateTraversalCache(file.path);\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAMA,SAASA,MAAM,QAAQ,mBAAmB;AAG1C,SAASC,YAAY,QAAQ,uBAAuB;AACpD,SAASC,eAAe,QAAQ,0BAA0B;AAI1D,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,wBAAwB,QAAQ,yBAAyB;AAElE,OAAO,MAAMC,QAAQ,GAAGC,UAAU;AAElC,OAAO,SAASC,SAASA,CACvBC,IAAe,EACfC,OAGmC,EACnCC,MAAkB,EAClB;EACA,MAAMC,YAAY,GAAGF,OAAO,CAACE,YAAY,IAAIV,YAAY,CAACW,KAAK;EAC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QAAQ,CAACC,OAAO,GAAG;QAC3BvB,UAAU;QACVwB,YAAY,EAAE,EAAE;QAChBC,KAAK,EAAE,CAAC,CAAC;QACTC,YAAY,EAAE;MAChB,CAAC;MAEDR,KAAK,CAAC,QAAQ,EAAEvB,IAAI,CAACQ,IAAI,CAACX,QAAQ,CAAC;IACrC,CAAC;IACDmC,OAAO,EAAE,CAAC,CAAC;IACXC,IAAIA,CAACjC,IAAe,EAAE;MACpBJ,wBAAwB,CAACI,IAAI,CAACO,IAAI,CAAC;IACrC;EACF,CAAC;AACH"}
|
package/esm/plugins/preeval.js
CHANGED
|
@@ -4,19 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { isFeatureEnabled, logger } from '@wyw-in-js/shared';
|
|
7
|
+
import { applyProcessors } from '../utils/getTagProcessor';
|
|
7
8
|
import { EventEmitter } from '../utils/EventEmitter';
|
|
8
9
|
import { addIdentifierToWywPreval } from '../utils/addIdentifierToWywPreval';
|
|
9
10
|
import { getFileIdx } from '../utils/getFileIdx';
|
|
10
|
-
import { processTemplateExpression } from '../utils/processTemplateExpression';
|
|
11
11
|
import { removeDangerousCode } from '../utils/removeDangerousCode';
|
|
12
12
|
import { invalidateTraversalCache } from '../utils/traversalCache';
|
|
13
|
-
export function preeval(babel, {
|
|
14
|
-
eventEmitter = EventEmitter.dummy,
|
|
15
|
-
...options
|
|
16
|
-
}) {
|
|
13
|
+
export function preeval(babel, options) {
|
|
17
14
|
const {
|
|
18
15
|
types: t
|
|
19
16
|
} = babel;
|
|
17
|
+
const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;
|
|
20
18
|
return {
|
|
21
19
|
name: '@wyw-in-js/transform/preeval',
|
|
22
20
|
pre(file) {
|
|
@@ -26,18 +24,14 @@ export function preeval(babel, {
|
|
|
26
24
|
const rootScope = file.scope;
|
|
27
25
|
this.processors = [];
|
|
28
26
|
eventEmitter.perf('transform:preeval:processTemplate', () => {
|
|
29
|
-
file.path.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
processor.doEvaltimeReplacement();
|
|
38
|
-
this.processors.push(processor);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
27
|
+
applyProcessors(file.path, file.opts, options, processor => {
|
|
28
|
+
processor.dependencies.forEach(dependency => {
|
|
29
|
+
if (dependency.ex.type === 'Identifier') {
|
|
30
|
+
addIdentifierToWywPreval(rootScope, dependency.ex.name);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
processor.doEvaltimeReplacement();
|
|
34
|
+
this.processors.push(processor);
|
|
41
35
|
});
|
|
42
36
|
});
|
|
43
37
|
if (isFeatureEnabled(options.features, 'dangerousCodeRemover', filename)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preeval.js","names":["isFeatureEnabled","logger","EventEmitter","addIdentifierToWywPreval","getFileIdx","
|
|
1
|
+
{"version":3,"file":"preeval.js","names":["isFeatureEnabled","logger","applyProcessors","EventEmitter","addIdentifierToWywPreval","getFileIdx","removeDangerousCode","invalidateTraversalCache","preeval","babel","options","types","t","eventEmitter","dummy","name","pre","file","filename","opts","log","extend","rootScope","scope","processors","perf","path","processor","dependencies","forEach","dependency","ex","type","doEvaltimeReplacement","push","features","visitor","post","length","metadata","wywInJS","replacements","rules","wywPreval","getData","wywExport","expressionStatement","assignmentExpression","memberExpression","identifier","objectExpression","pushContainer"],"sources":["../../src/plugins/preeval.ts"],"sourcesContent":["/**\n * This file is a babel preset used to transform files inside evaluators.\n * It works the same as main `babel/extract` preset, but do not evaluate lazy dependencies.\n */\nimport type { BabelFile, PluginObj } from '@babel/core';\n\nimport type { StrictOptions } from '@wyw-in-js/shared';\nimport { isFeatureEnabled, logger } from '@wyw-in-js/shared';\n\nimport { applyProcessors } from '../utils/getTagProcessor';\nimport type { Core } from '../babel';\nimport type { IPluginState } from '../types';\nimport { EventEmitter } from '../utils/EventEmitter';\nimport { addIdentifierToWywPreval } from '../utils/addIdentifierToWywPreval';\nimport { getFileIdx } from '../utils/getFileIdx';\nimport { removeDangerousCode } from '../utils/removeDangerousCode';\nimport { invalidateTraversalCache } from '../utils/traversalCache';\n\nexport type PreevalOptions = Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'features' | 'tagResolver'\n> & { eventEmitter?: EventEmitter };\n\nexport function preeval(\n babel: Core,\n options: PreevalOptions\n): PluginObj<IPluginState & { onFinish: () => void }> {\n const { types: t } = babel;\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n return {\n name: '@wyw-in-js/transform/preeval',\n pre(file: BabelFile) {\n const filename = file.opts.filename!;\n const log = logger.extend('preeval').extend(getFileIdx(filename));\n\n log('start', 'Looking for template literals…');\n\n const rootScope = file.scope;\n this.processors = [];\n\n eventEmitter.perf('transform:preeval:processTemplate', () => {\n applyProcessors(file.path, file.opts, options, (processor) => {\n processor.dependencies.forEach((dependency) => {\n if (dependency.ex.type === 'Identifier') {\n addIdentifierToWywPreval(rootScope, dependency.ex.name);\n }\n });\n\n processor.doEvaltimeReplacement();\n this.processors.push(processor);\n });\n });\n\n if (\n isFeatureEnabled(options.features, 'dangerousCodeRemover', filename)\n ) {\n log('start', 'Strip all JSX and browser related stuff');\n eventEmitter.perf('transform:preeval:removeDangerousCode', () =>\n removeDangerousCode(file.path)\n );\n }\n },\n visitor: {},\n post(file: BabelFile) {\n const log = logger\n .extend('preeval')\n .extend(getFileIdx(file.opts.filename!));\n\n invalidateTraversalCache(file.path);\n\n if (this.processors.length === 0) {\n log('end', \"We didn't find any wyw-in-js template literals\");\n\n // We didn't find any wyw-in-js template literals.\n return;\n }\n\n this.file.metadata.wywInJS = {\n processors: this.processors,\n replacements: [],\n rules: {},\n dependencies: [],\n };\n\n const wywPreval = file.path.getData('__wywPreval');\n if (!wywPreval) {\n // Event if there is no dependencies, we still need to add __wywPreval\n const wywExport = t.expressionStatement(\n t.assignmentExpression(\n '=',\n t.memberExpression(\n t.identifier('exports'),\n t.identifier('__wywPreval')\n ),\n t.objectExpression([])\n )\n );\n\n file.path.pushContainer('body', wywExport);\n }\n\n log('end', '__wywPreval has been added');\n },\n };\n}\n\nexport default preeval;\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAIA,SAASA,gBAAgB,EAAEC,MAAM,QAAQ,mBAAmB;AAE5D,SAASC,eAAe,QAAQ,0BAA0B;AAG1D,SAASC,YAAY,QAAQ,uBAAuB;AACpD,SAASC,wBAAwB,QAAQ,mCAAmC;AAC5E,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,SAASC,wBAAwB,QAAQ,yBAAyB;AAOlE,OAAO,SAASC,OAAOA,CACrBC,KAAW,EACXC,OAAuB,EAC6B;EACpD,MAAM;IAAEC,KAAK,EAAEC;EAAE,CAAC,GAAGH,KAAK;EAC1B,MAAMI,YAAY,GAAGH,OAAO,CAACG,YAAY,IAAIV,YAAY,CAACW,KAAK;EAC/D,OAAO;IACLC,IAAI,EAAE,8BAA8B;IACpCC,GAAGA,CAACC,IAAe,EAAE;MACnB,MAAMC,QAAQ,GAAGD,IAAI,CAACE,IAAI,CAACD,QAAS;MACpC,MAAME,GAAG,GAAGnB,MAAM,CAACoB,MAAM,CAAC,SAAS,CAAC,CAACA,MAAM,CAAChB,UAAU,CAACa,QAAQ,CAAC,CAAC;MAEjEE,GAAG,CAAC,OAAO,EAAE,gCAAgC,CAAC;MAE9C,MAAME,SAAS,GAAGL,IAAI,CAACM,KAAK;MAC5B,IAAI,CAACC,UAAU,GAAG,EAAE;MAEpBX,YAAY,CAACY,IAAI,CAAC,mCAAmC,EAAE,MAAM;QAC3DvB,eAAe,CAACe,IAAI,CAACS,IAAI,EAAET,IAAI,CAACE,IAAI,EAAET,OAAO,EAAGiB,SAAS,IAAK;UAC5DA,SAAS,CAACC,YAAY,CAACC,OAAO,CAAEC,UAAU,IAAK;YAC7C,IAAIA,UAA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mBAAmB,CACrClC,CAAC,CAACmC,oBAAoB,CACpB,GAAG,EACHnC,CAAC,CAACoC,gBAAgB,CAChBpC,CAAC,CAACqC,UAAU,CAAC,SAAS,CAAC,EACvBrC,CAAC,CAACqC,UAAU,CAAC,aAAa,CAC5B,CAAC,EACDrC,CAAC,CAACsC,gBAAgB,CAAC,EAAE,CACvB,CACF,CAAC;QAEDjC,IAAI,CAACS,IAAI,CAACyB,aAAa,CAAC,MAAM,EAAEN,SAAS,CAAC;MAC5C;MAEAzB,GAAG,CAAC,KAAK,EAAE,4BAA4B,CAAC;IAC1C;EACF,CAAC;AACH;AAEA,eAAeZ,OAAO"}
|
|
@@ -34,7 +34,8 @@ export class Entrypoint extends BaseEntrypoint {
|
|
|
34
34
|
if (this.loadedAndParsed.code !== undefined) {
|
|
35
35
|
services.cache.invalidateIfChanged(name, this.loadedAndParsed.code);
|
|
36
36
|
}
|
|
37
|
-
this.
|
|
37
|
+
const code = this.loadedAndParsed.evaluator === 'ignored' ? '[IGNORED]' : this.originalCode || EMPTY_FILE;
|
|
38
|
+
this.log.extend('source')('created %s (%o)\n%s', name, only, code);
|
|
38
39
|
}
|
|
39
40
|
get ignored() {
|
|
40
41
|
return this.loadedAndParsed.evaluator === 'ignored';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entrypoint.js","names":["invariant","BaseEntrypoint","isSuperSet","mergeOnly","EvaluatedEntrypoint","AbortError","BaseAction","UnprocessedEntrypointError","EMPTY_FILE","hasLoop","name","parent","processed","includes","p","parents","found","Entrypoint","evaluated","onSupersedeHandlers","actionsCache","Map","hasWywMetadata","supersededWith","transformResultCode","constructor","services","initialCode","only","exports","evaluatedOnly","loadedAndParsed","resolveTasks","dependencies","generation","loadAndParseFn","log","code","undefined","cache","invalidateIfChanged","extend","originalCode","ignored","evaluator","transformedCode","createRoot","loadedCode","created","create","eventEmitter","perf","status","entrypoint","innerCreate","seqId","add","cached","get","changed","mergedOnly","filter","i","isLoop","map","push","supersede","newEntrypoint","addDependency","dependency","delete","source","set","addResolveTask","assertNotSuperseded","assertTransformed","createAction","actionType","data","abortSignal","has","aborted","newAction","entrypointEvent","type","actionIdx","idx","createChild","createEvaluated","exportsProxy","getDependency","getResolveTask","onSupersede","callback","index","indexOf","splice","setTransformResult","res","Boolean","metadata","isNull","newOnlyOrEntrypoint","with","forEach","handler"],"sources":["../../src/transform/Entrypoint.ts"],"sourcesContent":["import { invariant } from 'ts-invariant';\n\nimport type { ParentEntrypoint, ITransformFileResult } from '../types';\n\nimport { BaseEntrypoint } from './BaseEntrypoint';\nimport { isSuperSet, mergeOnly } from './Entrypoint.helpers';\nimport type {\n IEntrypointCode,\n IEntrypointDependency,\n IIgnoredEntrypoint,\n} from './Entrypoint.types';\nimport { EvaluatedEntrypoint } from './EvaluatedEntrypoint';\nimport { AbortError } from './actions/AbortError';\nimport type { ActionByType } from './actions/BaseAction';\nimport { BaseAction } from './actions/BaseAction';\nimport { UnprocessedEntrypointError } from './actions/UnprocessedEntrypointError';\nimport type { Services, ActionTypes, ActionQueueItem } from './types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nfunction hasLoop(\n name: string,\n parent: ParentEntrypoint,\n processed: string[] = []\n): boolean {\n if (parent.name === name || processed.includes(parent.name)) {\n return true;\n }\n\n for (const p of parent.parents) {\n const found = hasLoop(name, p, [...processed, parent.name]);\n if (found) {\n return found;\n }\n }\n\n return false;\n}\n\nexport class Entrypoint extends BaseEntrypoint {\n public readonly evaluated = false;\n\n public readonly loadedAndParsed: IEntrypointCode | IIgnoredEntrypoint;\n\n protected onSupersedeHandlers: Array<(newEntrypoint: Entrypoint) => void> =\n [];\n\n private actionsCache: Map<\n ActionTypes,\n Map<unknown, BaseAction<ActionQueueItem>>\n > = new Map();\n\n #hasWywMetadata: boolean = false;\n\n #supersededWith: Entrypoint | null = null;\n\n #transformResultCode: string | null = null;\n\n private constructor(\n services: Services,\n parents: ParentEntrypoint[],\n public readonly initialCode: string | undefined,\n name: string,\n only: string[],\n exports: Record<string | symbol, unknown> | undefined,\n evaluatedOnly: string[],\n loadedAndParsed?: IEntrypointCode | IIgnoredEntrypoint,\n protected readonly resolveTasks = new Map<\n string,\n Promise<IEntrypointDependency>\n >(),\n protected readonly dependencies = new Map<string, IEntrypointDependency>(),\n generation = 1\n ) {\n super(services, evaluatedOnly, exports, generation, name, only, parents);\n\n this.loadedAndParsed =\n loadedAndParsed ??\n services.loadAndParseFn(\n services,\n name,\n initialCode,\n parents[0]?.log ?? services.log\n );\n\n if (this.loadedAndParsed.code !== undefined) {\n services.cache.invalidateIfChanged(name, this.loadedAndParsed.code);\n }\n\n this.log.extend('source')(\n 'created %s (%o)\\n%s',\n name,\n only,\n this.originalCode || EMPTY_FILE\n );\n }\n\n public get ignored() {\n return this.loadedAndParsed.evaluator === 'ignored';\n }\n\n public get originalCode() {\n return this.loadedAndParsed.code;\n }\n\n public get supersededWith(): Entrypoint | null {\n return this.#supersededWith?.supersededWith ?? this.#supersededWith;\n }\n\n public get transformedCode(): string | null {\n return (\n this.#transformResultCode ?? this.supersededWith?.transformedCode ?? null\n );\n }\n\n public static createRoot(\n services: Services,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint {\n const created = Entrypoint.create(services, null, name, only, loadedCode);\n invariant(created !== 'loop', 'loop detected');\n\n return created;\n }\n\n /**\n * Creates an entrypoint for the specified file.\n * If there is already an entrypoint for this file, there will be four possible outcomes:\n * 1. If `loadedCode` is specified and is different from the one that was used to create the existing entrypoint,\n * the existing entrypoint will be superseded by a new one and all cached results for it will be invalidated.\n * It can happen if the file was changed and the watcher notified us about it, or we received a new version\n * of the file from a loader whereas the previous one was loaded from the filesystem.\n * The new entrypoint will be returned.\n * 2. If `only` is subset of the existing entrypoint's `only`, the existing entrypoint will be returned.\n * 3. If `only` is superset of the existing entrypoint's `only`, the existing entrypoint will be superseded and the new one will be returned.\n * 4. If a loop is detected, 'ignored' will be returned, the existing entrypoint will be superseded or not depending on the `only` value.\n */\n protected static create(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint | 'loop' {\n const { cache, eventEmitter } = services;\n return eventEmitter.perf('createEntrypoint', () => {\n const [status, entrypoint] = Entrypoint.innerCreate(\n services,\n parent\n ? {\n evaluated: parent.evaluated,\n log: parent.log,\n name: parent.name,\n parents: parent.parents,\n seqId: parent.seqId,\n }\n : null,\n name,\n only,\n loadedCode\n );\n\n if (status !== 'cached') {\n cache.add('entrypoints', name, entrypoint);\n }\n\n return status === 'loop' ? 'loop' : entrypoint;\n });\n }\n\n private static innerCreate(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): ['loop' | 'created' | 'cached', Entrypoint] {\n const { cache } = services;\n\n const cached = cache.get('entrypoints', name);\n const changed =\n loadedCode !== undefined\n ? cache.invalidateIfChanged(name, loadedCode)\n : false;\n\n if (!cached?.evaluated && cached?.ignored) {\n return ['cached', cached];\n }\n\n const exports = cached?.exports;\n const evaluatedOnly = cached?.evaluatedOnly ?? [];\n const mergedOnly =\n !changed && cached?.only\n ? mergeOnly(cached.only, only).filter((i) => !evaluatedOnly.includes(i))\n : only;\n\n if (cached?.evaluated) {\n cached.log('is already evaluated with', cached.evaluatedOnly);\n }\n\n if (!changed && cached && !cached.evaluated) {\n const isLoop = parent && hasLoop(name, parent);\n if (isLoop) {\n parent.log('[createEntrypoint] %s is a loop', name);\n }\n\n if (parent && !cached.parents.map((p) => p.name).includes(parent.name)) {\n cached.parents.push(parent);\n }\n\n if (isSuperSet(cached.only, mergedOnly)) {\n cached.log('is cached', name);\n return [isLoop ? 'loop' : 'cached', cached];\n }\n\n cached.log(\n 'is cached, but with different `only` %o (the cached one %o)',\n only,\n cached?.only\n );\n\n return [isLoop ? 'loop' : 'created', cached.supersede(mergedOnly)];\n }\n\n const newEntrypoint = new Entrypoint(\n services,\n parent ? [parent] : [],\n loadedCode,\n name,\n mergedOnly,\n exports,\n evaluatedOnly,\n undefined,\n cached && 'resolveTasks' in cached ? cached.resolveTasks : undefined,\n cached && 'dependencies' in cached ? cached.dependencies : undefined,\n cached ? cached.generation + 1 : 1\n );\n\n if (cached && !cached.evaluated) {\n cached.log('is cached, but with different code');\n cached.supersede(newEntrypoint);\n }\n\n return ['created', newEntrypoint];\n }\n\n public addDependency(dependency: IEntrypointDependency): void {\n this.resolveTasks.delete(dependency.source);\n this.dependencies.set(dependency.source, dependency);\n }\n\n public addResolveTask(\n name: string,\n dependency: Promise<IEntrypointDependency>\n ): void {\n this.resolveTasks.set(name, dependency);\n }\n\n public assertNotSuperseded() {\n if (this.supersededWith) {\n this.log('superseded');\n throw new AbortError('superseded');\n }\n }\n\n public assertTransformed() {\n if (this.transformedCode === null) {\n this.log('not transformed');\n throw new UnprocessedEntrypointError(this.supersededWith ?? this);\n }\n }\n\n public createAction<\n TType extends ActionTypes,\n TAction extends ActionByType<TType>,\n >(\n actionType: TType,\n data: TAction['data'],\n abortSignal: AbortSignal | null = null\n ): BaseAction<TAction> {\n if (!this.actionsCache.has(actionType)) {\n this.actionsCache.set(actionType, new Map());\n }\n\n const cache = this.actionsCache.get(actionType)!;\n const cached = cache.get(data);\n if (cached && !cached.abortSignal?.aborted) {\n return cached as BaseAction<TAction>;\n }\n\n const newAction = new BaseAction<TAction>(\n actionType as TAction['type'],\n this.services,\n this,\n data,\n abortSignal\n );\n\n cache.set(data, newAction);\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'actionCreated',\n actionType,\n actionIdx: newAction.idx,\n });\n\n return newAction;\n }\n\n public createChild(\n name: string,\n only: string[],\n loadedCode?: string\n ): Entrypoint | 'loop' {\n return Entrypoint.create(this.services, this, name, only, loadedCode);\n }\n\n public createEvaluated() {\n const evaluatedOnly = mergeOnly(this.evaluatedOnly, this.only);\n this.log('create EvaluatedEntrypoint for %o', evaluatedOnly);\n\n return new EvaluatedEntrypoint(\n this.services,\n evaluatedOnly,\n this.exportsProxy,\n this.generation + 1,\n this.name,\n this.only,\n this.parents\n );\n }\n\n public getDependency(name: string): IEntrypointDependency | undefined {\n return this.dependencies.get(name);\n }\n\n public getResolveTask(\n name: string\n ): Promise<IEntrypointDependency> | undefined {\n return this.resolveTasks.get(name);\n }\n\n public hasWywMetadata() {\n return this.#hasWywMetadata;\n }\n\n public onSupersede(callback: (newEntrypoint: Entrypoint) => void) {\n if (this.#supersededWith) {\n callback(this.#supersededWith);\n return () => {};\n }\n\n this.onSupersedeHandlers.push(callback);\n\n return () => {\n const index = this.onSupersedeHandlers.indexOf(callback);\n if (index >= 0) {\n this.onSupersedeHandlers.splice(index, 1);\n }\n };\n }\n\n public setTransformResult(res: ITransformFileResult | null) {\n this.#hasWywMetadata = Boolean(res?.metadata);\n this.#transformResultCode = res?.code ?? null;\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n isNull: res === null,\n type: 'setTransformResult',\n });\n }\n\n private supersede(newOnlyOrEntrypoint: string[] | Entrypoint): Entrypoint {\n const newEntrypoint =\n newOnlyOrEntrypoint instanceof Entrypoint\n ? newOnlyOrEntrypoint\n : new Entrypoint(\n this.services,\n this.parents,\n this.initialCode,\n this.name,\n newOnlyOrEntrypoint,\n this.exports,\n this.evaluatedOnly,\n this.loadedAndParsed,\n this.resolveTasks,\n this.dependencies,\n this.generation + 1\n );\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'superseded',\n with: newEntrypoint.seqId,\n });\n this.log(\n 'superseded by %s (%o -> %o)',\n newEntrypoint.name,\n this.only,\n newEntrypoint.only\n );\n this.#supersededWith = newEntrypoint;\n this.onSupersedeHandlers.forEach((handler) => handler(newEntrypoint));\n\n return newEntrypoint;\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,cAAc;AAIxC,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,UAAU,EAAEC,SAAS,QAAQ,sBAAsB;AAM5D,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,UAAU,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,CAACtC,aAAa,CAAC,CAAC;IAErE,OAAOA,aAAa;EACtB;AACF"}
|
|
1
|
+
{"version":3,"file":"Entrypoint.js","names":["invariant","BaseEntrypoint","isSuperSet","mergeOnly","EvaluatedEntrypoint","AbortError","BaseAction","UnprocessedEntrypointError","EMPTY_FILE","hasLoop","name","parent","processed","includes","p","parents","found","Entrypoint","evaluated","onSupersedeHandlers","actionsCache","Map","hasWywMetadata","supersededWith","transformResultCode","constructor","services","initialCode","only","exports","evaluatedOnly","loadedAndParsed","resolveTasks","dependencies","generation","loadAndParseFn","log","code","undefined","cache","invalidateIfChanged","evaluator","originalCode","extend","ignored","transformedCode","createRoot","loadedCode","created","create","eventEmitter","perf","status","entrypoint","innerCreate","seqId","add","cached","get","changed","mergedOnly","filter","i","isLoop","map","push","supersede","newEntrypoint","addDependency","dependency","delete","source","set","addResolveTask","assertNotSuperseded","assertTransformed","createAction","actionType","data","abortSignal","has","aborted","newAction","entrypointEvent","type","actionIdx","idx","createChild","createEvaluated","exportsProxy","getDependency","getResolveTask","onSupersede","callback","index","indexOf","splice","setTransformResult","res","Boolean","metadata","isNull","newOnlyOrEntrypoint","with","forEach","handler"],"sources":["../../src/transform/Entrypoint.ts"],"sourcesContent":["import { invariant } from 'ts-invariant';\n\nimport type { ParentEntrypoint, ITransformFileResult } from '../types';\n\nimport { BaseEntrypoint } from './BaseEntrypoint';\nimport { isSuperSet, mergeOnly } from './Entrypoint.helpers';\nimport type {\n IEntrypointCode,\n IEntrypointDependency,\n IIgnoredEntrypoint,\n} from './Entrypoint.types';\nimport { EvaluatedEntrypoint } from './EvaluatedEntrypoint';\nimport { AbortError } from './actions/AbortError';\nimport type { ActionByType } from './actions/BaseAction';\nimport { BaseAction } from './actions/BaseAction';\nimport { UnprocessedEntrypointError } from './actions/UnprocessedEntrypointError';\nimport type { Services, ActionTypes, ActionQueueItem } from './types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nfunction hasLoop(\n name: string,\n parent: ParentEntrypoint,\n processed: string[] = []\n): boolean {\n if (parent.name === name || processed.includes(parent.name)) {\n return true;\n }\n\n for (const p of parent.parents) {\n const found = hasLoop(name, p, [...processed, parent.name]);\n if (found) {\n return found;\n }\n }\n\n return false;\n}\n\nexport class Entrypoint extends BaseEntrypoint {\n public readonly evaluated = false;\n\n public readonly loadedAndParsed: IEntrypointCode | IIgnoredEntrypoint;\n\n protected onSupersedeHandlers: Array<(newEntrypoint: Entrypoint) => void> =\n [];\n\n private actionsCache: Map<\n ActionTypes,\n Map<unknown, BaseAction<ActionQueueItem>>\n > = new Map();\n\n #hasWywMetadata: boolean = false;\n\n #supersededWith: Entrypoint | null = null;\n\n #transformResultCode: string | null = null;\n\n private constructor(\n services: Services,\n parents: ParentEntrypoint[],\n public readonly initialCode: string | undefined,\n name: string,\n only: string[],\n exports: Record<string | symbol, unknown> | undefined,\n evaluatedOnly: string[],\n loadedAndParsed?: IEntrypointCode | IIgnoredEntrypoint,\n protected readonly resolveTasks = new Map<\n string,\n Promise<IEntrypointDependency>\n >(),\n protected readonly dependencies = new Map<string, IEntrypointDependency>(),\n generation = 1\n ) {\n super(services, evaluatedOnly, exports, generation, name, only, parents);\n\n this.loadedAndParsed =\n loadedAndParsed ??\n services.loadAndParseFn(\n services,\n name,\n initialCode,\n parents[0]?.log ?? services.log\n );\n\n if (this.loadedAndParsed.code !== undefined) {\n services.cache.invalidateIfChanged(name, this.loadedAndParsed.code);\n }\n\n const code =\n this.loadedAndParsed.evaluator === 'ignored'\n ? '[IGNORED]'\n : this.originalCode || EMPTY_FILE;\n\n this.log.extend('source')('created %s (%o)\\n%s', name, only, code);\n }\n\n public get ignored() {\n return this.loadedAndParsed.evaluator === 'ignored';\n }\n\n public get originalCode() {\n return this.loadedAndParsed.code;\n }\n\n public get supersededWith(): Entrypoint | null {\n return this.#supersededWith?.supersededWith ?? this.#supersededWith;\n }\n\n public get transformedCode(): string | null {\n return (\n this.#transformResultCode ?? this.supersededWith?.transformedCode ?? null\n );\n }\n\n public static createRoot(\n services: Services,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint {\n const created = Entrypoint.create(services, null, name, only, loadedCode);\n invariant(created !== 'loop', 'loop detected');\n\n return created;\n }\n\n /**\n * Creates an entrypoint for the specified file.\n * If there is already an entrypoint for this file, there will be four possible outcomes:\n * 1. If `loadedCode` is specified and is different from the one that was used to create the existing entrypoint,\n * the existing entrypoint will be superseded by a new one and all cached results for it will be invalidated.\n * It can happen if the file was changed and the watcher notified us about it, or we received a new version\n * of the file from a loader whereas the previous one was loaded from the filesystem.\n * The new entrypoint will be returned.\n * 2. If `only` is subset of the existing entrypoint's `only`, the existing entrypoint will be returned.\n * 3. If `only` is superset of the existing entrypoint's `only`, the existing entrypoint will be superseded and the new one will be returned.\n * 4. If a loop is detected, 'ignored' will be returned, the existing entrypoint will be superseded or not depending on the `only` value.\n */\n protected static create(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint | 'loop' {\n const { cache, eventEmitter } = services;\n return eventEmitter.perf('createEntrypoint', () => {\n const [status, entrypoint] = Entrypoint.innerCreate(\n services,\n parent\n ? {\n evaluated: parent.evaluated,\n log: parent.log,\n name: parent.name,\n parents: parent.parents,\n seqId: parent.seqId,\n }\n : null,\n name,\n only,\n loadedCode\n );\n\n if (status !== 'cached') {\n cache.add('entrypoints', name, entrypoint);\n }\n\n return status === 'loop' ? 'loop' : entrypoint;\n });\n }\n\n private static innerCreate(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): ['loop' | 'created' | 'cached', Entrypoint] {\n const { cache } = services;\n\n const cached = cache.get('entrypoints', name);\n const changed =\n loadedCode !== undefined\n ? cache.invalidateIfChanged(name, loadedCode)\n : false;\n\n if (!cached?.evaluated && cached?.ignored) {\n return ['cached', cached];\n }\n\n const exports = cached?.exports;\n const evaluatedOnly = cached?.evaluatedOnly ?? [];\n const mergedOnly =\n !changed && cached?.only\n ? mergeOnly(cached.only, only).filter((i) => !evaluatedOnly.includes(i))\n : only;\n\n if (cached?.evaluated) {\n cached.log('is already evaluated with', cached.evaluatedOnly);\n }\n\n if (!changed && cached && !cached.evaluated) {\n const isLoop = parent && hasLoop(name, parent);\n if (isLoop) {\n parent.log('[createEntrypoint] %s is a loop', name);\n }\n\n if (parent && !cached.parents.map((p) => p.name).includes(parent.name)) {\n cached.parents.push(parent);\n }\n\n if (isSuperSet(cached.only, mergedOnly)) {\n cached.log('is cached', name);\n return [isLoop ? 'loop' : 'cached', cached];\n }\n\n cached.log(\n 'is cached, but with different `only` %o (the cached one %o)',\n only,\n cached?.only\n );\n\n return [isLoop ? 'loop' : 'created', cached.supersede(mergedOnly)];\n }\n\n const newEntrypoint = new Entrypoint(\n services,\n parent ? [parent] : [],\n loadedCode,\n name,\n mergedOnly,\n exports,\n evaluatedOnly,\n undefined,\n cached && 'resolveTasks' in cached ? cached.resolveTasks : undefined,\n cached && 'dependencies' in cached ? cached.dependencies : undefined,\n cached ? cached.generation + 1 : 1\n );\n\n if (cached && !cached.evaluated) {\n cached.log('is cached, but with different code');\n cached.supersede(newEntrypoint);\n }\n\n return ['created', newEntrypoint];\n }\n\n public addDependency(dependency: IEntrypointDependency): void {\n this.resolveTasks.delete(dependency.source);\n this.dependencies.set(dependency.source, dependency);\n }\n\n public addResolveTask(\n name: string,\n dependency: Promise<IEntrypointDependency>\n ): void {\n this.resolveTasks.set(name, dependency);\n }\n\n public assertNotSuperseded() {\n if (this.supersededWith) {\n this.log('superseded');\n throw new AbortError('superseded');\n }\n }\n\n public assertTransformed() {\n if (this.transformedCode === null) {\n this.log('not transformed');\n throw new UnprocessedEntrypointError(this.supersededWith ?? this);\n }\n }\n\n public createAction<\n TType extends ActionTypes,\n TAction extends ActionByType<TType>,\n >(\n actionType: TType,\n data: TAction['data'],\n abortSignal: AbortSignal | null = null\n ): BaseAction<TAction> {\n if (!this.actionsCache.has(actionType)) {\n this.actionsCache.set(actionType, new Map());\n }\n\n const cache = this.actionsCache.get(actionType)!;\n const cached = cache.get(data);\n if (cached && !cached.abortSignal?.aborted) {\n return cached as BaseAction<TAction>;\n }\n\n const newAction = new BaseAction<TAction>(\n actionType as TAction['type'],\n this.services,\n this,\n data,\n abortSignal\n );\n\n cache.set(data, newAction);\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'actionCreated',\n actionType,\n actionIdx: newAction.idx,\n });\n\n return newAction;\n }\n\n public createChild(\n name: string,\n only: string[],\n loadedCode?: string\n ): Entrypoint | 'loop' {\n return Entrypoint.create(this.services, this, name, only, loadedCode);\n }\n\n public createEvaluated() {\n const evaluatedOnly = mergeOnly(this.evaluatedOnly, this.only);\n this.log('create EvaluatedEntrypoint for %o', evaluatedOnly);\n\n return new EvaluatedEntrypoint(\n this.services,\n evaluatedOnly,\n this.exportsProxy,\n this.generation + 1,\n this.name,\n this.only,\n this.parents\n );\n }\n\n public getDependency(name: string): IEntrypointDependency | undefined {\n return this.dependencies.get(name);\n }\n\n public getResolveTask(\n name: string\n ): Promise<IEntrypointDependency> | undefined {\n return this.resolveTasks.get(name);\n }\n\n public hasWywMetadata() {\n return this.#hasWywMetadata;\n }\n\n public onSupersede(callback: (newEntrypoint: Entrypoint) => void) {\n if (this.#supersededWith) {\n callback(this.#supersededWith);\n return () => {};\n }\n\n this.onSupersedeHandlers.push(callback);\n\n return () => {\n const index = this.onSupersedeHandlers.indexOf(callback);\n if (index >= 0) {\n this.onSupersedeHandlers.splice(index, 1);\n }\n };\n }\n\n public setTransformResult(res: ITransformFileResult | null) {\n this.#hasWywMetadata = Boolean(res?.metadata);\n this.#transformResultCode = res?.code ?? null;\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n isNull: res === null,\n type: 'setTransformResult',\n });\n }\n\n private supersede(newOnlyOrEntrypoint: string[] | Entrypoint): Entrypoint {\n const newEntrypoint =\n newOnlyOrEntrypoint instanceof Entrypoint\n ? newOnlyOrEntrypoint\n : new Entrypoint(\n this.services,\n this.parents,\n this.initialCode,\n this.name,\n newOnlyOrEntrypoint,\n this.exports,\n this.evaluatedOnly,\n this.loadedAndParsed,\n this.resolveTasks,\n this.dependencies,\n this.generation + 1\n );\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'superseded',\n with: newEntrypoint.seqId,\n });\n this.log(\n 'superseded by %s (%o -> %o)',\n newEntrypoint.name,\n this.only,\n newEntrypoint.only\n );\n this.#supersededWith = newEntrypoint;\n this.onSupersedeHandlers.forEach((handler) => handler(newEntrypoint));\n\n return newEntrypoint;\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,cAAc;AAIxC,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,UAAU,EAAEC,SAAS,QAAQ,sBAAsB;AAM5D,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,UAAU,QAAQ,sBAAsB;AAEjD,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,0BAA0B,QAAQ,sCAAsC;AAGjF,MAAMC,UAAU,GAAG,oBAAoB;AAEvC,SAASC,OAAOA,CACdC,IAAY,EACZC,MAAwB,EACxBC,SAAmB,GAAG,EAAE,EACf;EACT,IAAID,MAAM,CAACD,IAAI,KAAKA,IAAI,IAAIE,SAAS,CAACC,QAAQ,CAACF,MAAM,CAACD,IAAI,CAAC,EAAE;IAC3D,OAAO,IAAI;EACb;EAEA,KAAK,MAAMI,CAAC,IAAIH,MAAM,CAACI,OAAO,EAAE;IAC9B,MAAMC,KAAK,GAAGP,OAAO,CAACC,IAAI,EAAEI,CAAC,EAAE,CAAC,GAAGF,SAAS,EAAED,MAAM,CAACD,IAAI,CAAC,CAAC;IAC3D,IAAIM,KAAK,EAAE;MACT,OAAOA,KAAK;IACd;EACF;EAEA,OAAO,KAAK;AACd;AAEA,OAAO,MAAMC,UAAU,SAAShB,cAAc,CAAC;EAC7BiB,SAAS,GAAG,KAAK;EAIvBC,mBAAmB,GAC3B,EAAE;EAEIC,YAA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O,EACZ,IAAI,CAACY,WAAW,EAChB,IAAI,CAACjB,IAAI,EACT4F,mBAAmB,EACnB,IAAI,CAACzE,OAAO,EACZ,IAAI,CAACC,aAAa,EAClB,IAAI,CAACC,eAAe,EACpB,IAAI,CAACC,YAAY,EACjB,IAAI,CAACC,YAAY,EACjB,IAAI,CAACC,UAAU,GAAG,CACpB,CAAC;IAEP,IAAI,CAACR,QAAQ,CAACwB,YAAY,CAACiC,eAAe,CAAC,IAAI,CAAC5B,KAAK,EAAE;MACrD6B,IAAI,EAAE,YAAY;MAClBmB,IAAI,EAAEpC,aAAa,CAACZ;IACtB,CAAC,CAAC;IACF,IAAI,CAACnB,GAAG,CACN,6BAA6B,EAC7B+B,aAAa,CAACzD,IAAI,EAClB,IAAI,CAACkB,IAAI,EACTuC,aAAa,CAACvC,IAChB,CAAC;IACD,IAAI,CAAC,CAACL,cAAc,GAAG4C,aAAa;IACpC,IAAI,CAAChD,mBAAmB,CAACqF,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAACtC,aAAa,CAAC,CAAC;IAErE,OAAOA,aAAa;EACtB;AACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
1
2
|
import * as path from 'path';
|
|
2
|
-
import { compile, middleware, prefixer, serialize, stringify, tokenize, RULESET } from 'stylis';
|
|
3
|
+
import { compile, middleware, prefixer, serialize, stringify, tokenize, RULESET, KEYFRAMES, DECLARATION } from 'stylis';
|
|
3
4
|
const POSIX_SEP = path.posix.sep;
|
|
4
5
|
export function transformUrl(url, outputFilename, sourceFilename, platformPath = path) {
|
|
5
6
|
// Replace asset path with new path relative to the output CSS
|
|
@@ -11,12 +12,50 @@ export function transformUrl(url, outputFilename, sourceFilename, platformPath =
|
|
|
11
12
|
}
|
|
12
13
|
return relative.split(platformPath.sep).join(POSIX_SEP);
|
|
13
14
|
}
|
|
15
|
+
const DEFINED_KEYFRAMES = Symbol('definedKeyframes');
|
|
16
|
+
const ORIGINAL_VALUE_KEY = Symbol('originalValue');
|
|
17
|
+
const IS_GLOBAL_KEYFRAMES = Symbol('isGlobalKeyframes');
|
|
18
|
+
const getOriginalElementValue = element => {
|
|
19
|
+
return element ? element[ORIGINAL_VALUE_KEY] ?? element.value : '';
|
|
20
|
+
};
|
|
21
|
+
function throwIfNotProd(key, value, type) {
|
|
22
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
23
|
+
throw new Error(`"element.${key}" has type "${type}" (${JSON.stringify(value, null, 2)}), it's not expected. Please report a bug if it happens.`);
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
function childrenIsString(children) {
|
|
28
|
+
return typeof children === 'string' || throwIfNotProd('children', children, 'Element[]');
|
|
29
|
+
}
|
|
30
|
+
function propsAreStrings(props) {
|
|
31
|
+
return Array.isArray(props) || throwIfNotProd('props', props, 'string');
|
|
32
|
+
}
|
|
33
|
+
function propsIsString(props) {
|
|
34
|
+
return typeof props === 'string' || throwIfNotProd('props', props, 'string[]');
|
|
35
|
+
}
|
|
36
|
+
const isDeclaration = element => {
|
|
37
|
+
return element.type === DECLARATION && propsIsString(element.props) && childrenIsString(element.children);
|
|
38
|
+
};
|
|
39
|
+
const isKeyframes = element => {
|
|
40
|
+
return element.type === KEYFRAMES && propsAreStrings(element.props);
|
|
41
|
+
};
|
|
42
|
+
const isRuleset = element => {
|
|
43
|
+
return element.type === RULESET && propsAreStrings(element.props);
|
|
44
|
+
};
|
|
14
45
|
|
|
15
46
|
/**
|
|
16
47
|
* Stylis plugin that mimics :global() selector behavior from Stylis v3.
|
|
17
48
|
*/
|
|
18
49
|
export const stylisGlobalPlugin = element => {
|
|
19
|
-
function getGlobalSelectorModifiers(
|
|
50
|
+
function getGlobalSelectorModifiers(el) {
|
|
51
|
+
const {
|
|
52
|
+
parent
|
|
53
|
+
} = el;
|
|
54
|
+
const value = getOriginalElementValue(el);
|
|
55
|
+
const parentValue = getOriginalElementValue(parent);
|
|
56
|
+
if (parent?.children.length === 0 && parentValue.includes(':global(') || parent && !value.includes(':global(')) {
|
|
57
|
+
return getGlobalSelectorModifiers(parent);
|
|
58
|
+
}
|
|
20
59
|
const match = value.match(/(&\f( )?)?:global\(/);
|
|
21
60
|
if (match === null) {
|
|
22
61
|
throw new Error(`Failed to match :global() selector in "${value}". Please report a bug if it happens.`);
|
|
@@ -27,57 +66,51 @@ export const stylisGlobalPlugin = element => {
|
|
|
27
66
|
includeSpaceDelimiter: !!spaceDelimiter
|
|
28
67
|
};
|
|
29
68
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
69
|
+
if (!isRuleset(element)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
Object.assign(element, {
|
|
73
|
+
props: element.props.map(cssSelector => {
|
|
74
|
+
// The value can be changed by other middlewares, but we need an original one with `&`
|
|
38
75
|
Object.assign(element, {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!cssSelector.includes(':global(')) {
|
|
42
|
-
return cssSelector;
|
|
43
|
-
}
|
|
44
|
-
if (element.children.length === 0) {
|
|
45
|
-
Object.assign(element, {
|
|
46
|
-
global: getGlobalSelectorModifiers(element.value)
|
|
47
|
-
});
|
|
48
|
-
return cssSelector;
|
|
49
|
-
}
|
|
50
|
-
const {
|
|
51
|
-
includeBaseSelector,
|
|
52
|
-
includeSpaceDelimiter
|
|
53
|
-
} = element.parent?.global || getGlobalSelectorModifiers(element.value);
|
|
54
|
-
const tokens = tokenize(cssSelector);
|
|
55
|
-
let selector = '';
|
|
56
|
-
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
57
|
-
const token = tokens[i];
|
|
76
|
+
[ORIGINAL_VALUE_KEY]: element.value
|
|
77
|
+
});
|
|
58
78
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
// Avoids calling tokenize() on every string
|
|
80
|
+
if (!cssSelector.includes(':global(')) {
|
|
81
|
+
return cssSelector;
|
|
82
|
+
}
|
|
83
|
+
if (element.children.length === 0) {
|
|
84
|
+
return cssSelector;
|
|
85
|
+
}
|
|
86
|
+
const {
|
|
87
|
+
includeBaseSelector,
|
|
88
|
+
includeSpaceDelimiter
|
|
89
|
+
} = getGlobalSelectorModifiers(element);
|
|
90
|
+
const tokens = tokenize(cssSelector);
|
|
91
|
+
let selector = '';
|
|
92
|
+
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
93
|
+
const token = tokens[i];
|
|
68
94
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
95
|
+
//
|
|
96
|
+
// Match for ":global("
|
|
97
|
+
if (token === ':' && tokens[i + 1] === 'global') {
|
|
98
|
+
//
|
|
99
|
+
// Match for ":global()"
|
|
100
|
+
if (tokens[i + 2] === '()') {
|
|
101
|
+
selector = [...tokens.slice(i + 4), includeSpaceDelimiter ? ' ' : '', ...(includeBaseSelector ? tokens.slice(0, i - 1) : []), includeSpaceDelimiter ? '' : ' '].join('');
|
|
102
|
+
break;
|
|
74
103
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
104
|
+
|
|
105
|
+
//
|
|
106
|
+
// Match for ":global(selector)"
|
|
107
|
+
selector = [tokens[i + 2].slice(1, -1), includeSpaceDelimiter ? ' ' : '', ...(includeBaseSelector ? tokens.slice(0, i - 1) : []), includeSpaceDelimiter ? '' : ' '].join('');
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return selector;
|
|
112
|
+
})
|
|
113
|
+
});
|
|
81
114
|
};
|
|
82
115
|
export function createStylisUrlReplacePlugin(filename, outputFilename) {
|
|
83
116
|
return element => {
|
|
@@ -85,14 +118,101 @@ export function createStylisUrlReplacePlugin(filename, outputFilename) {
|
|
|
85
118
|
// When writing to a file, we need to adjust the relative paths inside url(..) expressions.
|
|
86
119
|
// It'll allow css-loader to resolve an imported asset properly.
|
|
87
120
|
// eslint-disable-next-line no-param-reassign
|
|
88
|
-
element.return = element.value.replace(/\b(url\((["']?))(\.[^)]+?)(\2\))/g, (
|
|
121
|
+
element.return = element.value.replace(/\b(url\((["']?))(\.[^)]+?)(\2\))/g, (_match, p1, _p2, p3, p4) => p1 + transformUrl(p3, outputFilename, filename) + p4);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export function createKeyframeSuffixerPlugin() {
|
|
126
|
+
const prefixes = ['webkit', 'moz', 'ms', 'o', ''].map(i => i ? `-${i}-` : '');
|
|
127
|
+
const getPrefixedProp = prop => prefixes.map(prefix => `${prefix}${prop}`);
|
|
128
|
+
const buildPropsRegexp = (prop, isAtRule) => {
|
|
129
|
+
const [at, colon] = isAtRule ? ['@', ''] : ['', ':'];
|
|
130
|
+
return new RegExp(`^(${at}(?:${getPrefixedProp(prop).join('|')})${colon})\\s*`);
|
|
131
|
+
};
|
|
132
|
+
const animationNameRegexp = /:global\(([\w_-]+)\)|([\w_-]+)/;
|
|
133
|
+
const getReplacer = (startsWith, searchValue, replacer) => {
|
|
134
|
+
return input => {
|
|
135
|
+
const [fullMatch] = input.match(startsWith) ?? [];
|
|
136
|
+
if (fullMatch === undefined) {
|
|
137
|
+
return input;
|
|
138
|
+
}
|
|
139
|
+
const rest = input.slice(fullMatch.length);
|
|
140
|
+
return fullMatch + rest.replace(searchValue, replacer);
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const elementToKeyframeSuffix = el => {
|
|
144
|
+
if (el.parent) {
|
|
145
|
+
return elementToKeyframeSuffix(el.parent);
|
|
146
|
+
}
|
|
147
|
+
return el.value.replaceAll(/[^a-zA-Z0-9_-]/g, '');
|
|
148
|
+
};
|
|
149
|
+
const animationPropsSet = new Set([...getPrefixedProp('animation'), ...getPrefixedProp('animation-name')]);
|
|
150
|
+
const getDefinedKeyframes = element => {
|
|
151
|
+
if (element[DEFINED_KEYFRAMES]) {
|
|
152
|
+
return element[DEFINED_KEYFRAMES];
|
|
153
|
+
}
|
|
154
|
+
if (element.parent) {
|
|
155
|
+
return getDefinedKeyframes(element.parent);
|
|
156
|
+
}
|
|
157
|
+
const keyframes = new Set();
|
|
158
|
+
for (const sibling of element.siblings ?? []) {
|
|
159
|
+
if (!isKeyframes(sibling) || sibling[IS_GLOBAL_KEYFRAMES] === true) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
keyframes.add(sibling.props[0]);
|
|
163
|
+
}
|
|
164
|
+
Object.assign(element, {
|
|
165
|
+
[DEFINED_KEYFRAMES]: keyframes
|
|
166
|
+
});
|
|
167
|
+
return keyframes;
|
|
168
|
+
};
|
|
169
|
+
return element => {
|
|
170
|
+
if (isKeyframes(element) && element.parent) {
|
|
171
|
+
const suffix = elementToKeyframeSuffix(element);
|
|
172
|
+
const replaceFn = (_match, globalMatch, scopedMatch) => globalMatch || `${scopedMatch}-${suffix}`;
|
|
173
|
+
Object.assign(element, {
|
|
174
|
+
[IS_GLOBAL_KEYFRAMES]: element.props[0]?.startsWith(':global(') ?? false,
|
|
175
|
+
props: element.props.map(getReplacer(/^\s*/, animationNameRegexp, replaceFn)),
|
|
176
|
+
value: getReplacer(buildPropsRegexp('keyframes', true), animationNameRegexp, replaceFn)(element.value)
|
|
177
|
+
});
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (isDeclaration(element)) {
|
|
181
|
+
const suffix = elementToKeyframeSuffix(element);
|
|
182
|
+
const keys = ['children', 'return', 'value'];
|
|
183
|
+
if (animationPropsSet.has(element.props)) {
|
|
184
|
+
const scopedKeyframes = getDefinedKeyframes(element);
|
|
185
|
+
const patch = Object.fromEntries(keys.map(key => {
|
|
186
|
+
const tokens = tokenize(element[key]);
|
|
187
|
+
let result = '';
|
|
188
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
189
|
+
if (tokens[i] === ':' && tokens[i + 1] === 'global' && tokens[i + 2].startsWith('(')) {
|
|
190
|
+
const globalName = tokens[i + 2].substring(1, tokens[i + 2].length - 1);
|
|
191
|
+
i += 2;
|
|
192
|
+
result += globalName;
|
|
193
|
+
if (tokens[i + 1] !== ';') {
|
|
194
|
+
result += ' ';
|
|
195
|
+
}
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (scopedKeyframes.has(tokens[i])) {
|
|
199
|
+
result += `${tokens[i]}-${suffix}`;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
result += tokens[i];
|
|
203
|
+
}
|
|
204
|
+
return [key, result];
|
|
205
|
+
}));
|
|
206
|
+
Object.assign(element, patch);
|
|
207
|
+
}
|
|
89
208
|
}
|
|
90
209
|
};
|
|
91
210
|
}
|
|
211
|
+
const isMiddleware = obj => obj !== null;
|
|
92
212
|
export function createStylisPreprocessor(options) {
|
|
93
213
|
function stylisPreprocess(selector, text) {
|
|
94
214
|
const compiled = compile(`${selector} {${text}}\n`);
|
|
95
|
-
return serialize(compiled, middleware([createStylisUrlReplacePlugin(options.filename, options.outputFilename), stylisGlobalPlugin, prefixer, stringify]));
|
|
215
|
+
return serialize(compiled, middleware([createStylisUrlReplacePlugin(options.filename, options.outputFilename), stylisGlobalPlugin, options.prefixer === false ? null : prefixer, createKeyframeSuffixerPlugin(), stringify].filter(isMiddleware)));
|
|
96
216
|
}
|
|
97
217
|
return stylisPreprocess;
|
|
98
218
|
}
|