@atlaspack/core 2.24.0 → 2.24.2-dev-ts-project-refs-d30e9754f.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +201 -0
  3. package/dist/AssetGraph.js +591 -0
  4. package/dist/Atlaspack.js +656 -0
  5. package/dist/AtlaspackConfig.js +324 -0
  6. package/dist/AtlaspackConfig.schema.js +108 -0
  7. package/dist/BundleGraph.js +1628 -0
  8. package/dist/CommittedAsset.js +142 -0
  9. package/dist/Dependency.js +125 -0
  10. package/dist/Environment.js +132 -0
  11. package/dist/EnvironmentManager.js +108 -0
  12. package/dist/IdentifierRegistry.js +38 -0
  13. package/dist/InternalConfig.js +37 -0
  14. package/dist/PackagerRunner.js +531 -0
  15. package/dist/ReporterRunner.js +151 -0
  16. package/dist/RequestTracker.js +1368 -0
  17. package/dist/SymbolPropagation.js +620 -0
  18. package/dist/TargetDescriptor.schema.js +143 -0
  19. package/dist/Transformation.js +487 -0
  20. package/dist/UncommittedAsset.js +315 -0
  21. package/dist/Validation.js +196 -0
  22. package/dist/applyRuntimes.js +305 -0
  23. package/dist/assetUtils.js +168 -0
  24. package/dist/atlaspack-v3/AtlaspackV3.js +70 -0
  25. package/dist/atlaspack-v3/NapiWorkerPool.js +57 -0
  26. package/dist/atlaspack-v3/fs.js +52 -0
  27. package/dist/atlaspack-v3/index.js +25 -0
  28. package/dist/atlaspack-v3/jsCallable.js +16 -0
  29. package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
  30. package/dist/atlaspack-v3/worker/compat/bitflags.js +94 -0
  31. package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
  32. package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
  33. package/dist/atlaspack-v3/worker/compat/index.js +25 -0
  34. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
  35. package/dist/atlaspack-v3/worker/compat/plugin-config.js +76 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
  37. package/dist/atlaspack-v3/worker/compat/plugin-options.js +122 -0
  38. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  39. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  40. package/dist/atlaspack-v3/worker/worker.js +292 -0
  41. package/dist/constants.js +17 -0
  42. package/dist/dumpGraphToGraphViz.js +281 -0
  43. package/dist/index.js +62 -0
  44. package/dist/loadAtlaspackPlugin.js +128 -0
  45. package/dist/loadDotEnv.js +41 -0
  46. package/dist/projectPath.js +83 -0
  47. package/dist/public/Asset.js +279 -0
  48. package/dist/public/Bundle.js +224 -0
  49. package/dist/public/BundleGraph.js +359 -0
  50. package/dist/public/BundleGroup.js +53 -0
  51. package/dist/public/Config.js +286 -0
  52. package/dist/public/Dependency.js +138 -0
  53. package/dist/public/Environment.js +278 -0
  54. package/dist/public/MutableBundleGraph.js +277 -0
  55. package/dist/public/PluginOptions.js +80 -0
  56. package/dist/public/Symbols.js +248 -0
  57. package/dist/public/Target.js +69 -0
  58. package/dist/registerCoreWithSerializer.js +38 -0
  59. package/dist/requests/AssetGraphRequest.js +429 -0
  60. package/dist/requests/AssetGraphRequestRust.js +246 -0
  61. package/dist/requests/AssetRequest.js +130 -0
  62. package/dist/requests/AtlaspackBuildRequest.js +60 -0
  63. package/dist/requests/AtlaspackConfigRequest.js +490 -0
  64. package/dist/requests/BundleGraphRequest.js +441 -0
  65. package/dist/requests/ConfigRequest.js +222 -0
  66. package/dist/requests/DevDepRequest.js +204 -0
  67. package/dist/requests/EntryRequest.js +314 -0
  68. package/dist/requests/PackageRequest.js +65 -0
  69. package/dist/requests/PathRequest.js +349 -0
  70. package/dist/requests/TargetRequest.js +1310 -0
  71. package/dist/requests/ValidationRequest.js +49 -0
  72. package/dist/requests/WriteBundleRequest.js +254 -0
  73. package/dist/requests/WriteBundlesRequest.js +165 -0
  74. package/dist/requests/asset-graph-diff.js +126 -0
  75. package/dist/requests/asset-graph-dot.js +131 -0
  76. package/dist/resolveOptions.js +268 -0
  77. package/dist/rustWorkerThreadDylibHack.js +19 -0
  78. package/dist/serializerCore.browser.js +43 -0
  79. package/dist/summarizeRequest.js +39 -0
  80. package/dist/types.js +31 -0
  81. package/dist/utils.js +172 -0
  82. package/dist/worker.js +130 -0
  83. package/lib/AssetGraph.js +1 -0
  84. package/lib/atlaspack-v3/AtlaspackV3.js +7 -3
  85. package/lib/requests/AssetGraphRequestRust.js +1 -1
  86. package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +1 -1
  87. package/package.json +22 -22
  88. package/src/AssetGraph.ts +1 -0
  89. package/src/atlaspack-v3/AtlaspackV3.ts +12 -3
  90. package/src/requests/AssetGraphRequestRust.ts +1 -1
  91. package/tsconfig.json +55 -2
  92. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,349 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ResolverRunner = void 0;
