@atlaspack/core 2.13.2-dev.3682 → 2.14.0

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 (87) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/package.json +20 -20
  3. package/src/Atlaspack.js +3 -2
  4. package/src/atlaspack-v3/AtlaspackV3.js +24 -8
  5. package/src/loadAtlaspackPlugin.js +26 -71
  6. package/src/projectPath.js +14 -1
  7. package/src/requests/WriteBundlesRequest.js +31 -22
  8. package/LICENSE +0 -201
  9. package/lib/AssetGraph.js +0 -521
  10. package/lib/Atlaspack.js +0 -676
  11. package/lib/AtlaspackConfig.js +0 -298
  12. package/lib/AtlaspackConfig.schema.js +0 -103
  13. package/lib/BundleGraph.js +0 -1527
  14. package/lib/CommittedAsset.js +0 -155
  15. package/lib/Dependency.js +0 -136
  16. package/lib/Environment.js +0 -144
  17. package/lib/IdentifierRegistry.js +0 -36
  18. package/lib/InternalConfig.js +0 -56
  19. package/lib/PackagerRunner.js +0 -525
  20. package/lib/ReporterRunner.js +0 -151
  21. package/lib/RequestTracker.js +0 -1178
  22. package/lib/SymbolPropagation.js +0 -618
  23. package/lib/TargetDescriptor.schema.js +0 -118
  24. package/lib/Transformation.js +0 -522
  25. package/lib/UncommittedAsset.js +0 -348
  26. package/lib/Validation.js +0 -203
  27. package/lib/applyRuntimes.js +0 -355
  28. package/lib/assetUtils.js +0 -205
  29. package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
  30. package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
  31. package/lib/atlaspack-v3/fs.js +0 -39
  32. package/lib/atlaspack-v3/index.js +0 -26
  33. package/lib/atlaspack-v3/jsCallable.js +0 -20
  34. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
  35. package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
  36. package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
  37. package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
  38. package/lib/atlaspack-v3/worker/compat/index.js +0 -104
  39. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
  40. package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
  41. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
  42. package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
  43. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
  44. package/lib/atlaspack-v3/worker/compat/target.js +0 -17
  45. package/lib/atlaspack-v3/worker/index.js +0 -3
  46. package/lib/atlaspack-v3/worker/worker.js +0 -280
  47. package/lib/constants.js +0 -21
  48. package/lib/dumpGraphToGraphViz.js +0 -206
  49. package/lib/index.js +0 -70
  50. package/lib/loadAtlaspackPlugin.js +0 -136
  51. package/lib/loadDotEnv.js +0 -54
  52. package/lib/projectPath.js +0 -94
  53. package/lib/public/Asset.js +0 -259
  54. package/lib/public/Bundle.js +0 -236
  55. package/lib/public/BundleGraph.js +0 -279
  56. package/lib/public/BundleGroup.js +0 -50
  57. package/lib/public/Config.js +0 -202
  58. package/lib/public/Dependency.js +0 -131
  59. package/lib/public/Environment.js +0 -247
  60. package/lib/public/MutableBundleGraph.js +0 -204
  61. package/lib/public/PluginOptions.js +0 -71
  62. package/lib/public/Symbols.js +0 -247
  63. package/lib/public/Target.js +0 -64
  64. package/lib/registerCoreWithSerializer.js +0 -51
  65. package/lib/requests/AssetGraphRequest.js +0 -432
  66. package/lib/requests/AssetGraphRequestRust.js +0 -220
  67. package/lib/requests/AssetRequest.js +0 -132
  68. package/lib/requests/AtlaspackBuildRequest.js +0 -79
  69. package/lib/requests/AtlaspackConfigRequest.js +0 -479
  70. package/lib/requests/BundleGraphRequest.js +0 -485
  71. package/lib/requests/ConfigRequest.js +0 -203
  72. package/lib/requests/DevDepRequest.js +0 -193
  73. package/lib/requests/EntryRequest.js +0 -295
  74. package/lib/requests/PackageRequest.js +0 -88
  75. package/lib/requests/PathRequest.js +0 -357
  76. package/lib/requests/TargetRequest.js +0 -1179
  77. package/lib/requests/ValidationRequest.js +0 -66
  78. package/lib/requests/WriteBundleRequest.js +0 -252
  79. package/lib/requests/WriteBundlesRequest.js +0 -153
  80. package/lib/requests/asset-graph-diff.js +0 -128
  81. package/lib/requests/asset-graph-dot.js +0 -131
  82. package/lib/resolveOptions.js +0 -265
  83. package/lib/serializerCore.browser.js +0 -29
  84. package/lib/summarizeRequest.js +0 -55
  85. package/lib/types.js +0 -35
  86. package/lib/utils.js +0 -160
  87. package/lib/worker.js +0 -184
