parcel 2.0.0-nightly.99 → 2.1.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/lib/cli.js CHANGED
@@ -1,106 +1,241 @@
1
1
  "use strict";
2
2
 
3
- var _core = require("@parcel/core");
3
+ function _core() {
4
+ const data = require("@parcel/core");
4
5
 
5
- var _packageManager = require("@parcel/package-manager");
6
+ _core = function () {
7
+ return data;
8
+ };
6
9
 
7
- var _fs = require("@parcel/fs");
10
+ return data;
11
+ }
8
12
 
9
- var _diagnostic = _interopRequireDefault(require("@parcel/diagnostic"));
13
+ function _fs() {
14
+ const data = require("@parcel/fs");
10
15
 
11
- var _utils = require("@parcel/utils");
16
+ _fs = function () {
17
+ return data;
18
+ };
12
19
 
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+ return data;
21
+ }
22
+
23
+ function _diagnostic() {
24
+ const data = _interopRequireDefault(require("@parcel/diagnostic"));
25
+
26
+ _diagnostic = function () {
27
+ return data;
28
+ };
29
+
30
+ return data;
31
+ }
32
+
33
+ function _utils() {
34
+ const data = require("@parcel/utils");
35
+
36
+ _utils = function () {
37
+ return data;
38
+ };
39
+
40
+ return data;
41
+ }
42
+
43
+ function _events() {
44
+ const data = require("@parcel/events");
45
+
46
+ _events = function () {
47
+ return data;
48
+ };
49
+
50
+ return data;
51
+ }
52
+
53
+ function _logger() {
54
+ const data = require("@parcel/logger");
55
+
56
+ _logger = function () {
57
+ return data;
58
+ };
59
+
60
+ return data;
61
+ }
62
+
63
+ function _chalk() {
64
+ const data = _interopRequireDefault(require("chalk"));
14
65
 
15
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
66
+ _chalk = function () {
67
+ return data;
68
+ };
69
+
70
+ return data;
71
+ }
16
72
 
17
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
73
+ function _commander() {
74
+ const data = _interopRequireDefault(require("commander"));
75
+
76
+ _commander = function () {
77
+ return data;
78
+ };
79
+
80
+ return data;
81
+ }
82
+
83
+ function _path() {
84
+ const data = _interopRequireDefault(require("path"));
85
+
86
+ _path = function () {
87
+ return data;
88
+ };
89
+
90
+ return data;
91
+ }
18
92
 
19
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
93
+ function _getPort() {
94
+ const data = _interopRequireDefault(require("get-port"));
95
+
96
+ _getPort = function () {
97
+ return data;
98
+ };
99
+
100
+ return data;
101
+ }
102
+
103
+ var _package = require("../package.json");
104
+
105
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
106
 
21
107
  require('v8-compile-cache');
22
108
 
