@atlaspack/core 2.13.2-dev.3682 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/package.json +20 -20
- package/src/Atlaspack.js +3 -2
- package/src/atlaspack-v3/AtlaspackV3.js +24 -8
- package/src/loadAtlaspackPlugin.js +26 -71
- package/src/projectPath.js +14 -1
- package/src/requests/WriteBundlesRequest.js +31 -22
- package/LICENSE +0 -201
- package/lib/AssetGraph.js +0 -521
- package/lib/Atlaspack.js +0 -676
- package/lib/AtlaspackConfig.js +0 -298
- package/lib/AtlaspackConfig.schema.js +0 -103
- package/lib/BundleGraph.js +0 -1527
- package/lib/CommittedAsset.js +0 -155
- package/lib/Dependency.js +0 -136
- package/lib/Environment.js +0 -144
- package/lib/IdentifierRegistry.js +0 -36
- package/lib/InternalConfig.js +0 -56
- package/lib/PackagerRunner.js +0 -525
- package/lib/ReporterRunner.js +0 -151
- package/lib/RequestTracker.js +0 -1178
- package/lib/SymbolPropagation.js +0 -618
- package/lib/TargetDescriptor.schema.js +0 -118
- package/lib/Transformation.js +0 -522
- package/lib/UncommittedAsset.js +0 -348
- package/lib/Validation.js +0 -203
- package/lib/applyRuntimes.js +0 -355
- package/lib/assetUtils.js +0 -205
- package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
- package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
- package/lib/atlaspack-v3/fs.js +0 -39
- package/lib/atlaspack-v3/index.js +0 -26
- package/lib/atlaspack-v3/jsCallable.js +0 -20
- package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
- package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
- package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
- package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
- package/lib/atlaspack-v3/worker/compat/index.js +0 -104
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
- package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
- package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
- package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
- package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
- package/lib/atlaspack-v3/worker/compat/target.js +0 -17
- package/lib/atlaspack-v3/worker/index.js +0 -3
- package/lib/atlaspack-v3/worker/worker.js +0 -280
- package/lib/constants.js +0 -21
- package/lib/dumpGraphToGraphViz.js +0 -206
- package/lib/index.js +0 -70
- package/lib/loadAtlaspackPlugin.js +0 -136
- package/lib/loadDotEnv.js +0 -54
- package/lib/projectPath.js +0 -94
- package/lib/public/Asset.js +0 -259
- package/lib/public/Bundle.js +0 -236
- package/lib/public/BundleGraph.js +0 -279
- package/lib/public/BundleGroup.js +0 -50
- package/lib/public/Config.js +0 -202
- package/lib/public/Dependency.js +0 -131
- package/lib/public/Environment.js +0 -247
- package/lib/public/MutableBundleGraph.js +0 -204
- package/lib/public/PluginOptions.js +0 -71
- package/lib/public/Symbols.js +0 -247
- package/lib/public/Target.js +0 -64
- package/lib/registerCoreWithSerializer.js +0 -51
- package/lib/requests/AssetGraphRequest.js +0 -432
- package/lib/requests/AssetGraphRequestRust.js +0 -220
- package/lib/requests/AssetRequest.js +0 -132
- package/lib/requests/AtlaspackBuildRequest.js +0 -79
- package/lib/requests/AtlaspackConfigRequest.js +0 -479
- package/lib/requests/BundleGraphRequest.js +0 -485
- package/lib/requests/ConfigRequest.js +0 -203
- package/lib/requests/DevDepRequest.js +0 -193
- package/lib/requests/EntryRequest.js +0 -295
- package/lib/requests/PackageRequest.js +0 -88
- package/lib/requests/PathRequest.js +0 -357
- package/lib/requests/TargetRequest.js +0 -1179
- package/lib/requests/ValidationRequest.js +0 -66
- package/lib/requests/WriteBundleRequest.js +0 -252
- package/lib/requests/WriteBundlesRequest.js +0 -153
- package/lib/requests/asset-graph-diff.js +0 -128
- package/lib/requests/asset-graph-dot.js +0 -131
- package/lib/resolveOptions.js +0 -265
- package/lib/serializerCore.browser.js +0 -29
- package/lib/summarizeRequest.js +0 -55
- package/lib/types.js +0 -35
- package/lib/utils.js +0 -160
- package/lib/worker.js +0 -184
|
@@ -1,1179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TargetResolver = void 0;
|
|
7
|
-
exports.default = createTargetRequest;
|
|
8
|
-
exports.skipTarget = skipTarget;
|
|
9
|
-
function _diagnostic() {
|
|
10
|
-
const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
|
|
11
|
-
_diagnostic = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
function _path() {
|
|
17
|
-
const data = _interopRequireDefault(require("path"));
|
|
18
|
-
_path = function () {
|
|
19
|
-
return data;
|
|
20
|
-
};
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
function _utils() {
|
|
24
|
-
const data = require("@atlaspack/utils");
|
|
25
|
-
_utils = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
function _logger() {
|
|
31
|
-
const data = _interopRequireDefault(require("@atlaspack/logger"));
|
|
32
|
-
_logger = function () {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
var _Environment = require("../Environment");
|
|
38
|
-
var _AtlaspackConfigRequest = _interopRequireWildcard(require("./AtlaspackConfigRequest"));
|
|
39
|
-
function _browserslist() {
|
|
40
|
-
const data = _interopRequireDefault(require("browserslist"));
|
|
41
|
-
_browserslist = function () {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
return data;
|
|
45
|
-
}
|
|
46
|
-
function _jsonSourcemap() {
|
|
47
|
-
const data = require("@mischnic/json-sourcemap");
|
|
48
|
-
_jsonSourcemap = function () {
|
|
49
|
-
return data;
|
|
50
|
-
};
|
|
51
|
-
return data;
|
|
52
|
-
}
|
|
53
|
-
function _assert() {
|
|
54
|
-
const data = _interopRequireDefault(require("assert"));
|
|
55
|
-
_assert = function () {
|
|
56
|
-
return data;
|
|
57
|
-
};
|
|
58
|
-
return data;
|
|
59
|
-
}
|
|
60
|
-
function _nullthrows() {
|
|
61
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
62
|
-
_nullthrows = function () {
|
|
63
|
-
return data;
|
|
64
|
-
};
|
|
65
|
-
return data;
|
|
66
|
-
}
|
|
67
|
-
var _TargetDescriptor = require("../TargetDescriptor.schema");
|
|
68
|
-
var _Environment2 = require("../public/Environment");
|
|
69
|
-
var _utils2 = require("../utils");
|
|
70
|
-
var _projectPath = require("../projectPath");
|
|
71
|
-
var _RequestTracker = require("../RequestTracker");
|
|
72
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
73
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
74
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
75
|
-
// $FlowFixMe
|
|
76
|
-
const DEFAULT_DIST_DIRNAME = 'dist';
|
|
77
|
-
const JS_RE = /\.[mc]?js$/;
|
|
78
|
-
const JS_EXTENSIONS = ['.js', '.mjs', '.cjs'];
|
|
79
|
-
const COMMON_TARGETS = {
|
|
80
|
-
main: {
|
|
81
|
-
match: JS_RE,
|
|
82
|
-
extensions: JS_EXTENSIONS
|
|
83
|
-
},
|
|
84
|
-
module: {
|
|
85
|
-
// module field is always ESM. Don't allow .cjs extension here.
|
|
86
|
-
match: /\.m?js$/,
|
|
87
|
-
extensions: ['.js', '.mjs']
|
|
88
|
-
},
|
|
89
|
-
browser: {
|
|
90
|
-
match: JS_RE,
|
|
91
|
-
extensions: JS_EXTENSIONS
|
|
92
|
-
},
|
|
93
|
-
types: {
|
|
94
|
-
match: /\.d\.ts$/,
|
|
95
|
-
extensions: ['.d.ts']
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const DEFAULT_ENGINES = {
|
|
99
|
-
node: 'current',
|
|
100
|
-
browsers: ['last 1 Chrome version', 'last 1 Safari version', 'last 1 Firefox version', 'last 1 Edge version']
|
|
101
|
-
};
|
|
102
|
-
const type = 'target_request';
|
|
103
|
-
function createTargetRequest(input) {
|
|
104
|
-
return {
|
|
105
|
-
id: `${type}:${(0, _utils().hashObject)(input)}`,
|
|
106
|
-
type: _RequestTracker.requestTypes.target_request,
|
|
107
|
-
run,
|
|
108
|
-
input
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function skipTarget(targetName, exclusiveTarget, descriptorSource) {
|
|
112
|
-
// We skip targets if they have a descriptor.source and don't match the current exclusiveTarget
|
|
113
|
-
// They will be handled by a separate resolvePackageTargets call from their Entry point
|
|
114
|
-
// but with exclusiveTarget set.
|
|
115
|
-
|
|
116
|
-
return exclusiveTarget == null ? descriptorSource != null : targetName !== exclusiveTarget;
|
|
117
|
-
}
|
|
118
|
-
async function run({
|
|
119
|
-
input,
|
|
120
|
-
api,
|
|
121
|
-
options
|
|
122
|
-
}) {
|
|
123
|
-
let targetResolver = new TargetResolver(api, (0, _utils2.optionsProxy)(options, api.invalidateOnOptionChange));
|
|
124
|
-
let targets = await targetResolver.resolve((0, _projectPath.fromProjectPath)(options.projectRoot, input.packagePath), input.target);
|
|
125
|
-
assertTargetsAreNotEntries(targets, input, options);
|
|
126
|
-
let configResult = (0, _nullthrows().default)(await api.runRequest((0, _AtlaspackConfigRequest.default)()));
|
|
127
|
-
let atlaspackConfig = (0, _AtlaspackConfigRequest.getCachedAtlaspackConfig)(configResult, options);
|
|
128
|
-
|
|
129
|
-
// Find named pipelines for each target.
|
|
130
|
-
let pipelineNames = new Set(atlaspackConfig.getNamedPipelines());
|
|
131
|
-
for (let target of targets) {
|
|
132
|
-
if (pipelineNames.has(target.name)) {
|
|
133
|
-
target.pipeline = target.name;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (options.logLevel === 'verbose') {
|
|
137
|
-
await debugResolvedTargets(input, targets, targetResolver.targetInfo, options);
|
|
138
|
-
}
|
|
139
|
-
return targets;
|
|
140
|
-
}
|
|
141
|
-
class TargetResolver {
|
|
142
|
-
constructor(api, options) {
|
|
143
|
-
this.api = api;
|
|
144
|
-
this.fs = options.inputFS;
|
|
145
|
-
this.options = options;
|
|
146
|
-
this.targetInfo = new Map();
|
|
147
|
-
}
|
|
148
|
-
async resolve(rootDir, exclusiveTarget) {
|
|
149
|
-
let optionTargets = this.options.targets;
|
|
150
|
-
if (exclusiveTarget != null && optionTargets == null) {
|
|
151
|
-
optionTargets = [exclusiveTarget];
|
|
152
|
-
}
|
|
153
|
-
let packageTargets = await this.resolvePackageTargets(rootDir, exclusiveTarget);
|
|
154
|
-
let targets;
|
|
155
|
-
if (optionTargets) {
|
|
156
|
-
if (Array.isArray(optionTargets)) {
|
|
157
|
-
if (optionTargets.length === 0) {
|
|
158
|
-
throw new (_diagnostic().default)({
|
|
159
|
-
diagnostic: {
|
|
160
|
-
message: `Targets option is an empty array`,
|
|
161
|
-
origin: '@atlaspack/core'
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Only build the intersection of the exclusive target and option targets.
|
|
167
|
-
if (exclusiveTarget != null) {
|
|
168
|
-
optionTargets = optionTargets.filter(target => target === exclusiveTarget);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// If an array of strings is passed, it's a filter on the resolved package
|
|
172
|
-
// targets. Load them, and find the matching targets.
|
|
173
|
-
targets = optionTargets.map(target => {
|
|
174
|
-
// null means skipped.
|
|
175
|
-
if (!packageTargets.has(target)) {
|
|
176
|
-
throw new (_diagnostic().default)({
|
|
177
|
-
diagnostic: {
|
|
178
|
-
message: (0, _diagnostic().md)`Could not find target with name "${target}"`,
|
|
179
|
-
origin: '@atlaspack/core'
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
return packageTargets.get(target);
|
|
184
|
-
}).filter(Boolean);
|
|
185
|
-
} else {
|
|
186
|
-
// Otherwise, it's an object map of target descriptors (similar to those
|
|
187
|
-
// in package.json). Adapt them to native targets.
|
|
188
|
-
targets = Object.entries(optionTargets).map(([name, _descriptor]) => {
|
|
189
|
-
let {
|
|
190
|
-
distDir,
|
|
191
|
-
...descriptor
|
|
192
|
-
} = parseDescriptor(name, _descriptor, null, JSON.stringify({
|
|
193
|
-
targets: optionTargets
|
|
194
|
-
}, null, '\t'));
|
|
195
|
-
if (distDir == null) {
|
|
196
|
-
let optionTargetsString = JSON.stringify(optionTargets, null, '\t');
|
|
197
|
-
throw new (_diagnostic().default)({
|
|
198
|
-
diagnostic: {
|
|
199
|
-
message: (0, _diagnostic().md)`Missing distDir for target "${name}"`,
|
|
200
|
-
origin: '@atlaspack/core',
|
|
201
|
-
codeFrames: [{
|
|
202
|
-
code: optionTargetsString,
|
|
203
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(optionTargetsString || '', [{
|
|
204
|
-
key: `/${name}`,
|
|
205
|
-
type: 'value'
|
|
206
|
-
}])
|
|
207
|
-
}]
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
let target = {
|
|
212
|
-
name,
|
|
213
|
-
distDir: (0, _projectPath.toProjectPath)(this.options.projectRoot, _path().default.resolve(this.fs.cwd(), distDir)),
|
|
214
|
-
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
215
|
-
env: (0, _Environment.createEnvironment)({
|
|
216
|
-
engines: descriptor.engines,
|
|
217
|
-
context: descriptor.context,
|
|
218
|
-
isLibrary: descriptor.isLibrary ?? this.options.defaultTargetOptions.isLibrary,
|
|
219
|
-
includeNodeModules: descriptor.includeNodeModules,
|
|
220
|
-
outputFormat: descriptor.outputFormat ?? this.options.defaultTargetOptions.outputFormat,
|
|
221
|
-
shouldOptimize: this.options.defaultTargetOptions.shouldOptimize && descriptor.optimize !== false,
|
|
222
|
-
shouldScopeHoist: this.options.defaultTargetOptions.shouldScopeHoist && descriptor.scopeHoist !== false,
|
|
223
|
-
sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap),
|
|
224
|
-
unstableSingleFileOutput: descriptor.__unstable_singleFileOutput
|
|
225
|
-
})
|
|
226
|
-
};
|
|
227
|
-
if (descriptor.distEntry != null) {
|
|
228
|
-
target.distEntry = descriptor.distEntry;
|
|
229
|
-
}
|
|
230
|
-
if (descriptor.source != null) {
|
|
231
|
-
target.source = descriptor.source;
|
|
232
|
-
}
|
|
233
|
-
return target;
|
|
234
|
-
}).filter(target => !skipTarget(target.name, exclusiveTarget, target.source));
|
|
235
|
-
}
|
|
236
|
-
let serve = this.options.serveOptions;
|
|
237
|
-
if (serve && targets.length > 0) {
|
|
238
|
-
// In serve mode, we only support a single browser target. If the user
|
|
239
|
-
// provided more than one, or the matching target is not a browser, throw.
|
|
240
|
-
if (targets.length > 1) {
|
|
241
|
-
throw new (_diagnostic().default)({
|
|
242
|
-
diagnostic: {
|
|
243
|
-
message: `More than one target is not supported in serve mode`,
|
|
244
|
-
origin: '@atlaspack/core'
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
if (!_Environment2.BROWSER_ENVS.has(targets[0].env.context)) {
|
|
249
|
-
throw new (_diagnostic().default)({
|
|
250
|
-
diagnostic: {
|
|
251
|
-
message: `Only browser targets are supported in serve mode`,
|
|
252
|
-
origin: '@atlaspack/core'
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
targets[0].distDir = (0, _projectPath.toProjectPath)(this.options.projectRoot, serve.distDir);
|
|
257
|
-
}
|
|
258
|
-
} else {
|
|
259
|
-
// Explicit targets were not provided. Either use a modern target for server
|
|
260
|
-
// mode, or simply use the package.json targets.
|
|
261
|
-
if (this.options.serveOptions) {
|
|
262
|
-
// In serve mode, we only support a single browser target. Since the user
|
|
263
|
-
// hasn't specified a target, use one targeting modern browsers for development
|
|
264
|
-
targets = [{
|
|
265
|
-
name: 'default',
|
|
266
|
-
distDir: (0, _projectPath.toProjectPath)(this.options.projectRoot, this.options.serveOptions.distDir),
|
|
267
|
-
publicUrl: this.options.defaultTargetOptions.publicUrl ?? '/',
|
|
268
|
-
env: (0, _Environment.createEnvironment)({
|
|
269
|
-
context: 'browser',
|
|
270
|
-
engines: {
|
|
271
|
-
browsers: DEFAULT_ENGINES.browsers
|
|
272
|
-
},
|
|
273
|
-
shouldOptimize: this.options.defaultTargetOptions.shouldOptimize,
|
|
274
|
-
outputFormat: this.options.defaultTargetOptions.outputFormat,
|
|
275
|
-
shouldScopeHoist: this.options.defaultTargetOptions.shouldScopeHoist,
|
|
276
|
-
sourceMap: this.options.defaultTargetOptions.sourceMaps ? {} : undefined
|
|
277
|
-
})
|
|
278
|
-
}];
|
|
279
|
-
} else {
|
|
280
|
-
targets = Array.from(packageTargets.values()).filter(Boolean).filter(descriptor => {
|
|
281
|
-
return descriptor && !skipTarget(descriptor.name, exclusiveTarget, descriptor.source);
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return targets;
|
|
286
|
-
}
|
|
287
|
-
async resolvePackageTargets(rootDir, exclusiveTarget) {
|
|
288
|
-
let rootFile = _path().default.join(rootDir, 'index');
|
|
289
|
-
let conf = await (0, _utils().loadConfig)(this.fs, rootFile, ['package.json'], this.options.projectRoot);
|
|
290
|
-
let rootFileProject = (0, _projectPath.toProjectPath)(this.options.projectRoot, rootFile);
|
|
291
|
-
|
|
292
|
-
// Invalidate whenever a package.json file is added.
|
|
293
|
-
this.api.invalidateOnFileCreate({
|
|
294
|
-
fileName: 'package.json',
|
|
295
|
-
aboveFilePath: rootFileProject
|
|
296
|
-
});
|
|
297
|
-
let pkg;
|
|
298
|
-
let pkgContents;
|
|
299
|
-
let pkgFilePath;
|
|
300
|
-
let pkgDir;
|
|
301
|
-
let pkgMap;
|
|
302
|
-
if (conf) {
|
|
303
|
-
pkg = conf.config;
|
|
304
|
-
let pkgFile = conf.files[0];
|
|
305
|
-
if (pkgFile == null) {
|
|
306
|
-
throw new (_diagnostic().default)({
|
|
307
|
-
diagnostic: {
|
|
308
|
-
message: (0, _diagnostic().md)`Expected package.json file in ${rootDir}`,
|
|
309
|
-
origin: '@atlaspack/core'
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
let _pkgFilePath = pkgFilePath = pkgFile.filePath; // For Flow
|
|
314
|
-
pkgDir = _path().default.dirname(_pkgFilePath);
|
|
315
|
-
pkgContents = await this.fs.readFile(_pkgFilePath, 'utf8');
|
|
316
|
-
pkgMap = (0, _jsonSourcemap().parse)(pkgContents, undefined, {
|
|
317
|
-
tabWidth: 1
|
|
318
|
-
});
|
|
319
|
-
let pp = (0, _projectPath.toProjectPath)(this.options.projectRoot, _pkgFilePath);
|
|
320
|
-
this.api.invalidateOnFileUpdate(pp);
|
|
321
|
-
this.api.invalidateOnFileDelete(pp);
|
|
322
|
-
} else {
|
|
323
|
-
pkg = {};
|
|
324
|
-
pkgDir = this.fs.cwd();
|
|
325
|
-
}
|
|
326
|
-
let pkgTargets = pkg.targets || {};
|
|
327
|
-
let pkgEngines = parseEngines(pkg.engines, pkgFilePath, pkgContents, '/engines', 'Invalid engines in package.json') || {};
|
|
328
|
-
let browsersLoc = {
|
|
329
|
-
path: '/engines/browsers'
|
|
330
|
-
};
|
|
331
|
-
let nodeLoc = {
|
|
332
|
-
path: '/engines/node'
|
|
333
|
-
};
|
|
334
|
-
if (pkgEngines.browsers == null) {
|
|
335
|
-
let env = this.options.env.BROWSERSLIST_ENV ?? this.options.env.NODE_ENV ?? this.options.mode;
|
|
336
|
-
if (pkg.browserslist != null) {
|
|
337
|
-
let pkgBrowserslist = pkg.browserslist;
|
|
338
|
-
let browserslist = typeof pkgBrowserslist === 'object' && !Array.isArray(pkgBrowserslist) ? pkgBrowserslist[env] : pkgBrowserslist;
|
|
339
|
-
pkgEngines = {
|
|
340
|
-
...pkgEngines,
|
|
341
|
-
browsers: browserslist
|
|
342
|
-
};
|
|
343
|
-
browsersLoc = {
|
|
344
|
-
path: '/browserslist'
|
|
345
|
-
};
|
|
346
|
-
} else {
|
|
347
|
-
let browserslistConfig = await (0, _utils().resolveConfig)(this.fs, _path().default.join(rootDir, 'index'), ['browserslist', '.browserslistrc'], this.options.projectRoot);
|
|
348
|
-
this.api.invalidateOnFileCreate({
|
|
349
|
-
fileName: 'browserslist',
|
|
350
|
-
aboveFilePath: rootFileProject
|
|
351
|
-
});
|
|
352
|
-
this.api.invalidateOnFileCreate({
|
|
353
|
-
fileName: '.browserslistrc',
|
|
354
|
-
aboveFilePath: rootFileProject
|
|
355
|
-
});
|
|
356
|
-
if (browserslistConfig != null) {
|
|
357
|
-
let contents = await this.fs.readFile(browserslistConfig, 'utf8');
|
|
358
|
-
let config = _browserslist().default.parseConfig(contents);
|
|
359
|
-
let browserslistBrowsers = config[env] || config.defaults;
|
|
360
|
-
let pp = (0, _projectPath.toProjectPath)(this.options.projectRoot, browserslistConfig);
|
|
361
|
-
if ((browserslistBrowsers === null || browserslistBrowsers === void 0 ? void 0 : browserslistBrowsers.length) > 0) {
|
|
362
|
-
pkgEngines = {
|
|
363
|
-
...pkgEngines,
|
|
364
|
-
browsers: browserslistBrowsers
|
|
365
|
-
};
|
|
366
|
-
browsersLoc = {
|
|
367
|
-
message: `(defined in ${_path().default.relative(process.cwd(), browserslistConfig)})`
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// Invalidate whenever browserslist config file or relevant environment variables change
|
|
372
|
-
this.api.invalidateOnFileUpdate(pp);
|
|
373
|
-
this.api.invalidateOnFileDelete(pp);
|
|
374
|
-
this.api.invalidateOnEnvChange('BROWSERSLIST_ENV');
|
|
375
|
-
this.api.invalidateOnEnvChange('NODE_ENV');
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
let targets = new Map();
|
|
380
|
-
let node = pkgEngines.node;
|
|
381
|
-
let browsers = pkgEngines.browsers;
|
|
382
|
-
let defaultEngines = this.options.defaultTargetOptions.engines;
|
|
383
|
-
let context = browsers ?? node == null ? 'browser' : 'node';
|
|
384
|
-
if (context === 'browser' && pkgEngines.browsers == null) {
|
|
385
|
-
pkgEngines = {
|
|
386
|
-
...pkgEngines,
|
|
387
|
-
browsers: (defaultEngines === null || defaultEngines === void 0 ? void 0 : defaultEngines.browsers) ?? DEFAULT_ENGINES.browsers
|
|
388
|
-
};
|
|
389
|
-
browsersLoc = {
|
|
390
|
-
message: '(default)'
|
|
391
|
-
};
|
|
392
|
-
} else if (context === 'node' && pkgEngines.node == null) {
|
|
393
|
-
pkgEngines = {
|
|
394
|
-
...pkgEngines,
|
|
395
|
-
node: (defaultEngines === null || defaultEngines === void 0 ? void 0 : defaultEngines.node) ?? DEFAULT_ENGINES.node
|
|
396
|
-
};
|
|
397
|
-
nodeLoc = {
|
|
398
|
-
message: '(default)'
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// If there is a separate `browser` target, or an `engines.node` field but no browser targets, then
|
|
403
|
-
// the `main` and `module` targets refer to node, otherwise browser.
|
|
404
|
-
let mainContext = pkg.browser ?? pkgTargets.browser ?? (node != null && browsers == null) ? 'node' : 'browser';
|
|
405
|
-
let mainContextLoc = pkg.browser != null ? {
|
|
406
|
-
inferred: '/browser',
|
|
407
|
-
message: '(because a browser field also exists)',
|
|
408
|
-
type: 'key'
|
|
409
|
-
} : pkgTargets.browser ? {
|
|
410
|
-
inferred: '/targets/browser',
|
|
411
|
-
message: '(because a browser target also exists)',
|
|
412
|
-
type: 'key'
|
|
413
|
-
} : node != null && browsers == null ? nodeLoc.path ? {
|
|
414
|
-
inferred: nodeLoc.path,
|
|
415
|
-
message: '(because node engines were defined)',
|
|
416
|
-
type: 'key'
|
|
417
|
-
} : nodeLoc : {
|
|
418
|
-
message: '(default)'
|
|
419
|
-
};
|
|
420
|
-
let moduleContext = pkg.browser ?? pkgTargets.browser ? 'browser' : mainContext;
|
|
421
|
-
let moduleContextLoc = pkg.browser != null ? {
|
|
422
|
-
inferred: '/browser',
|
|
423
|
-
message: '(because a browser field also exists)',
|
|
424
|
-
type: 'key'
|
|
425
|
-
} : pkgTargets.browser ? {
|
|
426
|
-
inferred: '/targets/browser',
|
|
427
|
-
message: '(becausea browser target also exists)',
|
|
428
|
-
type: 'key'
|
|
429
|
-
} : mainContextLoc;
|
|
430
|
-
let getEnginesLoc = (targetName, descriptor) => {
|
|
431
|
-
let enginesLoc = `/targets/${targetName}/engines`;
|
|
432
|
-
switch (context) {
|
|
433
|
-
case 'browser':
|
|
434
|
-
case 'web-worker':
|
|
435
|
-
case 'service-worker':
|
|
436
|
-
case 'worklet':
|
|
437
|
-
{
|
|
438
|
-
if (descriptor.engines) {
|
|
439
|
-
return {
|
|
440
|
-
path: enginesLoc + '/browsers'
|
|
441
|
-
};
|
|
442
|
-
} else {
|
|
443
|
-
return browsersLoc;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
case 'node':
|
|
447
|
-
{
|
|
448
|
-
if (descriptor.engines) {
|
|
449
|
-
return {
|
|
450
|
-
path: enginesLoc + '/node'
|
|
451
|
-
};
|
|
452
|
-
} else {
|
|
453
|
-
return nodeLoc;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
case 'electron-main':
|
|
457
|
-
case 'electron-renderer':
|
|
458
|
-
{
|
|
459
|
-
var _descriptor$engines, _pkgEngines;
|
|
460
|
-
if (((_descriptor$engines = descriptor.engines) === null || _descriptor$engines === void 0 ? void 0 : _descriptor$engines.electron) != null) {
|
|
461
|
-
return {
|
|
462
|
-
path: enginesLoc + '/electron'
|
|
463
|
-
};
|
|
464
|
-
} else if (((_pkgEngines = pkgEngines) === null || _pkgEngines === void 0 ? void 0 : _pkgEngines.electron) != null) {
|
|
465
|
-
return {
|
|
466
|
-
path: '/engines/electron'
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return {
|
|
472
|
-
message: '(default)'
|
|
473
|
-
};
|
|
474
|
-
};
|
|
475
|
-
for (let targetName in COMMON_TARGETS) {
|
|
476
|
-
let _targetDist;
|
|
477
|
-
let pointer;
|
|
478
|
-
if (targetName === 'browser' && pkg[targetName] != null && typeof pkg[targetName] === 'object' && pkg.name) {
|
|
479
|
-
// The `browser` field can be a file path or an alias map.
|
|
480
|
-
_targetDist = pkg[targetName][pkg.name];
|
|
481
|
-
pointer = `/${targetName}/${(0, _diagnostic().encodeJSONKeyComponent)(pkg.name)}`;
|
|
482
|
-
} else {
|
|
483
|
-
_targetDist = pkg[targetName];
|
|
484
|
-
pointer = `/${targetName}`;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// For Flow
|
|
488
|
-
let targetDist = _targetDist;
|
|
489
|
-
if (typeof targetDist === 'string' || pkgTargets[targetName]) {
|
|
490
|
-
let distDir;
|
|
491
|
-
let distEntry;
|
|
492
|
-
let loc;
|
|
493
|
-
(0, _assert().default)(pkgMap != null);
|
|
494
|
-
let _descriptor = pkgTargets[targetName] ?? {};
|
|
495
|
-
if (typeof targetDist === 'string') {
|
|
496
|
-
distDir = (0, _projectPath.toProjectPath)(this.options.projectRoot, _path().default.resolve(pkgDir, _path().default.dirname(targetDist)));
|
|
497
|
-
distEntry = _path().default.basename(targetDist);
|
|
498
|
-
loc = {
|
|
499
|
-
filePath: (0, _nullthrows().default)(pkgFilePath),
|
|
500
|
-
...(0, _diagnostic().getJSONSourceLocation)(pkgMap.pointers[pointer], 'value')
|
|
501
|
-
};
|
|
502
|
-
} else {
|
|
503
|
-
distDir = this.options.defaultTargetOptions.distDir ?? (0, _projectPath.toProjectPath)(this.options.projectRoot, _path().default.join(pkgDir, DEFAULT_DIST_DIRNAME, targetName));
|
|
504
|
-
}
|
|
505
|
-
if (_descriptor == false) {
|
|
506
|
-
continue;
|
|
507
|
-
}
|
|
508
|
-
let descriptor = parseCommonTargetDescriptor(targetName, _descriptor, pkgFilePath, pkgContents);
|
|
509
|
-
if (skipTarget(targetName, exclusiveTarget, descriptor.source)) {
|
|
510
|
-
targets.set(targetName, null);
|
|
511
|
-
continue;
|
|
512
|
-
}
|
|
513
|
-
if (distEntry != null && !COMMON_TARGETS[targetName].match.test(distEntry)) {
|
|
514
|
-
let contents = typeof pkgContents === 'string' ? pkgContents :
|
|
515
|
-
// $FlowFixMe
|
|
516
|
-
JSON.stringify(pkgContents, null, '\t');
|
|
517
|
-
// $FlowFixMe
|
|
518
|
-
let listFormat = new Intl.ListFormat('en-US', {
|
|
519
|
-
type: 'disjunction'
|
|
520
|
-
});
|
|
521
|
-
let extensions = listFormat.format(COMMON_TARGETS[targetName].extensions);
|
|
522
|
-
let ext = _path().default.extname(distEntry);
|
|
523
|
-
throw new (_diagnostic().default)({
|
|
524
|
-
diagnostic: {
|
|
525
|
-
message: (0, _diagnostic().md)`Unexpected output file type ${ext} in target "${targetName}"`,
|
|
526
|
-
origin: '@atlaspack/core',
|
|
527
|
-
codeFrames: [{
|
|
528
|
-
language: 'json',
|
|
529
|
-
filePath: pkgFilePath ?? undefined,
|
|
530
|
-
code: contents,
|
|
531
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
532
|
-
key: pointer,
|
|
533
|
-
type: 'value',
|
|
534
|
-
message: `File extension must be ${extensions}`
|
|
535
|
-
}])
|
|
536
|
-
}],
|
|
537
|
-
hints: [`The "${targetName}" field is meant for libraries. If you meant to output a ${ext} file, either remove the "${targetName}" field or choose a different target name.`],
|
|
538
|
-
documentationURL: 'https://parceljs.org/features/targets/#library-targets'
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
if (descriptor.outputFormat === 'global') {
|
|
543
|
-
let contents = typeof pkgContents === 'string' ? pkgContents :
|
|
544
|
-
// $FlowFixMe
|
|
545
|
-
JSON.stringify(pkgContents, null, '\t');
|
|
546
|
-
throw new (_diagnostic().default)({
|
|
547
|
-
diagnostic: {
|
|
548
|
-
message: (0, _diagnostic().md)`The "global" output format is not supported in the "${targetName}" target.`,
|
|
549
|
-
origin: '@atlaspack/core',
|
|
550
|
-
codeFrames: [{
|
|
551
|
-
language: 'json',
|
|
552
|
-
filePath: pkgFilePath ?? undefined,
|
|
553
|
-
code: contents,
|
|
554
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
555
|
-
key: `/targets/${targetName}/outputFormat`,
|
|
556
|
-
type: 'value'
|
|
557
|
-
}])
|
|
558
|
-
}],
|
|
559
|
-
hints: [`The "${targetName}" field is meant for libraries. The outputFormat must be either "commonjs" or "esmodule". Either change or remove the declared outputFormat.`],
|
|
560
|
-
documentationURL: 'https://parceljs.org/features/targets/#library-targets'
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
let [inferredOutputFormat, inferredOutputFormatField] = this.inferOutputFormat(distEntry, descriptor, targetName, pkg, pkgFilePath, pkgContents);
|
|
565
|
-
let outputFormat = descriptor.outputFormat ?? this.options.defaultTargetOptions.outputFormat ?? inferredOutputFormat ?? (targetName === 'module' ? 'esmodule' : 'commonjs');
|
|
566
|
-
let isModule = outputFormat === 'esmodule';
|
|
567
|
-
if (targetName === 'main' && outputFormat === 'esmodule' && inferredOutputFormat !== 'esmodule') {
|
|
568
|
-
let contents = typeof pkgContents === 'string' ? pkgContents :
|
|
569
|
-
// $FlowFixMe
|
|
570
|
-
JSON.stringify(pkgContents, null, '\t');
|
|
571
|
-
throw new (_diagnostic().default)({
|
|
572
|
-
diagnostic: {
|
|
573
|
-
// prettier-ignore
|
|
574
|
-
message: (0, _diagnostic().md)`Output format "esmodule" cannot be used in the "main" target without a .mjs extension or "type": "module" field.`,
|
|
575
|
-
origin: '@atlaspack/core',
|
|
576
|
-
codeFrames: [{
|
|
577
|
-
language: 'json',
|
|
578
|
-
filePath: pkgFilePath ?? undefined,
|
|
579
|
-
code: contents,
|
|
580
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
581
|
-
key: `/targets/${targetName}/outputFormat`,
|
|
582
|
-
type: 'value',
|
|
583
|
-
message: 'Declared output format defined here'
|
|
584
|
-
}, {
|
|
585
|
-
key: '/main',
|
|
586
|
-
type: 'value',
|
|
587
|
-
message: 'Inferred output format defined here'
|
|
588
|
-
}])
|
|
589
|
-
}],
|
|
590
|
-
hints: [`Either change the output file extension to .mjs, add "type": "module" to package.json, or remove the declared outputFormat.`],
|
|
591
|
-
documentationURL: 'https://parceljs.org/features/targets/#library-targets'
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
if (descriptor.scopeHoist === false) {
|
|
596
|
-
let contents = typeof pkgContents === 'string' ? pkgContents :
|
|
597
|
-
// $FlowFixMe
|
|
598
|
-
JSON.stringify(pkgContents, null, '\t');
|
|
599
|
-
throw new (_diagnostic().default)({
|
|
600
|
-
diagnostic: {
|
|
601
|
-
message: 'Scope hoisting cannot be disabled for library targets.',
|
|
602
|
-
origin: '@atlaspack/core',
|
|
603
|
-
codeFrames: [{
|
|
604
|
-
language: 'json',
|
|
605
|
-
filePath: pkgFilePath ?? undefined,
|
|
606
|
-
code: contents,
|
|
607
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
608
|
-
key: `/targets/${targetName}/scopeHoist`,
|
|
609
|
-
type: 'value'
|
|
610
|
-
}])
|
|
611
|
-
}],
|
|
612
|
-
hints: [`The "${targetName}" target is meant for libraries. Either remove the "scopeHoist" option, or use a different target name.`],
|
|
613
|
-
documentationURL: 'https://parceljs.org/features/targets/#library-targets'
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
let context = descriptor.context ?? (targetName === 'browser' ? 'browser' : isModule ? moduleContext : mainContext);
|
|
618
|
-
targets.set(targetName, {
|
|
619
|
-
name: targetName,
|
|
620
|
-
distDir,
|
|
621
|
-
distEntry,
|
|
622
|
-
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
623
|
-
env: (0, _Environment.createEnvironment)({
|
|
624
|
-
engines: descriptor.engines ?? pkgEngines,
|
|
625
|
-
context,
|
|
626
|
-
includeNodeModules: descriptor.includeNodeModules ?? false,
|
|
627
|
-
outputFormat,
|
|
628
|
-
isLibrary: true,
|
|
629
|
-
shouldOptimize: this.options.defaultTargetOptions.shouldOptimize && descriptor.optimize === true,
|
|
630
|
-
shouldScopeHoist: true,
|
|
631
|
-
sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap)
|
|
632
|
-
}),
|
|
633
|
-
loc: (0, _utils2.toInternalSourceLocation)(this.options.projectRoot, loc)
|
|
634
|
-
});
|
|
635
|
-
this.targetInfo.set(targetName, {
|
|
636
|
-
output: {
|
|
637
|
-
path: pointer
|
|
638
|
-
},
|
|
639
|
-
engines: getEnginesLoc(targetName, descriptor),
|
|
640
|
-
context: descriptor.context ? {
|
|
641
|
-
path: `/targets/${targetName}/context`
|
|
642
|
-
} : targetName === 'browser' ? {
|
|
643
|
-
message: '(inferred from target name)',
|
|
644
|
-
inferred: pointer,
|
|
645
|
-
type: 'key'
|
|
646
|
-
} : isModule ? moduleContextLoc : mainContextLoc,
|
|
647
|
-
includeNodeModules: descriptor.includeNodeModules ? {
|
|
648
|
-
path: `/targets/${targetName}/includeNodeModules`,
|
|
649
|
-
type: 'key'
|
|
650
|
-
} : {
|
|
651
|
-
message: '(default)'
|
|
652
|
-
},
|
|
653
|
-
outputFormat: descriptor.outputFormat ? {
|
|
654
|
-
path: `/targets/${targetName}/outputFormat`
|
|
655
|
-
} : inferredOutputFormatField === '/type' ? {
|
|
656
|
-
message: `(inferred from package.json#type)`,
|
|
657
|
-
inferred: inferredOutputFormatField
|
|
658
|
-
} : inferredOutputFormatField != null ? {
|
|
659
|
-
message: `(inferred from file extension)`,
|
|
660
|
-
inferred: inferredOutputFormatField
|
|
661
|
-
} : {
|
|
662
|
-
message: '(default)'
|
|
663
|
-
},
|
|
664
|
-
isLibrary: {
|
|
665
|
-
message: '(default)'
|
|
666
|
-
},
|
|
667
|
-
shouldOptimize: descriptor.optimize ? {
|
|
668
|
-
path: `/targets/${targetName}/optimize`
|
|
669
|
-
} : {
|
|
670
|
-
message: '(default)'
|
|
671
|
-
},
|
|
672
|
-
shouldScopeHoist: {
|
|
673
|
-
message: '(default)'
|
|
674
|
-
}
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
let customTargets = Object.keys(pkgTargets).filter(targetName => !COMMON_TARGETS[targetName]);
|
|
679
|
-
|
|
680
|
-
// Custom targets
|
|
681
|
-
for (let targetName of customTargets) {
|
|
682
|
-
let distPath = pkg[targetName];
|
|
683
|
-
let distDir;
|
|
684
|
-
let distEntry;
|
|
685
|
-
let loc;
|
|
686
|
-
let pointer;
|
|
687
|
-
if (distPath == null) {
|
|
688
|
-
distDir = (0, _projectPath.fromProjectPath)(this.options.projectRoot, this.options.defaultTargetOptions.distDir) ?? _path().default.join(pkgDir, DEFAULT_DIST_DIRNAME);
|
|
689
|
-
if (customTargets.length >= 2) {
|
|
690
|
-
distDir = _path().default.join(distDir, targetName);
|
|
691
|
-
}
|
|
692
|
-
(0, _assert().default)(pkgMap != null);
|
|
693
|
-
(0, _assert().default)(typeof pkgFilePath === 'string');
|
|
694
|
-
loc = {
|
|
695
|
-
filePath: pkgFilePath,
|
|
696
|
-
...(0, _diagnostic().getJSONSourceLocation)(pkgMap.pointers[`/targets/${targetName}`], 'key')
|
|
697
|
-
};
|
|
698
|
-
} else {
|
|
699
|
-
if (typeof distPath !== 'string') {
|
|
700
|
-
let contents = typeof pkgContents === 'string' ? pkgContents :
|
|
701
|
-
// $FlowFixMe
|
|
702
|
-
JSON.stringify(pkgContents, null, '\t');
|
|
703
|
-
throw new (_diagnostic().default)({
|
|
704
|
-
diagnostic: {
|
|
705
|
-
message: (0, _diagnostic().md)`Invalid distPath for target "${targetName}"`,
|
|
706
|
-
origin: '@atlaspack/core',
|
|
707
|
-
codeFrames: [{
|
|
708
|
-
language: 'json',
|
|
709
|
-
filePath: pkgFilePath ?? undefined,
|
|
710
|
-
code: contents,
|
|
711
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
712
|
-
key: `/${targetName}`,
|
|
713
|
-
type: 'value',
|
|
714
|
-
message: 'Expected type string'
|
|
715
|
-
}])
|
|
716
|
-
}]
|
|
717
|
-
}
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
distDir = _path().default.resolve(pkgDir, _path().default.dirname(distPath));
|
|
721
|
-
distEntry = _path().default.basename(distPath);
|
|
722
|
-
(0, _assert().default)(typeof pkgFilePath === 'string');
|
|
723
|
-
(0, _assert().default)(pkgMap != null);
|
|
724
|
-
loc = {
|
|
725
|
-
filePath: pkgFilePath,
|
|
726
|
-
...(0, _diagnostic().getJSONSourceLocation)(pkgMap.pointers[`/${targetName}`], 'value')
|
|
727
|
-
};
|
|
728
|
-
pointer = `/${targetName}`;
|
|
729
|
-
}
|
|
730
|
-
if (targetName in pkgTargets) {
|
|
731
|
-
let descriptor = parsePackageDescriptor(targetName, pkgTargets[targetName], pkgFilePath, pkgContents);
|
|
732
|
-
let pkgDir = _path().default.dirname((0, _nullthrows().default)(pkgFilePath));
|
|
733
|
-
if (skipTarget(targetName, exclusiveTarget, descriptor.source)) {
|
|
734
|
-
targets.set(targetName, null);
|
|
735
|
-
continue;
|
|
736
|
-
}
|
|
737
|
-
let [inferredOutputFormat, inferredOutputFormatField] = this.inferOutputFormat(distEntry, descriptor, targetName, pkg, pkgFilePath, pkgContents);
|
|
738
|
-
if (descriptor.scopeHoist === false && descriptor.isLibrary) {
|
|
739
|
-
let contents = typeof pkgContents === 'string' ? pkgContents :
|
|
740
|
-
// $FlowFixMe
|
|
741
|
-
JSON.stringify(pkgContents, null, '\t');
|
|
742
|
-
throw new (_diagnostic().default)({
|
|
743
|
-
diagnostic: {
|
|
744
|
-
message: 'Scope hoisting cannot be disabled for library targets.',
|
|
745
|
-
origin: '@atlaspack/core',
|
|
746
|
-
codeFrames: [{
|
|
747
|
-
language: 'json',
|
|
748
|
-
filePath: pkgFilePath ?? undefined,
|
|
749
|
-
code: contents,
|
|
750
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
751
|
-
key: `/targets/${targetName}/scopeHoist`,
|
|
752
|
-
type: 'value'
|
|
753
|
-
}, {
|
|
754
|
-
key: `/targets/${targetName}/isLibrary`,
|
|
755
|
-
type: 'value'
|
|
756
|
-
}])
|
|
757
|
-
}],
|
|
758
|
-
hints: [`Either remove the "scopeHoist" or "isLibrary" option.`],
|
|
759
|
-
documentationURL: 'https://parceljs.org/features/targets/#library-targets'
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
let isLibrary = descriptor.isLibrary ?? this.options.defaultTargetOptions.isLibrary ?? false;
|
|
764
|
-
let shouldScopeHoist = isLibrary ? true : this.options.defaultTargetOptions.shouldScopeHoist;
|
|
765
|
-
targets.set(targetName, {
|
|
766
|
-
name: targetName,
|
|
767
|
-
distDir: (0, _projectPath.toProjectPath)(this.options.projectRoot, descriptor.distDir != null ? _path().default.resolve(pkgDir, descriptor.distDir) : distDir),
|
|
768
|
-
distEntry,
|
|
769
|
-
publicUrl: descriptor.publicUrl ?? this.options.defaultTargetOptions.publicUrl,
|
|
770
|
-
env: (0, _Environment.createEnvironment)({
|
|
771
|
-
engines: descriptor.engines ?? pkgEngines,
|
|
772
|
-
context: descriptor.context,
|
|
773
|
-
includeNodeModules: descriptor.includeNodeModules,
|
|
774
|
-
unstableSingleFileOutput: descriptor.__unstable_singleFileOutput,
|
|
775
|
-
outputFormat: descriptor.outputFormat ?? this.options.defaultTargetOptions.outputFormat ?? inferredOutputFormat ?? undefined,
|
|
776
|
-
isLibrary,
|
|
777
|
-
shouldOptimize: this.options.defaultTargetOptions.shouldOptimize && (
|
|
778
|
-
// Libraries are not optimized by default, users must explicitly configure this.
|
|
779
|
-
isLibrary ? descriptor.optimize === true : descriptor.optimize !== false),
|
|
780
|
-
shouldScopeHoist: shouldScopeHoist && descriptor.scopeHoist !== false,
|
|
781
|
-
sourceMap: normalizeSourceMap(this.options, descriptor.sourceMap)
|
|
782
|
-
}),
|
|
783
|
-
loc: (0, _utils2.toInternalSourceLocation)(this.options.projectRoot, loc)
|
|
784
|
-
});
|
|
785
|
-
this.targetInfo.set(targetName, {
|
|
786
|
-
output: pointer != null ? {
|
|
787
|
-
path: pointer
|
|
788
|
-
} : {
|
|
789
|
-
message: '(default)'
|
|
790
|
-
},
|
|
791
|
-
engines: getEnginesLoc(targetName, descriptor),
|
|
792
|
-
context: descriptor.context ? {
|
|
793
|
-
path: `/targets/${targetName}/context`
|
|
794
|
-
} : {
|
|
795
|
-
message: '(default)'
|
|
796
|
-
},
|
|
797
|
-
includeNodeModules: descriptor.includeNodeModules ? {
|
|
798
|
-
path: `/targets/${targetName}/includeNodeModules`,
|
|
799
|
-
type: 'key'
|
|
800
|
-
} : {
|
|
801
|
-
message: '(default)'
|
|
802
|
-
},
|
|
803
|
-
outputFormat: descriptor.outputFormat ? {
|
|
804
|
-
path: `/targets/${targetName}/outputFormat`
|
|
805
|
-
} : inferredOutputFormatField === '/type' ? {
|
|
806
|
-
message: `(inferred from package.json#type)`,
|
|
807
|
-
inferred: inferredOutputFormatField
|
|
808
|
-
} : inferredOutputFormatField != null ? {
|
|
809
|
-
message: `(inferred from file extension)`,
|
|
810
|
-
inferred: inferredOutputFormatField
|
|
811
|
-
} : {
|
|
812
|
-
message: '(default)'
|
|
813
|
-
},
|
|
814
|
-
isLibrary: descriptor.isLibrary != null ? {
|
|
815
|
-
path: `/targets/${targetName}/isLibrary`
|
|
816
|
-
} : {
|
|
817
|
-
message: '(default)'
|
|
818
|
-
},
|
|
819
|
-
shouldOptimize: descriptor.optimize != null ? {
|
|
820
|
-
path: `/targets/${targetName}/optimize`
|
|
821
|
-
} : {
|
|
822
|
-
message: '(default)'
|
|
823
|
-
},
|
|
824
|
-
shouldScopeHoist: descriptor.scopeHoist != null ? {
|
|
825
|
-
path: `/targets/${targetName}/scopeHoist`
|
|
826
|
-
} : {
|
|
827
|
-
message: '(default)'
|
|
828
|
-
}
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// If no explicit targets were defined, add a default.
|
|
834
|
-
if (targets.size === 0) {
|
|
835
|
-
targets.set('default', {
|
|
836
|
-
name: 'default',
|
|
837
|
-
distDir: this.options.defaultTargetOptions.distDir ?? (0, _projectPath.toProjectPath)(this.options.projectRoot, _path().default.join(pkgDir, DEFAULT_DIST_DIRNAME)),
|
|
838
|
-
publicUrl: this.options.defaultTargetOptions.publicUrl,
|
|
839
|
-
env: (0, _Environment.createEnvironment)({
|
|
840
|
-
engines: pkgEngines,
|
|
841
|
-
context,
|
|
842
|
-
outputFormat: this.options.defaultTargetOptions.outputFormat,
|
|
843
|
-
isLibrary: this.options.defaultTargetOptions.isLibrary,
|
|
844
|
-
shouldOptimize: this.options.defaultTargetOptions.shouldOptimize,
|
|
845
|
-
shouldScopeHoist: this.options.defaultTargetOptions.shouldScopeHoist ?? (this.options.mode === 'production' && !this.options.defaultTargetOptions.isLibrary),
|
|
846
|
-
sourceMap: this.options.defaultTargetOptions.sourceMaps ? {} : undefined
|
|
847
|
-
})
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
assertNoDuplicateTargets(this.options, targets, pkgFilePath, pkgContents);
|
|
851
|
-
return targets;
|
|
852
|
-
}
|
|
853
|
-
inferOutputFormat(distEntry, descriptor, targetName, pkg, pkgFilePath, pkgContents) {
|
|
854
|
-
// Infer the outputFormat based on package.json properties.
|
|
855
|
-
// If the extension is .mjs it's always a module.
|
|
856
|
-
// If the extension is .cjs, it's always commonjs.
|
|
857
|
-
// If the "type" field is set to "module" and the extension is .js, it's a module.
|
|
858
|
-
let ext = distEntry != null ? _path().default.extname(distEntry) : null;
|
|
859
|
-
let inferredOutputFormat, inferredOutputFormatField;
|
|
860
|
-
switch (ext) {
|
|
861
|
-
case '.mjs':
|
|
862
|
-
inferredOutputFormat = 'esmodule';
|
|
863
|
-
inferredOutputFormatField = `/${targetName}`;
|
|
864
|
-
break;
|
|
865
|
-
case '.cjs':
|
|
866
|
-
inferredOutputFormat = 'commonjs';
|
|
867
|
-
inferredOutputFormatField = `/${targetName}`;
|
|
868
|
-
break;
|
|
869
|
-
case '.js':
|
|
870
|
-
if (pkg.type === 'module') {
|
|
871
|
-
inferredOutputFormat = 'esmodule';
|
|
872
|
-
inferredOutputFormatField = '/type';
|
|
873
|
-
}
|
|
874
|
-
break;
|
|
875
|
-
}
|
|
876
|
-
if (descriptor.outputFormat && inferredOutputFormat && descriptor.outputFormat !== inferredOutputFormat) {
|
|
877
|
-
let contents = typeof pkgContents === 'string' ? pkgContents :
|
|
878
|
-
// $FlowFixMe
|
|
879
|
-
JSON.stringify(pkgContents, null, '\t');
|
|
880
|
-
let expectedExtensions;
|
|
881
|
-
switch (descriptor.outputFormat) {
|
|
882
|
-
case 'esmodule':
|
|
883
|
-
expectedExtensions = ['.mjs', '.js'];
|
|
884
|
-
break;
|
|
885
|
-
case 'commonjs':
|
|
886
|
-
expectedExtensions = ['.cjs', '.js'];
|
|
887
|
-
break;
|
|
888
|
-
case 'global':
|
|
889
|
-
expectedExtensions = ['.js'];
|
|
890
|
-
break;
|
|
891
|
-
}
|
|
892
|
-
// $FlowFixMe
|
|
893
|
-
let listFormat = new Intl.ListFormat('en-US', {
|
|
894
|
-
type: 'disjunction'
|
|
895
|
-
});
|
|
896
|
-
throw new (_diagnostic().default)({
|
|
897
|
-
diagnostic: {
|
|
898
|
-
message: (0, _diagnostic().md)`Declared output format "${descriptor.outputFormat}" does not match expected output format "${inferredOutputFormat}".`,
|
|
899
|
-
origin: '@atlaspack/core',
|
|
900
|
-
codeFrames: [{
|
|
901
|
-
language: 'json',
|
|
902
|
-
filePath: pkgFilePath ?? undefined,
|
|
903
|
-
code: contents,
|
|
904
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(contents, [{
|
|
905
|
-
key: `/targets/${targetName}/outputFormat`,
|
|
906
|
-
type: 'value',
|
|
907
|
-
message: 'Declared output format defined here'
|
|
908
|
-
}, {
|
|
909
|
-
key: (0, _nullthrows().default)(inferredOutputFormatField),
|
|
910
|
-
type: 'value',
|
|
911
|
-
message: 'Inferred output format defined here'
|
|
912
|
-
}])
|
|
913
|
-
}],
|
|
914
|
-
hints: [inferredOutputFormatField === '/type' ? 'Either remove the target\'s declared "outputFormat" or remove the "type" field.' : `Either remove the target's declared "outputFormat" or change the extension to ${listFormat.format(expectedExtensions)}.`],
|
|
915
|
-
documentationURL: 'https://parceljs.org/features/targets/#library-targets'
|
|
916
|
-
}
|
|
917
|
-
});
|
|
918
|
-
}
|
|
919
|
-
return [inferredOutputFormat, inferredOutputFormatField];
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
exports.TargetResolver = TargetResolver;
|
|
923
|
-
function parseEngines(engines, pkgPath, pkgContents, prependKey, message) {
|
|
924
|
-
if (engines === undefined) {
|
|
925
|
-
return engines;
|
|
926
|
-
} else {
|
|
927
|
-
_utils().validateSchema.diagnostic(_TargetDescriptor.ENGINES_SCHEMA, {
|
|
928
|
-
data: engines,
|
|
929
|
-
source: pkgContents,
|
|
930
|
-
filePath: pkgPath,
|
|
931
|
-
prependKey
|
|
932
|
-
}, '@atlaspack/core', message);
|
|
933
|
-
// $FlowFixMe we just verified this
|
|
934
|
-
return engines;
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
function parseDescriptor(targetName, descriptor, pkgPath, pkgContents) {
|
|
938
|
-
_utils().validateSchema.diagnostic(_TargetDescriptor.DESCRIPTOR_SCHEMA, {
|
|
939
|
-
data: descriptor,
|
|
940
|
-
source: pkgContents,
|
|
941
|
-
filePath: pkgPath,
|
|
942
|
-
prependKey: `/targets/${targetName}`
|
|
943
|
-
}, '@atlaspack/core', `Invalid target descriptor for target "${targetName}"`);
|
|
944
|
-
|
|
945
|
-
// $FlowFixMe we just verified this
|
|
946
|
-
return descriptor;
|
|
947
|
-
}
|
|
948
|
-
function parsePackageDescriptor(targetName, descriptor, pkgPath, pkgContents) {
|
|
949
|
-
_utils().validateSchema.diagnostic(_TargetDescriptor.PACKAGE_DESCRIPTOR_SCHEMA, {
|
|
950
|
-
data: descriptor,
|
|
951
|
-
source: pkgContents,
|
|
952
|
-
filePath: pkgPath,
|
|
953
|
-
prependKey: `/targets/${targetName}`
|
|
954
|
-
}, '@atlaspack/core', `Invalid target descriptor for target "${targetName}"`);
|
|
955
|
-
// $FlowFixMe we just verified this
|
|
956
|
-
return descriptor;
|
|
957
|
-
}
|
|
958
|
-
function parseCommonTargetDescriptor(targetName, descriptor, pkgPath, pkgContents) {
|
|
959
|
-
_utils().validateSchema.diagnostic(_TargetDescriptor.COMMON_TARGET_DESCRIPTOR_SCHEMA, {
|
|
960
|
-
data: descriptor,
|
|
961
|
-
source: pkgContents,
|
|
962
|
-
filePath: pkgPath,
|
|
963
|
-
prependKey: `/targets/${targetName}`
|
|
964
|
-
}, '@atlaspack/core', `Invalid target descriptor for target "${targetName}"`);
|
|
965
|
-
|
|
966
|
-
// $FlowFixMe we just verified this
|
|
967
|
-
return descriptor;
|
|
968
|
-
}
|
|
969
|
-
function assertNoDuplicateTargets(options, targets, pkgFilePath, pkgContents) {
|
|
970
|
-
// Detect duplicate targets by destination path and provide a nice error.
|
|
971
|
-
// Without this, an assertion is thrown much later after naming the bundles and finding duplicates.
|
|
972
|
-
let targetsByPath = new Map();
|
|
973
|
-
for (let target of targets.values()) {
|
|
974
|
-
if (!target) {
|
|
975
|
-
continue;
|
|
976
|
-
}
|
|
977
|
-
let {
|
|
978
|
-
distEntry
|
|
979
|
-
} = target;
|
|
980
|
-
if (distEntry != null) {
|
|
981
|
-
var _targetsByPath$get;
|
|
982
|
-
let distPath = _path().default.join((0, _projectPath.fromProjectPath)(options.projectRoot, target.distDir), distEntry);
|
|
983
|
-
if (!targetsByPath.has(distPath)) {
|
|
984
|
-
targetsByPath.set(distPath, []);
|
|
985
|
-
}
|
|
986
|
-
(_targetsByPath$get = targetsByPath.get(distPath)) === null || _targetsByPath$get === void 0 || _targetsByPath$get.push(target.name);
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
let diagnostics = [];
|
|
990
|
-
for (let [targetPath, targetNames] of targetsByPath) {
|
|
991
|
-
if (targetNames.length > 1 && pkgContents != null && pkgFilePath != null) {
|
|
992
|
-
diagnostics.push({
|
|
993
|
-
message: (0, _diagnostic().md)`Multiple targets have the same destination path "${_path().default.relative(_path().default.dirname(pkgFilePath), targetPath)}"`,
|
|
994
|
-
origin: '@atlaspack/core',
|
|
995
|
-
codeFrames: [{
|
|
996
|
-
language: 'json',
|
|
997
|
-
filePath: pkgFilePath || undefined,
|
|
998
|
-
code: pkgContents,
|
|
999
|
-
codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(pkgContents, targetNames.map(t => ({
|
|
1000
|
-
key: `/${t}`,
|
|
1001
|
-
type: 'value'
|
|
1002
|
-
})))
|
|
1003
|
-
}]
|
|
1004
|
-
});
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
if (diagnostics.length > 0) {
|
|
1008
|
-
// Only add hints to the last diagnostic so it isn't duplicated on each one
|
|
1009
|
-
diagnostics[diagnostics.length - 1].hints = ['Try removing the duplicate targets, or changing the destination paths.'];
|
|
1010
|
-
throw new (_diagnostic().default)({
|
|
1011
|
-
diagnostic: diagnostics
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
function normalizeSourceMap(options, sourceMap) {
|
|
1016
|
-
if (options.defaultTargetOptions.sourceMaps) {
|
|
1017
|
-
if (typeof sourceMap === 'boolean') {
|
|
1018
|
-
return sourceMap ? {} : undefined;
|
|
1019
|
-
} else {
|
|
1020
|
-
return sourceMap ?? {};
|
|
1021
|
-
}
|
|
1022
|
-
} else {
|
|
1023
|
-
return undefined;
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
function assertTargetsAreNotEntries(targets, input, options) {
|
|
1027
|
-
for (const target of targets) {
|
|
1028
|
-
if (target.distEntry != null && (0, _projectPath.joinProjectPath)(target.distDir, target.distEntry) === input.filePath) {
|
|
1029
|
-
let loc = target.loc;
|
|
1030
|
-
let relativeEntry = _path().default.relative(process.cwd(), (0, _projectPath.fromProjectPath)(options.projectRoot, input.filePath));
|
|
1031
|
-
let codeFrames = [];
|
|
1032
|
-
if (loc) {
|
|
1033
|
-
codeFrames.push({
|
|
1034
|
-
filePath: (0, _projectPath.fromProjectPath)(options.projectRoot, loc.filePath),
|
|
1035
|
-
codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(loc, 'Target defined here')]
|
|
1036
|
-
});
|
|
1037
|
-
let inputLoc = input.loc;
|
|
1038
|
-
if (inputLoc) {
|
|
1039
|
-
let highlight = (0, _diagnostic().convertSourceLocationToHighlight)(inputLoc, 'Entry defined here');
|
|
1040
|
-
if (inputLoc.filePath === loc.filePath) {
|
|
1041
|
-
codeFrames[0].codeHighlights.push(highlight);
|
|
1042
|
-
} else {
|
|
1043
|
-
codeFrames.push({
|
|
1044
|
-
filePath: (0, _projectPath.fromProjectPath)(options.projectRoot, inputLoc.filePath),
|
|
1045
|
-
codeHighlights: [highlight]
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
throw new (_diagnostic().default)({
|
|
1051
|
-
diagnostic: {
|
|
1052
|
-
origin: '@atlaspack/core',
|
|
1053
|
-
message: `Target "${target.name}" is configured to overwrite entry "${relativeEntry}".`,
|
|
1054
|
-
codeFrames,
|
|
1055
|
-
hints: [(COMMON_TARGETS[target.name] ? `The "${target.name}" field is an _output_ file path so that your build can be consumed by other tools. ` : '') + `Change the "${target.name}" field to point to an output file rather than your source code.`],
|
|
1056
|
-
documentationURL: 'https://parceljs.org/features/targets/'
|
|
1057
|
-
}
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
async function debugResolvedTargets(input, targets, targetInfo, options) {
|
|
1063
|
-
for (let target of targets) {
|
|
1064
|
-
let info = targetInfo.get(target.name);
|
|
1065
|
-
let loc = target.loc;
|
|
1066
|
-
if (!loc || !info) {
|
|
1067
|
-
continue;
|
|
1068
|
-
}
|
|
1069
|
-
let output = (0, _projectPath.fromProjectPath)(options.projectRoot, target.distDir);
|
|
1070
|
-
if (target.distEntry != null) {
|
|
1071
|
-
output = _path().default.join(output, target.distEntry);
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
// Resolve relevant engines for context.
|
|
1075
|
-
let engines;
|
|
1076
|
-
switch (target.env.context) {
|
|
1077
|
-
case 'browser':
|
|
1078
|
-
case 'web-worker':
|
|
1079
|
-
case 'service-worker':
|
|
1080
|
-
case 'worklet':
|
|
1081
|
-
{
|
|
1082
|
-
let browsers = target.env.engines.browsers;
|
|
1083
|
-
engines = Array.isArray(browsers) ? browsers.join(', ') : browsers;
|
|
1084
|
-
break;
|
|
1085
|
-
}
|
|
1086
|
-
case 'node':
|
|
1087
|
-
engines = target.env.engines.node;
|
|
1088
|
-
break;
|
|
1089
|
-
case 'electron-main':
|
|
1090
|
-
case 'electron-renderer':
|
|
1091
|
-
engines = target.env.engines.electron;
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
let highlights = [];
|
|
1095
|
-
if (input.loc) {
|
|
1096
|
-
highlights.push((0, _diagnostic().convertSourceLocationToHighlight)(input.loc, 'entry defined here'));
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
// Read package.json where target is defined.
|
|
1100
|
-
let targetFilePath = (0, _projectPath.fromProjectPath)(options.projectRoot, loc.filePath);
|
|
1101
|
-
let contents = await options.inputFS.readFile(targetFilePath, 'utf8');
|
|
1102
|
-
|
|
1103
|
-
// Builds up map of code highlights for each defined/inferred path in the package.json.
|
|
1104
|
-
let jsonHighlights = new Map();
|
|
1105
|
-
for (let key in info) {
|
|
1106
|
-
let keyInfo = info[key];
|
|
1107
|
-
let path = keyInfo.path || keyInfo.inferred;
|
|
1108
|
-
if (!path) {
|
|
1109
|
-
continue;
|
|
1110
|
-
}
|
|
1111
|
-
let type = keyInfo.type || 'value';
|
|
1112
|
-
let highlight = jsonHighlights.get(path);
|
|
1113
|
-
if (!highlight) {
|
|
1114
|
-
highlight = {
|
|
1115
|
-
type: type,
|
|
1116
|
-
defined: '',
|
|
1117
|
-
inferred: []
|
|
1118
|
-
};
|
|
1119
|
-
jsonHighlights.set(path, highlight);
|
|
1120
|
-
} else if (highlight.type !== type) {
|
|
1121
|
-
highlight.type = null;
|
|
1122
|
-
}
|
|
1123
|
-
if (keyInfo.path) {
|
|
1124
|
-
highlight.defined = (0, _diagnostic().md)`${key} defined here`;
|
|
1125
|
-
}
|
|
1126
|
-
if (keyInfo.inferred) {
|
|
1127
|
-
highlight.inferred.push((0, _diagnostic().md)`${key} to be ${JSON.stringify(target.env[key])}`);
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
// $FlowFixMe
|
|
1132
|
-
let listFormat = new Intl.ListFormat('en-US');
|
|
1133
|
-
|
|
1134
|
-
// Generate human friendly messages for each field.
|
|
1135
|
-
let highlightsWithMessages = [...jsonHighlights].map(([k, v]) => {
|
|
1136
|
-
let message = v.defined;
|
|
1137
|
-
if (v.inferred.length > 0) {
|
|
1138
|
-
message += (message ? ', ' : '') + 'caused ';
|
|
1139
|
-
message += listFormat.format(v.inferred);
|
|
1140
|
-
}
|
|
1141
|
-
return {
|
|
1142
|
-
key: k,
|
|
1143
|
-
type: v.type,
|
|
1144
|
-
message
|
|
1145
|
-
};
|
|
1146
|
-
});
|
|
1147
|
-
|
|
1148
|
-
// Get code highlights from JSON paths.
|
|
1149
|
-
highlights.push(...(0, _diagnostic().generateJSONCodeHighlights)(contents, highlightsWithMessages));
|
|
1150
|
-
|
|
1151
|
-
// Format includeNodeModules to be human readable.
|
|
1152
|
-
let includeNodeModules;
|
|
1153
|
-
if (typeof target.env.includeNodeModules === 'boolean') {
|
|
1154
|
-
includeNodeModules = String(target.env.includeNodeModules);
|
|
1155
|
-
} else if (Array.isArray(target.env.includeNodeModules)) {
|
|
1156
|
-
includeNodeModules = 'only ' + listFormat.format(target.env.includeNodeModules.map(m => JSON.stringify(m)));
|
|
1157
|
-
} else if (target.env.includeNodeModules && typeof target.env.includeNodeModules === 'object') {
|
|
1158
|
-
includeNodeModules = 'all except ' + listFormat.format(Object.entries(target.env.includeNodeModules).filter(([, v]) => v === false).map(([k]) => JSON.stringify(k)));
|
|
1159
|
-
}
|
|
1160
|
-
let format = v => v.message != null ? _diagnostic().md.italic(v.message) : '';
|
|
1161
|
-
_logger().default.verbose({
|
|
1162
|
-
origin: '@atlaspack/core',
|
|
1163
|
-
message: (0, _diagnostic().md)`**Target** "${target.name}"
|
|
1164
|
-
|
|
1165
|
-
**Entry**: ${_path().default.relative(process.cwd(), (0, _projectPath.fromProjectPath)(options.projectRoot, input.filePath))}
|
|
1166
|
-
**Output**: ${_path().default.relative(process.cwd(), output)}
|
|
1167
|
-
**Format**: ${target.env.outputFormat} ${format(info.outputFormat)}
|
|
1168
|
-
**Context**: ${target.env.context} ${format(info.context)}
|
|
1169
|
-
**Engines**: ${engines || ''} ${format(info.engines)}
|
|
1170
|
-
**Library Mode**: ${String(target.env.isLibrary)} ${format(info.isLibrary)}
|
|
1171
|
-
**Include Node Modules**: ${includeNodeModules} ${format(info.includeNodeModules)}
|
|
1172
|
-
**Optimize**: ${String(target.env.shouldOptimize)} ${format(info.shouldOptimize)}`,
|
|
1173
|
-
codeFrames: target.loc ? [{
|
|
1174
|
-
filePath: targetFilePath,
|
|
1175
|
-
codeHighlights: highlights
|
|
1176
|
-
}] : []
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
}
|