@atlaspack/core 2.16.2-dev.14 → 2.16.2-dev.1c70d50f9.99

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 (75) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/lib/AssetGraph.js +27 -7
  3. package/lib/Atlaspack.js +10 -2
  4. package/lib/BundleGraph.js +6 -105
  5. package/lib/Dependency.js +6 -2
  6. package/lib/Environment.js +5 -3
  7. package/lib/EnvironmentManager.js +137 -0
  8. package/lib/InternalConfig.js +3 -2
  9. package/lib/PackagerRunner.js +52 -15
  10. package/lib/RequestTracker.js +313 -94
  11. package/lib/UncommittedAsset.js +20 -2
  12. package/lib/applyRuntimes.js +2 -1
  13. package/lib/assetUtils.js +2 -1
  14. package/lib/atlaspack-v3/worker/worker.js +8 -0
  15. package/lib/index.js +29 -1
  16. package/lib/public/Asset.js +3 -2
  17. package/lib/public/Bundle.js +2 -1
  18. package/lib/public/BundleGraph.js +21 -8
  19. package/lib/public/Config.js +91 -3
  20. package/lib/public/Dependency.js +2 -1
  21. package/lib/public/MutableBundleGraph.js +2 -1
  22. package/lib/public/Target.js +2 -1
  23. package/lib/requests/AssetGraphRequest.js +13 -1
  24. package/lib/requests/AssetGraphRequestRust.js +17 -2
  25. package/lib/requests/AssetRequest.js +2 -1
  26. package/lib/requests/BundleGraphRequest.js +13 -1
  27. package/lib/requests/ConfigRequest.js +27 -4
  28. package/lib/requests/DevDepRequest.js +21 -1
  29. package/lib/requests/PathRequest.js +10 -0
  30. package/lib/requests/TargetRequest.js +18 -16
  31. package/lib/requests/WriteBundleRequest.js +15 -3
  32. package/lib/requests/WriteBundlesRequest.js +1 -0
  33. package/lib/resolveOptions.js +4 -2
  34. package/package.json +18 -25
  35. package/src/AssetGraph.js +30 -7
  36. package/src/Atlaspack.js +13 -5
  37. package/src/BundleGraph.js +13 -175
  38. package/src/Dependency.js +13 -5
  39. package/src/Environment.js +9 -6
  40. package/src/EnvironmentManager.js +145 -0
  41. package/src/InternalConfig.js +6 -5
  42. package/src/PackagerRunner.js +72 -20
  43. package/src/RequestTracker.js +532 -150
  44. package/src/UncommittedAsset.js +23 -3
  45. package/src/applyRuntimes.js +6 -1
  46. package/src/assetUtils.js +4 -3
  47. package/src/atlaspack-v3/worker/compat/plugin-config.js +9 -5
  48. package/src/atlaspack-v3/worker/worker.js +7 -0
  49. package/src/index.js +5 -1
  50. package/src/public/Asset.js +9 -2
  51. package/src/public/Bundle.js +2 -1
  52. package/src/public/BundleGraph.js +22 -15
  53. package/src/public/Config.js +128 -14
  54. package/src/public/Dependency.js +2 -1
  55. package/src/public/MutableBundleGraph.js +5 -2
  56. package/src/public/Target.js +2 -1
  57. package/src/requests/AssetGraphRequest.js +13 -3
  58. package/src/requests/AssetGraphRequestRust.js +14 -2
  59. package/src/requests/AssetRequest.js +2 -1
  60. package/src/requests/BundleGraphRequest.js +13 -3
  61. package/src/requests/ConfigRequest.js +33 -9
  62. package/src/requests/DevDepRequest.js +44 -12
  63. package/src/requests/PathRequest.js +4 -0
  64. package/src/requests/TargetRequest.js +19 -25
  65. package/src/requests/WriteBundleRequest.js +14 -8
  66. package/src/requests/WriteBundlesRequest.js +1 -0
  67. package/src/resolveOptions.js +4 -2
  68. package/src/types.js +10 -7
  69. package/test/Environment.test.js +43 -34
  70. package/test/EnvironmentManager.test.js +192 -0
  71. package/test/PublicEnvironment.test.js +10 -7
  72. package/test/RequestTracker.test.js +115 -3
  73. package/test/public/Config.test.js +108 -0
  74. package/test/requests/ConfigRequest.test.js +187 -3
  75. package/test/test-utils.js +4 -9
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fromEnvironmentId = fromEnvironmentId;
7
+ exports.loadEnvironmentsFromCache = loadEnvironmentsFromCache;
8
+ exports.toEnvironmentId = toEnvironmentId;
9
+ exports.toEnvironmentRef = toEnvironmentRef;
10
+ exports.writeEnvironmentsToCache = writeEnvironmentsToCache;
11
+ function _rust() {
12
+ const data = require("@atlaspack/rust");
13
+ _rust = function () {
14
+ return data;
15
+ };
16
+ return data;
17
+ }
18
+ function _featureFlags() {
19
+ const data = require("@atlaspack/feature-flags");
20
+ _featureFlags = function () {
21
+ return data;
22
+ };
23
+ return data;
24
+ }
25
+ function _logger() {
26
+ const data = require("@atlaspack/logger");
27
+ _logger = function () {
28
+ return data;
29
+ };
30
+ return data;
31
+ }
32
+ var _constants = require("./constants");
33
+ /*!
34
+ * At the moment we're doing this change for `CoreEnvironment`,
35
+ * but the same change must be made for `TypesEnvironment` in @atlaspack/types.
36
+ */
37
+ const localEnvironmentCache = new Map();
38
+
39
+ /**
40
+ * When deduplication is cleaned-up this will always be a string.
41
+ */
42
+
43
+ /**
44
+ * Convert environment to a ref.
45
+ * This is what we should be using to store environments.
46
+ */
47
+ function toEnvironmentRef(env) {
48
+ if (!(0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
49
+ return env;
50
+ }
51
+ const id = toEnvironmentId(env);
52
+ return id;
53
+ }
54
+
55
+ /**
56
+ * Convert environment to a string ID
57
+ */
58
+ function toEnvironmentId(
59
+ /**
60
+ * Redundant type during roll-out
61
+ */
62
+ env) {
63
+ if (!(0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
64
+ return typeof env === 'string' ? env : env.id;
65
+ }
66
+ if (typeof env === 'string') {
67
+ return env;
68
+ }
69
+ (0, _rust().addEnvironment)(env);
70
+ return env.id;
71
+ }
72
+ function fromEnvironmentId(id) {
73
+ if (!(0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
74
+ if (typeof id === 'string') {
75
+ throw new Error('This should never happen when environmentDeduplication feature-flag is off');
76
+ } else {
77
+ return id;
78
+ }
79
+ }
80
+ if (typeof id !== 'string') {
81
+ return id;
82
+ }
83
+ const localEnv = localEnvironmentCache.get(id);
84
+ if (localEnv) {
85
+ return localEnv;
86
+ }
87
+ const env = Object.freeze((0, _rust().getEnvironment)(id));
88
+ localEnvironmentCache.set(id, env);
89
+ return env;
90
+ }
91
+
92
+ /**
93
+ * Writes all environments and their IDs to the cache
94
+ * @param {Cache} cache
95
+ * @returns {Promise<void>}
96
+ */
97
+ async function writeEnvironmentsToCache(cache) {
98
+ const environments = (0, _rust().getAllEnvironments)();
99
+ const environmentIds = new Set();
100
+
101
+ // Store each environment individually
102
+ for (const env of environments) {
103
+ environmentIds.add(env.id);
104
+ const envKey = `Environment/${_constants.ATLASPACK_VERSION}/${env.id}`;
105
+ await (0, _logger().instrument)(`RequestTracker::writeToCache::cache.put(${envKey})`, async () => {
106
+ await cache.set(envKey, env);
107
+ });
108
+ }
109
+
110
+ // Store the list of environment IDs
111
+ await (0, _logger().instrument)(`RequestTracker::writeToCache::cache.put(${`EnvironmentManager/${_constants.ATLASPACK_VERSION}`})`, async () => {
112
+ await cache.set(`EnvironmentManager/${_constants.ATLASPACK_VERSION}`, Array.from(environmentIds));
113
+ });
114
+ }
115
+
116
+ /**
117
+ * Loads all environments and their IDs from the cache
118
+ * @param {Cache} cache
119
+ * @returns {Promise<void>}
120
+ */
121
+ async function loadEnvironmentsFromCache(cache) {
122
+ const cachedEnvIds = await cache.get(`EnvironmentManager/${_constants.ATLASPACK_VERSION}`);
123
+ if (cachedEnvIds == null) {
124
+ return;
125
+ }
126
+ const environments = [];
127
+ for (const envId of cachedEnvIds) {
128
+ const envKey = `Environment/${_constants.ATLASPACK_VERSION}/${envId}`;
129
+ const cachedEnv = await cache.get(envKey);
130
+ if (cachedEnv != null) {
131
+ environments.push(cachedEnv);
132
+ }
133
+ }
134
+ if (environments.length > 0) {
135
+ (0, _rust().setAllEnvironments)(environments);
136
+ }
137
+ }
@@ -14,6 +14,7 @@ function _rust() {
14
14
  return data;
15
15
  }
16
16
  var _IdentifierRegistry = require("./IdentifierRegistry");
17
+ var _EnvironmentManager = require("./EnvironmentManager");
17
18
  function createConfig({
18
19
  plugin,
19
20
  isSource,
@@ -30,11 +31,11 @@ function createConfig({
30
31
  invalidateOnBuild
31
32
  }) {
32
33
  let environment = env ?? (0, _Environment.createEnvironment)();
33
- const configId = (0, _rust().hashString)(plugin + (0, _projectPath.fromProjectPathRelative)(searchPath) + environment.id + String(isSource));
34
+ const configId = (0, _rust().hashString)(plugin + (0, _projectPath.fromProjectPathRelative)(searchPath) + (0, _EnvironmentManager.toEnvironmentId)(environment) + String(isSource));
34
35
  _IdentifierRegistry.identifierRegistry.addIdentifier('config_request', configId, {
35
36
  plugin,
36
37
  searchPath,
37
- environmentId: environment.id,
38
+ environmentId: (0, _EnvironmentManager.toEnvironmentId)(environment),
38
39
  isSource
39
40
  });
40
41
  return {
@@ -92,6 +92,14 @@ function _profiler() {
92
92
  };
93
93
  return data;
94
94
  }
95
+ 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
+ }
95
103
  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); }
96
104
  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; }
97
105
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -390,20 +398,22 @@ class PackagerRunner {
390
398
  let fullPath = (0, _projectPath.fromProjectPath)(this.options.projectRoot, filePath);
391
399
  let sourceRoot = _path().default.relative(_path().default.dirname(fullPath), this.options.projectRoot);
392
400
  let inlineSources = false;
401
+ const bundleEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
393
402
  if (bundle.target) {
394
- if (bundle.env.sourceMap && bundle.env.sourceMap.sourceRoot !== undefined) {
395
- sourceRoot = bundle.env.sourceMap.sourceRoot;
396
- } else if (this.options.serveOptions && bundle.target.env.context === 'browser') {
403
+ const bundleTargetEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.target.env);
404
+ if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
405
+ sourceRoot = bundleEnv.sourceMap.sourceRoot;
406
+ } else if (this.options.serveOptions && bundleTargetEnv.context === 'browser') {
397
407
  sourceRoot = '/__parcel_source_root';
398
408
  }
399
- if (bundle.env.sourceMap && bundle.env.sourceMap.inlineSources !== undefined) {
400
- inlineSources = bundle.env.sourceMap.inlineSources;
401
- } else if (bundle.target.env.context !== 'node') {
409
+ if (bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources !== undefined) {
410
+ inlineSources = bundleEnv.sourceMap.inlineSources;
411
+ } else if (bundleTargetEnv.context !== 'node') {
402
412
  // inlining should only happen in production for browser targets by default
403
413
  inlineSources = this.options.mode === 'production';
404
414
  }
405
415
  }
406
- let isInlineMap = bundle.env.sourceMap && bundle.env.sourceMap.inline;
416
+ let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
407
417
  let stringified = await map.stringify({
408
418
  file: _path().default.basename(fullPath + '.map'),
409
419
  // $FlowFixMe
@@ -434,6 +444,10 @@ class PackagerRunner {
434
444
  devDepHashes += await this.getDevDepHashes(inlineBundle);
435
445
  }
436
446
  let invalidationHash = await (0, _assetUtils.getInvalidationHash)(invalidations, this.options);
447
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
448
+ 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'));
449
+ return _path().default.join(bundle.displayName ?? bundle.name ?? bundle.id, hash);
450
+ }
437
451
  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'));
438
452
  }
439
453
  async getDevDepHashes(bundle) {
@@ -457,25 +471,27 @@ class PackagerRunner {
457
471
  let contentKey = PackagerRunner.getContentKey(cacheKey);
458
472
  let mapKey = PackagerRunner.getMapKey(cacheKey);
459
473
  let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
460
- let contentExists = isLargeBlob || (await this.options.cache.has(contentKey));
474
+ let contentExists = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? isLargeBlob : isLargeBlob || (await this.options.cache.has(contentKey));
461
475
  if (!contentExists) {
462
476
  return null;
463
477
  }
464
- let mapExists = await this.options.cache.has(mapKey);
478
+ let mapExists = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await this.options.cache.hasLargeBlob(mapKey) : await this.options.cache.has(mapKey);
465
479
  return {
466
480
  contents: isLargeBlob ? this.options.cache.getStream(contentKey) : (0, _utils().blobToStream)(await this.options.cache.getBlob(contentKey)),
467
- map: mapExists ? (0, _utils().blobToStream)(await this.options.cache.getBlob(mapKey)) : null
481
+ map: mapExists ? (0, _utils().blobToStream)((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await this.options.cache.getLargeBlob(mapKey) : await this.options.cache.getBlob(mapKey)) : null
468
482
  };
469
483
  }
470
484
  async writeToCache(cacheKeys, type, contents, map) {
471
485
  let size = 0;
472
486
  let hash;
473
487
  let hashReferences = [];
474
- let isLargeBlob = false;
488
+ let isLargeBlob = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements');
475
489
 
476
490
  // TODO: don't replace hash references in binary files??
477
491
  if (contents instanceof _stream().Readable) {
478
- isLargeBlob = true;
492
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
493
+ isLargeBlob = true;
494
+ }
479
495
  let boundaryStr = '';
480
496
  let h = new (_rust().Hash)();
481
497
  await this.options.cache.setStream(cacheKeys.content, (0, _utils().blobToStream)(contents).pipe(new (_utils().TapStream)(buf => {
@@ -491,15 +507,27 @@ class PackagerRunner {
491
507
  size = buffer.byteLength;
492
508
  hash = (0, _rust().hashBuffer)(buffer);
493
509
  hashReferences = contents.match(_constants.HASH_REF_REGEX) ?? [];
494
- await this.options.cache.setBlob(cacheKeys.content, buffer);
510
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
511
+ await this.options.cache.setLargeBlob(cacheKeys.content, buffer);
512
+ } else {
513
+ await this.options.cache.setBlob(cacheKeys.content, buffer);
514
+ }
495
515
  } else {
496
516
  size = contents.length;
497
517
  hash = (0, _rust().hashBuffer)(contents);
498
518
  hashReferences = contents.toString().match(_constants.HASH_REF_REGEX) ?? [];
499
- await this.options.cache.setBlob(cacheKeys.content, contents);
519
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
520
+ await this.options.cache.setLargeBlob(cacheKeys.content, contents);
521
+ } else {
522
+ await this.options.cache.setBlob(cacheKeys.content, contents);
523
+ }
500
524
  }
501
525
  if (map != null) {
502
- await this.options.cache.setBlob(cacheKeys.map, map);
526
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
527
+ await this.options.cache.setLargeBlob(cacheKeys.map, map);
528
+ } else {
529
+ await this.options.cache.setBlob(cacheKeys.map, map);
530
+ }
503
531
  }
504
532
  let info = {
505
533
  type,
@@ -513,12 +541,21 @@ class PackagerRunner {
513
541
  return info;
514
542
  }
515
543
  static getContentKey(cacheKey) {
544
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
545
+ return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/content`;
546
+ }
516
547
  return (0, _rust().hashString)(`${cacheKey}:content`);
517
548
  }
518
549
  static getMapKey(cacheKey) {
550
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
551
+ return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/map`;
552
+ }
519
553
  return (0, _rust().hashString)(`${cacheKey}:map`);
520
554
  }
521
555
  static getInfoKey(cacheKey) {
556
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
557
+ return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/info`;
558
+ }
522
559
  return (0, _rust().hashString)(`${cacheKey}:info`);
523
560
  }
524
561
  }