@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.
Files changed (98) hide show
  1. package/esm/cache.js +160 -12
  2. package/esm/cache.js.map +1 -1
  3. package/esm/debug/fileReporter.js.map +1 -1
  4. package/esm/module.js +59 -5
  5. package/esm/module.js.map +1 -1
  6. package/esm/plugins/shaker.js +152 -13
  7. package/esm/plugins/shaker.js.map +1 -1
  8. package/esm/shaker.js +51 -23
  9. package/esm/shaker.js.map +1 -1
  10. package/esm/transform/BaseEntrypoint.js +3 -1
  11. package/esm/transform/BaseEntrypoint.js.map +1 -1
  12. package/esm/transform/Entrypoint.js +68 -20
  13. package/esm/transform/Entrypoint.js.map +1 -1
  14. package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
  15. package/esm/transform/actions/BaseAction.js +2 -1
  16. package/esm/transform/actions/BaseAction.js.map +1 -1
  17. package/esm/transform/actions/actionRunner.js +2 -2
  18. package/esm/transform/actions/actionRunner.js.map +1 -1
  19. package/esm/transform/barrelManifest.js +291 -0
  20. package/esm/transform/barrelManifest.js.map +1 -0
  21. package/esm/transform/generators/getExports.js +5 -0
  22. package/esm/transform/generators/getExports.js.map +1 -1
  23. package/esm/transform/generators/processEntrypoint.js +31 -1
  24. package/esm/transform/generators/processEntrypoint.js.map +1 -1
  25. package/esm/transform/generators/resolveImports.js +29 -5
  26. package/esm/transform/generators/resolveImports.js.map +1 -1
  27. package/esm/transform/generators/rewriteBarrelImports.js +733 -0
  28. package/esm/transform/generators/rewriteBarrelImports.js.map +1 -0
  29. package/esm/transform/generators/transform.js +154 -21
  30. package/esm/transform/generators/transform.js.map +1 -1
  31. package/esm/transform/types.js.map +1 -1
  32. package/esm/transform.js +45 -23
  33. package/esm/transform.js.map +1 -1
  34. package/esm/utils/collectTemplateDependencies.js +9 -0
  35. package/esm/utils/collectTemplateDependencies.js.map +1 -1
  36. package/lib/cache.js +163 -12
  37. package/lib/cache.js.map +1 -1
  38. package/lib/debug/fileReporter.js.map +1 -1
  39. package/lib/module.js +61 -7
  40. package/lib/module.js.map +1 -1
  41. package/lib/plugins/shaker.js +152 -13
  42. package/lib/plugins/shaker.js.map +1 -1
  43. package/lib/shaker.js +58 -26
  44. package/lib/shaker.js.map +1 -1
  45. package/lib/transform/BaseEntrypoint.js +3 -1
  46. package/lib/transform/BaseEntrypoint.js.map +1 -1
  47. package/lib/transform/Entrypoint.js +69 -20
  48. package/lib/transform/Entrypoint.js.map +1 -1
  49. package/lib/transform/EvaluatedEntrypoint.js.map +1 -1
  50. package/lib/transform/actions/BaseAction.js +2 -1
  51. package/lib/transform/actions/BaseAction.js.map +1 -1
  52. package/lib/transform/actions/actionRunner.js +2 -2
  53. package/lib/transform/actions/actionRunner.js.map +1 -1
  54. package/lib/transform/barrelManifest.js +300 -0
  55. package/lib/transform/barrelManifest.js.map +1 -0
  56. package/lib/transform/generators/getExports.js +5 -0
  57. package/lib/transform/generators/getExports.js.map +1 -1
  58. package/lib/transform/generators/processEntrypoint.js +31 -1
  59. package/lib/transform/generators/processEntrypoint.js.map +1 -1
  60. package/lib/transform/generators/resolveImports.js +29 -5
  61. package/lib/transform/generators/resolveImports.js.map +1 -1
  62. package/lib/transform/generators/rewriteBarrelImports.js +743 -0
  63. package/lib/transform/generators/rewriteBarrelImports.js.map +1 -0
  64. package/lib/transform/generators/transform.js +158 -22
  65. package/lib/transform/generators/transform.js.map +1 -1
  66. package/lib/transform/types.js.map +1 -1
  67. package/lib/transform.js +45 -23
  68. package/lib/transform.js.map +1 -1
  69. package/lib/utils/collectTemplateDependencies.js +9 -0
  70. package/lib/utils/collectTemplateDependencies.js.map +1 -1
  71. package/package.json +8 -4
  72. package/types/cache.d.ts +23 -2
  73. package/types/cache.js +170 -10
  74. package/types/debug/fileReporter.d.ts +1 -0
  75. package/types/module.d.ts +3 -0
  76. package/types/module.js +65 -5
  77. package/types/plugins/shaker.js +161 -16
  78. package/types/shaker.d.ts +10 -1
  79. package/types/shaker.js +56 -28
  80. package/types/transform/BaseEntrypoint.d.ts +3 -1
  81. package/types/transform/BaseEntrypoint.js +5 -1
  82. package/types/transform/Entrypoint.d.ts +10 -1
  83. package/types/transform/Entrypoint.js +81 -23
  84. package/types/transform/EvaluatedEntrypoint.d.ts +2 -0
  85. package/types/transform/actions/BaseAction.d.ts +2 -1
  86. package/types/transform/actions/BaseAction.js +3 -1
  87. package/types/transform/actions/actionRunner.js +2 -2
  88. package/types/transform/barrelManifest.d.ts +42 -0
  89. package/types/transform/barrelManifest.js +300 -0
  90. package/types/transform/generators/getExports.js +5 -0
  91. package/types/transform/generators/processEntrypoint.js +29 -1
  92. package/types/transform/generators/resolveImports.js +29 -5
  93. package/types/transform/generators/rewriteBarrelImports.d.ts +15 -0
  94. package/types/transform/generators/rewriteBarrelImports.js +815 -0
  95. package/types/transform/generators/transform.js +148 -19
  96. package/types/transform/types.d.ts +3 -0
  97. package/types/transform.js +47 -23
  98. package/types/utils/collectTemplateDependencies.js +9 -0
