@atlaspack/core 2.24.1 → 2.24.2

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 (90) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/AssetGraph.js +591 -0
  3. package/dist/Atlaspack.js +656 -0
  4. package/dist/AtlaspackConfig.js +324 -0
  5. package/dist/AtlaspackConfig.schema.js +108 -0
  6. package/dist/BundleGraph.js +1628 -0
  7. package/dist/CommittedAsset.js +142 -0
  8. package/dist/Dependency.js +125 -0
  9. package/dist/Environment.js +132 -0
  10. package/dist/EnvironmentManager.js +108 -0
  11. package/dist/IdentifierRegistry.js +38 -0
  12. package/dist/InternalConfig.js +37 -0
  13. package/dist/PackagerRunner.js +531 -0
  14. package/dist/ReporterRunner.js +151 -0
  15. package/dist/RequestTracker.js +1368 -0
  16. package/dist/SymbolPropagation.js +617 -0
  17. package/dist/TargetDescriptor.schema.js +143 -0
  18. package/dist/Transformation.js +487 -0
  19. package/dist/UncommittedAsset.js +315 -0
  20. package/dist/Validation.js +196 -0
  21. package/dist/applyRuntimes.js +305 -0
  22. package/dist/assetUtils.js +168 -0
  23. package/dist/atlaspack-v3/AtlaspackV3.js +70 -0
  24. package/dist/atlaspack-v3/NapiWorkerPool.js +57 -0
  25. package/dist/atlaspack-v3/fs.js +52 -0
  26. package/dist/atlaspack-v3/index.js +25 -0
  27. package/dist/atlaspack-v3/jsCallable.js +16 -0
  28. package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
  29. package/dist/atlaspack-v3/worker/compat/bitflags.js +94 -0
  30. package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
  31. package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
  32. package/dist/atlaspack-v3/worker/compat/index.js +25 -0
  33. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
  34. package/dist/atlaspack-v3/worker/compat/plugin-config.js +76 -0
  35. package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-options.js +122 -0
  37. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  38. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  39. package/dist/atlaspack-v3/worker/worker.js +292 -0
  40. package/dist/constants.js +17 -0
  41. package/dist/dumpGraphToGraphViz.js +281 -0
  42. package/dist/index.js +62 -0
  43. package/dist/loadAtlaspackPlugin.js +128 -0
  44. package/dist/loadDotEnv.js +41 -0
  45. package/dist/projectPath.js +83 -0
  46. package/dist/public/Asset.js +279 -0
  47. package/dist/public/Bundle.js +224 -0
  48. package/dist/public/BundleGraph.js +359 -0
  49. package/dist/public/BundleGroup.js +53 -0
  50. package/dist/public/Config.js +286 -0
  51. package/dist/public/Dependency.js +138 -0
  52. package/dist/public/Environment.js +278 -0
  53. package/dist/public/MutableBundleGraph.js +277 -0
  54. package/dist/public/PluginOptions.js +80 -0
  55. package/dist/public/Symbols.js +248 -0
  56. package/dist/public/Target.js +69 -0
  57. package/dist/registerCoreWithSerializer.js +38 -0
  58. package/dist/requests/AssetGraphRequest.js +429 -0
  59. package/dist/requests/AssetGraphRequestRust.js +246 -0
  60. package/dist/requests/AssetRequest.js +130 -0
  61. package/dist/requests/AtlaspackBuildRequest.js +60 -0
  62. package/dist/requests/AtlaspackConfigRequest.js +490 -0
  63. package/dist/requests/BundleGraphRequest.js +441 -0
  64. package/dist/requests/ConfigRequest.js +222 -0
  65. package/dist/requests/DevDepRequest.js +204 -0
  66. package/dist/requests/EntryRequest.js +314 -0
  67. package/dist/requests/PackageRequest.js +65 -0
  68. package/dist/requests/PathRequest.js +349 -0
  69. package/dist/requests/TargetRequest.js +1310 -0
  70. package/dist/requests/ValidationRequest.js +49 -0
  71. package/dist/requests/WriteBundleRequest.js +254 -0
  72. package/dist/requests/WriteBundlesRequest.js +165 -0
  73. package/dist/requests/asset-graph-diff.js +126 -0
  74. package/dist/requests/asset-graph-dot.js +131 -0
  75. package/dist/resolveOptions.js +268 -0
  76. package/dist/rustWorkerThreadDylibHack.js +19 -0
  77. package/dist/serializerCore.browser.js +43 -0
  78. package/dist/summarizeRequest.js +39 -0
  79. package/dist/types.js +31 -0
  80. package/dist/utils.js +172 -0
  81. package/dist/worker.js +123 -0
  82. package/lib/AssetGraph.js +1 -0
  83. package/lib/SymbolPropagation.js +3 -12
  84. package/lib/worker.js +0 -7
  85. package/package.json +13 -14
  86. package/src/AssetGraph.ts +1 -0
  87. package/src/SymbolPropagation.ts +5 -9
  88. package/src/worker.ts +0 -8
  89. package/tsconfig.json +55 -2
  90. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = dumpGraphToGraphViz;
