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