@atlaspack/core 2.17.3 → 2.18.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 (67) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/lib/AssetGraph.js +17 -6
  3. package/lib/Atlaspack.js +3 -1
  4. package/lib/BundleGraph.js +6 -5
  5. package/lib/Dependency.js +6 -2
  6. package/lib/Environment.js +4 -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 +191 -89
  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/public/Asset.js +3 -2
  16. package/lib/public/Bundle.js +2 -1
  17. package/lib/public/BundleGraph.js +21 -5
  18. package/lib/public/Config.js +98 -3
  19. package/lib/public/Dependency.js +2 -1
  20. package/lib/public/MutableBundleGraph.js +2 -1
  21. package/lib/public/Target.js +2 -1
  22. package/lib/requests/AssetGraphRequest.js +13 -1
  23. package/lib/requests/AssetRequest.js +2 -1
  24. package/lib/requests/BundleGraphRequest.js +13 -1
  25. package/lib/requests/ConfigRequest.js +27 -4
  26. package/lib/requests/TargetRequest.js +18 -16
  27. package/lib/requests/WriteBundleRequest.js +15 -3
  28. package/lib/requests/WriteBundlesRequest.js +1 -0
  29. package/lib/resolveOptions.js +4 -2
  30. package/package.json +13 -13
  31. package/src/AssetGraph.js +12 -6
  32. package/src/Atlaspack.js +5 -4
  33. package/src/BundleGraph.js +13 -8
  34. package/src/Dependency.js +13 -5
  35. package/src/Environment.js +8 -5
  36. package/src/EnvironmentManager.js +145 -0
  37. package/src/InternalConfig.js +6 -5
  38. package/src/PackagerRunner.js +72 -20
  39. package/src/RequestTracker.js +330 -146
  40. package/src/UncommittedAsset.js +23 -3
  41. package/src/applyRuntimes.js +6 -1
  42. package/src/assetUtils.js +4 -3
  43. package/src/atlaspack-v3/worker/compat/plugin-config.js +9 -5
  44. package/src/atlaspack-v3/worker/worker.js +7 -0
  45. package/src/public/Asset.js +9 -2
  46. package/src/public/Bundle.js +2 -1
  47. package/src/public/BundleGraph.js +22 -5
  48. package/src/public/Config.js +129 -14
  49. package/src/public/Dependency.js +2 -1
  50. package/src/public/MutableBundleGraph.js +2 -1
  51. package/src/public/Target.js +2 -1
  52. package/src/requests/AssetGraphRequest.js +13 -3
  53. package/src/requests/AssetRequest.js +2 -1
  54. package/src/requests/BundleGraphRequest.js +13 -3
  55. package/src/requests/ConfigRequest.js +33 -9
  56. package/src/requests/TargetRequest.js +19 -25
  57. package/src/requests/WriteBundleRequest.js +14 -8
  58. package/src/requests/WriteBundlesRequest.js +1 -0
  59. package/src/resolveOptions.js +4 -2
  60. package/src/types.js +9 -7
  61. package/test/Environment.test.js +43 -34
  62. package/test/EnvironmentManager.test.js +192 -0
  63. package/test/PublicEnvironment.test.js +10 -7
  64. package/test/RequestTracker.test.js +115 -3
  65. package/test/public/Config.test.js +108 -0
  66. package/test/requests/ConfigRequest.test.js +187 -3
  67. package/test/test-utils.js +4 -9
@@ -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,81 @@ function _utils() {
27
28
  }
28
29
  var _Environment = _interopRequireDefault(require("./Environment"));
29
30
  var _projectPath = require("../projectPath");