@@ -0,0 +1,300 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.analyzeBarrelFile = analyzeBarrelFile;
7
+ var _traverse = _interopRequireDefault(require("@babel/traverse"));
8
+ var _types = require("@babel/types");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ /* eslint-disable no-continue, @typescript-eslint/no-use-before-define */
11
+
12
+ const isTypeOnlyImport = statement => {
13
+ if (statement.importKind === 'type') {
14
+ return true;
15
+ }
16
+ if (statement.specifiers.length === 0) {
17
+ return false;
18
+ }
19
+ return statement.specifiers.every(specifier => specifier.type === 'ImportSpecifier' && specifier.importKind === 'type');
20
+ };
21
+ const isTypeOnlyExport = statement => statement.exportKind === 'type';
22
+ const getModuleExportName = node => node.type === 'Identifier' ? node.name : node.value;
23
+ const isTypeOnlyStatement = statement => {
24
+ switch (statement.type) {
25
+ case 'EmptyStatement':
26
+ case 'TSDeclareFunction':
27
+ case 'TSInterfaceDeclaration':
28
+ case 'TSTypeAliasDeclaration':
29
+ return true;
30
+ default:
31
+ return false;
32
+ }
33
+ };
34
+ function collectExportNamedDeclaration(statement, reexports, explicitExports) {
35
+ if (!statement.source) {
36
+ return isTypeOnlyExport(statement);
37
+ }
38
+ if (isTypeOnlyExport(statement)) {
39
+ return true;
40
+ }
41
+ const source = statement.source.value;
42
+ for (const specifier of statement.specifiers) {
43
+ if (specifier.type === 'ExportSpecifier') {
44
+ if (specifier.exportKind === 'type') {
45
+ continue;
46
+ }
47
+ explicitExports.add(getModuleExportName(specifier.exported));
48
+ reexports.push(getNamedReexport(specifier, source));
49
+ continue;
50
+ }
51
+ if (specifier.type === 'ExportDefaultSpecifier') {
52
+ explicitExports.add(getModuleExportName(specifier.exported));
53
+ reexports.push(getDefaultReexport(specifier, source));
54
+ continue;
55
+ }
56
+ if (specifier.type === 'ExportNamespaceSpecifier') {
57
+ explicitExports.add(getModuleExportName(specifier.exported));
58
+ reexports.push(getNamespaceReexport(specifier, source));
59
+ continue;
60
+ }
61
+ return false;
62
+ }
63
+ return statement.specifiers.length > 0;
64
+ }
65
+ function getNamedReexport(specifier, source) {
66
+ return {
67
+ exported: getModuleExportName(specifier.exported),
68
+ imported: getModuleExportName(specifier.local),
69
+ kind: 'named',
70
+ source
71
+ };
72
+ }
73
+ function getDefaultReexport(specifier, source) {
74
+ return {
75
+ exported: getModuleExportName(specifier.exported),
76
+ imported: 'default',
77
+ kind: 'named',
78
+ source
79
+ };
80
+ }
81
+ function getNamespaceReexport(specifier, source) {
82
+ return {
83
+ exported: getModuleExportName(specifier.exported),
84
+ kind: 'namespace',
85
+ source
86
+ };
87
+ }
88
+ const collectImportBinding = (statement, imports) => {
89
+ if (statement.importKind === 'type') {
90
+ return true;
91
+ }
92
+ if (statement.specifiers.length === 0) {
93
+ return false;
94
+ }
95
+ let sawValueImport = false;
96
+ for (const specifier of statement.specifiers) {
97
+ if (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type') {
98
+ continue;
99
+ }
100
+ sawValueImport = true;
101
+ if (specifier.type === 'ImportSpecifier') {
102
+ imports.set(specifier.local.name, {
103
+ imported: getImportSpecifierName(specifier),
104
+ kind: 'named',
105
+ source: statement.source.value
106
+ });
107
+ continue;
108
+ }
109
+ if (specifier.type === 'ImportDefaultSpecifier') {
110
+ imports.set(specifier.local.name, {
111
+ imported: 'default',
112
+ kind: 'named',
113
+ source: statement.source.value
114
+ });
115
+ continue;
116
+ }
117
+ imports.set(specifier.local.name, {
118
+ kind: 'namespace',
119
+ source: statement.source.value
120
+ });
121
+ }
122
+ return sawValueImport || isTypeOnlyImport(statement);
123
+ };
124
+ const getImportSpecifierName = specifier => getModuleExportName(specifier.imported);
125
+ const getLocalDeclarationNames = declaration => {
126
+ if (declaration.type === 'VariableDeclaration' || declaration.type === 'FunctionDeclaration' || declaration.type === 'ClassDeclaration') {
127
+ return Object.keys((0, _types.getBindingIdentifiers)(declaration));
128
+ }
129
+ if (declaration.type === 'TSEnumDeclaration' || declaration.type === 'TSModuleDeclaration') {
130
+ return null;
131
+ }
132
+ return [];
133
+ };
134
+ const collectLocalExportNamedDeclaration = (statement, importedBindings, passthroughCandidates, explicitExports) => {
135
+ let complete = true;
136
+ if (isTypeOnlyExport(statement)) {
137
+ return {
138
+ complete: true,
139
+ ok: true
140
+ };
141
+ }
142
+ if (statement.declaration) {
143
+ const names = getLocalDeclarationNames(statement.declaration);
144
+ if (names === null) {
145
+ return {
146
+ complete: false,
147
+ ok: false
148
+ };
149
+ }
150
+ for (const name of names) {
151
+ explicitExports.add(name);
152
+ }
153
+ return {
154
+ complete: names.length === 0,
155
+ ok: true
156
+ };
157
+ }
158
+ for (const specifier of statement.specifiers) {
159
+ if (specifier.type !== 'ExportSpecifier') {
160
+ return {
161
+ complete: false,
162
+ ok: false
163
+ };
164
+ }
165
+ if (specifier.exportKind === 'type') {
166
+ continue;
167
+ }
168
+ const exported = getModuleExportName(specifier.exported);
169
+ explicitExports.add(exported);
170
+ if (specifier.local.type !== 'Identifier') {
171
+ complete = false;
172
+ continue;
173
+ }
174
+ if (!importedBindings.has(specifier.local.name)) {
175
+ complete = false;
176
+ continue;
177
+ }
178
+ if (!passthroughCandidates.has(specifier.local.name)) {
179
+ passthroughCandidates.set(specifier.local.name, []);
180
+ }
181
+ passthroughCandidates.get(specifier.local.name).push(exported);
182
+ }
183
+ return {
184
+ complete: complete && statement.specifiers.length > 0,
185
+ ok: true
186
+ };
187
+ };
188
+ const collectPassthroughReexports = (ast, importedBindings, passthroughCandidates, reexports) => {
189
+ let complete = true;
190
+ const bindingReferenceCounts = new Map();
191
+ (0, _traverse.default)(ast, {
192
+ Program(path) {
193
+ for (const localName of passthroughCandidates.keys()) {
194
+ var _path$scope$getBindin, _path$scope$getBindin2;
195
+ bindingReferenceCounts.set(localName, (_path$scope$getBindin = (_path$scope$getBindin2 = path.scope.getBinding(localName)) === null || _path$scope$getBindin2 === void 0 ? void 0 : _path$scope$getBindin2.referencePaths.length) !== null && _path$scope$getBindin !== void 0 ? _path$scope$getBindin : -1);
196
+ }
197
+ path.stop();
198
+ }
199
+ });
200
+ for (const [localName, exportedNames] of passthroughCandidates) {
201
+ if (bindingReferenceCounts.get(localName) !== exportedNames.length) {
202
+ complete = false;
203
+ continue;
204
+ }
205
+ const imported = importedBindings.get(localName);
206
+ for (const exported of exportedNames) {
207
+ if (imported.kind === 'namespace') {
208
+ reexports.push({
209
+ exported,
210
+ kind: 'namespace',
211
+ source: imported.source
212
+ });
213
+ continue;
214
+ }
215
+ reexports.push({
216
+ exported,
217
+ imported: imported.imported,
218
+ kind: 'named',
219
+ source: imported.source
220
+ });
221
+ }
222
+ }
223
+ return {
224
+ complete,
225
+ ok: true
226
+ };
227
+ };
228
+ function analyzeBarrelProgram(ast) {
229
+ const reexports = [];
230
+ const explicitExports = new Set();
231
+ const exportAll = [];
232
+ const importedBindings = new Map();
233
+ const passthroughCandidates = new Map();
234
+ let complete = true;
235
+ for (const statement of ast.program.body) {
236
+ if (statement.type === 'ImportDeclaration') {
237
+ if (!collectImportBinding(statement, importedBindings)) {
238
+ return null;
239
+ }
240
+ continue;
241
+ }
242
+ if (statement.type === 'ExportNamedDeclaration') {
243
+ if (statement.source) {
244
+ if (!collectExportNamedDeclaration(statement, reexports, explicitExports)) {
245
+ return null;
246
+ }
247
+ continue;
248
+ }
249
+ const localResult = collectLocalExportNamedDeclaration(statement, importedBindings, passthroughCandidates, explicitExports);
250
+ if (!localResult.ok) {
251
+ return null;
252
+ }
253
+ complete = complete && localResult.complete;
254
+ continue;
255
+ }
256
+ if (statement.type === 'ExportAllDeclaration') {
257
+ if (statement.exportKind === 'type') {
258
+ continue;
259
+ }
260
+ if (!statement.source) {
261
+ return null;
262
+ }
263
+ exportAll.push(getExportAllSource(statement));
264
+ continue;
265
+ }
266
+ if (statement.type === 'ExportDefaultDeclaration') {
267
+ return null;
268
+ }
269
+ if (!isTypeOnlyStatement(statement)) {
270
+ return null;
271
+ }
272
+ }
273
+ const passthroughResult = collectPassthroughReexports(ast, importedBindings, passthroughCandidates, reexports);
274
+ if (!passthroughResult.ok) {
275
+ return null;
276
+ }
277
+ complete = complete && passthroughResult.complete;
278
+ if (reexports.length === 0 && exportAll.length === 0) {
279
+ return null;
280
+ }
281
+ return {
282
+ complete,
283
+ explicitExports: [...explicitExports],
284
+ exportAll,
285
+ kind: 'barrel',
286
+ reexports
287
+ };
288
+ }
289
+ const getExportAllSource = statement => statement.source.value;
290
+ function analyzeBarrelFile(ast) {
291
+ const result = analyzeBarrelProgram(ast);
292
+ if (!result) {
293
+ return {
294
+ kind: 'ineligible',
295
+ reason: 'impure'
296
+ };
297
+ }
298
+ return result;
299
+ }
300
+ //# sourceMappingURL=barrelManifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"barrelManifest.js","names":["_traverse","_interopRequireDefault","require","_types","e","__esModule","default","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","getBindingIdentifiers","collectLocalExportNamedDeclaration","importedBindings","passthroughCandidates","complete","ok","names","has","get","collectPassthroughReexports","ast","bindingReferenceCounts","Map","traverse","Program","path","localName","_path$scope$getBindin","_path$scope$getBindin2","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":";;;;;;AACA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAAqD,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAFrD;;AAmGA,MAAMG,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,eAA4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YAAY;MAClB4C,MAAM,EAAE;IACV,CAAC;EACH;EAEA,OAAOD,MAAM;AACf","ignoreList":[]}
@@ -67,11 +67,16 @@ function* getExports() {
67
67
  const resolvedImports = yield* this.getNext('resolveImports', entrypoint, {
68
68
  imports: new Map(withWildcardReexport.map(i => [i.source, []]))
69
69
  });
70
+ const dependencyFilenames = resolvedImports.flatMap(dependency => dependency.resolved ? [dependency.resolved] : []);
70
71
  const importedEntrypoints = findExportsInImports(entrypoint, resolvedImports);
71
72
  for (const importedEntrypoint of importedEntrypoints) {
72
73
  const exports = yield* this.getNext('getExports', importedEntrypoint.entrypoint, undefined);
73
74
  result.push(...exports);
74
75
  }
76
+ cache.add('exports', entrypoint.name, result);
77
+ cache.setCacheDependencies('exports', entrypoint.name, dependencyFilenames);
78
+ entrypoint.log(`exports: %o`, result);
79
+ return result;
75
80
  }
