@atlaspack/core 2.16.2-dev.55 → 2.16.2-dev.72

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 (89) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/_empty.js +0 -0
  3. package/lib/AssetGraph.js +17 -6
  4. package/lib/Atlaspack.js +2 -5
  5. package/lib/AtlaspackConfig.schema.js +1 -7
  6. package/lib/BundleGraph.js +10 -8
  7. package/lib/Dependency.js +6 -2
  8. package/lib/Environment.js +4 -3
  9. package/lib/EnvironmentManager.js +137 -0
  10. package/lib/InternalConfig.js +3 -2
  11. package/lib/PackagerRunner.js +15 -9
  12. package/lib/RequestTracker.js +56 -46
  13. package/lib/Transformation.js +2 -2
  14. package/lib/UncommittedAsset.js +3 -2
  15. package/lib/applyRuntimes.js +2 -1
  16. package/lib/assetUtils.js +2 -1
  17. package/lib/atlaspack-v3/AtlaspackV3.js +44 -1
  18. package/lib/atlaspack-v3/NapiWorkerPool.js +1 -1
  19. package/lib/atlaspack-v3/worker/compat/environment.js +2 -2
  20. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +6 -6
  21. package/lib/atlaspack-v3/worker/compat/plugin-config.js +5 -5
  22. package/lib/atlaspack-v3/worker/napi-worker.js +3 -0
  23. package/lib/atlaspack-v3/worker/worker.js +11 -4
  24. package/lib/dumpGraphToGraphViz.js +1 -1
  25. package/lib/index.js +9 -1
  26. package/lib/internal-plugins.js +9 -0
  27. package/lib/isSuperPackage.js +23 -0
  28. package/lib/loadAtlaspackPlugin.js +15 -0
  29. package/lib/public/Asset.js +3 -2
  30. package/lib/public/Bundle.js +2 -1
  31. package/lib/public/Config.js +86 -19
  32. package/lib/public/Dependency.js +2 -1
  33. package/lib/public/MutableBundleGraph.js +2 -1
  34. package/lib/public/PluginOptions.js +3 -0
  35. package/lib/public/Target.js +2 -1
  36. package/lib/requests/AssetRequest.js +2 -1
  37. package/lib/requests/AtlaspackConfigRequest.js +44 -29
  38. package/lib/requests/ConfigRequest.js +27 -4
  39. package/lib/requests/TargetRequest.js +18 -16
  40. package/lib/requests/WriteBundleRequest.js +5 -2
  41. package/lib/requests/WriteBundlesRequest.js +1 -0
  42. package/lib/resolveOptions.js +5 -4
  43. package/lib/worker.js +9 -26
  44. package/package.json +21 -18
  45. package/src/AssetGraph.js +12 -6
  46. package/src/Atlaspack.js +8 -7
  47. package/src/BundleGraph.js +21 -9
  48. package/src/Dependency.js +13 -5
  49. package/src/Environment.js +8 -5
  50. package/src/EnvironmentManager.js +145 -0
  51. package/src/InternalConfig.js +6 -5
  52. package/src/PackagerRunner.js +17 -11
  53. package/src/RequestTracker.js +39 -13
  54. package/src/UncommittedAsset.js +7 -2
  55. package/src/applyRuntimes.js +6 -1
  56. package/src/assetUtils.js +4 -3
  57. package/src/atlaspack-v3/AtlaspackV3.js +53 -2
  58. package/src/atlaspack-v3/NapiWorkerPool.js +5 -1
  59. package/src/atlaspack-v3/worker/compat/plugin-config.js +1 -1
  60. package/src/atlaspack-v3/worker/worker.js +11 -4
  61. package/src/index.js +2 -0
  62. package/src/internal-plugins.js +4 -0
  63. package/src/isSuperPackage.js +28 -0
  64. package/src/loadAtlaspackPlugin.js +23 -1
  65. package/src/public/Asset.js +9 -2
  66. package/src/public/Bundle.js +2 -1
  67. package/src/public/Config.js +110 -29
  68. package/src/public/Dependency.js +2 -1
  69. package/src/public/MutableBundleGraph.js +2 -1
  70. package/src/public/PluginOptions.js +4 -0
  71. package/src/public/Target.js +2 -1
  72. package/src/requests/AssetRequest.js +2 -1
  73. package/src/requests/AtlaspackConfigRequest.js +77 -31
  74. package/src/requests/ConfigRequest.js +33 -9
  75. package/src/requests/TargetRequest.js +19 -25
  76. package/src/requests/WriteBundleRequest.js +6 -7
  77. package/src/requests/WriteBundlesRequest.js +1 -0
  78. package/src/resolveOptions.js +2 -0
  79. package/src/types.js +10 -7
  80. package/src/worker.js +8 -7
  81. package/test/Environment.test.js +43 -34
  82. package/test/EnvironmentManager.test.js +192 -0
  83. package/test/PublicEnvironment.test.js +10 -7
  84. package/test/RequestTracker.test.js +1 -4
  85. package/test/public/Config.test.js +108 -0
  86. package/test/requests/ConfigRequest.test.js +187 -3
  87. package/test/test-utils.js +3 -2
  88. package/lib/atlaspack-v3/worker/index.js +0 -6
  89. /package/src/atlaspack-v3/worker/{index.js → napi-worker.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.16.2-dev.55+5a11f33c5",
3
+ "version": "2.16.2-dev.72+9840480de",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,24 +18,24 @@
18
18
  "scripts": {
19
19
  "test": "mocha",
20
20
  "test-ci": "mocha",
21
- "check-ts": "tsc --module node16 --moduleResolution node16 --noEmit index.d.ts"
21
+ "check-ts": "tsc --noEmit index.d.ts"
22
22
  },
23
23
  "dependencies": {
24
- "@atlaspack/build-cache": "2.13.3-dev.123+5a11f33c5",
25
- "@atlaspack/cache": "3.1.1-dev.55+5a11f33c5",
26
- "@atlaspack/diagnostic": "2.14.1-dev.123+5a11f33c5",
27
- "@atlaspack/events": "2.14.1-dev.123+5a11f33c5",
28
- "@atlaspack/feature-flags": "2.14.1-dev.123+5a11f33c5",
29
- "@atlaspack/fs": "2.14.5-dev.55+5a11f33c5",
30
- "@atlaspack/graph": "3.4.1-dev.123+5a11f33c5",
31
- "@atlaspack/logger": "2.14.5-dev.55+5a11f33c5",
32
- "@atlaspack/package-manager": "2.14.5-dev.55+5a11f33c5",
33
- "@atlaspack/plugin": "2.14.5-dev.55+5a11f33c5",
34
- "@atlaspack/profiler": "2.14.1-dev.123+5a11f33c5",
35
- "@atlaspack/rust": "3.2.1-dev.55+5a11f33c5",
36
- "@atlaspack/types": "2.14.5-dev.55+5a11f33c5",
37
- "@atlaspack/utils": "2.14.5-dev.55+5a11f33c5",
38
- "@atlaspack/workers": "2.14.5-dev.55+5a11f33c5",
24
+ "@atlaspack/build-cache": "2.13.3-dev.140+9840480de",
25
+ "@atlaspack/cache": "3.1.1-dev.72+9840480de",
26
+ "@atlaspack/diagnostic": "2.14.1-dev.140+9840480de",
27
+ "@atlaspack/events": "2.14.1-dev.140+9840480de",
28
+ "@atlaspack/feature-flags": "2.14.1-dev.140+9840480de",
29
+ "@atlaspack/fs": "2.14.5-dev.72+9840480de",
30
+ "@atlaspack/graph": "3.4.1-dev.140+9840480de",
31
+ "@atlaspack/logger": "2.14.5-dev.72+9840480de",
32
+ "@atlaspack/package-manager": "2.14.5-dev.72+9840480de",
33
+ "@atlaspack/plugin": "2.14.5-dev.72+9840480de",
34
+ "@atlaspack/profiler": "2.14.1-dev.140+9840480de",
35
+ "@atlaspack/rust": "3.2.1-dev.72+9840480de",
36
+ "@atlaspack/types": "2.14.5-dev.72+9840480de",
37
+ "@atlaspack/utils": "2.14.5-dev.72+9840480de",
38
+ "@atlaspack/workers": "2.14.5-dev.72+9840480de",
39
39
  "@mischnic/json-sourcemap": "^0.1.0",
40
40
  "@parcel/source-map": "^2.1.1",
41
41
  "base-x": "^3.0.8",
@@ -67,9 +67,12 @@
67
67
  "default": "./lib/worker.js"
68
68
  }
69
69
  },