23
- function logUncaughtError(e) {
24
- if (e instanceof _diagnostic.default) {
25
- for (let diagnostic of e.diagnostics) {
26
- let out = (0, _utils.prettyDiagnostic)(diagnostic);
27
- console.error(out.message);
28
- console.error(out.codeframe || out.stack);
109
+ const program = new (_commander().default.Command)(); // Exit codes in response to signals are traditionally
110
+ // 128 + signal value
111
+ // https://tldp.org/LDP/abs/html/exitcodes.html
29
112
 
30
- for (let h of out.hints) {
31
- console.error(h);
113
+ const SIGINT_EXIT_CODE = 130;
114
+
115
+ async function logUncaughtError(e) {
116
+ if (e instanceof _diagnostic().default) {
117
+ for (let diagnostic of e.diagnostics) {
118
+ let {
119
+ message,
120
+ codeframe,
121
+ stack,
122
+ hints,
123
+ documentation
124
+ } = await (0, _utils().prettyDiagnostic)(diagnostic);
125
+
126
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error(_chalk().default.red(message));
127
+
128
+ if (codeframe || stack) {
129
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error('');
32
130
  }
33
- }
34
- } else {
35
- console.error(e);
36
- }
37
- }
38
131
 
39
- process.on('unhandledRejection', reason => {
40
- logUncaughtError(reason);
41
- process.exit(1);
42
- });
132
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error(codeframe);
43
133
 
44
- const chalk = require('chalk');
134
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error(stack);
45
135
 
46
- const program = require('commander');
136
+ if ((stack || codeframe) && hints.length > 0) {
137
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error('');
138
+ }
47
139
 
48
- const path = require('path');
140
+ for (let h of hints) {
141
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error(_chalk().default.blue(h));
142
+ }
49
143
 
50
- const getPort = require('get-port');
144
+ if (documentation) {
145
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error(_chalk().default.magenta.bold(documentation));
146
+ }
147
+ }
148
+ } else {
149
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error(e);
150
+ } // A hack to definitely ensure we logged the uncaught exception
51
151
 
52
- const version = require('../package.json').version; // Capture the NODE_ENV this process was launched with, so that it can be
53
- // used in Parcel (such as in process.env inlining).
54
152
 
153
+ await new Promise(resolve => setTimeout(resolve, 100));
154
+ }
55
155
 
56
- const initialNodeEnv = process.env.NODE_ENV; // Then, override NODE_ENV to be PARCEL_BUILD_ENV (replaced with `production` in builds)
57
- // so that dependencies of Parcel like React (which renders the cli through `ink`)
58
- // run in the appropriate mode.
156
+ const handleUncaughtException = async exception => {
157
+ try {
158
+ await logUncaughtError(exception);
159
+ } catch (err) {
160
+ console.error(exception);
161
+ console.error(err);
162
+ }
59
163
 
60
- process.env.NODE_ENV = "production";
61
- program.version(version); // --no-cache, --cache-dir, --no-source-maps, --no-autoinstall, --global?, --public-url, --log-level
164
+ process.exit(1);
165
+ };
166
+
167
+ process.on('unhandledRejection', handleUncaughtException);
168
+ program.storeOptionsAsProperties();
169
+ program.version(_package.version); // --no-cache, --cache-dir, --no-source-maps, --no-autoinstall, --global?, --public-url, --log-level
62
170
  // --no-content-hash, --experimental-scope-hoisting, --detailed-report
63
171
 
64
172
  const commonOptions = {
65
173
  '--no-cache': 'disable the filesystem cache',
174
+ '--config <path>': 'specify which config to use. can be a path or a package name',
66
175
  '--cache-dir <path>': 'set the cache directory. defaults to ".parcel-cache"',
67
176
  '--no-source-maps': 'disable sourcemaps',
68
- '--no-autoinstall': 'disable autoinstall',
69
177
  '--target [name]': ['only build given target(s)', (val, list) => list.concat([val]), []],
70
- '--log-level <level>': ['set the log level, either "none", "error", "warn", "info", or "verbose".', /^(none|error|warn|info|verbose)$/],
178
+ '--log-level <level>': new (_commander().default.Option)('--log-level <level>', 'set the log level').choices(['none', 'error', 'warn', 'info', 'verbose']),
179
+ '--dist-dir <dir>': 'output directory to write to when unspecified by targets',
180
+ '--no-autoinstall': 'disable autoinstall',
71
181
  '--profile': 'enable build profiling',
72
- '-V, --version': 'output the version number'
182
+ '-V, --version': 'output the version number',
183
+ '--detailed-report [count]': ['print the asset timings and sizes in the build report', parseOptionInt],
184
+ '--reporter <name>': ['additional reporters to run', (val, acc) => {
185
+ acc.push(val);
186
+ return acc;
187
+ }, []]
73
188
  };
74
189
  var hmrOptions = {
75
190
  '--no-hmr': 'disable hot module replacement',
191
+ '-p, --port <port>': ['set the port to serve on. defaults to $PORT or 1234', process.env.PORT],
192
+ '--host <host>': 'set the host to listen on, defaults to listening on all interfaces',
76
193
  '--https': 'serves files over HTTPS',
77
194
  '--cert <path>': 'path to certificate to use with HTTPS',
78
- '--key <path>': 'path to private key to use with HTTPS'
195
+ '--key <path>': 'path to private key to use with HTTPS',
196
+ '--hmr-port <port>': ['hot module replacement port', process.env.HMR_PORT]
79
197
  };
80
198
 
81
199
  function applyOptions(cmd, options) {
82
200
  for (let opt in options) {
83
- cmd.option(opt, ...(Array.isArray(options[opt]) ? options[opt] : [options[opt]]));
201
+ const option = options[opt];
202
+
203
+ if (option instanceof _commander().default.Option) {
204
+ cmd.addOption(option);
205
+ } else {
206
+ cmd.option(opt, ...(Array.isArray(option) ? option : [option]));
207
+ }
84
208
  }
85
209
  }
86
210
 
87
- let serve = program.command('serve [input...]').description('starts a development server').option('-p, --port <port>', 'set the port to serve on. defaults to 1234', parseInt).option('--public-url <url>', 'the path prefix for absolute urls').option('--host <host>', 'set the host to listen on, defaults to listening on all interfaces').option('--open [browser]', 'automatically open in specified browser, defaults to default browser').option('--watch-for-stdin', 'exit when stdin closes').action(run);
211
+ let serve = program.command('serve [input...]').description('starts a development server').option('--public-url <url>', 'the path prefix for absolute urls').option('--open [browser]', 'automatically open in specified browser, defaults to default browser').option('--watch-for-stdin', 'exit when stdin closes').option('--lazy', 'Build async bundles on demand, when requested in the browser').action(runCommand);
88
212
  applyOptions(serve, hmrOptions);
89
213
  applyOptions(serve, commonOptions);
90
- let watch = program.command('watch [input...]').description('starts the bundler in watch mode').option('--dist-dir <dir>', 'output directory to write to when unspecified by targets').option('--public-url <url>', 'the path prefix for absolute urls').option('--watch-for-stdin', 'exit when stdin closes').action(run);
214
+ let watch = program.command('watch [input...]').description('starts the bundler in watch mode').option('--public-url <url>', 'the path prefix for absolute urls').option('--no-content-hash', 'disable content hashing').option('--watch-for-stdin', 'exit when stdin closes').action(runCommand);
91
215
  applyOptions(watch, hmrOptions);
92
216
  applyOptions(watch, commonOptions);
93
- let build = program.command('build [input...]').description('bundles for production').option('--no-minify', 'disable minification').option('--no-scope-hoist', 'disable scope-hoisting').option('--public-url <url>', 'the path prefix for absolute urls').option('--dist-dir <dir>', 'Output directory to write to when unspecified by targets').action(run);
217
+ let build = program.command('build [input...]').description('bundles for production').option('--no-optimize', 'disable minification').option('--no-scope-hoist', 'disable scope-hoisting').option('--public-url <url>', 'the path prefix for absolute urls').option('--no-content-hash', 'disable content hashing').action(runCommand);
94
218
  applyOptions(build, commonOptions);
95
219
  program.command('help [command]').description('display help information for a command').action(function (command) {
96
220
  let cmd = program.commands.find(c => c.name() === command) || program;
97
221
  cmd.help();
98
222
  });
99
223
  program.on('--help', function () {
100
- console.log('');
101
- console.log(' Run `' + chalk.bold('parcel help <command>') + '` for more information on specific commands');
102
- console.log('');
103
- }); // Make serve the default command except for --help
224
+ _logger().INTERNAL_ORIGINAL_CONSOLE.log('');
225
+
226
+ _logger().INTERNAL_ORIGINAL_CONSOLE.log(' Run `' + _chalk().default.bold('parcel help <command>') + '` for more information on specific commands');
227
+
228
+ _logger().INTERNAL_ORIGINAL_CONSOLE.log('');
229
+ }); // Override to output option description if argument was missing
230
+
231
+ _commander().default.Command.prototype.optionMissingArgument = function (option) {
232
+ _logger().INTERNAL_ORIGINAL_CONSOLE.error("error: option `%s' argument missing", option.flags);
233
+
234
+ _logger().INTERNAL_ORIGINAL_CONSOLE.log(program.createHelp().optionDescription(option));
235
+
236
+ process.exit(1);
237
+ }; // Make serve the default command except for --help
238
+
104
239
 
