@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
@@ -53,6 +53,14 @@ var _assetUtils = require("./assetUtils");
53
53
  var _types = require("./types");
54
54
  var _utils2 = require("./utils");
55
55
  var _projectPath = require("./projectPath");
56
+ function _featureFlags() {
57
+ const data = require("@atlaspack/feature-flags");
58
+ _featureFlags = function () {
59
+ return data;
60
+ };
61
+ return data;
62
+ }
63
+ var _EnvironmentManager = require("./EnvironmentManager");
56
64
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
65
  class UncommittedAsset {
58
66
  constructor({
@@ -133,6 +141,8 @@ class UncommittedAsset {
133
141
  hash = (0, _rust().hashBuffer)(content);
134
142
  size = content.length;
135
143
  }
144
+
145
+ // Maybe we should just store this in a file instead of LMDB
136
146
  await this.options.cache.setBlob(contentKey, content);
137
147
  return {
138
148
  size,
@@ -184,6 +194,10 @@ class UncommittedAsset {
184
194
  this.content = buffer;
185
195
  this.clearAST();
186
196
  }
197
+
198
+ /**
199
+ * @deprecated This has been broken on any cache other than FSCache for a long time.
200
+ */
187
201
  setStream(stream) {
188
202
  this.content = stream;
189
203
  this.clearAST();
@@ -248,6 +262,10 @@ class UncommittedAsset {
248
262
  this.value.astGenerator = null;
249
263
  }
250
264
  getCacheKey(key) {
265
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
266
+ const filePath = (0, _projectPath.fromProjectPathRelative)(this.value.filePath);
267
+ return `Asset/${_constants.ATLASPACK_VERSION}/${filePath}/${this.value.id}/${key}`;
268
+ }
251
269
  return (0, _rust().hashString)(_constants.ATLASPACK_VERSION + key + this.value.id);
252
270
  }
253
271
  addDependency(opts) {
@@ -261,7 +279,7 @@ class UncommittedAsset {
261
279
  ...rest,
262
280
  // $FlowFixMe "convert" the $ReadOnlyMaps to the interal mutable one
263
281
  symbols,
264
- env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, this.value.env, env),
282
+ env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, (0, _EnvironmentManager.fromEnvironmentId)(this.value.env), env),
265
283
  sourceAssetId: this.value.id,
266
284
  sourcePath: (0, _projectPath.fromProjectPath)(this.options.projectRoot, this.value.filePath)
267
285
  });
@@ -301,7 +319,7 @@ class UncommittedAsset {
301
319
  bundleBehavior: result.bundleBehavior ?? (this.value.bundleBehavior == null ? null : _types.BundleBehaviorNames[this.value.bundleBehavior]),
302
320
  isBundleSplittable: result.isBundleSplittable ?? this.value.isBundleSplittable,
303
321
  isSource: this.value.isSource,
304
- env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, this.value.env, result.env),
322
+ env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, (0, _EnvironmentManager.fromEnvironmentId)(this.value.env), result.env),
305
323
  dependencies: this.value.type === result.type ? new Map(this.value.dependencies) : new Map(),
306
324
  meta: {
307
325
  ...this.value.meta,
@@ -69,6 +69,7 @@ function _utils() {
69
69
  };
70
70
  return data;
71
71
  }
72
+ var _EnvironmentManager = require("./EnvironmentManager");
72
73
  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); }
73
74
  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; }
