@atlaspack/core 2.13.2-dev.3689 → 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 (85) 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 +25 -9
  5. package/src/requests/WriteBundlesRequest.js +31 -22
  6. package/LICENSE +0 -201
  7. package/lib/AssetGraph.js +0 -521
  8. package/lib/Atlaspack.js +0 -676
  9. package/lib/AtlaspackConfig.js +0 -298
  10. package/lib/AtlaspackConfig.schema.js +0 -103
  11. package/lib/BundleGraph.js +0 -1527
  12. package/lib/CommittedAsset.js +0 -155
  13. package/lib/Dependency.js +0 -136
  14. package/lib/Environment.js +0 -144
  15. package/lib/IdentifierRegistry.js +0 -36
  16. package/lib/InternalConfig.js +0 -56
  17. package/lib/PackagerRunner.js +0 -525
  18. package/lib/ReporterRunner.js +0 -151
  19. package/lib/RequestTracker.js +0 -1178
  20. package/lib/SymbolPropagation.js +0 -618
  21. package/lib/TargetDescriptor.schema.js +0 -118
  22. package/lib/Transformation.js +0 -522
  23. package/lib/UncommittedAsset.js +0 -348
  24. package/lib/Validation.js +0 -203
  25. package/lib/applyRuntimes.js +0 -355
  26. package/lib/assetUtils.js +0 -205
  27. package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
  28. package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
  29. package/lib/atlaspack-v3/fs.js +0 -39
  30. package/lib/atlaspack-v3/index.js +0 -26
  31. package/lib/atlaspack-v3/jsCallable.js +0 -20
  32. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
  33. package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
  34. package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
  35. package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
  36. package/lib/atlaspack-v3/worker/compat/index.js +0 -104
  37. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
  38. package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
  39. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
  40. package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
  41. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
  42. package/lib/atlaspack-v3/worker/compat/target.js +0 -17
  43. package/lib/atlaspack-v3/worker/index.js +0 -3
  44. package/lib/atlaspack-v3/worker/worker.js +0 -280
  45. package/lib/constants.js +0 -21
  46. package/lib/dumpGraphToGraphViz.js +0 -206
  47. package/lib/index.js +0 -70
  48. package/lib/loadAtlaspackPlugin.js +0 -115
  49. package/lib/loadDotEnv.js +0 -54
  50. package/lib/projectPath.js +0 -112
  51. package/lib/public/Asset.js +0 -259
  52. package/lib/public/Bundle.js +0 -236
  53. package/lib/public/BundleGraph.js +0 -279
  54. package/lib/public/BundleGroup.js +0 -50
  55. package/lib/public/Config.js +0 -202
  56. package/lib/public/Dependency.js +0 -131
  57. package/lib/public/Environment.js +0 -247
  58. package/lib/public/MutableBundleGraph.js +0 -204
  59. package/lib/public/PluginOptions.js +0 -71
  60. package/lib/public/Symbols.js +0 -247
  61. package/lib/public/Target.js +0 -64
  62. package/lib/registerCoreWithSerializer.js +0 -51
  63. package/lib/requests/AssetGraphRequest.js +0 -432
  64. package/lib/requests/AssetGraphRequestRust.js +0 -220
  65. package/lib/requests/AssetRequest.js +0 -132
  66. package/lib/requests/AtlaspackBuildRequest.js +0 -79
  67. package/lib/requests/AtlaspackConfigRequest.js +0 -479
  68. package/lib/requests/BundleGraphRequest.js +0 -485
  69. package/lib/requests/ConfigRequest.js +0 -203
  70. package/lib/requests/DevDepRequest.js +0 -193
  71. package/lib/requests/EntryRequest.js +0 -295
  72. package/lib/requests/PackageRequest.js +0 -88
  73. package/lib/requests/PathRequest.js +0 -357
  74. package/lib/requests/TargetRequest.js +0 -1179
  75. package/lib/requests/ValidationRequest.js +0 -66
  76. package/lib/requests/WriteBundleRequest.js +0 -252
  77. package/lib/requests/WriteBundlesRequest.js +0 -153
  78. package/lib/requests/asset-graph-diff.js +0 -128
  79. package/lib/requests/asset-graph-dot.js +0 -131
  80. package/lib/resolveOptions.js +0 -265
  81. package/lib/serializerCore.browser.js +0 -29
  82. package/lib/summarizeRequest.js +0 -55
  83. package/lib/types.js +0 -35
  84. package/lib/utils.js +0 -160
  85. package/lib/worker.js +0 -184
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = createAssetRequest;
7
- function _nullthrows() {
8
- const data = _interopRequireDefault(require("nullthrows"));
9
- _nullthrows = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _diagnostic() {
15
- const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
16
- _diagnostic = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _rust() {
22
- const data = require("@atlaspack/rust");
23
- _rust = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
- var _AtlaspackConfigRequest = _interopRequireDefault(require("./AtlaspackConfigRequest"));
29
- var _DevDepRequest = require("./DevDepRequest");
30
- var _ConfigRequest = require("./ConfigRequest");
31
- var _projectPath = require("../projectPath");
32
- var _ReporterRunner = require("../ReporterRunner");
33
- var _RequestTracker = require("../RequestTracker");
34
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
- function createAssetRequest(input) {
36
- return {
37
- type: _RequestTracker.requestTypes.asset_request,
38
- id: getId(input),
39
- run,
40
- input
41
- };
42
- }
43
- const type = 'asset_request';
44
- function getId(input) {
45
- return (0, _rust().hashString)(type + (0, _projectPath.fromProjectPathRelative)(input.filePath) + input.env.id + String(input.isSource) + String(input.sideEffects) + (input.code ?? '') + ':' + (input.pipeline ?? '') + ':' + (input.query ?? ''));
46
- }
47
- async function run({
48
- input,
49
- api,
50
- farm,
51
- invalidateReason,
52
- options
53
- }) {
54
- (0, _ReporterRunner.report)({
55
- type: 'buildProgress',
56
- phase: 'transforming',
57
- filePath: (0, _projectPath.fromProjectPath)(options.projectRoot, input.filePath)
58
- });
59
- api.invalidateOnFileUpdate(input.filePath);
60
- let start = Date.now();
61
- let {
62
- optionsRef,
63
- ...rest
64
- } = input;
65
- let {
66
- cachePath
67
- } = (0, _nullthrows().default)(await api.runRequest((0, _AtlaspackConfigRequest.default)()));
68
- let previousDevDepRequests = new Map(await Promise.all(api.getSubRequests().filter(req => req.requestType === _RequestTracker.requestTypes.dev_dep_request).map(async req => [req.id, (0, _nullthrows().default)(await api.getRequestResult(req.id))])));
69
- let request = {
70
- ...rest,
71
- invalidateReason,
72
- devDeps: new Map([...previousDevDepRequests.entries()].filter(([id]) => api.canSkipSubrequest(id)).map(([, req]) => [`${req.specifier}:${(0, _projectPath.fromProjectPathRelative)(req.resolveFrom)}`, req.hash])),
73
- invalidDevDeps: await Promise.all([...previousDevDepRequests.entries()].filter(([id]) => !api.canSkipSubrequest(id)).flatMap(([, req]) => {
74
- return [{
75
- specifier: req.specifier,
76
- resolveFrom: req.resolveFrom
77
- }, ...(req.additionalInvalidations ?? []).map(i => ({
78
- specifier: i.specifier,
79
- resolveFrom: i.resolveFrom
80
- }))];
81
- }))
82
- };
83
- let {
84
- assets,
85
- configRequests,
86
- error,
87
- invalidations,
88
- devDepRequests
89
- } = await farm.createHandle('runTransform', input.isSingleChangeRebuild)({
90
- configCachePath: cachePath,
91
- optionsRef,
92
- request
93
- });
94
- let time = Date.now() - start;
95
- if (assets) {
96
- for (let asset of assets) {
97
- asset.stats.time = time;
98
- }
99
- }
100
- for (let filePath of invalidations.invalidateOnFileChange) {
101
- api.invalidateOnFileUpdate(filePath);
102
- api.invalidateOnFileDelete(filePath);
103
- }
104
- for (let invalidation of invalidations.invalidateOnFileCreate) {
105
- api.invalidateOnFileCreate(invalidation);
106
- }
107
- for (let env of invalidations.invalidateOnEnvChange) {
108
- api.invalidateOnEnvChange(env);
109
- }
110
- for (let option of invalidations.invalidateOnOptionChange) {
111
- api.invalidateOnOptionChange(option);
112
- }
113
- if (invalidations.invalidateOnStartup) {
114
- api.invalidateOnStartup();
115
- }
116
- if (invalidations.invalidateOnBuild) {
117
- api.invalidateOnBuild();
118
- }
119
- for (let devDepRequest of devDepRequests) {
120
- await (0, _DevDepRequest.runDevDepRequest)(api, devDepRequest);
121
- }
122
- for (let configRequest of configRequests) {
123
- await (0, _ConfigRequest.runConfigRequest)(api, configRequest);
124
- }
125
- if (error != null) {
126
- throw new (_diagnostic().default)({
127
- diagnostic: error
128
- });
129
- } else {
130
- return (0, _nullthrows().default)(assets);
131
- }
132
- }
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = createAtlaspackBuildRequest;
7
- var _BundleGraphRequest = _interopRequireDefault(require("./BundleGraphRequest"));
8
- var _WriteBundlesRequest = _interopRequireDefault(require("./WriteBundlesRequest"));
9
- var _utils = require("../utils");
10
- var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
11
- var _BundleGraph = require("../BundleGraph");
12
- var _ReporterRunner = require("../ReporterRunner");
13
- var _BundleGraph2 = _interopRequireDefault(require("../public/BundleGraph"));
14
- var _Bundle = require("../public/Bundle");
15
- var _Asset = require("../public/Asset");
16
- function _profiler() {
17
- const data = require("@atlaspack/profiler");
18
- _profiler = function () {
19
- return data;
20
- };
21
- return data;
22
- }
23
- var _RequestTracker = require("../RequestTracker");
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
- function createAtlaspackBuildRequest(input) {
26
- return {
27
- type: _RequestTracker.requestTypes.atlaspack_build_request,
28
- id: 'atlaspack_build_request',
29
- run,
30
- input
31
- };
32
- }
33
- async function run({
34
- input,
35
- api,
36
- options,
37
- rustAtlaspack
38
- }) {
39
- let {
40
- optionsRef,
41
- requestedAssetIds,
42
- signal
43
- } = input;
44
- let bundleGraphRequest = (0, _BundleGraphRequest.default)({
45
- optionsRef,
46
- requestedAssetIds,
47
- signal
48
- });
49
- let {
50
- bundleGraph,
51
- changedAssets,
52
- assetRequests
53
- } = await api.runRequest(bundleGraphRequest, {
54
- force: Boolean(rustAtlaspack) || options.shouldBuildLazily && requestedAssetIds.size > 0
55
- });
56
-
57
- // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381 (Windows only)
58
- (0, _dumpGraphToGraphViz.default)(bundleGraph._graph, 'BundleGraph', _BundleGraph.bundleGraphEdgeTypes);
59
- await (0, _ReporterRunner.report)({
60
- type: 'buildProgress',
61
- phase: 'bundled',
62
- bundleGraph: new _BundleGraph2.default(bundleGraph, (bundle, bundleGraph, options) => _Bundle.NamedBundle.get(bundle, bundleGraph, options), options),
63
- changedAssets: new Map(Array.from(changedAssets).map(([id, asset]) => [id, (0, _Asset.assetFromValue)(asset, options)]))
64
- });
65
- let packagingMeasurement = _profiler().tracer.createMeasurement('packaging');
66
- let writeBundlesRequest = (0, _WriteBundlesRequest.default)({
67
- bundleGraph,
68
- optionsRef
69
- });
70
- let bundleInfo = await api.runRequest(writeBundlesRequest);
71
- packagingMeasurement && packagingMeasurement.end();
72
- (0, _utils.assertSignalNotAborted)(signal);
73
- return {
74
- bundleGraph,
75
- bundleInfo,
76
- changedAssets,
77
- assetRequests
78
- };
79
- }
@@ -1,479 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.create = create;
7
- exports.default = createAtlaspackConfigRequest;
8
- exports.getCachedAtlaspackConfig = getCachedAtlaspackConfig;
9
- exports.getResolveFrom = getResolveFrom;
10
- exports.loadAtlaspackConfig = loadAtlaspackConfig;
11
- exports.mergeConfigs = mergeConfigs;
12
- exports.mergeMaps = mergeMaps;
13
- exports.mergePipelines = mergePipelines;
14
- exports.parseAndProcessConfig = parseAndProcessConfig;
15
- exports.processConfig = processConfig;
16
- exports.processConfigChain = processConfigChain;
17
- exports.resolveAtlaspackConfig = resolveAtlaspackConfig;
18
- exports.resolveExtends = resolveExtends;
19
- exports.validateConfigFile = validateConfigFile;
20
- exports.validateNotEmpty = validateNotEmpty;
21
- function _buildCache() {
22
- const data = require("@atlaspack/build-cache");
23
- _buildCache = function () {
24
- return data;
25
- };
26
- return data;
27
- }
28
- function _utils() {
29
- const data = require("@atlaspack/utils");
30
- _utils = function () {
31
- return data;
32
- };
33
- return data;
34
- }
35
- function _diagnostic() {
36
- const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
37
- _diagnostic = function () {
38
- return data;
39
- };
40
- return data;
41
- }
42
- function _json() {
43
- const data = require("json5");
44
- _json = function () {
45
- return data;
46
- };
47
- return data;
48
- }
49
- function _path() {
50
- const data = _interopRequireDefault(require("path"));
51
- _path = function () {
52
- return data;
53
- };
54
- return data;
55
- }
56
- function _assert() {
57
- const data = _interopRequireDefault(require("assert"));
58
- _assert = function () {
59
- return data;
60
- };
61
- return data;
62
- }
63
- var _AtlaspackConfig = require("../AtlaspackConfig");
64
- var _AtlaspackConfig2 = _interopRequireDefault(require("../AtlaspackConfig.schema"));
65
- var _projectPath = require("../projectPath");
66
- var _RequestTracker = require("../RequestTracker");
67
- var _utils2 = require("../utils");
68
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
70
- 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; }
71
- const type = 'atlaspack_config_request';
72
- function createAtlaspackConfigRequest() {
73
- return {
74
- id: type,
75
- type: _RequestTracker.requestTypes[type],
76
- async run({
77
- api,
78
- options
79
- }) {
80
- let {
81
- config,
82
- extendedFiles,
83
- usedDefault
84
- } = await loadAtlaspackConfig((0, _utils2.optionsProxy)(options, api.invalidateOnOptionChange));
85
- api.invalidateOnFileUpdate(config.filePath);
86
- api.invalidateOnFileDelete(config.filePath);
87
- for (let filePath of extendedFiles) {
88
- let pp = (0, _projectPath.toProjectPath)(options.projectRoot, filePath);
89
- api.invalidateOnFileUpdate(pp);
90
- api.invalidateOnFileDelete(pp);
91
- }
92
- if (usedDefault) {
93
- let resolveFrom = getResolveFrom(options.inputFS, options.projectRoot);
94
- api.invalidateOnFileCreate({
95
- fileName: '.parcelrc',
96
- aboveFilePath: (0, _projectPath.toProjectPath)(options.projectRoot, resolveFrom)
97
- });
98
- }
99
- let cachePath = (0, _utils().hashObject)(config);
100
- await options.cache.set(cachePath, config);
101
- let result = {
102
- config,
103
- cachePath
104
- };
105
- // TODO: don't store config twice (once in the graph and once in a separate cache entry)
106
- api.storeResult(result);
107
- return result;
108
- },
109
- input: null
110
- };
111
- }
112
- const atlaspackConfigCache = (0, _buildCache().createBuildCache)();
113
- function getCachedAtlaspackConfig(result, options) {
114
- let {
115
- config: processedConfig,
116
- cachePath
117
- } = result;
118
- let config = atlaspackConfigCache.get(cachePath);
119
- if (config) {
120
- return config;
121
- }
122
- config = new _AtlaspackConfig.AtlaspackConfig(processedConfig, options);
123
- atlaspackConfigCache.set(cachePath, config);
124
- return config;
125
- }
126
- async function loadAtlaspackConfig(options) {
127
- let atlaspackConfig = await resolveAtlaspackConfig(options);
128
- if (!atlaspackConfig) {
129
- throw new Error('Could not find a .parcelrc');
130
- }
131
- return atlaspackConfig;
132
- }
133
- async function resolveAtlaspackConfig(options) {
134
- let resolveFrom = getResolveFrom(options.inputFS, options.projectRoot);
135
- let configPath = options.config != null ? (await options.packageManager.resolve(options.config, resolveFrom)).resolved : await (0, _utils().resolveConfig)(options.inputFS, resolveFrom, ['.parcelrc'], options.projectRoot);
136
- let usedDefault = false;
137
- if (configPath == null && options.defaultConfig != null) {
138
- usedDefault = true;
139
- configPath = (await options.packageManager.resolve(options.defaultConfig, resolveFrom)).resolved;
140
- }
141
- if (configPath == null) {
142
- return null;
143
- }
144
- let contents;
145
- try {
146
- contents = await options.inputFS.readFile(configPath, 'utf8');
147
- } catch (e) {
148
- throw new (_diagnostic().default)({
149
- diagnostic: {
150
- message: (0, _diagnostic().md)`Could not find parcel config at ${_path().default.relative(options.projectRoot, configPath)}`,
151
- origin: '@atlaspack/core'
152
- }
153
- });
154
- }
155
- let {
156
- config,
157
- extendedFiles
158
- } = await parseAndProcessConfig(configPath, contents, options);
159
- if (options.additionalReporters.length > 0) {
160
- config.reporters = [...options.additionalReporters.map(({
161
- packageName,
162
- resolveFrom
163
- }) => ({
164
- packageName,
165
- resolveFrom
166
- })), ...(config.reporters ?? [])];
167
- }
168
- return {
169
- config,
170
- extendedFiles,
171
- usedDefault
172
- };
173
- }
174
- function create(config, options) {
175
- return processConfigChain(config, config.filePath, options);
176
- }
177
-
178
- // eslint-disable-next-line require-await
179
- async function parseAndProcessConfig(configPath, contents, options) {
180
- let config;
181
- try {
182
- config = (0, _json().parse)(contents);
183
- } catch (e) {
184
- let pos = {
185
- line: e.lineNumber,
186
- column: e.columnNumber
187
- };
188
- throw new (_diagnostic().default)({
189
- diagnostic: {
190
- message: `Failed to parse .parcelrc`,
191
- origin: '@atlaspack/core',
192
- codeFrames: [{
193
- filePath: configPath,
194
- language: 'json5',
195
- code: contents,
196
- codeHighlights: [{
197
- start: pos,
198
- end: pos,
199
- message: (0, _diagnostic().escapeMarkdown)(e.message)
200
- }]
201
- }]
202
- }
203
- });
204
- }
205
- return processConfigChain(config, configPath, options);
206
- }
207
- function processPipeline(options, pipeline, keyPath, filePath) {
208
- if (pipeline) {
209
- return pipeline.map((pkg, i) => {
210
- // $FlowFixMe
211
- if (pkg === '...') return pkg;
212
- return {
213
- packageName: pkg,
214
- resolveFrom: (0, _projectPath.toProjectPath)(options.projectRoot, filePath),
215
- keyPath: `${keyPath}/${i}`
216
- };
217
- });
218
- }
219
- }
220
- const RESERVED_PIPELINES = new Set(['node:', 'npm:', 'http:', 'https:', 'data:', 'tel:', 'mailto:']);
221
- async function processMap(
222
- // $FlowFixMe
223
- map, keyPath, filePath, options
224
- // $FlowFixMe
225
- ) {
226
- if (!map) return undefined;
227
-
228
- // $FlowFixMe
229
- let res = {};
230
- for (let k in map) {
231
- let i = k.indexOf(':');
232
- if (i > 0 && RESERVED_PIPELINES.has(k.slice(0, i + 1))) {
233
- let code = await options.inputFS.readFile(filePath, 'utf8');
234
- throw new (_diagnostic().default)({
235
- diagnostic: {
236
- message: `Named pipeline '${k.slice(0, i + 1)}' is reserved.`,
237
- origin: '@atlaspack/core',
238
- codeFrames: [{
239
- filePath: filePath,
240
- language: 'json5',
241
- code,
242
- codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(code, [{
243
- key: `${keyPath}/${k}`,
244
- type: 'key'
245
- }])
246
- }],
247
- documentationURL: 'https://parceljs.org/features/dependency-resolution/#url-schemes'
248
- }
249
- });
250
- }
251
- if (typeof map[k] === 'string') {
252
- res[k] = {
253
- packageName: map[k],
254
- resolveFrom: (0, _projectPath.toProjectPath)(options.projectRoot, filePath),
255
- keyPath: `${keyPath}/${k}`
256
- };
257
- } else {
258
- res[k] = processPipeline(options, map[k], `${keyPath}/${k}`, filePath);
259
- }
260
- }
261
- return res;
262
- }
263
- async function processConfig(configFile, options) {
264
- return {
265
- filePath: (0, _projectPath.toProjectPath)(options.projectRoot, configFile.filePath),
266
- ...(configFile.resolveFrom != null ? {
267
- resolveFrom: (0, _projectPath.toProjectPath)(options.projectRoot, configFile.resolveFrom)
268
- } : {
269
- /*::...null*/
270
- }),
271
- resolvers: processPipeline(options, configFile.resolvers, '/resolvers', configFile.filePath),
272
- transformers: await processMap(configFile.transformers, '/transformers', configFile.filePath, options),
273
- bundler: configFile.bundler != null ? {
274
- packageName: configFile.bundler,
275
- resolveFrom: (0, _projectPath.toProjectPath)(options.projectRoot, configFile.filePath),
276
- keyPath: '/bundler'
277
- } : undefined,
278
- namers: processPipeline(options, configFile.namers, '/namers', configFile.filePath),
279
- runtimes: processPipeline(options, configFile.runtimes, '/runtimes', configFile.filePath),
280
- packagers: await processMap(configFile.packagers, '/packagers', configFile.filePath, options),
281
- optimizers: await processMap(configFile.optimizers, '/optimizers', configFile.filePath, options),
282
- compressors: await processMap(configFile.compressors, '/compressors', configFile.filePath, options),
283
- reporters: processPipeline(options, configFile.reporters, '/reporters', configFile.filePath),
284
- validators: await processMap(configFile.validators, '/validators', configFile.filePath, options)
285
- };
286
- }
287
- async function processConfigChain(configFile, filePath, options) {
288
- // Validate config...
289
- let relativePath = _path().default.relative(options.inputFS.cwd(), filePath);
290
- validateConfigFile(configFile, relativePath);
291
-
292
- // Process config...
293
- let config = await processConfig({
294
- filePath,
295
- ...configFile
296
- }, options);
297
- let extendedFiles = [];
298
- if (configFile.extends != null) {
299
- let exts = Array.isArray(configFile.extends) ? configFile.extends : [configFile.extends];
300
- let errors = [];
301
- if (exts.length !== 0) {
302
- let extStartConfig;
303
- let i = 0;
304
- for (let ext of exts) {
305
- try {
306
- let key = Array.isArray(configFile.extends) ? `/extends/${i}` : '/extends';
307
- let resolved = await resolveExtends(ext, filePath, key, options);
308
- extendedFiles.push(resolved);
309
- let {
310
- extendedFiles: moreExtendedFiles,
311
- config: nextConfig
312
- } = await processExtendedConfig(filePath, key, ext, resolved, options);
313
- extendedFiles = extendedFiles.concat(moreExtendedFiles);
314
- extStartConfig = extStartConfig ? mergeConfigs(extStartConfig, nextConfig) : nextConfig;
315
- } catch (err) {
316
- errors.push(err);
317
- }
318
- i++;
319
- }
320
-
321
- // Merge with the inline config last
322
- if (extStartConfig) {
323
- config = mergeConfigs(extStartConfig, config);
324
- }
325
- }
326
- if (errors.length > 0) {
327
- throw new (_diagnostic().default)({
328
- diagnostic: errors.flatMap(e => e.diagnostics ?? (0, _diagnostic().errorToDiagnostic)(e))
329
- });
330
- }
331
- }
332
- return {
333
- config,
334
- extendedFiles
335
- };
336
- }
337
- async function resolveExtends(ext, configPath, extendsKey, options) {
338
- if (ext.startsWith('.')) {
339
- return _path().default.resolve(_path().default.dirname(configPath), ext);
340
- } else {
341
- try {
342
- let {
343
- resolved
344
- } = await options.packageManager.resolve(ext, configPath);
345
- return options.inputFS.realpath(resolved);
346
- } catch (err) {
347
- let parentContents = await options.inputFS.readFile(configPath, 'utf8');
348
- let alternatives = await (0, _utils().findAlternativeNodeModules)(options.inputFS, ext, _path().default.dirname(configPath));
349
- throw new (_diagnostic().default)({
350
- diagnostic: {
351
- message: `Cannot find extended parcel config`,
352
- origin: '@atlaspack/core',
353
- codeFrames: [{
354
- filePath: configPath,
355
- language: 'json5',
356
- code: parentContents,
357
- codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(parentContents, [{
358
- key: extendsKey,
359
- type: 'value',
360
- message: (0, _diagnostic().md)`Cannot find module "${ext}"${alternatives[0] ? `, did you mean "${alternatives[0]}"?` : ''}`
361
- }])
362
- }]
363
- }
364
- });
365
- }
366
- }
367
- }
368
- async function processExtendedConfig(configPath, extendsKey, extendsSpecifier, resolvedExtendedConfigPath, options) {
369
- let contents;
370
- try {
371
- contents = await options.inputFS.readFile(resolvedExtendedConfigPath, 'utf8');
372
- } catch (e) {
373
- let parentContents = await options.inputFS.readFile(configPath, 'utf8');
374
- let alternatives = await (0, _utils().findAlternativeFiles)(options.inputFS, extendsSpecifier, _path().default.dirname(resolvedExtendedConfigPath), options.projectRoot);
375
- throw new (_diagnostic().default)({
376
- diagnostic: {
377
- message: 'Cannot find extended parcel config',
378
- origin: '@atlaspack/core',
379
- codeFrames: [{
380
- filePath: configPath,
381
- language: 'json5',
382
- code: parentContents,
383
- codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(parentContents, [{
384
- key: extendsKey,
385
- type: 'value',
386
- message: (0, _diagnostic().md)`"${extendsSpecifier}" does not exist${alternatives[0] ? `, did you mean "${alternatives[0]}"?` : ''}`
387
- }])
388
- }]
389
- }
390
- });
391
- }
392
- return parseAndProcessConfig(resolvedExtendedConfigPath, contents, options);
393
- }
394
- function validateConfigFile(config, relativePath) {
395
- try {
396
- validateNotEmpty(config, relativePath);
397
- } catch (e) {
398
- throw new (_diagnostic().default)({
399
- diagnostic: {
400
- message: e.message,
401
- origin: '@atlaspack/core'
402
- }
403
- });
404
- }
405
- _utils().validateSchema.diagnostic(_AtlaspackConfig2.default, {
406
- data: config,
407
- filePath: relativePath
408
- }, '@atlaspack/core', 'Invalid Parcel Config');
409
- }
410
- function validateNotEmpty(config, relativePath) {
411
- _assert().default.notDeepStrictEqual(config, {}, `${relativePath} can't be empty`);
412
- }
413
- function mergeConfigs(base, ext) {
414
- return {
415
- filePath: ext.filePath,
416
- resolvers: assertPurePipeline(mergePipelines(base.resolvers, ext.resolvers)),
417
- transformers: mergeMaps(base.transformers, ext.transformers, mergePipelines),
418
- validators: mergeMaps(base.validators, ext.validators, mergePipelines),
419
- bundler: ext.bundler || base.bundler,
420
- namers: assertPurePipeline(mergePipelines(base.namers, ext.namers)),
421
- runtimes: assertPurePipeline(mergePipelines(base.runtimes, ext.runtimes)),
422
- packagers: mergeMaps(base.packagers, ext.packagers),
423
- optimizers: mergeMaps(base.optimizers, ext.optimizers, mergePipelines),
424
- compressors: mergeMaps(base.compressors, ext.compressors, mergePipelines),
425
- reporters: assertPurePipeline(mergePipelines(base.reporters, ext.reporters))
426
- };
427
- }
428
- function getResolveFrom(fs, projectRoot) {
429
- let cwd = fs.cwd();
430
- let dir = (0, _utils().isDirectoryInside)(cwd, projectRoot) ? cwd : projectRoot;
431
- return _path().default.join(dir, 'index');
432
- }
433
- function assertPurePipeline(pipeline) {
434
- return pipeline.map(s => {
435
- (0, _assert().default)(typeof s !== 'string');
436
- return s;
437
- });
438
- }
439
- function mergePipelines(base, ext) {
440
- if (ext == null) {
441
- return base ?? [];
442
- }
443
- if (ext.filter(v => v === '...').length > 1) {
444
- throw new Error('Only one spread element can be included in a config pipeline');
445
- }
446
-
447
- // Merge the base pipeline if a rest element is defined
448
- let spreadIndex = ext.indexOf('...');
449
- if (spreadIndex >= 0) {
450
- return [...ext.slice(0, spreadIndex), ...(base ?? []), ...ext.slice(spreadIndex + 1)];
451
- } else {
452
- return ext;
453
- }
454
- }
455
- function mergeMaps(base, ext, merger) {
456
- if (!ext || Object.keys(ext).length === 0) {
457
- return base || {};
458
- }
459
- if (!base) {
460
- return ext;
461
- }
462
- let res = {};
463
- // Add the extension options first so they have higher precedence in the output glob map
464
- for (let k in ext) {
465
- //$FlowFixMe Flow doesn't correctly infer the type. See https://github.com/facebook/flow/issues/1736.
466
- let key = k;
467
- res[key] = merger && base[key] != null ? merger(base[key], ext[key]) : ext[key];
468
- }
469
-
470
- // Add base options that aren't defined in the extension
471
- for (let k in base) {
472
- // $FlowFixMe
473
- let key = k;
474
- if (res[key] == null) {
475
- res[key] = base[key];
476
- }
477
- }
478
- return res;
479
- }