@atlaspack/core 2.16.2-canary.13 → 2.16.2-canary.131

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 (95) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/index.d.ts +4 -0
  3. package/lib/AssetGraph.js +27 -7
  4. package/lib/Atlaspack.js +35 -27
  5. package/lib/AtlaspackConfig.schema.js +7 -1
  6. package/lib/BundleGraph.js +8 -5
  7. package/lib/Dependency.js +6 -2
  8. package/lib/Environment.js +5 -3
  9. package/lib/EnvironmentManager.js +137 -0
  10. package/lib/InternalConfig.js +3 -2
  11. package/lib/PackagerRunner.js +54 -16
  12. package/lib/RequestTracker.js +345 -132
  13. package/lib/SymbolPropagation.js +14 -0
  14. package/lib/Transformation.js +2 -2
  15. package/lib/UncommittedAsset.js +20 -2
  16. package/lib/applyRuntimes.js +2 -1
  17. package/lib/assetUtils.js +2 -1
  18. package/lib/atlaspack-v3/AtlaspackV3.js +16 -3
  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/index.js +3 -0
  23. package/lib/atlaspack-v3/worker/worker.js +8 -0
  24. package/lib/dumpGraphToGraphViz.js +1 -1
  25. package/lib/index.js +29 -1
  26. package/lib/public/Asset.js +7 -9
  27. package/lib/public/Bundle.js +12 -13
  28. package/lib/public/BundleGraph.js +3 -2
  29. package/lib/public/BundleGroup.js +2 -3
  30. package/lib/public/Config.js +95 -8
  31. package/lib/public/Dependency.js +4 -4
  32. package/lib/public/Environment.js +2 -3
  33. package/lib/public/MutableBundleGraph.js +5 -4
  34. package/lib/public/PluginOptions.js +1 -2
  35. package/lib/public/Target.js +4 -4
  36. package/lib/requests/AssetGraphRequest.js +13 -1
  37. package/lib/requests/AssetGraphRequestRust.js +17 -2
  38. package/lib/requests/AssetRequest.js +2 -1
  39. package/lib/requests/BundleGraphRequest.js +13 -1
  40. package/lib/requests/ConfigRequest.js +27 -4
  41. package/lib/requests/DevDepRequest.js +11 -1
  42. package/lib/requests/PathRequest.js +10 -0
  43. package/lib/requests/TargetRequest.js +18 -16
  44. package/lib/requests/WriteBundleRequest.js +15 -3
  45. package/lib/requests/WriteBundlesRequest.js +22 -1
  46. package/lib/resolveOptions.js +7 -4
  47. package/lib/worker.js +18 -1
  48. package/package.json +18 -25
  49. package/src/AssetGraph.js +30 -7
  50. package/src/Atlaspack.js +40 -23
  51. package/src/BundleGraph.js +13 -8
  52. package/src/Dependency.js +13 -5
  53. package/src/Environment.js +9 -6
  54. package/src/EnvironmentManager.js +145 -0
  55. package/src/InternalConfig.js +6 -5
  56. package/src/PackagerRunner.js +72 -20
  57. package/src/RequestTracker.js +526 -157
  58. package/src/SymbolPropagation.js +13 -1
  59. package/src/UncommittedAsset.js +23 -3
  60. package/src/applyRuntimes.js +6 -1
  61. package/src/assetUtils.js +4 -3
  62. package/src/atlaspack-v3/AtlaspackV3.js +24 -3
  63. package/src/atlaspack-v3/worker/compat/plugin-config.js +9 -5
  64. package/src/atlaspack-v3/worker/index.js +2 -1
  65. package/src/atlaspack-v3/worker/worker.js +7 -0
  66. package/src/index.js +5 -1
  67. package/src/public/Asset.js +13 -6
  68. package/src/public/Bundle.js +12 -11
  69. package/src/public/BundleGraph.js +10 -2
  70. package/src/public/BundleGroup.js +2 -2
  71. package/src/public/Config.js +132 -18
  72. package/src/public/Dependency.js +4 -3
  73. package/src/public/Environment.js +2 -2
  74. package/src/public/MutableBundleGraph.js +8 -5
  75. package/src/public/PluginOptions.js +1 -1
  76. package/src/public/Target.js +4 -3
  77. package/src/requests/AssetGraphRequest.js +13 -3
  78. package/src/requests/AssetGraphRequestRust.js +14 -2
  79. package/src/requests/AssetRequest.js +2 -1
  80. package/src/requests/BundleGraphRequest.js +13 -3
  81. package/src/requests/ConfigRequest.js +33 -9
  82. package/src/requests/DevDepRequest.js +22 -9
  83. package/src/requests/PathRequest.js +4 -0
  84. package/src/requests/TargetRequest.js +19 -25
  85. package/src/requests/WriteBundleRequest.js +14 -8
  86. package/src/requests/WriteBundlesRequest.js +31 -3
  87. package/src/resolveOptions.js +4 -2
  88. package/src/types.js +10 -7
  89. package/test/Environment.test.js +43 -34
  90. package/test/EnvironmentManager.test.js +192 -0
  91. package/test/PublicEnvironment.test.js +10 -7
  92. package/test/RequestTracker.test.js +124 -29
  93. package/test/public/Config.test.js +108 -0
  94. package/test/requests/ConfigRequest.test.js +199 -7
  95. package/test/test-utils.js +4 -9