@@ -1,279 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.bundleGraphToInternalBundleGraph = bundleGraphToInternalBundleGraph;
7
- exports.default = void 0;
8
- function _assert() {
9
- const data = _interopRequireDefault(require("assert"));
10
- _assert = function () {
11
- return data;
12
- };
13
- return data;
14
- }
15
- function _nullthrows() {
16
- const data = _interopRequireDefault(require("nullthrows"));
17
- _nullthrows = function () {
18
- return data;
19
- };
20
- return data;
21
- }
22
- function _graph() {
23
- const data = require("@atlaspack/graph");
24
- _graph = function () {
25
- return data;
26
- };
27
- return data;
28
- }
29
- var _Asset = require("./Asset");
30
- var _Bundle = require("./Bundle");
31
- var _Dependency = _interopRequireWildcard(require("./Dependency"));
32
- var _Target = require("./Target");
33
- var _utils = require("../utils");
34
- var _BundleGroup = _interopRequireWildcard(require("./BundleGroup"));
35
- 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); }
36
- 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; }
37
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
- // Friendly access for other modules within this package that need access
39
- // to the internal bundle.
40
- const _bundleGraphToInternalBundleGraph = new WeakMap();
41
- function bundleGraphToInternalBundleGraph(bundleGraph) {
42
- return (0, _nullthrows().default)(_bundleGraphToInternalBundleGraph.get(bundleGraph));
43
- }
44
- class BundleGraph {
45
- #graph;
46
- #options;
47
- #createBundle;
48
- constructor(graph, createBundle, options) {
49
- this.#graph = graph;
50
- this.#options = options;
51
- this.#createBundle = createBundle;
52
- // $FlowFixMe
53
- _bundleGraphToInternalBundleGraph.set(this, graph);
54
- }
55
- getAssetById(id) {
56
- return (0, _Asset.assetFromValue)(this.#graph.getAssetById(id), this.#options);
57
- }
58
- getAssetPublicId(asset) {
59
- return this.#graph.getAssetPublicId((0, _Asset.assetToAssetValue)(asset));
60
- }
61
- isDependencySkipped(dep) {
62
- return this.#graph.isDependencySkipped((0, _Dependency.dependencyToInternalDependency)(dep));
63
- }
64
- getResolvedAsset(dep, bundle) {
65
- let resolution = this.#graph.getResolvedAsset((0, _Dependency.dependencyToInternalDependency)(dep), bundle && (0, _Bundle.bundleToInternalBundle)(bundle));
66
- if (resolution) {
67
- return (0, _Asset.assetFromValue)(resolution, this.#options);
68
- }
69
- }
70
- getIncomingDependencies(asset) {
71
- return this.#graph.getIncomingDependencies((0, _Asset.assetToAssetValue)(asset)).map(dep => (0, _Dependency.getPublicDependency)(dep, this.#options));
72
- }
73
- getAssetWithDependency(dep) {
74
- let asset = this.#graph.getAssetWithDependency((0, _Dependency.dependencyToInternalDependency)(dep));
75
- if (asset) {
76
- return (0, _Asset.assetFromValue)(asset, this.#options);
77
- }
78
- }
79
- getBundleGroupsContainingBundle(bundle) {
80
- return this.#graph.getBundleGroupsContainingBundle((0, _Bundle.bundleToInternalBundle)(bundle)).map(bundleGroup => new _BundleGroup.default(bundleGroup, this.#options));
81
- }
82
- getReferencedBundles(bundle, opts) {
83
- return this.#graph.getReferencedBundles((0, _Bundle.bundleToInternalBundle)(bundle), opts).map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
84
- }
85
- getReferencingBundles(bundle) {
86
- return this.#graph.getReferencingBundles((0, _Bundle.bundleToInternalBundle)(bundle)).map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
87
- }
88
- resolveAsyncDependency(dependency, bundle) {
89
- let resolved = this.#graph.resolveAsyncDependency((0, _Dependency.dependencyToInternalDependency)(dependency), bundle && (0, _Bundle.bundleToInternalBundle)(bundle));
90
- if (resolved == null) {
91
- return;
92
- } else if (resolved.type === 'bundle_group') {
93
- return {
94
- type: 'bundle_group',
95
- value: new _BundleGroup.default(resolved.value, this.#options)
96
- };
97
- }
98
- return {
99
- type: 'asset',
100
- value: (0, _Asset.assetFromValue)(resolved.value, this.#options)
101
- };
102
- }
103
- getReferencedBundle(dependency, bundle) {
104
- let result = this.#graph.getReferencedBundle((0, _Dependency.dependencyToInternalDependency)(dependency), (0, _Bundle.bundleToInternalBundle)(bundle));
105
- if (result != null) {
106
- return this.#createBundle(result, this.#graph, this.#options);
107
- }
108
- }
109
- getDependencies(asset) {
110
- return this.#graph.getDependencies((0, _Asset.assetToAssetValue)(asset)).map(dep => (0, _Dependency.getPublicDependency)(dep, this.#options));
111
- }
112
- isAssetReachableFromBundle(asset, bundle) {
113
- return this.#graph.isAssetReachableFromBundle((0, _Asset.assetToAssetValue)(asset), (0, _Bundle.bundleToInternalBundle)(bundle));
114
- }
115
- isAssetReferenced(bundle, asset) {
116
- return this.#graph.isAssetReferenced((0, _Bundle.bundleToInternalBundle)(bundle), (0, _Asset.assetToAssetValue)(asset));
117
- }
118
- hasParentBundleOfType(bundle, type) {
119
- return this.#graph.hasParentBundleOfType((0, _Bundle.bundleToInternalBundle)(bundle), type);
120
- }
121
- getBundlesInBundleGroup(bundleGroup, opts) {
122
- return this.#graph.getBundlesInBundleGroup((0, _BundleGroup.bundleGroupToInternalBundleGroup)(bundleGroup), opts).map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
123
- }
124
- getBundles(opts) {
125
- return this.#graph.getBundles(opts).map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
126
- }
127
- isEntryBundleGroup(bundleGroup) {
128
- return this.#graph.isEntryBundleGroup((0, _BundleGroup.bundleGroupToInternalBundleGroup)(bundleGroup));
129
- }
130
- getChildBundles(bundle) {
131
- return this.#graph.getChildBundles((0, _Bundle.bundleToInternalBundle)(bundle)).map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
132
- }
133
- getParentBundles(bundle) {
134
- return this.#graph.getParentBundles((0, _Bundle.bundleToInternalBundle)(bundle)).map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
135
- }
136
- getSymbolResolution(asset, symbol, boundary) {
137
- let res = this.#graph.getSymbolResolution((0, _Asset.assetToAssetValue)(asset), symbol, boundary ? (0, _Bundle.bundleToInternalBundle)(boundary) : null);
138
- return {
139
- asset: (0, _Asset.assetFromValue)(res.asset, this.#options),
140
- exportSymbol: res.exportSymbol,
141
- symbol: res.symbol,
142
- loc: (0, _utils.fromInternalSourceLocation)(this.#options.projectRoot, res.loc)
143
- };
144
- }
145
- getExportedSymbols(asset, boundary) {
146
- let res = this.#graph.getExportedSymbols((0, _Asset.assetToAssetValue)(asset), boundary ? (0, _Bundle.bundleToInternalBundle)(boundary) : null);
147
- return res.map(e => ({
148
- asset: (0, _Asset.assetFromValue)(e.asset, this.#options),
149
- exportSymbol: e.exportSymbol,
150
- symbol: e.symbol,
151
- loc: (0, _utils.fromInternalSourceLocation)(this.#options.projectRoot, e.loc),
152
- exportAs: e.exportAs
153
- }));
154
- }
155
- traverse(visit, start, opts) {
156
- return this.#graph.traverse((0, _graph().mapVisitor)((node, actions) => {
157
- // Skipping unused dependencies here is faster than doing an isDependencySkipped check inside the visitor
158
- // because the node needs to be re-looked up by id from the hashmap.
159
- if (opts !== null && opts !== void 0 && opts.skipUnusedDependencies && node.type === 'dependency' && (node.hasDeferred || node.excluded)) {
160
- actions.skipChildren();
161
- return null;
162
- }
163
- return node.type === 'asset' ? {
164
- type: 'asset',
165
- value: (0, _Asset.assetFromValue)(node.value, this.#options)
166
- } : {
167
- type: 'dependency',
168
- value: (0, _Dependency.getPublicDependency)(node.value, this.#options)
169
- };
170
- }, visit), start ? (0, _Asset.assetToAssetValue)(start) : undefined);
171
- }
172
- traverseBundles(visit, startBundle) {
173
- return this.#graph.traverseBundles((0, _graph().mapVisitor)(bundle => this.#createBundle(bundle, this.#graph, this.#options), visit), startBundle == null ? undefined : (0, _Bundle.bundleToInternalBundle)(startBundle));
174
- }
175
- getBundlesWithAsset(asset) {
176
- return this.#graph.getBundlesWithAsset((0, _Asset.assetToAssetValue)(asset)).map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
177
- }
178
- getBundlesWithDependency(dependency) {
179
- return this.#graph.getBundlesWithDependency((0, _Dependency.dependencyToInternalDependency)(dependency)).map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
180
- }
181
- getUsedSymbols(v) {
182
- if (v instanceof _Asset.Asset) {
183
- return this.#graph.getUsedSymbolsAsset((0, _Asset.assetToAssetValue)(v));
184
- } else {
185
- (0, _assert().default)(v instanceof _Dependency.default);
186
- return this.#graph.getUsedSymbolsDependency((0, _Dependency.dependencyToInternalDependency)(v));
187
- }
188
- }
189
- getEntryRoot(target) {
190
- return this.#graph.getEntryRoot(this.#options.projectRoot, (0, _Target.targetToInternalTarget)(target));
191
- }
192
-
193
- // Given a set of dependencies, return any conditions where those dependencies are either
194
- // the true or false dependency for those conditions. This is currently used to work out which
195
- // conditions belong to a bundle in packaging.
196
- getConditionsForDependencies(deps, bundle) {
197
- const conditions = new Set();
198
- const depIds = deps.map(dep => dep.id);
199
- for (const condition of this.#graph._conditions.values()) {
200
- if (depIds.includes(condition.ifTrueDependency.id) || depIds.includes(condition.ifFalseDependency.id)) {
201
- const [[trueAsset, ifTrueBundles], [falseAsset, ifFalseBundles]] = [condition.ifTrueDependency, condition.ifFalseDependency].map(dep => {
202
- const asset = this.#graph.getResolvedAsset(dep, (0, _Bundle.bundleToInternalBundle)(bundle));
203
- if (asset && this.#graph.bundleHasAsset((0, _Bundle.bundleToInternalBundle)(bundle), asset)) {
204
- // Asset is in the same bundle, we know it doesn't need to be loaded externally
205
- return [asset, []];
206
- }
207
- const resolvedAsync = this.#graph.resolveAsyncDependency(dep, (0, _Bundle.bundleToInternalBundle)(bundle));
208
- if ((resolvedAsync === null || resolvedAsync === void 0 ? void 0 : resolvedAsync.type) === 'asset') {
209
- // Single bundle to load dynamically
210
- return [resolvedAsync.value, [this.#createBundle((0, _nullthrows().default)(this.#graph.getReferencedBundle(dep, (0, _Bundle.bundleToInternalBundle)(bundle)), `Failed to load referenced bundle for '${dep.specifier}' specifier from '${String(dep.sourcePath)}'`), this.#graph, this.#options)]];
211
- } else if (resolvedAsync) {
212
- // Bundle group means we have multiple bundles to load first
213
- return [this.#graph.getAssetById(resolvedAsync.value.entryAssetId), this.#graph.getBundlesInBundleGroup(resolvedAsync.value).map(b => this.#createBundle(b, this.#graph, this.#options))];
214
- } else {
215
- return [(0, _nullthrows().default)(asset, `Failed to load depenendency for '${dep.specifier}' specifier from '${String(dep.sourcePath)}'`), []];
216
- }
217
- });
218
- conditions.add({
219
- publicId: condition.publicId,
220
- key: condition.key,
221
- ifTrueDependency: (0, _nullthrows().default)(deps.find(dep => dep.id === condition.ifTrueDependency.id), 'ifTrueDependency was null'),
222
- ifFalseDependency: (0, _nullthrows().default)(deps.find(dep => dep.id === condition.ifFalseDependency.id), 'ifFalseDependency was null'),
223
- ifTrueBundles,
224
- ifFalseBundles,
225
- ifTrueAssetId: this.#graph.getAssetPublicId(trueAsset),
226
- ifFalseAssetId: this.#graph.getAssetPublicId(falseAsset)
227
- });
228
- }
229
- }
230
- return conditions;
231
- }
232
-
233
- // This is used to generate information for building a manifest that can
234
- // be used by a webserver to understand which conditions are used by which bundles,
235
- // and which bundles those conditions require depending on what they evaluate to.
236
- getConditionalBundleMapping() {
237
- let bundleConditions = new Map();
238
-
239
- // Convert the internal references in conditions to public API references
240
- for (const cond of this.#graph._conditions.values()) {
241
- let assets = Array.from(cond.assets).map(asset => (0, _nullthrows().default)(this.getAssetById(asset.id)));
242
- let bundles = new Set();
243
- let ifTrueBundles = [];
244
- let ifFalseBundles = [];
245
- for (const asset of assets) {
246
- const bundlesWithAsset = this.getBundlesWithAsset(asset);
247
- for (const bundle of bundlesWithAsset) {
248
- bundles.add(bundle);
249
- }
250
- const assetDeps = this.getDependencies(asset);
251
- const depToBundles = dep => {
252
- const publicDep = (0, _nullthrows().default)(assetDeps.find(assetDep => dep.id === assetDep.id));
253
- const resolved = this.resolveAsyncDependency(publicDep);
254
- if (!resolved) {
255
- // If there's no async dependency, don't list it as required
256
- return [];
257
- }
258
- (0, _assert().default)(resolved.type === 'bundle_group');
259
- return this.getBundlesInBundleGroup(resolved.value);
260
- };
261
- ifTrueBundles.push(...depToBundles(cond.ifTrueDependency));
262
- ifFalseBundles.push(...depToBundles(cond.ifFalseDependency));
263
- }
264
- for (let bundle of bundles) {
265
- const conditions = bundleConditions.get(bundle) ?? new Map();
266
- conditions.set(cond.key, {
267
- ifTrueBundles,
268
- ifFalseBundles
269
- });
270
- bundleConditions.set(bundle, conditions);
271
- }
272
- }
273
- return bundleConditions;
274
- }
275
- getReferencedConditionalBundles(bundle) {
276
- return this.#graph.getReferencedConditionalBundles((0, _Bundle.bundleToInternalBundle)(bundle)).map(result => this.#createBundle(result, this.#graph, this.#options));
277
- }
278
- }
279
- exports.default = BundleGraph;
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.bundleGroupToInternalBundleGroup = bundleGroupToInternalBundleGroup;
7
- exports.default = void 0;
8
- function _nullthrows() {
9
- const data = _interopRequireDefault(require("nullthrows"));
10
- _nullthrows = function () {
11
- return data;
12
- };
13
- return data;
14
- }
15
- var _Target = _interopRequireDefault(require("./Target"));
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
- const internalBundleGroupToBundleGroup = new WeakMap();
18
- const _bundleGroupToInternalBundleGroup = new WeakMap();
19
- function bundleGroupToInternalBundleGroup(target) {
20
- return (0, _nullthrows().default)(_bundleGroupToInternalBundleGroup.get(target));
21
- }
22
- const inspect = Symbol.for('nodejs.util.inspect.custom');
23
- class BundleGroup {
24
- #bundleGroup /*: InternalBundleGroup */;
25
- #options /*: AtlaspackOptions */;
26
-
27
- constructor(bundleGroup, options) {
28
- let existing = internalBundleGroupToBundleGroup.get(bundleGroup);
29
- if (existing != null) {
30
- return existing;
31
- }
32
- this.#bundleGroup = bundleGroup;
33
- this.#options = options;
34
- _bundleGroupToInternalBundleGroup.set(this, bundleGroup);
35
- internalBundleGroupToBundleGroup.set(bundleGroup, this);
36
- return this;
37
- }
38
- get target() {
39
- return new _Target.default(this.#bundleGroup.target, this.#options);
40
- }
41
- get entryAssetId() {
42
- return this.#bundleGroup.entryAssetId;
43
- }
44
-
45
- // $FlowFixMe
46
- [inspect]() {
47
- return `BundleGroup(${this.entryAssetId})`;
48
- }
49
- }
50
- exports.default = BundleGroup;
@@ -1,202 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- function _assert() {
8
- const data = _interopRequireDefault(require("assert"));
9
- _assert = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _path() {
15
- const data = _interopRequireDefault(require("path"));
16
- _path = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _utils() {
22
- const data = require("@atlaspack/utils");
23
- _utils = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
- var _Environment = _interopRequireDefault(require("./Environment"));
29
- var _projectPath = require("../projectPath");
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
- const internalConfigToConfig = new (_utils().DefaultWeakMap)(() => new WeakMap());
32
- class PublicConfig {
33
- #config /*: Config */;
34
- #pkg /*: ?PackageJSON */;
35
- #pkgFilePath /*: ?FilePath */;
36
- #options /*: AtlaspackOptions */;
37
-
38
- constructor(config, options) {
39
- let existing = internalConfigToConfig.get(options).get(config);
40
- if (existing != null) {
41
- return existing;
42
- }
43
- this.#config = config;
44
- this.#options = options;
45
- internalConfigToConfig.get(options).set(config, this);
46
- return this;
47
- }
48
- get env() {
49
- return new _Environment.default(this.#config.env, this.#options);
50
- }
51
- get searchPath() {
52
- return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#config.searchPath);
53
- }
54
- get result() {
55
- return this.#config.result;
56
- }
57
- get isSource() {
58
- return this.#config.isSource;
59
- }
60
-
61
- // $FlowFixMe
62
- setResult(result) {
63
- this.#config.result = result;
64
- }
65
- setCacheKey(cacheKey) {
66
- this.#config.cacheKey = cacheKey;
67
- }
68
- invalidateOnFileChange(filePath) {
69
- this.#config.invalidateOnFileChange.add((0, _projectPath.toProjectPath)(this.#options.projectRoot, filePath));
70
- }
71
- invalidateOnConfigKeyChange(filePath, configKey) {
72
- this.#config.invalidateOnConfigKeyChange.push({
73
- filePath: (0, _projectPath.toProjectPath)(this.#options.projectRoot, filePath),
74
- configKey
75
- });
76
- }
77
- addDevDependency(devDep) {
78
- var _devDep$additionalInv;
79
- this.#config.devDeps.push({
80
- ...devDep,
81
- resolveFrom: (0, _projectPath.toProjectPath)(this.#options.projectRoot, devDep.resolveFrom),
82
- additionalInvalidations: (_devDep$additionalInv = devDep.additionalInvalidations) === null || _devDep$additionalInv === void 0 ? void 0 : _devDep$additionalInv.map(i => ({
83
- ...i,
84
- resolveFrom: (0, _projectPath.toProjectPath)(this.#options.projectRoot, i.resolveFrom)
85
- }))
86
- });
87
- }
88
- invalidateOnFileCreate(invalidation) {
89
- if (invalidation.glob != null) {
90
- // $FlowFixMe
91
- this.#config.invalidateOnFileCreate.push(invalidation);
92
- } else if (invalidation.filePath != null) {
93
- this.#config.invalidateOnFileCreate.push({
94
- filePath: (0, _projectPath.toProjectPath)(this.#options.projectRoot, invalidation.filePath)
95
- });
96
- } else {
97
- (0, _assert().default)(invalidation.aboveFilePath != null);
98
- this.#config.invalidateOnFileCreate.push({
99
- // $FlowFixMe
100
- fileName: invalidation.fileName,
101
- aboveFilePath: (0, _projectPath.toProjectPath)(this.#options.projectRoot, invalidation.aboveFilePath)
102
- });
103
- }
104
- }
105
- invalidateOnEnvChange(env) {
106
- this.#config.invalidateOnEnvChange.add(env);
107
- }
108
- invalidateOnStartup() {
109
- this.#config.invalidateOnStartup = true;
110
- }
111
- invalidateOnBuild() {
112
- this.#config.invalidateOnBuild = true;
113
- }
114
- async getConfigFrom(searchPath, fileNames, options) {
115
- let packageKey = options === null || options === void 0 ? void 0 : options.packageKey;
116
- if (packageKey != null) {
117
- let pkg = await this.getConfigFrom(searchPath, ['package.json'], {
118
- exclude: true
119
- });
120
- if (pkg && pkg.contents[packageKey]) {
121
- // Invalidate only when the package key changes
122
- this.invalidateOnConfigKeyChange(pkg.filePath, packageKey);
123
- return {
124
- contents: pkg.contents[packageKey],
125
- filePath: pkg.filePath
126
- };
127
- }
128
- }
129
- if (fileNames.length === 0) {
130
- return null;
131
- }
132
-
133
- // Invalidate when any of the file names are created above the search path.
134
- for (let fileName of fileNames) {
135
- this.invalidateOnFileCreate({
136
- fileName,
137
- aboveFilePath: searchPath
138
- });
139
- }
140
- let parse = options && options.parse;
141
- let configFilePath = await (0, _utils().resolveConfig)(this.#options.inputFS, searchPath, fileNames, this.#options.projectRoot);
142
- if (configFilePath == null) {
143
- return null;
144
- }
145
- if (!options || !options.exclude) {
146
- this.invalidateOnFileChange(configFilePath);
147
- }
148
-
149
- // If this is a JavaScript file, load it with the package manager.
150
- let extname = _path().default.extname(configFilePath);
151
- if (extname === '.js' || extname === '.cjs' || extname === '.mjs') {
152
- let specifier = (0, _utils().relativePath)(_path().default.dirname(searchPath), configFilePath);
153
-
154
- // Add dev dependency so we reload the config and any dependencies in watch mode.
155
- this.addDevDependency({
156
- specifier,
157
- resolveFrom: searchPath
158
- });
159
-
160
- // Invalidate on startup in case the config is non-deterministic,
161
- // e.g. uses unknown environment variables, reads from the filesystem, etc.
162
- this.invalidateOnStartup();
163
- let config = await this.#options.packageManager.require(specifier, searchPath);
164
- if (
165
- // $FlowFixMe
166
- Object.prototype.toString.call(config) === '[object Module]' && config.default != null) {
167
- // Native ESM config. Try to use a default export, otherwise fall back to the whole namespace.
168
- config = config.default;
169
- }
170
- return {
171
- contents: config,
172
- filePath: configFilePath
173
- };
174
- }
175
- let conf = await (0, _utils().readConfig)(this.#options.inputFS, configFilePath, parse == null ? null : {
176
- parse
177
- });
178
- if (conf == null) {
179
- return null;
180
- }
181
- return {
182
- contents: conf.config,
183
- filePath: configFilePath
184
- };
185
- }
186
- getConfig(filePaths, options) {
187
- return this.getConfigFrom(this.searchPath, filePaths, options);
188
- }
189
- async getPackage() {
190
- if (this.#pkg) {
191
- return this.#pkg;
192
- }
193
- let pkgConfig = await this.getConfig(['package.json']);
194
- if (!pkgConfig) {
195
- return null;
196
- }
197
- this.#pkg = pkgConfig.contents;
198
- this.#pkgFilePath = pkgConfig.filePath;
199
- return this.#pkg;
200
- }
201
- }
202
- exports.default = PublicConfig;
@@ -1,131 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.dependencyToInternalDependency = dependencyToInternalDependency;
8
- exports.getPublicDependency = getPublicDependency;
9
- var _types = require("../types");
10
- function _nullthrows() {
11
- const data = _interopRequireDefault(require("nullthrows"));
12
- _nullthrows = function () {
13
- return data;
14
- };
15
- return data;
16
- }
17
- var _Environment = _interopRequireDefault(require("./Environment"));
18
- var _Target = _interopRequireDefault(require("./Target"));
19
- var _Symbols = require("./Symbols");
20
- var _projectPath = require("../projectPath");
21
- var _utils = require("../utils");
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
- const SpecifierTypeNames = Object.keys(_types.SpecifierType);
24
- const PriorityNames = Object.keys(_types.Priority);
25
- const inspect = Symbol.for('nodejs.util.inspect.custom');
26
- const internalDependencyToDependency = new WeakMap();
27
- const _dependencyToInternalDependency = new WeakMap();
28
- function dependencyToInternalDependency(dependency) {
29
- return (0, _nullthrows().default)(_dependencyToInternalDependency.get(dependency));
30
- }
31
- function getPublicDependency(dep, options) {
32
- let existing = internalDependencyToDependency.get(dep);
33
- if (existing != null) {
34
- return existing;
35
- }
36
- return new Dependency(dep, options);
37
- }
38
- class Dependency {
39
- #dep /*: InternalDependency */;
40
- #options /*: AtlaspackOptions */;
41
-
42
- constructor(dep, options) {
43
- this.#dep = dep;
44
- this.#options = options;
45
- _dependencyToInternalDependency.set(this, dep);
46
- internalDependencyToDependency.set(dep, this);
47
- return this;
48
- }
49
-
50
- // $FlowFixMe
51
- [inspect]() {
52
- return `Dependency(${String(this.sourcePath)} -> ${this.specifier})`;
53
- }
54
- get id() {
55
- return this.#dep.id;
56
- }
57
- get specifier() {
58
- return this.#dep.specifier;
59
- }
60
- get specifierType() {
61
- return SpecifierTypeNames[this.#dep.specifierType];
62
- }
63
- get priority() {
64
- return PriorityNames[this.#dep.priority];
65
- }
66
- get needsStableName() {
67
- return this.#dep.needsStableName;
68
- }
69
- get bundleBehavior() {
70
- let bundleBehavior = this.#dep.bundleBehavior;
71
- return bundleBehavior == null ? null : _types.BundleBehaviorNames[bundleBehavior];
72
- }
73
- get isEntry() {
74
- return this.#dep.isEntry;
75
- }
76
- get isOptional() {
77
- return this.#dep.isOptional;
78
- }
79
- get loc() {
80
- return (0, _utils.fromInternalSourceLocation)(this.#options.projectRoot, this.#dep.loc);
81
- }
82
- get env() {
83
- return new _Environment.default(this.#dep.env, this.#options);
84
- }
85
- get packageConditions() {
86
- // Merge custom conditions with conditions stored as bitflags.
87
- // Order is not important because exports conditions are resolved
88
- // in the order they are declared in the package.json.
89
- let conditions = this.#dep.customPackageConditions;
90
- if (this.#dep.packageConditions) {
91
- conditions = conditions ? [...conditions] : [];
92
- for (let key in _types.ExportsCondition) {
93
- if (this.#dep.packageConditions & _types.ExportsCondition[key]) {
94
- conditions.push(key);
95
- }
96
- }
97
- }
98
- return conditions;
99
- }
100
- get meta() {
101
- return this.#dep.meta;
102
- }
103
- get symbols() {
104
- return new _Symbols.MutableDependencySymbols(this.#options, this.#dep);
105
- }
106
- get target() {
107
- let target = this.#dep.target;
108
- return target ? new _Target.default(target, this.#options) : null;
109
- }
110
- get sourceAssetId() {
111
- // TODO: does this need to be public?
112
- return this.#dep.sourceAssetId;
113
- }
114
- get sourcePath() {
115
- // TODO: does this need to be public?
116
- return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#dep.sourcePath);
117
- }
118
- get sourceAssetType() {
119
- return this.#dep.sourceAssetType;
120
- }
121
- get resolveFrom() {
122
- return (0, _projectPath.fromProjectPath)(this.#options.projectRoot, this.#dep.resolveFrom ?? this.#dep.sourcePath);
123
- }
124
- get range() {
125
- return this.#dep.range;
126
- }
127
- get pipeline() {
128
- return this.#dep.pipeline;
129
- }
130
- }
131
- exports.default = Dependency;