@atlaspack/core 2.16.2-canary.56 → 2.16.2-canary.57

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 (45) hide show
  1. package/lib/AssetGraph.js +17 -6
  2. package/lib/BundleGraph.js +6 -5
  3. package/lib/Dependency.js +6 -2
  4. package/lib/Environment.js +4 -3
  5. package/lib/EnvironmentManager.js +80 -0
  6. package/lib/InternalConfig.js +3 -2
  7. package/lib/PackagerRunner.js +10 -7
  8. package/lib/RequestTracker.js +2 -2
  9. package/lib/UncommittedAsset.js +3 -2
  10. package/lib/applyRuntimes.js +2 -1
  11. package/lib/assetUtils.js +2 -1
  12. package/lib/public/Asset.js +3 -2
  13. package/lib/public/Bundle.js +2 -1
  14. package/lib/public/Config.js +2 -1
  15. package/lib/public/Dependency.js +2 -1
  16. package/lib/public/MutableBundleGraph.js +2 -1
  17. package/lib/public/Target.js +2 -1
  18. package/lib/requests/AssetRequest.js +2 -1
  19. package/lib/requests/TargetRequest.js +18 -16
  20. package/lib/requests/WriteBundleRequest.js +4 -2
  21. package/package.json +17 -17
  22. package/src/AssetGraph.js +12 -6
  23. package/src/BundleGraph.js +13 -8
  24. package/src/Dependency.js +13 -5
  25. package/src/Environment.js +8 -5
  26. package/src/EnvironmentManager.js +76 -0
  27. package/src/InternalConfig.js +5 -4
  28. package/src/PackagerRunner.js +12 -11
  29. package/src/RequestTracker.js +2 -2
  30. package/src/UncommittedAsset.js +7 -2
  31. package/src/applyRuntimes.js +6 -1
  32. package/src/assetUtils.js +4 -3
  33. package/src/public/Asset.js +9 -2
  34. package/src/public/Bundle.js +2 -1
  35. package/src/public/Config.js +2 -1
  36. package/src/public/Dependency.js +2 -1
  37. package/src/public/MutableBundleGraph.js +2 -1
  38. package/src/public/Target.js +2 -1
  39. package/src/requests/AssetRequest.js +2 -1
  40. package/src/requests/TargetRequest.js +19 -25
  41. package/src/requests/WriteBundleRequest.js +5 -7
  42. package/src/types.js +7 -6
  43. package/test/Environment.test.js +43 -34
  44. package/test/PublicEnvironment.test.js +10 -7
  45. package/test/test-utils.js +3 -2
package/lib/AssetGraph.js CHANGED
@@ -46,6 +46,14 @@ function _graph() {
46
46
  }
47
47
  var _Dependency = require("./Dependency");
48
48
  var _projectPath = require("./projectPath");
