@wyw-in-js/transform 1.0.6 → 1.0.8
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/cache.js +160 -12
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/module.js +59 -5
- package/esm/module.js.map +1 -1
- package/esm/plugins/shaker.js +152 -13
- package/esm/plugins/shaker.js.map +1 -1
- package/esm/shaker.js +51 -23
- package/esm/shaker.js.map +1 -1
- package/esm/transform/BaseEntrypoint.js +3 -1
- package/esm/transform/BaseEntrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.js +68 -20
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
- package/esm/transform/actions/BaseAction.js +2 -1
- package/esm/transform/actions/BaseAction.js.map +1 -1
- package/esm/transform/actions/actionRunner.js +2 -2
- package/esm/transform/actions/actionRunner.js.map +1 -1
- package/esm/transform/barrelManifest.js +291 -0
- package/esm/transform/barrelManifest.js.map +1 -0
- package/esm/transform/generators/getExports.js +5 -0
- package/esm/transform/generators/getExports.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +31 -1
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +29 -5
- package/esm/transform/generators/resolveImports.js.map +1 -1
- package/esm/transform/generators/rewriteBarrelImports.js +733 -0
- package/esm/transform/generators/rewriteBarrelImports.js.map +1 -0
- package/esm/transform/generators/transform.js +154 -21
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/types.js.map +1 -1
- package/esm/transform.js +45 -23
- package/esm/transform.js.map +1 -1
- package/esm/utils/collectTemplateDependencies.js +9 -0
- package/esm/utils/collectTemplateDependencies.js.map +1 -1
- package/lib/cache.js +163 -12
- package/lib/cache.js.map +1 -1
- package/lib/debug/fileReporter.js.map +1 -1
- package/lib/module.js +61 -7
- package/lib/module.js.map +1 -1
- package/lib/plugins/shaker.js +152 -13
- package/lib/plugins/shaker.js.map +1 -1
- package/lib/shaker.js +58 -26
- package/lib/shaker.js.map +1 -1
- package/lib/transform/BaseEntrypoint.js +3 -1
- package/lib/transform/BaseEntrypoint.js.map +1 -1
- package/lib/transform/Entrypoint.js +69 -20
- package/lib/transform/Entrypoint.js.map +1 -1
- package/lib/transform/EvaluatedEntrypoint.js.map +1 -1
- package/lib/transform/actions/BaseAction.js +2 -1
- package/lib/transform/actions/BaseAction.js.map +1 -1
- package/lib/transform/actions/actionRunner.js +2 -2
- package/lib/transform/actions/actionRunner.js.map +1 -1
- package/lib/transform/barrelManifest.js +300 -0
- package/lib/transform/barrelManifest.js.map +1 -0
- package/lib/transform/generators/getExports.js +5 -0
- package/lib/transform/generators/getExports.js.map +1 -1
- package/lib/transform/generators/processEntrypoint.js +31 -1
- package/lib/transform/generators/processEntrypoint.js.map +1 -1
- package/lib/transform/generators/resolveImports.js +29 -5
- package/lib/transform/generators/resolveImports.js.map +1 -1
- package/lib/transform/generators/rewriteBarrelImports.js +743 -0
- package/lib/transform/generators/rewriteBarrelImports.js.map +1 -0
- package/lib/transform/generators/transform.js +158 -22
- package/lib/transform/generators/transform.js.map +1 -1
- package/lib/transform/types.js.map +1 -1
- package/lib/transform.js +45 -23
- package/lib/transform.js.map +1 -1
- package/lib/utils/collectTemplateDependencies.js +9 -0
- package/lib/utils/collectTemplateDependencies.js.map +1 -1
- package/package.json +8 -4
- package/types/cache.d.ts +23 -2
- package/types/cache.js +170 -10
- package/types/debug/fileReporter.d.ts +1 -0
- package/types/module.d.ts +3 -0
- package/types/module.js +65 -5
- package/types/plugins/shaker.js +161 -16
- package/types/shaker.d.ts +10 -1
- package/types/shaker.js +56 -28
- package/types/transform/BaseEntrypoint.d.ts +3 -1
- package/types/transform/BaseEntrypoint.js +5 -1
- package/types/transform/Entrypoint.d.ts +10 -1
- package/types/transform/Entrypoint.js +81 -23
- package/types/transform/EvaluatedEntrypoint.d.ts +2 -0
- package/types/transform/actions/BaseAction.d.ts +2 -1
- package/types/transform/actions/BaseAction.js +3 -1
- package/types/transform/actions/actionRunner.js +2 -2
- package/types/transform/barrelManifest.d.ts +42 -0
- package/types/transform/barrelManifest.js +300 -0
- package/types/transform/generators/getExports.js +5 -0
- package/types/transform/generators/processEntrypoint.js +29 -1
- package/types/transform/generators/resolveImports.js +29 -5
- package/types/transform/generators/rewriteBarrelImports.d.ts +15 -0
- package/types/transform/generators/rewriteBarrelImports.js +815 -0
- package/types/transform/generators/transform.js +148 -19
- package/types/transform/types.d.ts +3 -0
- package/types/transform.js +47 -23
- package/types/utils/collectTemplateDependencies.js +9 -0
|
@@ -4,15 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Entrypoint = void 0;
|
|
7
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
7
8
|
var _tsInvariant = require("ts-invariant");
|
|
8
9
|
var _BaseEntrypoint = require("./BaseEntrypoint");
|
|
9
10
|
var _Entrypoint = require("./Entrypoint.helpers");
|
|
10
|
-
var _isStaticallyEvaluatableModule = require("./isStaticallyEvaluatableModule");
|
|
11
11
|
var _EvaluatedEntrypoint = require("./EvaluatedEntrypoint");
|
|
12
12
|
var _AbortError = require("./actions/AbortError");
|
|
13
13
|
var _BaseAction = require("./actions/BaseAction");
|
|
14
14
|
var _UnprocessedEntrypointError = require("./actions/UnprocessedEntrypointError");
|
|
15
|
+
var _parseRequest = require("../utils/parseRequest");
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
17
|
const EMPTY_FILE = '=== empty file ===';
|
|
18
|
+
const DEFAULT_ACTION_CONTEXT = Symbol('defaultActionContext');
|
|
16
19
|
function hasLoop(name, parent, processed = []) {
|
|
17
20
|
if (parent.name === name || processed.includes(parent.name)) {
|
|
18
21
|
return true;
|
|
@@ -30,14 +33,18 @@ class Entrypoint extends _BaseEntrypoint.BaseEntrypoint {
|
|
|
30
33
|
onSupersedeHandlers = [];
|
|
31
34
|
actionsCache = new Map();
|
|
32
35
|
#hasWywMetadata = false;
|
|
36
|
+
#isProcessing = false;
|
|
37
|
+
#pendingOnly = null;
|
|
33
38
|
#supersededWith = null;
|
|
34
39
|
#transformResultCode = null;
|
|
35
|
-
constructor(services, parents, initialCode, name, only, exports, evaluatedOnly, loadedAndParsed, resolveTasks = new Map(), dependencies = new Map(), generation = 1) {
|
|
40
|
+
constructor(services, parents, initialCode, name, only, exports, evaluatedOnly, loadedAndParsed, resolveTasks = new Map(), dependencies = new Map(), invalidationDependencies = new Map(), invalidateOnDependencyChange = new Set(), generation = 1) {
|
|
36
41
|
var _parents$0$log, _parents$;
|
|
37
|
-
super(services, evaluatedOnly, exports, generation, name, only, parents, dependencies);
|
|
42
|
+
super(services, evaluatedOnly, exports, generation, name, only, parents, dependencies, invalidationDependencies, invalidateOnDependencyChange);
|
|
38
43
|
this.initialCode = initialCode;
|
|
39
44
|
this.resolveTasks = resolveTasks;
|
|
40
45
|
this.dependencies = dependencies;
|
|
46
|
+
this.invalidationDependencies = invalidationDependencies;
|
|
47
|
+
this.invalidateOnDependencyChange = invalidateOnDependencyChange;
|
|
41
48
|
this.loadedAndParsed = loadedAndParsed !== null && loadedAndParsed !== void 0 ? loadedAndParsed : services.loadAndParseFn(services, name, initialCode, (_parents$0$log = (_parents$ = parents[0]) === null || _parents$ === void 0 ? void 0 : _parents$.log) !== null && _parents$0$log !== void 0 ? _parents$0$log : services.log);
|
|
42
49
|
if (this.loadedAndParsed.code !== undefined) {
|
|
43
50
|
services.cache.invalidateIfChanged(name, this.loadedAndParsed.code, undefined, this.initialCode === undefined ? 'fs' : 'loaded');
|
|
@@ -102,7 +109,16 @@ class Entrypoint extends _BaseEntrypoint.BaseEntrypoint {
|
|
|
102
109
|
cache
|
|
103
110
|
} = services;
|
|
104
111
|
const cached = cache.get('entrypoints', name);
|
|
105
|
-
|
|
112
|
+
let changed = false;
|
|
113
|
+
if (loadedCode !== undefined) {
|
|
114
|
+
changed = cache.invalidateIfChanged(name, loadedCode, undefined, 'loaded');
|
|
115
|
+
} else if (cached && cached.initialCode === undefined) {
|
|
116
|
+
try {
|
|
117
|
+
changed = cache.invalidateIfChanged(name, _nodeFs.default.readFileSync((0, _parseRequest.stripQueryAndHash)(name), 'utf8'), undefined, 'fs');
|
|
118
|
+
} catch {
|
|
119
|
+
changed = false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
106
122
|
if (!(cached !== null && cached !== void 0 && cached.evaluated) && cached !== null && cached !== void 0 && cached.ignored) {
|
|
107
123
|
return ['cached', cached];
|
|
108
124
|
}
|
|
@@ -125,19 +141,14 @@ class Entrypoint extends _BaseEntrypoint.BaseEntrypoint {
|
|
|
125
141
|
return [isLoop ? 'loop' : 'cached', cached];
|
|
126
142
|
}
|
|
127
143
|
cached.log('is cached, but with different `only` %o (the cached one %o)', only, cached === null || cached === void 0 ? void 0 : cached.only);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const {
|
|
133
|
-
ast
|
|
134
|
-
} = newEntrypoint.loadedAndParsed;
|
|
135
|
-
if (ast && (0, _isStaticallyEvaluatableModule.isStaticallyEvaluatableModule)(ast)) {
|
|
136
|
-
newEntrypoint.log('[entrypoint] promote `only` to "*" for statically evaluatable module');
|
|
137
|
-
newEntrypoint.only.length = 0;
|
|
138
|
-
newEntrypoint.only.push('*');
|
|
144
|
+
if (cached.#isProcessing) {
|
|
145
|
+
cached.deferOnlySupersede(mergedOnly);
|
|
146
|
+
cached.log('is being processed, defer supersede (%o -> %o)', cached.only, mergedOnly);
|
|
147
|
+
return [isLoop ? 'loop' : 'cached', cached];
|
|
139
148
|
}
|
|
149
|
+
return [isLoop ? 'loop' : 'created', cached.supersede(mergedOnly)];
|
|
140
150
|
}
|
|
151
|
+
const newEntrypoint = new Entrypoint(services, parent ? [parent] : [], loadedCode, name, mergedOnly, exports, evaluatedOnly, undefined, cached && 'resolveTasks' in cached ? cached.resolveTasks : undefined, cached && 'dependencies' in cached ? cached.dependencies : undefined, cached && 'invalidationDependencies' in cached ? cached.invalidationDependencies : undefined, cached && 'invalidateOnDependencyChange' in cached ? cached.invalidateOnDependencyChange : undefined, cached ? cached.generation + 1 : 1);
|
|
141
152
|
if (cached && !cached.evaluated) {
|
|
142
153
|
cached.log('is cached, but with different code');
|
|
143
154
|
cached.supersede(newEntrypoint);
|
|
@@ -148,9 +159,27 @@ class Entrypoint extends _BaseEntrypoint.BaseEntrypoint {
|
|
|
148
159
|
this.resolveTasks.delete(dependency.source);
|
|
149
160
|
this.dependencies.set(dependency.source, dependency);
|
|
150
161
|
}
|
|
162
|
+
addInvalidationDependency(dependency) {
|
|
163
|
+
this.resolveTasks.delete(dependency.source);
|
|
164
|
+
this.invalidationDependencies.set(dependency.source, dependency);
|
|
165
|
+
}
|
|
151
166
|
addResolveTask(name, dependency) {
|
|
152
167
|
this.resolveTasks.set(name, dependency);
|
|
153
168
|
}
|
|
169
|
+
applyDeferredSupersede() {
|
|
170
|
+
if (this.#supersededWith || this.#pendingOnly === null) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const mergedOnly = (0, _Entrypoint.mergeOnly)(this.only, this.#pendingOnly);
|
|
174
|
+
this.#pendingOnly = null;
|
|
175
|
+
if ((0, _Entrypoint.isSuperSet)(this.only, mergedOnly)) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
this.log('apply deferred supersede (%o -> %o)', this.only, mergedOnly);
|
|
179
|
+
const nextEntrypoint = this.supersede(mergedOnly);
|
|
180
|
+
this.services.cache.add('entrypoints', this.name, nextEntrypoint);
|
|
181
|
+
return nextEntrypoint;
|
|
182
|
+
}
|
|
154
183
|
assertNotSuperseded() {
|
|
155
184
|
if (this.supersededWith) {
|
|
156
185
|
this.log('superseded');
|
|
@@ -164,17 +193,24 @@ class Entrypoint extends _BaseEntrypoint.BaseEntrypoint {
|
|
|
164
193
|
throw new _UnprocessedEntrypointError.UnprocessedEntrypointError((_this$supersededWith3 = this.supersededWith) !== null && _this$supersededWith3 !== void 0 ? _this$supersededWith3 : this);
|
|
165
194
|
}
|
|
166
195
|
}
|
|
167
|
-
|
|
196
|
+
beginProcessing() {
|
|
197
|
+
this.#isProcessing = true;
|
|
198
|
+
}
|
|
199
|
+
createAction(actionType, data, abortSignal = null, actionContext = DEFAULT_ACTION_CONTEXT) {
|
|
168
200
|
var _cached$abortSignal;
|
|
169
201
|
if (!this.actionsCache.has(actionType)) {
|
|
170
202
|
this.actionsCache.set(actionType, new Map());
|
|
171
203
|
}
|
|
172
|
-
const
|
|
204
|
+
const contexts = this.actionsCache.get(actionType);
|
|
205
|
+
if (!contexts.has(actionContext)) {
|
|
206
|
+
contexts.set(actionContext, new Map());
|
|
207
|
+
}
|
|
208
|
+
const cache = contexts.get(actionContext);
|
|
173
209
|
const cached = cache.get(data);
|
|
174
210
|
if (cached && !((_cached$abortSignal = cached.abortSignal) !== null && _cached$abortSignal !== void 0 && _cached$abortSignal.aborted)) {
|
|
175
211
|
return cached;
|
|
176
212
|
}
|
|
177
|
-
const newAction = new _BaseAction.BaseAction(actionType, this.services, this, data, abortSignal);
|
|
213
|
+
const newAction = new _BaseAction.BaseAction(actionType, this.services, this, data, abortSignal, actionContext);
|
|
178
214
|
cache.set(data, newAction);
|
|
179
215
|
this.services.eventEmitter.entrypointEvent(this.seqId, {
|
|
180
216
|
type: 'actionCreated',
|
|
@@ -189,13 +225,22 @@ class Entrypoint extends _BaseEntrypoint.BaseEntrypoint {
|
|
|
189
225
|
createEvaluated() {
|
|
190
226
|
const evaluatedOnly = (0, _Entrypoint.mergeOnly)(this.evaluatedOnly, this.only);
|
|
191
227
|
this.log('create EvaluatedEntrypoint for %o', evaluatedOnly);
|
|
192
|
-
const evaluated = new _EvaluatedEntrypoint.EvaluatedEntrypoint(this.services, evaluatedOnly, this.exportsProxy, this.generation + 1, this.name, this.only, this.parents, this.dependencies);
|
|
228
|
+
const evaluated = new _EvaluatedEntrypoint.EvaluatedEntrypoint(this.services, evaluatedOnly, this.exportsProxy, this.generation + 1, this.name, this.only, this.parents, this.dependencies, this.invalidationDependencies, this.invalidateOnDependencyChange);
|
|
193
229
|
evaluated.initialCode = this.initialCode;
|
|
194
230
|
return evaluated;
|
|
195
231
|
}
|
|
232
|
+
endProcessing() {
|
|
233
|
+
this.#isProcessing = false;
|
|
234
|
+
}
|
|
196
235
|
getDependency(name) {
|
|
197
236
|
return this.dependencies.get(name);
|
|
198
237
|
}
|
|
238
|
+
getInvalidationDependency(name) {
|
|
239
|
+
return this.invalidationDependencies.get(name);
|
|
240
|
+
}
|
|
241
|
+
markInvalidateOnDependencyChange(filename) {
|
|
242
|
+
this.invalidateOnDependencyChange.add(filename);
|
|
243
|
+
}
|
|
199
244
|
getResolveTask(name) {
|
|
200
245
|
return this.resolveTasks.get(name);
|
|
201
246
|
}
|
|
@@ -224,8 +269,12 @@ class Entrypoint extends _BaseEntrypoint.BaseEntrypoint {
|
|
|
224
269
|
type: 'setTransformResult'
|
|
225
270
|
});
|
|
226
271
|
}
|
|
272
|
+
deferOnlySupersede(only) {
|
|
273
|
+
this.#pendingOnly = this.#pendingOnly ? (0, _Entrypoint.mergeOnly)(this.#pendingOnly, only) : [...only];
|
|
274
|
+
}
|
|
227
275
|
supersede(newOnlyOrEntrypoint) {
|
|
228
|
-
|
|
276
|
+
this.#pendingOnly = null;
|
|
277
|
+
const newEntrypoint = newOnlyOrEntrypoint instanceof Entrypoint ? newOnlyOrEntrypoint : new Entrypoint(this.services, this.parents, this.initialCode, this.name, newOnlyOrEntrypoint, this.exports, this.evaluatedOnly, this.loadedAndParsed, this.resolveTasks, this.dependencies, this.invalidationDependencies, this.invalidateOnDependencyChange, this.generation + 1);
|
|
229
278
|
this.services.eventEmitter.entrypointEvent(this.seqId, {
|
|
230
279
|
type: 'superseded',
|
|
231
280
|
with: newEntrypoint.seqId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entrypoint.js","names":["_tsInvariant","require","_BaseEntrypoint","_Entrypoint","_isStaticallyEvaluatableModule","_EvaluatedEntrypoint","_AbortError","_BaseAction","_UnprocessedEntrypointError","EMPTY_FILE","hasLoop","name","parent","processed","includes","p","parents","found","Entrypoint","BaseEntrypoint","evaluated","onSupersedeHandlers","actionsCache","Map","hasWywMetadata","supersededWith","transformResultCode","constructor","services","initialCode","only","exports","evaluatedOnly","loadedAndParsed","resolveTasks","dependencies","generation","_parents$0$log","_parents$","loadAndParseFn","log","code","undefined","cache","invalidateIfChanged","evaluator","originalCode","extend","ignored","_this$supersededWith$","_this$supersededWith","transformedCode","_ref","_this$transformResult","_this$supersededWith2","createRoot","loadedCode","created","create","invariant","eventEmitter","perf","status","entrypoint","innerCreate","seqId","add","_cached$evaluatedOnly","cached","get","changed","mergedOnly","mergeOnly","isLoop","map","push","isSuperSet","supersede","newEntrypoint","ast","isStaticallyEvaluatableModule","length","addDependency","dependency","delete","source","set","addResolveTask","assertNotSuperseded","AbortError","assertTransformed","_this$supersededWith3","UnprocessedEntrypointError","createAction","actionType","data","abortSignal","_cached$abortSignal","has","aborted","newAction","BaseAction","entrypointEvent","type","actionIdx","idx","createChild","createEvaluated","EvaluatedEntrypoint","exportsProxy","getDependency","getResolveTask","onSupersede","callback","index","indexOf","splice","setTransformResult","res","_res$code","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 { isStaticallyEvaluatableModule } from './isStaticallyEvaluatableModule';\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 readonly dependencies = new Map<string, IEntrypointDependency>(),\n generation = 1\n ) {\n super(\n services,\n evaluatedOnly,\n exports,\n generation,\n name,\n only,\n parents,\n dependencies\n );\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(\n name,\n this.loadedAndParsed.code,\n undefined,\n this.initialCode === undefined ? 'fs' : 'loaded'\n );\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, undefined, 'loaded')\n : false;\n\n if (!cached?.evaluated && cached?.ignored) {\n return ['cached', cached];\n }\n\n const exports = cached?.exports;\n const evaluatedOnly = changed ? [] : cached?.evaluatedOnly ?? [];\n\n const mergedOnly = cached?.only ? mergeOnly(cached.only, only) : [...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 (\n !newEntrypoint.ignored &&\n !newEntrypoint.only.includes('*') &&\n !newEntrypoint.only.includes('__wywPreval') &&\n !newEntrypoint.only.includes('side-effect')\n ) {\n const { ast } = newEntrypoint.loadedAndParsed;\n\n if (ast && isStaticallyEvaluatableModule(ast)) {\n newEntrypoint.log(\n '[entrypoint] promote `only` to \"*\" for statically evaluatable module'\n );\n newEntrypoint.only.length = 0;\n newEntrypoint.only.push('*');\n }\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 const evaluated = new EvaluatedEntrypoint(\n this.services,\n evaluatedOnly,\n this.exportsProxy,\n this.generation + 1,\n this.name,\n this.only,\n this.parents,\n this.dependencies\n );\n\n evaluated.initialCode = this.initialCode;\n\n return evaluated;\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,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,8BAAA,GAAAH,OAAA;AAMA,IAAAI,oBAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAEA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,2BAAA,GAAAP,OAAA;A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jB,IAAI,CAACC,YAAY,EACjB,IAAI,CAACC,UAAU,GAAG,CACpB,CAAC;IAEP,IAAI,CAACR,QAAQ,CAACgC,YAAY,CAAC0C,eAAe,CAAC,IAAI,CAACrC,KAAK,EAAE;MACrDsC,IAAI,EAAE,YAAY;MAClBqB,IAAI,EAAE9C,aAAa,CAACb;IACtB,CAAC,CAAC;IACF,IAAI,CAACzB,GAAG,CACN,6BAA6B,EAC7BsC,aAAa,CAACnE,IAAI,EAClB,IAAI,CAACmB,IAAI,EACTgD,aAAa,CAAChD,IAChB,CAAC;IACD,IAAI,CAAC,CAACL,cAAc,GAAGqD,aAAa;IACpC,IAAI,CAACzD,mBAAmB,CAACwG,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAAChD,aAAa,CAAC,CAAC;IAErE,OAAOA,aAAa;EACtB;AACF;AAAC/C,OAAA,CAAAb,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Entrypoint.js","names":["_nodeFs","_interopRequireDefault","require","_tsInvariant","_BaseEntrypoint","_Entrypoint","_EvaluatedEntrypoint","_AbortError","_BaseAction","_UnprocessedEntrypointError","_parseRequest","e","__esModule","default","EMPTY_FILE","DEFAULT_ACTION_CONTEXT","Symbol","hasLoop","name","parent","processed","includes","p","parents","found","Entrypoint","BaseEntrypoint","evaluated","onSupersedeHandlers","actionsCache","Map","hasWywMetadata","isProcessing","pendingOnly","supersededWith","transformResultCode","constructor","services","initialCode","only","exports","evaluatedOnly","loadedAndParsed","resolveTasks","dependencies","invalidationDependencies","invalidateOnDependencyChange","Set","generation","_parents$0$log","_parents$","loadAndParseFn","log","code","undefined","cache","invalidateIfChanged","evaluator","originalCode","extend","ignored","_this$supersededWith$","_this$supersededWith","transformedCode","_ref","_this$transformResult","_this$supersededWith2","createRoot","loadedCode","created","create","invariant","eventEmitter","perf","status","entrypoint","innerCreate","seqId","add","_cached$evaluatedOnly","cached","get","changed","fs","readFileSync","stripQueryAndHash","mergedOnly","mergeOnly","isLoop","map","push","isSuperSet","deferOnlySupersede","supersede","newEntrypoint","addDependency","dependency","delete","source","set","addInvalidationDependency","addResolveTask","applyDeferredSupersede","nextEntrypoint","assertNotSuperseded","AbortError","assertTransformed","_this$supersededWith3","UnprocessedEntrypointError","beginProcessing","createAction","actionType","data","abortSignal","actionContext","_cached$abortSignal","has","contexts","aborted","newAction","BaseAction","entrypointEvent","type","actionIdx","idx","createChild","createEvaluated","EvaluatedEntrypoint","exportsProxy","endProcessing","getDependency","getInvalidationDependency","markInvalidateOnDependencyChange","filename","getResolveTask","onSupersede","callback","index","indexOf","splice","setTransformResult","res","_res$code","Boolean","metadata","isNull","newOnlyOrEntrypoint","with","forEach","handler"],"sources":["../../src/transform/Entrypoint.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { 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';\nimport { stripQueryAndHash } from '../utils/parseRequest';\n\nconst EMPTY_FILE = '=== empty file ===';\nconst DEFAULT_ACTION_CONTEXT = Symbol('defaultActionContext');\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, Map<unknown, BaseAction<ActionQueueItem>>>\n > = new Map();\n\n #hasWywMetadata: boolean = false;\n\n #isProcessing = false;\n\n #pendingOnly: string[] | null = null;\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 readonly dependencies = new Map<string, IEntrypointDependency>(),\n readonly invalidationDependencies = new Map<\n string,\n IEntrypointDependency\n >(),\n readonly invalidateOnDependencyChange = new Set<string>(),\n generation = 1\n ) {\n super(\n services,\n evaluatedOnly,\n exports,\n generation,\n name,\n only,\n parents,\n dependencies,\n invalidationDependencies,\n invalidateOnDependencyChange\n );\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(\n name,\n this.loadedAndParsed.code,\n undefined,\n this.initialCode === undefined ? 'fs' : 'loaded'\n );\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 let changed = false;\n if (loadedCode !== undefined) {\n changed = cache.invalidateIfChanged(\n name,\n loadedCode,\n undefined,\n 'loaded'\n );\n } else if (cached && cached.initialCode === undefined) {\n try {\n changed = cache.invalidateIfChanged(\n name,\n fs.readFileSync(stripQueryAndHash(name), 'utf8'),\n undefined,\n 'fs'\n );\n } catch {\n changed = false;\n }\n }\n\n if (!cached?.evaluated && cached?.ignored) {\n return ['cached', cached];\n }\n\n const exports = cached?.exports;\n const evaluatedOnly = changed ? [] : cached?.evaluatedOnly ?? [];\n\n const mergedOnly = cached?.only ? mergeOnly(cached.only, only) : [...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 if (cached.#isProcessing) {\n cached.deferOnlySupersede(mergedOnly);\n cached.log(\n 'is being processed, defer supersede (%o -> %o)',\n cached.only,\n mergedOnly\n );\n return [isLoop ? 'loop' : 'cached', cached];\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 && 'invalidationDependencies' in cached\n ? cached.invalidationDependencies\n : undefined,\n cached && 'invalidateOnDependencyChange' in cached\n ? cached.invalidateOnDependencyChange\n : 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 addInvalidationDependency(dependency: IEntrypointDependency): void {\n this.resolveTasks.delete(dependency.source);\n this.invalidationDependencies.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 applyDeferredSupersede() {\n if (this.#supersededWith || this.#pendingOnly === null) {\n return null;\n }\n\n const mergedOnly = mergeOnly(this.only, this.#pendingOnly);\n this.#pendingOnly = null;\n\n if (isSuperSet(this.only, mergedOnly)) {\n return null;\n }\n\n this.log('apply deferred supersede (%o -> %o)', this.only, mergedOnly);\n\n const nextEntrypoint = this.supersede(mergedOnly);\n this.services.cache.add('entrypoints', this.name, nextEntrypoint);\n\n return nextEntrypoint;\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 beginProcessing() {\n this.#isProcessing = true;\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 actionContext: unknown = DEFAULT_ACTION_CONTEXT\n ): BaseAction<TAction> {\n if (!this.actionsCache.has(actionType)) {\n this.actionsCache.set(actionType, new Map());\n }\n\n const contexts = this.actionsCache.get(actionType)!;\n if (!contexts.has(actionContext)) {\n contexts.set(actionContext, new Map());\n }\n\n const cache = contexts.get(actionContext)!;\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 actionContext\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 const evaluated = new EvaluatedEntrypoint(\n this.services,\n evaluatedOnly,\n this.exportsProxy,\n this.generation + 1,\n this.name,\n this.only,\n this.parents,\n this.dependencies,\n this.invalidationDependencies,\n this.invalidateOnDependencyChange\n );\n\n evaluated.initialCode = this.initialCode;\n\n return evaluated;\n }\n\n public endProcessing() {\n this.#isProcessing = false;\n }\n\n public getDependency(name: string): IEntrypointDependency | undefined {\n return this.dependencies.get(name);\n }\n\n public getInvalidationDependency(\n name: string\n ): IEntrypointDependency | undefined {\n return this.invalidationDependencies.get(name);\n }\n\n public markInvalidateOnDependencyChange(filename: string): void {\n this.invalidateOnDependencyChange.add(filename);\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 deferOnlySupersede(only: string[]) {\n this.#pendingOnly = this.#pendingOnly\n ? mergeOnly(this.#pendingOnly, only)\n : [...only];\n }\n\n private supersede(newOnlyOrEntrypoint: string[] | Entrypoint): Entrypoint {\n this.#pendingOnly = null;\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.invalidationDependencies,\n this.invalidateOnDependencyChange,\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,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAIA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAMA,IAAAI,oBAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAEA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,2BAAA,GAAAP,OAAA;AAEA,IAAAQ,aAAA,GAAAR,OAAA;AAA0D,SAAAD,uBAAAU,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1D,MAAMG,UAAU,GAAG,oBAAoB;AACvC,MAAMC,sBAAsB,GAAGC,MAAM,CAAC,sBAAsB,CAAC;AAE7D,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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Ac,GAAG4D,aAAa;IACpC,IAAI,CAAClE,mBAAmB,CAACwH,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAACvD,aAAa,CAAC,CAAC;IAErE,OAAOA,aAAa;EACtB;AACF;AAACtD,OAAA,CAAAf,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EvaluatedEntrypoint.js","names":["_BaseEntrypoint","require","EvaluatedEntrypoint","BaseEntrypoint","evaluated","ignored","exports"],"sources":["../../src/transform/EvaluatedEntrypoint.ts"],"sourcesContent":["import type { Debugger } from '@wyw-in-js/shared';\n\nimport { BaseEntrypoint } from './BaseEntrypoint';\nimport type { IEntrypointDependency } from './Entrypoint.types';\n\nexport interface IEvaluatedEntrypoint {\n dependencies: Map<string, IEntrypointDependency>;\n evaluated: true;\n evaluatedOnly: string[];\n exports: Record<string | symbol, unknown>;\n generation: number;\n ignored: false;\n initialCode?: string;\n log: Debugger;\n only: string[];\n}\n\nexport class EvaluatedEntrypoint\n extends BaseEntrypoint\n implements IEvaluatedEntrypoint\n{\n public readonly evaluated = true;\n\n public readonly ignored = false;\n\n public initialCode?: string;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,eAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"file":"EvaluatedEntrypoint.js","names":["_BaseEntrypoint","require","EvaluatedEntrypoint","BaseEntrypoint","evaluated","ignored","exports"],"sources":["../../src/transform/EvaluatedEntrypoint.ts"],"sourcesContent":["import type { Debugger } from '@wyw-in-js/shared';\n\nimport { BaseEntrypoint } from './BaseEntrypoint';\nimport type { IEntrypointDependency } from './Entrypoint.types';\n\nexport interface IEvaluatedEntrypoint {\n dependencies: Map<string, IEntrypointDependency>;\n evaluated: true;\n evaluatedOnly: string[];\n exports: Record<string | symbol, unknown>;\n generation: number;\n ignored: false;\n initialCode?: string;\n invalidationDependencies: Map<string, IEntrypointDependency>;\n invalidateOnDependencyChange: Set<string>;\n log: Debugger;\n only: string[];\n}\n\nexport class EvaluatedEntrypoint\n extends BaseEntrypoint\n implements IEvaluatedEntrypoint\n{\n public readonly evaluated = true;\n\n public readonly ignored = false;\n\n public initialCode?: string;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,eAAA,GAAAC,OAAA;AAiBO,MAAMC,mBAAmB,SACtBC,8BAAc,CAExB;EACkBC,SAAS,GAAG,IAAI;EAEhBC,OAAO,GAAG,KAAK;AAGjC;AAACC,OAAA,CAAAJ,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -14,12 +14,13 @@ class BaseAction {
|
|
|
14
14
|
activeScenario = null;
|
|
15
15
|
activeScenarioNextResults = [];
|
|
16
16
|
handler = null;
|
|
17
|
-
constructor(type, services, entrypoint, data, abortSignal) {
|
|
17
|
+
constructor(type, services, entrypoint, data, abortSignal, actionContext) {
|
|
18
18
|
this.type = type;
|
|
19
19
|
this.services = services;
|
|
20
20
|
this.entrypoint = entrypoint;
|
|
21
21
|
this.data = data;
|
|
22
22
|
this.abortSignal = abortSignal;
|
|
23
|
+
this.actionContext = actionContext;
|
|
23
24
|
actionIdx += 1;
|
|
24
25
|
this.idx = actionIdx.toString(16).padStart(6, '0');
|
|
25
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseAction.js","names":["require","_types","actionIdx","BaseAction","result","Pending","activeScenario","activeScenarioNextResults","handler","constructor","type","services","entrypoint","data","abortSignal","idx","toString","padStart","log","extend","ref","createAbortSignal","abortController","AbortController","unsubscribeFromParentAbort","onAbort","abort","unsubscribeFromSupersede","onSupersede","signal","Symbol","dispose","getNext","fn","_this$abortSignal","addEventListener","_this$abortSignal2","removeEventListener","run","Error","name","call","nextIdx","throwFn","e","emitAction","throw","nextFn","arg","next","processNextResult","onError","then","r","done","value","push","processError","length","nextResult","errorInGenerator","recover","activeScenarioError","processNext","rethrowActiveScenarioError","yieldIdx","eventEmitter","action","exports"],"sources":["../../../src/transform/actions/BaseAction.ts"],"sourcesContent":["/* eslint-disable no-plusplus */\nimport '../../utils/dispose-polyfill';\nimport type { Debugger } from '@wyw-in-js/shared';\n\nimport type { Entrypoint } from '../Entrypoint';\nimport type {\n ActionQueueItem,\n ActionTypes,\n AnyIteratorResult,\n AsyncScenarioForAction,\n Handler,\n IBaseAction,\n Services,\n SyncScenarioForAction,\n TypeOfResult,\n YieldResult,\n} from '../types';\nimport { Pending } from '../types';\n\nlet actionIdx = 0;\n\nexport type ActionByType<TType extends ActionTypes> = Extract<\n ActionQueueItem,\n {\n type: TType;\n }\n>;\n\ntype GetBase<TAction extends ActionQueueItem> = IBaseAction<\n TAction,\n TypeOfResult<TAction>,\n TAction['data']\n>;\n\nexport class BaseAction<TAction extends ActionQueueItem>\n implements GetBase<TAction>\n{\n public readonly idx: string;\n\n public result: TypeOfResult<TAction> | typeof Pending = Pending;\n\n private activeScenario:\n | SyncScenarioForAction<TAction>\n | AsyncScenarioForAction<TAction>\n | null = null;\n\n private activeScenarioError?: unknown;\n\n private activeScenarioNextResults: AnyIteratorResult<\n 'async' | 'sync',\n TypeOfResult<TAction>\n >[] = [];\n\n private handler: null | unknown = null;\n\n public constructor(\n public readonly type: TAction['type'],\n public readonly services: Services,\n public readonly entrypoint: Entrypoint,\n public readonly data: TAction['data'],\n public readonly abortSignal: AbortSignal | null\n ) {\n actionIdx += 1;\n this.idx = actionIdx.toString(16).padStart(6, '0');\n }\n\n public get log(): Debugger {\n return this.entrypoint.log.extend(this.ref);\n }\n\n public get ref() {\n return `${this.type}@${this.idx}`;\n }\n\n public createAbortSignal(): AbortSignal & Disposable {\n const abortController = new AbortController();\n\n const unsubscribeFromParentAbort = this.onAbort(() => {\n this.entrypoint.log('parent aborted');\n abortController.abort();\n });\n\n const unsubscribeFromSupersede = this.entrypoint.onSupersede(() => {\n this.entrypoint.log('entrypoint superseded, aborting processing');\n abortController.abort();\n });\n\n const abortSignal = abortController.signal as AbortSignal & Disposable;\n abortSignal[Symbol.dispose] = () => {\n unsubscribeFromParentAbort();\n unsubscribeFromSupersede();\n };\n\n return abortSignal;\n }\n\n public *getNext<\n TNextType extends ActionTypes,\n TNextAction extends ActionByType<TNextType> = ActionByType<TNextType>,\n >(\n type: TNextType,\n entrypoint: Entrypoint,\n data: TNextAction['data'],\n abortSignal: AbortSignal | null = this.abortSignal\n ): Generator<\n [TNextType, Entrypoint, TNextAction['data'], AbortSignal | null],\n TypeOfResult<TNextAction>,\n YieldResult\n > {\n return (yield [\n type,\n entrypoint,\n data,\n abortSignal,\n ]) as TypeOfResult<TNextAction>;\n }\n\n public onAbort(fn: () => void): () => void {\n this.abortSignal?.addEventListener('abort', fn);\n\n return () => {\n this.abortSignal?.removeEventListener('abort', fn);\n };\n }\n\n public run<\n TMode extends 'async' | 'sync',\n THandler extends Handler<TMode, TAction> = Handler<TMode, TAction>,\n >(handler: THandler) {\n type IterationResult = AnyIteratorResult<TMode, TypeOfResult<TAction>>;\n\n if (this.handler && this.handler !== handler) {\n throw new Error(\n `action handler is already set for ${this.ref} (${this.entrypoint.name})`\n );\n }\n\n this.handler = handler;\n\n if (!this.activeScenario) {\n this.activeScenario = handler.call(this);\n this.activeScenarioNextResults = [];\n }\n\n let nextIdx = 0;\n\n const throwFn = (e: unknown) =>\n this.emitAction(nextIdx, () => this.activeScenario!.throw(e));\n\n const nextFn = (arg: YieldResult) =>\n this.emitAction(nextIdx, () => this.activeScenario!.next(arg));\n\n const processNextResult = (\n result: IterationResult,\n onError?: (e: unknown) => void\n ) => {\n if ('then' in result) {\n result.then((r) => {\n if (r.done) {\n this.result = r.value;\n }\n }, onError);\n } else if (result.done) {\n this.result = result.value;\n }\n\n this.activeScenarioNextResults.push(result);\n };\n\n const processError = (e: unknown) => {\n if (this.activeScenarioNextResults.length > nextIdx) {\n this.log(\n 'error was already handled in another branch, result idx is %d',\n nextIdx\n );\n return;\n }\n\n this.log('error processing, result idx is %d', nextIdx);\n\n try {\n const nextResult = throwFn(e);\n processNextResult(nextResult as IterationResult, processError);\n } catch (errorInGenerator) {\n const { recover } = handler;\n if (recover) {\n const nextResult = {\n done: false,\n value: recover(errorInGenerator, this),\n };\n\n processNextResult(nextResult as IterationResult, processError);\n return;\n }\n\n this.activeScenarioError = errorInGenerator;\n throw errorInGenerator;\n }\n };\n\n const processNext = (arg: YieldResult) => {\n if (this.activeScenarioNextResults.length > nextIdx) {\n this.log(\n 'next was already handled in another branch, result idx is %d',\n nextIdx\n );\n return;\n }\n\n this.log('next processing, result idx is %d', nextIdx);\n\n try {\n const nextResult = nextFn(arg);\n processNextResult(nextResult as IterationResult, processError);\n } catch (e) {\n processError(e);\n }\n };\n\n return {\n next: (arg: YieldResult): IterationResult => {\n this.rethrowActiveScenarioError();\n processNext(arg);\n return this.activeScenarioNextResults[nextIdx++] as IterationResult;\n },\n throw: (e: unknown): IterationResult => {\n this.rethrowActiveScenarioError();\n processError(e);\n return this.activeScenarioNextResults[nextIdx++] as IterationResult;\n },\n };\n }\n\n protected emitAction<TRes>(yieldIdx: number, fn: () => TRes) {\n return this.services.eventEmitter.action(\n this.type,\n `${this.idx}:${yieldIdx + 1}`,\n this.entrypoint.ref,\n fn\n );\n }\n\n private rethrowActiveScenarioError() {\n if (!this.activeScenarioError) {\n return;\n }\n\n this.log(\n 'scenario has an unhandled error from another branch, rethrow %o',\n this.activeScenarioError\n );\n\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw this.activeScenarioError;\n }\n}\n"],"mappings":";;;;;;AACAA,OAAA;AAgBA,IAAAC,MAAA,GAAAD,OAAA;AAjBA;;AAmBA,IAAIE,SAAS,GAAG,CAAC;AAeV,MAAMC,UAAU,CAEvB;EAGSC,MAAM,GAA2CC,cAAO;EAEvDC,cAAc,GAGX,IAAI;EAIPC,yBAAyB,GAG3B,EAAE;EAEAC,OAAO,GAAmB,IAAI;EAE/BC,WAAWA,CACAC,IAAqB,EACrBC,QAAkB,EAClBC,UAAsB,EACtBC,IAAqB,EACrBC,WAA+B,EAC/C;IAAA,KALgBJ,IAAqB,GA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]}
|
|
1
|
+
{"version":3,"file":"BaseAction.js","names":["require","_types","actionIdx","BaseAction","result","Pending","activeScenario","activeScenarioNextResults","handler","constructor","type","services","entrypoint","data","abortSignal","actionContext","idx","toString","padStart","log","extend","ref","createAbortSignal","abortController","AbortController","unsubscribeFromParentAbort","onAbort","abort","unsubscribeFromSupersede","onSupersede","signal","Symbol","dispose","getNext","fn","_this$abortSignal","addEventListener","_this$abortSignal2","removeEventListener","run","Error","name","call","nextIdx","throwFn","e","emitAction","throw","nextFn","arg","next","processNextResult","onError","then","r","done","value","push","processError","length","nextResult","errorInGenerator","recover","activeScenarioError","processNext","rethrowActiveScenarioError","yieldIdx","eventEmitter","action","exports"],"sources":["../../../src/transform/actions/BaseAction.ts"],"sourcesContent":["/* eslint-disable no-plusplus */\nimport '../../utils/dispose-polyfill';\nimport type { Debugger } from '@wyw-in-js/shared';\n\nimport type { Entrypoint } from '../Entrypoint';\nimport type {\n ActionQueueItem,\n ActionTypes,\n AnyIteratorResult,\n AsyncScenarioForAction,\n Handler,\n IBaseAction,\n Services,\n SyncScenarioForAction,\n TypeOfResult,\n YieldResult,\n} from '../types';\nimport { Pending } from '../types';\n\nlet actionIdx = 0;\n\nexport type ActionByType<TType extends ActionTypes> = Extract<\n ActionQueueItem,\n {\n type: TType;\n }\n>;\n\ntype GetBase<TAction extends ActionQueueItem> = IBaseAction<\n TAction,\n TypeOfResult<TAction>,\n TAction['data']\n>;\n\nexport class BaseAction<TAction extends ActionQueueItem>\n implements GetBase<TAction>\n{\n public readonly idx: string;\n\n public result: TypeOfResult<TAction> | typeof Pending = Pending;\n\n private activeScenario:\n | SyncScenarioForAction<TAction>\n | AsyncScenarioForAction<TAction>\n | null = null;\n\n private activeScenarioError?: unknown;\n\n private activeScenarioNextResults: AnyIteratorResult<\n 'async' | 'sync',\n TypeOfResult<TAction>\n >[] = [];\n\n private handler: null | unknown = null;\n\n public constructor(\n public readonly type: TAction['type'],\n public readonly services: Services,\n public readonly entrypoint: Entrypoint,\n public readonly data: TAction['data'],\n public readonly abortSignal: AbortSignal | null,\n public readonly actionContext: unknown\n ) {\n actionIdx += 1;\n this.idx = actionIdx.toString(16).padStart(6, '0');\n }\n\n public get log(): Debugger {\n return this.entrypoint.log.extend(this.ref);\n }\n\n public get ref() {\n return `${this.type}@${this.idx}`;\n }\n\n public createAbortSignal(): AbortSignal & Disposable {\n const abortController = new AbortController();\n\n const unsubscribeFromParentAbort = this.onAbort(() => {\n this.entrypoint.log('parent aborted');\n abortController.abort();\n });\n\n const unsubscribeFromSupersede = this.entrypoint.onSupersede(() => {\n this.entrypoint.log('entrypoint superseded, aborting processing');\n abortController.abort();\n });\n\n const abortSignal = abortController.signal as AbortSignal & Disposable;\n abortSignal[Symbol.dispose] = () => {\n unsubscribeFromParentAbort();\n unsubscribeFromSupersede();\n };\n\n return abortSignal;\n }\n\n public *getNext<\n TNextType extends ActionTypes,\n TNextAction extends ActionByType<TNextType> = ActionByType<TNextType>,\n >(\n type: TNextType,\n entrypoint: Entrypoint,\n data: TNextAction['data'],\n abortSignal: AbortSignal | null = this.abortSignal\n ): Generator<\n [TNextType, Entrypoint, TNextAction['data'], AbortSignal | null],\n TypeOfResult<TNextAction>,\n YieldResult\n > {\n return (yield [\n type,\n entrypoint,\n data,\n abortSignal,\n ]) as TypeOfResult<TNextAction>;\n }\n\n public onAbort(fn: () => void): () => void {\n this.abortSignal?.addEventListener('abort', fn);\n\n return () => {\n this.abortSignal?.removeEventListener('abort', fn);\n };\n }\n\n public run<\n TMode extends 'async' | 'sync',\n THandler extends Handler<TMode, TAction> = Handler<TMode, TAction>,\n >(handler: THandler) {\n type IterationResult = AnyIteratorResult<TMode, TypeOfResult<TAction>>;\n\n if (this.handler && this.handler !== handler) {\n throw new Error(\n `action handler is already set for ${this.ref} (${this.entrypoint.name})`\n );\n }\n\n this.handler = handler;\n\n if (!this.activeScenario) {\n this.activeScenario = handler.call(this);\n this.activeScenarioNextResults = [];\n }\n\n let nextIdx = 0;\n\n const throwFn = (e: unknown) =>\n this.emitAction(nextIdx, () => this.activeScenario!.throw(e));\n\n const nextFn = (arg: YieldResult) =>\n this.emitAction(nextIdx, () => this.activeScenario!.next(arg));\n\n const processNextResult = (\n result: IterationResult,\n onError?: (e: unknown) => void\n ) => {\n if ('then' in result) {\n result.then((r) => {\n if (r.done) {\n this.result = r.value;\n }\n }, onError);\n } else if (result.done) {\n this.result = result.value;\n }\n\n this.activeScenarioNextResults.push(result);\n };\n\n const processError = (e: unknown) => {\n if (this.activeScenarioNextResults.length > nextIdx) {\n this.log(\n 'error was already handled in another branch, result idx is %d',\n nextIdx\n );\n return;\n }\n\n this.log('error processing, result idx is %d', nextIdx);\n\n try {\n const nextResult = throwFn(e);\n processNextResult(nextResult as IterationResult, processError);\n } catch (errorInGenerator) {\n const { recover } = handler;\n if (recover) {\n const nextResult = {\n done: false,\n value: recover(errorInGenerator, this),\n };\n\n processNextResult(nextResult as IterationResult, processError);\n return;\n }\n\n this.activeScenarioError = errorInGenerator;\n throw errorInGenerator;\n }\n };\n\n const processNext = (arg: YieldResult) => {\n if (this.activeScenarioNextResults.length > nextIdx) {\n this.log(\n 'next was already handled in another branch, result idx is %d',\n nextIdx\n );\n return;\n }\n\n this.log('next processing, result idx is %d', nextIdx);\n\n try {\n const nextResult = nextFn(arg);\n processNextResult(nextResult as IterationResult, processError);\n } catch (e) {\n processError(e);\n }\n };\n\n return {\n next: (arg: YieldResult): IterationResult => {\n this.rethrowActiveScenarioError();\n processNext(arg);\n return this.activeScenarioNextResults[nextIdx++] as IterationResult;\n },\n throw: (e: unknown): IterationResult => {\n this.rethrowActiveScenarioError();\n processError(e);\n return this.activeScenarioNextResults[nextIdx++] as IterationResult;\n },\n };\n }\n\n protected emitAction<TRes>(yieldIdx: number, fn: () => TRes) {\n return this.services.eventEmitter.action(\n this.type,\n `${this.idx}:${yieldIdx + 1}`,\n this.entrypoint.ref,\n fn\n );\n }\n\n private rethrowActiveScenarioError() {\n if (!this.activeScenarioError) {\n return;\n }\n\n this.log(\n 'scenario has an unhandled error from another branch, rethrow %o',\n this.activeScenarioError\n );\n\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw this.activeScenarioError;\n }\n}\n"],"mappings":";;;;;;AACAA,OAAA;AAgBA,IAAAC,MAAA,GAAAD,OAAA;AAjBA;;AAmBA,IAAIE,SAAS,GAAG,CAAC;AAeV,MAAMC,UAAU,CAEvB;EAGSC,MAAM,GAA2CC,cAAO;EAEvDC,cAAc,GAGX,IAAI;EAIPC,yBAAyB,GAG3B,EAAE;EAEAC,OAAO,GAAmB,IAAI;EAE/BC,WAAWA,CACAC,IAAqB,EACrBC,QAAkB,EAClBC,UAAsB,EACtBC,IAAqB,EACrBC,WAA+B,EAC/BC,aAAsB,EACtC;IAAA,KANgBL,IAAqB,GAArBA,IAAqB;IAAA,KACrBC,QAAkB,GAAlBA,QAAkB;IAAA,KAClBC,UAAsB,GAAtBA,UAAsB;IAAA,KACtBC,IAAqB,GAArBA,IAAqB;IAAA,KACrBC,WAA+B,GAA/BA,WAA+B;IAAA,KAC/BC,aAAsB,GAAtBA,aAAsB;IAEtCb,SAAS,IAAI,CAAC;IACd,IAAI,CAACc,GAAG,GAAGd,SAAS,CAACe,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EACpD;EAEA,IAAWC,GAAGA,CAAA,EAAa;IACzB,OAAO,IAAI,CAACP,UAAU,CAACO,GAAG,CAACC,MAAM,CAAC,IAAI,CAACC,GAAG,CAAC;EAC7C;EAEA,IAAWA,GAAGA,CAAA,EAAG;IACf,OAAO,GAAG,IAAI,CAACX,IAAI,IAAI,IAAI,CAACM,GAAG,EAAE;EACnC;EAEOM,iBAAiBA,CAAA,EAA6B;IACnD,MAAMC,eAAe,GAAG,IAAIC,eAAe,CAAC,CAAC;IAE7C,MAAMC,0BAA0B,GAAG,IAAI,CAACC,OAAO,CAAC,MAAM;MACpD,IAAI,CAACd,UAAU,CAACO,GAAG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D;IACF,CAAC;EACH;EAEUG,UAAUA,CAAOoB,QAAgB,EAAEhC,EAAc,EAAE;IAC3D,OAAO,IAAI,CAACvB,QAAQ,CAACwD,YAAY,CAACC,MAAM,CACtC,IAAI,CAAC1D,IAAI,EACT,GAAG,IAAI,CAACM,GAAG,IAAIkD,QAAQ,GAAG,CAAC,EAAE,EAC7B,IAAI,CAACtD,UAAU,CAACS,GAAG,EACnBa,EACF,CAAC;EACH;EAEQ+B,0BAA0BA,CAAA,EAAG;IACnC,IAAI,CAAC,IAAI,CAACF,mBAAmB,EAAE;MAC7B;IACF;IAEA,IAAI,CAAC5C,GAAG,CACN,iEAAiE,EACjE,IAAI,CAAC4C,mBACP,CAAC;;IAED;IACA,MAAM,IAAI,CAACA,mBAAmB;EAChC;AACF;AAACM,OAAA,CAAAlE,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -41,7 +41,7 @@ async function asyncActionRunner(action, actionHandlers, stack = [getActionRef(a
|
|
|
41
41
|
return result.value;
|
|
42
42
|
}
|
|
43
43
|
const [type, entrypoint, data, abortSignal] = result.value;
|
|
44
|
-
const nextAction = entrypoint.createAction(type, data, abortSignal);
|
|
44
|
+
const nextAction = entrypoint.createAction(type, data, abortSignal, action.actionContext);
|
|
45
45
|
try {
|
|
46
46
|
actionResult = await asyncActionRunner(nextAction, actionHandlers, [...stack, getActionRef(type, entrypoint)]);
|
|
47
47
|
} catch (e) {
|
|
@@ -70,7 +70,7 @@ function syncActionRunner(action, actionHandlers, stack = [getActionRef(action.t
|
|
|
70
70
|
return result.value;
|
|
71
71
|
}
|
|
72
72
|
const [type, entrypoint, data, abortSignal] = result.value;
|
|
73
|
-
const nextAction = entrypoint.createAction(type, data, abortSignal);
|
|
73
|
+
const nextAction = entrypoint.createAction(type, data, abortSignal, action.actionContext);
|
|
74
74
|
try {
|
|
75
75
|
actionResult = syncActionRunner(nextAction, actionHandlers, [...stack, getActionRef(type, entrypoint)]);
|
|
76
76
|
} catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actionRunner.js","names":["_types","require","_AbortError","getHandler","action","actionHandlers","handler","type","Error","getActionRef","entrypoint","ref","ACTION_ERROR","Symbol","isActionError","e","Array","isArray","asyncActionRunner","stack","result","Pending","log","generator","run","actionResult","_action$abortSignal","abortSignal","aborted","throw","AbortError","next","done","value","data","nextAction","createAction","syncActionRunner","_action$abortSignal2"],"sources":["../../../src/transform/actions/actionRunner.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop */\nimport type {\n ActionQueueItem,\n Handler,\n Handlers,\n TypeOfResult,\n} from '../types';\nimport { Pending } from '../types';\n\nimport { AbortError } from './AbortError';\nimport type { BaseAction } from './BaseAction';\n\nfunction getHandler<\n TMode extends 'async' | 'sync',\n TAction extends ActionQueueItem,\n>(\n action: BaseAction<TAction>,\n actionHandlers: Handlers<TMode>\n): Handler<TMode, TAction> {\n const handler = actionHandlers[action.type];\n if (!handler) {\n throw new Error(`No handler for action ${action.type}`);\n }\n\n // FIXME Handlers<TMode>[TAction['type']] is not assignable to Handler<TMode, TAction>\n return handler as unknown as Handler<TMode, TAction>;\n}\n\nconst getActionRef = (type: string, entrypoint: { ref: string }) =>\n `${type}@${entrypoint.ref}`;\n\nconst ACTION_ERROR = Symbol('ACTION_ERROR');\ntype ActionError = [marker: typeof ACTION_ERROR, err: unknown];\nconst isActionError = (e: unknown): e is ActionError =>\n Array.isArray(e) && e[0] === ACTION_ERROR;\n\nexport async function asyncActionRunner<TAction extends ActionQueueItem>(\n action: BaseAction<TAction>,\n actionHandlers: Handlers<'async' | 'sync'>,\n stack: string[] = [getActionRef(action.type, action.entrypoint)]\n): Promise<TypeOfResult<TAction>> {\n if (action.result !== Pending) {\n action.log('result is cached');\n return action.result as TypeOfResult<TAction>;\n }\n\n const handler = getHandler(action, actionHandlers);\n const generator = action.run<'async' | 'sync'>(handler);\n let actionResult: TypeOfResult<ActionQueueItem> | ActionError | undefined;\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (action.abortSignal?.aborted) {\n action.log('action is aborted');\n generator.throw(new AbortError(stack[0]));\n }\n\n const result = await (isActionError(actionResult)\n ? generator.throw(actionResult[1])\n : generator.next(actionResult));\n if (result.done) {\n return result.value as TypeOfResult<TAction>;\n }\n\n const [type, entrypoint, data, abortSignal] = result.value;\n const nextAction = entrypoint.createAction(type
|
|
1
|
+
{"version":3,"file":"actionRunner.js","names":["_types","require","_AbortError","getHandler","action","actionHandlers","handler","type","Error","getActionRef","entrypoint","ref","ACTION_ERROR","Symbol","isActionError","e","Array","isArray","asyncActionRunner","stack","result","Pending","log","generator","run","actionResult","_action$abortSignal","abortSignal","aborted","throw","AbortError","next","done","value","data","nextAction","createAction","actionContext","syncActionRunner","_action$abortSignal2"],"sources":["../../../src/transform/actions/actionRunner.ts"],"sourcesContent":["/* eslint-disable no-await-in-loop */\nimport type {\n ActionQueueItem,\n Handler,\n Handlers,\n TypeOfResult,\n} from '../types';\nimport { Pending } from '../types';\n\nimport { AbortError } from './AbortError';\nimport type { BaseAction } from './BaseAction';\n\nfunction getHandler<\n TMode extends 'async' | 'sync',\n TAction extends ActionQueueItem,\n>(\n action: BaseAction<TAction>,\n actionHandlers: Handlers<TMode>\n): Handler<TMode, TAction> {\n const handler = actionHandlers[action.type];\n if (!handler) {\n throw new Error(`No handler for action ${action.type}`);\n }\n\n // FIXME Handlers<TMode>[TAction['type']] is not assignable to Handler<TMode, TAction>\n return handler as unknown as Handler<TMode, TAction>;\n}\n\nconst getActionRef = (type: string, entrypoint: { ref: string }) =>\n `${type}@${entrypoint.ref}`;\n\nconst ACTION_ERROR = Symbol('ACTION_ERROR');\ntype ActionError = [marker: typeof ACTION_ERROR, err: unknown];\nconst isActionError = (e: unknown): e is ActionError =>\n Array.isArray(e) && e[0] === ACTION_ERROR;\n\nexport async function asyncActionRunner<TAction extends ActionQueueItem>(\n action: BaseAction<TAction>,\n actionHandlers: Handlers<'async' | 'sync'>,\n stack: string[] = [getActionRef(action.type, action.entrypoint)]\n): Promise<TypeOfResult<TAction>> {\n if (action.result !== Pending) {\n action.log('result is cached');\n return action.result as TypeOfResult<TAction>;\n }\n\n const handler = getHandler(action, actionHandlers);\n const generator = action.run<'async' | 'sync'>(handler);\n let actionResult: TypeOfResult<ActionQueueItem> | ActionError | undefined;\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (action.abortSignal?.aborted) {\n action.log('action is aborted');\n generator.throw(new AbortError(stack[0]));\n }\n\n const result = await (isActionError(actionResult)\n ? generator.throw(actionResult[1])\n : generator.next(actionResult));\n if (result.done) {\n return result.value as TypeOfResult<TAction>;\n }\n\n const [type, entrypoint, data, abortSignal] = result.value;\n const nextAction = entrypoint.createAction(\n type,\n data,\n abortSignal,\n action.actionContext\n );\n\n try {\n actionResult = await asyncActionRunner(nextAction, actionHandlers, [\n ...stack,\n getActionRef(type, entrypoint),\n ]);\n } catch (e) {\n nextAction.log('error', e);\n actionResult = [ACTION_ERROR, e];\n }\n }\n}\n\nexport function syncActionRunner<TAction extends ActionQueueItem>(\n action: BaseAction<TAction>,\n actionHandlers: Handlers<'sync'>,\n stack: string[] = [getActionRef(action.type, action.entrypoint)]\n): TypeOfResult<TAction> {\n if (action.result !== Pending) {\n action.log('result is cached');\n return action.result as TypeOfResult<TAction>;\n }\n\n const handler = getHandler(action, actionHandlers);\n const generator = action.run<'sync'>(handler);\n let actionResult: TypeOfResult<ActionQueueItem> | ActionError | undefined;\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (action.abortSignal?.aborted) {\n action.log('action is aborted');\n generator.throw(new AbortError(stack[0]));\n }\n\n const result = isActionError(actionResult)\n ? generator.throw(actionResult[1])\n : generator.next(actionResult);\n if (result.done) {\n return result.value as TypeOfResult<TAction>;\n }\n\n const [type, entrypoint, data, abortSignal] = result.value;\n const nextAction = entrypoint.createAction(\n type,\n data,\n abortSignal,\n action.actionContext\n );\n\n try {\n actionResult = syncActionRunner(nextAction, actionHandlers, [\n ...stack,\n getActionRef(type, entrypo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