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

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 +33 -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
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ exports.makeConfigProxy = makeConfigProxy;
7
8
  function _assert() {
8
9
  const data = _interopRequireDefault(require("assert"));
9
10
  _assert = function () {
@@ -34,8 +35,74 @@ function _featureFlags() {
34
35
  };
35
36
  return data;
36
37
  }
38
+ var _EnvironmentManager = require("../EnvironmentManager");
37
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
40
  const internalConfigToConfig = new (_utils().DefaultWeakMap)(() => new WeakMap());
41
+
42
+ /**
43
+ * Implements read tracking over an object.
44
+ *
45
+ * Calling this function with a non-trivial object like a class instance will fail to work.
46
+ *
47
+ * We track reads to fields that resolve to:
48
+ *
49
+ * - primitive values
50
+ * - arrays
51
+ *
52
+ * That is, reading a nested field `a.b.c` will make a single call to `onRead` with the path
53
+ * `['a', 'b', 'c']`.
54
+ *
55
+ * In case the value is null or an array, we will track the read as well.
56
+ *
57
+ * Iterating over `Object.keys(obj.field)` will register a read for the `['field']` path.
58
+ * Other reads work normally.
59
+ *
60
+ * @example
61
+ *
62
+ * const usedPaths = new Set();
63
+ * const onRead = (path) => {
64
+ * usedPaths.add(path);
65
+ * };
66
+ *
67
+ * const config = makeConfigProxy(onRead, {a: {b: {c: 'd'}}})
68
+ * console.log(config.a.b.c);
69
+ * console.log(Array.from(usedPaths));
70
+ * // We get a single read for the path
71
+ * // ['a', 'b', 'c']
72
+ *
73
+ */
74
+ function makeConfigProxy(onRead, config) {
75
+ const reportedPaths = new Set();
76
+ const reportPath = path => {
77
+ if (reportedPaths.has(path)) {
78
+ return;
79
+ }
80
+ reportedPaths.add(path);
81
+ onRead(path);
82
+ };
83
+ const makeProxy = (target, path) => {
84
+ return new Proxy(target, {
85
+ ownKeys(target) {
86
+ reportPath(path);
87
+
88
+ // $FlowFixMe
89
+ return Object.getOwnPropertyNames(target);
90
+ },
91
+ get(target, prop) {
92
+ // $FlowFixMe
93
+ const value = target[prop];
94
+ if (typeof value === 'object' && value != null && !Array.isArray(value)) {
95
+ return makeProxy(value, [...path, prop]);
96
+ }
97
+ reportPath([...path, prop]);
98
+ return value;
99
+ }
100
+ });
101
+ };
102
+
103
+ // $FlowFixMe
104
+ return makeProxy(config, []);
105
+ }
39
106
  class PublicConfig {
40
107
  #config /*: Config */;
41
108
  #pkg /*: ?PackageJSON */;
@@ -53,7 +120,7 @@ class PublicConfig {
53
120
  return this;
54
121
  }
55
122
  get env() {
56
- return new _Environment.default(this.#config.env, this.#options);
123
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#config.env), this.#options);
57
124
  }
58
125
  get searchPath() {
59
126
  return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#config.searchPath);
@@ -126,32 +193,30 @@ class PublicConfig {
126
193
  });
127
194
  if (pkg && pkg.contents[packageKey]) {
128
195
  // Invalidate only when the package key changes
129
- this.invalidateOnConfigKeyChange(pkg.filePath, packageKey);
196
+ this.invalidateOnConfigKeyChange(pkg.filePath, [packageKey]);
130
197
  return {
131
198
  contents: pkg.contents[packageKey],
132
199
  filePath: pkg.filePath
133
200
  };
134
201
  }
135
202
  }
136
- if ((0, _featureFlags().getFeatureFlag)('granularTsConfigInvalidation')) {
137
- const configKey = options === null || options === void 0 ? void 0 : options.configKey;
138
- if (configKey != null) {
139
- for (let fileName of fileNames) {
140
- let config = await this.getConfigFrom(searchPath, [fileName], {
141
- exclude: true
203
+ const readTracking = options === null || options === void 0 ? void 0 : options.readTracking;
204
+ if (readTracking === true) {
205
+ for (let fileName of fileNames) {
206
+ const config = await this.getConfigFrom(searchPath, [fileName], {
207
+ exclude: true
208
+ });
209
+ if (config != null) {
210
+ return Promise.resolve({
211
+ contents: makeConfigProxy(keyPath => {
212
+ this.invalidateOnConfigKeyChange(config.filePath, keyPath);
213
+ }, config.contents),
214
+ filePath: config.filePath
142
215
  });
143
- if (config && config.contents[configKey]) {
144
- // Invalidate only when the package key changes
145
- this.invalidateOnConfigKeyChange(config.filePath, configKey);
146
- return {
147
- contents: config.contents[configKey],
148
- filePath: config.filePath
149
- };
150
- }
151
216
  }
152
-
153
- // fall through so that file above invalidations are registered
154
217
  }
218
+
219
+ // fall through so that file above invalidations are registered
155
220
  }
156
221
 
157
222
  if (fileNames.length === 0) {
@@ -218,7 +283,9 @@ class PublicConfig {
218
283
  if (this.#pkg) {
219
284
  return this.#pkg;
220
285
  }
221
- let pkgConfig = await this.getConfig(['package.json']);
286
+ let pkgConfig = await this.getConfig(['package.json'], {
287
+ readTracking: (0, _featureFlags().getFeatureFlag)('granularTsConfigInvalidation')
288
+ });
222
289
  if (!pkgConfig) {
223
290
  return null;
224
291
  }
@@ -19,6 +19,7 @@ var _Target = _interopRequireDefault(require("./Target"));
19
19
  var _Symbols = require("./Symbols");
20
20
  var _projectPath = require("../projectPath");
21
21
  var _utils = require("../utils");
22
+ var _EnvironmentManager = require("../EnvironmentManager");
22
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
24
  const SpecifierTypeNames = Object.keys(_types.SpecifierType);
24
25
  const PriorityNames = Object.keys(_types.Priority);
@@ -80,7 +81,7 @@ class Dependency {
80
81
  return (0, _utils.fromInternalSourceLocation)(this.#options.projectRoot, this.#dep.loc);
81
82
  }
82
83
  get env() {
83
- return new _Environment.default(this.#dep.env, this.#options);
84
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#dep.env), this.#options);
84
85
  }
85
86
  get packageConditions() {
86
87
  // Merge custom conditions with conditions stored as bitflags.
@@ -38,6 +38,7 @@ var _projectPath = require("../projectPath");
38
38
  var _types = require("../types");
39
39
  var _BundleGroup = _interopRequireWildcard(require("./BundleGroup"));
40
40
  var _IdentifierRegistry = require("../IdentifierRegistry");
41
+ var _EnvironmentManager = require("../EnvironmentManager");
41
42
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
42
43
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
43
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -149,7 +150,7 @@ class MutableBundleGraph extends _BundleGraph.default {
149
150
  id: bundleId,
150
151
  hashReference: this.#options.shouldContentHash ? _constants.HASH_REF_PREFIX + bundleId : bundleId.slice(-8),
151
152
  type: opts.entryAsset ? opts.entryAsset.type : opts.type,
152
- env: opts.env ? (0, _Environment.environmentToInternalEnvironment)(opts.env) : (0, _nullthrows().default)(entryAsset).env,
153
+ env: opts.env ? (0, _EnvironmentManager.toEnvironmentRef)((0, _Environment.environmentToInternalEnvironment)(opts.env)) : (0, _nullthrows().default)(entryAsset).env,
153
154
  entryAssetIds: entryAsset ? [entryAsset.id] : [],
154
155
  mainEntryId: entryAsset === null || entryAsset === void 0 ? void 0 : entryAsset.id,
155
156
  pipeline: opts.entryAsset ? opts.entryAsset.pipeline : opts.pipeline,
@@ -29,6 +29,9 @@ class PluginOptions {
29
29
  get parcelVersion() {
30
30
  return this.#options.parcelVersion;
31
31
  }
32
+ get isAtlaspackSuper() {
33
+ return Boolean(this.#options.isAtlaspackSuper);
34
+ }
32
35
  get hmrOptions() {
33
36
  return this.#options.hmrOptions;
34
37
  }
@@ -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,
@@ -40,7 +40,7 @@ function _diagnostic() {
40
40
  return data;
41
41
  }
42
42
  function _json() {
43
- const data = require("json5");
43
+ const data = _interopRequireDefault(require("json5"));
44
44
  _json = function () {
45
45
  return data;
46
46
  };
@@ -60,11 +60,13 @@ function _assert() {
60
60
  };
61
61
  return data;
62
62
  }
63
+ var _internalPlugins = _interopRequireDefault(require("../internal-plugins"));
63
64
  var _AtlaspackConfig = require("../AtlaspackConfig");
64
65
  var _AtlaspackConfig2 = _interopRequireDefault(require("../AtlaspackConfig.schema"));
65
66
  var _projectPath = require("../projectPath");
66
67
  var _RequestTracker = require("../RequestTracker");
67
68
  var _utils2 = require("../utils");
69
+ var _isSuperPackage = require("../isSuperPackage");
68
70
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
71
  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); }
70
72
  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; }
@@ -134,28 +136,38 @@ async function resolveAtlaspackConfig(options) {
134
136
  let resolveFrom = getResolveFrom(options.inputFS, options.projectRoot);
135
137
  let configPath = options.config != null ? (await options.packageManager.resolve(options.config, resolveFrom)).resolved : await (0, _utils().resolveConfig)(options.inputFS, resolveFrom, ['.parcelrc'], options.projectRoot);
136
138
  let usedDefault = false;
137
- if (configPath == null && options.defaultConfig != null) {
139
+ let config, extendedFiles;
140
+ if (configPath == null && options.defaultConfig != null && (0, _isSuperPackage.isSuperPackage)() && options.defaultConfig.endsWith('.js')) {
138
141
  usedDefault = true;
139
- configPath = (await options.packageManager.resolve(options.defaultConfig, resolveFrom)).resolved;
140
- }
141
- if (configPath == null) {
142
- return null;
143
- }
144
- let contents;
145
- try {
146
- contents = await options.inputFS.readFile(configPath, 'utf8');
147
- } catch (e) {
148
- throw new (_diagnostic().default)({
149
- diagnostic: {
150
- message: (0, _diagnostic().md)`Could not find parcel config at ${_path().default.relative(options.projectRoot, configPath)}`,
151
- origin: '@atlaspack/core'
152
- }
153
- });
142
+ // Load the super package default config
143
+ let result = await processConfigChain(_internalPlugins.default['@atlaspack/config-default'](),
144
+ // $FlowFixMe
145
+ options.defaultConfig, options);
146
+ config = result.config;
147
+ extendedFiles = result.extendedFiles;
148
+ } else {
149
+ if (configPath == null && options.defaultConfig != null) {
150
+ usedDefault = true;
151
+ configPath = (await options.packageManager.resolve(options.defaultConfig, resolveFrom)).resolved;
152
+ }
153
+ if (configPath == null) {
154
+ return null;
155
+ }
156
+ let contents;
157
+ try {
158
+ contents = await options.inputFS.readFile(configPath, 'utf8');
159
+ } catch (e) {
160
+ throw new (_diagnostic().default)({
161
+ diagnostic: {
162
+ message: (0, _diagnostic().md)`Could not find parcel config at ${_path().default.relative(options.projectRoot, configPath)}`,
163
+ origin: '@atlaspack/core'
164
+ }
165
+ });
166
+ }
167
+ let result = await parseAndProcessConfig(configPath, contents, options);
168
+ config = result.config;
169
+ extendedFiles = result.extendedFiles;
154
170
  }
155
- let {
156
- config,
157
- extendedFiles
158
- } = await parseAndProcessConfig(configPath, contents, options);
159
171
  if (options.additionalReporters.length > 0) {
160
172
  config.reporters = [...options.additionalReporters.map(({
161
173
  packageName,
@@ -179,7 +191,7 @@ function create(config, options) {
179
191
  async function parseAndProcessConfig(configPath, contents, options) {
180
192
  let config;
181
193
  try {
182
- config = (0, _json().parse)(contents);
194
+ config = _json().default.parse(contents);
183
195
  } catch (e) {
184
196
  let pos = {
185
197
  line: e.lineNumber,
@@ -304,13 +316,16 @@ async function processConfigChain(configFile, filePath, options) {
304
316
  for (let ext of exts) {
305
317
  try {
306
318
  let key = Array.isArray(configFile.extends) ? `/extends/${i}` : '/extends';
307
- let resolved = await resolveExtends(ext, filePath, key, options);
308
- extendedFiles.push(resolved);
309
- let {
310
- extendedFiles: moreExtendedFiles,
311
- config: nextConfig
312
- } = await processExtendedConfig(filePath, key, ext, resolved, options);
313
- extendedFiles = extendedFiles.concat(moreExtendedFiles);
319
+ let nextConfig;
320
+ if (_internalPlugins.default[ext]) {
321
+ nextConfig = (await processConfigChain(_internalPlugins.default[ext](), /*#__ATLASPACK_IGNORE__*/__dirname, options)).config;
322
+ } else {
323
+ let resolved = await resolveExtends(ext, filePath, key, options);
324
+ extendedFiles.push(resolved);
325
+ let result = await processExtendedConfig(filePath, key, ext, resolved, options);
326
+ extendedFiles = extendedFiles.concat(result.extendedFiles);
327
+ nextConfig = result.config;
328
+ }
314
329
  extStartConfig = extStartConfig ? mergeConfigs(extStartConfig, nextConfig) : nextConfig;
315
330
  } catch (err) {
316
331
  errors.push(err);
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getConfigHash = getConfigHash;
7
7
  exports.getConfigKeyContentHash = getConfigKeyContentHash;
8
8
  exports.getConfigRequests = getConfigRequests;
9
+ exports.getValueAtPath = getValueAtPath;
9
10
  exports.loadPluginConfig = loadPluginConfig;
10
11
  exports.runConfigRequest = runConfigRequest;
11
12
  function _utils() {
@@ -86,19 +87,41 @@ async function loadPluginConfig(loadedPlugin, config, options) {
86
87
  });
87
88
  }
88
89
  }
90
+
91
+ /**
92
+ * Return value at a given key path within an object.
93
+ *
94
+ * @example
95
+ * const obj = { a: { b: { c: 'd' } } };
96
+ * getValueAtPath(obj, ['a', 'b', 'c']); // 'd'
97
+ * getValueAtPath(obj, ['a', 'b', 'd']); // undefined
98
+ * getValueAtPath(obj, ['a', 'b']); // { c: 'd' }
99
+ * getValueAtPath(obj, ['a', 'b', 'c', 'd']); // undefined
100
+ */
101
+ function getValueAtPath(obj, key) {
102
+ let current = obj;
103
+ for (let part of key) {
104
+ if (current == null) {
105
+ return undefined;
106
+ }
107
+ current = current[part];
108
+ }
109
+ return current;
110
+ }
89
111
  const configKeyCache = (0, _buildCache().createBuildCache)();
90
112
  async function getConfigKeyContentHash(filePath, configKey, options) {
91
- let cacheKey = `${(0, _projectPath.fromProjectPathRelative)(filePath)}:${configKey}`;
113
+ let cacheKey = `${(0, _projectPath.fromProjectPathRelative)(filePath)}:${JSON.stringify(configKey)}`;
92
114
  let cachedValue = configKeyCache.get(cacheKey);
93
115
  if (cachedValue) {
94
116
  return cachedValue;
95
117
  }
96
- let conf = await (0, _utils().readConfig)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, filePath));
97
- if (conf == null || conf.config[configKey] == null) {
118
+ const conf = await (0, _utils().readConfig)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, filePath));
119
+ const value = getValueAtPath(conf === null || conf === void 0 ? void 0 : conf.config, configKey);
120
+ if (conf == null || value == null) {
98
121
  // This can occur when a config key has been removed entirely during `respondToFSEvents`
99
122
  return '';
100
123
  }
101
- let contentHash = typeof conf.config[configKey] === 'object' ? (0, _utils().hashObject)(conf.config[configKey]) : (0, _rust().hashString)(JSON.stringify(conf.config[configKey]));
124
+ const contentHash = typeof value === 'object' ? (0, _utils().hashObject)(value) : (0, _rust().hashString)(JSON.stringify(value));
102
125
  configKeyCache.set(cacheKey, contentHash);
103
126
  return contentHash;
104
127
  }
@@ -69,6 +69,7 @@ var _Environment2 = require("../public/Environment");
69
69
  var _utils2 = require("../utils");
70
70
  var _projectPath = require("../projectPath");
71
71
  var _RequestTracker = require("../RequestTracker");
72
+ var _EnvironmentManager = require("../EnvironmentManager");
72
73
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
73
74
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
74
75
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -245,7 +246,7 @@ class TargetResolver {
245
246
  }
246
247
  });
247
248
  }
248
- if (!_Environment2.BROWSER_ENVS.has(targets[0].env.context)) {
249
+ if (!_Environment2.BROWSER_ENVS.has((0, _EnvironmentManager.fromEnvironmentId)(targets[0].env).context)) {
249
250
  throw new (_diagnostic().default)({
250
251
  diagnostic: {
251
252
  message: `Only browser targets are supported in serve mode`,
@@ -1073,22 +1074,23 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1073
1074
 
1074
1075
  // Resolve relevant engines for context.
1075
1076
  let engines;
1076
- switch (target.env.context) {
1077
+ const env = (0, _EnvironmentManager.fromEnvironmentId)(target.env);
1078
+ switch (env.context) {
1077
1079
  case 'browser':
1078
1080
  case 'web-worker':
1079
1081
  case 'service-worker':
1080
1082
  case 'worklet':
1081
1083
  {
1082
- let browsers = target.env.engines.browsers;
1084
+ let browsers = env.engines.browsers;
1083
1085
  engines = Array.isArray(browsers) ? browsers.join(', ') : browsers;
1084
1086
  break;
1085
1087
  }
1086
1088
  case 'node':
1087
- engines = target.env.engines.node;
1089
+ engines = env.engines.node;
1088
1090
  break;
1089
1091
  case 'electron-main':
1090
1092
  case 'electron-renderer':
1091
- engines = target.env.engines.electron;
1093
+ engines = env.engines.electron;
1092
1094
  break;
1093
1095
  }
1094
1096
  let highlights = [];
@@ -1124,7 +1126,7 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1124
1126
  highlight.defined = (0, _diagnostic().md)`${key} defined here`;
1125
1127
  }
1126
1128
  if (keyInfo.inferred) {
1127
- highlight.inferred.push((0, _diagnostic().md)`${key} to be ${JSON.stringify(target.env[key])}`);
1129
+ highlight.inferred.push((0, _diagnostic().md)`${key} to be ${JSON.stringify(env[key])}`);
1128
1130
  }
1129
1131
  }
1130
1132
 
@@ -1150,12 +1152,12 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1150
1152
 
1151
1153
  // Format includeNodeModules to be human readable.
1152
1154
  let includeNodeModules;
1153
- if (typeof target.env.includeNodeModules === 'boolean') {
1154
- includeNodeModules = String(target.env.includeNodeModules);
1155
- } else if (Array.isArray(target.env.includeNodeModules)) {
1156
- includeNodeModules = 'only ' + listFormat.format(target.env.includeNodeModules.map(m => JSON.stringify(m)));
1157
- } else if (target.env.includeNodeModules && typeof target.env.includeNodeModules === 'object') {
1158
- includeNodeModules = 'all except ' + listFormat.format(Object.entries(target.env.includeNodeModules).filter(([, v]) => v === false).map(([k]) => JSON.stringify(k)));
1155
+ if (typeof env.includeNodeModules === 'boolean') {
1156
+ includeNodeModules = String(env.includeNodeModules);
1157
+ } else if (Array.isArray(env.includeNodeModules)) {
1158
+ includeNodeModules = 'only ' + listFormat.format(env.includeNodeModules.map(m => JSON.stringify(m)));
1159
+ } else if (env.includeNodeModules && typeof env.includeNodeModules === 'object') {
1160
+ includeNodeModules = 'all except ' + listFormat.format(Object.entries(env.includeNodeModules).filter(([, v]) => v === false).map(([k]) => JSON.stringify(k)));
1159
1161
  }
1160
1162
  let format = v => v.message != null ? _diagnostic().md.italic(v.message) : '';
1161
1163
  _logger().default.verbose({
@@ -1164,12 +1166,12 @@ async function debugResolvedTargets(input, targets, targetInfo, options) {
1164
1166
 
1165
1167
  **Entry**: ${_path().default.relative(process.cwd(), (0, _projectPath.fromProjectPath)(options.projectRoot, input.filePath))}
1166
1168
  **Output**: ${_path().default.relative(process.cwd(), output)}
1167
- **Format**: ${target.env.outputFormat} ${format(info.outputFormat)}
1168
- **Context**: ${target.env.context} ${format(info.context)}
1169
+ **Format**: ${env.outputFormat} ${format(info.outputFormat)}
1170
+ **Context**: ${env.context} ${format(info.context)}
1169
1171
  **Engines**: ${engines || ''} ${format(info.engines)}
1170
- **Library Mode**: ${String(target.env.isLibrary)} ${format(info.isLibrary)}
1172
+ **Library Mode**: ${String(env.isLibrary)} ${format(info.isLibrary)}
1171
1173
  **Include Node Modules**: ${includeNodeModules} ${format(info.includeNodeModules)}
1172
- **Optimize**: ${String(target.env.shouldOptimize)} ${format(info.shouldOptimize)}`,
1174
+ **Optimize**: ${String(env.shouldOptimize)} ${format(info.shouldOptimize)}`,
1173
1175
  codeFrames: target.loc ? [{
1174
1176
  filePath: targetFilePath,
1175
1177
  codeHighlights: highlights
@@ -68,6 +68,7 @@ function _featureFlags() {
68
68
  };
69
69
  return data;
70
70
  }
71
+ var _EnvironmentManager = require("../EnvironmentManager");
71
72
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
72
73
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
73
74
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -121,7 +122,8 @@ async function run({
121
122
  let cacheKeys = info.cacheKeys;
122
123
  let mapKey = cacheKeys.map;
123
124
  let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
124
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline) {
125
+ const env = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
126
+ if (mapKey && env.sourceMap && !env.sourceMap.inline) {
125
127
  api.invalidateOnFileDelete((0, _projectPath.toProjectPath)(options.projectRoot, fullPath + '.map'));
126
128
  }
127
129
  let dir = _path().default.dirname(fullPath);
@@ -153,12 +155,13 @@ async function run({
153
155
  (0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, options, config);
154
156
  await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api);
155
157
  const hasSourceMap = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.hasLargeBlob(mapKey) : await options.cache.has(mapKey);
156
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline && hasSourceMap) {
158
+ if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
157
159
  const mapEntry = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.getLargeBlob(mapKey) : await options.cache.getBlob(mapKey);
158
160
  await writeFiles((0, _utils().blobToStream)(mapEntry), info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
159
161
  }
160
162
  let res = {
161
163
  filePath,
164
+ bundleId: bundle.id,
162
165
  type: info.type,
163
166
  stats: {
164
167
  size,
@@ -76,6 +76,7 @@ async function run({
76
76
  let name = (0, _nullthrows().default)(bundle.name, `Expected ${bundle.type} bundle to have a name`).replace(bundle.hashReference, hash);
77
77
  res.set(bundle.id, {
78
78
  filePath: (0, _projectPath.joinProjectPath)(bundle.target.distDir, name),
79
+ bundleId: bundle.id,
79
80
  type: bundle.type,
80
81
  // FIXME: this is wrong if the packager changes the type...
81
82
  stats: {
@@ -56,6 +56,7 @@ function _utils() {
56
56
  var _loadDotEnv = _interopRequireDefault(require("./loadDotEnv"));
57
57
  var _projectPath = require("./projectPath");
58
58
  var _AtlaspackConfigRequest = require("./requests/AtlaspackConfigRequest");
59
+ var _isSuperPackage = require("./isSuperPackage");
59
60
  var _constants = require("./constants");
60
61
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
61
62
  // Default cache directory name
@@ -139,7 +140,7 @@ async function resolveOptions(initialOptions) {
139
140
  // where symlinked dependencies outside the project root need to trigger HMR
140
141
  // updates. Default to the project root if not provided.
141
142
  let watchDir = initialOptions.watchDir != null ? _path().default.resolve(initialOptions.watchDir) : projectRoot;
142
- function createCache() {
143
+ let cache = function createCache() {
143
144
  if (initialOptions.cache) {
144
145
  return initialOptions.cache;
145
146
  }
@@ -150,8 +151,7 @@ async function resolveOptions(initialOptions) {
150
151
  }
151
152
  }
152
153
  return new (_cache().LMDBLiteCache)(cacheDir);
153
- }
154
- let cache = createCache();
154
+ }();
155
155
  let mode = initialOptions.mode ?? 'development';
156
156
  let shouldOptimize = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau = initialOptions.defaultTargetOptions) === null || _initialOptions$defau === void 0 ? void 0 : _initialOptions$defau.shouldOptimize) ?? mode === 'production';
157
157
  let publicUrl = (initialOptions === null || initialOptions === void 0 || (_initialOptions$defau2 = initialOptions.defaultTargetOptions) === null || _initialOptions$defau2 === void 0 ? void 0 : _initialOptions$defau2.publicUrl) ?? '/';
@@ -238,7 +238,8 @@ async function resolveOptions(initialOptions) {
238
238
  ..._featureFlags().DEFAULT_FEATURE_FLAGS,
239
239
  ...(initialOptions === null || initialOptions === void 0 ? void 0 : initialOptions.featureFlags)
240
240
  },
241
- parcelVersion: _constants.ATLASPACK_VERSION
241
+ parcelVersion: _constants.ATLASPACK_VERSION,
242
+ isAtlaspackSuper: (0, _isSuperPackage.isSuperPackage)()
242
243
  };
243
244
  }
244
245
  function getRelativeConfigSpecifier(fs, projectRoot, specifier) {
package/lib/worker.js CHANGED
@@ -78,15 +78,15 @@ require("@atlaspack/package-manager");
78
78
  require("@atlaspack/fs");
79
79
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
80
80
  // register with serializer
81
+ // Repl builds are currently not enabled
81
82
  // $FlowFixMe
82
- if (process.env.ATLASPACK_BUILD_REPL && process.browser) {
83
- /* eslint-disable import/no-extraneous-dependencies, monorepo/no-internal-import */
84
- require('@atlaspack/repl/src/atlaspack/BrowserPackageManager.js');
85
- // $FlowFixMe
86
- require('@atlaspack/repl/src/atlaspack/ExtendedMemoryFS.js');
87
- /* eslint-enable import/no-extraneous-dependencies, monorepo/no-internal-import */
88
- }
89
-
83
+ // if (process.env.ATLASPACK_BUILD_REPL && process.browser) {
84
+ // /* eslint-disable import/no-extraneous-dependencies, monorepo/no-internal-import */
85
+ // require('@atlaspack/repl/src/atlaspack/BrowserPackageManager.js');
86
+ // // $FlowFixMe
87
+ // require('@atlaspack/repl/src/atlaspack/ExtendedMemoryFS.js');
88
+ // /* eslint-enable import/no-extraneous-dependencies, monorepo/no-internal-import */
89
+ // }
90
90
  (0, _registerCoreWithSerializer.registerCoreWithSerializer)();
91
91
 
92
92
  // Remove the workerApi type from the TransformationOpts and ValidationOpts types:
@@ -172,24 +172,7 @@ 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(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
- }
175
+ function invalidateRequireCache() {
193
176
  throw new Error('invalidateRequireCache is only for tests');
194
177
  }
195
178