31
+ function _featureFlags() {
32
+ const data = require("@atlaspack/feature-flags");
33
+ _featureFlags = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ var _EnvironmentManager = require("../EnvironmentManager");
30
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
40
  const internalConfigToConfig = new (_utils().DefaultWeakMap)(() => new WeakMap());
41
+
42
+ /**
43
+ * Implements read tracking over an object.
44
+ *
45
+ * Calling this function with a non-trivial object like a class instance will fail to work.
46
+ *
47
+ * We track reads to fields that resolve to:
48
+ *
49
+ * - primitive values
50
+ * - arrays
51
+ *
52
+ * That is, reading a nested field `a.b.c` will make a single call to `onRead` with the path
53
+ * `['a', 'b', 'c']`.
54
+ *
55
+ * In case the value is null or an array, we will track the read as well.
56
+ *
57
+ * Iterating over `Object.keys(obj.field)` will register a read for the `['field']` path.
58
+ * Other reads work normally.
59
+ *
60
+ * @example
61
+ *
62
+ * const usedPaths = new Set();
63
+ * const onRead = (path) => {
64
+ * usedPaths.add(path);
65
+ * };
66
+ *
67
+ * const config = makeConfigProxy(onRead, {a: {b: {c: 'd'}}})
68
+ * console.log(config.a.b.c);
69
+ * console.log(Array.from(usedPaths));
70
+ * // We get a single read for the path
71
+ * // ['a', 'b', 'c']
72
+ *
73
+ */
74
+ function makeConfigProxy(onRead, config) {
75
+ const reportedPaths = new Set();
76
+ const reportPath = path => {
77
+ if (reportedPaths.has(path)) {
78
+ return;
79
+ }
80
+ reportedPaths.add(path);
81
+ onRead(path);
82
+ };
83
+ const makeProxy = (target, path) => {
84
+ return new Proxy(target, {
85
+ ownKeys(target) {
86
+ reportPath(path);
87
+
88
+ // $FlowFixMe
89
+ return Object.getOwnPropertyNames(target);
90
+ },
91
+ get(target, prop) {
92
+ // $FlowFixMe
93
+ const value = target[prop];
94
+ if (typeof value === 'object' && value != null && !Array.isArray(value)) {
95
+ return makeProxy(value, [...path, prop]);
96
+ }
97
+ reportPath([...path, prop]);
98
+ return value;
99
+ }
100
+ });
101
+ };
102
+
103
+ // $FlowFixMe
104
+ return makeProxy(config, []);
105
+ }
32
106
  class PublicConfig {
33
107
  #config /*: Config */;
34
108
  #pkg /*: ?PackageJSON */;
@@ -46,7 +120,7 @@ class PublicConfig {
46
120
  return this;
47
121
  }
48
122
  get env() {
49
- return new _Environment.default(this.#config.env, this.#options);
123
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#config.env), this.#options);
50
124
  }
51
125
  get searchPath() {
52
126
  return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#config.searchPath);
@@ -119,13 +193,32 @@ class PublicConfig {
119
193
  });
120
194
  if (pkg && pkg.contents[packageKey]) {
121
195
  // Invalidate only when the package key changes
122
- this.invalidateOnConfigKeyChange(pkg.filePath, packageKey);
196
+ this.invalidateOnConfigKeyChange(pkg.filePath, [packageKey]);
123
197
  return {
124
198
  contents: pkg.contents[packageKey],
125
199
  filePath: pkg.filePath
126
200
  };
127
201
  }
128
202
  }
203
+ const readTracking = options === null || options === void 0 ? void 0 : options.readTracking;
204
+ if (readTracking === true) {
205
+ for (let fileName of fileNames) {
206
+ const config = await this.getConfigFrom(searchPath, [fileName], {
207
+ exclude: true
208
+ });
209
+ if (config != null) {
210
+ return Promise.resolve({
211
+ contents: makeConfigProxy(keyPath => {
212
+ this.invalidateOnConfigKeyChange(config.filePath, keyPath);
213
+ }, config.contents),
214
+ filePath: config.filePath
215
+ });
216
+ }
217
+ }
218
+
219
+ // fall through so that file above invalidations are registered
220
+ }
221
+
129
222
  if (fileNames.length === 0) {
130
223
  return null;
131
224
  }
@@ -190,7 +283,9 @@ class PublicConfig {
190
283
  if (this.#pkg) {
191
284
  return this.#pkg;
192
285
  }
193
- let pkgConfig = await this.getConfig(['package.json']);
286
+ let pkgConfig = await this.getConfig(['package.json'], {
287
+ readTracking: (0, _featureFlags().getFeatureFlag)('granularTsConfigInvalidation')
288
+ });
194
289
  if (!pkgConfig) {
195
290
  return null;
196
291
  }
@@ -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 => {
@@ -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
  }
@@ -69,6 +69,7 @@ var _Environment2 = require("../public/Environment");
69
69
  var _utils2 = require("../utils");
70
70
  var _projectPath = require("../projectPath");
71
71
  var _RequestTracker = require("../RequestTracker");
72
+ var _EnvironmentManager = require("../EnvironmentManager");
72
73
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
73
74
  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); }
74
75
  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; }
@@ -245,7 +246,7 @@ class TargetResolver {
245
246
  }
246
247
  });
247
248
  }