105
240
  var args = process.argv;
106
241
  if (args[2] === '--help' || args[2] === '-h') args[2] = 'help';
@@ -111,76 +246,125 @@ if (!args[2] || !program.commands.some(c => c.name() === args[2])) {
111
246
 
112
247
  program.parse(args);
113
248
 
114
- async function run(entries, command) {
115
- entries = entries.map(entry => path.resolve(entry));
249
+ function runCommand(...args) {
250
+ run(...args).catch(handleUncaughtException);
251
+ }
116
252
 
253
+ async function run(entries, _opts, // using pre v7 Commander options as properties
254
+ command) {
117
255
  if (entries.length === 0) {
118
- console.log('No entries found');
119
- return;
256
+ entries = ['.'];
120
257
  }
121
258
 
259
+ entries = entries.map(entry => _path().default.resolve(entry));
260
+
122
261
  let Parcel = require('@parcel/core').default;
123
262
 
124
- let packageManager = new _packageManager.NodePackageManager(new _fs.NodeFS());
125
- let defaultConfig = await packageManager.require('@parcel/config-default', __filename);
126
- let parcel = new Parcel(_objectSpread({
263
+ let fs = new (_fs().NodeFS)();
264
+ let options = await normalizeOptions(command, fs);
265
+ let parcel = new Parcel({
127
266
  entries,
128
- packageManager,
129
- defaultConfig: _objectSpread({}, defaultConfig, {
130
- filePath: (await packageManager.resolve('@parcel/config-default', __filename)).resolved
267
+ // $FlowFixMe[extra-arg] - flow doesn't know about the `paths` option (added in Node v8.9.0)
268
+ defaultConfig: require.resolve('@parcel/config-default', {
269
+ paths: [fs.cwd(), __dirname]
131
270
  }),
132
- patchConsole: true
133
- }, (await normalizeOptions(command))));
271
+ shouldPatchConsole: true,
272
+ ...options
273
+ });
274
+ let disposable = new (_events().Disposable)();
275
+ let unsubscribe;
276
+ let isExiting;
277
+
278
+ async function exit(exitCode = 0) {
279
+ if (isExiting) {
280
+ return;
281
+ }
134
282
 
135
- if (command.name() === 'watch' || command.name() === 'serve') {
136
- let {
283
+ isExiting = true;
284
+
285
+ if (unsubscribe != null) {
286
+ await unsubscribe();
287
+ } else if (parcel.isProfiling) {
288
+ await parcel.stopProfiling();
289
+ }
290
+
291
+ if (process.stdin.isTTY && process.stdin.isRaw) {
292
+ // $FlowFixMe
293
+ process.stdin.setRawMode(false);
294
+ }
295
+
296
+ disposable.dispose();
297
+ process.exit(exitCode);
298
+ }
299
+
300
+ const isWatching = command.name() === 'watch' || command.name() === 'serve';
301
+
302
+ if (process.stdin.isTTY) {
303
+ // $FlowFixMe
304
+ process.stdin.setRawMode(true);
305
+
306
+ require('readline').emitKeypressEvents(process.stdin);
307
+
308
+ let stream = process.stdin.on('keypress', async (char, key) => {
309
+ if (!key.ctrl) {
310
+ return;
311
+ }
312
+
313
+ switch (key.name) {
314
+ case 'c':
315
+ // Detect the ctrl+c key, and gracefully exit after writing the asset graph to the cache.
316
+ // This is mostly for tools that wrap Parcel as a child process like yarn and npm.
317
+ //
318
+ // Setting raw mode prevents SIGINT from being sent in response to ctrl-c:
319
+ // https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode
320
+ //
321
+ // We don't use the SIGINT event for this because when run inside yarn, the parent
322
+ // yarn process ends before Parcel and it appears that Parcel has ended while it may still
323
+ // be cleaning up. Handling events from stdin prevents this impression.
324
+ // Enqueue a busy message to be shown if Parcel doesn't shut down
325
+ // within the timeout.
326
+ setTimeout(() => _logger().INTERNAL_ORIGINAL_CONSOLE.log(_chalk().default.bold.yellowBright('Parcel is shutting down...')), 500); // When watching, a 0 success code is acceptable when Parcel is interrupted with ctrl-c.
327
+ // When building, fail with a code as if we received a SIGINT.
328
+
329
+ await exit(isWatching ? 0 : SIGINT_EXIT_CODE);
330
+ break;
331
+
332
+ case 'e':
333
+ await (parcel.isProfiling ? parcel.stopProfiling() : parcel.startProfiling());
334
+ break;
335
+
336
+ case 'y':
337
+ await parcel.takeHeapSnapshot();
338
+ break;
339
+ }
340
+ });
341
+ disposable.add(() => {
342
+ stream.destroy();
343
+ });
344
+ }
345
+
346
+ if (isWatching) {
347
+ ({
137
348
  unsubscribe
138
349
  } = await parcel.watch(err => {
139
350
  if (err) {
140
351
  throw err;
141
352
  }
142
- });
143
- let isExiting;
144
-
145
- const exit = async () => {
146
- if (isExiting) {
147
- return;
148
- }
353
+ }));
149
354
 
150
- isExiting = true;
151
- await unsubscribe();
152
- process.exit();
153
- };
355
+ if (command.open && options.serveOptions) {
356
+ await (0, _utils().openInBrowser)(`${options.serveOptions.https ? 'https' : 'http'}://${options.serveOptions.host || 'localhost'}:${options.serveOptions.port}`, command.open);
357
+ }
154
358
 
155
359
  if (command.watchForStdin) {
156
360
  process.stdin.on('end', async () => {
157
- console.log('STDIN closed, ending');
361
+ _logger().INTERNAL_ORIGINAL_CONSOLE.log('STDIN closed, ending');
362
+
158
363
  await exit();
159
364
  });
160
365
  process.stdin.resume();
161
- } // Detect the ctrl+c key, and gracefully exit after writing the asset graph to the cache.
162
- // This is mostly for tools that wrap Parcel as a child process like yarn and npm.
163
- //
164
- // Setting raw mode prevents SIGINT from being sent in response to ctrl-c:
165
- // https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode
166
- //
167
- // We don't use the SIGINT event for this because when run inside yarn, the parent
168
- // yarn process ends before Parcel and it appears that Parcel has ended while it may still
169
- // be cleaning up. Handling events from stdin prevents this impression.
170
-
171
-
172
- if (process.stdin.isTTY) {
173
- // $FlowFixMe
174
- process.stdin.setRawMode(true);
175
-
176
- require('readline').emitKeypressEvents(process.stdin);
177
-
178
- process.stdin.on('keypress', async (char, key) => {
179
- if (key.ctrl && key.name === 'c') {
180
- await exit();
181
- }
182
- });
183
- } // In non-tty cases, respond to SIGINT by cleaning up.
366
+ } // In non-tty cases, respond to SIGINT by cleaning up. Since we're watching,
367
+ // a 0 success code is acceptable.
184
368
 
185
369
 
186
370
  process.on('SIGINT', exit);
@@ -188,29 +372,56 @@ async function run(entries, command) {
188
372
  } else {
189
373
  try {
190
374
  await parcel.run();
191
- } catch (e) {
375
+ } catch (err) {
192
376
  // If an exception is thrown during Parcel.build, it is given to reporters in a
193
377
  // buildFailure event, and has been shown to the user.
194
- if (!(e instanceof _core.BuildError)) {
195
- logUncaughtError(e);
378
+ if (!(err instanceof _core().BuildError)) {
379
+ await logUncaughtError(err);
196
380
  }
197
381
 
198
- process.exit(1);
382
+ await exit(1);
199
383
  }
384
+
385
+ await exit();
386
+ }
387
+ }
388
+
389
+ function parsePort(portValue) {
390
+ let parsedPort = Number(portValue); // Throw an error if port value is invalid...
391
+
392
+ if (!Number.isInteger(parsedPort)) {
393
+ throw new Error(`Port ${portValue} is not a valid integer.`);
200
394
  }
395
+
396
+ return parsedPort;
201
397
  }
202
398
 
203
- async function normalizeOptions(command) {
204
- var _command$sourceMaps, _command$autoinstall;
399
+ function parseOptionInt(value) {
400
+ const parsedValue = parseInt(value, 10);
401
+
402
+ if (isNaN(parsedValue)) {
403
+ throw new (_commander().default.InvalidOptionArgumentError)('Must be an integer.');
404
+ }
405
+
406
+ return parsedValue;
407
+ }
408
+
409
+ async function normalizeOptions(command, inputFS) {
410
+ var _command$autoinstall, _command$sourceMaps;
205
411
 
206
412
  let nodeEnv;
207
413
 
208
414
  if (command.name() === 'build') {
209
- nodeEnv = initialNodeEnv || 'production';
415
+ nodeEnv = process.env.NODE_ENV || 'production'; // Autoinstall unless explicitly disabled or we detect a CI environment.
416
+
417
+ command.autoinstall = !(command.autoinstall === false || process.env.CI);
210
418
  } else {
211
- nodeEnv = initialNodeEnv || 'development';
212
- }
419
+ nodeEnv = process.env.NODE_ENV || 'development';
420
+ } // Set process.env.NODE_ENV to a default if undefined so that it is
421
+ // available in JS configs and plugins.
213
422
 
423
+
424
+ process.env.NODE_ENV = nodeEnv;
214
425
  let https = !!command.https;
215
426
 
216
427
  if (command.cert && command.key) {
@@ -220,25 +431,48 @@ async function normalizeOptions(command) {
220
431
  };
221
432
  }
222
433
 
223
- let serve = false;
434
+ let serveOptions = false;
435
+ let {
436
+ host
437
+ } = command; // Ensure port is valid and available
438
+
439
+ let port = parsePort(command.port || '1234');
440
+ let originalPort = port;
441
+
442
+ if (command.name() === 'serve' || command.hmr) {
443
+ try {
444
+ port = await (0, _getPort().default)({
445
+ port,
446
+ host
447
+ });
448
+ } catch (err) {
449
+ throw new (_diagnostic().default)({
450
+ diagnostic: {
451
+ message: `Could not get available port: ${err.message}`,
452
+ origin: 'parcel',
453
+ stack: err.stack
454
+ }
455
+ });
456
+ }
457
+
458
+ if (port !== originalPort) {
459
+ let errorMessage = `Port "${originalPort}" could not be used`;
460
+
461
+ if (command.port != null) {
462
+ // Throw the error if the user defined a custom port
463
+ throw new Error(errorMessage);
464
+ } else {
465
+ // Parcel logger is not set up at this point, so just use native INTERNAL_ORIGINAL_CONSOLE
466
+ _logger().INTERNAL_ORIGINAL_CONSOLE.warn(errorMessage);
467
+ }
468
+ }
469
+ }
224
470
 
225
471
  if (command.name() === 'serve') {
226
472
  let {
227
- port = 1234,
228
- host,
229
473
  publicUrl
230
474
  } = command;
231
- port = await getPort({
232
- port,
233
- host
234
- });
235
-
236
- if (command.port && port !== command.port) {
237
- // Parcel logger is not set up at this point, so just use native console.
238
- console.warn(chalk.bold.yellowBright(`⚠️ Port ${command.port} could not be used.`));
239
- }
240
-
241
- serve = {
475
+ serveOptions = {
242
476
  https,
243
477
  port,
244
478
  host,
@@ -246,30 +480,54 @@ async function normalizeOptions(command) {
246
480
  };
247
481
  }
248
482
 
249
- let hmr = false;
483
+ let hmrOptions = null;
250
484
 
251
485
  if (command.name() !== 'build' && command.hmr !== false) {
252
- hmr = true;
486
+ let hmrport = command.hmrPort ? parsePort(command.hmrPort) : port;
487
+ hmrOptions = {
488
+ port: hmrport,
489
+ host
490
+ };
491
+ }
492
+
493
+ if (command.detailedReport === true) {
494
+ command.detailedReport = '10';
253
495
  }
254
496
 
497
+ let additionalReporters = [{
498
+ packageName: '@parcel/reporter-cli',
499
+ resolveFrom: __filename
500
+ }, ...command.reporter.map(packageName => ({
501
+ packageName,
502
+ resolveFrom: _path().default.join(inputFS.cwd(), 'index')
503
+ }))];
255
504
  let mode = command.name() === 'build' ? 'production' : 'development';
256
505
  return {
257
- disableCache: command.cache === false,
506
+ shouldDisableCache: command.cache === false,
258
507
  cacheDir: command.cacheDir,
508
+ config: command.config,
259
509
  mode,
260
- minify: command.minify != null ? command.minify : mode === 'production',
261
- sourceMaps: (_command$sourceMaps = command.sourceMaps) !== null && _command$sourceMaps !== void 0 ? _command$sourceMaps : true,
262
- scopeHoist: command.scopeHoist,
263
- publicUrl: command.publicUrl,
264
- distDir: command.distDir,
265
- hot: hmr,
266
- serve,
510
+ hmrOptions,
511
+ shouldContentHash: hmrOptions ? false : command.contentHash,
512
+ serveOptions,
267
513
  targets: command.target.length > 0 ? command.target : null,
268
- autoinstall: (_command$autoinstall = command.autoinstall) !== null && _command$autoinstall !== void 0 ? _command$autoinstall : true,
514
+ shouldAutoInstall: (_command$autoinstall = command.autoinstall) !== null && _command$autoinstall !== void 0 ? _command$autoinstall : true,
269
515
  logLevel: command.logLevel,
270
- profile: command.profile,
516
+ shouldProfile: command.profile,
517
+ shouldBuildLazily: command.lazy,
518
+ detailedReport: command.detailedReport != null ? {
519
+ assetsPerBundle: parseInt(command.detailedReport, 10)
520
+ } : null,
271
521
  env: {
272
522
  NODE_ENV: nodeEnv
523
+ },
524
+ additionalReporters,
525
+ defaultTargetOptions: {
526
+ shouldOptimize: command.optimize != null ? command.optimize : mode === 'production',
527
+ sourceMaps: (_command$sourceMaps = command.sourceMaps) !== null && _command$sourceMaps !== void 0 ? _command$sourceMaps : true,
528
+ shouldScopeHoist: command.scopeHoist,
529
+ publicUrl: command.publicUrl,
530
+ distDir: command.distDir
273
531
  }
274
532
  };
275
533
  }