@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.
Files changed (68) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/dist/AssetGraph.js +4 -72
  3. package/dist/BundleGraph.js +34 -0
  4. package/dist/PackagerRunner.js +13 -88
  5. package/dist/RequestTracker.js +17 -80
  6. package/dist/TargetDescriptor.schema.js +3 -0
  7. package/dist/UncommittedAsset.js +0 -5
  8. package/dist/applyRuntimes.js +2 -1
  9. package/dist/atlaspack-v3/AtlaspackV3.js +6 -2
  10. package/dist/requests/AssetGraphRequest.js +6 -15
  11. package/dist/requests/AssetGraphRequestRust.js +119 -22
  12. package/dist/requests/AtlaspackBuildRequest.js +8 -2
  13. package/dist/requests/BundleGraphRequest.js +9 -15
  14. package/dist/requests/BundleGraphRequestRust.js +1 -2
  15. package/dist/requests/PackageRequest.js +1 -1
  16. package/dist/requests/TargetRequest.js +5 -0
  17. package/dist/requests/WriteBundleRequest.js +129 -12
  18. package/dist/requests/WriteBundlesRequest.js +15 -9
  19. package/dist/resolveOptions.js +2 -4
  20. package/lib/AssetGraph.js +3 -62
  21. package/lib/BundleGraph.js +38 -0
  22. package/lib/PackagerRunner.js +13 -77
  23. package/lib/RequestTracker.js +15 -69
  24. package/lib/TargetDescriptor.schema.js +3 -0
  25. package/lib/UncommittedAsset.js +0 -11
  26. package/lib/applyRuntimes.js +1 -1
  27. package/lib/atlaspack-v3/AtlaspackV3.js +6 -2
  28. package/lib/requests/AssetGraphRequest.js +4 -18
  29. package/lib/requests/AssetGraphRequestRust.js +88 -23
  30. package/lib/requests/AtlaspackBuildRequest.js +8 -2
  31. package/lib/requests/BundleGraphRequest.js +12 -16
  32. package/lib/requests/BundleGraphRequestRust.js +2 -3
  33. package/lib/requests/PackageRequest.js +3 -1
  34. package/lib/requests/TargetRequest.js +5 -0
  35. package/lib/requests/WriteBundleRequest.js +131 -8
  36. package/lib/requests/WriteBundlesRequest.js +12 -5
  37. package/lib/resolveOptions.js +2 -4
  38. package/lib/types/AssetGraph.d.ts +2 -27
  39. package/lib/types/BundleGraph.d.ts +5 -0
  40. package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +3 -2
  41. package/lib/types/requests/BundleGraphRequest.d.ts +1 -1
  42. package/lib/types/requests/WriteBundleRequest.d.ts +20 -1
  43. package/lib/types/types.d.ts +1 -0
  44. package/package.json +15 -15
  45. package/src/AssetGraph.ts +4 -72
  46. package/src/BundleGraph.ts +39 -0
  47. package/src/PackagerRunner.ts +15 -101
  48. package/src/RequestTracker.ts +24 -110
  49. package/src/TargetDescriptor.schema.ts +3 -0
  50. package/src/UncommittedAsset.ts +1 -11
  51. package/src/applyRuntimes.ts +3 -1
  52. package/src/atlaspack-v3/AtlaspackV3.ts +19 -3
  53. package/src/requests/AssetGraphRequest.ts +8 -20
  54. package/src/requests/AssetGraphRequestRust.ts +96 -23
  55. package/src/requests/AtlaspackBuildRequest.ts +16 -8
  56. package/src/requests/BundleGraphRequest.ts +12 -30
  57. package/src/requests/BundleGraphRequestRust.ts +1 -2
  58. package/src/requests/PackageRequest.ts +1 -1
  59. package/src/requests/TargetRequest.ts +5 -0
  60. package/src/requests/WriteBundleRequest.ts +177 -13
  61. package/src/requests/WriteBundlesRequest.ts +25 -13
  62. package/src/resolveOptions.ts +2 -4
  63. package/src/types.ts +1 -0
  64. package/test/AssetGraph.test.ts +0 -32
  65. package/test/RequestTracker.test.ts +0 -165
  66. package/test/TargetRequest.test.ts +25 -0
  67. package/test/requests/WriteBundleRequest.test.ts +239 -0
  68. package/tsconfig.tsbuildinfo +1 -1