49
+ var _EnvironmentManager = require("./EnvironmentManager");
50
+ function _featureFlags() {
51
+ const data = require("@atlaspack/feature-flags");
52
+ _featureFlags = function () {
53
+ return data;
54
+ };
55
+ return data;
56
+ }
49
57
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
50
58
  function nodeFromDep(dep) {
51
59
  return {
@@ -63,7 +71,7 @@ function nodeFromDep(dep) {
63
71
  }
64
72
  function nodeFromAssetGroup(assetGroup) {
65
73
  return {
66
- id: (0, _rust().hashString)((0, _projectPath.fromProjectPathRelative)(assetGroup.filePath) + assetGroup.env.id + String(assetGroup.isSource) + String(assetGroup.sideEffects) + (assetGroup.code ?? '') + ':' + (assetGroup.pipeline ?? '') + ':' + (assetGroup.query ?? '')),
74
+ id: (0, _rust().hashString)((0, _projectPath.fromProjectPathRelative)(assetGroup.filePath) + (0, _EnvironmentManager.toEnvironmentId)(assetGroup.env) + String(assetGroup.isSource) + String(assetGroup.sideEffects) + (assetGroup.code ?? '') + ':' + (assetGroup.pipeline ?? '') + ':' + (assetGroup.query ?? '')),
67
75
  type: 'asset_group',
68
76
  value: assetGroup,
69
77
  usedSymbolsDownDirty: true
@@ -130,16 +138,19 @@ class AssetGraph extends _graph().ContentGraph {
130
138
 
131
139
  // Deduplicates Environments by making them referentially equal
132
140
  normalizeEnvironment(input) {
141
+ if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
142
+ return;
143
+ }
133
144
  let {
134
145
  id,
135
146
  context
136
- } = input.env;
147
+ } = (0, _EnvironmentManager.fromEnvironmentId)(input.env);
137
148
  let idAndContext = `${id}-${context}`;
138
149
  let env = this.envCache.get(idAndContext);
139
150
  if (env) {
140
151
  input.env = env;
141
152
  } else {
142
- this.envCache.set(idAndContext, input.env);
153
+ this.envCache.set(idAndContext, (0, _EnvironmentManager.fromEnvironmentId)(input.env));
143
154
  }
144
155
  }
145
156
  setRootConnections({
@@ -199,13 +210,13 @@ class AssetGraph extends _graph().ContentGraph {
199
210
  env: target.env,
200
211
  isEntry: true,
201
212
  needsStableName: true,
202
- symbols: target.env.isLibrary ? new Map([['*', {
213
+ symbols: (0, _EnvironmentManager.fromEnvironmentId)(target.env).isLibrary ? new Map([['*', {
203
214
  local: '*',
204
215
  isWeak: true,
205
216
  loc: null
206
217
  }]]) : undefined
207
218
  }));
208
- if (node.value.env.isLibrary) {
219
+ if ((0, _EnvironmentManager.fromEnvironmentId)(node.value.env).isLibrary) {
209
220
  // in library mode, all of the entry's symbols are "used"
210
221
  node.usedSymbolsDown.add('*');
211
222
  node.usedSymbolsUp.set('*', undefined);
@@ -348,7 +359,7 @@ class AssetGraph extends _graph().ContentGraph {
348
359
  if (this.undeferredDependencies.has(d)) {
349
360
  return false;
350
361
  }
351
- let depIsDeferrable = d.symbols && !(d.env.isLibrary && d.isEntry) && !d.symbols.has('*') && ![...d.symbols.keys()].some(symbol => {
362
+ let depIsDeferrable = d.symbols && !((0, _EnvironmentManager.fromEnvironmentId)(d.env).isLibrary && d.isEntry) && !d.symbols.has('*') && ![...d.symbols.keys()].some(symbol => {
352
363
  var _resolvedAsset$symbol;
353
364
  let assetSymbol = (_resolvedAsset$symbol = resolvedAsset.symbols) === null || _resolvedAsset$symbol === void 0 || (_resolvedAsset$symbol = _resolvedAsset$symbol.get(symbol)) === null || _resolvedAsset$symbol === void 0 ? void 0 : _resolvedAsset$symbol.local;
354
365
  return assetSymbol != null && symbols.has(assetSymbol);
@@ -51,6 +51,7 @@ function _featureFlags() {
51
51
  };
52
52
  return data;
53
53
  }
54
+ var _EnvironmentManager = require("./EnvironmentManager");
54
55
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
55
56
  const bundleGraphEdgeTypes = exports.bundleGraphEdgeTypes = {
56
57
  // A lack of an edge type indicates to follow the edge while traversing
@@ -207,7 +208,7 @@ class BundleGraph {
207
208
  }
208
209
  }
209
210
  }
210
- if (node.type === 'dependency' && node.value.symbols != null && node.value.env.shouldScopeHoist &&
211
+ if (node.type === 'dependency' && node.value.symbols != null && (0, _EnvironmentManager.fromEnvironmentId)(node.value.env).shouldScopeHoist &&
211
212
  // Disable in dev mode because this feature is at odds with safeToIncrementallyBundle
212
213
  isProduction) {
213
214
  let nodeValueSymbols = node.value.symbols;
@@ -859,7 +860,7 @@ class BundleGraph {
859
860
  return;
860
861
  }
861
862
  visitedBundles.add(descendant);
862
- if (descendant.type !== bundle.type || descendant.env.context !== bundle.env.context) {
863
+ if (descendant.type !== bundle.type || (0, _EnvironmentManager.fromEnvironmentId)(descendant.env).context !== (0, _EnvironmentManager.fromEnvironmentId)(bundle.env).context) {
863
864
  actions.skipChildren();
864
865
  return;
865
866
  }
@@ -887,7 +888,7 @@ class BundleGraph {
887
888
  isAssetReachableFromBundle(asset, bundle) {
888
889
  // If a bundle's environment is isolated, it can't access assets present
889
890
  // in any ancestor bundles. Don't consider any assets reachable.
890
- if (_Environment.ISOLATED_ENVS.has(bundle.env.context) || !bundle.isSplittable || bundle.bundleBehavior === _types.BundleBehavior.isolated || bundle.bundleBehavior === _types.BundleBehavior.inline) {
891
+ if (_Environment.ISOLATED_ENVS.has((0, _EnvironmentManager.fromEnvironmentId)(bundle.env).context) || !bundle.isSplittable || bundle.bundleBehavior === _types.BundleBehavior.isolated || bundle.bundleBehavior === _types.BundleBehavior.inline) {
891
892
  return false;
892
893
  }
893
894
 
@@ -915,7 +916,7 @@ class BundleGraph {
915
916
  let node = (0, _nullthrows().default)(this._graph.getNode(nodeId));
916
917
  // If we've reached the root or a context change without
917
918
  // finding this asset in the ancestry, it is not reachable.
918
- if (node.type === 'root' || node.type === 'bundle' && (node.value.id === bundle.id || node.value.env.context !== bundle.env.context)) {
919
+ if (node.type === 'root' || node.type === 'bundle' && (node.value.id === bundle.id || (0, _EnvironmentManager.fromEnvironmentId)(node.value.env).context !== (0, _EnvironmentManager.fromEnvironmentId)(bundle.env).context)) {
919
920
  isReachable = false;
920
921
  actions.stop();
921
922
  return;
@@ -1410,7 +1411,7 @@ class BundleGraph {
1410
1411
  for (let referencedBundle of this.getReferencedBundles(bundle)) {
1411
1412
  hash.writeString(referencedBundle.id);
1412
1413
  }
1413
- hash.writeString(JSON.stringify((0, _utils().objectSortedEntriesDeep)(bundle.env)));
1414
+ hash.writeString(JSON.stringify((0, _utils().objectSortedEntriesDeep)((0, _EnvironmentManager.fromEnvironmentId)(bundle.env))));
1414
1415
  return hash.finish();
1415
1416
  }
1416
1417
  getBundleGraphHash() {
package/lib/Dependency.js CHANGED
@@ -24,6 +24,7 @@ function _assert() {
24
24
  return data;
25
25
  }
26
26
  var _IdentifierRegistry = require("./IdentifierRegistry");
27
+ var _EnvironmentManager = require("./EnvironmentManager");
27
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
29
  function createDependencyId({
29
30
  sourceAssetId,
@@ -41,8 +42,11 @@ function createDependencyId({
41
42
  const params = {
42
43
  sourceAssetId,
43
44
  specifier,
44
- environmentId: env.id,
45
- target,
45
+ environmentId: (0, _EnvironmentManager.toEnvironmentId)(env),
46
+ target: target != null ? {
47
+ ...target,
48
+ env: (0, _EnvironmentManager.fromEnvironmentId)(target.env)
49
+ } : null,
46
50
  pipeline,
47
51
  specifierType: _types.SpecifierType[specifierType],
48
52
  bundleBehavior,
@@ -15,6 +15,7 @@ function _rust() {
15
15
  var _utils = require("./utils");
16
16
  var _Environment = _interopRequireWildcard(require("./public/Environment"));
17
17
  var _IdentifierRegistry = require("./IdentifierRegistry");
18
+ var _EnvironmentManager = require("./EnvironmentManager");
18
19
  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); }
19
20
  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; }
20
21
  const DEFAULT_ENGINES = {
@@ -108,15 +109,15 @@ function createEnvironment({
108
109
  loc
109
110
  };
110
111
  res.id = getEnvironmentHash(res);
111
- return Object.freeze(res);
112
+ return (0, _EnvironmentManager.toEnvironmentRef)(Object.freeze(res));
112
113
  }
113
114
  function mergeEnvironments(projectRoot, a, b) {
114
115
  // If merging the same object, avoid copying.
115
116
  if (a === b || !b) {
116
- return a;
117
+ return (0, _EnvironmentManager.toEnvironmentRef)(a);
117
118
  }
118
119
  if (b instanceof _Environment.default) {
119
- return (0, _Environment.environmentToInternalEnvironment)(b);
120
+ return (0, _EnvironmentManager.toEnvironmentRef)((0, _Environment.environmentToInternalEnvironment)(b));
120
121
  }
121
122
 
122
123
  // $FlowFixMe - ignore the `id` that is already on a
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.fromEnvironmentId = fromEnvironmentId;
7
+ exports.toEnvironmentId = toEnvironmentId;
8
+ exports.toEnvironmentRef = toEnvironmentRef;
9
+ function _rust() {
10
+ const data = require("@atlaspack/rust");
11
+ _rust = function () {
12
+ return data;
13
+ };
14
+ return data;
15
+ }
16
+ function _featureFlags() {
17
+ const data = require("@atlaspack/feature-flags");
18
+ _featureFlags = function () {
19
+ return data;
20
+ };
21
+ return data;
22
+ }
23
+ /*!
24
+ * At the moment we're doing this change for `CoreEnvironment`,
25
+ * but the same change must be made for `TypesEnvironment` in @atlaspack/types.
26
+ */
27
+ const localEnvironmentCache = new Map();
28
+
29
+ /**
30
+ * When deduplication is cleaned-up this will always be a string.
31
+ */
32
+
33
+ /**
34
+ * Convert environment to a ref.
35
+ * This is what we should be using to store environments.
36
+ */
37
+ function toEnvironmentRef(env) {
38
+ if (!(0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
39
+ return env;
40
+ }
41
+ const id = toEnvironmentId(env);
42
+ return id;
43
+ }
44
+
45
+ /**
46
+ * Convert environment to a string ID
47
+ */
48
+ function toEnvironmentId(
49
+ /**
50
+ * Redundant type during roll-out
51
+ */
52
+ env) {
53
+ if (!(0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
54
+ return typeof env === 'string' ? env : env.id;
55
+ }
56
+ if (typeof env === 'string') {
57
+ return env;
58
+ }
59
+ (0, _rust().addEnvironment)(env);
60
+ return env.id;
61
+ }
62
+ function fromEnvironmentId(id) {
63
+ if (!(0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
64
+ if (typeof id === 'string') {
65
+ throw new Error('This should never happen when environmentDeduplication feature-flag is off');
66
+ } else {
67
+ return id;
68
+ }
69
+ }
70
+ if (typeof id !== 'string') {
71
+ return id;
72
+ }
73
+ const localEnv = localEnvironmentCache.get(id);
74
+ if (localEnv) {
75
+ return localEnv;
76
+ }
77
+ const env = Object.freeze((0, _rust().getEnvironment)(id));
78
+ localEnvironmentCache.set(id, env);
79
+ return env;
80
+ }
@@ -14,6 +14,7 @@ function _rust() {
14
14
  return data;
15
15
  }
16
16
  var _IdentifierRegistry = require("./IdentifierRegistry");
17
+ var _EnvironmentManager = require("./EnvironmentManager");
17
18
  function createConfig({
18
19
  plugin,
19
20
  isSource,
@@ -30,11 +31,11 @@ function createConfig({
30
31
  invalidateOnBuild
31
32
  }) {
32
33
  let environment = env ?? (0, _Environment.createEnvironment)();
33
- const configId = (0, _rust().hashString)(plugin + (0, _projectPath.fromProjectPathRelative)(searchPath) + environment.id + String(isSource));
34
+ const configId = (0, _rust().hashString)(plugin + (0, _projectPath.fromProjectPathRelative)(searchPath) + (0, _EnvironmentManager.toEnvironmentId)(environment) + String(isSource));
34
35
  _IdentifierRegistry.identifierRegistry.addIdentifier('config_request', configId, {
35
36
  plugin,
36
37
  searchPath,
37
- environmentId: environment.id,
38
+ environmentId: (0, _EnvironmentManager.toEnvironmentId)(environment),
38
39
  isSource
39
40
  });
40
41
  return {
@@ -92,6 +92,7 @@ function _profiler() {
92
92
  };
93
93
  return data;
94
94
  }
95
+ var _EnvironmentManager = require("./EnvironmentManager");
95
96
  function _featureFlags() {
96
97
  const data = require("@atlaspack/feature-flags");
97
98
  _featureFlags = function () {
@@ -397,20 +398,22 @@ class PackagerRunner {
397
398
  let fullPath = (0, _projectPath.fromProjectPath)(this.options.projectRoot, filePath);
398
399
  let sourceRoot = _path().default.relative(_path().default.dirname(fullPath), this.options.projectRoot);
399
400
  let inlineSources = false;
401
+ const bundleEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
400
402
  if (bundle.target) {
401
- if (bundle.env.sourceMap && bundle.env.sourceMap.sourceRoot !== undefined) {
402
- sourceRoot = bundle.env.sourceMap.sourceRoot;
403
- } else if (this.options.serveOptions && bundle.target.env.context === 'browser') {
403
+ const bundleTargetEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.target.env);
404
+ if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
405
+ sourceRoot = bundleEnv.sourceMap.sourceRoot;
406
+ } else if (this.options.serveOptions && bundleTargetEnv.context === 'browser') {
404
407
  sourceRoot = '/__parcel_source_root';
405
408
  }
406
- if (bundle.env.sourceMap && bundle.env.sourceMap.inlineSources !== undefined) {
407
- inlineSources = bundle.env.sourceMap.inlineSources;
408
- } else if (bundle.target.env.context !== 'node') {
409
+ if (bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources !== undefined) {
410
+ inlineSources = bundleEnv.sourceMap.inlineSources;
411
+ } else if (bundleTargetEnv.context !== 'node') {
409
412
  // inlining should only happen in production for browser targets by default
410
413
  inlineSources = this.options.mode === 'production';
411
414
  }
412
415
  }
413
- let isInlineMap = bundle.env.sourceMap && bundle.env.sourceMap.inline;
416
+ let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
414
417
  let stringified = await map.stringify({
415
418
  file: _path().default.basename(fullPath + '.map'),
416
419
  // $FlowFixMe
@@ -445,8 +445,8 @@ class RequestGraph extends _graph().ContentGraph {
445
445
  this.invalidateOnBuildNodeIds.add(requestNodeId);
446
446
  }
447
447
  invalidateOnEnvChange(requestNodeId, env, value) {
448
- let envNode = nodeFromEnv(env, value);
449
- let envNodeId = this.addNode(envNode);
448
+ const envNode = nodeFromEnv(env, value);
449
+ const envNodeId = this.addNode(envNode);
450
450
  if (!this.hasEdge(requestNodeId, envNodeId, requestGraphEdgeTypes.invalidated_by_update)) {
451
451
  this.addEdge(requestNodeId, envNodeId, requestGraphEdgeTypes.invalidated_by_update);
452
452
  }
@@ -60,6 +60,7 @@ function _featureFlags() {
60
60
  };
61
61
  return data;
62
62
  }
63
+ var _EnvironmentManager = require("./EnvironmentManager");
63
64
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
64
65
  class UncommittedAsset {
65
66
  constructor({
@@ -278,7 +279,7 @@ class UncommittedAsset {
278
279
  ...rest,
279
280
  // $FlowFixMe "convert" the $ReadOnlyMaps to the interal mutable one
280
281
  symbols,
281
- 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),
282
283
  sourceAssetId: this.value.id,
283
284
  sourcePath: (0, _projectPath.fromProjectPath)(this.options.projectRoot, this.value.filePath)
284
285
  });
@@ -318,7 +319,7 @@ class UncommittedAsset {
318
319
  bundleBehavior: result.bundleBehavior ?? (this.value.bundleBehavior == null ? null : _types.BundleBehaviorNames[this.value.bundleBehavior]),
319
320
  isBundleSplittable: result.isBundleSplittable ?? this.value.isBundleSplittable,
320
321
  isSource: this.value.isSource,
321
- 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),
322
323
  dependencies: this.value.type === result.type ? new Map(this.value.dependencies) : new Map(),
323
324
  meta: {
324
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,
@@ -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;
@@ -34,6 +34,7 @@ function _featureFlags() {
34
34
  };
35
35
  return data;
36
36
  }
37
+ var _EnvironmentManager = require("../EnvironmentManager");
37
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
39
  const internalConfigToConfig = new (_utils().DefaultWeakMap)(() => new WeakMap());
39
40
  class PublicConfig {
@@ -53,7 +54,7 @@ class PublicConfig {
53
54
  return this;
54
55
  }
55
56
  get env() {
56
- return new _Environment.default(this.#config.env, this.#options);
57
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#config.env), this.#options);
57
58
  }
58
59
  get searchPath() {
59
60
  return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#config.searchPath);
@@ -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,
@@ -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,7 +155,7 @@ 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
  }