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