74
75
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -164,7 +165,7 @@ async function applyRuntimes({
164
165
  let assetGroup = {
165
166
  code,
166
167
  filePath: (0, _projectPath.toProjectPath)(options.projectRoot, sourceName),
167
- env: (0, _Environment.mergeEnvironments)(options.projectRoot, bundle.env, env),
168
+ env: (0, _Environment.mergeEnvironments)(options.projectRoot, (0, _EnvironmentManager.fromEnvironmentId)(bundle.env), env),
168
169
  // Runtime assets should be considered source, as they should be
169
170
  // e.g. compiled to run in the target environment
170
171
  isSource: true
package/lib/assetUtils.js CHANGED
@@ -66,10 +66,11 @@ function _profiler() {
66
66
  return data;
67
67
  }
68
68
  var _IdentifierRegistry = require("./IdentifierRegistry");
69
+ var _EnvironmentManager = require("./EnvironmentManager");
69
70
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
70
71
  function createAssetIdFromOptions(options) {
71
72
  const data = {
72
- environmentId: options.env.id,
73
+ environmentId: (0, _EnvironmentManager.toEnvironmentId)(options.env),
73
74
  filePath: options.filePath,
74
75
  code: options.code,
75
76
  pipeline: options.pipeline,
@@ -149,6 +149,14 @@ class AtlaspackWorker {
149
149
  }
150
150
  };
151
151
  }
152
+ if (result.isExcluded) {
153
+ return {
154
+ invalidations: [],
155
+ resolution: {
156
+ type: 'excluded'
157
+ }
158
+ };
159
+ }
152
160
  return {
153
161
  invalidations: [],
154
162
  resolution: {
package/lib/index.js CHANGED
@@ -4,13 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
+ EnvironmentManager: true,
7
8
  Atlaspack: true,
8
9
  Parcel: true,
9
10
  BuildError: true,
10
11
  createWorkerFarm: true,
11
12
  INTERNAL_RESOLVE: true,
12
- INTERNAL_TRANSFORM: true
13
+ INTERNAL_TRANSFORM: true,
14
+ WORKER_PATH: true,
15
+ ATLASPACK_VERSION: true,
16
+ resolveOptions: true
13
17
  };
18
+ Object.defineProperty(exports, "ATLASPACK_VERSION", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _constants.ATLASPACK_VERSION;
22
+ }
23
+ });
14
24
  Object.defineProperty(exports, "Atlaspack", {
15
25
  enumerable: true,
16
26
  get: function () {
@@ -23,6 +33,7 @@ Object.defineProperty(exports, "BuildError", {
23
33
  return _Atlaspack.BuildError;
24
34
  }
25
35
  });
36
+ exports.EnvironmentManager = void 0;
26
37
  Object.defineProperty(exports, "INTERNAL_RESOLVE", {
27
38
  enumerable: true,
28
39
  get: function () {
@@ -41,6 +52,12 @@ Object.defineProperty(exports, "Parcel", {
41
52
  return _Atlaspack.default;
42
53
  }
43
54
  });
55
+ Object.defineProperty(exports, "WORKER_PATH", {
56
+ enumerable: true,
57
+ get: function () {
58
+ return _Atlaspack.WORKER_PATH;
59
+ }
60
+ });
44
61
  Object.defineProperty(exports, "createWorkerFarm", {
45
62
  enumerable: true,
46
63
  get: function () {
@@ -53,7 +70,17 @@ Object.defineProperty(exports, "default", {
53
70
  return _Atlaspack.default;
54
71
  }
55
72
  });
73
+ Object.defineProperty(exports, "resolveOptions", {
74
+ enumerable: true,
75
+ get: function () {
76
+ return _resolveOptions.default;
77
+ }
78
+ });
79
+ var EnvironmentManager = _interopRequireWildcard(require("./EnvironmentManager"));
80
+ exports.EnvironmentManager = EnvironmentManager;
56
81
  var _Atlaspack = _interopRequireWildcard(require("./Atlaspack"));
82
+ var _constants = require("./constants");
83
+ var _resolveOptions = _interopRequireDefault(require("./resolveOptions"));
57
84
  var _atlaspackV = require("./atlaspack-v3");
58
85
  Object.keys(_atlaspackV).forEach(function (key) {
59
86
  if (key === "default" || key === "__esModule") return;
@@ -66,5 +93,6 @@ Object.keys(_atlaspackV).forEach(function (key) {
66
93
  }
67
94
  });
68
95
  });
96
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
97
  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); }
70
98
  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; }
@@ -23,6 +23,7 @@ var _Environment2 = require("../Environment");
23
23
  var _projectPath = require("../projectPath");
24
24
  var _types = require("../types");
25
25
  var _utils = require("../utils");
26
+ var _EnvironmentManager = require("../EnvironmentManager");
26
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
28
  const inspect = Symbol.for('nodejs.util.inspect.custom');
28
29
  const uncommittedAssetValueToAsset = new WeakMap();
@@ -62,7 +63,7 @@ class BaseAsset {
62
63
  return this.#asset.value.type;
63
64
  }
64
65
  get env() {
65
- return new _Environment.default(this.#asset.value.env, this.#asset.options);
66
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#asset.value.env), this.#asset.options);
66
67
  }
67
68
  get fs() {
68
69
  return this.#asset.options.inputFS;
@@ -142,7 +143,7 @@ class Asset extends BaseAsset {
142
143
  return this;
143
144
  }
144
145
  get env() {
145
- this.#env ??= new _Environment.default(this.#asset.value.env, this.#asset.options);
146
+ this.#env ??= new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#asset.value.env), this.#asset.options);
146
147
  return this.#env;
147
148
  }
148
149
  get stats() {
@@ -40,6 +40,7 @@ var _Dependency = require("./Dependency");
40
40
  var _Target = _interopRequireDefault(require("./Target"));
41
41
  var _types = require("../types");
42
42
  var _projectPath = require("../projectPath");
43
+ var _EnvironmentManager = require("../EnvironmentManager");
43
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44
45
  const inspect = Symbol.for('nodejs.util.inspect.custom');
45
46
  const internalBundleToBundle = new (_utils().DefaultWeakMap)(() => new (_utils().DefaultWeakMap)(() => new WeakMap()));
@@ -99,7 +100,7 @@ class Bundle {
99
100
  return this.#bundle.type;
100
101
  }
101
102
  get env() {
102
- return new _Environment.default(this.#bundle.env, this.#options);
103
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#bundle.env), this.#options);
103
104
  }
104
105
  get needsStableName() {
105
106
  return this.#bundle.needsStableName;
@@ -32,6 +32,13 @@ var _Dependency = _interopRequireWildcard(require("./Dependency"));
32
32
  var _Target = require("./Target");
33
33
  var _utils = require("../utils");
34
34
  var _BundleGroup = _interopRequireWildcard(require("./BundleGroup"));
35
+ function _featureFlags() {
36
+ const data = require("@atlaspack/feature-flags");
37
+ _featureFlags = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
35
42
  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); }
36
43
  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; }
37
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -115,9 +122,6 @@ class BundleGraph {
115
122
  isAssetReferenced(bundle, asset) {
116
123
  return this.#graph.isAssetReferenced((0, _Bundle.bundleToInternalBundle)(bundle), (0, _Asset.assetToAssetValue)(asset));
117
124
  }
118
- getReferencedAssets(bundle, cache) {
119
- return this.#graph.getReferencedAssets((0, _Bundle.bundleToInternalBundle)(bundle), cache);
120
- }
121
125
  hasParentBundleOfType(bundle, type) {
122
126
  return this.#graph.hasParentBundleOfType((0, _Bundle.bundleToInternalBundle)(bundle), type);
123
127
  }
@@ -266,11 +270,20 @@ class BundleGraph {
266
270
  }
267
271
  for (let bundle of bundles) {
268
272
  const conditions = bundleConditions.get(bundle.id) ?? new Map();
269
- conditions.set(cond.key, {
270
- bundle,
271
- ifTrueBundles,
272
- ifFalseBundles
273
- });
273
+ const currentCondition = conditions.get(cond.key);
274
+ if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingReporterSameConditionFix')) {
275
+ conditions.set(cond.key, {
276
+ bundle,
277
+ ifTrueBundles: [...((currentCondition === null || currentCondition === void 0 ? void 0 : currentCondition.ifTrueBundles) ?? []), ...ifTrueBundles],
278
+ ifFalseBundles: [...((currentCondition === null || currentCondition === void 0 ? void 0 : currentCondition.ifFalseBundles) ?? []), ...ifFalseBundles]
279
+ });
280
+ } else {
281
+ conditions.set(cond.key, {
282
+ bundle,
283
+ ifTrueBundles,
284
+ ifFalseBundles
285
+ });
286
+ }
274
287
  bundleConditions.set(bundle.id, conditions);
275
288
  }
276
289
  }
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ exports.makeConfigProxy = makeConfigProxy;
7
8
  function _assert() {
8
9
  const data = _interopRequireDefault(require("assert"));
9
10
  _assert = function () {
@@ -27,8 +28,74 @@ function _utils() {
27
28
  }
28
29
  var _Environment = _interopRequireDefault(require("./Environment"));
29
30
  var _projectPath = require("../projectPath");
31
+ var _EnvironmentManager = require("../EnvironmentManager");
30
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
33
  const internalConfigToConfig = new (_utils().DefaultWeakMap)(() => new WeakMap());
34
+
35
+ /**
36
+ * Implements read tracking over an object.
37
+ *
38
+ * Calling this function with a non-trivial object like a class instance will fail to work.
39
+ *
40
+ * We track reads to fields that resolve to:
41
+ *
42
+ * - primitive values
43
+ * - arrays
44
+ *
45
+ * That is, reading a nested field `a.b.c` will make a single call to `onRead` with the path
46
+ * `['a', 'b', 'c']`.
47
+ *
48
+ * In case the value is null or an array, we will track the read as well.
49
+ *
50
+ * Iterating over `Object.keys(obj.field)` will register a read for the `['field']` path.
51
+ * Other reads work normally.
52
+ *
53
+ * @example
54
+ *
55
+ * const usedPaths = new Set();
56
+ * const onRead = (path) => {
57
+ * usedPaths.add(path);
58
+ * };
59
+ *
60
+ * const config = makeConfigProxy(onRead, {a: {b: {c: 'd'}}})
61
+ * console.log(config.a.b.c);
62
+ * console.log(Array.from(usedPaths));
63
+ * // We get a single read for the path
64
+ * // ['a', 'b', 'c']
65
+ *
66
+ */
67
+ function makeConfigProxy(onRead, config) {
68
+ const reportedPaths = new Set();
69
+ const reportPath = path => {
70
+ if (reportedPaths.has(path)) {
71
+ return;
72
+ }
73
+ reportedPaths.add(path);
74
+ onRead(path);
75
+ };
76
+ const makeProxy = (target, path) => {
77
+ return new Proxy(target, {
78
+ ownKeys(target) {
79
+ reportPath(path);
80
+
81
+ // $FlowFixMe
82
+ return Object.getOwnPropertyNames(target);
83
+ },
84
+ get(target, prop) {
85
+ // $FlowFixMe
86
+ const value = target[prop];
87
+ if (typeof value === 'object' && value != null && !Array.isArray(value)) {
88
+ return makeProxy(value, [...path, prop]);
89
+ }
90
+ reportPath([...path, prop]);
91
+ return value;
92
+ }
93
+ });
94
+ };
95
+
96
+ // $FlowFixMe
97
+ return makeProxy(config, []);
98
+ }
32
99
  class PublicConfig {
33
100
  #config /*: Config */;
34
101
  #pkg /*: ?PackageJSON */;
@@ -46,7 +113,7 @@ class PublicConfig {
46
113
  return this;
47
114
  }
48
115
  get env() {
49
- return new _Environment.default(this.#config.env, this.#options);
116
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#config.env), this.#options);
50
117
  }
51
118
  get searchPath() {
52
119
  return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#config.searchPath);
@@ -119,13 +186,32 @@ class PublicConfig {
119
186
  });
120
187
  if (pkg && pkg.contents[packageKey]) {
121
188
  // Invalidate only when the package key changes
122
- this.invalidateOnConfigKeyChange(pkg.filePath, packageKey);
189
+ this.invalidateOnConfigKeyChange(pkg.filePath, [packageKey]);
123
190
  return {
124
191
  contents: pkg.contents[packageKey],
125
192
  filePath: pkg.filePath
126
193
  };
127
194
  }
128
195
  }
196
+ const readTracking = options === null || options === void 0 ? void 0 : options.readTracking;
197
+ if (readTracking === true) {
198
+ for (let fileName of fileNames) {
199
+ const config = await this.getConfigFrom(searchPath, [fileName], {
200
+ exclude: true
201
+ });
202
+ if (config != null) {
203
+ return Promise.resolve({
204
+ contents: makeConfigProxy(keyPath => {
205
+ this.invalidateOnConfigKeyChange(config.filePath, keyPath);
206
+ }, config.contents),
207
+ filePath: config.filePath
208
+ });
209
+ }
210
+ }
211
+
212
+ // fall through so that file above invalidations are registered
213
+ }
214
+
129
215
  if (fileNames.length === 0) {
130
216
  return null;
131
217
  }
@@ -190,7 +276,9 @@ class PublicConfig {
190
276
  if (this.#pkg) {
191
277
  return this.#pkg;
192
278
  }
193
- let pkgConfig = await this.getConfig(['package.json']);
279
+ let pkgConfig = await this.getConfig(['package.json'], {
280
+ readTracking: true
281
+ });
194
282
  if (!pkgConfig) {
195
283
  return null;
196
284
  }
@@ -19,6 +19,7 @@ var _Target = _interopRequireDefault(require("./Target"));
19
19
  var _Symbols = require("./Symbols");
20
20
  var _projectPath = require("../projectPath");
21
21
  var _utils = require("../utils");
22
+ var _EnvironmentManager = require("../EnvironmentManager");
22
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
24
  const SpecifierTypeNames = Object.keys(_types.SpecifierType);
24
25
  const PriorityNames = Object.keys(_types.Priority);
@@ -80,7 +81,7 @@ class Dependency {
80
81
  return (0, _utils.fromInternalSourceLocation)(this.#options.projectRoot, this.#dep.loc);
81
82
  }
82
83
  get env() {
83
- return new _Environment.default(this.#dep.env, this.#options);
84
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#dep.env), this.#options);
84
85
  }
85
86
  get packageConditions() {
86
87
  // Merge custom conditions with conditions stored as bitflags.
@@ -38,6 +38,7 @@ var _projectPath = require("../projectPath");
38
38
  var _types = require("../types");
39
39
  var _BundleGroup = _interopRequireWildcard(require("./BundleGroup"));
40
40
  var _IdentifierRegistry = require("../IdentifierRegistry");
41
+ var _EnvironmentManager = require("../EnvironmentManager");
41
42
  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); }
42
43
  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; }
43
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -149,7 +150,7 @@ class MutableBundleGraph extends _BundleGraph.default {
149
150
  id: bundleId,
150
151
  hashReference: this.#options.shouldContentHash ? _constants.HASH_REF_PREFIX + bundleId : bundleId.slice(-8),
151
152
  type: opts.entryAsset ? opts.entryAsset.type : opts.type,
152
- env: opts.env ? (0, _Environment.environmentToInternalEnvironment)(opts.env) : (0, _nullthrows().default)(entryAsset).env,
153
+ env: opts.env ? (0, _EnvironmentManager.toEnvironmentRef)((0, _Environment.environmentToInternalEnvironment)(opts.env)) : (0, _nullthrows().default)(entryAsset).env,
153
154
  entryAssetIds: entryAsset ? [entryAsset.id] : [],
154
155
  mainEntryId: entryAsset === null || entryAsset === void 0 ? void 0 : entryAsset.id,
155
156
  pipeline: opts.entryAsset ? opts.entryAsset.pipeline : opts.pipeline,
@@ -15,6 +15,7 @@ function _nullthrows() {
15
15
  var _Environment = _interopRequireDefault(require("./Environment"));
16
16
  var _projectPath = require("../projectPath");
17
17
  var _utils = require("../utils");
18
+ var _EnvironmentManager = require("../EnvironmentManager");
18
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
20
  const inspect = Symbol.for('nodejs.util.inspect.custom');
20
21
  const internalTargetToTarget = new WeakMap();
@@ -44,7 +45,7 @@ class Target {
44
45
  return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#target.distDir);
45
46
  }
46
47
  get env() {
47
- return new _Environment.default(this.#target.env, this.#options);
48
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#target.env), this.#options);
48
49
  }
49
50
  get name() {
50
51
  return this.#target.name;
@@ -26,6 +26,13 @@ function _nullthrows() {
26
26
  };
27
27
  return data;
28
28
  }
29
+ function _featureFlags() {
30
+ const data = require("@atlaspack/feature-flags");
31
+ _featureFlags = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
29
36
  function _utils() {
30
37
  const data = require("@atlaspack/utils");
31
38
  _utils = function () {
@@ -116,7 +123,12 @@ class AssetGraphBuilder {
116
123
  this.shouldBuildLazily = shouldBuildLazily ?? false;
117
124
  this.lazyIncludes = lazyIncludes ?? [];
118
125
  this.lazyExcludes = lazyExcludes ?? [];
119
- this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
126
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
127
+ const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
128
+ this.cacheKey = `AssetGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
129
+ } else {
130
+ this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
131
+ }
120
132
  this.isSingleChangeRebuild = api.getInvalidSubRequests().filter(req => req.requestType === 'asset_request').length === 1;
121
133
  this.queue = new (_utils().PromiseQueue)();
122
134
  assetGraph.onNodeRemoved = nodeId => {
@@ -26,9 +26,18 @@ function _logger() {
26
26
  };
27
27
  return data;
28
28
  }
29
+ function _featureFlags() {
30
+ const data = require("@atlaspack/feature-flags");
31
+ _featureFlags = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
29
36
  var _AssetGraph = _interopRequireWildcard(require("../AssetGraph"));
30
37
  var _RequestTracker = require("../RequestTracker");
31
38
  var _SymbolPropagation = require("../SymbolPropagation");
39
+ var _EnvironmentManager = require("../EnvironmentManager");
40
+ var _Environment = require("../Environment");
32
41
  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); }
33
42
  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; }
34
43
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -137,8 +146,11 @@ function getAssetGraph(serializedGraph) {
137
146
  let id = asset.id;
138
147
  asset.committed = true;
139
148
  asset.contentKey = id;
140
- asset.env.id = getEnvId(asset.env);
149
+ asset.env.id = (0, _featureFlags().getFeatureFlag)('environmentDeduplication') ?
150
+ // TODO: Rust can do this and avoid copying a significant amount of data over
151
+ (0, _Environment.getEnvironmentHash)(asset.env) : getEnvId(asset.env);
141
152
  asset.mapKey = `map:${asset.id}`;
153
+ asset.env = (0, _EnvironmentManager.toEnvironmentRef)(asset.env);
142
154
 
143
155
  // This is populated later when we map the edges between assets and dependencies
144
156
  asset.dependencies = new Map();
@@ -162,7 +174,10 @@ function getAssetGraph(serializedGraph) {
162
174
  let id = node.value.id;
163
175
  let dependency = node.value.dependency;
164
176
  dependency.id = id;
165
- dependency.env.id = getEnvId(dependency.env);
177
+ dependency.env.id = (0, _featureFlags().getFeatureFlag)('environmentDeduplication') ?
178
+ // TODO: Rust can do this and avoid copying a significant amount of data over
179
+ (0, _Environment.getEnvironmentHash)(dependency.env) : getEnvId(dependency.env);
180
+ dependency.env = (0, _EnvironmentManager.toEnvironmentRef)(dependency.env);
166
181
  if (dependency.symbols != null) {
167
182
  var _dependency$symbols;
168
183
  dependency.symbols = new Map((_dependency$symbols = dependency.symbols) === null || _dependency$symbols === void 0 ? void 0 : _dependency$symbols.map(mapSymbols));
@@ -31,6 +31,7 @@ var _ConfigRequest = require("./ConfigRequest");
31
31
  var _projectPath = require("../projectPath");
32
32
  var _ReporterRunner = require("../ReporterRunner");
33
33
  var _RequestTracker = require("../RequestTracker");
34
+ var _EnvironmentManager = require("../EnvironmentManager");
34
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
36
  function createAssetRequest(input) {
36
37
  return {
@@ -42,7 +43,7 @@ function createAssetRequest(input) {
42
43
  }
43
44
  const type = 'asset_request';
44
45
  function getId(input) {
45
- return (0, _rust().hashString)(type + (0, _projectPath.fromProjectPathRelative)(input.filePath) + input.env.id + String(input.isSource) + String(input.sideEffects) + (input.code ?? '') + ':' + (input.pipeline ?? '') + ':' + (input.query ?? ''));
46
+ return (0, _rust().hashString)(type + (0, _projectPath.fromProjectPathRelative)(input.filePath) + (0, _EnvironmentManager.toEnvironmentId)(input.env) + String(input.isSource) + String(input.sideEffects) + (input.code ?? '') + ':' + (input.pipeline ?? '') + ':' + (input.query ?? ''));
46
47
  }
47
48
  async function run({
48
49
  input,
@@ -32,6 +32,13 @@ function _logger() {
32
32
  };
33
33
  return data;
34
34
  }
35
+ function _featureFlags() {
36
+ const data = require("@atlaspack/feature-flags");
37
+ _featureFlags = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
35
42
  function _diagnostic() {
36
43
  const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
37
44
  _diagnostic = function () {
@@ -225,7 +232,12 @@ class BundlerRunner {
225
232
  this.devDepRequests = new Map();
226
233
  this.configs = new Map();
227
234
  this.pluginOptions = new _PluginOptions.default((0, _utils2.optionsProxy)(this.options, api.invalidateOnOptionChange));
228
- this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
235
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
236
+ const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
237
+ this.cacheKey = `BundleGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
238
+ } else {
239
+ this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
240
+ }
229
241
  }
230
242
  async loadConfigs() {
231
243
  // Load all configs up front so we can use them in the cache key
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getConfigHash = getConfigHash;
7
7
  exports.getConfigKeyContentHash = getConfigKeyContentHash;
8
8
  exports.getConfigRequests = getConfigRequests;
9
+ exports.getValueAtPath = getValueAtPath;
9
10
  exports.loadPluginConfig = loadPluginConfig;
10
11
  exports.runConfigRequest = runConfigRequest;
11
12
  function _utils() {
@@ -86,19 +87,41 @@ async function loadPluginConfig(loadedPlugin, config, options) {
86
87
  });
87
88
  }
88
89
  }
90
+
91
+ /**
92
+ * Return value at a given key path within an object.
93
+ *
94
+ * @example
95
+ * const obj = { a: { b: { c: 'd' } } };
96
+ * getValueAtPath(obj, ['a', 'b', 'c']); // 'd'
97
+ * getValueAtPath(obj, ['a', 'b', 'd']); // undefined
98
+ * getValueAtPath(obj, ['a', 'b']); // { c: 'd' }
99
+ * getValueAtPath(obj, ['a', 'b', 'c', 'd']); // undefined
100
+ */
101
+ function getValueAtPath(obj, key) {
102
+ let current = obj;
103
+ for (let part of key) {
104
+ if (current == null) {
105
+ return undefined;
106
+ }
107
+ current = current[part];
108
+ }
109
+ return current;
110
+ }
89
111
  const configKeyCache = (0, _buildCache().createBuildCache)();
90
112
  async function getConfigKeyContentHash(filePath, configKey, options) {
91
- let cacheKey = `${(0, _projectPath.fromProjectPathRelative)(filePath)}:${configKey}`;
113
+ let cacheKey = `${(0, _projectPath.fromProjectPathRelative)(filePath)}:${JSON.stringify(configKey)}`;
92
114
  let cachedValue = configKeyCache.get(cacheKey);
93
115
  if (cachedValue) {
94
116
  return cachedValue;
95
117
  }
96
- let conf = await (0, _utils().readConfig)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, filePath));
97
- if (conf == null || conf.config[configKey] == null) {
118
+ const conf = await (0, _utils().readConfig)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, filePath));
119
+ const value = getValueAtPath(conf === null || conf === void 0 ? void 0 : conf.config, configKey);
120
+ if (conf == null || value == null) {
98
121
  // This can occur when a config key has been removed entirely during `respondToFSEvents`
99
122
  return '';
100
123
  }
101
- let contentHash = typeof conf.config[configKey] === 'object' ? (0, _utils().hashObject)(conf.config[configKey]) : (0, _rust().hashString)(JSON.stringify(conf.config[configKey]));
124
+ const contentHash = typeof value === 'object' ? (0, _utils().hashObject)(value) : (0, _rust().hashString)(JSON.stringify(value));
102
125
  configKeyCache.set(cacheKey, contentHash);
103
126
  return contentHash;
104
127
  }