@atlaspack/core 2.17.4 → 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 (54) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/lib/AssetGraph.js +17 -6
  3. package/lib/BundleGraph.js +6 -5
  4. package/lib/Dependency.js +6 -2
  5. package/lib/Environment.js +4 -3
  6. package/lib/EnvironmentManager.js +137 -0
  7. package/lib/InternalConfig.js +3 -2
  8. package/lib/PackagerRunner.js +10 -7
  9. package/lib/RequestTracker.js +20 -5
  10. package/lib/UncommittedAsset.js +3 -2
  11. package/lib/applyRuntimes.js +2 -1
  12. package/lib/assetUtils.js +2 -1
  13. package/lib/public/Asset.js +3 -2
  14. package/lib/public/Bundle.js +2 -1
  15. package/lib/public/Config.js +86 -19
  16. package/lib/public/Dependency.js +2 -1
  17. package/lib/public/MutableBundleGraph.js +2 -1
  18. package/lib/public/Target.js +2 -1
  19. package/lib/requests/AssetRequest.js +2 -1
  20. package/lib/requests/ConfigRequest.js +27 -4
  21. package/lib/requests/TargetRequest.js +18 -16
  22. package/lib/requests/WriteBundleRequest.js +5 -2
  23. package/lib/requests/WriteBundlesRequest.js +1 -0
  24. package/package.json +11 -11
  25. package/src/AssetGraph.js +12 -6
  26. package/src/BundleGraph.js +13 -8
  27. package/src/Dependency.js +13 -5
  28. package/src/Environment.js +8 -5
  29. package/src/EnvironmentManager.js +145 -0
  30. package/src/InternalConfig.js +6 -5
  31. package/src/PackagerRunner.js +12 -11
  32. package/src/RequestTracker.js +39 -13
  33. package/src/UncommittedAsset.js +7 -2
  34. package/src/applyRuntimes.js +6 -1
  35. package/src/assetUtils.js +4 -3
  36. package/src/atlaspack-v3/worker/compat/plugin-config.js +1 -1
  37. package/src/public/Asset.js +9 -2
  38. package/src/public/Bundle.js +2 -1
  39. package/src/public/Config.js +110 -29
  40. package/src/public/Dependency.js +2 -1
  41. package/src/public/MutableBundleGraph.js +2 -1
  42. package/src/public/Target.js +2 -1
  43. package/src/requests/AssetRequest.js +2 -1
  44. package/src/requests/ConfigRequest.js +33 -9
  45. package/src/requests/TargetRequest.js +19 -25
  46. package/src/requests/WriteBundleRequest.js +6 -7
  47. package/src/requests/WriteBundlesRequest.js +1 -0
  48. package/src/types.js +9 -7
  49. package/test/Environment.test.js +43 -34
  50. package/test/EnvironmentManager.test.js +192 -0
  51. package/test/PublicEnvironment.test.js +10 -7
  52. package/test/public/Config.test.js +108 -0
  53. package/test/requests/ConfigRequest.test.js +187 -3
  54. package/test/test-utils.js +3 -2
@@ -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 () {
@@ -34,8 +35,74 @@ function _featureFlags() {
34
35
  };
35
36
  return data;
36
37
  }