70
+ "atlaspackReferences": [
71
+ "_empty.js"
72
+ ],
70
73
  "browser": {
71
74
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
72
75
  },
73
76
  "type": "commonjs",
74
- "gitHead": "5a11f33c51ff74d1cf8d4b72cfa0fda833aa980a"
77
+ "gitHead": "9840480de27511f558d8f5b8cf82220de977b4fb"
75
78
  }
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
@@ -69,7 +69,10 @@ registerCoreWithSerializer();
69
69
 
70
70
  export const INTERNAL_TRANSFORM: symbol = Symbol('internal_transform');
71
71
  export const INTERNAL_RESOLVE: symbol = Symbol('internal_resolve');
72
- export const WORKER_PATH: string = path.join(__dirname, 'worker.js');
72
+ export const WORKER_PATH: string = path.join(
73
+ /*#__ATLASPACK_IGNORE__*/ __dirname,
74
+ 'worker.js',
75
+ );
73
76
 
74
77
  export default class Atlaspack {
75
78
  #requestTracker /*: RequestTracker*/;
@@ -174,7 +177,6 @@ export default class Atlaspack {
174
177
 
175
178
  rustAtlaspack = await AtlaspackV3.create({
176
179
  ...options,
177
- corePath: path.join(__dirname, '..'),
178
180
  threads,
179
181
  entries: Array.isArray(entries)
180
182
  ? entries
@@ -533,11 +535,10 @@ export default class Atlaspack {
533
535
  nativeInvalid = await this.rustAtlaspack.respondToFsEvents(events);
534
536
  }
535
537
 
536
- let {didInvalidate: isInvalid} =
537
- await this.#requestTracker.respondToFSEvents(
538
- events,
539
- Number.POSITIVE_INFINITY,
540
- );
538
+ let isInvalid = await this.#requestTracker.respondToFSEvents(
539
+ events,
540
+ Number.POSITIVE_INFINITY,
541
+ );
541
542
 
542
543
  if (
543
544
  (nativeInvalid || isInvalid) &&
@@ -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,
@@ -1315,7 +1316,14 @@ export default class BundleGraph {
1315
1316
  }
1316
1317
 
1317
1318
  let dependencies = this._graph
1318
- .getNodeIdsConnectedTo(assetNodeId)
1319
+ .getNodeIdsConnectedTo(
1320
+ assetNodeId,
1321
+ // TODO: This seems like bug with library builds when assets are present
1322
+ // in other files. Guarding the fix for now exclusively for super builds
1323
+ process.env.ATLASPACK_SUPER_BUILD === 'true'
1324
+ ? ALL_EDGE_TYPES
1325
+ : undefined,
1326
+ )
1319
1327
  .map((id) => nullthrows(this._graph.getNode(id)))
1320
1328
  .filter((node) => node.type === 'dependency')
1321
1329
  .map((node) => {
@@ -1359,7 +1367,8 @@ export default class BundleGraph {
1359
1367
 
1360
1368
  if (
1361
1369
  descendant.type !== bundle.type ||
1362
- descendant.env.context !== bundle.env.context
1370
+ fromEnvironmentId(descendant.env).context !==
1371
+ fromEnvironmentId(bundle.env).context
1363
1372
  ) {
1364
1373
  actions.skipChildren();
1365
1374
  return;
@@ -1400,7 +1409,7 @@ export default class BundleGraph {
1400
1409
  // If a bundle's environment is isolated, it can't access assets present
1401
1410
  // in any ancestor bundles. Don't consider any assets reachable.
1402
1411
  if (
1403
- ISOLATED_ENVS.has(bundle.env.context) ||
1412
+ ISOLATED_ENVS.has(fromEnvironmentId(bundle.env).context) ||
1404
1413
  !bundle.isSplittable ||
1405
1414
  bundle.bundleBehavior === BundleBehavior.isolated ||
1406
1415
  bundle.bundleBehavior === BundleBehavior.inline
@@ -1454,7 +1463,8 @@ export default class BundleGraph {
1454
1463
  node.type === 'root' ||
1455
1464
  (node.type === 'bundle' &&
1456
1465
  (node.value.id === bundle.id ||
1457
- node.value.env.context !== bundle.env.context))
1466
+ fromEnvironmentId(node.value.env).context !==
1467
+ fromEnvironmentId(bundle.env).context))
1458
1468
  ) {
1459
1469
  isReachable = false;
1460
1470
  actions.stop();
@@ -2128,7 +2138,9 @@ export default class BundleGraph {
2128
2138
  hash.writeString(referencedBundle.id);
2129
2139
  }
2130
2140
 
2131
- hash.writeString(JSON.stringify(objectSortedEntriesDeep(bundle.env)));
2141
+ hash.writeString(
2142
+ JSON.stringify(objectSortedEntriesDeep(fromEnvironmentId(bundle.env))),
2143
+ );
2132
2144
  return hash.finish();
2133
2145
  }
2134
2146
 
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,
@@ -10,6 +10,8 @@ import {toInternalSourceLocation} from './utils';
10
10
  import PublicEnvironment from './public/Environment';
11
11
  import {environmentToInternalEnvironment} from './public/Environment';
12
12
  import {identifierRegistry} from './IdentifierRegistry';
13
+ import {toEnvironmentRef} from './EnvironmentManager';
14
+ import type {EnvironmentRef} from './EnvironmentManager';
13
15
 
14
16
  const DEFAULT_ENGINES = {
15
17
  browsers: ['> 0.25%'],
@@ -35,7 +37,7 @@ export function createEnvironment({
35
37
  loc,
36
38
  }: EnvironmentOpts = {
37
39
  /*::...null*/
38
- }): Environment {
40
+ }): EnvironmentRef {
39
41
  if (context == null) {
40
42
  if (engines?.node) {
41
43
  context = 'node';
@@ -112,21 +114,22 @@ export function createEnvironment({
112
114
  };
113
115
 
114
116
  res.id = getEnvironmentHash(res);
115
- return Object.freeze(res);
117
+
118
+ return toEnvironmentRef(Object.freeze(res));
116
119
  }
117
120
 
118
121
  export function mergeEnvironments(
119
122
  projectRoot: FilePath,
120
123
  a: Environment,
121
124
  b: ?(EnvironmentOptions | IEnvironment),
122
- ): Environment {
125
+ ): EnvironmentRef {
123
126
  // If merging the same object, avoid copying.
124
127
  if (a === b || !b) {
125
- return a;
128
+ return toEnvironmentRef(a);
126
129
  }
127
130
 
128
131
  if (b instanceof PublicEnvironment) {
129
- return environmentToInternalEnvironment(b);
132
+ return toEnvironmentRef(environmentToInternalEnvironment(b));
130
133
  }
131
134
 
132
135
  // $FlowFixMe - ignore the `id` that is already on a
@@ -0,0 +1,145 @@
1
+ // @flow strict-local
2
+ /*!
3
+ * At the moment we're doing this change for `CoreEnvironment`,
4
+ * but the same change must be made for `TypesEnvironment` in @atlaspack/types.
5
+ */
6
+ import type {Environment as CoreEnvironment} from './types';
7
+ import {type Cache} from '@atlaspack/cache';
8
+ import {
9
+ addEnvironment,
10
+ getEnvironment,
11
+ getAllEnvironments,
12
+ setAllEnvironments,
13
+ } from '@atlaspack/rust';
14
+ import {getFeatureFlag} from '@atlaspack/feature-flags';
15
+ import {instrument} from '@atlaspack/logger';
16
+ import {ATLASPACK_VERSION} from './constants';
17
+
18
+ const localEnvironmentCache = new Map<string, CoreEnvironment>();
19
+
20
+ export opaque type EnvironmentId = string;
21
+ /**
22
+ * When deduplication is cleaned-up this will always be a string.
23
+ */
24
+ export type EnvironmentRef = EnvironmentId | CoreEnvironment;
25
+
26
+ /**
27
+ * Convert environment to a ref.
28
+ * This is what we should be using to store environments.
29
+ */
30
+ export function toEnvironmentRef(env: CoreEnvironment): EnvironmentRef {
31
+ if (!getFeatureFlag('environmentDeduplication')) {
32
+ return env;
33
+ }
34
+
35
+ const id = toEnvironmentId(env);
36
+ return id;
37
+ }
38
+
39
+ /**
40
+ * Convert environment to a string ID
41
+ */
42
+ export function toEnvironmentId(
43
+ /**
44
+ * Redundant type during roll-out
45
+ */
46
+ env: CoreEnvironment | EnvironmentRef,
47
+ ): string {
48
+ if (!getFeatureFlag('environmentDeduplication')) {
49
+ return typeof env === 'string' ? env : env.id;
50
+ }
51
+
52
+ if (typeof env === 'string') {
53
+ return env;
54
+ }
55
+
56
+ addEnvironment(env);
57
+ return env.id;
58
+ }
59
+
60
+ export function fromEnvironmentId(id: EnvironmentRef): CoreEnvironment {
61
+ if (!getFeatureFlag('environmentDeduplication')) {
62
+ if (typeof id === 'string') {
63
+ throw new Error(
64
+ 'This should never happen when environmentDeduplication feature-flag is off',
65
+ );
66
+ } else {
67
+ return id;
68
+ }
69
+ }
70
+
71
+ if (typeof id !== 'string') {
72
+ return id;
73
+ }
74
+
75
+ const localEnv = localEnvironmentCache.get(id);
76
+
77
+ if (localEnv) {
78
+ return localEnv;
79
+ }
80
+
81
+ const env = Object.freeze(getEnvironment(id));
82
+ localEnvironmentCache.set(id, env);
83
+ return env;
84
+ }
85
+
86
+ /**
87
+ * Writes all environments and their IDs to the cache
88
+ * @param {Cache} cache
89
+ * @returns {Promise<void>}
90
+ */
91
+ export async function writeEnvironmentsToCache(cache: Cache): Promise<void> {
92
+ const environments = getAllEnvironments();
93
+ const environmentIds = new Set<string>();
94
+
95
+ // Store each environment individually
96
+ for (const env of environments) {
97
+ environmentIds.add(env.id);
98
+ const envKey = `Environment/${ATLASPACK_VERSION}/${env.id}`;
99
+
100
+ await instrument(
101
+ `RequestTracker::writeToCache::cache.put(${envKey})`,
102
+ async () => {
103
+ await cache.set(envKey, env);
104
+ },
105
+ );
106
+ }
107
+
108
+ // Store the list of environment IDs
109
+ await instrument(
110
+ `RequestTracker::writeToCache::cache.put(${`EnvironmentManager/${ATLASPACK_VERSION}`})`,
111
+ async () => {
112
+ await cache.set(
113
+ `EnvironmentManager/${ATLASPACK_VERSION}`,
114
+ Array.from(environmentIds),
115
+ );
116
+ },
117
+ );
118
+ }
119
+
120
+ /**
121
+ * Loads all environments and their IDs from the cache
122
+ * @param {Cache} cache
123
+ * @returns {Promise<void>}
124
+ */
125
+ export async function loadEnvironmentsFromCache(cache: Cache): Promise<void> {
126
+ const cachedEnvIds = await cache.get(
127
+ `EnvironmentManager/${ATLASPACK_VERSION}`,
128
+ );
129
+
130
+ if (cachedEnvIds == null) {
131
+ return;
132
+ }
133
+
134
+ const environments = [];
135
+ for (const envId of cachedEnvIds) {
136
+ const envKey = `Environment/${ATLASPACK_VERSION}/${envId}`;
137
+ const cachedEnv = await cache.get(envKey);
138
+ if (cachedEnv != null) {
139
+ environments.push(cachedEnv);
140
+ }
141
+ }
142
+ if (environments.length > 0) {
143
+ setAllEnvironments(environments);
144
+ }
145
+ }
@@ -3,7 +3,6 @@
3
3
  import type {PackageName, ConfigResult} from '@atlaspack/types';
4
4
  import type {
5
5
  Config,
6
- Environment,
7
6
  InternalFileCreateInvalidation,
8
7
  InternalDevDepOptions,
9
8
  } from './types';
@@ -13,17 +12,19 @@ import {fromProjectPathRelative} from './projectPath';
13
12
  import {createEnvironment} from './Environment';
14
13
  import {hashString} from '@atlaspack/rust';
15
14
  import {identifierRegistry} from './IdentifierRegistry';
15
+ import type {EnvironmentRef} from './EnvironmentManager';
16
+ import {toEnvironmentId} from './EnvironmentManager';
16
17
 
17
18
  type ConfigOpts = {|
18
19
  plugin: PackageName,
19
20
  searchPath: ProjectPath,
20
21
  isSource?: boolean,
21
- env?: Environment,
22
+ env?: EnvironmentRef,
22
23
  result?: ConfigResult,
23
24
  invalidateOnFileChange?: Set<ProjectPath>,
24
25
  invalidateOnConfigKeyChange?: Array<{|
25
26
  filePath: ProjectPath,
26
- configKey: string,
27
+ configKey: string[],
27
28
  |}>,
28
29
  invalidateOnFileCreate?: Array<InternalFileCreateInvalidation>,
29
30
  invalidateOnEnvChange?: Set<string>,
@@ -52,13 +53,13 @@ export function createConfig({
52
53
  const configId = hashString(
53
54
  plugin +
54
55
  fromProjectPathRelative(searchPath) +
55
- environment.id +
56
+ toEnvironmentId(environment) +
56
57
  String(isSource),
57
58
  );
58
59
  identifierRegistry.addIdentifier('config_request', configId, {
59
60
  plugin,
60
61
  searchPath,
61
- environmentId: environment.id,
62
+ environmentId: toEnvironmentId(environment),
62
63
  isSource,
63
64
  });
64
65
  return {
@@ -63,6 +63,7 @@ import {getInvalidationId, getInvalidationHash} from './assetUtils';
63
63
  import {optionsProxy} from './utils';
64
64
  import {invalidateDevDeps} from './requests/DevDepRequest';
65
65
  import {tracer, PluginTracer} from '@atlaspack/profiler';
66
+ import {fromEnvironmentId} from './EnvironmentManager';
66
67
  import {getFeatureFlag} from '@atlaspack/feature-flags';
67
68
 
68
69
  type Opts = {|
@@ -578,32 +579,37 @@ export default class PackagerRunner {
578
579
  );
579
580
  let inlineSources = false;
580
581
 
582
+ const bundleEnv = fromEnvironmentId(bundle.env);
581
583
  if (bundle.target) {
582
- if (
583
- bundle.env.sourceMap &&
584
- bundle.env.sourceMap.sourceRoot !== undefined
585
- ) {
586
- sourceRoot = bundle.env.sourceMap.sourceRoot;
584
+ const bundleTargetEnv = fromEnvironmentId(bundle.target.env);
585
+
586
+ if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
587
+ sourceRoot = bundleEnv.sourceMap.sourceRoot;
587
588
  } else if (
588
589
  this.options.serveOptions &&
589
- bundle.target.env.context === 'browser'
590
+ bundleTargetEnv.context === 'browser'
590
591
  ) {
591
592
  sourceRoot = '/__parcel_source_root';
592
593
  }
593
594
 
594
595
  if (
595
- bundle.env.sourceMap &&
596
- bundle.env.sourceMap.inlineSources !== undefined
596
+ bundleEnv.sourceMap &&
597
+ bundleEnv.sourceMap.inlineSources !== undefined
597
598
  ) {
598
- inlineSources = bundle.env.sourceMap.inlineSources;
599
- } else if (bundle.target.env.context !== 'node') {
599
+ inlineSources = bundleEnv.sourceMap.inlineSources;
600
+ } else if (bundleTargetEnv.context !== 'node') {
600
601
  // inlining should only happen in production for browser targets by default
601
602
  inlineSources = this.options.mode === 'production';
602
603
  }
603
604
  }
604
605
 
606
+ if (process.env.ATLASPACK_SUPER_BUILD === 'true') {
607
+ // Set source root to 'atlaspack' so stack traces are clean in Sentry
608
+ sourceRoot = 'atlaspack';
609
+ }
610
+
605
611
  let mapFilename = fullPath + '.map';
606
- let isInlineMap = bundle.env.sourceMap && bundle.env.sourceMap.inline;
612
+ let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
607
613
 
608
614
  let stringified = await map.stringify({
609
615
  file: path.basename(mapFilename),