@atlaspack/core 2.33.1 → 2.35.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 +72 -0
- package/dist/AssetGraph.js +4 -72
- package/dist/BundleGraph.js +34 -0
- package/dist/PackagerRunner.js +13 -88
- package/dist/RequestTracker.js +17 -80
- package/dist/TargetDescriptor.schema.js +3 -0
- package/dist/UncommittedAsset.js +0 -5
- package/dist/applyRuntimes.js +2 -1
- package/dist/atlaspack-v3/AtlaspackV3.js +6 -2
- package/dist/requests/AssetGraphRequest.js +6 -15
- package/dist/requests/AssetGraphRequestRust.js +119 -22
- package/dist/requests/AtlaspackBuildRequest.js +8 -2
- package/dist/requests/BundleGraphRequest.js +9 -15
- package/dist/requests/BundleGraphRequestRust.js +1 -2
- package/dist/requests/PackageRequest.js +1 -1
- package/dist/requests/TargetRequest.js +5 -0
- package/dist/requests/WriteBundleRequest.js +129 -12
- package/dist/requests/WriteBundlesRequest.js +15 -9
- package/dist/resolveOptions.js +2 -4
- package/lib/AssetGraph.js +3 -62
- package/lib/BundleGraph.js +38 -0
- package/lib/PackagerRunner.js +13 -77
- package/lib/RequestTracker.js +15 -69
- package/lib/TargetDescriptor.schema.js +3 -0
- package/lib/UncommittedAsset.js +0 -11
- package/lib/applyRuntimes.js +1 -1
- package/lib/atlaspack-v3/AtlaspackV3.js +6 -2
- package/lib/requests/AssetGraphRequest.js +4 -18
- package/lib/requests/AssetGraphRequestRust.js +88 -23
- package/lib/requests/AtlaspackBuildRequest.js +8 -2
- package/lib/requests/BundleGraphRequest.js +12 -16
- package/lib/requests/BundleGraphRequestRust.js +2 -3
- package/lib/requests/PackageRequest.js +3 -1
- package/lib/requests/TargetRequest.js +5 -0
- package/lib/requests/WriteBundleRequest.js +131 -8
- package/lib/requests/WriteBundlesRequest.js +12 -5
- package/lib/resolveOptions.js +2 -4
- package/lib/types/AssetGraph.d.ts +2 -27
- package/lib/types/BundleGraph.d.ts +5 -0
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +3 -2
- package/lib/types/requests/BundleGraphRequest.d.ts +1 -1
- package/lib/types/requests/WriteBundleRequest.d.ts +20 -1
- package/lib/types/types.d.ts +1 -0
- package/package.json +15 -15
- package/src/AssetGraph.ts +4 -72
- package/src/BundleGraph.ts +39 -0
- package/src/PackagerRunner.ts +15 -101
- package/src/RequestTracker.ts +24 -110
- package/src/TargetDescriptor.schema.ts +3 -0
- package/src/UncommittedAsset.ts +1 -11
- package/src/applyRuntimes.ts +3 -1
- package/src/atlaspack-v3/AtlaspackV3.ts +19 -3
- package/src/requests/AssetGraphRequest.ts +8 -20
- package/src/requests/AssetGraphRequestRust.ts +96 -23
- package/src/requests/AtlaspackBuildRequest.ts +16 -8
- package/src/requests/BundleGraphRequest.ts +12 -30
- package/src/requests/BundleGraphRequestRust.ts +1 -2
- package/src/requests/PackageRequest.ts +1 -1
- package/src/requests/TargetRequest.ts +5 -0
- package/src/requests/WriteBundleRequest.ts +177 -13
- package/src/requests/WriteBundlesRequest.ts +25 -13
- package/src/resolveOptions.ts +2 -4
- package/src/types.ts +1 -0
- package/test/AssetGraph.test.ts +0 -32
- package/test/RequestTracker.test.ts +0 -165
- package/test/TargetRequest.test.ts +25 -0
- package/test/requests/WriteBundleRequest.test.ts +239 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -37,9 +37,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = createWriteBundleRequest;
|
|
40
|
+
exports.applyReplacementsToSourceMap = applyReplacementsToSourceMap;
|
|
41
|
+
exports.computeSourceMapRoot = computeSourceMapRoot;
|
|
40
42
|
const constants_1 = require("../constants");
|
|
41
43
|
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
42
44
|
const path_1 = __importDefault(require("path"));
|
|
45
|
+
const url_1 = __importDefault(require("url"));
|
|
43
46
|
const Bundle_1 = require("../public/Bundle");
|
|
44
47
|
const utils_1 = require("@atlaspack/utils");
|
|
45
48
|
const stream_1 = require("stream");
|
|
@@ -53,8 +56,10 @@ const profiler_1 = require("@atlaspack/profiler");
|
|
|
53
56
|
const RequestTracker_1 = require("../RequestTracker");
|
|
54
57
|
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
55
58
|
const EnvironmentManager_1 = require("../EnvironmentManager");
|
|
59
|
+
const source_map_1 = __importDefault(require("@atlaspack/source-map"));
|
|
56
60
|
const HASH_REF_PREFIX_LEN = constants_1.HASH_REF_PREFIX.length;
|
|
57
61
|
const BOUNDARY_LENGTH = constants_1.HASH_REF_PREFIX.length + 32 - 1;
|
|
62
|
+
const HASH_REF_PLACEHOLDER_LEN = HASH_REF_PREFIX_LEN + constants_1.HASH_REF_HASH_LEN;
|
|
58
63
|
/**
|
|
59
64
|
* Writes a bundle to the dist directory, replacing hash references with the final content hashes.
|
|
60
65
|
*/
|
|
@@ -125,15 +130,37 @@ async function run({ input, options, api }) {
|
|
|
125
130
|
let config = (0, AtlaspackConfigRequest_1.getCachedAtlaspackConfig)(configResult, options);
|
|
126
131
|
let { devDeps, invalidDevDeps } = await (0, DevDepRequest_1.getDevDepRequests)(api);
|
|
127
132
|
(0, DevDepRequest_1.invalidateDevDeps)(invalidDevDeps, options, config);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
const bundleReplacements = (0, feature_flags_1.getFeatureFlag)('fixSourceMapHashRefs')
|
|
134
|
+
? []
|
|
135
|
+
: undefined;
|
|
136
|
+
await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements);
|
|
137
|
+
const hasSourceMap = await options.cache.has(mapKey);
|
|
132
138
|
if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
let mapStream;
|
|
140
|
+
if ((0, feature_flags_1.getFeatureFlag)('fixSourceMapHashRefs') &&
|
|
141
|
+
bundleReplacements &&
|
|
142
|
+
bundleReplacements.length > 0) {
|
|
143
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
144
|
+
const mapBuffer = Buffer.isBuffer(mapEntry)
|
|
145
|
+
? mapEntry
|
|
146
|
+
: Buffer.from(mapEntry);
|
|
147
|
+
const projectRoot = typeof options.projectRoot === 'string'
|
|
148
|
+
? options.projectRoot
|
|
149
|
+
: String(options.projectRoot);
|
|
150
|
+
const sourceMap = new source_map_1.default(projectRoot, mapBuffer);
|
|
151
|
+
applyReplacementsToSourceMap(sourceMap, bundleReplacements);
|
|
152
|
+
const mapJson = await sourceMap.stringify({
|
|
153
|
+
format: 'string',
|
|
154
|
+
file: name,
|
|
155
|
+
sourceRoot: computeSourceMapRoot(bundle, options),
|
|
156
|
+
});
|
|
157
|
+
mapStream = (0, utils_1.blobToStream)(Buffer.from(typeof mapJson === 'string' ? mapJson : JSON.stringify(mapJson), 'utf8'));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
161
|
+
mapStream = (0, utils_1.blobToStream)(mapEntry);
|
|
162
|
+
}
|
|
163
|
+
await writeFiles(mapStream, info, hashRefToNameHash, options, config, outputFS, (0, projectPath_1.toProjectPathUnsafe)((0, projectPath_1.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
|
|
137
164
|
}
|
|
138
165
|
let res = {
|
|
139
166
|
filePath,
|
|
@@ -147,13 +174,75 @@ async function run({ input, options, api }) {
|
|
|
147
174
|
api.storeResult(res);
|
|
148
175
|
return res;
|
|
149
176
|
}
|
|
177
|
+
function applyReplacementsToSourceMap(sourceMap, replacements) {
|
|
178
|
+
if (replacements.length === 0)
|
|
179
|
+
return;
|
|
180
|
+
const sorted = [...replacements].sort((a, b) => a.line - b.line || a.column - b.column);
|
|
181
|
+
for (const r of sorted) {
|
|
182
|
+
const delta = r.newLength - r.originalLength;
|
|
183
|
+
if (delta !== 0) {
|
|
184
|
+
// r.column is in post-replacement coordinates (matching the already-shifted
|
|
185
|
+
// source map state after previous offsetColumns calls). The end of the
|
|
186
|
+
// placeholder in these coordinates is simply r.column + r.originalLength.
|
|
187
|
+
const offsetStartColumn = r.column + r.originalLength;
|
|
188
|
+
const line1Based = r.line + 1;
|
|
189
|
+
if (line1Based >= 1 && offsetStartColumn + delta >= 0) {
|
|
190
|
+
sourceMap.offsetColumns(line1Based, offsetStartColumn, delta);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Computes the sourceRoot for a source map file. This is the relative path from
|
|
197
|
+
* the output directory back to the project root, so that source paths (stored
|
|
198
|
+
* relative to projectRoot) resolve correctly from the .map file location.
|
|
199
|
+
*
|
|
200
|
+
* Returns undefined when sources are inlined (inlineSources), since the browser
|
|
201
|
+
* doesn't need to fetch them and sourceRoot would be unnecessary.
|
|
202
|
+
*
|
|
203
|
+
* This logic must stay in sync with PackagerRunner.generateSourceMap.
|
|
204
|
+
*/
|
|
205
|
+
function computeSourceMapRoot(bundle, options) {
|
|
206
|
+
let name = (0, nullthrows_1.default)(bundle.name);
|
|
207
|
+
let filePath = (0, projectPath_1.joinProjectPath)(bundle.target.distDir, name);
|
|
208
|
+
let fullPath = (0, projectPath_1.fromProjectPath)(options.projectRoot, filePath);
|
|
209
|
+
let sourceRoot = path_1.default.relative(path_1.default.dirname(fullPath), options.projectRoot);
|
|
210
|
+
let inlineSources = false;
|
|
211
|
+
const bundleEnv = (0, EnvironmentManager_1.fromEnvironmentId)(bundle.env);
|
|
212
|
+
if (bundle.target) {
|
|
213
|
+
const bundleTargetEnv = (0, EnvironmentManager_1.fromEnvironmentId)(bundle.target.env);
|
|
214
|
+
if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
|
|
215
|
+
sourceRoot = bundleEnv.sourceMap.sourceRoot;
|
|
216
|
+
}
|
|
217
|
+
else if (options.serveOptions && bundleTargetEnv.context === 'browser') {
|
|
218
|
+
sourceRoot = '/__parcel_source_root';
|
|
219
|
+
}
|
|
220
|
+
if (bundleEnv.sourceMap &&
|
|
221
|
+
bundleEnv.sourceMap.inlineSources !== undefined) {
|
|
222
|
+
inlineSources = bundleEnv.sourceMap.inlineSources;
|
|
223
|
+
}
|
|
224
|
+
else if (bundleTargetEnv.context !== 'node') {
|
|
225
|
+
inlineSources = options.mode === 'production';
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
|
|
229
|
+
if ((0, feature_flags_1.getFeatureFlag)('omitSourcesContentInMemory') && !isInlineMap) {
|
|
230
|
+
if (!(bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources === false)) {
|
|
231
|
+
inlineSources = true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (inlineSources) {
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
return url_1.default.format(url_1.default.parse(sourceRoot + '/'));
|
|
238
|
+
}
|
|
150
239
|
async function writeFiles(
|
|
151
240
|
// @ts-expect-error TS2503
|
|
152
|
-
inputStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api) {
|
|
241
|
+
inputStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements) {
|
|
153
242
|
let compressors = await config.getCompressors((0, projectPath_1.fromProjectPathRelative)(filePath));
|
|
154
243
|
let fullPath = (0, projectPath_1.fromProjectPath)(options.projectRoot, filePath);
|
|
155
244
|
let stream = info.hashReferences.length
|
|
156
|
-
? inputStream.pipe(replaceStream(hashRefToNameHash))
|
|
245
|
+
? inputStream.pipe(replaceStream(hashRefToNameHash, bundleReplacements))
|
|
157
246
|
: inputStream;
|
|
158
247
|
let promises = [];
|
|
159
248
|
for (let compressor of compressors) {
|
|
@@ -202,9 +291,23 @@ stream, options, outputFS, filePath, writeOptions, devDeps, api) {
|
|
|
202
291
|
await (0, DevDepRequest_1.runDevDepRequest)(api, devDepRequest);
|
|
203
292
|
}
|
|
204
293
|
}
|
|
205
|
-
function
|
|
294
|
+
function advanceLineColumn(line, column, buf) {
|
|
295
|
+
for (let i = 0; i < buf.length; i++) {
|
|
296
|
+
if (buf[i] === 0x0a) {
|
|
297
|
+
line++;
|
|
298
|
+
column = 0;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
column++;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return { line, column };
|
|
305
|
+
}
|
|
306
|
+
function replaceStream(hashRefToNameHash, replacements) {
|
|
206
307
|
let boundaryStr = Buffer.alloc(0);
|
|
207
308
|
let replaced = Buffer.alloc(0);
|
|
309
|
+
let outputLine = 0;
|
|
310
|
+
let outputColumn = 0;
|
|
208
311
|
return new stream_1.Transform({
|
|
209
312
|
transform(chunk, encoding, cb) {
|
|
210
313
|
let str = Buffer.concat([boundaryStr, Buffer.from(chunk)]);
|
|
@@ -225,15 +328,29 @@ function replaceStream(hashRefToNameHash) {
|
|
|
225
328
|
.subarray(matchI, matchI + HASH_REF_PREFIX_LEN + constants_1.HASH_REF_HASH_LEN)
|
|
226
329
|
.toString();
|
|
227
330
|
let replacement = Buffer.from(hashRefToNameHash.get(match) ?? match);
|
|
331
|
+
// Copy pre-match content FIRST so position calculation includes it
|
|
228
332
|
replaced.set(str.subarray(lastMatchI, matchI), replacedLength);
|
|
229
333
|
replacedLength += matchI - lastMatchI;
|
|
334
|
+
if (replacements) {
|
|
335
|
+
const pos = advanceLineColumn(outputLine, outputColumn, replaced.subarray(0, replacedLength));
|
|
336
|
+
replacements.push({
|
|
337
|
+
line: pos.line,
|
|
338
|
+
column: pos.column,
|
|
339
|
+
originalLength: HASH_REF_PLACEHOLDER_LEN,
|
|
340
|
+
newLength: replacement.byteLength,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
230
343
|
replaced.set(replacement, replacedLength);
|
|
231
344
|
replacedLength += replacement.byteLength;
|
|
232
345
|
lastMatchI = matchI + HASH_REF_PREFIX_LEN + constants_1.HASH_REF_HASH_LEN;
|
|
233
346
|
}
|
|
234
347
|
}
|
|
348
|
+
const pushLen = replacedLength - BOUNDARY_LENGTH;
|
|
349
|
+
const pushed = advanceLineColumn(outputLine, outputColumn, replaced.subarray(0, pushLen));
|
|
350
|
+
outputLine = pushed.line;
|
|
351
|
+
outputColumn = pushed.column;
|
|
235
352
|
boundaryStr = replaced.subarray(replacedLength - BOUNDARY_LENGTH, replacedLength);
|
|
236
|
-
let strUpToBoundary = replaced.subarray(0,
|
|
353
|
+
let strUpToBoundary = replaced.subarray(0, pushLen);
|
|
237
354
|
cb(null, strUpToBoundary);
|
|
238
355
|
},
|
|
239
356
|
flush(cb) {
|
|
@@ -15,6 +15,14 @@ const rust_1 = require("@atlaspack/rust");
|
|
|
15
15
|
const PackageRequest_1 = require("./PackageRequest");
|
|
16
16
|
const WriteBundleRequest_1 = __importDefault(require("./WriteBundleRequest"));
|
|
17
17
|
const utils_1 = require("@atlaspack/utils");
|
|
18
|
+
/** Length of the hash suffix in output filenames (e.g. .runtime.13dc01ac.js). */
|
|
19
|
+
const NAME_HASH_DISPLAY_LEN = 8;
|
|
20
|
+
/** Use at most NAME_HASH_DISPLAY_LEN chars for the name hash so filenames stay short. */
|
|
21
|
+
function nameHashForFilename(hash) {
|
|
22
|
+
return hash.length <= NAME_HASH_DISPLAY_LEN
|
|
23
|
+
? hash
|
|
24
|
+
: hash.slice(-NAME_HASH_DISPLAY_LEN);
|
|
25
|
+
}
|
|
18
26
|
function reportPackagingProgress(completeBundles, totalBundles) {
|
|
19
27
|
if (!(0, feature_flags_1.getFeatureFlag)('cliProgressReportingImprovements')) {
|
|
20
28
|
return;
|
|
@@ -57,9 +65,9 @@ async function run({ input, api, farm, options, }) {
|
|
|
57
65
|
// Do not package and write placeholder bundles to disk. We just
|
|
58
66
|
// need to update the name so other bundles can reference it.
|
|
59
67
|
if (bundle.isPlaceholder) {
|
|
60
|
-
|
|
61
|
-
hashRefToNameHash.set(bundle.hashReference,
|
|
62
|
-
let name = (0, nullthrows_1.default)(bundle.name, `Expected ${bundle.type} bundle to have a name`).replace(bundle.hashReference,
|
|
68
|
+
const nameHash = nameHashForFilename(bundle.id);
|
|
69
|
+
hashRefToNameHash.set(bundle.hashReference, nameHash);
|
|
70
|
+
let name = (0, nullthrows_1.default)(bundle.name, `Expected ${bundle.type} bundle to have a name`).replace(bundle.hashReference, nameHash);
|
|
63
71
|
res.set(bundle.id, {
|
|
64
72
|
filePath: (0, projectPath_1.joinProjectPath)(bundle.target.distDir, name),
|
|
65
73
|
bundleId: bundle.id,
|
|
@@ -106,9 +114,7 @@ async function run({ input, api, farm, options, }) {
|
|
|
106
114
|
}
|
|
107
115
|
bundleInfoMap[bundle.id] = info;
|
|
108
116
|
if (!info.hashReferences.length) {
|
|
109
|
-
hashRefToNameHash.set(bundle.hashReference, options.shouldContentHash
|
|
110
|
-
? info.hash.slice(-8)
|
|
111
|
-
: bundle.id.slice(-8));
|
|
117
|
+
hashRefToNameHash.set(bundle.hashReference, nameHashForFilename(options.shouldContentHash ? info.hash : bundle.id));
|
|
112
118
|
let writeBundleRequest = (0, WriteBundleRequest_1.default)({
|
|
113
119
|
bundle,
|
|
114
120
|
info,
|
|
@@ -162,11 +168,11 @@ function assignComplexNameHashes(hashRefToNameHash, bundles, bundleInfoMap, opti
|
|
|
162
168
|
if (hashRefToNameHash.get(bundle.hashReference) != null) {
|
|
163
169
|
continue;
|
|
164
170
|
}
|
|
165
|
-
hashRefToNameHash.set(bundle.hashReference, options.shouldContentHash
|
|
171
|
+
hashRefToNameHash.set(bundle.hashReference, nameHashForFilename(options.shouldContentHash
|
|
166
172
|
? (0, rust_1.hashString)([...getBundlesIncludedInHash(bundle.id, bundleInfoMap)]
|
|
167
173
|
.map((bundleId) => bundleInfoMap[bundleId].hash)
|
|
168
|
-
.join(':'))
|
|
169
|
-
: bundle.id
|
|
174
|
+
.join(':'))
|
|
175
|
+
: bundle.id));
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
178
|
function getBundlesIncludedInHash(bundleId, bundleInfoMap, included = new Set()) {
|
package/dist/resolveOptions.js
CHANGED
|
@@ -133,10 +133,8 @@ async function resolveOptions(initialOptions) {
|
|
|
133
133
|
return initialOptions.cache;
|
|
134
134
|
}
|
|
135
135
|
const needsRustLmdbCache = (0, feature_flags_1.getFeatureFlag)('atlaspackV3') || (0, feature_flags_1.getFeatureFlag)('nativePackager');
|
|
136
|
-
if (!(
|
|
137
|
-
|
|
138
|
-
return new cache_1.FSCache(outputFS, cacheDir);
|
|
139
|
-
}
|
|
136
|
+
if (!needsRustLmdbCache && !(outputFS instanceof fs_1.NodeFS)) {
|
|
137
|
+
return new cache_1.FSCache(outputFS, cacheDir);
|
|
140
138
|
}
|
|
141
139
|
return new cache_1.LMDBLiteCache(cacheDir);
|
|
142
140
|
}
|
package/lib/AssetGraph.js
CHANGED
|
@@ -108,32 +108,16 @@ function nodeFromEntryFile(entry) {
|
|
|
108
108
|
|
|
109
109
|
// @ts-expect-error TS2417
|
|
110
110
|
class AssetGraph extends _graph().ContentGraph {
|
|
111
|
-
/**
|
|
112
|
-
* Incremented when the asset graph is modified such that it requires a bundling pass.
|
|
113
|
-
*/
|
|
114
|
-
#bundlingVersion = 0;
|
|
115
|
-
/**
|
|
116
|
-
* Force incremental bundling to be disabled.
|
|
117
|
-
*/
|
|
118
|
-
#disableIncrementalBundling = false;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @deprecated
|
|
122
|
-
*/
|
|
123
111
|
safeToIncrementallyBundle = true;
|
|
124
112
|
constructor(opts) {
|
|
125
113
|
if (opts) {
|
|
126
114
|
let {
|
|
127
115
|
hash,
|
|
128
|
-
bundlingVersion,
|
|
129
|
-
disableIncrementalBundling,
|
|
130
116
|
...rest
|
|
131
117
|
} = opts;
|
|
132
118
|
// @ts-expect-error TS2345
|
|
133
119
|
super(rest);
|
|
134
120
|
this.hash = hash;
|
|
135
|
-
this.#bundlingVersion = bundlingVersion ?? 0;
|
|
136
|
-
this.#disableIncrementalBundling = disableIncrementalBundling ?? false;
|
|
137
121
|
} else {
|
|
138
122
|
super();
|
|
139
123
|
this.setRootNodeId(this.addNode({
|
|
@@ -151,57 +135,16 @@ class AssetGraph extends _graph().ContentGraph {
|
|
|
151
135
|
serialize() {
|
|
152
136
|
return {
|
|
153
137
|
...super.serialize(),
|
|
154
|
-
bundlingVersion: this.#bundlingVersion,
|
|
155
|
-
disableIncrementalBundling: this.#disableIncrementalBundling,
|
|
156
138
|
hash: this.hash
|
|
157
139
|
};
|
|
158
140
|
}
|
|
159
141
|
|
|
160
142
|
/**
|
|
161
|
-
*
|
|
162
|
-
*/
|
|
163
|
-
setDisableIncrementalBundling(disable) {
|
|
164
|
-
this.#disableIncrementalBundling = disable;
|
|
165
|
-
}
|
|
166
|
-
testing_getDisableIncrementalBundling() {
|
|
167
|
-
return this.#disableIncrementalBundling;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Make sure this asset graph is marked as needing a full bundling pass.
|
|
172
|
-
*/
|
|
173
|
-
setNeedsBundling() {
|
|
174
|
-
if (!(0, _featureFlags().getFeatureFlag)('incrementalBundlingVersioning')) {
|
|
175
|
-
// In legacy mode, we rely solely on safeToIncrementallyBundle to
|
|
176
|
-
// invalidate incremental bundling, so we skip bumping the version.
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
this.#bundlingVersion += 1;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Get the current bundling version.
|
|
184
|
-
*
|
|
185
|
-
* Each bundle pass should keep this version around. Whenever an asset graph has a new version,
|
|
186
|
-
* bundling should be re-run.
|
|
187
|
-
*/
|
|
188
|
-
getBundlingVersion() {
|
|
189
|
-
if (!(0, _featureFlags().getFeatureFlag)('incrementalBundlingVersioning')) {
|
|
190
|
-
return 0;
|
|
191
|
-
}
|
|
192
|
-
return this.#bundlingVersion;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* If the `bundlingVersion` has not changed since the last bundling pass,
|
|
197
|
-
* we can incrementally bundle, which will not require a full bundling pass
|
|
143
|
+
* Determine if we can incrementally bundle, which will not require a full bundling pass
|
|
198
144
|
* but just update assets into the bundle graph output.
|
|
199
145
|
*/
|
|
200
|
-
canIncrementallyBundle(
|
|
201
|
-
|
|
202
|
-
return this.safeToIncrementallyBundle && !this.#disableIncrementalBundling;
|
|
203
|
-
}
|
|
204
|
-
return this.safeToIncrementallyBundle && this.#bundlingVersion === lastVersion && !this.#disableIncrementalBundling;
|
|
146
|
+
canIncrementallyBundle() {
|
|
147
|
+
return this.safeToIncrementallyBundle;
|
|
205
148
|
}
|
|
206
149
|
|
|
207
150
|
// Deduplicates Environments by making them referentially equal
|
|
@@ -381,13 +324,11 @@ class AssetGraph extends _graph().ContentGraph {
|
|
|
381
324
|
// @ts-expect-error TS2339
|
|
382
325
|
if (!(ctx !== null && ctx !== void 0 && ctx.hasDeferred)) {
|
|
383
326
|
this.safeToIncrementallyBundle = false;
|
|
384
|
-
this.setNeedsBundling();
|
|
385
327
|
delete traversedNode.hasDeferred;
|
|
386
328
|
}
|
|
387
329
|
actions.skipChildren();
|
|
388
330
|
} else if (traversedNode.type === 'dependency') {
|
|
389
331
|
this.safeToIncrementallyBundle = false;
|
|
390
|
-
this.setNeedsBundling();
|
|
391
332
|
traversedNode.hasDeferred = false;
|
|
392
333
|
} else if (nodeId !== traversedNodeId) {
|
|
393
334
|
actions.skipChildren();
|
package/lib/BundleGraph.js
CHANGED
|
@@ -516,6 +516,44 @@ class BundleGraph {
|
|
|
516
516
|
};
|
|
517
517
|
}
|
|
518
518
|
|
|
519
|
+
/**
|
|
520
|
+
* Serialize only the given asset nodes for native incremental update.
|
|
521
|
+
* Same node shape and env/omit logic as serializeForNative.
|
|
522
|
+
*/
|
|
523
|
+
serializeAssetNodesForNative(assetIds) {
|
|
524
|
+
const start = performance.now();
|
|
525
|
+
if (assetIds.length === 0) {
|
|
526
|
+
return '[]';
|
|
527
|
+
}
|
|
528
|
+
const nodes = [];
|
|
529
|
+
for (const assetId of assetIds) {
|
|
530
|
+
var _node$value4;
|
|
531
|
+
const node = this._graph.getNodeByContentKey(assetId);
|
|
532
|
+
if ((node === null || node === void 0 ? void 0 : node.type) !== 'asset') {
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
const processedNode = {
|
|
536
|
+
...node
|
|
537
|
+
};
|
|
538
|
+
if ((_node$value4 = node.value) !== null && _node$value4 !== void 0 && _node$value4.env) {
|
|
539
|
+
processedNode.value = {
|
|
540
|
+
...node.value,
|
|
541
|
+
env: (0, _EnvironmentManager.fromEnvironmentId)(node.value.env).id
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
nodes.push(processedNode);
|
|
545
|
+
}
|
|
546
|
+
const optimizedNodes = nodes.map(node => this._omitNulls(node));
|
|
547
|
+
const nodesJson = JSON.stringify(optimizedNodes);
|
|
548
|
+
const duration = performance.now() - start;
|
|
549
|
+
const nodesSizeMB = (nodesJson.length / (1024 * 1024)).toFixed(2);
|
|
550
|
+
_logger().default.verbose({
|
|
551
|
+
origin: '@atlaspack/core',
|
|
552
|
+
message: `serializeAssetNodesForNative: ${duration.toFixed(1)}ms, ${nodesSizeMB}MB nodes, ${nodes.length} nodes`
|
|
553
|
+
});
|
|
554
|
+
return nodesJson;
|
|
555
|
+
}
|
|
556
|
+
|
|
519
557
|
/**
|
|
520
558
|
* Remove null and undefined values from an object to reduce JSON size.
|
|
521
559
|
* Preserves false, 0, empty strings, and arrays.
|
package/lib/PackagerRunner.js
CHANGED
|
@@ -60,13 +60,6 @@ function _path() {
|
|
|
60
60
|
};
|
|
61
61
|
return data;
|
|
62
62
|
}
|
|
63
|
-
function _url() {
|
|
64
|
-
const data = _interopRequireDefault(require("url"));
|
|
65
|
-
_url = function () {
|
|
66
|
-
return data;
|
|
67
|
-
};
|
|
68
|
-
return data;
|
|
69
|
-
}
|
|
70
63
|
function _rust() {
|
|
71
64
|
const data = require("@atlaspack/rust");
|
|
72
65
|
_rust = function () {
|
|
@@ -85,6 +78,7 @@ var _ConfigRequest = require("./requests/ConfigRequest");
|
|
|
85
78
|
var _DevDepRequest = require("./requests/DevDepRequest");
|
|
86
79
|
var _assetUtils = require("./assetUtils");
|
|
87
80
|
var _utils2 = require("./utils");
|
|
81
|
+
var _WriteBundleRequest = require("./requests/WriteBundleRequest");
|
|
88
82
|
function _profiler() {
|
|
89
83
|
const data = require("@atlaspack/profiler");
|
|
90
84
|
_profiler = function () {
|
|
@@ -93,13 +87,6 @@ function _profiler() {
|
|
|
93
87
|
return data;
|
|
94
88
|
}
|
|
95
89
|
var _EnvironmentManager = require("./EnvironmentManager");
|
|
96
|
-
function _featureFlags() {
|
|
97
|
-
const data = require("@atlaspack/feature-flags");
|
|
98
|
-
_featureFlags = function () {
|
|
99
|
-
return data;
|
|
100
|
-
};
|
|
101
|
-
return data;
|
|
102
|
-
}
|
|
103
90
|
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); }
|
|
104
91
|
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; }
|
|
105
92
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -407,42 +394,18 @@ class PackagerRunner {
|
|
|
407
394
|
return optimized;
|
|
408
395
|
}
|
|
409
396
|
async generateSourceMap(bundle, map) {
|
|
410
|
-
|
|
397
|
+
let sourceRoot = (0, _WriteBundleRequest.computeSourceMapRoot)(bundle, this.options);
|
|
398
|
+
let inlineSources = sourceRoot === undefined;
|
|
411
399
|
let filePath = (0, _projectPath.joinProjectPath)(bundle.target.distDir, (0, _nullthrows().default)(bundle.name));
|
|
412
400
|
let fullPath = (0, _projectPath.fromProjectPath)(this.options.projectRoot, filePath);
|
|
413
|
-
let sourceRoot = _path().default.relative(_path().default.dirname(fullPath), this.options.projectRoot);
|
|
414
|
-
let inlineSources = false;
|
|
415
|
-
const bundleEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
|
|
416
|
-
if (bundle.target) {
|
|
417
|
-
const bundleTargetEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.target.env);
|
|
418
|
-
if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
|
|
419
|
-
sourceRoot = bundleEnv.sourceMap.sourceRoot;
|
|
420
|
-
} else if (this.options.serveOptions && bundleTargetEnv.context === 'browser') {
|
|
421
|
-
sourceRoot = '/__parcel_source_root';
|
|
422
|
-
}
|
|
423
|
-
if (bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources !== undefined) {
|
|
424
|
-
inlineSources = bundleEnv.sourceMap.inlineSources;
|
|
425
|
-
} else if (bundleTargetEnv.context !== 'node') {
|
|
426
|
-
// inlining should only happen in production for browser targets by default
|
|
427
|
-
inlineSources = this.options.mode === 'production';
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
401
|
let mapFilename = fullPath + '.map';
|
|
402
|
+
const bundleEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
|
|
431
403
|
let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
|
|
432
|
-
if ((0, _featureFlags().getFeatureFlag)('omitSourcesContentInMemory') && !isInlineMap) {
|
|
433
|
-
if (!(bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources === false)) {
|
|
434
|
-
/*
|
|
435
|
-
We're omitting sourcesContent during transformation to allow GC to run.
|
|
436
|
-
Ensure sources are still inlined into the final source maps written to disk. UNLESS the user explicitly disabled inlineSources.
|
|
437
|
-
*/
|
|
438
|
-
inlineSources = true;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
404
|
let stringified = await map.stringify({
|
|
442
405
|
file: _path().default.basename(mapFilename),
|
|
443
406
|
fs: this.options.inputFS,
|
|
444
407
|
rootDir: this.options.projectRoot,
|
|
445
|
-
sourceRoot
|
|
408
|
+
sourceRoot,
|
|
446
409
|
inlineSources,
|
|
447
410
|
format: isInlineMap ? 'inline' : 'string'
|
|
448
411
|
});
|
|
@@ -467,10 +430,6 @@ class PackagerRunner {
|
|
|
467
430
|
devDepHashes += await this.getDevDepHashes(inlineBundle);
|
|
468
431
|
}
|
|
469
432
|
let invalidationHash = await (0, _assetUtils.getInvalidationHash)(invalidations, this.options);
|
|
470
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
471
|
-
const hash = (0, _rust().hashString)(_constants.ATLASPACK_VERSION + devDepHashes + invalidationHash + bundle.target.publicUrl + bundleGraph.getHash(bundle) + JSON.stringify(configResults) + JSON.stringify(globalInfoResults) + this.options.mode + (this.options.shouldBuildLazily ? 'lazy' : 'eager'));
|
|
472
|
-
return _path().default.join(bundle.displayName ?? bundle.name ?? bundle.id, hash);
|
|
473
|
-
}
|
|
474
433
|
return (0, _rust().hashString)(_constants.ATLASPACK_VERSION + devDepHashes + invalidationHash + bundle.target.publicUrl + bundleGraph.getHash(bundle) + JSON.stringify(configResults) + JSON.stringify(globalInfoResults) + this.options.mode + (this.options.shouldBuildLazily ? 'lazy' : 'eager'));
|
|
475
434
|
}
|
|
476
435
|
async getDevDepHashes(bundle) {
|
|
@@ -494,14 +453,14 @@ class PackagerRunner {
|
|
|
494
453
|
let contentKey = PackagerRunner.getContentKey(cacheKey);
|
|
495
454
|
let mapKey = PackagerRunner.getMapKey(cacheKey);
|
|
496
455
|
let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
|
|
497
|
-
let contentExists =
|
|
456
|
+
let contentExists = isLargeBlob || (await this.options.cache.has(contentKey));
|
|
498
457
|
if (!contentExists) {
|
|
499
458
|
return null;
|
|
500
459
|
}
|
|
501
|
-
let mapExists =
|
|
460
|
+
let mapExists = await this.options.cache.has(mapKey);
|
|
502
461
|
return {
|
|
503
462
|
contents: isLargeBlob ? this.options.cache.getStream(contentKey) : (0, _utils().blobToStream)(await this.options.cache.getBlob(contentKey)),
|
|
504
|
-
map: mapExists ? (0, _utils().blobToStream)(
|
|
463
|
+
map: mapExists ? (0, _utils().blobToStream)(await this.options.cache.getBlob(mapKey)) : null
|
|
505
464
|
};
|
|
506
465
|
}
|
|
507
466
|
async writeToCache(cacheKeys, type, contents, map) {
|
|
@@ -509,13 +468,11 @@ class PackagerRunner {
|
|
|
509
468
|
let hash;
|
|
510
469
|
// @ts-expect-error TS2702
|
|
511
470
|
let hashReferences = [];
|
|
512
|
-
let isLargeBlob =
|
|
471
|
+
let isLargeBlob = false;
|
|
513
472
|
|
|
514
473
|
// TODO: don't replace hash references in binary files??
|
|
515
474
|
if (contents instanceof _stream().Readable) {
|
|
516
|
-
|
|
517
|
-
isLargeBlob = true;
|
|
518
|
-
}
|
|
475
|
+
isLargeBlob = true;
|
|
519
476
|
let boundaryStr = '';
|
|
520
477
|
let h = new (_rust().Hash)();
|
|
521
478
|
await this.options.cache.setStream(cacheKeys.content, (0, _utils().blobToStream)(contents).pipe(
|
|
@@ -533,27 +490,15 @@ class PackagerRunner {
|
|
|
533
490
|
size = buffer.byteLength;
|
|
534
491
|
hash = (0, _rust().hashBuffer)(buffer);
|
|
535
492
|
hashReferences = contents.match(_constants.HASH_REF_REGEX) ?? [];
|
|
536
|
-
|
|
537
|
-
await this.options.cache.setLargeBlob(cacheKeys.content, buffer);
|
|
538
|
-
} else {
|
|
539
|
-
await this.options.cache.setBlob(cacheKeys.content, buffer);
|
|
540
|
-
}
|
|
493
|
+
await this.options.cache.setBlob(cacheKeys.content, buffer);
|
|
541
494
|
} else {
|
|
542
495
|
size = contents.length;
|
|
543
496
|
hash = (0, _rust().hashBuffer)(contents);
|
|
544
497
|
hashReferences = contents.toString().match(_constants.HASH_REF_REGEX) ?? [];
|
|
545
|
-
|
|
546
|
-
await this.options.cache.setLargeBlob(cacheKeys.content, contents);
|
|
547
|
-
} else {
|
|
548
|
-
await this.options.cache.setBlob(cacheKeys.content, contents);
|
|
549
|
-
}
|
|
498
|
+
await this.options.cache.setBlob(cacheKeys.content, contents);
|
|
550
499
|
}
|
|
551
500
|
if (map != null) {
|
|
552
|
-
|
|
553
|
-
await this.options.cache.setLargeBlob(cacheKeys.map, map);
|
|
554
|
-
} else {
|
|
555
|
-
await this.options.cache.setBlob(cacheKeys.map, map);
|
|
556
|
-
}
|
|
501
|
+
await this.options.cache.setBlob(cacheKeys.map, map);
|
|
557
502
|
}
|
|
558
503
|
let info = {
|
|
559
504
|
type,
|
|
@@ -567,21 +512,12 @@ class PackagerRunner {
|
|
|
567
512
|
return info;
|
|
568
513
|
}
|
|
569
514
|
static getContentKey(cacheKey) {
|
|
570
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
571
|
-
return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/content`;
|
|
572
|
-
}
|
|
573
515
|
return (0, _rust().hashString)(`${cacheKey}:content`);
|
|
574
516
|
}
|
|
575
517
|
static getMapKey(cacheKey) {
|
|
576
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
577
|
-
return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/map`;
|
|
578
|
-
}
|
|
579
518
|
return (0, _rust().hashString)(`${cacheKey}:map`);
|
|
580
519
|
}
|
|
581
520
|
static getInfoKey(cacheKey) {
|
|
582
|
-
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
583
|
-
return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/info`;
|
|
584
|
-
}
|
|
585
521
|
return (0, _rust().hashString)(`${cacheKey}:info`);
|
|
586
522
|
}
|
|
587
523
|
}
|