@atlaspack/core 2.13.2-dev.3689 → 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 +25 -9
- 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 -115
- package/lib/loadDotEnv.js +0 -54
- package/lib/projectPath.js +0 -112
- 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
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = createValidationRequest;
|
|
7
|
-
function _nullthrows() {
|
|
8
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
9
|
-
_nullthrows = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
var _AtlaspackConfig = require("../AtlaspackConfig");
|
|
15
|
-
var _ReporterRunner = require("../ReporterRunner");
|
|
16
|
-
var _Validation = _interopRequireDefault(require("../Validation"));
|
|
17
|
-
var _AtlaspackConfigRequest = _interopRequireDefault(require("./AtlaspackConfigRequest"));
|
|
18
|
-
var _RequestTracker = require("../RequestTracker");
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
function createValidationRequest(input) {
|
|
21
|
-
return {
|
|
22
|
-
id: 'validation',
|
|
23
|
-
type: _RequestTracker.requestTypes.validation_request,
|
|
24
|
-
run: async ({
|
|
25
|
-
input: {
|
|
26
|
-
assetRequests,
|
|
27
|
-
optionsRef
|
|
28
|
-
},
|
|
29
|
-
api,
|
|
30
|
-
options,
|
|
31
|
-
farm
|
|
32
|
-
}) => {
|
|
33
|
-
let {
|
|
34
|
-
config: processedConfig,
|
|
35
|
-
cachePath
|
|
36
|
-
} = (0, _nullthrows().default)(await api.runRequest((0, _AtlaspackConfigRequest.default)()));
|
|
37
|
-
let config = new _AtlaspackConfig.AtlaspackConfig(processedConfig, options);
|
|
38
|
-
let trackedRequestsDesc = assetRequests.filter(request => {
|
|
39
|
-
return config.getValidatorNames(request.filePath).length > 0;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Schedule validations on workers for all plugins that implement the one-asset-at-a-time "validate" method.
|
|
43
|
-
let promises = trackedRequestsDesc.map(async request => (await farm.createHandle('runValidate'))({
|
|
44
|
-
requests: [request],
|
|
45
|
-
optionsRef: optionsRef,
|
|
46
|
-
configCachePath: cachePath
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
// Skip sending validation requests if no validators were configured
|
|
50
|
-
if (trackedRequestsDesc.length === 0) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Schedule validations on the main thread for all validation plugins that implement "validateAll".
|
|
55
|
-
promises.push(new _Validation.default({
|
|
56
|
-
requests: trackedRequestsDesc,
|
|
57
|
-
options,
|
|
58
|
-
config,
|
|
59
|
-
report: _ReporterRunner.report,
|
|
60
|
-
dedicatedThread: true
|
|
61
|
-
}).run());
|
|
62
|
-
await Promise.all(promises);
|
|
63
|
-
},
|
|
64
|
-
input
|
|
65
|
-
};
|
|
66
|
-
}
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = createWriteBundleRequest;
|
|
7
|
-
var _constants = require("../constants");
|
|
8
|
-
function _nullthrows() {
|
|
9
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
10
|
-
_nullthrows = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
function _path() {
|
|
16
|
-
const data = _interopRequireDefault(require("path"));
|
|
17
|
-
_path = function () {
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
var _Bundle = require("../public/Bundle");
|
|
23
|
-
function _utils() {
|
|
24
|
-
const data = require("@atlaspack/utils");
|
|
25
|
-
_utils = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
function _stream() {
|
|
31
|
-
const data = require("stream");
|
|
32
|
-
_stream = function () {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
var _projectPath = require("../projectPath");
|
|
38
|
-
var _AtlaspackConfigRequest = _interopRequireWildcard(require("./AtlaspackConfigRequest"));
|
|
39
|
-
var _PluginOptions = _interopRequireDefault(require("../public/PluginOptions"));
|
|
40
|
-
function _logger() {
|
|
41
|
-
const data = require("@atlaspack/logger");
|
|
42
|
-
_logger = function () {
|
|
43
|
-
return data;
|
|
44
|
-
};
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
var _DevDepRequest = require("./DevDepRequest");
|
|
48
|
-
var _AtlaspackConfig = require("../AtlaspackConfig");
|
|
49
|
-
function _diagnostic() {
|
|
50
|
-
const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
|
|
51
|
-
_diagnostic = function () {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
function _profiler() {
|
|
57
|
-
const data = require("@atlaspack/profiler");
|
|
58
|
-
_profiler = function () {
|
|
59
|
-
return data;
|
|
60
|
-
};
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
var _RequestTracker = require("../RequestTracker");
|
|
64
|
-
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); }
|
|
65
|
-
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; }
|
|
66
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
67
|
-
const HASH_REF_PREFIX_LEN = _constants.HASH_REF_PREFIX.length;
|
|
68
|
-
const BOUNDARY_LENGTH = _constants.HASH_REF_PREFIX.length + 32 - 1;
|
|
69
|
-
/**
|
|
70
|
-
* Writes a bundle to the dist directory, replacing hash references with the final content hashes.
|
|
71
|
-
*/
|
|
72
|
-
function createWriteBundleRequest(input) {
|
|
73
|
-
let name = (0, _nullthrows().default)(input.bundle.name);
|
|
74
|
-
let nameHash = (0, _nullthrows().default)(input.hashRefToNameHash.get(input.bundle.hashReference));
|
|
75
|
-
return {
|
|
76
|
-
id: `${input.bundle.id}:${input.info.hash}:${nameHash}:${name}`,
|
|
77
|
-
type: _RequestTracker.requestTypes.write_bundle_request,
|
|
78
|
-
run,
|
|
79
|
-
input
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
async function run({
|
|
83
|
-
input,
|
|
84
|
-
options,
|
|
85
|
-
api
|
|
86
|
-
}) {
|
|
87
|
-
let {
|
|
88
|
-
bundleGraph,
|
|
89
|
-
bundle,
|
|
90
|
-
info,
|
|
91
|
-
hashRefToNameHash
|
|
92
|
-
} = input;
|
|
93
|
-
let {
|
|
94
|
-
inputFS,
|
|
95
|
-
outputFS
|
|
96
|
-
} = options;
|
|
97
|
-
let name = (0, _nullthrows().default)(bundle.name);
|
|
98
|
-
let thisHashReference = bundle.hashReference;
|
|
99
|
-
if (info.type !== bundle.type) {
|
|
100
|
-
name = name.slice(0, -_path().default.extname(name).length) + '.' + info.type;
|
|
101
|
-
}
|
|
102
|
-
if (name.includes(thisHashReference)) {
|
|
103
|
-
let thisNameHash = (0, _nullthrows().default)(hashRefToNameHash.get(thisHashReference));
|
|
104
|
-
name = name.replace(thisHashReference, thisNameHash);
|
|
105
|
-
}
|
|
106
|
-
let filePath = (0, _projectPath.joinProjectPath)(bundle.target.distDir, name);
|
|
107
|
-
|
|
108
|
-
// Watch the bundle and source map for deletion.
|
|
109
|
-
// Also watch the dist dir because invalidateOnFileDelete does not currently
|
|
110
|
-
// invalidate when a parent directory is deleted.
|
|
111
|
-
// TODO: do we want to also watch for file edits?
|
|
112
|
-
api.invalidateOnFileDelete(bundle.target.distDir);
|
|
113
|
-
api.invalidateOnFileDelete(filePath);
|
|
114
|
-
let cacheKeys = info.cacheKeys;
|
|
115
|
-
let mapKey = cacheKeys.map;
|
|
116
|
-
let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
|
|
117
|
-
if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline) {
|
|
118
|
-
api.invalidateOnFileDelete((0, _projectPath.toProjectPath)(options.projectRoot, fullPath + '.map'));
|
|
119
|
-
}
|
|
120
|
-
let dir = _path().default.dirname(fullPath);
|
|
121
|
-
await outputFS.mkdirp(dir); // ? Got rid of dist exists, is this an expensive operation
|
|
122
|
-
|
|
123
|
-
// Use the file mode from the entry asset as the file mode for the bundle.
|
|
124
|
-
// Don't do this for browser builds, as the executable bit in particular is unnecessary.
|
|
125
|
-
let publicBundle = _Bundle.NamedBundle.get(bundle, bundleGraph, options);
|
|
126
|
-
let mainEntry = publicBundle.getMainEntry();
|
|
127
|
-
let writeOptions = publicBundle.env.isBrowser() || !mainEntry ? undefined : {
|
|
128
|
-
mode: (await inputFS.stat(mainEntry.filePath)).mode
|
|
129
|
-
};
|
|
130
|
-
let contentStream;
|
|
131
|
-
if (info.isLargeBlob) {
|
|
132
|
-
contentStream = options.cache.getStream(cacheKeys.content);
|
|
133
|
-
} else {
|
|
134
|
-
contentStream = (0, _utils().blobToStream)(await options.cache.getBlob(cacheKeys.content));
|
|
135
|
-
}
|
|
136
|
-
let size = 0;
|
|
137
|
-
contentStream = contentStream.pipe(new (_utils().TapStream)(buf => {
|
|
138
|
-
size += buf.length;
|
|
139
|
-
}));
|
|
140
|
-
let configResult = (0, _nullthrows().default)(await api.runRequest((0, _AtlaspackConfigRequest.default)()));
|
|
141
|
-
let config = (0, _AtlaspackConfigRequest.getCachedAtlaspackConfig)(configResult, options);
|
|
142
|
-
let {
|
|
143
|
-
devDeps,
|
|
144
|
-
invalidDevDeps
|
|
145
|
-
} = await (0, _DevDepRequest.getDevDepRequests)(api);
|
|
146
|
-
(0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, options, config);
|
|
147
|
-
await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api);
|
|
148
|
-
if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline && (await options.cache.has(mapKey))) {
|
|
149
|
-
await writeFiles((0, _utils().blobToStream)(await options.cache.getBlob(mapKey)), info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
|
|
150
|
-
}
|
|
151
|
-
let res = {
|
|
152
|
-
filePath,
|
|
153
|
-
type: info.type,
|
|
154
|
-
stats: {
|
|
155
|
-
size,
|
|
156
|
-
time: info.time ?? 0
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
api.storeResult(res);
|
|
160
|
-
return res;
|
|
161
|
-
}
|
|
162
|
-
async function writeFiles(inputStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api) {
|
|
163
|
-
let compressors = await config.getCompressors((0, _projectPath.fromProjectPathRelative)(filePath));
|
|
164
|
-
let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
|
|
165
|
-
let stream = info.hashReferences.length ? inputStream.pipe(replaceStream(hashRefToNameHash)) : inputStream;
|
|
166
|
-
let promises = [];
|
|
167
|
-
for (let compressor of compressors) {
|
|
168
|
-
promises.push(runCompressor(compressor, cloneStream(stream), options, outputFS, fullPath, writeOptions, devDeps, api));
|
|
169
|
-
}
|
|
170
|
-
await Promise.all(promises);
|
|
171
|
-
}
|
|
172
|
-
async function runCompressor(compressor, stream, options, outputFS, filePath, writeOptions, devDeps, api) {
|
|
173
|
-
let measurement;
|
|
174
|
-
try {
|
|
175
|
-
measurement = _profiler().tracer.createMeasurement(compressor.name, 'compress', _path().default.relative(options.projectRoot, filePath));
|
|
176
|
-
let res = await compressor.plugin.compress({
|
|
177
|
-
stream,
|
|
178
|
-
options: new _PluginOptions.default(options),
|
|
179
|
-
logger: new (_logger().PluginLogger)({
|
|
180
|
-
origin: compressor.name
|
|
181
|
-
}),
|
|
182
|
-
tracer: new (_profiler().PluginTracer)({
|
|
183
|
-
origin: compressor.name,
|
|
184
|
-
category: 'compress'
|
|
185
|
-
})
|
|
186
|
-
});
|
|
187
|
-
if (res != null) {
|
|
188
|
-
await new Promise((resolve, reject) => (0, _stream().pipeline)(res.stream, outputFS.createWriteStream(filePath + (res.type != null ? '.' + res.type : ''), writeOptions), err => {
|
|
189
|
-
if (err) reject(err);else resolve();
|
|
190
|
-
}));
|
|
191
|
-
}
|
|
192
|
-
} catch (err) {
|
|
193
|
-
throw new (_diagnostic().default)({
|
|
194
|
-
diagnostic: (0, _diagnostic().errorToDiagnostic)(err, {
|
|
195
|
-
origin: compressor.name
|
|
196
|
-
})
|
|
197
|
-
});
|
|
198
|
-
} finally {
|
|
199
|
-
measurement && measurement.end();
|
|
200
|
-
// Add dev deps for compressor plugins AFTER running them, to account for lazy require().
|
|
201
|
-
let devDepRequest = await (0, _DevDepRequest.createDevDependency)({
|
|
202
|
-
specifier: compressor.name,
|
|
203
|
-
resolveFrom: compressor.resolveFrom
|
|
204
|
-
}, devDeps, options);
|
|
205
|
-
await (0, _DevDepRequest.runDevDepRequest)(api, devDepRequest);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function replaceStream(hashRefToNameHash) {
|
|
209
|
-
let boundaryStr = Buffer.alloc(0);
|
|
210
|
-
let replaced = Buffer.alloc(0);
|
|
211
|
-
return new (_stream().Transform)({
|
|
212
|
-
transform(chunk, encoding, cb) {
|
|
213
|
-
let str = Buffer.concat([boundaryStr, Buffer.from(chunk)]);
|
|
214
|
-
let lastMatchI = 0;
|
|
215
|
-
if (replaced.length < str.byteLength) {
|
|
216
|
-
replaced = Buffer.alloc(str.byteLength);
|
|
217
|
-
}
|
|
218
|
-
let replacedLength = 0;
|
|
219
|
-
while (lastMatchI < str.byteLength) {
|
|
220
|
-
let matchI = str.indexOf(_constants.HASH_REF_PREFIX, lastMatchI);
|
|
221
|
-
if (matchI === -1) {
|
|
222
|
-
replaced.set(str.subarray(lastMatchI, str.byteLength), replacedLength);
|
|
223
|
-
replacedLength += str.byteLength - lastMatchI;
|
|
224
|
-
break;
|
|
225
|
-
} else {
|
|
226
|
-
let match = str.subarray(matchI, matchI + HASH_REF_PREFIX_LEN + _constants.HASH_REF_HASH_LEN).toString();
|
|
227
|
-
let replacement = Buffer.from(hashRefToNameHash.get(match) ?? match);
|
|
228
|
-
replaced.set(str.subarray(lastMatchI, matchI), replacedLength);
|
|
229
|
-
replacedLength += matchI - lastMatchI;
|
|
230
|
-
replaced.set(replacement, replacedLength);
|
|
231
|
-
replacedLength += replacement.byteLength;
|
|
232
|
-
lastMatchI = matchI + HASH_REF_PREFIX_LEN + _constants.HASH_REF_HASH_LEN;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
boundaryStr = replaced.subarray(replacedLength - BOUNDARY_LENGTH, replacedLength);
|
|
236
|
-
let strUpToBoundary = replaced.subarray(0, replacedLength - BOUNDARY_LENGTH);
|
|
237
|
-
cb(null, strUpToBoundary);
|
|
238
|
-
},
|
|
239
|
-
flush(cb) {
|
|
240
|
-
cb(null, boundaryStr);
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
function cloneStream(readable) {
|
|
245
|
-
let res = new (_stream().Readable)();
|
|
246
|
-
// $FlowFixMe
|
|
247
|
-
res._read = () => {};
|
|
248
|
-
readable.on('data', chunk => res.push(chunk));
|
|
249
|
-
readable.on('end', () => res.push(null));
|
|
250
|
-
readable.on('error', err => res.emit('error', err));
|
|
251
|
-
return res;
|
|
252
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = createWriteBundlesRequest;
|
|
7
|
-
var _RequestTracker = require("../RequestTracker");
|
|
8
|
-
var _constants = require("../constants");
|
|
9
|
-
var _projectPath = require("../projectPath");
|
|
10
|
-
function _nullthrows() {
|
|
11
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
12
|
-
_nullthrows = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
function _rust() {
|
|
18
|
-
const data = require("@atlaspack/rust");
|
|
19
|
-
_rust = function () {
|
|
20
|
-
return data;
|
|
21
|
-
};
|
|
22
|
-
return data;
|
|
23
|
-
}
|
|
24
|
-
var _PackageRequest = require("./PackageRequest");
|
|
25
|
-
var _WriteBundleRequest = _interopRequireDefault(require("./WriteBundleRequest"));
|
|
26
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
/**
|
|
28
|
-
* Packages, optimizes, and writes all bundles to the dist directory.
|
|
29
|
-
*/
|
|
30
|
-
function createWriteBundlesRequest(input) {
|
|
31
|
-
return {
|
|
32
|
-
type: _RequestTracker.requestTypes.write_bundles_request,
|
|
33
|
-
id: 'write_bundles:' + input.bundleGraph.getBundleGraphHash(),
|
|
34
|
-
run,
|
|
35
|
-
input
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
async function run({
|
|
39
|
-
input,
|
|
40
|
-
api,
|
|
41
|
-
farm,
|
|
42
|
-
options
|
|
43
|
-
}) {
|
|
44
|
-
let {
|
|
45
|
-
bundleGraph,
|
|
46
|
-
optionsRef
|
|
47
|
-
} = input;
|
|
48
|
-
let {
|
|
49
|
-
ref,
|
|
50
|
-
dispose
|
|
51
|
-
} = await farm.createSharedReference(bundleGraph);
|
|
52
|
-
api.invalidateOnOptionChange('shouldContentHash');
|
|
53
|
-
let res = new Map();
|
|
54
|
-
let bundleInfoMap = {};
|
|
55
|
-
let writeEarlyPromises = {};
|
|
56
|
-
let hashRefToNameHash = new Map();
|
|
57
|
-
let bundles = bundleGraph.getBundles().filter(bundle => {
|
|
58
|
-
// Do not package and write placeholder bundles to disk. We just
|
|
59
|
-
// need to update the name so other bundles can reference it.
|
|
60
|
-
if (bundle.isPlaceholder) {
|
|
61
|
-
let hash = bundle.id.slice(-8);
|
|
62
|
-
hashRefToNameHash.set(bundle.hashReference, hash);
|
|
63
|
-
let name = (0, _nullthrows().default)(bundle.name, `Expected ${bundle.type} bundle to have a name`).replace(bundle.hashReference, hash);
|
|
64
|
-
res.set(bundle.id, {
|
|
65
|
-
filePath: (0, _projectPath.joinProjectPath)(bundle.target.distDir, name),
|
|
66
|
-
type: bundle.type,
|
|
67
|
-
// FIXME: this is wrong if the packager changes the type...
|
|
68
|
-
stats: {
|
|
69
|
-
time: 0,
|
|
70
|
-
size: 0
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// Package on the main thread if there is only one bundle to package.
|
|
79
|
-
// This avoids the cost of serializing the bundle graph for single file change builds.
|
|
80
|
-
let useMainThread = bundles.length === 1 || bundles.filter(b => !api.canSkipSubrequest(bundleGraph.getHash(b))).length === 1;
|
|
81
|
-
try {
|
|
82
|
-
await Promise.all(bundles.map(async bundle => {
|
|
83
|
-
let request = (0, _PackageRequest.createPackageRequest)({
|
|
84
|
-
bundle,
|
|
85
|
-
bundleGraph,
|
|
86
|
-
bundleGraphReference: ref,
|
|
87
|
-
optionsRef,
|
|
88
|
-
useMainThread
|
|
89
|
-
});
|
|
90
|
-
let info = await api.runRequest(request);
|
|
91
|
-
if (!useMainThread) {
|
|
92
|
-
// Force a refresh of the cache to avoid a race condition
|
|
93
|
-
// between threaded reads and writes that can result in an LMDB cache miss:
|
|
94
|
-
// 1. The main thread has read some value from cache, necessitating a read transaction.
|
|
95
|
-
// 2. Concurrently, Thread A finishes a packaging request.
|
|
96
|
-
// 3. Subsequently, the main thread is tasked with this request, but fails because the read transaction is stale.
|
|
97
|
-
// This only occurs if the reading thread has a transaction that was created before the writing thread committed,
|
|
98
|
-
// and the transaction is still live when the reading thread attempts to get the written value.
|
|
99
|
-
// See https://github.com/parcel-bundler/parcel/issues/9121
|
|
100
|
-
options.cache.refresh();
|
|
101
|
-
}
|
|
102
|
-
bundleInfoMap[bundle.id] = info;
|
|
103
|
-
if (!info.hashReferences.length) {
|
|
104
|
-
hashRefToNameHash.set(bundle.hashReference, options.shouldContentHash ? info.hash.slice(-8) : bundle.id.slice(-8));
|
|
105
|
-
let writeBundleRequest = (0, _WriteBundleRequest.default)({
|
|
106
|
-
bundle,
|
|
107
|
-
info,
|
|
108
|
-
hashRefToNameHash,
|
|
109
|
-
bundleGraph
|
|
110
|
-
});
|
|
111
|
-
let promise = api.runRequest(writeBundleRequest);
|
|
112
|
-
// If the promise rejects before we await it (below), we don't want to crash the build.
|
|
113
|
-
promise.catch(() => {});
|
|
114
|
-
writeEarlyPromises[bundle.id] = promise;
|
|
115
|
-
}
|
|
116
|
-
}));
|
|
117
|
-
assignComplexNameHashes(hashRefToNameHash, bundles, bundleInfoMap, options);
|
|
118
|
-
await Promise.all(bundles.map(bundle => {
|
|
119
|
-
let promise = writeEarlyPromises[bundle.id] ?? api.runRequest((0, _WriteBundleRequest.default)({
|
|
120
|
-
bundle,
|
|
121
|
-
info: bundleInfoMap[bundle.id],
|
|
122
|
-
hashRefToNameHash,
|
|
123
|
-
bundleGraph
|
|
124
|
-
}));
|
|
125
|
-
return promise.then(r => res.set(bundle.id, r));
|
|
126
|
-
}));
|
|
127
|
-
api.storeResult(res);
|
|
128
|
-
return res;
|
|
129
|
-
} finally {
|
|
130
|
-
await dispose();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function assignComplexNameHashes(hashRefToNameHash, bundles, bundleInfoMap, options) {
|
|
134
|
-
for (let bundle of bundles) {
|
|
135
|
-
if (hashRefToNameHash.get(bundle.hashReference) != null) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
hashRefToNameHash.set(bundle.hashReference, options.shouldContentHash ? (0, _rust().hashString)([...getBundlesIncludedInHash(bundle.id, bundleInfoMap)].map(bundleId => bundleInfoMap[bundleId].hash).join(':')).slice(-8) : bundle.id.slice(-8));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function getBundlesIncludedInHash(bundleId, bundleInfoMap, included = new Set()) {
|
|
142
|
-
included.add(bundleId);
|
|
143
|
-
for (let hashRef of bundleInfoMap[bundleId].hashReferences) {
|
|
144
|
-
let referencedId = getIdFromHashRef(hashRef);
|
|
145
|
-
if (!included.has(referencedId)) {
|
|
146
|
-
getBundlesIncludedInHash(referencedId, bundleInfoMap, included);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return included;
|
|
150
|
-
}
|
|
151
|
-
function getIdFromHashRef(hashRef) {
|
|
152
|
-
return hashRef.slice(_constants.HASH_REF_PREFIX.length);
|
|
153
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _default() {
|
|
4
|
-
const data = _interopRequireDefault(require("rfdc/default"));
|
|
5
|
-
_default = function () {
|
|
6
|
-
return data;
|
|
7
|
-
};
|
|
8
|
-
return data;
|
|
9
|
-
}
|
|
10
|
-
function _jestDiff() {
|
|
11
|
-
const data = require("jest-diff");
|
|
12
|
-
_jestDiff = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
var _AssetGraph = _interopRequireDefault(require("../AssetGraph"));
|
|
18
|
-
var _projectPath = require("../projectPath");
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
/* eslint-disable no-console */ // $FlowFixMe
|
|
21
|
-
// $FlowFixMe
|
|
22
|
-
function filterNode(node) {
|
|
23
|
-
let clone = (0, _default().default)(node);
|
|
24
|
-
|
|
25
|
-
// Clean up anything you don't want to see in the diff
|
|
26
|
-
// delete clone.id;
|
|
27
|
-
delete clone.value.id;
|
|
28
|
-
delete clone.value.meta.id;
|
|
29
|
-
delete clone.value.sourceAssetId;
|
|
30
|
-
delete clone.value.env.id;
|
|
31
|
-
delete clone.value.isEsm;
|
|
32
|
-
delete clone.value.shouldWrap;
|
|
33
|
-
delete clone.value.contentKey;
|
|
34
|
-
delete clone.value.placeholder;
|
|
35
|
-
delete clone.value.code;
|
|
36
|
-
delete clone.value.hasCjsExports;
|
|
37
|
-
delete clone.value.staticExports;
|
|
38
|
-
delete clone.value.isConstantModule;
|
|
39
|
-
delete clone.value.hasNodeReplacements;
|
|
40
|
-
delete clone.value.stats;
|
|
41
|
-
delete clone.value.astKey;
|
|
42
|
-
delete clone.value.astGenerator;
|
|
43
|
-
delete clone.value.dependencies;
|
|
44
|
-
return clone;
|
|
45
|
-
}
|
|
46
|
-
function compactDeep(obj, ignoredPatterns = [], currentPath = '$') {
|
|
47
|
-
if (obj instanceof Map) {
|
|
48
|
-
const copy = {};
|
|
49
|
-
Array.from(obj.entries()).forEach(([k, v]) => {
|
|
50
|
-
if (v != null) {
|
|
51
|
-
copy[k] = compactDeep(v, ignoredPatterns, `${currentPath}.${k}`);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return copy;
|
|
55
|
-
} else if (Array.isArray(obj)) {
|
|
56
|
-
return obj.map(v => compactDeep(v, ignoredPatterns, `${currentPath}[]`));
|
|
57
|
-
} else if (typeof obj === 'object') {
|
|
58
|
-
const copy = {};
|
|
59
|
-
Object.entries(obj ?? {}).forEach(([key, value]) => {
|
|
60
|
-
const path = `${currentPath}.${key}`;
|
|
61
|
-
if (ignoredPatterns.some(pattern => path.includes(pattern))) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
// Equivalent false == null
|
|
65
|
-
if (key === 'isWeak' && value === false) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (value != null) {
|
|
69
|
-
copy[key] = compactDeep(value, ignoredPatterns, path);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return copy;
|
|
73
|
-
} else if (obj != null) {
|
|
74
|
-
return obj;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function assetGraphDiff(jsAssetGraph, rustAssetGraph) {
|
|
78
|
-
const getNodes = graph => {
|
|
79
|
-
let nodes = {};
|
|
80
|
-
graph.traverse(nodeId => {
|
|
81
|
-
let node = graph.getNode(nodeId) ?? null;
|
|
82
|
-
if (!node) return;
|
|
83
|
-
if (node.type === 'dependency') {
|
|
84
|
-
let sourcePath = node.value.sourcePath ?? (0, _projectPath.toProjectPath)('', 'entry');
|
|
85
|
-
nodes[`dep:${(0, _projectPath.fromProjectPathRelative)(sourcePath)}:${node.value.specifier}`] = filterNode(node);
|
|
86
|
-
} else if (node.type === 'asset') {
|
|
87
|
-
nodes[`asset:${(0, _projectPath.fromProjectPathRelative)(node.value.filePath)}`] = filterNode(node);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
return nodes;
|
|
91
|
-
};
|
|
92
|
-
const jsNodes = getNodes(jsAssetGraph);
|
|
93
|
-
const rustNodes = getNodes(rustAssetGraph);
|
|
94
|
-
const all = new Set([...Object.keys(jsNodes), ...Object.keys(rustNodes)]);
|
|
95
|
-
const missing = [];
|
|
96
|
-
const extra = [];
|
|
97
|
-
for (const key of all.keys()) {
|
|
98
|
-
if (process.env.NATIVE_COMPARE !== 'true') {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
let jsNode = jsNodes[key];
|
|
102
|
-
let rustNode = rustNodes[key];
|
|
103
|
-
if (!rustNode) {
|
|
104
|
-
missing.push(key);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (!jsNode) {
|
|
108
|
-
extra.push(key);
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
console.log(key);
|
|
112
|
-
const ignoredPatterns = [
|
|
113
|
-
// ignored because we don't copy the environment ID back from rust
|
|
114
|
-
// in the target value
|
|
115
|
-
'$.value.target.env.id',
|
|
116
|
-
// ignore asset.mapKey because we don't do persistence on rust yet
|
|
117
|
-
'$.value.mapKey',
|
|
118
|
-
// ignore this because it's just the output hash. We don't need to compute
|
|
119
|
-
// this yet
|
|
120
|
-
'$.value.outputHash',
|
|
121
|
-
// ignore correspondingRequest from all nodes
|
|
122
|
-
'$.correspondingRequest'];
|
|
123
|
-
console.log((0, _jestDiff().diff)(compactDeep(jsNode, ignoredPatterns), compactDeep(rustNode, ignoredPatterns)));
|
|
124
|
-
}
|
|
125
|
-
console.log('Missing', missing);
|
|
126
|
-
console.log('Extra', extra);
|
|
127
|
-
}
|
|
128
|
-
module.exports = assetGraphDiff;
|