40
+ exports.default = createPathRequest;
41
+ const build_cache_1 = require("@atlaspack/build-cache");
42
+ const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
43
+ const logger_1 = require("@atlaspack/logger");
44
+ const feature_flags_1 = require("@atlaspack/feature-flags");
45
+ const nullthrows_1 = __importDefault(require("nullthrows"));
46
+ const path_1 = __importDefault(require("path"));
47
+ const utils_1 = require("@atlaspack/utils");
48
+ const ReporterRunner_1 = require("../ReporterRunner");
49
+ const Dependency_1 = require("../public/Dependency");
50
+ const PluginOptions_1 = __importDefault(require("../public/PluginOptions"));
51
+ const AtlaspackConfigRequest_1 = __importStar(require("./AtlaspackConfigRequest"));
52
+ const utils_2 = require("../utils");
53
+ const projectPath_1 = require("../projectPath");
54
+ const types_1 = require("../types");
55
+ const InternalConfig_1 = require("../InternalConfig");
56
+ const ConfigRequest_1 = require("./ConfigRequest");
57
+ const DevDepRequest_1 = require("./DevDepRequest");
58
+ const profiler_1 = require("@atlaspack/profiler");
59
+ const RequestTracker_1 = require("../RequestTracker");
60
+ const PIPELINE_REGEX = /^([a-z0-9-]+?):(.*)$/i;
61
+ function createPathRequest(input) {
62
+ return {
63
+ id: input.dependency.id + ':' + input.name,
64
+ type: RequestTracker_1.requestTypes.path_request,
65
+ run,
66
+ input,
67
+ };
68
+ }
69
+ // @ts-expect-error TS7031
70
+ async function run({ input, api, options }) {
71
+ let configResult = (0, nullthrows_1.default)(
72
+ // @ts-expect-error TS2347
73
+ await api.runRequest((0, AtlaspackConfigRequest_1.default)()));
74
+ let config = (0, AtlaspackConfigRequest_1.getCachedAtlaspackConfig)(configResult, options);
75
+ let { devDeps, invalidDevDeps } = await (0, DevDepRequest_1.getDevDepRequests)(api);
76
+ (0, DevDepRequest_1.invalidateDevDeps)(invalidDevDeps, options, config);
77
+ let resolverRunner = new ResolverRunner({
78
+ options,
79
+ config,
80
+ previousDevDeps: devDeps,
81
+ });
82
+ let result = await resolverRunner.resolve(input.dependency);
83
+ if (result.invalidateOnEnvChange) {
84
+ for (let env of result.invalidateOnEnvChange) {
85
+ api.invalidateOnEnvChange(env);
86
+ }
87
+ }
88
+ if (result.invalidateOnFileCreate) {
89
+ for (let file of result.invalidateOnFileCreate) {
90
+ api.invalidateOnFileCreate((0, utils_2.invalidateOnFileCreateToInternal)(options.projectRoot, file));
91
+ }
92
+ }
93
+ if (result.invalidateOnFileChange) {
94
+ for (let filePath of result.invalidateOnFileChange) {
95
+ let pp = (0, projectPath_1.toProjectPath)(options.projectRoot, filePath);
96
+ api.invalidateOnFileUpdate(pp);
97
+ api.invalidateOnFileDelete(pp);
98
+ }
99
+ }
100
+ for (let config of resolverRunner.configs.values()) {
101
+ await (0, ConfigRequest_1.runConfigRequest)(api, config);
102
+ }
103
+ for (let devDepRequest of resolverRunner.devDepRequests.values()) {
104
+ await (0, DevDepRequest_1.runDevDepRequest)(api, devDepRequest);
105
+ }
106
+ if (result.assetGroup) {
107
+ api.invalidateOnFileDelete(result.assetGroup.filePath);
108
+ return result.assetGroup;
109
+ }
110
+ if (result.diagnostics && result.diagnostics.length > 0) {
111
+ let err = new diagnostic_1.default({ diagnostic: result.diagnostics });
112
+ // @ts-expect-error TS2339
113
+ err.code = 'MODULE_NOT_FOUND';
114
+ throw err;
115
+ }
116
+ }
117
+ const configCache = (0, build_cache_1.createBuildCache)();
118
+ class ResolverRunner {
119
+ constructor({ config, options, previousDevDeps }) {
120
+ this.config = config;
121
+ this.options = options;
122
+ this.pluginOptions = new PluginOptions_1.default(this.options);
123
+ this.previousDevDeps = previousDevDeps;
124
+ this.devDepRequests = new Map();
125
+ this.configs = new Map();
126
+ }
127
+ async getDiagnostic(dependency, message) {
128
+ let diagnostic = {
129
+ message,
130
+ origin: '@atlaspack/core',
131
+ };
132
+ if (dependency.loc && dependency.sourcePath != null) {
133
+ let filePath = (0, projectPath_1.fromProjectPath)(this.options.projectRoot, dependency.sourcePath);
134
+ diagnostic.codeFrames = [
135
+ {
136
+ filePath,
137
+ code: await this.options.inputFS
138
+ .readFile(filePath, 'utf8')
139
+ .catch(() => ''),
140
+ codeHighlights: dependency.loc
141
+ ? [(0, diagnostic_1.convertSourceLocationToHighlight)(dependency.loc)]
142
+ : [],
143
+ },
144
+ ];
145
+ }
146
+ return diagnostic;
147
+ }
148
+ async loadConfigs(resolvers) {
149
+ for (let plugin of resolvers) {
150
+ // Only load config for a plugin once per build.
151
+ let config = configCache.get(plugin.name);
152
+ if (!config && plugin.plugin.loadConfig != null) {
153
+ config = (0, InternalConfig_1.createConfig)({
154
+ plugin: plugin.name,
155
+ searchPath: (0, projectPath_1.toProjectPathUnsafe)('index'),
156
+ });
157
+ // @ts-expect-error TS2345
158
+ await (0, ConfigRequest_1.loadPluginConfig)(plugin, config, this.options);
159
+ configCache.set(plugin.name, config);
160
+ // @ts-expect-error TS2345
161
+ this.configs.set(plugin.name, config);
162
+ }
163
+ if (config) {
164
+ // @ts-expect-error TS2339
165
+ for (let devDep of config.devDeps) {
166
+ let devDepRequest = await (0, DevDepRequest_1.createDevDependency)(devDep, this.previousDevDeps, this.options);
167
+ this.runDevDepRequest(devDepRequest);
168
+ }
169
+ // @ts-expect-error TS2345
170
+ this.configs.set(plugin.name, config);
171
+ }
172
+ }
173
+ }
174
+ runDevDepRequest(devDepRequest) {
175
+ // @ts-expect-error TS2339
176
+ if (devDepRequest.type !== 'ref') {
177
+ let { specifier, resolveFrom } = devDepRequest;
178
+ let key = `${specifier}:${(0, projectPath_1.fromProjectPathRelative)(resolveFrom)}`;
179
+ // @ts-expect-error TS2345
180
+ this.devDepRequests.set(key, devDepRequest);
181
+ }
182
+ }
183
+ async resolve(dependency) {
184
+ let dep = (0, Dependency_1.getPublicDependency)(dependency, this.options);
185
+ (0, ReporterRunner_1.report)({
186
+ type: 'buildProgress',
187
+ phase: 'resolving',
188
+ dependency: dep,
189
+ });
190
+ let resolvers = await this.config.getResolvers();
191
+ await this.loadConfigs(resolvers);
192
+ let pipeline;
193
+ let specifier;
194
+ let validPipelines = new Set(this.config.getNamedPipelines());
195
+ let match = dependency.specifier.match(PIPELINE_REGEX);
196
+ if (match &&
197
+ // Don't consider absolute paths. Absolute paths are only supported for entries,
198
+ // and include e.g. `C:\` on Windows, conflicting with pipelines.
199
+ !path_1.default.isAbsolute(dependency.specifier)) {
200
+ [, pipeline, specifier] = match;
201
+ if (!validPipelines.has(pipeline)) {
202
+ // This may be a url protocol or scheme rather than a pipeline, such as
203
+ // `url('http://example.com/foo.png')`. Pass it to resolvers to handle.
204
+ specifier = dependency.specifier;
205
+ pipeline = null;
206
+ }
207
+ }
208
+ else {
209
+ specifier = dependency.specifier;
210
+ }
211
+ // Entrypoints, convert ProjectPath in module specifier to absolute path
212
+ if (dep.resolveFrom == null) {
213
+ specifier = path_1.default.join(this.options.projectRoot, specifier);
214
+ }
215
+ let diagnostics = [];
216
+ let invalidateOnFileCreate = [];
217
+ let invalidateOnFileChange = [];
218
+ let invalidateOnEnvChange = [];
219
+ for (let resolver of resolvers) {
220
+ let measurement;
221
+ try {
222
+ measurement = profiler_1.tracer.createMeasurement(resolver.name, 'resolve', specifier);
223
+ let result = await resolver.plugin.resolve({
224
+ specifier,
225
+ pipeline,
226
+ dependency: dep,
227
+ options: this.pluginOptions,
228
+ logger: new logger_1.PluginLogger({ origin: resolver.name }),
229
+ tracer: new profiler_1.PluginTracer({
230
+ origin: resolver.name,
231
+ category: 'resolver',
232
+ }),
233
+ config: this.configs.get(resolver.name)?.result,
234
+ });
235
+ measurement && measurement.end();
236
+ if (result) {
237
+ if (result.meta) {
238
+ dependency.resolverMeta = result.meta;
239
+ dependency.meta = {
240
+ ...dependency.meta,
241
+ ...result.meta,
242
+ };
243
+ }
244
+ if (result.priority != null) {
245
+ dependency.priority = types_1.Priority[result.priority];
246
+ if ((0, feature_flags_1.getFeatureFlag)('hmrImprovements')) {
247
+ dependency.resolverPriority = dependency.priority;
248
+ }
249
+ }
250
+ if (result.invalidateOnEnvChange) {
251
+ invalidateOnEnvChange.push(...result.invalidateOnEnvChange);
252
+ }
253
+ if (result.invalidateOnFileCreate) {
254
+ invalidateOnFileCreate.push(...result.invalidateOnFileCreate);
255
+ }
256
+ if (result.invalidateOnFileChange) {
257
+ invalidateOnFileChange.push(...result.invalidateOnFileChange);
258
+ }
259
+ if (result.isExcluded) {
260
+ return {
261
+ assetGroup: null,
262
+ invalidateOnFileCreate,
263
+ invalidateOnFileChange,
264
+ invalidateOnEnvChange,
265
+ };
266
+ }
267
+ if (result.filePath != null) {
268
+ let resultFilePath = result.filePath;
269
+ if (!path_1.default.isAbsolute(resultFilePath)) {
270
+ throw new Error((0, diagnostic_1.md) `Resolvers must return an absolute path, ${resolver.name} returned: ${resultFilePath}`);
271
+ }
272
+ return {
273
+ assetGroup: {
274
+ canDefer: result.canDefer,
275
+ filePath: (0, projectPath_1.toProjectPath)(this.options.projectRoot, resultFilePath),
276
+ query: result.query?.toString(),
277
+ sideEffects: result.sideEffects,
278
+ code: result.code,
279
+ env: dependency.env,
280
+ pipeline: result.pipeline === undefined
281
+ ? (pipeline ?? dependency.pipeline)
282
+ : result.pipeline,
283
+ isURL: dep.specifierType === 'url',
284
+ },
285
+ invalidateOnFileCreate,
286
+ invalidateOnFileChange,
287
+ invalidateOnEnvChange,
288
+ };
289
+ }
290
+ if (result.diagnostics != null &&
291
+ !(Array.isArray(result.diagnostics) &&
292
+ result.diagnostics.length === 0)) {
293
+ let errorDiagnostic = (0, diagnostic_1.errorToDiagnostic)(new diagnostic_1.default({ diagnostic: result.diagnostics }), {
294
+ origin: resolver.name,
295
+ filePath: specifier,
296
+ });
297
+ diagnostics.push(...errorDiagnostic);
298
+ }
299
+ }
300
+ }
301
+ catch (e) {
302
+ // Add error to error map, we'll append these to the standard error if we can't resolve the asset
303
+ let errorDiagnostic = (0, diagnostic_1.errorToDiagnostic)(e, {
304
+ origin: resolver.name,
305
+ filePath: specifier,
306
+ });
307
+ if (Array.isArray(errorDiagnostic)) {
308
+ diagnostics.push(...errorDiagnostic);
309
+ }
310
+ else {
311
+ diagnostics.push(errorDiagnostic);
312
+ }
313
+ break;
314
+ }
315
+ finally {
316
+ measurement && measurement.end();
317
+ // Add dev dependency for the resolver. This must be done AFTER running it due to
318
+ // the potential for lazy require() that aren't executed until the request runs.
319
+ let devDepRequest = await (0, DevDepRequest_1.createDevDependency)({
320
+ specifier: resolver.name,
321
+ resolveFrom: resolver.resolveFrom,
322
+ }, this.previousDevDeps, this.options);
323
+ this.runDevDepRequest(devDepRequest);
324
+ }
325
+ }
326
+ if (dep.isOptional) {
327
+ return {
328
+ assetGroup: null,
329
+ invalidateOnFileCreate,
330
+ invalidateOnFileChange,
331
+ invalidateOnEnvChange,
332
+ };
333
+ }
334
+ let resolveFrom = dependency.resolveFrom ?? dependency.sourcePath;
335
+ let dir = resolveFrom != null
336
+ ? (0, utils_1.normalizePath)((0, projectPath_1.fromProjectPathRelative)(resolveFrom))
337
+ : '';
338
+ let diagnostic = await this.getDiagnostic(dependency, (0, diagnostic_1.md) `Failed to resolve '${dependency.specifier}' ${dir ? `from '${dir}'` : ''}`);
339
+ diagnostics.unshift(diagnostic);
340
+ return {
341
+ assetGroup: null,
342
+ invalidateOnFileCreate,
343
+ invalidateOnFileChange,
344
+ invalidateOnEnvChange,
345
+ diagnostics,
346
+ };
347
+ }
348
+ }
349
+ exports.ResolverRunner = ResolverRunner;