@@ -13,6 +13,7 @@ import type {ProjectPath} from '../projectPath';
13
13
  import {HASH_REF_HASH_LEN, HASH_REF_PREFIX} from '../constants';
14
14
  import nullthrows from 'nullthrows';
15
15
  import path from 'path';
16
+ import url from 'url';
16
17
  import {NamedBundle} from '../public/Bundle';
17
18
  import {blobToStream, TapStream} from '@atlaspack/utils';
18
19
  import {Readable, Transform, pipeline} from 'stream';
@@ -40,9 +41,18 @@ import {PluginTracer, tracer} from '@atlaspack/profiler';
40
41
  import {requestTypes} from '../RequestTracker';
41
42
  import {getFeatureFlag} from '@atlaspack/feature-flags';
42
43
  import {fromEnvironmentId} from '../EnvironmentManager';
44
+ import SourceMap from '@atlaspack/source-map';
43
45
 
44
46
  const HASH_REF_PREFIX_LEN = HASH_REF_PREFIX.length;
45
47
  const BOUNDARY_LENGTH = HASH_REF_PREFIX.length + 32 - 1;
48
+ const HASH_REF_PLACEHOLDER_LEN = HASH_REF_PREFIX_LEN + HASH_REF_HASH_LEN;
49
+
50
+ export type HashRefReplacement = {
51
+ line: number;
52
+ column: number;
53
+ originalLength: number;
54
+ newLength: number;
55
+ };
46
56
 