248
- if (!_Environment2.BROWSER_ENVS.has(targets[0].env.context)) {
249
+ if (!_Environment2.BROWSER_ENVS.has((0, _EnvironmentManager.fromEnvironmentId)(targets[0].env).context)) {
249
250
  throw new (_diagnostic().default)({
250
251
  diagnostic: {
251
252
  message: `Only browser targets are supported in serve mode`,
@@ -1073,22 +1074,23 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1073
1074
 
1074
1075
  // Resolve relevant engines for context.
1075
1076
  let engines;
1076
- switch (target.env.context) {
1077
+ const env = (0, _EnvironmentManager.fromEnvironmentId)(target.env);
1078
+ switch (env.context) {
1077
1079
  case 'browser':
1078
1080
  case 'web-worker':
1079
1081
  case 'service-worker':
1080
1082
  case 'worklet':
1081
1083
  {
1082
- let browsers = target.env.engines.browsers;
1084
+ let browsers = env.engines.browsers;
1083
1085
  engines = Array.isArray(browsers) ? browsers.join(', ') : browsers;
1084
1086
  break;
1085
1087
  }
1086
1088
  case 'node':
1087
- engines = target.env.engines.node;
1089
+ engines = env.engines.node;
1088
1090
  break;
1089
1091
  case 'electron-main':
1090
1092
  case 'electron-renderer':
1091
- engines = target.env.engines.electron;
1093
+ engines = env.engines.electron;
1092
1094
  break;
1093
1095
  }
1094
1096
  let highlights = [];
@@ -1124,7 +1126,7 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1124
1126
  highlight.defined = (0, _diagnostic().md)`${key} defined here`;
1125
1127
  }
1126
1128
  if (keyInfo.inferred) {
1127
- highlight.inferred.push((0, _diagnostic().md)`${key} to be ${JSON.stringify(target.env[key])}`);
1129
+ highlight.inferred.push((0, _diagnostic().md)`${key} to be ${JSON.stringify(env[key])}`);
1128
1130
  }
1129
1131
  }
1130
1132
 
@@ -1150,12 +1152,12 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1150
1152
 
1151
1153
  // Format includeNodeModules to be human readable.
1152
1154
  let includeNodeModules;
1153
- if (typeof target.env.includeNodeModules === 'boolean') {
1154
- includeNodeModules = String(target.env.includeNodeModules);
1155
- } else if (Array.isArray(target.env.includeNodeModules)) {
1156
- includeNodeModules = 'only ' + listFormat.format(target.env.includeNodeModules.map(m => JSON.stringify(m)));
1157
- } else if (target.env.includeNodeModules && typeof target.env.includeNodeModules === 'object') {
1158
- includeNodeModules = 'all except ' + listFormat.format(Object.entries(target.env.includeNodeModules).filter(([, v]) => v === false).map(([k]) => JSON.stringify(k)));
1155
+ if (typeof env.includeNodeModules === 'boolean') {
1156
+ includeNodeModules = String(env.includeNodeModules);
1157
+ } else if (Array.isArray(env.includeNodeModules)) {
1158
+ includeNodeModules = 'only ' + listFormat.format(env.includeNodeModules.map(m => JSON.stringify(m)));
1159
+ } else if (env.includeNodeModules && typeof env.includeNodeModules === 'object') {
1160
+ includeNodeModules = 'all except ' + listFormat.format(Object.entries(env.includeNodeModules).filter(([, v]) => v === false).map(([k]) => JSON.stringify(k)));
1159
1161
  }
1160
1162
  let format = v => v.message != null ? _diagnostic().md.italic(v.message) : '';
1161
1163
  _logger().default.verbose({
@@ -1164,12 +1166,12 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1164
1166
 
1165
1167
  **Entry**: ${_path().default.relative(process.cwd(), (0, _projectPath.fromProjectPath)(options.projectRoot, input.filePath))}
1166
1168
  **Output**: ${_path().default.relative(process.cwd(), output)}
1167
- **Format**: ${target.env.outputFormat} ${format(info.outputFormat)}
1168
- **Context**: ${target.env.context} ${format(info.context)}
1169
+ **Format**: ${env.outputFormat} ${format(info.outputFormat)}
1170
+ **Context**: ${env.context} ${format(info.context)}
1169
1171
  **Engines**: ${engines || ''} ${format(info.engines)}
1170
- **Library Mode**: ${String(target.env.isLibrary)} ${format(info.isLibrary)}
1172
+ **Library Mode**: ${String(env.isLibrary)} ${format(info.isLibrary)}
1171
1173
  **Include Node Modules**: ${includeNodeModules} ${format(info.includeNodeModules)}
1172
- **Optimize**: ${String(target.env.shouldOptimize)} ${format(info.shouldOptimize)}`,
1174
+ **Optimize**: ${String(env.shouldOptimize)} ${format(info.shouldOptimize)}`,
1173
1175
  codeFrames: target.loc ? [{
1174
1176
  filePath: targetFilePath,
1175
1177
  codeHighlights: highlights
@@ -61,6 +61,14 @@ function _profiler() {
61
61
  return data;
62
62
  }
63
63
  var _RequestTracker = require("../RequestTracker");
64
+ function _featureFlags() {
65
+ const data = require("@atlaspack/feature-flags");
66
+ _featureFlags = function () {
67
+ return data;
68
+ };
69
+ return data;
70
+ }
71
+ var _EnvironmentManager = require("../EnvironmentManager");
64
72
  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); }
65
73
  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; }
66
74
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -114,7 +122,8 @@ async function run({
114
122
  let cacheKeys = info.cacheKeys;
115
123
  let mapKey = cacheKeys.map;
116
124
  let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
117
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline) {
125
+ const env = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
126
+ if (mapKey && env.sourceMap && !env.sourceMap.inline) {
118
127
  api.invalidateOnFileDelete((0, _projectPath.toProjectPath)(options.projectRoot, fullPath + '.map'));
119
128
  }
120
129
  let dir = _path().default.dirname(fullPath);
@@ -145,11 +154,14 @@ async function run({
145
154
  } = await (0, _DevDepRequest.getDevDepRequests)(api);
146
155
  (0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, options, config);
147
156
  await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api);
148
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline && (await options.cache.has(mapKey))) {
149
- await writeFiles((0, _utils().blobToStream)(await options.cache.getBlob(mapKey)), info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
157
+ const hasSourceMap = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.hasLargeBlob(mapKey) : await options.cache.has(mapKey);
158
+ if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
159
+ const mapEntry = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.getLargeBlob(mapKey) : await options.cache.getBlob(mapKey);
160
+ await writeFiles((0, _utils().blobToStream)(mapEntry), info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
150
161
  }
151
162
  let res = {
152
163
  filePath,
164
+ bundleId: bundle.id,
153
165
  type: info.type,
154
166
  stats: {
155
167
  size,
@@ -76,6 +76,7 @@ async function run({
76
76
  let name = (0, _nullthrows().default)(bundle.name, `Expected ${bundle.type} bundle to have a name`).replace(bundle.hashReference, hash);
77
77
  res.set(bundle.id, {
78
78
  filePath: (0, _projectPath.joinProjectPath)(bundle.target.distDir, name),
79
+ bundleId: bundle.id,
79
80
  type: bundle.type,
80
81
  // FIXME: this is wrong if the packager changes the type...
81
82
  stats: {
@@ -144,8 +144,10 @@ async function resolveOptions(initialOptions) {
144
144
  return initialOptions.cache;
145
145
  }
146
146
  const needsRustLmdbCache = (0, _featureFlags().getFeatureFlag)('atlaspackV3');
147
- if (!needsRustLmdbCache && !(outputFS instanceof _fs().NodeFS)) {
148
- return new (_cache().FSCache)(outputFS, cacheDir);
147
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
148
+ if (!needsRustLmdbCache && !(outputFS instanceof _fs().NodeFS)) {
149
+ return new (_cache().FSCache)(outputFS, cacheDir);
150
+ }
149
151
  }
150
152
  return new (_cache().LMDBLiteCache)(cacheDir);
151
153
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.17.3",
3
+ "version": "2.18.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,20 +23,20 @@
23
23
  "dependencies": {
24
24
  "@mischnic/json-sourcemap": "^0.1.0",
25
25
  "@atlaspack/build-cache": "2.13.3",
26
- "@atlaspack/cache": "3.2.3",
26
+ "@atlaspack/cache": "3.2.5",
27
27
  "@atlaspack/diagnostic": "2.14.1",
28
28
  "@atlaspack/events": "2.14.1",
29
- "@atlaspack/feature-flags": "2.15.1",
30
- "@atlaspack/fs": "2.15.3",
31
- "@atlaspack/graph": "3.4.6",
32
- "@atlaspack/logger": "2.14.8",
33
- "@atlaspack/package-manager": "2.14.8",
34
- "@atlaspack/plugin": "2.14.8",
35
- "@atlaspack/profiler": "2.14.6",
36
- "@atlaspack/rust": "3.3.3",
37
- "@atlaspack/types": "2.14.8",
38
- "@atlaspack/utils": "2.14.8",
39
- "@atlaspack/workers": "2.14.8",
29
+ "@atlaspack/feature-flags": "2.16.0",
30
+ "@atlaspack/fs": "2.15.5",
31
+ "@atlaspack/graph": "3.4.7",
32
+ "@atlaspack/logger": "2.14.10",
33
+ "@atlaspack/package-manager": "2.14.10",
34
+ "@atlaspack/plugin": "2.14.10",
35
+ "@atlaspack/profiler": "2.14.8",
36
+ "@atlaspack/rust": "3.3.5",
37
+ "@atlaspack/types": "2.15.0",
38
+ "@atlaspack/utils": "2.14.10",
39
+ "@atlaspack/workers": "2.14.10",
40
40
  "@parcel/source-map": "^2.1.1",
41
41
  "base-x": "^3.0.8",
42
42
  "browserslist": "^4.6.6",
package/src/AssetGraph.js CHANGED
@@ -29,6 +29,8 @@ import nullthrows from 'nullthrows';
29
29
  import {ContentGraph} from '@atlaspack/graph';
30
30
  import {createDependency} from './Dependency';
31
31
  import {type ProjectPath, fromProjectPathRelative} from './projectPath';
32
+ import {fromEnvironmentId, toEnvironmentId} from './EnvironmentManager';
33
+ import {getFeatureFlag} from '@atlaspack/feature-flags';
32
34
 
33
35
  type InitOpts = {|
34
36
  entries?: Array<ProjectPath>,
@@ -65,7 +67,7 @@ export function nodeFromAssetGroup(assetGroup: AssetGroup): AssetGroupNode {
65
67
  return {
66
68
  id: hashString(
67
69
  fromProjectPathRelative(assetGroup.filePath) +
68
- assetGroup.env.id +
70
+ toEnvironmentId(assetGroup.env) +
69
71
  String(assetGroup.isSource) +
70
72
  String(assetGroup.sideEffects) +
71
73
  (assetGroup.code ?? '') +
@@ -149,14 +151,18 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
149
151
 
150
152
  // Deduplicates Environments by making them referentially equal
151
153
  normalizeEnvironment(input: Asset | Dependency | AssetGroup) {
152
- let {id, context} = input.env;
154
+ if (getFeatureFlag('environmentDeduplication')) {
155
+ return;
156
+ }
157
+
158
+ let {id, context} = fromEnvironmentId(input.env);
153
159
  let idAndContext = `${id}-${context}`;
154
160
 
155
161
  let env = this.envCache.get(idAndContext);
156
162
  if (env) {
157
163
  input.env = env;
158
164
  } else {
159
- this.envCache.set(idAndContext, input.env);
165
+ this.envCache.set(idAndContext, fromEnvironmentId(input.env));
160
166
  }
161
167
  }
162
168
 
@@ -235,13 +241,13 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
235
241
  env: target.env,
236
242
  isEntry: true,
237
243
  needsStableName: true,
238
- symbols: target.env.isLibrary
244
+ symbols: fromEnvironmentId(target.env).isLibrary
239
245
  ? new Map([['*', {local: '*', isWeak: true, loc: null}]])
240
246
  : undefined,
241
247
  }),
242
248
  );
243
249
 
244
- if (node.value.env.isLibrary) {
250
+ if (fromEnvironmentId(node.value.env).isLibrary) {
245
251
  // in library mode, all of the entry's symbols are "used"
246
252
  node.usedSymbolsDown.add('*');
247
253
  node.usedSymbolsUp.set('*', undefined);
@@ -428,7 +434,7 @@ export default class AssetGraph extends ContentGraph<AssetGraphNode> {
428
434
 
429
435
  let depIsDeferrable =
430
436
  d.symbols &&
431
- !(d.env.isLibrary && d.isEntry) &&
437
+ !(fromEnvironmentId(d.env).isLibrary && d.isEntry) &&
432
438
  !d.symbols.has('*') &&
433
439
  ![...d.symbols.keys()].some((symbol) => {
434
440
  let assetSymbol = resolvedAsset.symbols?.get(symbol)?.local;
package/src/Atlaspack.js CHANGED
@@ -533,10 +533,11 @@ export default class Atlaspack {
533
533
  nativeInvalid = await this.rustAtlaspack.respondToFsEvents(events);
534
534
  }
535
535
 
536
- let isInvalid = await this.#requestTracker.respondToFSEvents(
537
- events,
538
- Number.POSITIVE_INFINITY,
539
- );
536
+ let {didInvalidate: isInvalid} =
537
+ await this.#requestTracker.respondToFSEvents(
538
+ events,
539
+ Number.POSITIVE_INFINITY,
540
+ );
540
541
 
541
542
  if (
542
543
  (nativeInvalid || isInvalid) &&