38
+ var _EnvironmentManager = require("../EnvironmentManager");
37
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
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
+ }
39
106
  class PublicConfig {
40
107
  #config /*: Config */;
41
108
  #pkg /*: ?PackageJSON */;
@@ -53,7 +120,7 @@ class PublicConfig {
53
120
  return this;
54
121
  }
55
122
  get env() {
56
- return new _Environment.default(this.#config.env, this.#options);
123
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#config.env), this.#options);
57
124
  }
58
125
  get searchPath() {
59
126
  return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#config.searchPath);
@@ -126,32 +193,30 @@ class PublicConfig {
126
193
  });
127
194
  if (pkg && pkg.contents[packageKey]) {
128
195
  // Invalidate only when the package key changes
129
- this.invalidateOnConfigKeyChange(pkg.filePath, packageKey);
196
+ this.invalidateOnConfigKeyChange(pkg.filePath, [packageKey]);
130
197
  return {
131
198
  contents: pkg.contents[packageKey],
132
199
  filePath: pkg.filePath
133
200
  };
134
201
  }
135
202
  }
136
- if ((0, _featureFlags().getFeatureFlag)('granularTsConfigInvalidation')) {
137
- const configKey = options === null || options === void 0 ? void 0 : options.configKey;
138
- if (configKey != null) {
139
- for (let fileName of fileNames) {
140
- let config = await this.getConfigFrom(searchPath, [fileName], {
141
- exclude: true
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
142
215
  });
143
- if (config && config.contents[configKey]) {
144
- // Invalidate only when the package key changes
145
- this.invalidateOnConfigKeyChange(config.filePath, configKey);
146
- return {
147
- contents: config.contents[configKey],
148
- filePath: config.filePath
149
- };
150
- }
151
216
  }
152
-
153
- // fall through so that file above invalidations are registered
154
217
  }
218
+
219
+ // fall through so that file above invalidations are registered
155
220
  }
156
221
 
157
222
  if (fileNames.length === 0) {
@@ -218,7 +283,9 @@ class PublicConfig {
218
283
  if (this.#pkg) {
219
284
  return this.#pkg;
220
285
  }
221
- let pkgConfig = await this.getConfig(['package.json']);
286
+ let pkgConfig = await this.getConfig(['package.json'], {
287
+ readTracking: (0, _featureFlags().getFeatureFlag)('granularTsConfigInvalidation')
288
+ });
222
289
  if (!pkgConfig) {
223
290
  return null;
224
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;
@@ -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,
@@ -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
@@ -68,6 +68,7 @@ function _featureFlags() {
68
68
  };
69
69
  return data;
70
70
  }
71
+ var _EnvironmentManager = require("../EnvironmentManager");
71
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); }
72
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; }
73
74
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -121,7 +122,8 @@ async function run({
121
122
  let cacheKeys = info.cacheKeys;
122
123
  let mapKey = cacheKeys.map;
123
124
  let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
124
- 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) {
125
127
  api.invalidateOnFileDelete((0, _projectPath.toProjectPath)(options.projectRoot, fullPath + '.map'));
126
128
  }
127
129
  let dir = _path().default.dirname(fullPath);
@@ -153,12 +155,13 @@ async function run({
153
155
  (0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, options, config);
154
156
  await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api);
155
157
  const hasSourceMap = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.hasLargeBlob(mapKey) : await options.cache.has(mapKey);
156
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline && hasSourceMap) {
158
+ if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
157
159
  const mapEntry = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.getLargeBlob(mapKey) : await options.cache.getBlob(mapKey);
158
160
  await writeFiles((0, _utils().blobToStream)(mapEntry), info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
159
161
  }
160
162
  let res = {
161
163
  filePath,
164
+ bundleId: bundle.id,
162
165
  type: info.type,
163
166
  stats: {
164
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: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.17.4",
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.4",
26
+ "@atlaspack/cache": "3.2.5",
27
27
  "@atlaspack/diagnostic": "2.14.1",
28
28
  "@atlaspack/events": "2.14.1",
29
29
  "@atlaspack/feature-flags": "2.16.0",
30
- "@atlaspack/fs": "2.15.4",
30
+ "@atlaspack/fs": "2.15.5",
31
31
  "@atlaspack/graph": "3.4.7",
32
- "@atlaspack/logger": "2.14.9",
33
- "@atlaspack/package-manager": "2.14.9",
34
- "@atlaspack/plugin": "2.14.9",
35
- "@atlaspack/profiler": "2.14.7",
36
- "@atlaspack/rust": "3.3.4",
37
- "@atlaspack/types": "2.14.9",
38
- "@atlaspack/utils": "2.14.9",
39
- "@atlaspack/workers": "2.14.9",
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;
@@ -24,7 +24,6 @@ import type {
24
24
  BundleNode,
25
25
  Dependency,
26
26
  DependencyNode,
27
- Environment,
28
27
  InternalSourceLocation,
29
28
  Target,
30
29
  Condition,
@@ -49,6 +48,8 @@ import {ISOLATED_ENVS} from './public/Environment';
49
48
  import {fromProjectPath, fromProjectPathRelative} from './projectPath';
50
49
  import {HASH_REF_PREFIX} from './constants';
51
50
  import {getFeatureFlag} from '@atlaspack/feature-flags';
51
+ import {fromEnvironmentId} from './EnvironmentManager';
52
+ import type {EnvironmentRef} from './EnvironmentManager';
52
53
 
53
54
  export const bundleGraphEdgeTypes = {
54
55
  // A lack of an edge type indicates to follow the edge while traversing
@@ -283,7 +284,7 @@ export default class BundleGraph {
283
284
  if (
284
285
  node.type === 'dependency' &&
285
286
  node.value.symbols != null &&
286
- node.value.env.shouldScopeHoist &&
287
+ fromEnvironmentId(node.value.env).shouldScopeHoist &&
287
288
  // Disable in dev mode because this feature is at odds with safeToIncrementallyBundle
288
289
  isProduction
289
290
  ) {
@@ -555,11 +556,11 @@ export default class BundleGraph {
555
556
  +needsStableName?: ?boolean,
556
557
  +bundleBehavior?: ?IBundleBehavior,
557
558
  +shouldContentHash: boolean,
558
- +env: Environment,
559
+ +env: EnvironmentRef,
559
560
  |}
560
561
  | {|
561
562
  +type: string,
562
- +env: Environment,
563
+ +env: EnvironmentRef,
563
564
  +uniqueKey: string,
564
565
  +target: Target,
565
566
  +needsStableName?: ?boolean,
@@ -1359,7 +1360,8 @@ export default class BundleGraph {
1359
1360
 
1360
1361
  if (
1361
1362
  descendant.type !== bundle.type ||
1362
- descendant.env.context !== bundle.env.context
1363
+ fromEnvironmentId(descendant.env).context !==
1364
+ fromEnvironmentId(bundle.env).context
1363
1365
  ) {
1364
1366
  actions.skipChildren();
1365
1367
  return;
@@ -1400,7 +1402,7 @@ export default class BundleGraph {
1400
1402
  // If a bundle's environment is isolated, it can't access assets present
1401
1403
  // in any ancestor bundles. Don't consider any assets reachable.
1402
1404
  if (
1403
- ISOLATED_ENVS.has(bundle.env.context) ||
1405
+ ISOLATED_ENVS.has(fromEnvironmentId(bundle.env).context) ||
1404
1406
  !bundle.isSplittable ||
1405
1407
  bundle.bundleBehavior === BundleBehavior.isolated ||
1406
1408
  bundle.bundleBehavior === BundleBehavior.inline
@@ -1454,7 +1456,8 @@ export default class BundleGraph {
1454
1456
  node.type === 'root' ||
1455
1457
  (node.type === 'bundle' &&
1456
1458
  (node.value.id === bundle.id ||
1457
- node.value.env.context !== bundle.env.context))
1459
+ fromEnvironmentId(node.value.env).context !==
1460
+ fromEnvironmentId(bundle.env).context))
1458
1461
  ) {
1459
1462
  isReachable = false;
1460
1463
  actions.stop();
@@ -2128,7 +2131,9 @@ export default class BundleGraph {
2128
2131
  hash.writeString(referencedBundle.id);
2129
2132
  }
2130
2133
 
2131
- hash.writeString(JSON.stringify(objectSortedEntriesDeep(bundle.env)));
2134
+ hash.writeString(
2135
+ JSON.stringify(objectSortedEntriesDeep(fromEnvironmentId(bundle.env))),
2136
+ );
2132
2137
  return hash.finish();
2133
2138
  }
2134
2139
 
package/src/Dependency.js CHANGED
@@ -8,7 +8,7 @@ import type {
8
8
  BundleBehavior as IBundleBehavior,
9
9
  SemverRange,
10
10
  } from '@atlaspack/types';
11
- import type {Dependency, Environment, Target} from './types';
11
+ import type {Dependency, Target} from './types';
12
12
  import {createDependencyId as createDependencyIdRust} from '@atlaspack/rust';
13
13
  import {
14
14
  SpecifierType,
@@ -21,6 +21,8 @@ import {toInternalSourceLocation} from './utils';
21
21
  import {toProjectPath} from './projectPath';
22
22
  import assert from 'assert';
23
23
  import {identifierRegistry} from './IdentifierRegistry';
24
+ import {fromEnvironmentId, toEnvironmentId} from './EnvironmentManager';
25
+ import type {EnvironmentRef} from './EnvironmentManager';
24
26
 
25
27
  type DependencyOpts = {|
26
28
  id?: string,
@@ -34,7 +36,7 @@ type DependencyOpts = {|
34
36
  isEntry?: boolean,
35
37
  isOptional?: boolean,
36
38
  loc?: SourceLocation,
37
- env: Environment,
39
+ env: EnvironmentRef,
38
40
  packageConditions?: Array<string>,
39
41
  meta?: Meta,
40
42
  resolveFrom?: FilePath,
@@ -60,7 +62,7 @@ export function createDependencyId({
60
62
  }: {|
61
63
  sourceAssetId?: string | void,
62
64
  specifier: DependencySpecifier,
63
- env: Environment,
65
+ env: EnvironmentRef,
64
66
  target?: Target | void,
65
67
  pipeline?: ?string,
66
68
  specifierType: $Keys<typeof SpecifierType>,
@@ -73,8 +75,14 @@ export function createDependencyId({
73
75
  const params = {
74
76
  sourceAssetId,
75
77
  specifier,
76
- environmentId: env.id,
77
- target,
78
+ environmentId: toEnvironmentId(env),
79
+ target:
80
+ target != null
81
+ ? {
82
+ ...target,
83
+ env: fromEnvironmentId(target.env),
84
+ }
85
+ : null,
78
86
  pipeline,
79
87
  specifierType: SpecifierType[specifierType],
80
88
  bundleBehavior,