parcel 2.0.0-beta.3 → 2.0.0-dev.1508
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/README.md +36 -1510
- package/lib/cli.js +80 -144
- package/package.json +16 -15
- package/src/bin.js +4 -1
- package/src/cli.js +64 -38
package/src/cli.js
CHANGED
|
@@ -13,8 +13,6 @@ import path from 'path';
|
|
|
13
13
|
import getPort from 'get-port';
|
|
14
14
|
import {version} from '../package.json';
|
|
15
15
|
|
|
16
|
-
require('v8-compile-cache');
|
|
17
|
-
|
|
18
16
|
const program = new commander.Command();
|
|
19
17
|
|
|
20
18
|
// Exit codes in response to signals are traditionally
|
|
@@ -25,12 +23,22 @@ const SIGINT_EXIT_CODE = 130;
|
|
|
25
23
|
async function logUncaughtError(e: mixed) {
|
|
26
24
|
if (e instanceof ThrowableDiagnostic) {
|
|
27
25
|
for (let diagnostic of e.diagnostics) {
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
INTERNAL_ORIGINAL_CONSOLE.error(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
let {message, codeframe, stack, hints, documentation} =
|
|
27
|
+
await prettyDiagnostic(diagnostic);
|
|
28
|
+
INTERNAL_ORIGINAL_CONSOLE.error(chalk.red(message));
|
|
29
|
+
if (codeframe || stack) {
|
|
30
|
+
INTERNAL_ORIGINAL_CONSOLE.error('');
|
|
31
|
+
}
|
|
32
|
+
INTERNAL_ORIGINAL_CONSOLE.error(codeframe);
|
|
33
|
+
INTERNAL_ORIGINAL_CONSOLE.error(stack);
|
|
34
|
+
if ((stack || codeframe) && hints.length > 0) {
|
|
35
|
+
INTERNAL_ORIGINAL_CONSOLE.error('');
|
|
36
|
+
}
|
|
37
|
+
for (let h of hints) {
|
|
38
|
+
INTERNAL_ORIGINAL_CONSOLE.error(chalk.blue(h));
|
|
39
|
+
}
|
|
40
|
+
if (documentation) {
|
|
41
|
+
INTERNAL_ORIGINAL_CONSOLE.error(chalk.magenta.bold(documentation));
|
|
34
42
|
}
|
|
35
43
|
}
|
|
36
44
|
} else {
|
|
@@ -65,6 +73,8 @@ const commonOptions = {
|
|
|
65
73
|
'--config <path>':
|
|
66
74
|
'specify which config to use. can be a path or a package name',
|
|
67
75
|
'--cache-dir <path>': 'set the cache directory. defaults to ".parcel-cache"',
|
|
76
|
+
'--watch-dir <path>':
|
|
77
|
+
'set the root watch directory. defaults to nearest lockfile or source control dir.',
|
|
68
78
|
'--no-source-maps': 'disable sourcemaps',
|
|
69
79
|
'--target [name]': [
|
|
70
80
|
'only build given target(s)',
|
|
@@ -78,7 +88,8 @@ const commonOptions = {
|
|
|
78
88
|
'--dist-dir <dir>':
|
|
79
89
|
'output directory to write to when unspecified by targets',
|
|
80
90
|
'--no-autoinstall': 'disable autoinstall',
|
|
81
|
-
'--profile': 'enable build profiling',
|
|
91
|
+
'--profile': 'enable sampling build profiling',
|
|
92
|
+
'--trace': 'enable build tracing',
|
|
82
93
|
'-V, --version': 'output the version number',
|
|
83
94
|
'--detailed-report [count]': [
|
|
84
95
|
'print the asset timings and sizes in the build report',
|
|
@@ -106,6 +117,7 @@ var hmrOptions = {
|
|
|
106
117
|
'--cert <path>': 'path to certificate to use with HTTPS',
|
|
107
118
|
'--key <path>': 'path to private key to use with HTTPS',
|
|
108
119
|
'--hmr-port <port>': ['hot module replacement port', process.env.HMR_PORT],
|
|
120
|
+
'--hmr-host <host>': ['hot module replacement host', process.env.HMR_HOST],
|
|
109
121
|
};
|
|
110
122
|
|
|
111
123
|
function applyOptions(cmd, options) {
|
|
@@ -129,8 +141,12 @@ let serve = program
|
|
|
129
141
|
)
|
|
130
142
|
.option('--watch-for-stdin', 'exit when stdin closes')
|
|
131
143
|
.option(
|
|
132
|
-
'--lazy',
|
|
133
|
-
'Build async bundles on demand, when requested in the browser',
|
|
144
|
+
'--lazy [includes]',
|
|
145
|
+
'Build async bundles on demand, when requested in the browser. Defaults to all async bundles, unless a comma separated list of source file globs is provided. Only async bundles whose entry points match these globs will be built lazily',
|
|
146
|
+
)
|
|
147
|
+
.option(
|
|
148
|
+
'--lazy-exclude <excludes>',
|
|
149
|
+
'Can only be used in combination with --lazy. Comma separated list of source file globs, async bundles whose entry points match these globs will not be built lazily',
|
|
134
150
|
)
|
|
135
151
|
.action(runCommand);
|
|
136
152
|
|
|
@@ -162,12 +178,12 @@ applyOptions(build, commonOptions);
|
|
|
162
178
|
program
|
|
163
179
|
.command('help [command]')
|
|
164
180
|
.description('display help information for a command')
|
|
165
|
-
.action(function(command) {
|
|
181
|
+
.action(function (command) {
|
|
166
182
|
let cmd = program.commands.find(c => c.name() === command) || program;
|
|
167
183
|
cmd.help();
|
|
168
184
|
});
|
|
169
185
|
|
|
170
|
-
program.on('--help', function() {
|
|
186
|
+
program.on('--help', function () {
|
|
171
187
|
INTERNAL_ORIGINAL_CONSOLE.log('');
|
|
172
188
|
INTERNAL_ORIGINAL_CONSOLE.log(
|
|
173
189
|
' Run `' +
|
|
@@ -178,7 +194,8 @@ program.on('--help', function() {
|
|
|
178
194
|
});
|
|
179
195
|
|
|
180
196
|
// Override to output option description if argument was missing
|
|
181
|
-
|
|
197
|
+
// $FlowFixMe[prop-missing]
|
|
198
|
+
commander.Command.prototype.optionMissingArgument = function (option) {
|
|
182
199
|
INTERNAL_ORIGINAL_CONSOLE.error(
|
|
183
200
|
"error: option `%s' argument missing",
|
|
184
201
|
option.flags,
|
|
@@ -206,23 +223,21 @@ async function run(
|
|
|
206
223
|
_opts: any, // using pre v7 Commander options as properties
|
|
207
224
|
command: any,
|
|
208
225
|
) {
|
|
209
|
-
entries = entries.map(entry => path.resolve(entry));
|
|
210
|
-
|
|
211
226
|
if (entries.length === 0) {
|
|
212
|
-
|
|
213
|
-
INTERNAL_ORIGINAL_CONSOLE.log('No entries found');
|
|
214
|
-
return;
|
|
227
|
+
entries = ['.'];
|
|
215
228
|
}
|
|
229
|
+
|
|
230
|
+
entries = entries.map(entry => path.resolve(entry));
|
|
231
|
+
|
|
216
232
|
let Parcel = require('@parcel/core').default;
|
|
217
233
|
let fs = new NodeFS();
|
|
218
234
|
let options = await normalizeOptions(command, fs);
|
|
219
235
|
let parcel = new Parcel({
|
|
220
236
|
entries,
|
|
221
|
-
// $FlowFixMe[extra-arg] - flow doesn't know about the `paths` option (added in Node v8.9.0)
|
|
222
237
|
defaultConfig: require.resolve('@parcel/config-default', {
|
|
223
238
|
paths: [fs.cwd(), __dirname],
|
|
224
239
|
}),
|
|
225
|
-
shouldPatchConsole:
|
|
240
|
+
shouldPatchConsole: false,
|
|
226
241
|
...options,
|
|
227
242
|
});
|
|
228
243
|
|
|
@@ -272,16 +287,7 @@ async function run(
|
|
|
272
287
|
// We don't use the SIGINT event for this because when run inside yarn, the parent
|
|
273
288
|
// yarn process ends before Parcel and it appears that Parcel has ended while it may still
|
|
274
289
|
// be cleaning up. Handling events from stdin prevents this impression.
|
|
275
|
-
|
|
276
|
-
// Enqueue a busy message to be shown if Parcel doesn't shut down
|
|
277
|
-
// within the timeout.
|
|
278
|
-
setTimeout(
|
|
279
|
-
() =>
|
|
280
|
-
INTERNAL_ORIGINAL_CONSOLE.log(
|
|
281
|
-
chalk.bold.yellowBright('Parcel is shutting down...'),
|
|
282
|
-
),
|
|
283
|
-
500,
|
|
284
|
-
);
|
|
290
|
+
//
|
|
285
291
|
// When watching, a 0 success code is acceptable when Parcel is interrupted with ctrl-c.
|
|
286
292
|
// When building, fail with a code as if we received a SIGINT.
|
|
287
293
|
await exit(isWatching ? 0 : SIGINT_EXIT_CODE);
|
|
@@ -311,8 +317,9 @@ async function run(
|
|
|
311
317
|
|
|
312
318
|
if (command.open && options.serveOptions) {
|
|
313
319
|
await openInBrowser(
|
|
314
|
-
`${options.serveOptions.https ? 'https' : 'http'}://${
|
|
315
|
-
.serveOptions.host || 'localhost'
|
|
320
|
+
`${options.serveOptions.https ? 'https' : 'http'}://${
|
|
321
|
+
options.serveOptions.host || 'localhost'
|
|
322
|
+
}:${options.serveOptions.port}`,
|
|
316
323
|
command.open,
|
|
317
324
|
);
|
|
318
325
|
}
|
|
@@ -328,8 +335,8 @@ async function run(
|
|
|
328
335
|
|
|
329
336
|
// In non-tty cases, respond to SIGINT by cleaning up. Since we're watching,
|
|
330
337
|
// a 0 success code is acceptable.
|
|
331
|
-
process.on('SIGINT', exit);
|
|
332
|
-
process.on('SIGTERM', exit);
|
|
338
|
+
process.on('SIGINT', () => exit());
|
|
339
|
+
process.on('SIGTERM', () => exit());
|
|
333
340
|
} else {
|
|
334
341
|
try {
|
|
335
342
|
await parcel.run();
|
|
@@ -404,7 +411,6 @@ async function normalizeOptions(
|
|
|
404
411
|
diagnostic: {
|
|
405
412
|
message: `Could not get available port: ${err.message}`,
|
|
406
413
|
origin: 'parcel',
|
|
407
|
-
filePath: __filename,
|
|
408
414
|
stack: err.stack,
|
|
409
415
|
},
|
|
410
416
|
});
|
|
@@ -436,8 +442,9 @@ async function normalizeOptions(
|
|
|
436
442
|
let hmrOptions = null;
|
|
437
443
|
if (command.name() !== 'build' && command.hmr !== false) {
|
|
438
444
|
let hmrport = command.hmrPort ? parsePort(command.hmrPort) : port;
|
|
445
|
+
let hmrhost = command.hmrHost ? command.hmrHost : host;
|
|
439
446
|
|
|
440
|
-
hmrOptions = {port: hmrport, host};
|
|
447
|
+
hmrOptions = {port: hmrport, host: hmrhost};
|
|
441
448
|
}
|
|
442
449
|
|
|
443
450
|
if (command.detailedReport === true) {
|
|
@@ -452,10 +459,24 @@ async function normalizeOptions(
|
|
|
452
459
|
})),
|
|
453
460
|
];
|
|
454
461
|
|
|
462
|
+
if (command.trace) {
|
|
463
|
+
additionalReporters.unshift({
|
|
464
|
+
packageName: '@parcel/reporter-tracer',
|
|
465
|
+
resolveFrom: __filename,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
455
469
|
let mode = command.name() === 'build' ? 'production' : 'development';
|
|
470
|
+
|
|
471
|
+
const normalizeIncludeExcludeList = (input?: string): string[] => {
|
|
472
|
+
if (typeof input !== 'string') return [];
|
|
473
|
+
return input.split(',').map(value => value.trim());
|
|
474
|
+
};
|
|
456
475
|
return {
|
|
457
476
|
shouldDisableCache: command.cache === false,
|
|
458
477
|
cacheDir: command.cacheDir,
|
|
478
|
+
watchDir: command.watchDir,
|
|
479
|
+
config: command.config,
|
|
459
480
|
mode,
|
|
460
481
|
hmrOptions,
|
|
461
482
|
shouldContentHash: hmrOptions ? false : command.contentHash,
|
|
@@ -464,7 +485,12 @@ async function normalizeOptions(
|
|
|
464
485
|
shouldAutoInstall: command.autoinstall ?? true,
|
|
465
486
|
logLevel: command.logLevel,
|
|
466
487
|
shouldProfile: command.profile,
|
|
467
|
-
|
|
488
|
+
shouldTrace: command.trace,
|
|
489
|
+
shouldBuildLazily: typeof command.lazy !== 'undefined',
|
|
490
|
+
lazyIncludes: normalizeIncludeExcludeList(command.lazy),
|
|
491
|
+
lazyExcludes: normalizeIncludeExcludeList(command.lazyExclude),
|
|
492
|
+
shouldBundleIncrementally:
|
|
493
|
+
process.env.PARCEL_INCREMENTAL_BUNDLING === 'false' ? false : true,
|
|
468
494
|
detailedReport:
|
|
469
495
|
command.detailedReport != null
|
|
470
496
|
? {
|