@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
@@ -95,6 +95,7 @@ function _perf_hooks() {
95
95
  };
96
96
  return data;
97
97
  }
98
+ var _EnvironmentManager = require("./EnvironmentManager");
98
99
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
99
100
  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); }
100
101
  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; }
@@ -162,7 +163,7 @@ const nodeFromOption = (option, value) => ({
162
163
  hash: (0, _utils2.hashFromOption)(value)
163
164
  });
164
165
  const nodeFromConfigKey = (fileName, configKey, contentHash) => ({
165
- id: `config_key:${(0, _projectPath.fromProjectPathRelative)(fileName)}:${configKey}`,
166
+ id: `config_key:${(0, _projectPath.fromProjectPathRelative)(fileName)}:${JSON.stringify(configKey)}`,
166
167
  type: CONFIG_KEY,
167
168
  configKey,
168
169
  contentHash
@@ -445,8 +446,8 @@ class RequestGraph extends _graph().ContentGraph {
445
446
  this.invalidateOnBuildNodeIds.add(requestNodeId);
446
447
  }
447
448
  invalidateOnEnvChange(requestNodeId, env, value) {
448
- let envNode = nodeFromEnv(env, value);
449
- let envNodeId = this.addNode(envNode);
449
+ const envNode = nodeFromEnv(env, value);
450
+ const envNodeId = this.addNode(envNode);
450
451
  if (!this.hasEdge(requestNodeId, envNodeId, requestGraphEdgeTypes.invalidated_by_update)) {
451
452
  this.addEdge(requestNodeId, envNodeId, requestGraphEdgeTypes.invalidated_by_update);
452
453
  }
@@ -695,10 +696,18 @@ class RequestGraph extends _graph().ContentGraph {
695
696
  this.removeNode(nodeId, removeOrphans);
696
697
  }
697
698
  let configKeyNodes = this.configKeyNodes.get(_filePath);
698
- if (configKeyNodes && (type === 'delete' || type === 'update')) {
699
+
700
+ // With granular invalidations we will always run this block,
701
+ // so even if we get a create event (for whatever reason), we will still
702
+ // try to limit invalidations from config key changes through hashing.
703
+ //
704
+ // Currently create events can invalidate a large number of nodes due to
705
+ // "create above" invalidations.
706
+ const isConfigKeyChange = (0, _featureFlags().getFeatureFlag)('granularTsConfigInvalidation') || type === 'delete' || type === 'update';
707
+ if (configKeyNodes && isConfigKeyChange) {
699
708
  for (let nodeId of configKeyNodes) {
700
709
  let isInvalid = type === 'delete';
701
- if (type === 'update') {
710
+ if (type !== 'delete') {
702
711
  let node = this.getNode(nodeId);
703
712
  (0, _assert().default)(node && node.type === CONFIG_KEY);
704
713
  let contentHash = await (0, _ConfigRequest.getConfigKeyContentHash)(_filePath, node.configKey, options);
@@ -714,8 +723,7 @@ class RequestGraph extends _graph().ContentGraph {
714
723
  }
715
724
  }
716
725
  const invalidationsAfter = this.getInvalidNodeCount();
717
- const invalidationsForEvent = invalidationsAfter - invalidationsBefore;
718
- invalidationsByPath.set(_path, (invalidationsByPath.get(_path) ?? 0) + invalidationsForEvent);
726
+ invalidationsByPath.set(_path, (invalidationsByPath.get(_path) ?? 0) + (invalidationsAfter - invalidationsBefore));
719
727
  }
720
728
  if ((0, _featureFlags().getFeatureFlag)('fixQuadraticCacheInvalidation')) {
721
729
  cleanUpOrphans(this);
@@ -950,41 +958,40 @@ class RequestTracker {
950
958
  }
951
959
  createAPI(requestId, previousInvalidations) {
952
960
  let subRequestContentKeys = new Set();
953
- let api = {
954
- invalidateOnFileCreate: input => this.graph.invalidateOnFileCreate(requestId, input),
955
- invalidateOnConfigKeyChange: (filePath, configKey, contentHash) => this.graph.invalidateOnConfigKeyChange(requestId, filePath, configKey, contentHash),
956
- invalidateOnFileDelete: filePath => this.graph.invalidateOnFileDelete(requestId, filePath),
957
- invalidateOnFileUpdate: filePath => this.graph.invalidateOnFileUpdate(requestId, filePath),
958
- invalidateOnStartup: () => this.graph.invalidateOnStartup(requestId),
959
- invalidateOnBuild: () => this.graph.invalidateOnBuild(requestId),
960
- invalidateOnEnvChange: env => this.graph.invalidateOnEnvChange(requestId, env, this.options.env[env]),
961
- invalidateOnOptionChange: option => this.graph.invalidateOnOptionChange(requestId, option, this.options[option]),
962
- getInvalidations: () => previousInvalidations,
963
- storeResult: (result, cacheKey) => {
964
- this.storeResult(requestId, result, cacheKey);
965
- },
966
- getSubRequests: () => this.graph.getSubRequests(requestId),
967
- getInvalidSubRequests: () => this.graph.getInvalidSubRequests(requestId),
968
- getPreviousResult: ifMatch => {
969
- var _this$graph$getNode;
970
- let contentKey = (0, _nullthrows().default)((_this$graph$getNode = this.graph.getNode(requestId)) === null || _this$graph$getNode === void 0 ? void 0 : _this$graph$getNode.id);
971
- return this.getRequestResult(contentKey, ifMatch);
972
- },
973
- getRequestResult: id => this.getRequestResult(id),
974
- canSkipSubrequest: contentKey => {
975
- if (this.graph.hasContentKey(contentKey) && this.hasValidResult(this.graph.getNodeIdByContentKey(contentKey))) {
976
- subRequestContentKeys.add(contentKey);
977
- return true;
961
+ return {
962
+ api: {
963
+ invalidateOnFileCreate: input => this.graph.invalidateOnFileCreate(requestId, input),
964
+ invalidateOnConfigKeyChange: (filePath, configKey, contentHash) => this.graph.invalidateOnConfigKeyChange(requestId, filePath, configKey, contentHash),
965
+ invalidateOnFileDelete: filePath => this.graph.invalidateOnFileDelete(requestId, filePath),
966
+ invalidateOnFileUpdate: filePath => this.graph.invalidateOnFileUpdate(requestId, filePath),
967
+ invalidateOnStartup: () => this.graph.invalidateOnStartup(requestId),
968
+ invalidateOnBuild: () => this.graph.invalidateOnBuild(requestId),
969
+ invalidateOnEnvChange: env => this.graph.invalidateOnEnvChange(requestId, env, this.options.env[env]),
970
+ invalidateOnOptionChange: option => this.graph.invalidateOnOptionChange(requestId, option, this.options[option]),
971
+ getInvalidations: () => previousInvalidations,
972
+ storeResult: (result, cacheKey) => {
973
+ this.storeResult(requestId, result, cacheKey);
974
+ },
975
+ getSubRequests: () => this.graph.getSubRequests(requestId),
976
+ getInvalidSubRequests: () => this.graph.getInvalidSubRequests(requestId),
977
+ getPreviousResult: ifMatch => {
978
+ var _this$graph$getNode;
979
+ let contentKey = (0, _nullthrows().default)((_this$graph$getNode = this.graph.getNode(requestId)) === null || _this$graph$getNode === void 0 ? void 0 : _this$graph$getNode.id);
980
+ return this.getRequestResult(contentKey, ifMatch);
981
+ },
982
+ getRequestResult: id => this.getRequestResult(id),
983
+ canSkipSubrequest: contentKey => {
984
+ if (this.graph.hasContentKey(contentKey) && this.hasValidResult(this.graph.getNodeIdByContentKey(contentKey))) {
985
+ subRequestContentKeys.add(contentKey);
986
+ return true;
987
+ }
988
+ return false;
989
+ },
990
+ runRequest: (subRequest, opts) => {
991
+ subRequestContentKeys.add(subRequest.id);
992
+ return this.runRequest(subRequest, opts);
978
993
  }
979
- return false;
980
994
  },
981
- runRequest: (subRequest, opts) => {
982
- subRequestContentKeys.add(subRequest.id);
983
- return this.runRequest(subRequest, opts);
984
- }
985
- };
986
- return {
987
- api,
988
995
  subRequestContentKeys
989
996
  };
990
997
  }
@@ -1017,6 +1024,9 @@ class RequestTracker {
1017
1024
  total,
1018
1025
  size: this.graph.nodes.length
1019
1026
  });
1027
+ if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
1028
+ await (0, _EnvironmentManager.writeEnvironmentsToCache)(options.cache);
1029
+ }
1020
1030
  let serialisedGraph = this.graph.serialize();
1021
1031
 
1022
1032
  // Delete an existing request graph cache, to prevent invalid states
@@ -1133,8 +1143,7 @@ function getWatcherOptions({
1133
1143
  watchDir,
1134
1144
  watchBackend
1135
1145
  }) {
1136
- const vcsDirs = ['.git', '.hg'];
1137
- const uniqueDirs = [...new Set([...watchIgnore, ...vcsDirs, cacheDir])];
1146
+ const uniqueDirs = [...new Set([...watchIgnore, ...['.git', '.hg'], cacheDir])];
1138
1147
  const ignore = uniqueDirs.map(dir => _path2().default.resolve(watchDir, dir));
1139
1148
  return {
1140
1149
  ignore,
@@ -1209,6 +1218,9 @@ async function loadRequestGraph(options) {
1209
1218
  ...commonMeta
1210
1219
  }
1211
1220
  });
1221
+ if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
1222
+ await (0, _EnvironmentManager.loadEnvironmentsFromCache)(options.cache);
1223
+ }
1212
1224
  const hasRequestGraphInCache = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.has(requestGraphKey) : await options.cache.hasLargeBlob(requestGraphKey);
1213
1225
  if (hasRequestGraphInCache) {
1214
1226
  try {
@@ -1325,15 +1337,13 @@ async function invalidateRequestGraph(requestGraph, options, events) {
1325
1337
  const invalidatedCount = invalidations.reduce((acc, invalidation) => acc + invalidation.count, 0);
1326
1338
  const requestCount = requestGraph.nodes.reduce((acc, node) => acc + ((node === null || node === void 0 ? void 0 : node.type) === REQUEST ? 1 : 0), 0);
1327
1339
  const nodeCount = requestGraph.nodes.length;
1328
- const nodeInvalidationRatio = invalidatedCount / nodeCount;
1329
- const requestInvalidationRatio = invalidatedCount / requestCount;
1330
1340
  return {
1331
1341
  invalidations,
1332
1342
  nodeCount,
1333
1343
  requestCount,
1334
1344
  invalidatedCount,
1335
- nodeInvalidationRatio,
1336
- requestInvalidationRatio
1345
+ nodeInvalidationRatio: invalidatedCount / nodeCount,
1346
+ requestInvalidationRatio: invalidatedCount / requestCount
1337
1347
  };
1338
1348
  }
1339
1349
  /**
@@ -173,12 +173,12 @@ class Transformation {
173
173
  });
174
174
 
175
175
  // Prefer `isSource` originating from the AssetRequest.
176
- let isSource = isSourceOverride ?? summarizedIsSource;
176
+
177
177
  return new _UncommittedAsset.default({
178
178
  value: (0, _assetUtils.createAsset)(this.options.projectRoot, {
179
179
  code,
180
180
  filePath,
181
- isSource,
181
+ isSource: isSourceOverride ?? summarizedIsSource,
182
182
  type: _path().default.extname((0, _projectPath.fromProjectPathRelative)(filePath)).slice(1),
183
183
  pipeline,
184
184
  env,
@@ -60,6 +60,7 @@ function _featureFlags() {
60
60
  };
61
61
  return data;
62
62
  }
63
+ var _EnvironmentManager = require("./EnvironmentManager");
63
64
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
64
65
  class UncommittedAsset {
65
66
  constructor({
@@ -278,7 +279,7 @@ class UncommittedAsset {
278
279
  ...rest,
279
280
  // $FlowFixMe "convert" the $ReadOnlyMaps to the interal mutable one
280
281
  symbols,
281
- env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, this.value.env, env),
282
+ env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, (0, _EnvironmentManager.fromEnvironmentId)(this.value.env), env),
282
283
  sourceAssetId: this.value.id,
283
284
  sourcePath: (0, _projectPath.fromProjectPath)(this.options.projectRoot, this.value.filePath)
284
285
  });
@@ -318,7 +319,7 @@ class UncommittedAsset {
318
319
  bundleBehavior: result.bundleBehavior ?? (this.value.bundleBehavior == null ? null : _types.BundleBehaviorNames[this.value.bundleBehavior]),
319
320
  isBundleSplittable: result.isBundleSplittable ?? this.value.isBundleSplittable,
320
321
  isSource: this.value.isSource,
321
- env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, this.value.env, result.env),
322
+ env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, (0, _EnvironmentManager.fromEnvironmentId)(this.value.env), result.env),
322
323
  dependencies: this.value.type === result.type ? new Map(this.value.dependencies) : new Map(),
323
324
  meta: {
324
325
  ...this.value.meta,
@@ -69,6 +69,7 @@ function _utils() {
69
69
  };
70
70
  return data;
71
71
  }
72
+ var _EnvironmentManager = require("./EnvironmentManager");
72
73
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
73
74
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
74
75
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -164,7 +165,7 @@ async function applyRuntimes({
164
165
  let assetGroup = {
165
166
  code,
166
167
  filePath: (0, _projectPath.toProjectPath)(options.projectRoot, sourceName),
167
- env: (0, _Environment.mergeEnvironments)(options.projectRoot, bundle.env, env),
168
+ env: (0, _Environment.mergeEnvironments)(options.projectRoot, (0, _EnvironmentManager.fromEnvironmentId)(bundle.env), env),
168
169
  // Runtime assets should be considered source, as they should be
169
170
  // e.g. compiled to run in the target environment
170
171
  isSource: true
package/lib/assetUtils.js CHANGED
@@ -66,10 +66,11 @@ function _profiler() {
66
66
  return data;
67
67
  }
68
68
  var _IdentifierRegistry = require("./IdentifierRegistry");
69
+ var _EnvironmentManager = require("./EnvironmentManager");
69
70
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
70
71
  function createAssetIdFromOptions(options) {
71
72
  const data = {
72
- environmentId: options.env.id,
73
+ environmentId: (0, _EnvironmentManager.toEnvironmentId)(options.env),
73
74
  filePath: options.filePath,
74
75
  code: options.code,
75
76
  pipeline: options.pipeline,
@@ -19,7 +19,46 @@ function _diagnostic() {
19
19
  };
20
20
  return data;
21
21
  }
22
+ var _isSuperPackage = require("../isSuperPackage");
23
+ function _path() {
24
+ const data = _interopRequireDefault(require("path"));
25
+ _path = function () {
26
+ return data;
27
+ };
28
+ return data;
29
+ }
22
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+ function getJsPaths() {
32
+ const dirname = /*#__ATLASPACK_IGNORE__*/__dirname;
33
+ if ((0, _isSuperPackage.isSuperPackage)()) {
34
+ // dirname: atlaspack/lib/core/core/atlaspack-v3
35
+ // core: atlaspack/lib/core/core/index.js
36
+ const corePath = _path().default.join(dirname, '..');
37
+ // esmodule helpers: atlaspack/lib/transformers/js/esmodule-helpers.js
38
+ const esmoduleHelpersPath = _path().default.join(dirname, '../../../transformers/js/esmodule-helpers.js');
39
+
40
+ // empty file: atlaspack/lib/core/core/_empty.js
41
+ const emptyFile = _path().default.join(dirname, '_empty.js');
42
+ return {
43
+ corePath,
44
+ esmoduleHelpersSpecifier: _path().default.relative(corePath, esmoduleHelpersPath),
45
+ esmoduleHelpersIncludeNodeModules: 'atlaspack',
46
+ emptyFile
47
+ };
48
+ }
49
+
50
+ // dirname: @atlaspack/core/lib/atlaspack-v3
51
+ // core: @atlaspack/core
52
+ const corePath = _path().default.join(dirname, '../..');
53
+ // empty file: atlaspack/lib/core/core/_empty.js
54
+ const emptyFile = _path().default.join(dirname, '_empty.js');
55
+ return {
56
+ corePath,
57
+ esmoduleHelpersSpecifier: '@atlaspack/transformer-js/src/esmodule-helpers.js',
58
+ esmoduleHelpersIncludeNodeModules: '@atlaspack/transformer-js',
59
+ emptyFile
60
+ };
61
+ }
23
62
  class AtlaspackV3 {
24
63
  constructor(atlaspack_napi) {
25
64
  this._atlaspack_napi = atlaspack_napi;
@@ -40,7 +79,11 @@ class AtlaspackV3 {
40
79
  fs,
41
80
  packageManager,
42
81
  threads,
43
- options,
82
+ options: {
83
+ ...options,
84
+ jsPaths: getJsPaths(),
85
+ useBuiltinConfigs: (0, _isSuperPackage.isSuperPackage)()
86
+ },
44
87
  napiWorkerPool
45
88
  }, lmdb);
46
89
  if (error !== null) {
@@ -33,7 +33,7 @@ function _rust() {
33
33
  return data;
34
34
  }
35
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
- const WORKER_PATH = _path().default.join(__dirname, 'worker', 'index.js');
36
+ const WORKER_PATH = _path().default.join( /*#__ATLASPACK_IGNORE__*/__dirname, 'worker', 'napi-worker.js');
37
37
  const ATLASPACK_NAPI_WORKERS = _process().default.env.ATLASPACK_NAPI_WORKERS && parseInt(_process().default.env.ATLASPACK_NAPI_WORKERS, 10);
38
38
  class NapiWorkerPool {
39
39
  #workers;
@@ -44,13 +44,13 @@ class Environment {
44
44
 
45
45
  // TODO
46
46
  // eslint-disable-next-line no-unused-vars
47
- matchesEngines(minVersions, defaultValue) {
47
+ matchesEngines() {
48
48
  return true;
49
49
  }
50
50
 
51
51
  // TODO
52
52
  // eslint-disable-next-line no-unused-vars
53
- supports(feature, defaultValue) {
53
+ supports() {
54
54
  return true;
55
55
  }
56
56
  }
@@ -126,32 +126,32 @@ class MutableAsset {
126
126
  }
127
127
 
128
128
  // eslint-disable-next-line no-unused-vars
129
- addDependency(options) {
129
+ addDependency() {
130
130
  throw new Error('MutableAsset.addDependency()');
131
131
  }
132
132
 
133
133
  // eslint-disable-next-line no-unused-vars
134
- addURLDependency(url, opts) {
134
+ addURLDependency() {
135
135
  throw new Error('MutableAsset.addURLDependency()');
136
136
  }
137
137
 
138
138
  // eslint-disable-next-line no-unused-vars
139
- setEnvironment(opts) {
139
+ setEnvironment() {
140
140
  throw new Error('MutableAsset.setEnvironment()');
141
141
  }
142
142
 
143
143
  // eslint-disable-next-line no-unused-vars
144
- invalidateOnFileChange(invalidation) {
144
+ invalidateOnFileChange() {
145
145
  // TODO: Forward invalidations to Rust
146
146
  }
147
147
 
148
148
  // eslint-disable-next-line no-unused-vars
149
- invalidateOnFileCreate(invalidation) {
149
+ invalidateOnFileCreate() {
150
150
  // TODO: Forward invalidations to Rust
151
151
  }
152
152
 
153
153
  // eslint-disable-next-line no-unused-vars
154
- invalidateOnEnvChange(invalidation) {
154
+ invalidateOnEnvChange() {
155
155
  // TODO: Forward invalidations to Rust
156
156
  }
157
157
  invalidateOnStartup() {
@@ -40,21 +40,21 @@ class PluginConfig {
40
40
  }
41
41
 
42
42
  // eslint-disable-next-line no-unused-vars
43
- invalidateOnFileChange(filePath) {}
43
+ invalidateOnFileChange() {}
44
44
 
45
45
  // eslint-disable-next-line no-unused-vars
46
- invalidateOnFileCreate(invalidations) {}
46
+ invalidateOnFileCreate() {}
47
47
 
48
48
  // eslint-disable-next-line no-unused-vars
49
- invalidateOnEnvChange(invalidation) {}
49
+ invalidateOnEnvChange() {}
50
50
  invalidateOnStartup() {}
51
51
  invalidateOnBuild() {}
52
52
 
53
53
  // eslint-disable-next-line no-unused-vars
54
- addDevDependency(options) {}
54
+ addDevDependency() {}
55
55
 
56
56
  // eslint-disable-next-line no-unused-vars
57
- setCacheKey(key) {}
57
+ setCacheKey() {}
58
58
  getConfig(
59
59
  // eslint-disable-next-line no-unused-vars
60
60
  filePaths,
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ require('./worker');
@@ -48,6 +48,7 @@ function _module() {
48
48
  }
49
49
  var _jsCallable = require("../jsCallable");
50
50
  var _compat = require("./compat");
51
+ var _internalPlugins = _interopRequireDefault(require("../../internal-plugins"));
51
52
  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); }
52
53
  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; }
53
54
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -66,10 +67,16 @@ class AtlaspackWorker {
66
67
  specifier,
67
68
  resolveFrom
68
69
  }) => {
69
- let customRequire = _module().createRequire(resolveFrom);
70
- let resolvedPath = customRequire.resolve(specifier);
71
- // $FlowFixMe
72
- let resolvedModule = await import(resolvedPath);
70
+ let resolvedModule;
71
+ if (_internalPlugins.default && _internalPlugins.default[specifier]) {
72
+ // If the plugin is available inside the package then use it
73
+ resolvedModule = _internalPlugins.default[specifier]();
74
+ } else {
75
+ let customRequire = _module().createRequire(resolveFrom);
76
+ let resolvedPath = customRequire.resolve(specifier);
77
+ // $FlowFixMe
78
+ resolvedModule = await import(resolvedPath);
79
+ }
73
80
  let instance = undefined;
74
81
  if (resolvedModule.default && resolvedModule.default[CONFIG]) {
75
82
  instance = resolvedModule.default[CONFIG];
@@ -47,7 +47,7 @@ const TYPE_COLORS = {
47
47
  };
48
48
  async function dumpGraphToGraphViz(graph, name, edgeTypes) {
49
49
  var _globalThis$ATLASPACK;
50
- if (process.env.ATLASPACK_BUILD_ENV === 'production' && !process.env.ATLASPACK_BUILD_REPL) {
50
+ if ("production" === 'production' && !process.env.ATLASPACK_BUILD_REPL) {
51
51
  return;
52
52
  }
53
53
  let mode = process.env.ATLASPACK_BUILD_REPL ? // $FlowFixMe
package/lib/index.js CHANGED
@@ -9,7 +9,8 @@ var _exportNames = {
9
9
  BuildError: true,
10
10
  createWorkerFarm: true,
11
11
  INTERNAL_RESOLVE: true,
12
- INTERNAL_TRANSFORM: true
12
+ INTERNAL_TRANSFORM: true,
13
+ isSuperPackage: true
13
14
  };
14
15
  Object.defineProperty(exports, "Atlaspack", {
15
16
  enumerable: true,
@@ -53,7 +54,14 @@ Object.defineProperty(exports, "default", {
53
54
  return _Atlaspack.default;
54
55
  }
55
56
  });
57
+ Object.defineProperty(exports, "isSuperPackage", {
58
+ enumerable: true,
59
+ get: function () {
60
+ return _isSuperPackage.isSuperPackage;
61
+ }
62
+ });
56
63
  var _Atlaspack = _interopRequireWildcard(require("./Atlaspack"));
64
+ var _isSuperPackage = require("./isSuperPackage");
57
65
  var _atlaspackV = require("./atlaspack-v3");
58
66
  Object.keys(_atlaspackV).forEach(function (key) {
59
67
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // This file is overridden in super package builds
8
+ // $FlowFixMe
9
+ var _default = exports.default = {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ let fs = require('fs');
4
+ let {
5
+ findAncestorFile
6
+ } = require('@atlaspack/rust');
7
+ let dirname = /*#__ATLASPACK_IGNORE__*/__dirname;
8
+ function isSuperPackage() {
9
+ if (!dirname) {
10
+ return false;
11
+ }
12
+ let packageJson = JSON.parse(
13
+ // $FlowFixMe
14
+ fs.readFileSync(findAncestorFile(['package.json'], dirname, '/'), 'utf8'));
15
+ return packageJson.name === 'atlaspack';
16
+ }
17
+ let result;
18
+ module.exports.isSuperPackage = () => {
19
+ if (result == null) {
20
+ result = isSuperPackage();
21
+ }
22
+ return result;
23
+ };
@@ -25,6 +25,8 @@ function _diagnostic() {
25
25
  };
26
26
  return data;
27
27
  }
28
+ var _package = require("../package.json");
29
+ var _internalPlugins = _interopRequireDefault(require("./internal-plugins"));
28
30
  function _utils() {
29
31
  const data = require("@atlaspack/utils");
30
32
  _utils = function () {
@@ -39,6 +41,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
39
41
  const NODE_MODULES = `${_path().default.sep}node_modules${_path().default.sep}`;
40
42
  const CONFIG = Symbol.for('parcel-plugin-config');
41
43
  async function loadPlugin(pluginName, configPath, keyPath, options) {
44
+ if (_internalPlugins.default && _internalPlugins.default[pluginName]) {
45
+ let plugin = _internalPlugins.default[pluginName]();
46
+ plugin = plugin.default || plugin;
47
+ plugin = plugin[CONFIG];
48
+ if (!plugin) {
49
+ throw new Error(`Plugin ${pluginName} is not a valid Atlaspack plugin, should export an instance of a Atlaspack plugin ex. "export default new Reporter({ ... })".`);
50
+ }
51
+ return {
52
+ plugin,
53
+ version: _package.version,
54
+ resolveFrom: (0, _projectPath.toProjectPathUnsafe)(options.projectRoot)
55
+ };
56
+ }
42
57
  let resolveFrom = configPath;
43
58
 
44
59
  // Config packages can reference plugins, but cannot contain other plugins within them.
@@ -23,6 +23,7 @@ var _Environment2 = require("../Environment");
23
23
  var _projectPath = require("../projectPath");
24
24
  var _types = require("../types");
25
25
  var _utils = require("../utils");
26
+ var _EnvironmentManager = require("../EnvironmentManager");
26
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
28
  const inspect = Symbol.for('nodejs.util.inspect.custom');
28
29
  const uncommittedAssetValueToAsset = new WeakMap();
@@ -62,7 +63,7 @@ class BaseAsset {
62
63
  return this.#asset.value.type;
63
64
  }
64
65
  get env() {
65
- return new _Environment.default(this.#asset.value.env, this.#asset.options);
66
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#asset.value.env), this.#asset.options);
66
67
  }
67
68
  get fs() {
68
69
  return this.#asset.options.inputFS;
@@ -142,7 +143,7 @@ class Asset extends BaseAsset {
142
143
  return this;
143
144
  }
144
145
  get env() {
145
- this.#env ??= new _Environment.default(this.#asset.value.env, this.#asset.options);
146
+ this.#env ??= new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#asset.value.env), this.#asset.options);
146
147
  return this.#env;
147
148
  }
148
149
  get stats() {
@@ -40,6 +40,7 @@ var _Dependency = require("./Dependency");
40
40
  var _Target = _interopRequireDefault(require("./Target"));
41
41
  var _types = require("../types");
42
42
  var _projectPath = require("../projectPath");
43
+ var _EnvironmentManager = require("../EnvironmentManager");
43
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44
45
  const inspect = Symbol.for('nodejs.util.inspect.custom');
45
46
  const internalBundleToBundle = new (_utils().DefaultWeakMap)(() => new (_utils().DefaultWeakMap)(() => new WeakMap()));
@@ -99,7 +100,7 @@ class Bundle {
99
100
  return this.#bundle.type;
100
101
  }
101
102
  get env() {
102
- return new _Environment.default(this.#bundle.env, this.#options);
103
+ return new _Environment.default((0, _EnvironmentManager.fromEnvironmentId)(this.#bundle.env), this.#options);
103
104
  }
104
105
  get needsStableName() {
105
106
  return this.#bundle.needsStableName;