76
81
  entrypoint.log(`exports: %o`, result);
77
82
  cache.add('exports', entrypoint.name, result);
@@ -1 +1 @@
1
- {"version":3,"file":"getExports.js","names":["_collectExportsAndImports","require","findExportsInImports","entrypoint","imports","results","imp","resolved","Error","source","newEntrypoint","createChild","push","import","getExports","services","cache","loadedAndParsed","ast","undefined","log","name","has","get","withWildcardReexport","result","babel","traverse","Program","path","exports","reexports","collectExportsAndImports","Object","keys","forEach","token","e","exported","filter","length","resolvedImports","getNext","Map","map","i","importedEntrypoints","importedEntrypoint","add"],"sources":["../../../src/transform/generators/getExports.ts"],"sourcesContent":["import type { IReexport } from '../../utils/collectExportsAndImports';\nimport { collectExportsAndImports } from '../../utils/collectExportsAndImports';\nimport type { Entrypoint } from '../Entrypoint';\nimport type { IEntrypointDependency } from '../Entrypoint.types';\nimport type { IGetExportsAction, SyncScenarioForAction } from '../types';\n\nexport function findExportsInImports(\n entrypoint: Entrypoint,\n imports: IEntrypointDependency[]\n): { entrypoint: Entrypoint; import: string }[] {\n const results: {\n entrypoint: Entrypoint;\n import: string;\n }[] = [];\n\n for (const imp of imports) {\n const { resolved } = imp;\n if (!resolved) {\n throw new Error(`Could not resolve import ${imp.source}`);\n }\n\n const newEntrypoint = entrypoint.createChild(resolved, []);\n\n if (newEntrypoint === 'loop') {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n results.push({\n entrypoint: newEntrypoint,\n import: imp.source,\n });\n }\n\n return results;\n}\n\nexport function* getExports(\n this: IGetExportsAction\n): SyncScenarioForAction<IGetExportsAction> {\n const {\n entrypoint,\n services: { cache },\n } = this;\n const { loadedAndParsed } = entrypoint;\n if (loadedAndParsed.ast === undefined) {\n return [];\n }\n\n entrypoint.log(`get exports from %s`, entrypoint.name);\n\n if (cache.has('exports', entrypoint.name)) {\n return cache.get('exports', entrypoint.name)!;\n }\n\n let withWildcardReexport: IReexport[] = [];\n const result: string[] = [];\n\n this.services.babel.traverse(loadedAndParsed.ast!, {\n Program(path) {\n const { exports, reexports } = collectExportsAndImports(path, 'disabled');\n Object.keys(exports).forEach((token) => {\n result.push(token);\n });\n\n reexports.forEach((e) => {\n if (e.exported !== '*') {\n result.push(e.exported);\n }\n });\n\n withWildcardReexport = reexports.filter((e) => e.exported === '*');\n },\n });\n\n if (withWildcardReexport.length) {\n const resolvedImports = yield* this.getNext('resolveImports', entrypoint, {\n imports: new Map(withWildcardReexport.map((i) => [i.source, []])),\n });\n\n const importedEntrypoints = findExportsInImports(\n entrypoint,\n resolvedImports\n );\n\n for (const importedEntrypoint of importedEntrypoints) {\n const exports = yield* this.getNext(\n 'getExports',\n importedEntrypoint.entrypoint,\n undefined\n );\n\n result.push(...exports);\n }\n }\n\n entrypoint.log(`exports: %o`, result);\n\n cache.add('exports', entrypoint.name, result);\n\n return result;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,yBAAA,GAAAC,OAAA;AAKO,SAASC,oBAAoBA,CAClCC,UAAsB,EACtBC,OAAgC,EACc;EAC9C,MAAMC,OAGH,GAAG,EAAE;EAER,KAAK,MAAMC,GAAG,IAAIF,OAAO,EAAE;IACzB,MAAM;MAAEG;IAAS,CAAC,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MAAM,CAACb,IAAI,CAACwB,KAAK,CAAC;MACpB,CAAC,CAAC;MAEFL,SAAS,CAACI,OAAO,CAAEE,CAAC,IAAK;QACvB,IAAIA,CAAC,CAACC,QAAQ,KAAK,GAAG,EAAE;UACtBb,MAAM,CAACb,IAAI,CAACyB,CAAC,CAACC,QAAQ,CAAC;QACzB;MACF,CAAC,CAAC;MAEFd,oBAAoB,GAAGO,SAAS,CAACQ,MAAM,CAAEF,CAAC,IAAKA,CAAC,CAACC,QAAQ,KAAK,GAAG,CAAC;IACpE;EACF,CAAC,CAAC;EAEF,IAAId,oBAAoB,CAACgB,MAAM,EAAE;IAC/B,MAAMC,eAAe,GAAG,OAAO,IAAI,CAACC,OAAO,CAAC,gBAAgB,EAAEvC,UAAU,EAAE;MACxEC,OAAO,EAAE,IAAIuC,GAAG,CAACnB,oBAAoB,CAACoB,GAAG,CAAEC,CAAC,IAAK,CAACA,CAAC,CAACpC,MAAM,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC,CAAC;IAEF,MAAMqC,mBAAmB,GAAG5C,oBAAoB,CAC9CC,UAAU,EACVsC,eACF,CAAC;IAED,KAAK,MAAMM,kBAAkB,IAAID,mBAAmB,EAAE;MACpD,MAAMhB,OAAO,GAAG,OAAO,IAAI,CAACY,OAAO,CACjC,YAAY,EACZK,kBAAkB,CAAC5C,UAAU,EAC7BgB,SACF,CAAC;MAEDM,MAAM,CAACb,IAAI,CAAC,GAAGkB,OAAO,CAAC;IACzB;EACF;EAEA3B,UAAU,CAACiB,GAAG,CAAC,aAAa,EAAEK,MAAM,CAAC;EAErCT,KAAK,CAACgC,GAAG,CAAC,SAAS,EAAE7C,UAAU,CAACkB,IAAI,EAAEI,MAAM,CAAC;EAE7C,OAAOA,MAAM;AACf","ignoreList":[]}
1
+ {"version":3,"file":"getExports.js","names":["_collectExportsAndImports","require","findExportsInImports","entrypoint","imports","results","imp","resolved","Error","source","newEntrypoint","createChild","push","import","getExports","services","cache","loadedAndParsed","ast","undefined","log","name","has","get","withWildcardReexport","result","babel","traverse","Program","path","exports","reexports","collectExportsAndImports","Object","keys","forEach","token","e","exported","filter","length","resolvedImports","getNext","Map","map","i","dependencyFilenames","flatMap","dependency","importedEntrypoints","importedEntrypoint","add","setCacheDependencies"],"sources":["../../../src/transform/generators/getExports.ts"],"sourcesContent":["import type { IReexport } from '../../utils/collectExportsAndImports';\nimport { collectExportsAndImports } from '../../utils/collectExportsAndImports';\nimport type { Entrypoint } from '../Entrypoint';\nimport type { IEntrypointDependency } from '../Entrypoint.types';\nimport type { IGetExportsAction, SyncScenarioForAction } from '../types';\n\nexport function findExportsInImports(\n entrypoint: Entrypoint,\n imports: IEntrypointDependency[]\n): { entrypoint: Entrypoint; import: string }[] {\n const results: {\n entrypoint: Entrypoint;\n import: string;\n }[] = [];\n\n for (const imp of imports) {\n const { resolved } = imp;\n if (!resolved) {\n throw new Error(`Could not resolve import ${imp.source}`);\n }\n\n const newEntrypoint = entrypoint.createChild(resolved, []);\n\n if (newEntrypoint === 'loop') {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n results.push({\n entrypoint: newEntrypoint,\n import: imp.source,\n });\n }\n\n return results;\n}\n\nexport function* getExports(\n this: IGetExportsAction\n): SyncScenarioForAction<IGetExportsAction> {\n const {\n entrypoint,\n services: { cache },\n } = this;\n const { loadedAndParsed } = entrypoint;\n if (loadedAndParsed.ast === undefined) {\n return [];\n }\n\n entrypoint.log(`get exports from %s`, entrypoint.name);\n\n if (cache.has('exports', entrypoint.name)) {\n return cache.get('exports', entrypoint.name)!;\n }\n\n let withWildcardReexport: IReexport[] = [];\n const result: string[] = [];\n\n this.services.babel.traverse(loadedAndParsed.ast!, {\n Program(path) {\n const { exports, reexports } = collectExportsAndImports(path, 'disabled');\n Object.keys(exports).forEach((token) => {\n result.push(token);\n });\n\n reexports.forEach((e) => {\n if (e.exported !== '*') {\n result.push(e.exported);\n }\n });\n\n withWildcardReexport = reexports.filter((e) => e.exported === '*');\n },\n });\n\n if (withWildcardReexport.length) {\n const resolvedImports = yield* this.getNext('resolveImports', entrypoint, {\n imports: new Map(withWildcardReexport.map((i) => [i.source, []])),\n });\n const dependencyFilenames = resolvedImports.flatMap((dependency) =>\n dependency.resolved ? [dependency.resolved] : []\n );\n\n const importedEntrypoints = findExportsInImports(\n entrypoint,\n resolvedImports\n );\n\n for (const importedEntrypoint of importedEntrypoints) {\n const exports = yield* this.getNext(\n 'getExports',\n importedEntrypoint.entrypoint,\n undefined\n );\n\n result.push(...exports);\n }\n\n cache.add('exports', entrypoint.name, result);\n cache.setCacheDependencies('exports', entrypoint.name, dependencyFilenames);\n\n entrypoint.log(`exports: %o`, result);\n\n return result;\n }\n\n entrypoint.log(`exports: %o`, result);\n\n cache.add('exports', entrypoint.name, result);\n\n return result;\n}\n"],"mappings":";;;;;;;AACA,IAAAA,yBAAA,GAAAC,OAAA;AAKO,SAASC,oBAAoBA,CAClCC,UAAsB,EACtBC,OAAgC,EACc;EAC9C,MAAMC,OAGH,GAAG,EAAE;EAER,KAAK,MAAMC,GAAG,IAAIF,OAAO,EAAE;IACzB,MAAM;MAAEG;IAAS,CAAC,GAAGD,GAAG;IACxB,IAAI,CAACC,QAAQ,EAAE;MACb,MAAM,IAAIC,KAAK,CAAC,4BAA4BF,GAAG,CAACG,MAAM,EAAE,CAAC;IAC3D;IAEA,MAAMC,aAAa,GAAGP,UAAU,CAACQ,WAAW,CAACJ,QAAQ,EAAE,EAAE,CAAC;IAE1D,IAAIG,aAAa,KAAK,MAAM,EAAE;MAC5B;MACA;IACF;IAEAL,OAAO,CAACO,IAAI,CAAC;MACXT,UAAU,EAAEO,aAAa;MACzBG,MAAM,EAAEP,GAAG,CAACG;IACd,CAAC,CAAC;EACJ;EAEA,OAAOJ,OAAO;AAChB;AAEO,UAAUS,UAAUA,CAAA,EAEiB;EAC1C,MAAM;IACJX,UAAU;IACVY,QAAQ,EAAE;MAAEC;IAAM;EACpB,CAAC,GAAG,IAAI;EACR,MAAM;IAAEC;EAAgB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B,GAAG,CAAEC,CAAC,IAAK,CAACA,CAAC,CAACpC,MAAM,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC,CAAC;IACF,MAAMqC,mBAAmB,GAAGL,eAAe,CAACM,OAAO,CAAEC,UAAU,IAC7DA,UAAU,CAACzC,QAAQ,GAAG,CAACyC,UAAU,CAACzC,QAAQ,CAAC,GAAG,EAChD,CAAC;IAED,MAAM0C,mBAAmB,GAAG/C,oBAAoB,CAC9CC,UAAU,EACVsC,eACF,CAAC;IAED,KAAK,MAAMS,kBAAkB,IAAID,mBAAmB,EAAE;MACpD,MAAMnB,OAAO,GAAG,OAAO,IAAI,CAACY,OAAO,CACjC,YAAY,EACZQ,kBAAkB,CAAC/C,UAAU,EAC7BgB,SACF,CAAC;MAEDM,MAAM,CAACb,IAAI,CAAC,GAAGkB,OAAO,CAAC;IACzB;IAEAd,KAAK,CAACmC,GAAG,CAAC,SAAS,EAAEhD,UAAU,CAACkB,IAAI,EAAEI,MAAM,CAAC;IAC7CT,KAAK,CAACoC,oBAAoB,CAAC,SAAS,EAAEjD,UAAU,CAACkB,IAAI,EAAEyB,mBAAmB,CAAC;IAE3E3C,UAAU,CAACiB,GAAG,CAAC,aAAa,EAAEK,MAAM,CAAC;IAErC,OAAOA,MAAM;EACf;EAEAtB,UAAU,CAACiB,GAAG,CAAC,aAAa,EAAEK,MAAM,CAAC;EAErCT,KAAK,CAACmC,GAAG,CAAC,SAAS,EAAEhD,UAAU,CAACkB,IAAI,EAAEI,MAAM,CAAC;EAE7C,OAAOA,MAAM;AACf","ignoreList":[]}
@@ -4,8 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.processEntrypoint = processEntrypoint;
7
+ var _shaker = require("../../shaker");
7
8
  var _AbortError = require("../actions/AbortError");
9
+ var _barrelManifest = require("../barrelManifest");
8
10
  function _usingCtx2() { var r = "function" == typeof SuppressedError ? SuppressedError : function (r, e) { var n = Error(); return n.name = "SuppressedError", n.error = r, n.suppressed = e, n; }, e = {}, n = []; function using(r, e) { if (null != e) { if (Object(e) !== e) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined."); if (r) var o = e[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]; if (void 0 === o && (o = e[Symbol.dispose || Symbol.for("Symbol.dispose")], r)) var t = o; if ("function" != typeof o) throw new TypeError("Object is not disposable."); t && (o = function () { try { t.call(e); } catch (r) { return Promise.reject(r); } }), n.push({ v: e, d: o, a: r }); } else r && n.push({ d: e, a: r }); return e; } return { e: e, u: using.bind(null, !1), a: using.bind(null, !0), d: function () { var o, t = this.e, s = 0; function next() { for (; o = n.pop();) try { if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next); if (o.d) { var r = o.d.call(o.v); if (o.a) return s |= 2, Promise.resolve(r).then(next, err); } else s |= 1; } catch (r) { return err(r); } if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve(); if (t !== e) throw t; } function err(n) { return t = t !== e ? new r(n, t) : n, next(); } return next(); } }; }
11
+ const shouldSkipExplodeReexports = action => {
12
+ const {
13
+ loadedAndParsed,
14
+ only
15
+ } = action.entrypoint;
16
+ if (only.length === 1 && only[0] === '__wywPreval') {
17
+ return true;
18
+ }
19
+ if (loadedAndParsed.evaluator !== _shaker.shaker || !loadedAndParsed.ast) {
20
+ return false;
21
+ }
22
+ const barrelAnalysis = (0, _barrelManifest.analyzeBarrelFile)(loadedAndParsed.ast);
23
+ return barrelAnalysis.kind === 'barrel' && barrelAnalysis.complete;
24
+ };
25
+
9
26
  /**
10
27
  * The first stage of processing an entrypoint.
11
28
  * This stage is responsible for:
@@ -19,14 +36,25 @@ function* processEntrypoint() {
19
36
  log
20
37
  } = this.entrypoint;
21
38
  log('start processing (only: %o)', only);
39
+ this.entrypoint.beginProcessing();
22
40
  try {
23
41
  try {
24
42
  var _usingCtx = _usingCtx2();
25
43
  const abortSignal = _usingCtx.u(this.createAbortSignal());
26
- yield ['explodeReexports', this.entrypoint, undefined, abortSignal];
44
+ if (shouldSkipExplodeReexports(this)) {
45
+ log('skip explodeReexports for pure barrel');
46
+ } else {
47
+ yield ['explodeReexports', this.entrypoint, undefined, abortSignal];
48
+ }
27
49
  const result = yield* this.getNext('transform', this.entrypoint, undefined, abortSignal);
28
50
  this.entrypoint.assertNotSuperseded();
29
51
  this.entrypoint.setTransformResult(result);
52
+ const supersededWith = this.entrypoint.applyDeferredSupersede();
53
+ if (supersededWith) {
54
+ log('processing finished, deferred only detected; schedule next attempt');
55
+ yield* this.getNext('processEntrypoint', supersededWith, undefined, null);
56
+ return;
57
+ }
30
58
  log('entrypoint processing finished');
31
59
  } catch (_) {
32
60
  _usingCtx.e = _;
@@ -41,6 +69,8 @@ function* processEntrypoint() {
41
69
  }
42
70
  log(`Unhandled error: %O`, e);
43
71
  throw e;
72
+ } finally {
73
+ this.entrypoint.endProcessing();
44
74
  }
45
75
  }
46
76
  //# sourceMappingURL=processEntrypoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"processEntrypoint.js","names":["_AbortError","require","_usingCtx2","r","SuppressedError","e","n","Error","name","error","suppressed","using","Object","TypeError","o","Symbol","asyncDispose","for","dispose","t","call","Promise","reject","push","v","d","a","u","bind","s","next","pop","resolve","then","err","processEntrypoint","only","log","entrypoint","_usingCtx","abortSignal","createAbortSignal","undefined","result","getNext","assertNotSuperseded","setTransformResult","_","isAborted","supersededWith"],"sources":["../../../src/transform/generators/processEntrypoint.ts"],"sourcesContent":["import { isAborted } from '../actions/AbortError';\nimport type { IProcessEntrypointAction, SyncScenarioForAction } from '../types';\n\n/**\n * The first stage of processing an entrypoint.\n * This stage is responsible for:\n * - scheduling the explodeReexports action\n * - scheduling the transform action\n * - rescheduling itself if the entrypoint is superseded\n */\nexport function* processEntrypoint(\n this: IProcessEntrypointAction\n): SyncScenarioForAction<IProcessEntrypointAction> {\n const { only, log } = this.entrypoint;\n log('start processing (only: %o)', only);\n\n try {\n using abortSignal = this.createAbortSignal();\n\n yield ['explodeReexports', this.entrypoint, undefined, abortSignal];\n const result = yield* this.getNext(\n 'transform',\n this.entrypoint,\n undefined,\n abortSignal\n );\n\n this.entrypoint.assertNotSuperseded();\n\n this.entrypoint.setTransformResult(result);\n\n log('entrypoint processing finished');\n } catch (e) {\n if (isAborted(e) && this.entrypoint.supersededWith) {\n log('processing aborted, schedule the next attempt');\n yield* this.getNext(\n 'processEntrypoint',\n this.entrypoint.supersededWith,\n undefined,\n null\n );\n\n return;\n }\n\n log(`Unhandled error: %O`, e);\n throw e;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAkD,SAAAC,WAAA,QAAAC,CAAA,wBAAAC,eAAA,GAAAA,eAAA,aAAAD,CAAA,EAAAE,CAAA,QAAAC,CAAA,GAAAC,KAAA,WAAAD,CAAA,CAAAE,IAAA,sBAAAF,CAAA,CAAAG,KAAA,GAAAN,CAAA,EAAAG,CAAA,CAAAI,UAAA,GAAAL,CAAA,EAAAC,CAAA,KAAAD,CAAA,OAAAC,CAAA,gBAAAK,MAAAR,CAAA,EAAAE,CAAA,gBAAAA,CAAA,QAAAO,MAAA,CAAAP,CAAA,MAAAA,CAAA,YAAAQ,SAAA,0FAAAV,CAAA,MAAAW,CAAA,GAAAT,CAAA,CAAAU,MAAA,CAAAC,YAAA,IAAAD,MAAA,CAAAE,GAAA,yCAAAH,CAAA,KAAAA,CAAA,GAAAT,CAAA,CAAAU,MAAA,CAAAG,OAAA,IAAAH,MAAA,CAAAE,GAAA,qBAAAd,CAAA,OAAAgB,CAAA,GAAAL,CAAA,2BAAAA,CAAA,YAAAD,SAAA,+BAAAM,CAAA,KAAAL,CAAA,YAAAA,CAAA,UAAAK,CAAA,CAAAC,IAAA,CAAAf,CAAA,YAAAF,CAAA,WAAAkB,OAAA,CAAAC,MAAA,CAAAnB,CAAA,SAAAG,CAAA,CAAAiB,IAAA,GAAAC,CAAA,EAAAnB,CAAA,EAAAoB,CAAA,EAAAX,CAAA,EAAAY,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CAACC,UAAU;EACrCD,GAAG,CAAC,6BAA6B,EAAED,IAAI,CAAC;EAExC;IAAI;MAAA,IAAAG,SAAA,GAAArC,UAAA;MACF,MAAMsC,WAAW,GAAAD,SAAA,CAAAZ,CAAA,CAAG,IAAI,CAACc,iBAAiB,CAAC,CAAC;MAE5C,MAAM,CAAC,kBAAkB,EAAE,IAAI,CAACH,UAAU,EAAEI,SAAS,EAAEF,WAAW,CAAC;MACnE,MAAMG,MAAM,GAAG,OAAO,IAAI,CAACC,OAAO,CAChC,WAAW,EACX,IAAI,CAACN,UAAU,EACfI,SAAS,EACTF,WACF,CAAC;MAED,IAAI,CAACF,UAAU,CAACO,mBAAmB,CAAC,CAAC;MAErC,IAAI,CAACP,UAAU,CAACQ,kBAAkB,CAACH,MAAM,CAAC;MAE1CN,GAAG,CAAC,gCAAgC,CAAC;IAAC,SAAAU,CAAA;MAAAR,SAAA,CAAAlC,CAAA,GAAA0C,CAAA;IAAA;MAAAR,SAAA,CAAAd,CAAA;IAAA;EACvC,EAAC,OAAOpB,CAAC,EAAE;IACV,IAAI,IAAA2C,qBAAS,EAAC3C,CAAC,CAAC,IAAI,IAAI,CAACiC,UAAU,CAACW,cAAc,EAAE;MAClDZ,GAAG,CAAC,+CAA+C,CAAC;MACpD,OAAO,IAAI,CAACO,OAAO,CACjB,mBAAmB,EACnB,IAAI,CAACN,UAAU,CAACW,cAAc,EAC9BP,SAAS,EACT,IACF,CAAC;MAED;IACF;IAEAL,GAAG,CAAC,qBAAqB,EAAEhC,CAAC,CAAC;IAC7B,MAAMA,CAAC;EACT;AACF","ignoreList":[]}
1
+ {"version":3,"file":"processEntrypoint.js","names":["_shaker","require","_AbortError","_barrelManifest","_usingCtx2","r","SuppressedError","e","n","Error","name","error","suppressed","using","Object","TypeError","o","Symbol","asyncDispose","for","dispose","t","call","Promise","reject","push","v","d","a","u","bind","s","next","pop","resolve","then","err","shouldSkipExplodeReexports","action","loadedAndParsed","only","entrypoint","length","evaluator","shaker","ast","barrelAnalysis","analyzeBarrelFile","kind","complete","processEntrypoint","log","beginProcessing","_usingCtx","abortSignal","createAbortSignal","undefined","result","getNext","assertNotSuperseded","setTransformResult","supersededWith","applyDeferredSupersede","_","isAborted","endProcessing"],"sources":["../../../src/transform/generators/processEntrypoint.ts"],"sourcesContent":["import { shaker } from '../../shaker';\nimport { isAborted } from '../actions/AbortError';\nimport { analyzeBarrelFile } from '../barrelManifest';\nimport type { IProcessEntrypointAction, SyncScenarioForAction } from '../types';\n\nconst shouldSkipExplodeReexports = (\n action: IProcessEntrypointAction\n): boolean => {\n const { loadedAndParsed, only } = action.entrypoint;\n if (only.length === 1 && only[0] === '__wywPreval') {\n return true;\n }\n\n if (loadedAndParsed.evaluator !== shaker || !loadedAndParsed.ast) {\n return false;\n }\n\n const barrelAnalysis = analyzeBarrelFile(loadedAndParsed.ast);\n return barrelAnalysis.kind === 'barrel' && barrelAnalysis.complete;\n};\n\n/**\n * The first stage of processing an entrypoint.\n * This stage is responsible for:\n * - scheduling the explodeReexports action\n * - scheduling the transform action\n * - rescheduling itself if the entrypoint is superseded\n */\nexport function* processEntrypoint(\n this: IProcessEntrypointAction\n): SyncScenarioForAction<IProcessEntrypointAction> {\n const { only, log } = this.entrypoint;\n log('start processing (only: %o)', only);\n\n this.entrypoint.beginProcessing();\n\n try {\n using abortSignal = this.createAbortSignal();\n\n if (shouldSkipExplodeReexports(this)) {\n log('skip explodeReexports for pure barrel');\n } else {\n yield ['explodeReexports', this.entrypoint, undefined, abortSignal];\n }\n const result = yield* this.getNext(\n 'transform',\n this.entrypoint,\n undefined,\n abortSignal\n );\n\n this.entrypoint.assertNotSuperseded();\n\n this.entrypoint.setTransformResult(result);\n\n const supersededWith = this.entrypoint.applyDeferredSupersede();\n if (supersededWith) {\n log('processing finished, deferred only detected; schedule next attempt');\n yield* this.getNext('processEntrypoint', supersededWith, undefined, null);\n return;\n }\n\n log('entrypoint processing finished');\n } catch (e) {\n if (isAborted(e) && this.entrypoint.supersededWith) {\n log('processing aborted, schedule the next attempt');\n yield* this.getNext(\n 'processEntrypoint',\n this.entrypoint.supersededWith,\n undefined,\n null\n );\n\n return;\n }\n\n log(`Unhandled error: %O`, e);\n throw e;\n } finally {\n this.entrypoint.endProcessing();\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAAsD,SAAAG,WAAA,QAAAC,CAAA,wBAAAC,eAAA,GAAAA,eAAA,aAAAD,CAAA,EAAAE,CAAA,QAAAC,CAAA,GAAAC,KAAA,WAAAD,CAAA,CAAAE,IAAA,sBAAAF,CAAA,CAAAG,KAAA,GAAAN,CAAA,EAAAG,CAAA,CAAAI,UAAA,GAAAL,CAAA,EAAAC,CAAA,KAAAD,CAAA,OAAAC,CAAA,gBAAAK,MAAAR,CAAA,EAAAE,CAAA,gBAAAA,CAAA,QAAAO,MAAA,CAAAP,CAAA,MAAAA,CAAA,YAAAQ,SAAA,0FAAAV,CAAA,MAAAW,CAAA,GAAAT,CAAA,CAAAU,MAAA,CAAAC,YAAA,IAAAD,MAAA,CAAAE,GAAA,yCAAAH,CAAA,KAAAA,CAAA,GAAAT,CAAA,CAAAU,MAAA,CAAAG,OAAA,IAAAH,MAAA,CAAAE,GAAA,qBAAAd,CAAA,OAAAgB,CAAA,GAAAL,CAAA,2BAAAA,CAAA,YAAAD,SAAA,+BAAAM,CAAA,KAAAL,CAAA,YAAAA,CAAA,UAAAK,CAAA,CAAAC,IAAA,CAAAf,CAAA,YAAAF,CAAA,WAAAkB,OAAA,CAAAC,MAAA,CAAAnB,CAAA,SAAAG,CAAA,CAAAiB,IAAA,GAAAC,CAAA,EAAAnB,CAAA,EAAAoB,CAAA,EAAAX,CAAA,EAAAY,CAAA,EAAAvB,CAAA,YAAAA,CAAA,IAAAG,CAAA,CAAAiB,IAAA,GAAAE,CAAA,EAAApB,CAAA,EAAAqB,CAAA,EAAAvB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EAAE,IAAI,CAAC;QACzE;MACF;MAEAL,GAAG,CAAC,gCAAgC,CAAC;IAAC,SAAAY,CAAA;MAAAV,SAAA,CAAA9C,CAAA,GAAAwD,CAAA;IAAA;MAAAV,SAAA,CAAA1B,CAAA;IAAA;EACvC,EAAC,OAAOpB,CAAC,EAAE;IACV,IAAI,IAAAyD,qBAAS,EAACzD,CAAC,CAAC,IAAI,IAAI,CAACkC,UAAU,CAACoB,cAAc,EAAE;MAClDV,GAAG,CAAC,+CAA+C,CAAC;MACpD,OAAO,IAAI,CAACO,OAAO,CACjB,mBAAmB,EACnB,IAAI,CAACjB,UAAU,CAACoB,cAAc,EAC9BL,SAAS,EACT,IACF,CAAC;MAED;IACF;IAEAL,GAAG,CAAC,qBAAqB,EAAE5C,CAAC,CAAC;IAC7B,MAAMA,CAAC;EACT,CAAC,SAAS;IACR,IAAI,CAACkC,UAAU,CAACwB,aAAa,CAAC,CAAC;EACjC;AACF","ignoreList":[]}
@@ -46,11 +46,12 @@ function applyImportOverrides(services, entrypoint, resolvedImports) {
46
46
  };
47
47
  });
48
48
  }
49
- function emitDependency(emitter, entrypoint, imports) {
49
+ function emitDependency(emitter, entrypoint, imports, phase) {
50
50
  emitter.single({
51
51
  type: 'dependency',
52
52
  file: entrypoint.name,
53
53
  only: entrypoint.only,
54
+ phase,
54
55
  imports: imports.map(({
55
56
  resolved,
56
57
  only
@@ -70,6 +71,9 @@ function filterUnresolved(entrypoint, resolvedImports) {
70
71
  return true;
71
72
  });
72
73
  }
74
+ function getPreResolvedImports(preResolved) {
75
+ return new Map((preResolved !== null && preResolved !== void 0 ? preResolved : []).map(dependency => [dependency.source, dependency]));
76
+ }
73
77
 
74
78
  /**
75
79
  * Synchronously resolves specified imports with a provided resolver.
@@ -86,15 +90,25 @@ function* syncResolveImports(resolve) {
86
90
  }
87
91
  } = this;
88
92
  const listOfImports = Array.from((_imports$entries = imports === null || imports === void 0 ? void 0 : imports.entries()) !== null && _imports$entries !== void 0 ? _imports$entries : []);
93
+ const preResolvedImports = getPreResolvedImports(this.data.preResolved);
89
94
  const {
90
95
  log
91
96
  } = entrypoint;
92
97
  if (listOfImports.length === 0) {
93
- emitDependency(eventEmitter, entrypoint, []);
98
+ emitDependency(eventEmitter, entrypoint, [], this.data.phase);
94
99
  log('%s has no imports', entrypoint.name);
95
100
  return [];
96
101
  }
97
102
  const resolvedImports = listOfImports.map(([source, only]) => {
103
+ const preResolved = preResolvedImports.get(source);
104
+ if (preResolved) {
105
+ const mergedOnly = (0, _Entrypoint.mergeOnly)(preResolved.only, only);
106
+ log('[sync-resolve] ♻️ %s -> %s (only: %o)', source, preResolved.resolved, mergedOnly);
107
+ return {
108
+ ...preResolved,
109
+ only: mergedOnly
110
+ };
111
+ }
98
112
  let resolved = null;
99
113
  try {
100
114
  resolved = resolve(source, entrypoint.name, (0, _Entrypoint.getStack)(entrypoint));
@@ -110,7 +124,7 @@ function* syncResolveImports(resolve) {
110
124
  });
111
125
  const overriddenImports = applyImportOverrides(this.services, entrypoint, resolvedImports);
112
126
  const filteredImports = filterUnresolved(entrypoint, overriddenImports);
113
- emitDependency(eventEmitter, entrypoint, filteredImports);
127
+ emitDependency(eventEmitter, entrypoint, filteredImports, this.data.phase);
114
128
  return filteredImports;
115
129
  }
116
130
 
@@ -129,11 +143,12 @@ async function* asyncResolveImports(resolve) {
129
143
  }
130
144
  } = this;
131
145
  const listOfImports = Array.from((_imports$entries2 = imports === null || imports === void 0 ? void 0 : imports.entries()) !== null && _imports$entries2 !== void 0 ? _imports$entries2 : []);
146
+ const preResolvedImports = getPreResolvedImports(this.data.preResolved);
132
147
  const {
133
148
  log
134
149
  } = entrypoint;
135
150
  if (listOfImports.length === 0) {
136
- emitDependency(eventEmitter, entrypoint, []);
151
+ emitDependency(eventEmitter, entrypoint, [], this.data.phase);
137
152
  log('%s has no imports', entrypoint.name);
138
153
  return [];
139
154
  }
@@ -155,6 +170,15 @@ async function* asyncResolveImports(resolve) {
155
170
  };
156
171
  };
157
172
  const resolvedImports = await Promise.all(listOfImports.map(([source, importsOnly]) => {
173
+ const preResolved = preResolvedImports.get(source);
174
+ if (preResolved) {
175
+ const mergedOnly = (0, _Entrypoint.mergeOnly)(preResolved.only, importsOnly);
176
+ log('[async-resolve] ♻️ %s (%o) in %s -> %s', source, mergedOnly, entrypoint.name, preResolved.resolved);
177
+ return {
178
+ ...preResolved,
179
+ only: mergedOnly
180
+ };
181
+ }
158
182
  const cached = entrypoint.getDependency(source);
159
183
  if (cached) {
160
184
  return {
@@ -191,7 +215,7 @@ async function* asyncResolveImports(resolve) {
191
215
  log('resolved %d imports', resolvedImports.length);
192
216
  const overriddenImports = applyImportOverrides(this.services, entrypoint, resolvedImports);
193
217
  const filteredImports = filterUnresolved(entrypoint, overriddenImports);
194
- emitDependency(eventEmitter, entrypoint, filteredImports);
218
+ emitDependency(eventEmitter, entrypoint, filteredImports, this.data.phase);
195
219
  return filteredImports;
196
220
  }
197
221
  //# sourceMappingURL=resolveImports.js.map