@wyw-in-js/transform 1.0.6 → 1.0.7
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 +100 -7
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/module.js +51 -2
- 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 +60 -17
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/EvaluatedEntrypoint.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 +27 -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/lib/cache.js +103 -7
- package/lib/cache.js.map +1 -1
- package/lib/debug/fileReporter.js.map +1 -1
- package/lib/module.js +51 -2
- 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 +61 -17
- package/lib/transform/Entrypoint.js.map +1 -1
- package/lib/transform/EvaluatedEntrypoint.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 +27 -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/package.json +8 -4
- package/types/cache.d.ts +16 -2
- package/types/cache.js +111 -7
- package/types/debug/fileReporter.d.ts +1 -0
- package/types/module.d.ts +3 -0
- package/types/module.js +57 -2
- 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 +9 -0
- package/types/transform/Entrypoint.js +73 -20
- package/types/transform/EvaluatedEntrypoint.d.ts +2 -0
- 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 +26 -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 +2 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import { invariant } from 'ts-invariant';
|
|
2
3
|
import { BaseEntrypoint } from './BaseEntrypoint';
|
|
3
4
|
import { isSuperSet, mergeOnly } from './Entrypoint.helpers';
|
|
4
|
-
import { isStaticallyEvaluatableModule } from './isStaticallyEvaluatableModule';
|
|
5
5
|
import { EvaluatedEntrypoint } from './EvaluatedEntrypoint';
|
|
6
6
|
import { AbortError } from './actions/AbortError';
|
|
7
7
|
import { BaseAction } from './actions/BaseAction';
|
|
8
8
|
import { UnprocessedEntrypointError } from './actions/UnprocessedEntrypointError';
|
|
9
|
+
import { stripQueryAndHash } from '../utils/parseRequest';
|
|
9
10
|
const EMPTY_FILE = '=== empty file ===';
|
|
10
11
|
function hasLoop(name, parent, processed = []) {
|
|
11
12
|
if (parent.name === name || processed.includes(parent.name)) {
|
|
@@ -24,13 +25,17 @@ export class Entrypoint extends BaseEntrypoint {
|
|
|
24
25
|
onSupersedeHandlers = [];
|
|
25
26
|
actionsCache = new Map();
|
|
26
27
|
#hasWywMetadata = false;
|
|
28
|
+
#isProcessing = false;
|
|
29
|
+
#pendingOnly = null;
|
|
27
30
|
#supersededWith = null;
|
|
28
31
|
#transformResultCode = null;
|
|
29
|
-
constructor(services, parents, initialCode, name, only, exports, evaluatedOnly, loadedAndParsed, resolveTasks = new Map(), dependencies = new Map(), generation = 1) {
|
|
30
|
-
super(services, evaluatedOnly, exports, generation, name, only, parents, dependencies);
|
|
32
|
+
constructor(services, parents, initialCode, name, only, exports, evaluatedOnly, loadedAndParsed, resolveTasks = new Map(), dependencies = new Map(), invalidationDependencies = new Map(), invalidateOnDependencyChange = new Set(), generation = 1) {
|
|
33
|
+
super(services, evaluatedOnly, exports, generation, name, only, parents, dependencies, invalidationDependencies, invalidateOnDependencyChange);
|
|
31
34
|
this.initialCode = initialCode;
|
|
32
35
|
this.resolveTasks = resolveTasks;
|
|
33
36
|
this.dependencies = dependencies;
|
|
37
|
+
this.invalidationDependencies = invalidationDependencies;
|
|
38
|
+
this.invalidateOnDependencyChange = invalidateOnDependencyChange;
|
|
34
39
|
this.loadedAndParsed = loadedAndParsed ?? services.loadAndParseFn(services, name, initialCode, parents[0]?.log ?? services.log);
|
|
35
40
|
if (this.loadedAndParsed.code !== undefined) {
|
|
36
41
|
services.cache.invalidateIfChanged(name, this.loadedAndParsed.code, undefined, this.initialCode === undefined ? 'fs' : 'loaded');
|
|
@@ -92,7 +97,16 @@ export class Entrypoint extends BaseEntrypoint {
|
|
|
92
97
|
cache
|
|
93
98
|
} = services;
|
|
94
99
|
const cached = cache.get('entrypoints', name);
|
|
95
|
-
|
|
100
|
+
let changed = false;
|
|
101
|
+
if (loadedCode !== undefined) {
|
|
102
|
+
changed = cache.invalidateIfChanged(name, loadedCode, undefined, 'loaded');
|
|
103
|
+
} else if (cached && cached.initialCode === undefined) {
|
|
104
|
+
try {
|
|
105
|
+
changed = cache.invalidateIfChanged(name, fs.readFileSync(stripQueryAndHash(name), 'utf8'), undefined, 'fs');
|
|
106
|
+
} catch {
|
|
107
|
+
changed = false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
96
110
|
if (!cached?.evaluated && cached?.ignored) {
|
|
97
111
|
return ['cached', cached];
|
|
98
112
|
}
|
|
@@ -115,19 +129,14 @@ export class Entrypoint extends BaseEntrypoint {
|
|
|
115
129
|
return [isLoop ? 'loop' : 'cached', cached];
|
|
116
130
|
}
|
|
117
131
|
cached.log('is cached, but with different `only` %o (the cached one %o)', only, cached?.only);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const {
|
|
123
|
-
ast
|
|
124
|
-
} = newEntrypoint.loadedAndParsed;
|
|
125
|
-
if (ast && isStaticallyEvaluatableModule(ast)) {
|
|
126
|
-
newEntrypoint.log('[entrypoint] promote `only` to "*" for statically evaluatable module');
|
|
127
|
-
newEntrypoint.only.length = 0;
|
|
128
|
-
newEntrypoint.only.push('*');
|
|
132
|
+
if (cached.#isProcessing) {
|
|
133
|
+
cached.deferOnlySupersede(mergedOnly);
|
|
134
|
+
cached.log('is being processed, defer supersede (%o -> %o)', cached.only, mergedOnly);
|
|
135
|
+
return [isLoop ? 'loop' : 'cached', cached];
|
|
129
136
|
}
|
|
137
|
+
return [isLoop ? 'loop' : 'created', cached.supersede(mergedOnly)];
|
|
130
138
|
}
|
|
139
|
+
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);
|
|
131
140
|
if (cached && !cached.evaluated) {
|
|
132
141
|
cached.log('is cached, but with different code');
|
|
133
142
|
cached.supersede(newEntrypoint);
|
|
@@ -138,9 +147,27 @@ export class Entrypoint extends BaseEntrypoint {
|
|
|
138
147
|
this.resolveTasks.delete(dependency.source);
|
|
139
148
|
this.dependencies.set(dependency.source, dependency);
|
|
140
149
|
}
|
|
150
|
+
addInvalidationDependency(dependency) {
|
|
151
|
+
this.resolveTasks.delete(dependency.source);
|
|
152
|
+
this.invalidationDependencies.set(dependency.source, dependency);
|
|
153
|
+
}
|
|
141
154
|
addResolveTask(name, dependency) {
|
|
142
155
|
this.resolveTasks.set(name, dependency);
|
|
143
156
|
}
|
|
157
|
+
applyDeferredSupersede() {
|
|
158
|
+
if (this.#supersededWith || this.#pendingOnly === null) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const mergedOnly = mergeOnly(this.only, this.#pendingOnly);
|
|
162
|
+
this.#pendingOnly = null;
|
|
163
|
+
if (isSuperSet(this.only, mergedOnly)) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
this.log('apply deferred supersede (%o -> %o)', this.only, mergedOnly);
|
|
167
|
+
const nextEntrypoint = this.supersede(mergedOnly);
|
|
168
|
+
this.services.cache.add('entrypoints', this.name, nextEntrypoint);
|
|
169
|
+
return nextEntrypoint;
|
|
170
|
+
}
|
|
144
171
|
assertNotSuperseded() {
|
|
145
172
|
if (this.supersededWith) {
|
|
146
173
|
this.log('superseded');
|
|
@@ -153,6 +180,9 @@ export class Entrypoint extends BaseEntrypoint {
|
|
|
153
180
|
throw new UnprocessedEntrypointError(this.supersededWith ?? this);
|
|
154
181
|
}
|
|
155
182
|
}
|
|
183
|
+
beginProcessing() {
|
|
184
|
+
this.#isProcessing = true;
|
|
185
|
+
}
|
|
156
186
|
createAction(actionType, data, abortSignal = null) {
|
|
157
187
|
if (!this.actionsCache.has(actionType)) {
|
|
158
188
|
this.actionsCache.set(actionType, new Map());
|
|
@@ -177,13 +207,22 @@ export class Entrypoint extends BaseEntrypoint {
|
|
|
177
207
|
createEvaluated() {
|
|
178
208
|
const evaluatedOnly = mergeOnly(this.evaluatedOnly, this.only);
|
|
179
209
|
this.log('create EvaluatedEntrypoint for %o', evaluatedOnly);
|
|
180
|
-
const evaluated = new EvaluatedEntrypoint(this.services, evaluatedOnly, this.exportsProxy, this.generation + 1, this.name, this.only, this.parents, this.dependencies);
|
|
210
|
+
const evaluated = new EvaluatedEntrypoint(this.services, evaluatedOnly, this.exportsProxy, this.generation + 1, this.name, this.only, this.parents, this.dependencies, this.invalidationDependencies, this.invalidateOnDependencyChange);
|
|
181
211
|
evaluated.initialCode = this.initialCode;
|
|
182
212
|
return evaluated;
|
|
183
213
|
}
|
|
214
|
+
endProcessing() {
|
|
215
|
+
this.#isProcessing = false;
|
|
216
|
+
}
|
|
184
217
|
getDependency(name) {
|
|
185
218
|
return this.dependencies.get(name);
|
|
186
219
|
}
|
|
220
|
+
getInvalidationDependency(name) {
|
|
221
|
+
return this.invalidationDependencies.get(name);
|
|
222
|
+
}
|
|
223
|
+
markInvalidateOnDependencyChange(filename) {
|
|
224
|
+
this.invalidateOnDependencyChange.add(filename);
|
|
225
|
+
}
|
|
187
226
|
getResolveTask(name) {
|
|
188
227
|
return this.resolveTasks.get(name);
|
|
189
228
|
}
|
|
@@ -211,8 +250,12 @@ export class Entrypoint extends BaseEntrypoint {
|
|
|
211
250
|
type: 'setTransformResult'
|
|
212
251
|
});
|
|
213
252
|
}
|
|
253
|
+
deferOnlySupersede(only) {
|
|
254
|
+
this.#pendingOnly = this.#pendingOnly ? mergeOnly(this.#pendingOnly, only) : [...only];
|
|
255
|
+
}
|
|
214
256
|
supersede(newOnlyOrEntrypoint) {
|
|
215
|
-
|
|
257
|
+
this.#pendingOnly = null;
|
|
258
|
+
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);
|
|
216
259
|
this.services.eventEmitter.entrypointEvent(this.seqId, {
|
|
217
260
|
type: 'superseded',
|
|
218
261
|
with: newEntrypoint.seqId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entrypoint.js","names":["invariant","BaseEntrypoint","isSuperSet","mergeOnly","isStaticallyEvaluatableModule","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","isLoop","map","push","supersede","newEntrypoint","ast","length","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 { 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.onSupersedeHand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IAC7C,IAAI,CAAC,CAAC5E,mBAAmB,GAAG0E,GAAG,EAAE7D,IAAI,IAAI,IAAI;IAE7C,IAAI,CAACX,QAAQ,CAACwB,YAAY,CAACiC,eAAe,CAAC,IAAI,CAAC5B,KAAK,EAAE;MACrD8C,MAAM,EAAEH,GAAG,KAAK,IAAI;MACpBd,IAAI,EAAE;IACR,CAAC,CAAC;EACJ;EAEQpB,SAASA,CAACsC,mBAA0C,EAAc;IACxE,MAAMrC,aAAa,GACjBqC,mBAAmB,YAAYrF,UAAU,GACrCqF,mBAAmB,GACnB,IAAIrF,UAAU,CACZ,IAAI,CAACS,QAAQ,EACb,IAAI,CAACX,OAAO,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,EAAEtC,aAAa,CAACV;IACtB,CAAC,CAAC;IACF,IAAI,CAACnB,GAAG,CACN,6BAA6B,EAC7B6B,aAAa,CAACvD,IAAI,EAClB,IAAI,CAACkB,IAAI,EACTqC,aAAa,CAACrC,IAChB,CAAC;IACD,IAAI,CAAC,CAACL,cAAc,GAAG0C,aAAa;IACpC,IAAI,CAAC9C,mBAAmB,CAACqF,OAAO,CAAEC,OAAO,IAAKA,OAAO,CAACxC,aAAa,CAAC,CAAC;IAErE,OAAOA,aAAa;EACtB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Entrypoint.js","names":["fs","invariant","BaseEntrypoint","isSuperSet","mergeOnly","EvaluatedEntrypoint","AbortError","BaseAction","UnprocessedEntrypointError","stripQueryAndHash","EMPTY_FILE","hasLoop","name","parent","processed","includes","p","parents","found","Entrypoint","evaluated","onSupersedeHandlers","actionsCache","Map","hasWywMetadata","isProcessing","pendingOnly","supersededWith","transformResultCode","constructor","services","initialCode","only","exports","evaluatedOnly","loadedAndParsed","resolveTasks","dependencies","invalidationDependencies","invalidateOnDependencyChange","Set","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","readFileSync","mergedOnly","isLoop","map","push","deferOnlySupersede","supersede","newEntrypoint","addDependency","dependency","delete","source","set","addInvalidationDependency","addResolveTask","applyDeferredSupersede","nextEntrypoint","assertNotSuperseded","assertTransformed","beginProcessing","createAction","actionType","data","abortSignal","has","aborted","newAction","entrypointEvent","type","actionIdx","idx","createChild","createEvaluated","exportsProxy","endProcessing","getDependency","getInvalidationDependency","markInvalidateOnDependencyChange","filename","getResolveTask","onSupersede","callback","index","indexOf","splice","setTransformResult","res","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 ===';\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 #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 ): 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 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,OAAOA,EAAE,MAAM,SAAS;AACxB,SAASC,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;AAEjF,SAASC,iBAAiB,QAAQ,uBAAuB;AAEzD,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,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KA,OAAO,CAAC9C,aAAa,CAAC,CAAC;IAErE,OAAOA,aAAa;EACtB;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EvaluatedEntrypoint.js","names":["BaseEntrypoint","EvaluatedEntrypoint","evaluated","ignored"],"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,SAASA,cAAc,QAAQ,kBAAkB;
|
|
1
|
+
{"version":3,"file":"EvaluatedEntrypoint.js","names":["BaseEntrypoint","EvaluatedEntrypoint","evaluated","ignored"],"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,SAASA,cAAc,QAAQ,kBAAkB;AAiBjD,OAAO,MAAMC,mBAAmB,SACtBD,cAAc,CAExB;EACkBE,SAAS,GAAG,IAAI;EAEhBC,OAAO,GAAG,KAAK;AAGjC","ignoreList":[]}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/* eslint-disable no-continue, @typescript-eslint/no-use-before-define */
|
|
2
|
+
import traverse from '@babel/traverse';
|
|
3
|
+
import { getBindingIdentifiers } from '@babel/types';
|
|
4
|
+
const isTypeOnlyImport = statement => {
|
|
5
|
+
if (statement.importKind === 'type') {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
if (statement.specifiers.length === 0) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return statement.specifiers.every(specifier => specifier.type === 'ImportSpecifier' && specifier.importKind === 'type');
|
|
12
|
+
};
|
|
13
|
+
const isTypeOnlyExport = statement => statement.exportKind === 'type';
|
|
14
|
+
const getModuleExportName = node => node.type === 'Identifier' ? node.name : node.value;
|
|
15
|
+
const isTypeOnlyStatement = statement => {
|
|
16
|
+
switch (statement.type) {
|
|
17
|
+
case 'EmptyStatement':
|
|
18
|
+
case 'TSDeclareFunction':
|
|
19
|
+
case 'TSInterfaceDeclaration':
|
|
20
|
+
case 'TSTypeAliasDeclaration':
|
|
21
|
+
return true;
|
|
22
|
+
default:
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function collectExportNamedDeclaration(statement, reexports, explicitExports) {
|
|
27
|
+
if (!statement.source) {
|
|
28
|
+
return isTypeOnlyExport(statement);
|
|
29
|
+
}
|
|
30
|
+
if (isTypeOnlyExport(statement)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
const source = statement.source.value;
|
|
34
|
+
for (const specifier of statement.specifiers) {
|
|
35
|
+
if (specifier.type === 'ExportSpecifier') {
|
|
36
|
+
if (specifier.exportKind === 'type') {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
explicitExports.add(getModuleExportName(specifier.exported));
|
|
40
|
+
reexports.push(getNamedReexport(specifier, source));
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (specifier.type === 'ExportDefaultSpecifier') {
|
|
44
|
+
explicitExports.add(getModuleExportName(specifier.exported));
|
|
45
|
+
reexports.push(getDefaultReexport(specifier, source));
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (specifier.type === 'ExportNamespaceSpecifier') {
|
|
49
|
+
explicitExports.add(getModuleExportName(specifier.exported));
|
|
50
|
+
reexports.push(getNamespaceReexport(specifier, source));
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return statement.specifiers.length > 0;
|
|
56
|
+
}
|
|
57
|
+
function getNamedReexport(specifier, source) {
|
|
58
|
+
return {
|
|
59
|
+
exported: getModuleExportName(specifier.exported),
|
|
60
|
+
imported: getModuleExportName(specifier.local),
|
|
61
|
+
kind: 'named',
|
|
62
|
+
source
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function getDefaultReexport(specifier, source) {
|
|
66
|
+
return {
|
|
67
|
+
exported: getModuleExportName(specifier.exported),
|
|
68
|
+
imported: 'default',
|
|
69
|
+
kind: 'named',
|
|
70
|
+
source
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function getNamespaceReexport(specifier, source) {
|
|
74
|
+
return {
|
|
75
|
+
exported: getModuleExportName(specifier.exported),
|
|
76
|
+
kind: 'namespace',
|
|
77
|
+
source
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const collectImportBinding = (statement, imports) => {
|
|
81
|
+
if (statement.importKind === 'type') {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (statement.specifiers.length === 0) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
let sawValueImport = false;
|
|
88
|
+
for (const specifier of statement.specifiers) {
|
|
89
|
+
if (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
sawValueImport = true;
|
|
93
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
94
|
+
imports.set(specifier.local.name, {
|
|
95
|
+
imported: getImportSpecifierName(specifier),
|
|
96
|
+
kind: 'named',
|
|
97
|
+
source: statement.source.value
|
|
98
|
+
});
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
102
|
+
imports.set(specifier.local.name, {
|
|
103
|
+
imported: 'default',
|
|
104
|
+
kind: 'named',
|
|
105
|
+
source: statement.source.value
|
|
106
|
+
});
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
imports.set(specifier.local.name, {
|
|
110
|
+
kind: 'namespace',
|
|
111
|
+
source: statement.source.value
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return sawValueImport || isTypeOnlyImport(statement);
|
|
115
|
+
};
|
|
116
|
+
const getImportSpecifierName = specifier => getModuleExportName(specifier.imported);
|
|
117
|
+
const getLocalDeclarationNames = declaration => {
|
|
118
|
+
if (declaration.type === 'VariableDeclaration' || declaration.type === 'FunctionDeclaration' || declaration.type === 'ClassDeclaration') {
|
|
119
|
+
return Object.keys(getBindingIdentifiers(declaration));
|
|
120
|
+
}
|
|
121
|
+
if (declaration.type === 'TSEnumDeclaration' || declaration.type === 'TSModuleDeclaration') {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return [];
|
|
125
|
+
};
|
|
126
|
+
const collectLocalExportNamedDeclaration = (statement, importedBindings, passthroughCandidates, explicitExports) => {
|
|
127
|
+
let complete = true;
|
|
128
|
+
if (isTypeOnlyExport(statement)) {
|
|
129
|
+
return {
|
|
130
|
+
complete: true,
|
|
131
|
+
ok: true
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (statement.declaration) {
|
|
135
|
+
const names = getLocalDeclarationNames(statement.declaration);
|
|
136
|
+
if (names === null) {
|
|
137
|
+
return {
|
|
138
|
+
complete: false,
|
|
139
|
+
ok: false
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
for (const name of names) {
|
|
143
|
+
explicitExports.add(name);
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
complete: names.length === 0,
|
|
147
|
+
ok: true
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
for (const specifier of statement.specifiers) {
|
|
151
|
+
if (specifier.type !== 'ExportSpecifier') {
|
|
152
|
+
return {
|
|
153
|
+
complete: false,
|
|
154
|
+
ok: false
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (specifier.exportKind === 'type') {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const exported = getModuleExportName(specifier.exported);
|
|
161
|
+
explicitExports.add(exported);
|
|
162
|
+
if (specifier.local.type !== 'Identifier') {
|
|
163
|
+
complete = false;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (!importedBindings.has(specifier.local.name)) {
|
|
167
|
+
complete = false;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (!passthroughCandidates.has(specifier.local.name)) {
|
|
171
|
+
passthroughCandidates.set(specifier.local.name, []);
|
|
172
|
+
}
|
|
173
|
+
passthroughCandidates.get(specifier.local.name).push(exported);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
complete: complete && statement.specifiers.length > 0,
|
|
177
|
+
ok: true
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
const collectPassthroughReexports = (ast, importedBindings, passthroughCandidates, reexports) => {
|
|
181
|
+
let complete = true;
|
|
182
|
+
const bindingReferenceCounts = new Map();
|
|
183
|
+
traverse(ast, {
|
|
184
|
+
Program(path) {
|
|
185
|
+
for (const localName of passthroughCandidates.keys()) {
|
|
186
|
+
bindingReferenceCounts.set(localName, path.scope.getBinding(localName)?.referencePaths.length ?? -1);
|
|
187
|
+
}
|
|
188
|
+
path.stop();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
for (const [localName, exportedNames] of passthroughCandidates) {
|
|
192
|
+
if (bindingReferenceCounts.get(localName) !== exportedNames.length) {
|
|
193
|
+
complete = false;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const imported = importedBindings.get(localName);
|
|
197
|
+
for (const exported of exportedNames) {
|
|
198
|
+
if (imported.kind === 'namespace') {
|
|
199
|
+
reexports.push({
|
|
200
|
+
exported,
|
|
201
|
+
kind: 'namespace',
|
|
202
|
+
source: imported.source
|
|
203
|
+
});
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
reexports.push({
|
|
207
|
+
exported,
|
|
208
|
+
imported: imported.imported,
|
|
209
|
+
kind: 'named',
|
|
210
|
+
source: imported.source
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
complete,
|
|
216
|
+
ok: true
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
function analyzeBarrelProgram(ast) {
|
|
220
|
+
const reexports = [];
|
|
221
|
+
const explicitExports = new Set();
|
|
222
|
+
const exportAll = [];
|
|
223
|
+
const importedBindings = new Map();
|
|
224
|
+
const passthroughCandidates = new Map();
|
|
225
|
+
let complete = true;
|
|
226
|
+
for (const statement of ast.program.body) {
|
|
227
|
+
if (statement.type === 'ImportDeclaration') {
|
|
228
|
+
if (!collectImportBinding(statement, importedBindings)) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (statement.type === 'ExportNamedDeclaration') {
|
|
234
|
+
if (statement.source) {
|
|
235
|
+
if (!collectExportNamedDeclaration(statement, reexports, explicitExports)) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const localResult = collectLocalExportNamedDeclaration(statement, importedBindings, passthroughCandidates, explicitExports);
|
|
241
|
+
if (!localResult.ok) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
complete = complete && localResult.complete;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (statement.type === 'ExportAllDeclaration') {
|
|
248
|
+
if (statement.exportKind === 'type') {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (!statement.source) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
exportAll.push(getExportAllSource(statement));
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (statement.type === 'ExportDefaultDeclaration') {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
if (!isTypeOnlyStatement(statement)) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const passthroughResult = collectPassthroughReexports(ast, importedBindings, passthroughCandidates, reexports);
|
|
265
|
+
if (!passthroughResult.ok) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
complete = complete && passthroughResult.complete;
|
|
269
|
+
if (reexports.length === 0 && exportAll.length === 0) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
complete,
|
|
274
|
+
explicitExports: [...explicitExports],
|
|
275
|
+
exportAll,
|
|
276
|
+
kind: 'barrel',
|
|
277
|
+
reexports
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
const getExportAllSource = statement => statement.source.value;
|
|
281
|
+
export function analyzeBarrelFile(ast) {
|
|
282
|
+
const result = analyzeBarrelProgram(ast);
|
|
283
|
+
if (!result) {
|
|
284
|
+
return {
|
|
285
|
+
kind: 'ineligible',
|
|
286
|
+
reason: 'impure'
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=barrelManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrelManifest.js","names":["traverse","getBindingIdentifiers","isTypeOnlyImport","statement","importKind","specifiers","length","every","specifier","type","isTypeOnlyExport","exportKind","getModuleExportName","node","name","value","isTypeOnlyStatement","collectExportNamedDeclaration","reexports","explicitExports","source","add","exported","push","getNamedReexport","getDefaultReexport","getNamespaceReexport","imported","local","kind","collectImportBinding","imports","sawValueImport","set","getImportSpecifierName","getLocalDeclarationNames","declaration","Object","keys","collectLocalExportNamedDeclaration","importedBindings","passthroughCandidates","complete","ok","names","has","get","collectPassthroughReexports","ast","bindingReferenceCounts","Map","Program","path","localName","scope","getBinding","referencePaths","stop","exportedNames","analyzeBarrelProgram","Set","exportAll","program","body","localResult","getExportAllSource","passthroughResult","analyzeBarrelFile","result","reason"],"sources":["../../src/transform/barrelManifest.ts"],"sourcesContent":["/* eslint-disable no-continue, @typescript-eslint/no-use-before-define */\nimport traverse from '@babel/traverse';\nimport { getBindingIdentifiers } from '@babel/types';\nimport type {\n ClassDeclaration,\n Declaration,\n ExportAllDeclaration,\n ExportDefaultSpecifier,\n ExportNamedDeclaration,\n ExportNamespaceSpecifier,\n ExportSpecifier,\n File,\n FunctionDeclaration,\n Identifier,\n ImportDeclaration,\n ImportSpecifier,\n Program,\n StringLiteral,\n VariableDeclaration,\n} from '@babel/types';\n\nexport type BarrelSkipReason =\n | 'custom-evaluator'\n | 'empty'\n | 'ignored'\n | 'impure'\n | 'namespace-barrel'\n | 'unknown-star';\n\nexport type BarrelBlockedReason =\n | 'ambiguous'\n | 'cycle'\n | 'namespace-barrel'\n | 'unknown-star'\n | 'unresolved';\n\nexport type BarrelResolvedBinding =\n | {\n imported: string;\n kind: 'named';\n source: string;\n }\n | {\n kind: 'namespace';\n source: string;\n };\n\nexport type BarrelManifestExport =\n | BarrelResolvedBinding\n | {\n kind: 'blocked';\n reason: BarrelBlockedReason;\n };\n\nexport type BarrelManifest = {\n complete: boolean;\n exports: Record<string, BarrelManifestExport>;\n kind: 'barrel';\n};\n\nexport type BarrelManifestCacheEntry =\n | BarrelManifest\n | {\n kind: 'ineligible';\n reason: BarrelSkipReason;\n };\n\nexport type RawBarrelReexport =\n | {\n exported: string;\n imported: string;\n kind: 'named';\n source: string;\n }\n | {\n exported: string;\n kind: 'namespace';\n source: string;\n };\n\nexport type RawBarrelManifest = {\n complete: boolean;\n explicitExports: string[];\n exportAll: string[];\n kind: 'barrel';\n reexports: RawBarrelReexport[];\n};\n\ntype LocalImportBinding =\n | {\n imported: string;\n kind: 'named';\n source: string;\n }\n | {\n kind: 'namespace';\n source: string;\n };\n\nconst isTypeOnlyImport = (statement: ImportDeclaration): boolean => {\n if (statement.importKind === 'type') {\n return true;\n }\n\n if (statement.specifiers.length === 0) {\n return false;\n }\n\n return statement.specifiers.every(\n (specifier) =>\n specifier.type === 'ImportSpecifier' && specifier.importKind === 'type'\n );\n};\n\nconst isTypeOnlyExport = (statement: ExportNamedDeclaration): boolean =>\n statement.exportKind === 'type';\n\nconst getModuleExportName = (node: Identifier | StringLiteral): string =>\n node.type === 'Identifier' ? node.name : node.value;\n\nconst isTypeOnlyStatement = (statement: Program['body'][number]): boolean => {\n switch (statement.type) {\n case 'EmptyStatement':\n case 'TSDeclareFunction':\n case 'TSInterfaceDeclaration':\n case 'TSTypeAliasDeclaration':\n return true;\n default:\n return false;\n }\n};\n\nfunction collectExportNamedDeclaration(\n statement: ExportNamedDeclaration,\n reexports: RawBarrelReexport[],\n explicitExports: Set<string>\n): boolean {\n if (!statement.source) {\n return isTypeOnlyExport(statement);\n }\n\n if (isTypeOnlyExport(statement)) {\n return true;\n }\n\n const source = statement.source.value;\n for (const specifier of statement.specifiers) {\n if (specifier.type === 'ExportSpecifier') {\n if (specifier.exportKind === 'type') {\n continue;\n }\n\n explicitExports.add(getModuleExportName(specifier.exported));\n reexports.push(getNamedReexport(specifier, source));\n continue;\n }\n\n if (specifier.type === 'ExportDefaultSpecifier') {\n explicitExports.add(getModuleExportName(specifier.exported));\n reexports.push(getDefaultReexport(specifier, source));\n continue;\n }\n\n if (specifier.type === 'ExportNamespaceSpecifier') {\n explicitExports.add(getModuleExportName(specifier.exported));\n reexports.push(getNamespaceReexport(specifier, source));\n continue;\n }\n\n return false;\n }\n\n return statement.specifiers.length > 0;\n}\n\nfunction getNamedReexport(\n specifier: ExportSpecifier,\n source: string\n): RawBarrelReexport {\n return {\n exported: getModuleExportName(specifier.exported),\n imported: getModuleExportName(specifier.local),\n kind: 'named',\n source,\n };\n}\n\nfunction getDefaultReexport(\n specifier: ExportDefaultSpecifier,\n source: string\n): RawBarrelReexport {\n return {\n exported: getModuleExportName(specifier.exported),\n imported: 'default',\n kind: 'named',\n source,\n };\n}\n\nfunction getNamespaceReexport(\n specifier: ExportNamespaceSpecifier,\n source: string\n): RawBarrelReexport {\n return {\n exported: getModuleExportName(specifier.exported),\n kind: 'namespace',\n source,\n };\n}\n\nconst collectImportBinding = (\n statement: ImportDeclaration,\n imports: Map<string, LocalImportBinding>\n): boolean => {\n if (statement.importKind === 'type') {\n return true;\n }\n\n if (statement.specifiers.length === 0) {\n return false;\n }\n\n let sawValueImport = false;\n for (const specifier of statement.specifiers) {\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.importKind === 'type'\n ) {\n continue;\n }\n\n sawValueImport = true;\n\n if (specifier.type === 'ImportSpecifier') {\n imports.set(specifier.local.name, {\n imported: getImportSpecifierName(specifier),\n kind: 'named',\n source: statement.source.value,\n });\n continue;\n }\n\n if (specifier.type === 'ImportDefaultSpecifier') {\n imports.set(specifier.local.name, {\n imported: 'default',\n kind: 'named',\n source: statement.source.value,\n });\n continue;\n }\n\n imports.set(specifier.local.name, {\n kind: 'namespace',\n source: statement.source.value,\n });\n }\n\n return sawValueImport || isTypeOnlyImport(statement);\n};\n\nconst getImportSpecifierName = (specifier: ImportSpecifier): string =>\n getModuleExportName(specifier.imported);\n\nconst getLocalDeclarationNames = (\n declaration: Declaration\n): string[] | null => {\n if (\n declaration.type === 'VariableDeclaration' ||\n declaration.type === 'FunctionDeclaration' ||\n declaration.type === 'ClassDeclaration'\n ) {\n return Object.keys(\n getBindingIdentifiers(\n declaration as\n | VariableDeclaration\n | FunctionDeclaration\n | ClassDeclaration\n )\n );\n }\n\n if (\n declaration.type === 'TSEnumDeclaration' ||\n declaration.type === 'TSModuleDeclaration'\n ) {\n return null;\n }\n\n return [];\n};\n\nconst collectLocalExportNamedDeclaration = (\n statement: ExportNamedDeclaration,\n importedBindings: Map<string, LocalImportBinding>,\n passthroughCandidates: Map<string, string[]>,\n explicitExports: Set<string>\n): { complete: boolean; ok: boolean } => {\n let complete = true;\n\n if (isTypeOnlyExport(statement)) {\n return {\n complete: true,\n ok: true,\n };\n }\n\n if (statement.declaration) {\n const names = getLocalDeclarationNames(statement.declaration);\n if (names === null) {\n return {\n complete: false,\n ok: false,\n };\n }\n\n for (const name of names) {\n explicitExports.add(name);\n }\n\n return {\n complete: names.length === 0,\n ok: true,\n };\n }\n\n for (const specifier of statement.specifiers) {\n if (specifier.type !== 'ExportSpecifier') {\n return {\n complete: false,\n ok: false,\n };\n }\n\n if (specifier.exportKind === 'type') {\n continue;\n }\n\n const exported = getModuleExportName(specifier.exported);\n explicitExports.add(exported);\n\n if (specifier.local.type !== 'Identifier') {\n complete = false;\n continue;\n }\n\n if (!importedBindings.has(specifier.local.name)) {\n complete = false;\n continue;\n }\n\n if (!passthroughCandidates.has(specifier.local.name)) {\n passthroughCandidates.set(specifier.local.name, []);\n }\n passthroughCandidates.get(specifier.local.name)!.push(exported);\n }\n\n return {\n complete: complete && statement.specifiers.length > 0,\n ok: true,\n };\n};\n\nconst collectPassthroughReexports = (\n ast: File,\n importedBindings: Map<string, LocalImportBinding>,\n passthroughCandidates: Map<string, string[]>,\n reexports: RawBarrelReexport[]\n): { complete: boolean; ok: boolean } => {\n let complete = true;\n const bindingReferenceCounts = new Map<string, number>();\n\n traverse(ast, {\n Program(path) {\n for (const localName of passthroughCandidates.keys()) {\n bindingReferenceCounts.set(\n localName,\n path.scope.getBinding(localName)?.referencePaths.length ?? -1\n );\n }\n path.stop();\n },\n });\n\n for (const [localName, exportedNames] of passthroughCandidates) {\n if (bindingReferenceCounts.get(localName) !== exportedNames.length) {\n complete = false;\n continue;\n }\n\n const imported = importedBindings.get(localName)!;\n for (const exported of exportedNames) {\n if (imported.kind === 'namespace') {\n reexports.push({\n exported,\n kind: 'namespace',\n source: imported.source,\n });\n continue;\n }\n\n reexports.push({\n exported,\n imported: imported.imported,\n kind: 'named',\n source: imported.source,\n });\n }\n }\n\n return {\n complete,\n ok: true,\n };\n};\n\nfunction analyzeBarrelProgram(ast: File): RawBarrelManifest | null {\n const reexports: RawBarrelReexport[] = [];\n const explicitExports = new Set<string>();\n const exportAll: string[] = [];\n const importedBindings = new Map<string, LocalImportBinding>();\n const passthroughCandidates = new Map<string, string[]>();\n let complete = true;\n\n for (const statement of ast.program.body) {\n if (statement.type === 'ImportDeclaration') {\n if (!collectImportBinding(statement, importedBindings)) {\n return null;\n }\n continue;\n }\n\n if (statement.type === 'ExportNamedDeclaration') {\n if (statement.source) {\n if (\n !collectExportNamedDeclaration(statement, reexports, explicitExports)\n ) {\n return null;\n }\n continue;\n }\n\n const localResult = collectLocalExportNamedDeclaration(\n statement,\n importedBindings,\n passthroughCandidates,\n explicitExports\n );\n if (!localResult.ok) {\n return null;\n }\n complete = complete && localResult.complete;\n continue;\n }\n\n if (statement.type === 'ExportAllDeclaration') {\n if (statement.exportKind === 'type') {\n continue;\n }\n\n if (!statement.source) {\n return null;\n }\n\n exportAll.push(getExportAllSource(statement));\n continue;\n }\n\n if (statement.type === 'ExportDefaultDeclaration') {\n return null;\n }\n\n if (!isTypeOnlyStatement(statement)) {\n return null;\n }\n }\n\n const passthroughResult = collectPassthroughReexports(\n ast,\n importedBindings,\n passthroughCandidates,\n reexports\n );\n if (!passthroughResult.ok) {\n return null;\n }\n complete = complete && passthroughResult.complete;\n\n if (reexports.length === 0 && exportAll.length === 0) {\n return null;\n }\n\n return {\n complete,\n explicitExports: [...explicitExports],\n exportAll,\n kind: 'barrel',\n reexports,\n };\n}\n\nconst getExportAllSource = (statement: ExportAllDeclaration): string =>\n statement.source.value;\n\nexport function analyzeBarrelFile(\n ast: File\n): BarrelManifestCacheEntry | RawBarrelManifest {\n const result = analyzeBarrelProgram(ast);\n\n if (!result) {\n return {\n kind: 'ineligible',\n reason: 'impure',\n };\n }\n\n return result;\n}\n"],"mappings":"AAAA;AACA,OAAOA,QAAQ,MAAM,iBAAiB;AACtC,SAASC,qBAAqB,QAAQ,cAAc;AAiGpD,MAAMC,gBAAgB,GAAIC,SAA4B,IAAc;EAClE,IAAIA,SAAS,CAACC,UAAU,KAAK,MAAM,EAAE;IACnC,OAAO,IAAI;EACb;EAEA,IAAID,SAAS,CAACE,UAAU,CAACC,MAAM,KAAK,CAAC,EAAE;IACrC,OAAO,KAAK;EACd;EAEA,OAAOH,SAAS,CAACE,UAAU,CAACE,KAAK,CAC9BC,SAAS,IACRA,SAAS,CAACC,IAAI,KAAK,iBAAiB,IAAID,SAAS,CAACJ,UAAU,KAAK,MACrE,CAAC;AACH,CAAC;AAED,MAAMM,gBAAgB,GAAIP,SAAiC,IACzDA,SAAS,CAACQ,UAAU,KAAK,MAAM;AAEjC,MAAMC,mBAAmB,GAAIC,IAAgC,IAC3DA,IAAI,CAACJ,IAAI,KAAK,YAAY,GAAGI,IAAI,CAACC,IAAI,GAAGD,IAAI,CAACE,KAAK;AAErD,MAAMC,mBAAmB,GAAIb,SAAkC,IAAc;EAC3E,QAAQA,SAAS,CAACM,IAAI;IACpB,KAAK,gBAAgB;IACrB,KAAK,mBAAmB;IACxB,KAAK,wBAAwB;IAC7B,KAAK,wBAAwB;MAC3B,OAAO,IAAI;IACb;MACE,OAAO,KAAK;EAChB;AACF,CAAC;AAED,SAASQ,6BAA6BA,CACpCd,SAAiC,EACjCe,SAA8B,EAC9BC,eAA4B,EACnB;EACT,IAAI,CAAChB,SAAS,CAACiB,MAAM,EAAE;IACrB,OAAOV,gBAAgB,CAACP,SAAS,CAAC;EACpC;EAEA,IAAIO,gBAAgB,CAACP,SA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,IAAI;MACb;MAEAyC,SAAS,CAACtC,IAAI,CAAC0C,kBAAkB,CAAC9D,SAAS,CAAC,CAAC;MAC7C;IACF;IAEA,IAAIA,SAAS,CAACM,IAAI,KAAK,0BAA0B,EAAE;MACjD,OAAO,IAAI;IACb;IAEA,IAAI,CAACO,mBAAmB,CAACb,SAAS,CAAC,EAAE;MACnC,OAAO,IAAI;IACb;EACF;EAEA,MAAM+D,iBAAiB,GAAGnB,2BAA2B,CACnDC,GAAG,EACHR,gBAAgB,EAChBC,qBAAqB,EACrBvB,SACF,CAAC;EACD,IAAI,CAACgD,iBAAiB,CAACvB,EAAE,EAAE;IACzB,OAAO,IAAI;EACb;EACAD,QAAQ,GAAGA,QAAQ,IAAIwB,iBAAiB,CAACxB,QAAQ;EAEjD,IAAIxB,SAAS,CAACZ,MAAM,KAAK,CAAC,IAAIuD,SAAS,CAACvD,MAAM,KAAK,CAAC,EAAE;IACpD,OAAO,IAAI;EACb;EAEA,OAAO;IACLoC,QAAQ;IACRvB,eAAe,EAAE,CAAC,GAAGA,eAAe,CAAC;IACrC0C,SAAS;IACThC,IAAI,EAAE,QAAQ;IACdX;EACF,CAAC;AACH;AAEA,MAAM+C,kBAAkB,GAAI9D,SAA+B,IACzDA,SAAS,CAACiB,MAAM,CAACL,KAAK;AAExB,OAAO,SAASoD,iBAAiBA,CAC/BnB,GAAS,EACqC;EAC9C,MAAMoB,MAAM,GAAGT,oBAAoB,CAACX,GAAG,CAAC;EAExC,IAAI,CAACoB,MAAM,EAAE;IACX,OAAO;MACLvC,IAAI,EAAE,YAAY;MAClBwC,MAAM,EAAE;IACV,CAAC;EACH;EAEA,OAAOD,MAAM;AACf","ignoreList":[]}
|
|
@@ -60,11 +60,16 @@ export function* getExports() {
|
|
|
60
60
|
const resolvedImports = yield* this.getNext('resolveImports', entrypoint, {
|
|
61
61
|
imports: new Map(withWildcardReexport.map(i => [i.source, []]))
|
|
62
62
|
});
|
|
63
|
+
const dependencyFilenames = resolvedImports.flatMap(dependency => dependency.resolved ? [dependency.resolved] : []);
|
|
63
64
|
const importedEntrypoints = findExportsInImports(entrypoint, resolvedImports);
|
|
64
65
|
for (const importedEntrypoint of importedEntrypoints) {
|
|
65
66
|
const exports = yield* this.getNext('getExports', importedEntrypoint.entrypoint, undefined);
|
|
66
67
|
result.push(...exports);
|
|
67
68
|
}
|
|
69
|
+
cache.add('exports', entrypoint.name, result);
|
|
70
|
+
cache.setCacheDependencies('exports', entrypoint.name, dependencyFilenames);
|
|
71
|
+
entrypoint.log(`exports: %o`, result);
|
|
72
|
+
return result;
|
|
68
73
|
}
|
|
69
74
|
entrypoint.log(`exports: %o`, result);
|
|
70
75
|
cache.add('exports', entrypoint.name, result);
|