@atlaspack/core 2.16.2-canary.13 → 2.16.2-canary.131

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 (95) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/index.d.ts +4 -0
  3. package/lib/AssetGraph.js +27 -7
  4. package/lib/Atlaspack.js +35 -27
  5. package/lib/AtlaspackConfig.schema.js +7 -1
  6. package/lib/BundleGraph.js +8 -5
  7. package/lib/Dependency.js +6 -2
  8. package/lib/Environment.js +5 -3
  9. package/lib/EnvironmentManager.js +137 -0
  10. package/lib/InternalConfig.js +3 -2
  11. package/lib/PackagerRunner.js +54 -16
  12. package/lib/RequestTracker.js +345 -132
  13. package/lib/SymbolPropagation.js +14 -0
  14. package/lib/Transformation.js +2 -2
  15. package/lib/UncommittedAsset.js +20 -2
  16. package/lib/applyRuntimes.js +2 -1
  17. package/lib/assetUtils.js +2 -1
  18. package/lib/atlaspack-v3/AtlaspackV3.js +16 -3
  19. package/lib/atlaspack-v3/worker/compat/environment.js +2 -2
  20. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +6 -6
  21. package/lib/atlaspack-v3/worker/compat/plugin-config.js +5 -5
  22. package/lib/atlaspack-v3/worker/index.js +3 -0
  23. package/lib/atlaspack-v3/worker/worker.js +8 -0
  24. package/lib/dumpGraphToGraphViz.js +1 -1
  25. package/lib/index.js +29 -1
  26. package/lib/public/Asset.js +7 -9
  27. package/lib/public/Bundle.js +12 -13
  28. package/lib/public/BundleGraph.js +3 -2
  29. package/lib/public/BundleGroup.js +2 -3
  30. package/lib/public/Config.js +95 -8
  31. package/lib/public/Dependency.js +4 -4
  32. package/lib/public/Environment.js +2 -3
  33. package/lib/public/MutableBundleGraph.js +5 -4
  34. package/lib/public/PluginOptions.js +1 -2
  35. package/lib/public/Target.js +4 -4
  36. package/lib/requests/AssetGraphRequest.js +13 -1
  37. package/lib/requests/AssetGraphRequestRust.js +17 -2
  38. package/lib/requests/AssetRequest.js +2 -1
  39. package/lib/requests/BundleGraphRequest.js +13 -1
  40. package/lib/requests/ConfigRequest.js +27 -4
  41. package/lib/requests/DevDepRequest.js +11 -1
  42. package/lib/requests/PathRequest.js +10 -0
  43. package/lib/requests/TargetRequest.js +18 -16
  44. package/lib/requests/WriteBundleRequest.js +15 -3
  45. package/lib/requests/WriteBundlesRequest.js +22 -1
  46. package/lib/resolveOptions.js +7 -4
  47. package/lib/worker.js +18 -1
  48. package/package.json +18 -25
  49. package/src/AssetGraph.js +30 -7
  50. package/src/Atlaspack.js +40 -23
  51. package/src/BundleGraph.js +13 -8
  52. package/src/Dependency.js +13 -5
  53. package/src/Environment.js +9 -6
  54. package/src/EnvironmentManager.js +145 -0
  55. package/src/InternalConfig.js +6 -5
  56. package/src/PackagerRunner.js +72 -20
  57. package/src/RequestTracker.js +526 -157
  58. package/src/SymbolPropagation.js +13 -1
  59. package/src/UncommittedAsset.js +23 -3
  60. package/src/applyRuntimes.js +6 -1
  61. package/src/assetUtils.js +4 -3
  62. package/src/atlaspack-v3/AtlaspackV3.js +24 -3
  63. package/src/atlaspack-v3/worker/compat/plugin-config.js +9 -5
  64. package/src/atlaspack-v3/worker/index.js +2 -1
  65. package/src/atlaspack-v3/worker/worker.js +7 -0
  66. package/src/index.js +5 -1
  67. package/src/public/Asset.js +13 -6
  68. package/src/public/Bundle.js +12 -11
  69. package/src/public/BundleGraph.js +10 -2
  70. package/src/public/BundleGroup.js +2 -2
  71. package/src/public/Config.js +132 -18
  72. package/src/public/Dependency.js +4 -3
  73. package/src/public/Environment.js +2 -2
  74. package/src/public/MutableBundleGraph.js +8 -5
  75. package/src/public/PluginOptions.js +1 -1
  76. package/src/public/Target.js +4 -3
  77. package/src/requests/AssetGraphRequest.js +13 -3
  78. package/src/requests/AssetGraphRequestRust.js +14 -2
  79. package/src/requests/AssetRequest.js +2 -1
  80. package/src/requests/BundleGraphRequest.js +13 -3
  81. package/src/requests/ConfigRequest.js +33 -9
  82. package/src/requests/DevDepRequest.js +22 -9
  83. package/src/requests/PathRequest.js +4 -0
  84. package/src/requests/TargetRequest.js +19 -25
  85. package/src/requests/WriteBundleRequest.js +14 -8
  86. package/src/requests/WriteBundlesRequest.js +31 -3
  87. package/src/resolveOptions.js +4 -2
  88. package/src/types.js +10 -7
  89. package/test/Environment.test.js +43 -34
  90. package/test/EnvironmentManager.test.js +192 -0
  91. package/test/PublicEnvironment.test.js +10 -7
  92. package/test/RequestTracker.test.js +124 -29
  93. package/test/public/Config.test.js +108 -0
  94. package/test/requests/ConfigRequest.test.js +199 -7
  95. 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,22 +398,25 @@ 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 mapFilename = fullPath + '.map';
