@atlaspack/core 2.24.1 → 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 (86) hide show
  1. package/LICENSE +201 -0
  2. package/dist/AssetGraph.js +591 -0
  3. package/dist/Atlaspack.js +656 -0
  4. package/dist/AtlaspackConfig.js +324 -0
  5. package/dist/AtlaspackConfig.schema.js +108 -0
  6. package/dist/BundleGraph.js +1628 -0
  7. package/dist/CommittedAsset.js +142 -0
  8. package/dist/Dependency.js +125 -0
  9. package/dist/Environment.js +132 -0
  10. package/dist/EnvironmentManager.js +108 -0
  11. package/dist/IdentifierRegistry.js +38 -0
  12. package/dist/InternalConfig.js +37 -0
  13. package/dist/PackagerRunner.js +531 -0
  14. package/dist/ReporterRunner.js +151 -0
  15. package/dist/RequestTracker.js +1368 -0
  16. package/dist/SymbolPropagation.js +620 -0
  17. package/dist/TargetDescriptor.schema.js +143 -0
  18. package/dist/Transformation.js +487 -0
  19. package/dist/UncommittedAsset.js +315 -0
  20. package/dist/Validation.js +196 -0
  21. package/dist/applyRuntimes.js +305 -0
  22. package/dist/assetUtils.js +168 -0
  23. package/dist/atlaspack-v3/AtlaspackV3.js +70 -0
  24. package/dist/atlaspack-v3/NapiWorkerPool.js +57 -0
  25. package/dist/atlaspack-v3/fs.js +52 -0
  26. package/dist/atlaspack-v3/index.js +25 -0
  27. package/dist/atlaspack-v3/jsCallable.js +16 -0
  28. package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
  29. package/dist/atlaspack-v3/worker/compat/bitflags.js +94 -0
  30. package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
  31. package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
  32. package/dist/atlaspack-v3/worker/compat/index.js +25 -0
  33. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
  34. package/dist/atlaspack-v3/worker/compat/plugin-config.js +76 -0
  35. package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-options.js +122 -0
  37. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  38. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  39. package/dist/atlaspack-v3/worker/worker.js +292 -0
  40. package/dist/constants.js +17 -0
  41. package/dist/dumpGraphToGraphViz.js +281 -0
  42. package/dist/index.js +62 -0
  43. package/dist/loadAtlaspackPlugin.js +128 -0
  44. package/dist/loadDotEnv.js +41 -0
  45. package/dist/projectPath.js +83 -0
  46. package/dist/public/Asset.js +279 -0
  47. package/dist/public/Bundle.js +224 -0
  48. package/dist/public/BundleGraph.js +359 -0
  49. package/dist/public/BundleGroup.js +53 -0
  50. package/dist/public/Config.js +286 -0
  51. package/dist/public/Dependency.js +138 -0
  52. package/dist/public/Environment.js +278 -0
  53. package/dist/public/MutableBundleGraph.js +277 -0
  54. package/dist/public/PluginOptions.js +80 -0
  55. package/dist/public/Symbols.js +248 -0
  56. package/dist/public/Target.js +69 -0
  57. package/dist/registerCoreWithSerializer.js +38 -0
  58. package/dist/requests/AssetGraphRequest.js +429 -0
  59. package/dist/requests/AssetGraphRequestRust.js +246 -0
  60. package/dist/requests/AssetRequest.js +130 -0
  61. package/dist/requests/AtlaspackBuildRequest.js +60 -0
  62. package/dist/requests/AtlaspackConfigRequest.js +490 -0
  63. package/dist/requests/BundleGraphRequest.js +441 -0
  64. package/dist/requests/ConfigRequest.js +222 -0
  65. package/dist/requests/DevDepRequest.js +204 -0
  66. package/dist/requests/EntryRequest.js +314 -0
  67. package/dist/requests/PackageRequest.js +65 -0
  68. package/dist/requests/PathRequest.js +349 -0
  69. package/dist/requests/TargetRequest.js +1310 -0
  70. package/dist/requests/ValidationRequest.js +49 -0
  71. package/dist/requests/WriteBundleRequest.js +254 -0
  72. package/dist/requests/WriteBundlesRequest.js +165 -0
  73. package/dist/requests/asset-graph-diff.js +126 -0
  74. package/dist/requests/asset-graph-dot.js +131 -0
  75. package/dist/resolveOptions.js +268 -0
  76. package/dist/rustWorkerThreadDylibHack.js +19 -0
  77. package/dist/serializerCore.browser.js +43 -0
  78. package/dist/summarizeRequest.js +39 -0
  79. package/dist/types.js +31 -0
  80. package/dist/utils.js +172 -0
  81. package/dist/worker.js +130 -0
  82. package/lib/AssetGraph.js +1 -0
  83. package/package.json +22 -22
  84. package/src/AssetGraph.ts +1 -0
  85. package/tsconfig.json +55 -2
  86. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const assert_1 = __importDefault(require("assert"));