@@ -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);
@@ -36,9 +37,8 @@ function getPublicDependency(dep, options) {
36
37
  return new Dependency(dep, options);
37
38
  }
38
39
  class Dependency {
39
- #dep /*: InternalDependency */;
40
- #options /*: AtlaspackOptions */;
41
-
40
+ #dep;
41
+ #options;
42
42
  constructor(dep, options) {
43
43
  this.#dep = dep;
44
44
  this.#options = options;
@@ -80,7 +80,7 @@ class Dependency {
80
80
  return (0, _utils.fromInternalSourceLocation)(this.#options.projectRoot, this.#dep.loc);
81
81
  }
82
82
  get env() {
83
- return new _Environment.default(this.#dep.env, this.#options);
83
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#dep.env), this.#options);
84
84
  }
85
85
  get packageConditions() {
86
86
  // Merge custom conditions with conditions stored as bitflags.
@@ -127,9 +127,8 @@ function environmentToInternalEnvironment(environment) {
127
127
  return (0, _nullthrows().default)(_environmentToInternalEnvironment.get(environment));
128
128
  }
129
129
  class Environment {
130
- #environment /*: InternalEnvironment */;
131
- #options /*: AtlaspackOptions */;
132
-
130
+ #environment;
131
+ #options;
133
132
  constructor(env, options) {
134
133
  let existing = internalEnvironmentToEnvironment.get(env);
135
134
  if (existing != null) {
@@ -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 }; }
@@ -53,9 +54,9 @@ function createBundleId(data) {
53
54
  return id;
54
55
  }
55
56
  class MutableBundleGraph extends _BundleGraph.default {
56
- #graph /*: InternalBundleGraph */;
57
- #options /*: AtlaspackOptions */;
58
- #bundlePublicIds /*: Set<string> */ = new Set();
57
+ #graph;
58
+ #options;
59
+ #bundlePublicIds = new Set();
59
60
  constructor(graph, options) {
60
61
  super(graph, _Bundle.Bundle.get.bind(_Bundle.Bundle), options);
61
62
  this.#graph = graph;
@@ -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,
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  let parcelOptionsToPluginOptions = new WeakMap();
8
8
  class PluginOptions {
9
- #options /*: AtlaspackOptions */;
10
-
9
+ #options;
11
10
  constructor(options) {
12
11
  let existing = parcelOptionsToPluginOptions.get(options);
13
12
  if (existing != null) {
@@ -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();
@@ -23,9 +24,8 @@ function targetToInternalTarget(target) {
23
24
  return (0, _nullthrows().default)(_targetToInternalTarget.get(target));
24
25
  }
25
26
  class Target {
26
- #target /*: TargetValue */;
27
- #options /*: AtlaspackOptions */;
28
-
27
+ #target;
28
+ #options;
29
29
  constructor(target, options) {
30
30
  let existing = internalTargetToTarget.get(target);
31
31
  if (existing != null) {
@@ -44,7 +44,7 @@ class Target {
44
44
  return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#target.distDir);
45
45
  }
46
46
  get env() {
47
- return new _Environment.default(this.#target.env, this.#options);
47
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#target.env), this.#options);
48
48
  }
49
49
  get name() {
50
50
  return this.#target.name;
@@ -26,6 +26,13 @@ function _nullthrows() {
26
26
  };
27
27
  return data;
28
28
  }
29
+ function _featureFlags() {
30
+ const data = require("@atlaspack/feature-flags");
31
+ _featureFlags = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
29
36
  function _utils() {
30
37
  const data = require("@atlaspack/utils");
31
38
  _utils = function () {
@@ -116,7 +123,12 @@ class AssetGraphBuilder {
116
123
  this.shouldBuildLazily = shouldBuildLazily ?? false;
117
124
  this.lazyIncludes = lazyIncludes ?? [];
118
125
  this.lazyExcludes = lazyExcludes ?? [];
119
- this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
126
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
127
+ const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
128
+ this.cacheKey = `AssetGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
129
+ } else {
130
+ this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-AssetGraph';
131
+ }
120
132
  this.isSingleChangeRebuild = api.getInvalidSubRequests().filter(req => req.requestType === 'asset_request').length === 1;
121
133
  this.queue = new (_utils().PromiseQueue)();
122
134
  assetGraph.onNodeRemoved = nodeId => {
@@ -26,9 +26,18 @@ function _logger() {
26
26
  };
27
27
  return data;
28
28
  }
29
+ function _featureFlags() {
30
+ const data = require("@atlaspack/feature-flags");
31
+ _featureFlags = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
29
36
  var _AssetGraph = _interopRequireWildcard(require("../AssetGraph"));
30
37
  var _RequestTracker = require("../RequestTracker");
31
38
  var _SymbolPropagation = require("../SymbolPropagation");
39
+ var _EnvironmentManager = require("../EnvironmentManager");
40
+ var _Environment = require("../Environment");
32
41
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
33
42
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
34
43
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -137,8 +146,11 @@ function getAssetGraph(serializedGraph) {
137
146
  let id = asset.id;
138
147
  asset.committed = true;
139
148
  asset.contentKey = id;
140
- asset.env.id = getEnvId(asset.env);
149
+ asset.env.id = (0, _featureFlags().getFeatureFlag)('environmentDeduplication') ?
150
+ // TODO: Rust can do this and avoid copying a significant amount of data over
151
+ (0, _Environment.getEnvironmentHash)(asset.env) : getEnvId(asset.env);
141
152
  asset.mapKey = `map:${asset.id}`;
153
+ asset.env = (0, _EnvironmentManager.toEnvironmentRef)(asset.env);
142
154
 
143
155
  // This is populated later when we map the edges between assets and dependencies
144
156
  asset.dependencies = new Map();
@@ -162,7 +174,10 @@ function getAssetGraph(serializedGraph) {
162
174
  let id = node.value.id;
163
175
  let dependency = node.value.dependency;
164
176
  dependency.id = id;
165
- dependency.env.id = getEnvId(dependency.env);
177
+ dependency.env.id = (0, _featureFlags().getFeatureFlag)('environmentDeduplication') ?
178
+ // TODO: Rust can do this and avoid copying a significant amount of data over
179
+ (0, _Environment.getEnvironmentHash)(dependency.env) : getEnvId(dependency.env);
180
+ dependency.env = (0, _EnvironmentManager.toEnvironmentRef)(dependency.env);
166
181
  if (dependency.symbols != null) {
167
182
  var _dependency$symbols;
168
183
  dependency.symbols = new Map((_dependency$symbols = dependency.symbols) === null || _dependency$symbols === void 0 ? void 0 : _dependency$symbols.map(mapSymbols));
@@ -31,6 +31,7 @@ var _ConfigRequest = require("./ConfigRequest");
31
31
  var _projectPath = require("../projectPath");
32
32
  var _ReporterRunner = require("../ReporterRunner");
33
33
  var _RequestTracker = require("../RequestTracker");
34
+ var _EnvironmentManager = require("../EnvironmentManager");
34
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
36
  function createAssetRequest(input) {
36
37
  return {
@@ -42,7 +43,7 @@ function createAssetRequest(input) {
42
43
  }
43
44
  const type = 'asset_request';
44
45
  function getId(input) {
45
- return (0, _rust().hashString)(type + (0, _projectPath.fromProjectPathRelative)(input.filePath) + input.env.id + String(input.isSource) + String(input.sideEffects) + (input.code ?? '') + ':' + (input.pipeline ?? '') + ':' + (input.query ?? ''));
46
+ return (0, _rust().hashString)(type + (0, _projectPath.fromProjectPathRelative)(input.filePath) + (0, _EnvironmentManager.toEnvironmentId)(input.env) + String(input.isSource) + String(input.sideEffects) + (input.code ?? '') + ':' + (input.pipeline ?? '') + ':' + (input.query ?? ''));
46
47
  }
47
48
  async function run({
48
49
  input,
@@ -32,6 +32,13 @@ function _logger() {
32
32
  };
33
33
  return data;
34
34
  }
35
+ function _featureFlags() {
36
+ const data = require("@atlaspack/feature-flags");
37
+ _featureFlags = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
35
42
  function _diagnostic() {
36
43
  const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
37
44
  _diagnostic = function () {
@@ -225,7 +232,12 @@ class BundlerRunner {
225
232
  this.devDepRequests = new Map();
226
233
  this.configs = new Map();
227
234
  this.pluginOptions = new _PluginOptions.default((0, _utils2.optionsProxy)(this.options, api.invalidateOnOptionChange));
228
- this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
235
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
236
+ const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
237
+ this.cacheKey = `BundleGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
238
+ } else {
239
+ this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
240
+ }
229
241
  }
230
242
  async loadConfigs() {
231
243
  // Load all configs up front so we can use them in the cache key
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getConfigHash = getConfigHash;
7
7
  exports.getConfigKeyContentHash = getConfigKeyContentHash;
8
8
  exports.getConfigRequests = getConfigRequests;
9
+ exports.getValueAtPath = getValueAtPath;
9
10
  exports.loadPluginConfig = loadPluginConfig;
10
11
  exports.runConfigRequest = runConfigRequest;
11
12
  function _utils() {
@@ -86,19 +87,41 @@ async function loadPluginConfig(loadedPlugin, config, options) {
86
87
  });
87
88
  }
88
89
  }
90
+
91
+ /**
92
+ * Return value at a given key path within an object.
93
+ *
94
+ * @example
95
+ * const obj = { a: { b: { c: 'd' } } };
96
+ * getValueAtPath(obj, ['a', 'b', 'c']); // 'd'
97
+ * getValueAtPath(obj, ['a', 'b', 'd']); // undefined
98
+ * getValueAtPath(obj, ['a', 'b']); // { c: 'd' }
99
+ * getValueAtPath(obj, ['a', 'b', 'c', 'd']); // undefined
100
+ */
101
+ function getValueAtPath(obj, key) {
102
+ let current = obj;
103
+ for (let part of key) {
104
+ if (current == null) {
105
+ return undefined;
106
+ }
107
+ current = current[part];
108
+ }
109
+ return current;
110
+ }
89
111
  const configKeyCache = (0, _buildCache().createBuildCache)();
90
112
  async function getConfigKeyContentHash(filePath, configKey, options) {
91
- let cacheKey = `${(0, _projectPath.fromProjectPathRelative)(filePath)}:${configKey}`;
113
+ let cacheKey = `${(0, _projectPath.fromProjectPathRelative)(filePath)}:${JSON.stringify(configKey)}`;
92
114
  let cachedValue = configKeyCache.get(cacheKey);
93
115
  if (cachedValue) {
94
116
  return cachedValue;
95
117
  }
96
- let conf = await (0, _utils().readConfig)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, filePath));
97
- if (conf == null || conf.config[configKey] == null) {
118
+ const conf = await (0, _utils().readConfig)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, filePath));
119
+ const value = getValueAtPath(conf === null || conf === void 0 ? void 0 : conf.config, configKey);
120
+ if (conf == null || value == null) {
98
121
  // This can occur when a config key has been removed entirely during `respondToFSEvents`
99
122
  return '';
100
123
  }
101
- let contentHash = typeof conf.config[configKey] === 'object' ? (0, _utils().hashObject)(conf.config[configKey]) : (0, _rust().hashString)(JSON.stringify(conf.config[configKey]));
124
+ const contentHash = typeof value === 'object' ? (0, _utils().hashObject)(value) : (0, _rust().hashString)(JSON.stringify(value));
102
125
  configKeyCache.set(cacheKey, contentHash);
103
126
  return contentHash;
104
127
  }
@@ -89,7 +89,17 @@ async function createDevDependency(opts, requestDevDeps, options) {
89
89
  return devDepRequest;
90
90
  }
91
91
  async function getDevDepRequests(api) {
92
- let previousDevDepRequests = new Map(await Promise.all(api.getSubRequests().filter(req => req.requestType === _RequestTracker.requestTypes.dev_dep_request).map(async req => [req.id, (0, _nullthrows().default)(await api.getRequestResult(req.id))])));
92
+ async function getPreviousDevDepRequests() {
93
+ const allDevDepRequests = await Promise.all(api.getSubRequests().filter(req => req.requestType === _RequestTracker.requestTypes.dev_dep_request).map(async req => [req.id, await api.getRequestResult(req.id)]));
94
+ const nonNullDevDepRequests = [];
95
+ for (const [id, result] of allDevDepRequests) {
96
+ if (result != null) {
97
+ nonNullDevDepRequests.push([id, result]);
98
+ }
99
+ }
100
+ return new Map(nonNullDevDepRequests);
101
+ }
102
+ const previousDevDepRequests = await getPreviousDevDepRequests();
93
103
  return {
94
104
  devDeps: new Map([...previousDevDepRequests.entries()].filter(([id]) => api.canSkipSubrequest(id)).map(([, req]) => [`${req.specifier}:${(0, _projectPath.fromProjectPathRelative)(req.resolveFrom)}`, req.hash])),
95
105
  invalidDevDeps: await Promise.all([...previousDevDepRequests.entries()].filter(([id]) => !api.canSkipSubrequest(id)).flatMap(([, req]) => {
@@ -26,6 +26,13 @@ function _logger() {
26
26
  };
27
27
  return data;
28
28
  }
29
+ function _featureFlags() {
30
+ const data = require("@atlaspack/feature-flags");
31
+ _featureFlags = function () {
32
+ return data;
33
+ };
34
+ return data;
35
+ }
29
36
  function _nullthrows() {
30
37
  const data = _interopRequireDefault(require("nullthrows"));
31
38
  _nullthrows = function () {
@@ -259,6 +266,9 @@ class ResolverRunner {
259
266
  }
260
267
  if (result.priority != null) {
261
268
  dependency.priority = _types.Priority[result.priority];
269
+ if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
270
+ dependency.resolverPriority = dependency.priority;
271
+ }
262
272
  }
263
273
  if (result.invalidateOnEnvChange) {
264
274
  invalidateOnEnvChange.push(...result.invalidateOnEnvChange);
@@ -69,6 +69,7 @@ var _Environment2 = require("../public/Environment");
69
69
  var _utils2 = require("../utils");
70
70
  var _projectPath = require("../projectPath");
71
71
  var _RequestTracker = require("../RequestTracker");
72
+ var _EnvironmentManager = require("../EnvironmentManager");
72
73
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
73
74
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
74
75
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -245,7 +246,7 @@ class TargetResolver {
245
246
  }
246
247
  });
247
248
  }
248
- if (!_Environment2.BROWSER_ENVS.has(targets[0].env.context)) {
249
+ if (!_Environment2.BROWSER_ENVS.has((0, _EnvironmentManager.fromEnvironmentId)(targets[0].env).context)) {
249
250
  throw new (_diagnostic().default)({
250
251
  diagnostic: {
251
252
  message: `Only browser targets are supported in serve mode`,
@@ -1073,22 +1074,23 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1073
1074
 
1074
1075
  // Resolve relevant engines for context.
1075
1076
  let engines;
1076
- switch (target.env.context) {
1077
+ const env = (0, _EnvironmentManager.fromEnvironmentId)(target.env);
1078
+ switch (env.context) {
1077
1079
  case 'browser':
1078
1080
  case 'web-worker':
1079
1081
  case 'service-worker':
1080
1082
  case 'worklet':
1081
1083
  {
1082
- let browsers = target.env.engines.browsers;
1084
+ let browsers = env.engines.browsers;
1083
1085
  engines = Array.isArray(browsers) ? browsers.join(', ') : browsers;
1084
1086
  break;
1085
1087
  }
1086
1088
  case 'node':
1087
- engines = target.env.engines.node;
1089
+ engines = env.engines.node;
1088
1090
  break;
1089
1091
  case 'electron-main':
1090
1092
  case 'electron-renderer':
1091
- engines = target.env.engines.electron;
1093
+ engines = env.engines.electron;
1092
1094
  break;
1093
1095
  }
1094
1096
  let highlights = [];
@@ -1124,7 +1126,7 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1124
1126
  highlight.defined = (0, _diagnostic().md)`${key} defined here`;
1125
1127
  }
1126
1128
  if (keyInfo.inferred) {
1127
- highlight.inferred.push((0, _diagnostic().md)`${key} to be ${JSON.stringify(target.env[key])}`);
1129
+ highlight.inferred.push((0, _diagnostic().md)`${key} to be ${JSON.stringify(env[key])}`);
1128
1130
  }
1129
1131
  }
1130
1132
 
@@ -1150,12 +1152,12 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1150
1152
 
1151
1153
  // Format includeNodeModules to be human readable.
1152
1154
  let includeNodeModules;
1153
- if (typeof target.env.includeNodeModules === 'boolean') {
1154
- includeNodeModules = String(target.env.includeNodeModules);
1155
- } else if (Array.isArray(target.env.includeNodeModules)) {
1156
- includeNodeModules = 'only ' + listFormat.format(target.env.includeNodeModules.map(m => JSON.stringify(m)));
1157
- } else if (target.env.includeNodeModules && typeof target.env.includeNodeModules === 'object') {
1158
- includeNodeModules = 'all except ' + listFormat.format(Object.entries(target.env.includeNodeModules).filter(([, v]) => v === false).map(([k]) => JSON.stringify(k)));
1155
+ if (typeof env.includeNodeModules === 'boolean') {
1156
+ includeNodeModules = String(env.includeNodeModules);
1157
+ } else if (Array.isArray(env.includeNodeModules)) {
1158
+ includeNodeModules = 'only ' + listFormat.format(env.includeNodeModules.map(m => JSON.stringify(m)));
1159
+ } else if (env.includeNodeModules && typeof env.includeNodeModules === 'object') {
1160
+ includeNodeModules = 'all except ' + listFormat.format(Object.entries(env.includeNodeModules).filter(([, v]) => v === false).map(([k]) => JSON.stringify(k)));
1159
1161
  }
1160
1162
  let format = v => v.message != null ? _diagnostic().md.italic(v.message) : '';
1161
1163
  _logger().default.verbose({
@@ -1164,12 +1166,12 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1164
1166
 
1165
1167
  **Entry**: ${_path().default.relative(process.cwd(), (0, _projectPath.fromProjectPath)(options.projectRoot, input.filePath))}
1166
1168
  **Output**: ${_path().default.relative(process.cwd(), output)}
1167
- **Format**: ${target.env.outputFormat} ${format(info.outputFormat)}
1168
- **Context**: ${target.env.context} ${format(info.context)}
1169
+ **Format**: ${env.outputFormat} ${format(info.outputFormat)}
1170
+ **Context**: ${env.context} ${format(info.context)}
1169
1171
  **Engines**: ${engines || ''} ${format(info.engines)}
1170
- **Library Mode**: ${String(target.env.isLibrary)} ${format(info.isLibrary)}
1172
+ **Library Mode**: ${String(env.isLibrary)} ${format(info.isLibrary)}
1171
1173
  **Include Node Modules**: ${includeNodeModules} ${format(info.includeNodeModules)}
1172
- **Optimize**: ${String(target.env.shouldOptimize)} ${format(info.shouldOptimize)}`,
1174
+ **Optimize**: ${String(env.shouldOptimize)} ${format(info.shouldOptimize)}`,
1173
1175
  codeFrames: target.loc ? [{
1174
1176
  filePath: targetFilePath,
1175
1177
  codeHighlights: highlights
@@ -61,6 +61,14 @@ function _profiler() {
61
61
  return data;
62
62
  }
63
63
  var _RequestTracker = require("../RequestTracker");
64
+ function _featureFlags() {
65
+ const data = require("@atlaspack/feature-flags");
66
+ _featureFlags = function () {
67
+ return data;
68
+ };
69
+ return data;
70
+ }
71
+ var _EnvironmentManager = require("../EnvironmentManager");
64
72
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
65
73
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
66
74
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -114,7 +122,8 @@ async function run({
114
122
  let cacheKeys = info.cacheKeys;
115
123
  let mapKey = cacheKeys.map;
116
124
  let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
117
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline) {
125
+ const env = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
126
+ if (mapKey && env.sourceMap && !env.sourceMap.inline) {
118
127
  api.invalidateOnFileDelete((0, _projectPath.toProjectPath)(options.projectRoot, fullPath + '.map'));
119
128
  }
120
129
  let dir = _path().default.dirname(fullPath);
@@ -145,11 +154,14 @@ async function run({
145
154
  } = await (0, _DevDepRequest.getDevDepRequests)(api);
146
155
  (0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, options, config);
147
156
  await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api);
148
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline && (await options.cache.has(mapKey))) {
149
- await writeFiles((0, _utils().blobToStream)(await options.cache.getBlob(mapKey)), info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
157
+ const hasSourceMap = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.hasLargeBlob(mapKey) : await options.cache.has(mapKey);
158
+ if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
159
+ const mapEntry = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.getLargeBlob(mapKey) : await options.cache.getBlob(mapKey);
160
+ await writeFiles((0, _utils().blobToStream)(mapEntry), info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
150
161
  }
151
162
  let res = {
152
163
  filePath,
164
+ bundleId: bundle.id,
153
165
  type: info.type,
154
166
  stats: {
155
167
  size,
@@ -12,6 +12,7 @@ function _featureFlags() {
12
12
  return data;
13
13
  }
14
14
  var _RequestTracker = require("../RequestTracker");
15
+ var _ReporterRunner = require("../ReporterRunner");
15
16
  var _constants = require("../constants");
16
17
  var _projectPath = require("../projectPath");
17
18
  function _nullthrows() {
@@ -31,6 +32,18 @@ function _rust() {
31
32
  var _PackageRequest = require("./PackageRequest");
32
33
  var _WriteBundleRequest = _interopRequireDefault(require("./WriteBundleRequest"));
33
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ function reportPackagingProgress(completeBundles, totalBundles) {
36
+ if (!(0, _featureFlags().getFeatureFlag)('cliProgressReportingImprovements')) {
37
+ return;
38
+ }
39
+ (0, _ReporterRunner.report)({
40
+ type: 'buildProgress',
41
+ phase: 'packagingAndOptimizing',
42
+ totalBundles,
43
+ completeBundles
44
+ });
45
+ }
46
+
34
47
  /**
35
48
  * Packages, optimizes, and writes all bundles to the dist directory.
36
49
  */
@@ -76,6 +89,7 @@ async function run({
76
89
  let name = (0, _nullthrows().default)(bundle.name, `Expected ${bundle.type} bundle to have a name`).replace(bundle.hashReference, hash);
77
90
  res.set(bundle.id, {
78
91
  filePath: (0, _projectPath.joinProjectPath)(bundle.target.distDir, name),
92
+ bundleId: bundle.id,
79
93
  type: bundle.type,
80
94
  // FIXME: this is wrong if the packager changes the type...
81
95
  stats: {
@@ -87,11 +101,14 @@ async function run({
87
101
  }
88
102
  return true;
89
103
  });
104
+ let cachedBundles = new Set(bundles.filter(b => api.canSkipSubrequest(bundleGraph.getHash(b))));
90
105
 
91
106
  // Package on the main thread if there is only one bundle to package.
92
107
  // This avoids the cost of serializing the bundle graph for single file change builds.
93
- let useMainThread = bundles.length === 1 || bundles.filter(b => !api.canSkipSubrequest(bundleGraph.getHash(b))).length === 1;
108
+ let useMainThread = bundles.length === 1 || bundles.length - cachedBundles.size <= 1;
94
109
  try {
110
+ let completeBundles = cachedBundles.size;
111
+ reportPackagingProgress(completeBundles, bundles.length);
95
112
  await Promise.all(bundles.map(async bundle => {
96
113
  let request = (0, _PackageRequest.createPackageRequest)({
97
114
  bundle,
@@ -101,6 +118,10 @@ async function run({
101
118
  useMainThread
102
119
  });
103
120
  let info = await api.runRequest(request);
121
+ if (!cachedBundles.has(bundle)) {
122
+ completeBundles++;
123
+ reportPackagingProgress(completeBundles, bundles.length);
124
+ }
104
125
  if (!useMainThread) {
105
126
  // Force a refresh of the cache to avoid a race condition
106
127
  // between threaded reads and writes that can result in an LMDB cache miss:
@@ -139,16 +139,19 @@ async function resolveOptions(initialOptions) {
139
139
  // where symlinked dependencies outside the project root need to trigger HMR
140
140
  // updates. Default to the project root if not provided.
141
141
  let watchDir = initialOptions.watchDir != null ? _path().default.resolve(initialOptions.watchDir) : projectRoot;
142
- let cache = function createCache() {
142
+ function createCache() {
143
143
  if (initialOptions.cache) {
144
144
  return initialOptions.cache;
145
145
  }
146
146
  const needsRustLmdbCache = (0, _featureFlags().getFeatureFlag)('atlaspackV3');
147
- if (!needsRustLmdbCache && !(outputFS instanceof _fs().NodeFS)) {
148
- return new (_cache().FSCache)(outputFS, cacheDir);
147
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
148
+ if (!needsRustLmdbCache && !(outputFS instanceof _fs().NodeFS)) {
149
+ return new (_cache().FSCache)(outputFS, cacheDir);
150
+ }
149
151
  }
150
152
  return new (_cache().LMDBLiteCache)(cacheDir);
151
- }();
153
+ }
154
+ let cache = createCache();
152
155
  let mode = initialOptions.mode ?? 'development';
153
156
  let shouldOptimize = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau = initialOptions.defaultTargetOptions) === null || _initialOptions$defau === void 0 ? void 0 : _initialOptions$defau.shouldOptimize) ?? mode === 'production';
154
157
  let publicUrl = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau2 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau2 === void 0 ? void 0 : _initialOptions$defau2.publicUrl) ?? '/';
package/lib/worker.js CHANGED
@@ -172,7 +172,24 @@ async function childInit() {
172
172
  await (_rust().init === null || _rust().init === void 0 ? void 0 : (0, _rust().init)());
173
173
  }
174
174
  const PKG_RE = /node_modules[/\\]((?:@[^/\\]+[/\\][^/\\]+)|[^/\\]+)(?!.*[/\\]node_modules[/\\])/;
175
- function invalidateRequireCache() {
175
+ function invalidateRequireCache(workerApi, file) {
176
+ if (process.env.ATLASPACK_BUILD_ENV === 'test') {
177
+ // Delete this module and all children in the same node_modules folder
178
+ let module = require.cache[file];
179
+ if (module) {
180
+ var _file$match;
181
+ delete require.cache[file];
182
+ let pkg = (_file$match = file.match(PKG_RE)) === null || _file$match === void 0 ? void 0 : _file$match[1];
183
+ for (let child of module.children) {
184
+ var _child$id$match;
185
+ if (pkg === ((_child$id$match = child.id.match(PKG_RE)) === null || _child$id$match === void 0 ? void 0 : _child$id$match[1])) {
186
+ invalidateRequireCache(workerApi, child.id);
187
+ }
188
+ }
189
+ }
190
+ atlaspackConfigCache.clear();
191
+ return;
192
+ }
176
193
  throw new Error('invalidateRequireCache is only for tests');
177
194
  }
178
195