417
+ let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
407
418
  let stringified = await map.stringify({
408
- file: _path().default.basename(fullPath + '.map'),
419
+ file: _path().default.basename(mapFilename),
409
420
  // $FlowFixMe
410
421
  fs: this.options.inputFS,
411
422
  rootDir: this.options.projectRoot,
@@ -434,6 +445,10 @@ class PackagerRunner {
434
445
  devDepHashes += await this.getDevDepHashes(inlineBundle);
435
446
  }
436
447
  let invalidationHash = await (0, _assetUtils.getInvalidationHash)(invalidations, this.options);
448
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
449
+ 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'));
450
+ return _path().default.join(bundle.displayName ?? bundle.name ?? bundle.id, hash);
451
+ }
437
452
  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
453
  }
439
454
  async getDevDepHashes(bundle) {
@@ -457,25 +472,27 @@ class PackagerRunner {
457
472
  let contentKey = PackagerRunner.getContentKey(cacheKey);
458
473
  let mapKey = PackagerRunner.getMapKey(cacheKey);
459
474
  let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
460
- let contentExists = isLargeBlob || (await this.options.cache.has(contentKey));
475
+ let contentExists = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? isLargeBlob : isLargeBlob || (await this.options.cache.has(contentKey));
461
476
  if (!contentExists) {
462
477
  return null;
463
478
  }
464
- let mapExists = await this.options.cache.has(mapKey);
479
+ let mapExists = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await this.options.cache.hasLargeBlob(mapKey) : await this.options.cache.has(mapKey);
465
480
  return {
466
481
  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
482
+ map: mapExists ? (0, _utils().blobToStream)((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await this.options.cache.getLargeBlob(mapKey) : await this.options.cache.getBlob(mapKey)) : null
468
483
  };
469
484
  }
470
485
  async writeToCache(cacheKeys, type, contents, map) {
471
486
  let size = 0;
472
487
  let hash;
473
488
  let hashReferences = [];
474
- let isLargeBlob = false;
489
+ let isLargeBlob = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements');
475
490
 
476
491
  // TODO: don't replace hash references in binary files??
477
492
  if (contents instanceof _stream().Readable) {
478
- isLargeBlob = true;
493
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
494
+ isLargeBlob = true;
495
+ }
479
496
  let boundaryStr = '';
480
497
  let h = new (_rust().Hash)();
481
498
  await this.options.cache.setStream(cacheKeys.content, (0, _utils().blobToStream)(contents).pipe(new (_utils().TapStream)(buf => {
@@ -491,15 +508,27 @@ class PackagerRunner {
491
508
  size = buffer.byteLength;
492
509
  hash = (0, _rust().hashBuffer)(buffer);
493
510
  hashReferences = contents.match(_constants.HASH_REF_REGEX) ?? [];
494
- await this.options.cache.setBlob(cacheKeys.content, buffer);
511
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
512
+ await this.options.cache.setLargeBlob(cacheKeys.content, buffer);
513
+ } else {
514
+ await this.options.cache.setBlob(cacheKeys.content, buffer);
515
+ }
495
516
  } else {
496
517
  size = contents.length;
497
518
  hash = (0, _rust().hashBuffer)(contents);
498
519
  hashReferences = contents.toString().match(_constants.HASH_REF_REGEX) ?? [];
499
- await this.options.cache.setBlob(cacheKeys.content, contents);
520
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
521
+ await this.options.cache.setLargeBlob(cacheKeys.content, contents);
522
+ } else {
523
+ await this.options.cache.setBlob(cacheKeys.content, contents);
524
+ }
500
525
  }
501
526
  if (map != null) {
502
- await this.options.cache.setBlob(cacheKeys.map, map);
527
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
528
+ await this.options.cache.setLargeBlob(cacheKeys.map, map);
529
+ } else {
530
+ await this.options.cache.setBlob(cacheKeys.map, map);
531
+ }
503
532
  }
504
533
  let info = {
505
534
  type,
@@ -513,12 +542,21 @@ class PackagerRunner {
513
542
  return info;
514
543
  }
515
544
  static getContentKey(cacheKey) {
545
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
546
+ return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/content`;
547
+ }
516
548
  return (0, _rust().hashString)(`${cacheKey}:content`);
517
549
  }
518
550
  static getMapKey(cacheKey) {
551
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
552
+ return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/map`;
553
+ }
519
554
  return (0, _rust().hashString)(`${cacheKey}:map`);
520
555
  }
521
556
  static getInfoKey(cacheKey) {
557
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
558
+ return `PackagerRunner/${_constants.ATLASPACK_VERSION}/${cacheKey}/info`;
559
+ }
522
560
  return (0, _rust().hashString)(`${cacheKey}:info`);
523
561
  }
524
562
  }