7
+ const stream_1 = require("stream");
8
+ const source_map_1 = __importDefault(require("@parcel/source-map"));
9
+ const build_cache_1 = require("@atlaspack/build-cache");
10
+ const utils_1 = require("@atlaspack/utils");
11
+ const rust_1 = require("@atlaspack/rust");
12
+ const Dependency_1 = require("./Dependency");
13
+ const Environment_1 = require("./Environment");
14
+ const constants_1 = require("./constants");
15
+ const assetUtils_1 = require("./assetUtils");
16
+ const types_1 = require("./types");
17
+ const utils_2 = require("./utils");
18
+ const projectPath_1 = require("./projectPath");
19
+ const feature_flags_1 = require("@atlaspack/feature-flags");
20
+ const EnvironmentManager_1 = require("./EnvironmentManager");
21
+ class UncommittedAsset {
22
+ constructor({ value, options, content, mapBuffer, ast, isASTDirty, code, invalidations, }) {
23
+ this.value = value;
24
+ this.options = options;
25
+ this.content = content;
26
+ this.mapBuffer = mapBuffer;
27
+ this.ast = ast;
28
+ this.isASTDirty = isASTDirty || false;
29
+ this.code = code;
30
+ this.invalidations = invalidations || (0, utils_2.createInvalidations)();
31
+ }
32
+ /*
33
+ * Prepares the asset for being serialized to the cache by committing its
34
+ * content and map of the asset to the cache.
35
+ */
36
+ async commit() {
37
+ // If there is a dirty AST, clear out any old content and map as these
38
+ // must be regenerated later and shouldn't be committed.
39
+ if (this.ast != null && this.isASTDirty) {
40
+ this.content = null;
41
+ this.mapBuffer = null;
42
+ }
43
+ let size = 0;
44
+ let outputHash = '';
45
+ let contentKey = this.content == null ? null : this.getCacheKey('content');
46
+ let mapKey = this.mapBuffer == null ? null : this.getCacheKey('map');
47
+ let astKey = this.ast == null ? null : this.getCacheKey('ast');
48
+ // Since we can only read from the stream once, compute the content length
49
+ // and hash while it's being written to the cache.
50
+ await Promise.all([
51
+ contentKey != null &&
52
+ this.commitContent(contentKey).then((s) => ((size = s.size), (outputHash = s.hash))),
53
+ this.mapBuffer != null &&
54
+ mapKey != null &&
55
+ this.options.cache.setBlob(mapKey, this.mapBuffer),
56
+ astKey != null &&
57
+ this.options.cache.setBlob(astKey, (0, build_cache_1.serializeRaw)(this.ast)),
58
+ ]);
59
+ this.value.contentKey = contentKey;
60
+ this.value.mapKey = mapKey;
61
+ this.value.astKey = astKey;
62
+ this.value.outputHash = outputHash;
63
+ if (this.content != null) {
64
+ this.value.stats.size = size;
65
+ }
66
+ this.value.isLargeBlob = this.content instanceof stream_1.Readable;
67
+ this.value.committed = true;
68
+ }
69
+ async commitContent(contentKey) {
70
+ let content = await this.content;
71
+ if (content == null) {
72
+ return { size: 0, hash: '' };
73
+ }
74
+ let size = 0;
75
+ if (content instanceof stream_1.Readable) {
76
+ let hash = new rust_1.Hash();
77
+ await this.options.cache.setStream(contentKey, content.pipe(
78
+ // @ts-expect-error TS2554
79
+ new utils_1.TapStream((buf) => {
80
+ hash.writeBuffer(buf);
81
+ size += buf.length;
82
+ })));
83
+ return { size, hash: hash.finish() };
84
+ }
85
+ let hash;
86
+ if (typeof content === 'string') {
87
+ hash = (0, rust_1.hashString)(content);
88
+ size = Buffer.byteLength(content);
89
+ }
90
+ else {
91
+ hash = (0, rust_1.hashBuffer)(content);
92
+ size = content.length;
93
+ }
94
+ // Maybe we should just store this in a file instead of LMDB
95
+ await this.options.cache.setBlob(contentKey, content);
96
+ return { size, hash };
97
+ }
98
+ async getCode() {
99
+ if (this.ast != null && this.isASTDirty) {
100
+ throw new Error('Cannot call getCode() on an asset with a dirty AST. For transformers, implement canReuseAST() and check asset.isASTDirty.');
101
+ }
102
+ let content = await this.content;
103
+ if (typeof content === 'string' || content instanceof Buffer) {
104
+ return content.toString();
105
+ }
106
+ else if (content != null) {
107
+ // @ts-expect-error TS2345
108
+ this.content = (0, utils_1.bufferStream)(content);
109
+ return (await this.content).toString();
110
+ }
111
+ (0, assert_1.default)(false, 'Internal error: missing content');
112
+ }
113
+ async getBuffer() {
114
+ let content = await this.content;
115
+ if (content == null) {
116
+ return Buffer.alloc(0);
117
+ }
118
+ else if (content instanceof Buffer) {
119
+ return content;
120
+ }
121
+ else if (typeof content === 'string') {
122
+ return Buffer.from(content);
123
+ }
124
+ // @ts-expect-error TS2345
125
+ this.content = (0, utils_1.bufferStream)(content);
126
+ return this.content;
127
+ }
128
+ getStream() {
129
+ if (this.content instanceof stream_1.Readable) {
130
+ // Remove content if it's a stream, as it should not be reused.
131
+ let content = this.content;
132
+ this.content = null;
133
+ return content;
134
+ }
135
+ if (this.content instanceof Promise) {
136
+ return (0, utils_1.streamFromPromise)(this.content);
137
+ }
138
+ return (0, utils_1.blobToStream)(this.content ?? Buffer.alloc(0));
139
+ }
140
+ setCode(code) {
141
+ this.content = code;
142
+ this.clearAST();
143
+ }
144
+ setBuffer(buffer) {
145
+ this.content = buffer;
146
+ this.clearAST();
147
+ }
148
+ /**
149
+ * @deprecated This has been broken on any cache other than FSCache for a long time.
150
+ */
151
+ setStream(stream) {
152
+ this.content = stream;
153
+ this.clearAST();
154
+ }
155
+ async loadExistingSourcemap() {
156
+ if (this.map) {
157
+ return this.map;
158
+ }
159
+ let code = await this.getCode();
160
+ let map = await (0, utils_1.loadSourceMap)((0, projectPath_1.fromProjectPath)(this.options.projectRoot, this.value.filePath), code, {
161
+ fs: this.options.inputFS,
162
+ projectRoot: this.options.projectRoot,
163
+ });
164
+ if (map) {
165
+ this.map = map;
166
+ this.mapBuffer = map.toBuffer();
167
+ this.setCode(code.replace(utils_1.SOURCEMAP_RE, ''));
168
+ }
169
+ return this.map;
170
+ }
171
+ getMapBuffer() {
172
+ return Promise.resolve(this.mapBuffer);
173
+ }
174
+ async getMap() {
175
+ if (this.map == null) {
176
+ let mapBuffer = this.mapBuffer ?? (await this.getMapBuffer());
177
+ if (mapBuffer) {
178
+ // Get sourcemap from flatbuffer
179
+ this.map = new source_map_1.default(this.options.projectRoot, mapBuffer);
180
+ }
181
+ }
182
+ return this.map;
183
+ }
184
+ setMap(map) {
185
+ // If we have sourceContent available, it means this asset is source code without
186
+ // a previous source map. Ensure that the map set by the transformer has the original
187
+ // source content available.
188
+ if (map != null && this.sourceContent != null) {
189
+ map.setSourceContent((0, projectPath_1.fromProjectPath)(this.options.projectRoot, this.value.filePath), this.sourceContent);
190
+ this.sourceContent = null;
191
+ }
192
+ this.map = map;
193
+ this.mapBuffer = this.map?.toBuffer();
194
+ }
195
+ getAST() {
196
+ return Promise.resolve(this.ast);
197
+ }
198
+ setAST(ast) {
199
+ this.ast = ast;
200
+ this.isASTDirty = true;
201
+ this.value.astGenerator = {
202
+ type: ast.type,
203
+ version: ast.version,
204
+ };
205
+ }
206
+ clearAST() {
207
+ this.ast = null;
208
+ this.isASTDirty = false;
209
+ this.value.astGenerator = null;
210
+ }
211
+ getCacheKey(key) {
212
+ if ((0, feature_flags_1.getFeatureFlag)('cachePerformanceImprovements')) {
213
+ const filePath = (0, projectPath_1.fromProjectPathRelative)(this.value.filePath);
214
+ return `Asset/${constants_1.ATLASPACK_VERSION}/${filePath}/${this.value.id}/${key}`;
215
+ }
216
+ return (0, rust_1.hashString)(constants_1.ATLASPACK_VERSION + key + this.value.id);
217
+ }
218
+ addDependency(opts) {
219
+ // eslint-disable-next-line no-unused-vars
220
+ let { env, symbols, ...rest } = opts;
221
+ let dep = (0, Dependency_1.createDependency)(this.options.projectRoot, {
222
+ ...rest,
223
+ // @ts-expect-error TS2322
224
+ symbols,
225
+ env: (0, Environment_1.mergeEnvironments)(this.options.projectRoot, (0, EnvironmentManager_1.fromEnvironmentId)(this.value.env), env),
226
+ sourceAssetId: this.value.id,
227
+ sourcePath: (0, projectPath_1.fromProjectPath)(this.options.projectRoot, this.value.filePath),
228
+ });
229
+ let existing = this.value.dependencies.get(dep.id);
230
+ if (existing) {
231
+ (0, Dependency_1.mergeDependencies)(existing, dep);
232
+ }
233
+ else {
234
+ this.value.dependencies.set(dep.id, dep);
235
+ }
236
+ return dep.id;
237
+ }
238
+ invalidateOnFileChange(filePath) {
239
+ this.invalidations.invalidateOnFileChange.add(filePath);
240
+ }
241
+ invalidateOnFileCreate(invalidation) {
242
+ this.invalidations.invalidateOnFileCreate.push((0, utils_2.invalidateOnFileCreateToInternal)(this.options.projectRoot, invalidation));
243
+ }
244
+ invalidateOnEnvChange(key) {
245
+ this.invalidations.invalidateOnEnvChange.add(key);
246
+ }
247
+ invalidateOnBuild() {
248
+ this.invalidations.invalidateOnBuild = true;
249
+ }
250
+ invalidateOnStartup() {
251
+ this.invalidations.invalidateOnStartup = true;
252
+ }
253
+ getDependencies() {
254
+ return Array.from(this.value.dependencies.values());
255
+ }
256
+ createChildAsset(result, plugin, configPath, configKeyPath) {
257
+ let content = result.content ?? null;
258
+ let asset = new UncommittedAsset({
259
+ value: (0, assetUtils_1.createAsset)(this.options.projectRoot, {
260
+ code: this.code,
261
+ filePath: this.value.filePath,
262
+ type: result.type,
263
+ bundleBehavior: result.bundleBehavior ??
264
+ (this.value.bundleBehavior == null
265
+ ? null
266
+ : types_1.BundleBehaviorNames[this.value.bundleBehavior]),
267
+ isBundleSplittable: result.isBundleSplittable ?? this.value.isBundleSplittable,
268
+ isSource: this.value.isSource,
269
+ env: (0, Environment_1.mergeEnvironments)(this.options.projectRoot, (0, EnvironmentManager_1.fromEnvironmentId)(this.value.env), result.env),
270
+ dependencies: this.value.type === result.type
271
+ ? new Map(this.value.dependencies)
272
+ : new Map(),
273
+ meta: {
274
+ ...this.value.meta,
275
+ ...result.meta,
276
+ },
277
+ pipeline: result.pipeline ??
278
+ (this.value.type === result.type ? this.value.pipeline : null),
279
+ stats: {
280
+ time: 0,
281
+ size: this.value.stats.size,
282
+ },
283
+ // @ts-expect-error TS2322
284
+ symbols: result.symbols,
285
+ sideEffects: result.sideEffects ?? this.value.sideEffects,
286
+ uniqueKey: result.uniqueKey,
287
+ astGenerator: result.ast
288
+ ? { type: result.ast.type, version: result.ast.version }
289
+ : null,
290
+ plugin,
291
+ configPath,
292
+ configKeyPath,
293
+ }),
294
+ options: this.options,
295
+ content,
296
+ ast: result.ast,
297
+ isASTDirty: result.ast === this.ast ? this.isASTDirty : true,
298
+ mapBuffer: result.map ? result.map.toBuffer() : null,
299
+ code: this.code,
300
+ invalidations: this.invalidations,
301
+ });
302
+ let dependencies = result.dependencies;
303
+ if (dependencies) {
304
+ for (let dep of dependencies) {
305
+ asset.addDependency(dep);
306
+ }
307
+ }
308
+ return asset;
309
+ }
310
+ updateId() {
311
+ // @ts-expect-error TS2345
312
+ this.value.id = (0, assetUtils_1.createAssetIdFromOptions)(this.value);
313
+ }
314
+ }
315
+ exports.default = UncommittedAsset;
@@ -0,0 +1,196 @@
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
+ const path_1 = __importDefault(require("path"));
40
+ const utils_1 = require("@atlaspack/utils");
41
+ const logger_1 = __importStar(require("@atlaspack/logger"));
42
+ const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
43
+ const UncommittedAsset_1 = __importDefault(require("./UncommittedAsset"));
44
+ const assetUtils_1 = require("./assetUtils");
45
+ const Asset_1 = require("./public/Asset");
46
+ const PluginOptions_1 = __importDefault(require("./public/PluginOptions"));
47
+ const summarizeRequest_1 = __importDefault(require("./summarizeRequest"));
48
+ const projectPath_1 = require("./projectPath");
49
+ const profiler_1 = require("@atlaspack/profiler");
50
+ class Validation {
51
+ constructor({ config, dedicatedThread, options, requests, report, workerApi, }) {
52
+ this.allAssets = {};
53
+ this.allValidators = {};
54
+ this.dedicatedThread = dedicatedThread ?? false;
55
+ this.options = options;
56
+ this.atlaspackConfig = config;
57
+ this.report = report;
58
+ this.requests = requests;
59
+ this.workerApi = workerApi;
60
+ }
61
+ async run() {
62
+ let pluginOptions = new PluginOptions_1.default(this.options);
63
+ await this.buildAssetsAndValidators();
64
+ await Promise.all(Object.keys(this.allValidators).map(async (validatorName) => {
65
+ let assets = this.allAssets[validatorName];
66
+ if (assets) {
67
+ let plugin = this.allValidators[validatorName];
68
+ let validatorLogger = new logger_1.PluginLogger({ origin: validatorName });
69
+ let validatorTracer = new profiler_1.PluginTracer({
70
+ origin: validatorName,
71
+ category: 'validator',
72
+ });
73
+ let validatorResults = [];
74
+ try {
75
+ // If the plugin supports the single-threading validateAll method, pass all assets to it.
76
+ // @ts-expect-error TS2339
77
+ if (plugin.validateAll && this.dedicatedThread) {
78
+ // @ts-expect-error TS2339
79
+ validatorResults = await plugin.validateAll({
80
+ assets: assets.map((asset) => new Asset_1.Asset(asset)),
81
+ options: pluginOptions,
82
+ logger: validatorLogger,
83
+ tracer: validatorTracer,
84
+ resolveConfigWithPath: (configNames, assetFilePath) => (0, utils_1.resolveConfig)(this.options.inputFS, assetFilePath, configNames, this.options.projectRoot),
85
+ });
86
+ }
87
+ // Otherwise, pass the assets one-at-a-time
88
+ // @ts-expect-error TS2339
89
+ else if (plugin.validate && !this.dedicatedThread) {
90
+ await Promise.all(assets.map(async (input) => {
91
+ let config = null;
92
+ let publicAsset = new Asset_1.Asset(input);
93
+ // @ts-expect-error TS2339
94
+ if (plugin.getConfig) {
95
+ // @ts-expect-error TS2339
96
+ config = await plugin.getConfig({
97
+ asset: publicAsset,
98
+ options: pluginOptions,
99
+ logger: validatorLogger,
100
+ tracer: validatorTracer,
101
+ resolveConfig: (configNames) => (0, utils_1.resolveConfig)(this.options.inputFS, publicAsset.filePath, configNames, this.options.projectRoot),
102
+ });
103
+ }
104
+ // @ts-expect-error TS2339
105
+ let validatorResult = await plugin.validate({
106
+ asset: publicAsset,
107
+ options: pluginOptions,
108
+ config,
109
+ logger: validatorLogger,
110
+ tracer: validatorTracer,
111
+ });
112
+ validatorResults.push(validatorResult);
113
+ }));
114
+ }
115
+ this.handleResults(validatorResults);
116
+ }
117
+ catch (e) {
118
+ throw new diagnostic_1.default({
119
+ diagnostic: (0, diagnostic_1.errorToDiagnostic)(e, {
120
+ origin: validatorName,
121
+ }),
122
+ });
123
+ }
124
+ }
125
+ }));
126
+ }
127
+ async buildAssetsAndValidators() {
128
+ // Figure out what validators need to be run, and group the assets by the relevant validators.
129
+ await Promise.all(this.requests.map(async (request) => {
130
+ this.report({
131
+ type: 'validation',
132
+ // @ts-expect-error TS2322
133
+ filePath: (0, projectPath_1.fromProjectPath)(this.options.projectRoot, request.filePath),
134
+ });
135
+ let asset = await this.loadAsset(request);
136
+ let validators = await this.atlaspackConfig.getValidators(
137
+ // @ts-expect-error TS2345
138
+ request.filePath);
139
+ for (let validator of validators) {
140
+ this.allValidators[validator.name] = validator.plugin;
141
+ if (this.allAssets[validator.name]) {
142
+ this.allAssets[validator.name].push(asset);
143
+ }
144
+ else {
145
+ this.allAssets[validator.name] = [asset];
146
+ }
147
+ }
148
+ }));
149
+ }
150
+ handleResults(validatorResults) {
151
+ let warnings = [];
152
+ let errors = [];
153
+ validatorResults.forEach((result) => {
154
+ if (result) {
155
+ warnings.push(...result.warnings);
156
+ errors.push(...result.errors);
157
+ }
158
+ });
159
+ if (errors.length > 0) {
160
+ throw new diagnostic_1.default({
161
+ diagnostic: errors,
162
+ });
163
+ }
164
+ if (warnings.length > 0) {
165
+ logger_1.default.warn(warnings);
166
+ }
167
+ }
168
+ async loadAsset(request) {
169
+ let { filePath, env, code, sideEffects, query } = request;
170
+ let { content, size, isSource } = await (0, summarizeRequest_1.default)(this.options.inputFS, {
171
+ // @ts-expect-error TS2322
172
+ filePath: (0, projectPath_1.fromProjectPath)(this.options.projectRoot, request.filePath),
173
+ });
174
+ return new UncommittedAsset_1.default({
175
+ value: (0, assetUtils_1.createAsset)(this.options.projectRoot, {
176
+ code,
177
+ // @ts-expect-error TS2322
178
+ filePath: filePath,
179
+ isSource,
180
+ // @ts-expect-error TS2345
181
+ type: path_1.default.extname((0, projectPath_1.fromProjectPathRelative)(filePath)).slice(1),
182
+ query,
183
+ // @ts-expect-error TS2322
184
+ env: env,
185
+ stats: {
186
+ time: 0,
187
+ size,
188
+ },
189
+ sideEffects: sideEffects,
190
+ }),
191
+ options: this.options,
192
+ content,
193
+ });
194
+ }
195
+ }
196
+ exports.default = Validation;