7
+ const path_1 = __importDefault(require("path"));
8
+ const graph_1 = require("@atlaspack/graph");
9
+ const projectPath_1 = require("./projectPath");
10
+ const types_1 = require("./types");
11
+ const COLORS = {
12
+ root: 'gray',
13
+ asset: 'green',
14
+ dependency: 'orange',
15
+ transformer_request: 'cyan',
16
+ file: 'gray',
17
+ default: 'white',
18
+ };
19
+ const TYPE_COLORS = {
20
+ // bundle graph
21
+ bundle: 'blue',
22
+ contains: 'grey',
23
+ internal_async: 'orange',
24
+ references: 'red',
25
+ sibling: 'green',
26
+ // asset graph
27
+ // request graph
28
+ invalidated_by_create: 'green',
29
+ invalidated_by_create_above: 'orange',
30
+ invalidate_by_update: 'cyan',
31
+ invalidated_by_delete: 'red',
32
+ };
33
+ async function dumpGraphToGraphViz(graph, name, edgeTypes) {
34
+ if (process.env.ATLASPACK_BUILD_ENV === 'production' &&
35
+ !process.env.ATLASPACK_BUILD_REPL) {
36
+ return;
37
+ }
38
+ let mode = process.env.ATLASPACK_BUILD_REPL
39
+ ? // @ts-expect-error TS7017
40
+ globalThis.ATLASPACK_DUMP_GRAPHVIZ?.mode
41
+ : process.env.ATLASPACK_DUMP_GRAPHVIZ;
42
+ // @ts-expect-error TS2367
43
+ if (mode == null || mode == false) {
44
+ return;
45
+ }
46
+ let detailedSymbols = mode === 'symbols';
47
+ let GraphVizGraph = require('graphviz/lib/deps/graph').Graph;
48
+ let g = new GraphVizGraph(null, 'G');
49
+ g.type = 'digraph';
50
+ for (let [id, node] of graph.nodes.entries()) {
51
+ if (node == null)
52
+ continue;
53
+ let n = g.addNode(nodeId(id));
54
+ // @ts-expect-error TS7053
55
+ n.set('color', COLORS[node.type || 'default']);
56
+ n.set('shape', 'box');
57
+ n.set('style', 'filled');
58
+ let label;
59
+ if (typeof node === 'string') {
60
+ label = node;
61
+ // @ts-expect-error TS2339
62
+ }
63
+ else if (node.assets) {
64
+ // @ts-expect-error TS2339
65
+ label = `(${nodeId(id)}), (assetIds: ${[...node.assets]
66
+ .map((a) => {
67
+ let arr = a.filePath.split('/');
68
+ return arr[arr.length - 1];
69
+ })
70
+ // @ts-expect-error TS2339
71
+ .join(', ')}) (sourceBundles: ${[...node.sourceBundles].join(', ')}) (bb ${node.bundleBehavior ?? 'none'})`;
72
+ // @ts-expect-error TS2339
73
+ }
74
+ else if (node.type) {
75
+ // @ts-expect-error TS2339
76
+ label = `[${(0, graph_1.fromNodeId)(id)}] ${node.type || 'No Type'}: [${node.id}]: `;
77
+ // @ts-expect-error TS2339
78
+ if (node.type === 'dependency') {
79
+ // @ts-expect-error TS2339
80
+ label += node.value.specifier;
81
+ let parts = [];
82
+ // @ts-expect-error TS2339
83
+ if (node.value.priority !== types_1.Priority.sync) {
84
+ parts.push(Object.entries(types_1.Priority).find(
85
+ // @ts-expect-error TS2339
86
+ ([, v]) => v === node.value.priority)?.[0]);
87
+ }
88
+ // @ts-expect-error TS2339
89
+ if (node.value.isOptional)
90
+ parts.push('optional');
91
+ // @ts-expect-error TS2339
92
+ if (node.value.specifierType === types_1.SpecifierType.url)
93
+ parts.push('url');
94
+ // @ts-expect-error TS2339
95
+ if (node.hasDeferred)
96
+ parts.push('deferred');
97
+ // @ts-expect-error TS2339
98
+ if (node.deferred)
99
+ parts.push('deferred');
100
+ // @ts-expect-error TS2339
101
+ if (node.excluded)
102
+ parts.push('excluded');
103
+ if (parts.length)
104
+ label += ' (' + parts.join(', ') + ')';
105
+ // @ts-expect-error TS2339
106
+ if (node.value.env)
107
+ label += ` (${getEnvDescription(node.value.env)})`;
108
+ // @ts-expect-error TS2339
109
+ let depSymbols = node.value.symbols;
110
+ if (detailedSymbols) {
111
+ if (depSymbols) {
112
+ if (depSymbols.size) {
113
+ label +=
114
+ '\\nsymbols: ' +
115
+ [...depSymbols]
116
+ .map(([e, { local }]) => [e, local])
117
+ .join(';');
118
+ }
119
+ let weakSymbols = [...depSymbols]
120
+ .filter(([, { isWeak }]) => isWeak)
121
+ .map(([s]) => s);
122
+ if (weakSymbols.length) {
123
+ label += '\\nweakSymbols: ' + weakSymbols.join(',');
124
+ }
125
+ // @ts-expect-error TS2339
126
+ if (node.usedSymbolsUp.size > 0) {
127
+ label +=
128
+ '\\nusedSymbolsUp: ' +
129
+ // @ts-expect-error TS2339
130
+ [...node.usedSymbolsUp]
131
+ .map(([s, sAsset]) => sAsset
132
+ ? `${s}(${sAsset.asset}.${sAsset.symbol ?? ''})`
133
+ : sAsset === null
134
+ ? `${s}(external)`
135
+ : `${s}(ambiguous)`)
136
+ .join(',');
137
+ }
138
+ // @ts-expect-error TS2339
139
+ if (node.usedSymbolsDown.size > 0) {
140
+ label +=
141
+ // @ts-expect-error TS2339
142
+ '\\nusedSymbolsDown: ' + [...node.usedSymbolsDown].join(',');
143
+ }
144
+ // if (node.usedSymbolsDownDirty) label += '\\nusedSymbolsDownDirty';
145
+ // if (node.usedSymbolsUpDirtyDown)
146
+ // label += '\\nusedSymbolsUpDirtyDown';
147
+ // if (node.usedSymbolsUpDirtyUp) label += '\\nusedSymbolsUpDirtyUp';
148
+ }
149
+ else {
150
+ label += '\\nsymbols: cleared';
151
+ }
152
+ }
153
+ // @ts-expect-error TS2339
154
+ }
155
+ else if (node.type === 'asset') {
156
+ label +=
157
+ // @ts-expect-error TS2339
158
+ path_1.default.basename((0, projectPath_1.fromProjectPathRelative)(node.value.filePath)) +
159
+ '#' +
160
+ // @ts-expect-error TS2339
161
+ node.value.type;
162
+ if (detailedSymbols) {
163
+ // @ts-expect-error TS2339
164
+ if (!node.value.symbols) {
165
+ label += '\\nsymbols: cleared';
166
+ // @ts-expect-error TS2339
167
+ }
168
+ else if (node.value.symbols.size) {
169
+ label +=
170
+ '\\nsymbols: ' +
171
+ // @ts-expect-error TS2339
172
+ [...node.value.symbols]
173
+ .map(([e, { local }]) => [e, local])
174
+ .join(';');
175
+ }
176
+ // @ts-expect-error TS2339
177
+ if (node.usedSymbols.size) {
178
+ // @ts-expect-error TS2339
179
+ label += '\\nusedSymbols: ' + [...node.usedSymbols].join(',');
180
+ }
181
+ // if (node.usedSymbolsDownDirty) label += '\\nusedSymbolsDownDirty';
182
+ // if (node.usedSymbolsUpDirty) label += '\\nusedSymbolsUpDirty';
183
+ }
184
+ else {
185
+ label += '\\nsymbols: cleared';
186
+ }
187
+ // @ts-expect-error TS2339
188
+ }
189
+ else if (node.type === 'asset_group') {
190
+ // @ts-expect-error TS2339
191
+ if (node.deferred)
192
+ label += '(deferred)';
193
+ // @ts-expect-error TS2339
194
+ }
195
+ else if (node.type === 'file') {
196
+ // @ts-expect-error TS2339
197
+ label += path_1.default.basename(node.id);
198
+ // @ts-expect-error TS2339
199
+ }
200
+ else if (node.type === 'transformer_request') {
201
+ label +=
202
+ // @ts-expect-error TS2339
203
+ path_1.default.basename(node.value.filePath) +
204
+ // @ts-expect-error TS2339
205
+ ` (${getEnvDescription(node.value.env)})`;
206
+ // @ts-expect-error TS2339
207
+ }
208
+ else if (node.type === 'bundle') {
209
+ let parts = [];
210
+ // @ts-expect-error TS2339
211
+ if (node.value.needsStableName)
212
+ parts.push('stable name');
213
+ // @ts-expect-error TS2339
214
+ parts.push(node.value.name);
215
+ // @ts-expect-error TS2339
216
+ parts.push('bb:' + (node.value.bundleBehavior ?? 'null'));
217
+ // @ts-expect-error TS2339
218
+ if (node.value.isPlaceholder)
219
+ parts.push('placeholder');
220
+ if (parts.length)
221
+ label += ' (' + parts.join(', ') + ')';
222
+ // @ts-expect-error TS2339
223
+ if (node.value.env)
224
+ label += ` (${getEnvDescription(node.value.env)})`;
225
+ // @ts-expect-error TS2339
226
+ }
227
+ else if (node.type === 'request') {
228
+ // @ts-expect-error TS2339
229
+ label = node.requestType + ':' + node.id;
230
+ }
231
+ }
232
+ n.set('label', label);
233
+ }
234
+ let edgeNames;
235
+ if (edgeTypes) {
236
+ edgeNames = Object.fromEntries(Object.entries(edgeTypes).map(([k, v]) => [v, k]));
237
+ }
238
+ // @ts-expect-error TS2488
239
+ for (let edge of graph.getAllEdges()) {
240
+ let gEdge = g.addEdge(nodeId(edge.from), nodeId(edge.to));
241
+ let color = null;
242
+ if (edge.type != 1 && edgeNames) {
243
+ // @ts-expect-error TS7053
244
+ color = TYPE_COLORS[edgeNames[edge.type]];
245
+ }
246
+ if (color != null) {
247
+ gEdge.set('color', color);
248
+ }
249
+ }
250
+ if (process.env.ATLASPACK_BUILD_REPL) {
251
+ // @ts-expect-error TS7017
252
+ globalThis.ATLASPACK_DUMP_GRAPHVIZ?.(name, g.to_dot());
253
+ }
254
+ else {
255
+ const tempy = require('tempy');
256
+ let tmp = tempy.file({ name: `parcel-${name}.png` });
257
+ await g.output('png', tmp);
258
+ // eslint-disable-next-line no-console
259
+ console.log('Dumped', tmp);
260
+ }
261
+ }
262
+ // @ts-expect-error TS2552
263
+ function nodeId(id) {
264
+ return `node${id}`;
265
+ }
266
+ function getEnvDescription(env) {
267
+ let description;
268
+ if (typeof env.engines.browsers === 'string') {
269
+ description = `${env.context}: ${env.engines.browsers}`;
270
+ }
271
+ else if (Array.isArray(env.engines.browsers)) {
272
+ description = `${env.context}: ${env.engines.browsers.join(', ')}`;
273
+ }
274
+ else if (env.engines.node) {
275
+ description = `node: ${env.engines.node}`;
276
+ }
277
+ else if (env.engines.electron) {
278
+ description = `electron: ${env.engines.electron}`;
279
+ }
280
+ return description ?? '';
281
+ }
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.EnvironmentManager = exports.Environment = exports.createEnvironment = exports.resolveOptions = exports.ATLASPACK_VERSION = exports.WORKER_PATH = exports.INTERNAL_TRANSFORM = exports.INTERNAL_RESOLVE = exports.createWorkerFarm = exports.BuildError = exports.Parcel = exports.Atlaspack = exports.default = void 0;
43
+ const EnvironmentManager = __importStar(require("./EnvironmentManager"));
44
+ exports.EnvironmentManager = EnvironmentManager;
45
+ var Atlaspack_1 = require("./Atlaspack");
46
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(Atlaspack_1).default; } });
47
+ Object.defineProperty(exports, "Atlaspack", { enumerable: true, get: function () { return __importDefault(Atlaspack_1).default; } });
48
+ Object.defineProperty(exports, "Parcel", { enumerable: true, get: function () { return __importDefault(Atlaspack_1).default; } });
49
+ Object.defineProperty(exports, "BuildError", { enumerable: true, get: function () { return Atlaspack_1.BuildError; } });
50
+ Object.defineProperty(exports, "createWorkerFarm", { enumerable: true, get: function () { return Atlaspack_1.createWorkerFarm; } });
51
+ Object.defineProperty(exports, "INTERNAL_RESOLVE", { enumerable: true, get: function () { return Atlaspack_1.INTERNAL_RESOLVE; } });
52
+ Object.defineProperty(exports, "INTERNAL_TRANSFORM", { enumerable: true, get: function () { return Atlaspack_1.INTERNAL_TRANSFORM; } });
53
+ Object.defineProperty(exports, "WORKER_PATH", { enumerable: true, get: function () { return Atlaspack_1.WORKER_PATH; } });
54
+ var constants_1 = require("./constants");
55
+ Object.defineProperty(exports, "ATLASPACK_VERSION", { enumerable: true, get: function () { return constants_1.ATLASPACK_VERSION; } });
56
+ var resolveOptions_1 = require("./resolveOptions");
57
+ Object.defineProperty(exports, "resolveOptions", { enumerable: true, get: function () { return __importDefault(resolveOptions_1).default; } });
58
+ var Environment_1 = require("./Environment");
59
+ Object.defineProperty(exports, "createEnvironment", { enumerable: true, get: function () { return Environment_1.createEnvironment; } });
60
+ var Environment_2 = require("./public/Environment");
61
+ Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return __importDefault(Environment_2).default; } });
62
+ __exportStar(require("./atlaspack-v3"), exports);
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.default = loadPlugin;
40
+ const path_1 = __importDefault(require("path"));
41
+ const nullthrows_1 = __importDefault(require("nullthrows"));
42
+ const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
43
+ const utils_1 = require("@atlaspack/utils");
44
+ const projectPath_1 = require("./projectPath");
45
+ const NODE_MODULES = `${path_1.default.sep}node_modules${path_1.default.sep}`;
46
+ const CONFIG = Symbol.for('parcel-plugin-config');
47
+ async function loadPlugin(pluginName, configPath, keyPath, options) {
48
+ let resolveFrom = configPath;
49
+ // Config packages can reference plugins, but cannot contain other plugins within them.
50
+ // This forces every published plugin to be published separately so they can be mixed and matched if needed.
51
+ if (resolveFrom.includes(NODE_MODULES) && pluginName.startsWith('.')) {
52
+ let configContents = await options.inputFS.readFile(configPath, 'utf8');
53
+ throw new diagnostic_1.default({
54
+ diagnostic: {
55
+ message: (0, diagnostic_1.md) `Local plugins are not supported in Atlaspack config packages. Please publish "${pluginName}" as a separate npm package.`,
56
+ origin: '@atlaspack/core',
57
+ codeFrames: keyPath
58
+ ? [
59
+ {
60
+ filePath: configPath,
61
+ language: 'json5',
62
+ code: configContents,
63
+ codeHighlights: (0, diagnostic_1.generateJSONCodeHighlights)(configContents, [
64
+ {
65
+ key: keyPath,
66
+ type: 'value',
67
+ },
68
+ ]),
69
+ },
70
+ ]
71
+ : undefined,
72
+ },
73
+ });
74
+ }
75
+ let pkg;
76
+ try {
77
+ ({ pkg } = await options.packageManager.resolve(pluginName, resolveFrom, {
78
+ shouldAutoInstall: options.shouldAutoInstall,
79
+ }));
80
+ }
81
+ catch (err) {
82
+ if (err.code !== 'MODULE_NOT_FOUND') {
83
+ throw err;
84
+ }
85
+ let configContents = await options.inputFS.readFile(configPath, 'utf8');
86
+ let alternatives = await (0, utils_1.findAlternativeNodeModules)(options.inputFS, pluginName, path_1.default.dirname(resolveFrom));
87
+ throw new diagnostic_1.default({
88
+ diagnostic: {
89
+ message: (0, diagnostic_1.md) `Cannot find Atlaspack plugin "${pluginName}"`,
90
+ origin: '@atlaspack/core',
91
+ codeFrames: keyPath
92
+ ? [
93
+ {
94
+ filePath: configPath,
95
+ language: 'json5',
96
+ code: configContents,
97
+ codeHighlights: (0, diagnostic_1.generateJSONCodeHighlights)(configContents, [
98
+ {
99
+ key: keyPath,
100
+ type: 'value',
101
+ message: (0, diagnostic_1.md) `Cannot find module "${pluginName}"${alternatives[0]
102
+ ? `, did you mean "${alternatives[0]}"?`
103
+ : ''}`,
104
+ },
105
+ ]),
106
+ },
107
+ ]
108
+ : undefined,
109
+ },
110
+ });
111
+ }
112
+ let plugin = await options.packageManager.require(pluginName, resolveFrom, {
113
+ shouldAutoInstall: options.shouldAutoInstall,
114
+ });
115
+ plugin = plugin.default ? plugin.default : plugin;
116
+ if (!plugin) {
117
+ throw new Error(`Plugin ${pluginName} has no exports.`);
118
+ }
119
+ plugin = plugin[CONFIG];
120
+ if (!plugin) {
121
+ throw new Error(`Plugin ${pluginName} is not a valid Atlaspack plugin, should export an instance of a Atlaspack plugin ex. "export default new Reporter({ ... })".`);
122
+ }
123
+ return {
124
+ plugin,
125
+ version: (0, nullthrows_1.default)(pkg).version,
126
+ resolveFrom: (0, projectPath_1.toProjectPath)(options.projectRoot, resolveFrom),
127
+ };
128
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = loadEnv;
7
+ const utils_1 = require("@atlaspack/utils");
8
+ const dotenv_1 = __importDefault(require("dotenv"));
9
+ const dotenv_expand_1 = __importDefault(require("dotenv-expand"));
10
+ async function loadEnv(env, fs, filePath, projectRoot) {
11
+ const NODE_ENV = env.NODE_ENV ?? 'development';
12
+ const dotenvFiles = [
13
+ '.env',
14
+ // Don't include `.env.local` for `test` environment
15
+ // since normally you expect tests to produce the same
16
+ // results for everyone
17
+ NODE_ENV === 'test' ? null : '.env.local',
18
+ `.env.${NODE_ENV}`,
19
+ `.env.${NODE_ENV}.local`,
20
+ ].filter(Boolean);
21
+ let envs = await Promise.all(dotenvFiles.map(async (dotenvFile) => {
22
+ const envPath = await (0, utils_1.resolveConfig)(fs, filePath,
23
+ // @ts-expect-error TS2322
24
+ [dotenvFile], projectRoot);
25
+ if (envPath == null) {
26
+ return;
27
+ }
28
+ // `ignoreProcessEnv` prevents dotenv-expand from writing values into `process.env`:
29
+ // https://github.com/motdotla/dotenv-expand/blob/ddb73d02322fe8522b4e05b73e1c1ad24ea7c14a/lib/main.js#L5
30
+ let output = (0, dotenv_expand_1.default)({
31
+ parsed: dotenv_1.default.parse(await fs.readFile(envPath)),
32
+ // @ts-expect-error TS2353
33
+ ignoreProcessEnv: true,
34
+ });
35
+ if (output.error != null) {
36
+ throw output.error;
37
+ }
38
+ return output.parsed;
39
+ }));
40
+ return Object.assign({}, ...envs);
41
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fromProjectPath = exports.toProjectPath = void 0;
7
+ exports.fromProjectPathRelative = fromProjectPathRelative;
8
+ exports.toProjectPathUnsafe = toProjectPathUnsafe;
9
+ exports.joinProjectPath = joinProjectPath;
10
+ const path_1 = __importDefault(require("path"));
11
+ const utils_1 = require("@atlaspack/utils");
12
+ const feature_flags_1 = require("@atlaspack/feature-flags");
13
+ /**
14
+ * Converts a file path to a project-relative path.
15
+ *
16
+ * @param projectRoot - The project root.
17
+ * @param p - The file path to convert.
18
+ * @returns The project path.
19
+ */
20
+ function toProjectPath_(projectRoot, p) {
21
+ // If the file path is not provided, then treat it as though it is already from the project root
22
+ if (p == null) {
23
+ return p;
24
+ }
25
+ // If the file path is already relative and it does not begin with '.', then treat the path as if it
26
+ // is already from the project root. This prevents relative paths from being processed twice,
27
+ // most often within `toInternalSourceLocation` when handling loc types from symbols and asset
28
+ // dependencies.
29
+ if (p[0] !== '.' && !path_1.default.isAbsolute(p)) {
30
+ return p;
31
+ }
32
+ // If the file is outside the project root, store an absolute path rather than a relative one.
33
+ // This way if the project root is moved, the file references still work. Accessing files outside
34
+ // the project root is not portable anyway.
35
+ let relative = (0, utils_1.relativePath)(projectRoot, p, false);
36
+ if (relative.startsWith('..')) {
37
+ // e.g given projectRoot = '/Users/monorepo/project' and p = '/Users/monorepo/other-project/src/index.js' --> relative = '../other-project/src/index.js'
38
+ if ((0, feature_flags_1.getFeatureFlagValue)('patchProjectPaths')) {
39
+ return relative;
40
+ }
41
+ return process.platform === 'win32' ? (0, utils_1.normalizeSeparators)(p) : p;
42
+ }
43
+ return relative;
44
+ }
45
+ // @ts-expect-error TS2322
46
+ exports.toProjectPath = toProjectPath_;
47
+ function fromProjectPath_(projectRoot, p) {
48
+ if (p == null) {
49
+ return null;
50
+ }
51
+ // Project paths use normalized unix separators, so we only need to
52
+ // convert them on Windows.
53
+ let projectPath = process.platform === 'win32' ? path_1.default.normalize(p) : p;
54
+ // If the path is absolute (e.g. outside the project root), just return it.
55
+ if (path_1.default.isAbsolute(projectPath)) {
56
+ return projectPath;
57
+ }
58
+ // Add separator if needed. Doing this manunally is much faster than path.join.
59
+ if (projectRoot[projectRoot.length - 1] !== path_1.default.sep) {
60
+ return projectRoot + path_1.default.sep + projectPath;
61
+ }
62
+ return projectRoot + projectPath;
63
+ }
64
+ // @ts-expect-error TS2322
65
+ exports.fromProjectPath = fromProjectPath_;
66
+ /**
67
+ * Returns a path relative to the project root. This should be used when computing cache keys
68
+ */
69
+ function fromProjectPathRelative(p) {
70
+ return p;
71
+ }
72
+ /**
73
+ * This function should be avoided, it doesn't change the actual value.
74
+ */
75
+ function toProjectPathUnsafe(p) {
76
+ return p;
77
+ }
78
+ /**
79
+ * Joins a project root with relative paths (similar to `path.join`)
80
+ */
81
+ function joinProjectPath(a, ...b) {
82
+ return path_1.default.posix.join(a, ...b);
83
+ }