47
57
  type WriteBundleRequestInput = {
48
58
  bundleGraph: BundleGraph;
@@ -158,6 +168,9 @@ async function run({input, options, api}) {
158
168
  let {devDeps, invalidDevDeps} = await getDevDepRequests(api);
159
169
  invalidateDevDeps(invalidDevDeps, options, config);
160
170
 
171
+ const bundleReplacements = getFeatureFlag('fixSourceMapHashRefs')
172
+ ? []
173
+ : undefined;
161
174
  await writeFiles(
162
175
  contentStream,
163
176
  info,
@@ -169,17 +182,44 @@ async function run({input, options, api}) {
169
182
  writeOptions,
170
183
  devDeps,
171
184
  api,
185
+ bundleReplacements,
172
186
  );
173
187
 
174
- const hasSourceMap = getFeatureFlag('cachePerformanceImprovements')
175
- ? await options.cache.hasLargeBlob(mapKey)
176
- : await options.cache.has(mapKey);
188
+ const hasSourceMap = await options.cache.has(mapKey);
177
189
  if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
178
- const mapEntry = getFeatureFlag('cachePerformanceImprovements')
179
- ? await options.cache.getLargeBlob(mapKey)
180
- : await options.cache.getBlob(mapKey);
190
+ let mapStream: Readable;
191
+ if (
192
+ getFeatureFlag('fixSourceMapHashRefs') &&
193
+ bundleReplacements &&
194
+ bundleReplacements.length > 0
195
+ ) {
196
+ const mapEntry = await options.cache.getBlob(mapKey);
197
+ const mapBuffer = Buffer.isBuffer(mapEntry)
198
+ ? mapEntry
199
+ : Buffer.from(mapEntry);
200
+ const projectRoot =
201
+ typeof options.projectRoot === 'string'
202
+ ? options.projectRoot
203
+ : String(options.projectRoot);
204
+ const sourceMap = new SourceMap(projectRoot, mapBuffer);
205
+ applyReplacementsToSourceMap(sourceMap, bundleReplacements);
206
+ const mapJson = await sourceMap.stringify({
207
+ format: 'string',
208
+ file: name,
209
+ sourceRoot: computeSourceMapRoot(bundle, options),
210
+ });
211
+ mapStream = blobToStream(
212
+ Buffer.from(
213
+ typeof mapJson === 'string' ? mapJson : JSON.stringify(mapJson),
214
+ 'utf8',
215
+ ),
216
+ );
217
+ } else {
218
+ const mapEntry = await options.cache.getBlob(mapKey);
219
+ mapStream = blobToStream(mapEntry);
220
+ }
181
221
  await writeFiles(
182
- blobToStream(mapEntry),
222
+ mapStream,
183
223
  info,
184
224
  hashRefToNameHash,
185
225
  options,
@@ -206,6 +246,88 @@ async function run({input, options, api}) {
206
246
  return res;
207
247
  }
208
248
 
249
+ export function applyReplacementsToSourceMap(
250
+ sourceMap: SourceMap,
251
+ replacements: HashRefReplacement[],
252
+ ): void {
253
+ if (replacements.length === 0) return;
254
+ const sorted = [...replacements].sort(
255
+ (a, b) => a.line - b.line || a.column - b.column,
256
+ );
257
+ for (const r of sorted) {
258
+ const delta = r.newLength - r.originalLength;
259
+ if (delta !== 0) {
260
+ // r.column is in post-replacement coordinates (matching the already-shifted
261
+ // source map state after previous offsetColumns calls). The end of the
262
+ // placeholder in these coordinates is simply r.column + r.originalLength.
263
+ const offsetStartColumn = r.column + r.originalLength;
264
+ const line1Based = r.line + 1;
265
+ if (line1Based >= 1 && offsetStartColumn + delta >= 0) {
266
+ sourceMap.offsetColumns(line1Based, offsetStartColumn, delta);
267
+ }
268
+ }
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Computes the sourceRoot for a source map file. This is the relative path from
274
+ * the output directory back to the project root, so that source paths (stored
275
+ * relative to projectRoot) resolve correctly from the .map file location.
276
+ *
277
+ * Returns undefined when sources are inlined (inlineSources), since the browser
278
+ * doesn't need to fetch them and sourceRoot would be unnecessary.
279
+ *
280
+ * This logic must stay in sync with PackagerRunner.generateSourceMap.
281
+ */
282
+ export function computeSourceMapRoot(
283
+ bundle: Bundle,
284
+ options: AtlaspackOptions,
285
+ ): string | undefined {
286
+ let name = nullthrows(bundle.name);
287
+ let filePath = joinProjectPath(bundle.target.distDir, name);
288
+ let fullPath = fromProjectPath(options.projectRoot, filePath);
289
+ let sourceRoot: string = path.relative(
290
+ path.dirname(fullPath),
291
+ options.projectRoot,
292
+ );
293
+
294
+ let inlineSources = false;
295
+
296
+ const bundleEnv = fromEnvironmentId(bundle.env);
297
+ if (bundle.target) {
298
+ const bundleTargetEnv = fromEnvironmentId(bundle.target.env);
299
+
300
+ if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
301
+ sourceRoot = bundleEnv.sourceMap.sourceRoot;
302
+ } else if (options.serveOptions && bundleTargetEnv.context === 'browser') {
303
+ sourceRoot = '/__parcel_source_root';
304
+ }
305
+
306
+ if (
307
+ bundleEnv.sourceMap &&
308
+ bundleEnv.sourceMap.inlineSources !== undefined
309
+ ) {
310
+ inlineSources = bundleEnv.sourceMap.inlineSources;
311
+ } else if (bundleTargetEnv.context !== 'node') {
312
+ inlineSources = options.mode === 'production';
313
+ }
314
+ }
315
+
316
+ let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
317
+
318
+ if (getFeatureFlag('omitSourcesContentInMemory') && !isInlineMap) {
319
+ if (!(bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources === false)) {
320
+ inlineSources = true;
321
+ }
322
+ }
323
+
324
+ if (inlineSources) {
325
+ return undefined;
326
+ }
327
+
328
+ return url.format(url.parse(sourceRoot + '/'));
329
+ }
330
+
209
331
  async function writeFiles(
210
332
  // @ts-expect-error TS2503
211
333
  inputStream: stream.Readable,
@@ -218,6 +340,7 @@ async function writeFiles(
218
340
  writeOptions: FileOptions | null | undefined,
219
341
  devDeps: Map<string, string>,
220
342
  api: RunAPI<PackagedBundleInfo>,
343
+ bundleReplacements?: HashRefReplacement[],
221
344
  ) {
222
345
  let compressors = await config.getCompressors(
223
346
  fromProjectPathRelative(filePath),
@@ -225,7 +348,7 @@ async function writeFiles(
225
348
  let fullPath = fromProjectPath(options.projectRoot, filePath);
226
349
 
227
350
  let stream = info.hashReferences.length
228
- ? inputStream.pipe(replaceStream(hashRefToNameHash))
351
+ ? inputStream.pipe(replaceStream(hashRefToNameHash, bundleReplacements))
229
352
  : inputStream;
230
353
 
231
354
  let promises: Array<Promise<undefined>> = [];
@@ -314,9 +437,30 @@ async function runCompressor(
314
437
  }
315
438
  }
316
439
 
317
- function replaceStream(hashRefToNameHash: Map<string, string>) {
440
+ function advanceLineColumn(
441
+ line: number,
442
+ column: number,
443
+ buf: Buffer,
444
+ ): {line: number; column: number} {
445
+ for (let i = 0; i < buf.length; i++) {
446
+ if (buf[i] === 0x0a) {
447
+ line++;
448
+ column = 0;
449
+ } else {
450
+ column++;
451
+ }
452
+ }
453
+ return {line, column};
454
+ }
455
+
456
+ function replaceStream(
457
+ hashRefToNameHash: Map<string, string>,
458
+ replacements?: HashRefReplacement[],
459
+ ) {
318
460
  let boundaryStr = Buffer.alloc(0);
319
461
  let replaced = Buffer.alloc(0);
462
+ let outputLine = 0;
463
+ let outputColumn = 0;
320
464
  return new Transform({
321
465
  transform(
322
466
  chunk: Buffer | string,
@@ -347,22 +491,42 @@ function replaceStream(hashRefToNameHash: Map<string, string>) {
347
491
  .subarray(matchI, matchI + HASH_REF_PREFIX_LEN + HASH_REF_HASH_LEN)
348
492
  .toString();
349
493
  let replacement = Buffer.from(hashRefToNameHash.get(match) ?? match);
494
+ // Copy pre-match content FIRST so position calculation includes it
350
495
  replaced.set(str.subarray(lastMatchI, matchI), replacedLength);
351
496
  replacedLength += matchI - lastMatchI;
497
+ if (replacements) {
498
+ const pos = advanceLineColumn(
499
+ outputLine,
500
+ outputColumn,
501
+ replaced.subarray(0, replacedLength),
502
+ );
503
+ replacements.push({
504
+ line: pos.line,
505
+ column: pos.column,
506
+ originalLength: HASH_REF_PLACEHOLDER_LEN,
507
+ newLength: replacement.byteLength,
508
+ });
509
+ }
352
510
  replaced.set(replacement, replacedLength);
353
511
  replacedLength += replacement.byteLength;
354
512
  lastMatchI = matchI + HASH_REF_PREFIX_LEN + HASH_REF_HASH_LEN;
355
513
  }
356
514
  }
357
515
 
516
+ const pushLen = replacedLength - BOUNDARY_LENGTH;
517
+ const pushed = advanceLineColumn(
518
+ outputLine,
519
+ outputColumn,
520
+ replaced.subarray(0, pushLen),
521
+ );
522
+ outputLine = pushed.line;
523
+ outputColumn = pushed.column;
524
+
358
525
  boundaryStr = replaced.subarray(
359
526
  replacedLength - BOUNDARY_LENGTH,
360
527
  replacedLength,
361
528
  );
362
- let strUpToBoundary = replaced.subarray(
363
- 0,
364
- replacedLength - BOUNDARY_LENGTH,
365
- );
529
+ let strUpToBoundary = replaced.subarray(0, pushLen);
366
530
  cb(null, strUpToBoundary);
367
531
  },
368
532
 
@@ -22,6 +22,16 @@ import {createPackageRequest} from './PackageRequest';
22
22
  import createWriteBundleRequest from './WriteBundleRequest';
23
23
  import {debugTools} from '@atlaspack/utils';
24
24
 
25
+ /** Length of the hash suffix in output filenames (e.g. .runtime.13dc01ac.js). */
26
+ const NAME_HASH_DISPLAY_LEN = 8;
27
+
28
+ /** Use at most NAME_HASH_DISPLAY_LEN chars for the name hash so filenames stay short. */
29
+ function nameHashForFilename(hash: string): string {
30
+ return hash.length <= NAME_HASH_DISPLAY_LEN
31
+ ? hash
32
+ : hash.slice(-NAME_HASH_DISPLAY_LEN);
33
+ }
34
+
25
35
  type WriteBundlesRequestInput = {
26
36
  bundleGraph: BundleGraph;
27
37
  optionsRef: SharedReference;
@@ -111,12 +121,12 @@ async function run({
111
121
  // Do not package and write placeholder bundles to disk. We just
112
122
  // need to update the name so other bundles can reference it.
113
123
  if (bundle.isPlaceholder) {
114
- let hash = bundle.id.slice(-8);
115
- hashRefToNameHash.set(bundle.hashReference, hash);
124
+ const nameHash = nameHashForFilename(bundle.id);
125
+ hashRefToNameHash.set(bundle.hashReference, nameHash);
116
126
  let name = nullthrows(
117
127
  bundle.name,
118
128
  `Expected ${bundle.type} bundle to have a name`,
119
- ).replace(bundle.hashReference, hash);
129
+ ).replace(bundle.hashReference, nameHash);
120
130
  res.set(bundle.id, {
121
131
  filePath: joinProjectPath(bundle.target.distDir, name),
122
132
  bundleId: bundle.id,
@@ -178,9 +188,9 @@ async function run({
178
188
  if (!info.hashReferences.length) {
179
189
  hashRefToNameHash.set(
180
190
  bundle.hashReference,
181
- options.shouldContentHash
182
- ? info.hash.slice(-8)
183
- : bundle.id.slice(-8),
191
+ nameHashForFilename(
192
+ options.shouldContentHash ? info.hash : bundle.id,
193
+ ),
184
194
  );
185
195
  let writeBundleRequest = createWriteBundleRequest({
186
196
  bundle,
@@ -256,13 +266,15 @@ function assignComplexNameHashes(
256
266
  }
257
267
  hashRefToNameHash.set(
258
268
  bundle.hashReference,
259
- options.shouldContentHash
260
- ? hashString(
261
- [...getBundlesIncludedInHash(bundle.id, bundleInfoMap)]
262
- .map((bundleId) => bundleInfoMap[bundleId].hash)
263
- .join(':'),
264
- ).slice(-8)
265
- : bundle.id.slice(-8),
269
+ nameHashForFilename(
270
+ options.shouldContentHash
271
+ ? hashString(
272
+ [...getBundlesIncludedInHash(bundle.id, bundleInfoMap)]
273
+ .map((bundleId) => bundleInfoMap[bundleId].hash)
274
+ .join(':'),
275
+ )
276
+ : bundle.id,
277
+ ),
266
278
  );
267
279
  }
268
280
  }
@@ -184,10 +184,8 @@ export default async function resolveOptions(
184
184
  const needsRustLmdbCache =
185
185
  getFeatureFlag('atlaspackV3') || getFeatureFlag('nativePackager');
186
186
 
187
- if (!getFeatureFlag('cachePerformanceImprovements')) {
188
- if (!needsRustLmdbCache && !(outputFS instanceof NodeFS)) {
189
- return new FSCache(outputFS, cacheDir);
190
- }
187
+ if (!needsRustLmdbCache && !(outputFS instanceof NodeFS)) {
188
+ return new FSCache(outputFS, cacheDir);
191
189
  }
192
190
 
193
191
  return new LMDBLiteCache(cacheDir);
package/src/types.ts CHANGED
@@ -112,6 +112,7 @@ export type Target = {
112
112
  loc?: InternalSourceLocation | null | undefined;
113
113
  pipeline?: string;
114
114
  source?: FilePath | Array<FilePath>;
115
+ inlineRequires?: boolean;
115
116
  };
116
117
 
117
118
  export const SpecifierType = {
@@ -687,36 +687,4 @@ describe('AssetGraph', () => {
687
687
  invariant(node.type === 'asset_group');
688
688
  assert(!node.hasDeferred);
689
689
  });
690
-
691
- it('should serialize the bundling version and incremental bundling flag', () => {
692
- const graph = new AssetGraph();
693
- graph.setDisableIncrementalBundling(true);
694
- graph.setNeedsBundling();
695
- const serialized = serialize(graph);
696
- const deserialized = deserialize(serialized);
697
-
698
- assert.equal(deserialized.getBundlingVersion(), 1);
699
- assert.equal(deserialized.testing_getDisableIncrementalBundling(), true);
700
- });
701
-
702
- describe('setNeedsBundling', () => {
703
- it('should increment the bundling version', () => {
704
- const graph = new AssetGraph();
705
- assert.equal(graph.getBundlingVersion(), 0);
706
- graph.setNeedsBundling();
707
- assert.equal(graph.getBundlingVersion(), 1);
708
- graph.setNeedsBundling();
709
- assert.equal(graph.getBundlingVersion(), 2);
710
- });
711
- });
712
-
713
- describe('canIncrementallyBundle', () => {
714
- it('should return true if the bundling version has changed', () => {
715
- const graph = new AssetGraph();
716
- const lastVersion = graph.getBundlingVersion();
717
- assert.equal(graph.canIncrementallyBundle(lastVersion), true);
718
- graph.setNeedsBundling();
719
- assert.equal(graph.canIncrementallyBundle(lastVersion), false);
720
- });
721
- });
722
690
  });
@@ -538,171 +538,6 @@ describe('RequestTracker', () => {
538
538
  });
539
539
  });
540
540
  });
541
-
542
- describe('incremental bundling', () => {
543
- async function runIncrementalBundlingScenario(
544
- incrementalBundlingVersioning: boolean,
545
- ) {
546
- const fs = new OverlayFS(new MemoryFS(farm), new NodeFS());
547
- const appRoot = __dirname;
548
- await fs.mkdirp(path.join(appRoot, 'app'));
549
- await fs.writeFile(path.join(appRoot, 'app', 'package.json'), '{}');
550
- await fs.writeFile(path.join(appRoot, 'app', '.git'), '');
551
- await fs.writeFile(
552
- path.join(appRoot, 'app', '.parcelrc'),
553
- '{"extends":"@atlaspack/config-default"}',
554
- );
555
- await fs.writeFile(
556
- path.join(appRoot, 'app', 'target.js'),
557
- 'console.log("hello")',
558
- );
559
-
560
- const atlaspack = new Atlaspack({
561
- featureFlags: {
562
- incrementalBundlingVersioning,
563
- },
564
- workerFarm: farm,
565
- entries: [path.join(appRoot, 'app', 'target.js')],
566
- cache: new LMDBLiteCache(DEFAULT_OPTIONS.cacheDir),
567
- inputFS: fs,
568
- outputFS: fs,
569
- });
570
- await atlaspack._init();
571
- const options = atlaspack._getResolvedAtlaspackOptions();
572
- const tracker = new RequestTracker({farm, options});
573
- let {ref: optionsRef} = await farm.createSharedReference(options, false);
574
-
575
- const getAssetRequests = () =>
576
- runRequestSpy
577
- .getCalls()
578
- .map((call: any) => call.args[0])
579
- .filter(
580
- (request: any) => request.type === requestTypes.asset_request,
581
- );
582
-
583
- // Running the build once builds one asset
584
- const runRequestSpy = sinon.spy(tracker, 'runRequest');
585
- await tracker.runRequest(
586
- createAtlaspackBuildRequest({
587
- optionsRef,
588
- requestedAssetIds: new Set(),
589
- }),
590
- );
591
- assert.equal(getAssetRequests().length, 1);
592
- runRequestSpy.resetHistory();
593
-
594
- // Running the build again with no invalidations does not build any assets
595
- await tracker.runRequest(
596
- createAtlaspackBuildRequest({
597
- optionsRef,
598
- requestedAssetIds: new Set(),
599
- }),
600
- );
601
- assert.equal(getAssetRequests().length, 0);
602
- runRequestSpy.resetHistory();
603
-
604
- // Running the build again with a file change builds the asset again
605
- tracker.respondToFSEvents(
606
- [
607
- {
608
- type: 'update',
609
- path: path.join(appRoot, 'app', 'target.js'),
610
- },
611
- ],
612
- Number.MAX_VALUE,
613
- );
614
- await tracker.runRequest(
615
- createAtlaspackBuildRequest({
616
- optionsRef,
617
- requestedAssetIds: new Set(),
618
- }),
619
- );
620
- assert.equal(getAssetRequests().length, 1);
621
- runRequestSpy.resetHistory();
622
-
623
- // Run the asset graph request, but not bundling
624
- await fs.writeFile(
625
- path.join(appRoot, 'app', 'target.js'),
626
- 'require("./dep.js")',
627
- );
628
- await fs.writeFile(
629
- path.join(appRoot, 'app', 'dep.js'),
630
- 'console.log("dep")',
631
- );
632
- tracker.respondToFSEvents(
633
- [
634
- {
635
- type: 'update',
636
- path: path.join(appRoot, 'app', 'target.js'),
637
- },
638
- ],
639
- Number.MAX_VALUE,
640
- );
641
- const assetGraphRequestResult = await tracker.runRequest(
642
- createAssetGraphRequest({
643
- name: 'Main',
644
- entries: [
645
- toProjectPath(
646
- path.join(appRoot, 'app'),
647
- path.join(appRoot, 'app', 'target.js'),
648
- ),
649
- ],
650
- optionsRef,
651
- shouldBuildLazily: false,
652
- lazyIncludes: [],
653
- lazyExcludes: [],
654
- requestedAssetIds: new Set(),
655
- }),
656
- );
657
- assert.equal(getAssetRequests().length, 2);
658
- assert.equal(
659
- assetGraphRequestResult.assetGraph.safeToIncrementallyBundle,
660
- false,
661
- );
662
-
663
- // Now make another change
664
- tracker.respondToFSEvents(
665
- [
666
- {
667
- type: 'update',
668
- path: path.join(appRoot, 'app', 'target.js'),
669
- },
670
- {
671
- type: 'update',
672
- path: path.join(appRoot, 'app', 'dep.js'),
673
- },
674
- ],
675
- Number.MAX_VALUE,
676
- );
677
- // And run the build again
678
-
679
- if (!incrementalBundlingVersioning) {
680
- await assert.rejects(async () => {
681
- await tracker.runRequest(
682
- createAtlaspackBuildRequest({
683
- optionsRef,
684
- requestedAssetIds: new Set(),
685
- }),
686
- );
687
- });
688
- } else {
689
- await tracker.runRequest(
690
- createAtlaspackBuildRequest({
691
- optionsRef,
692
- requestedAssetIds: new Set(),
693
- }),
694
- );
695
- }
696
- }
697
-
698
- it('throws a content key not found exception without bundling versioning', async () => {
699
- await runIncrementalBundlingScenario(false);
700
- });
701
-
702
- it('works fine with bundling versioning', async () => {
703
- await runIncrementalBundlingScenario(true);
704
- });
705
- });
706
541
  });
707
542
 
708
543
  describe('cleanUpOrphans', () => {