parcel 2.8.3 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/cli.js +39 -118
  2. package/package.json +15 -15
  3. package/src/cli.js +11 -4
package/lib/cli.js CHANGED
@@ -2,116 +2,82 @@
2
2
 
3
3
  function _core() {
4
4
  const data = require("@parcel/core");
5
-
6
5
  _core = function () {
7
6
  return data;
8
7
  };
9
-
10
8
  return data;
11
9
  }
12
-
13
10
  function _fs() {
14
11
  const data = require("@parcel/fs");
15
-
16
12
  _fs = function () {
17
13
  return data;
18
14
  };
19
-
20
15
  return data;
21
16
  }
22
-
23
17
  function _diagnostic() {
24
18
  const data = _interopRequireDefault(require("@parcel/diagnostic"));
25
-
26
19
  _diagnostic = function () {
27
20
  return data;
28
21
  };
29
-
30
22
  return data;
31
23
  }
32
-
33
24
  function _utils() {
34
25
  const data = require("@parcel/utils");
35
-
36
26
  _utils = function () {
37
27
  return data;
38
28
  };
39
-
40
29
  return data;
41
30
  }
42
-
43
31
  function _events() {
44
32
  const data = require("@parcel/events");
45
-
46
33
  _events = function () {
47
34
  return data;
48
35
  };
49
-
50
36
  return data;
51
37
  }
52
-
53
38
  function _logger() {
54
39
  const data = require("@parcel/logger");
55
-
56
40
  _logger = function () {
57
41
  return data;
58
42
  };
59
-
60
43
  return data;
61
44
  }
62
-
63
45
  function _chalk() {
64
46
  const data = _interopRequireDefault(require("chalk"));
65
-
66
47
  _chalk = function () {
67
48
  return data;
68
49
  };
69
-
70
50
  return data;
71
51
  }
72
-
73
52
  function _commander() {
74
53
  const data = _interopRequireDefault(require("commander"));
75
-
76
54
  _commander = function () {
77
55
  return data;
78
56
  };
79
-
80
57
  return data;
81
58
  }
82
-
83
59
  function _path() {
84
60
  const data = _interopRequireDefault(require("path"));
85
-
86
61
  _path = function () {
87
62
  return data;
88
63
  };
89
-
90
64
  return data;
91
65
  }
92
-
93
66
  function _getPort() {
94
67
  const data = _interopRequireDefault(require("get-port"));
95
-
96
68
  _getPort = function () {
97
69
  return data;
98
70
  };
99
-
100
71
  return data;
101
72
  }
102
-
103
73
  var _package = require("../package.json");
104
-
105
74
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
75
+ const program = new (_commander().default.Command)();
106
76
 
107
- require('v8-compile-cache');
108
-
109
- const program = new (_commander().default.Command)(); // Exit codes in response to signals are traditionally
77
+ // Exit codes in response to signals are traditionally
110
78
  // 128 + signal value
111
79
  // https://tldp.org/LDP/abs/html/exitcodes.html
112
-
113
80
  const SIGINT_EXIT_CODE = 130;
114
-
115
81
  async function logUncaughtError(e) {
116
82
  if (e instanceof _diagnostic().default) {
117
83
  for (let diagnostic of e.diagnostics) {
@@ -122,37 +88,29 @@ async function logUncaughtError(e) {
122
88
  hints,
123
89
  documentation
124
90
  } = await (0, _utils().prettyDiagnostic)(diagnostic);
125
-
126
91
  _logger().INTERNAL_ORIGINAL_CONSOLE.error(_chalk().default.red(message));
127
-
128
92
  if (codeframe || stack) {
129
93
  _logger().INTERNAL_ORIGINAL_CONSOLE.error('');
130
94
  }
131
-
132
95
  _logger().INTERNAL_ORIGINAL_CONSOLE.error(codeframe);
133
-
134
96
  _logger().INTERNAL_ORIGINAL_CONSOLE.error(stack);
135
-
136
97
  if ((stack || codeframe) && hints.length > 0) {
137
98
  _logger().INTERNAL_ORIGINAL_CONSOLE.error('');
138
99
  }
139
-
140
100
  for (let h of hints) {
141
101
  _logger().INTERNAL_ORIGINAL_CONSOLE.error(_chalk().default.blue(h));
142
102
  }
143
-
144
103
  if (documentation) {
145
104
  _logger().INTERNAL_ORIGINAL_CONSOLE.error(_chalk().default.magenta.bold(documentation));
146
105
  }
147
106
  }
148
107
  } else {
149
108
  _logger().INTERNAL_ORIGINAL_CONSOLE.error(e);
150
- } // A hack to definitely ensure we logged the uncaught exception
151
-
109
+ }
152
110
 
111
+ // A hack to definitely ensure we logged the uncaught exception
153
112
  await new Promise(resolve => setTimeout(resolve, 100));
154
113
  }
155
-
156
114
  const handleUncaughtException = async exception => {
157
115
  try {
158
116
  await logUncaughtError(exception);
@@ -160,13 +118,13 @@ const handleUncaughtException = async exception => {
160
118
  console.error(exception);
161
119
  console.error(err);
162
120
  }
163
-
164
121
  process.exit(1);
165
122
  };
166
-
167
123
  process.on('unhandledRejection', handleUncaughtException);
168
124
  program.storeOptionsAsProperties();
169
- program.version(_package.version); // --no-cache, --cache-dir, --no-source-maps, --no-autoinstall, --global?, --public-url, --log-level
125
+ program.version(_package.version);
126
+
127
+ // --no-cache, --cache-dir, --no-source-maps, --no-autoinstall, --global?, --public-url, --log-level
170
128
  // --no-content-hash, --experimental-scope-hoisting, --detailed-report
171
129
 
172
130
  const commonOptions = {
@@ -178,7 +136,8 @@ const commonOptions = {
178
136
  '--log-level <level>': new (_commander().default.Option)('--log-level <level>', 'set the log level').choices(['none', 'error', 'warn', 'info', 'verbose']),
179
137
  '--dist-dir <dir>': 'output directory to write to when unspecified by targets',
180
138
  '--no-autoinstall': 'disable autoinstall',
181
- '--profile': 'enable build profiling',
139
+ '--profile': 'enable sampling build profiling',
140
+ '--trace': 'enable build tracing',
182
141
  '-V, --version': 'output the version number',
183
142
  '--detailed-report [count]': ['print the asset timings and sizes in the build report', parseOptionInt],
184
143
  '--reporter <name>': ['additional reporters to run', (val, acc) => {
@@ -196,11 +155,9 @@ var hmrOptions = {
196
155
  '--hmr-port <port>': ['hot module replacement port', process.env.HMR_PORT],
197
156
  '--hmr-host <host>': ['hot module replacement host', process.env.HMR_HOST]
198
157
  };
199
-
200
158
  function applyOptions(cmd, options) {
201
159
  for (let opt in options) {
202
160
  const option = options[opt];
203
-
204
161
  if (option instanceof _commander().default.Option) {
205
162
  cmd.addOption(option);
206
163
  } else {
@@ -208,7 +165,6 @@ function applyOptions(cmd, options) {
208
165
  }
209
166
  }
210
167
  }
211
-
212
168
  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);
213
169
  applyOptions(serve, hmrOptions);
214
170
  applyOptions(serve, commonOptions);
@@ -223,45 +179,36 @@ program.command('help [command]').description('display help information for a co
223
179
  });
224
180
  program.on('--help', function () {
225
181
  _logger().INTERNAL_ORIGINAL_CONSOLE.log('');
226
-
227
182
  _logger().INTERNAL_ORIGINAL_CONSOLE.log(' Run `' + _chalk().default.bold('parcel help <command>') + '` for more information on specific commands');
228
-
229
183
  _logger().INTERNAL_ORIGINAL_CONSOLE.log('');
230
- }); // Override to output option description if argument was missing
231
- // $FlowFixMe[prop-missing]
184
+ });
232
185
 
186
+ // Override to output option description if argument was missing
187
+ // $FlowFixMe[prop-missing]
233
188
  _commander().default.Command.prototype.optionMissingArgument = function (option) {
234
189
  _logger().INTERNAL_ORIGINAL_CONSOLE.error("error: option `%s' argument missing", option.flags);
235
-
236
190
  _logger().INTERNAL_ORIGINAL_CONSOLE.log(program.createHelp().optionDescription(option));
237
-
238
191
  process.exit(1);
239
- }; // Make serve the default command except for --help
240
-
192
+ };
241
193
 
194
+ // Make serve the default command except for --help
242
195
  var args = process.argv;
243
196
  if (args[2] === '--help' || args[2] === '-h') args[2] = 'help';
244
-
245
197
  if (!args[2] || !program.commands.some(c => c.name() === args[2])) {
246
198
  args.splice(2, 0, 'serve');
247
199
  }
248
-
249
200
  program.parse(args);
250
-
251
201
  function runCommand(...args) {
252
202
  run(...args).catch(handleUncaughtException);
253
203
  }
254
-
255
- async function run(entries, _opts, // using pre v7 Commander options as properties
204
+ async function run(entries, _opts,
205
+ // using pre v7 Commander options as properties
256
206
  command) {
257
207
  if (entries.length === 0) {
258
208
  entries = ['.'];
259
209
  }
260
-
261
210
  entries = entries.map(entry => _path().default.resolve(entry));
262
-
263
211
  let Parcel = require('@parcel/core').default;
264
-
265
212
  let fs = new (_fs().NodeFS)();
266
213
  let options = await normalizeOptions(command, fs);
267
214
  let parcel = new Parcel({
@@ -270,48 +217,38 @@ command) {
270
217
  defaultConfig: require.resolve('@parcel/config-default', {
271
218
  paths: [fs.cwd(), __dirname]
272
219
  }),
273
- shouldPatchConsole: true,
220
+ shouldPatchConsole: false,
274
221
  ...options
275
222
  });
276
223
  let disposable = new (_events().Disposable)();
277
224
  let unsubscribe;
278
225
  let isExiting;
279
-
280
226
  async function exit(exitCode = 0) {
281
227
  if (isExiting) {
282
228
  return;
283
229
  }
284
-
285
230
  isExiting = true;
286
-
287
231
  if (unsubscribe != null) {
288
232
  await unsubscribe();
289
233
  } else if (parcel.isProfiling) {
290
234
  await parcel.stopProfiling();
291
235
  }
292
-
293
236
  if (process.stdin.isTTY && process.stdin.isRaw) {
294
237
  // $FlowFixMe
295
238
  process.stdin.setRawMode(false);
296
239
  }
297
-
298
240
  disposable.dispose();
299
241
  process.exit(exitCode);
300
242
  }
301
-
302
243
  const isWatching = command.name() === 'watch' || command.name() === 'serve';
303
-
304
244
  if (process.stdin.isTTY) {
305
245
  // $FlowFixMe
306
246
  process.stdin.setRawMode(true);
307
-
308
247
  require('readline').emitKeypressEvents(process.stdin);
309
-
310
248
  let stream = process.stdin.on('keypress', async (char, key) => {
311
249
  if (!key.ctrl) {
312
250
  return;
313
251
  }
314
-
315
252
  switch (key.name) {
316
253
  case 'c':
317
254
  // Detect the ctrl+c key, and gracefully exit after writing the asset graph to the cache.
@@ -323,18 +260,17 @@ command) {
323
260
  // We don't use the SIGINT event for this because when run inside yarn, the parent
324
261
  // yarn process ends before Parcel and it appears that Parcel has ended while it may still
325
262
  // be cleaning up. Handling events from stdin prevents this impression.
263
+
326
264
  // Enqueue a busy message to be shown if Parcel doesn't shut down
327
265
  // within the timeout.
328
- 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.
266
+ setTimeout(() => _logger().INTERNAL_ORIGINAL_CONSOLE.log(_chalk().default.bold.yellowBright('Parcel is shutting down...')), 500);
267
+ // When watching, a 0 success code is acceptable when Parcel is interrupted with ctrl-c.
329
268
  // When building, fail with a code as if we received a SIGINT.
330
-
331
269
  await exit(isWatching ? 0 : SIGINT_EXIT_CODE);
332
270
  break;
333
-
334
271
  case 'e':
335
272
  await (parcel.isProfiling ? parcel.stopProfiling() : parcel.startProfiling());
336
273
  break;
337
-
338
274
  case 'y':
339
275
  await parcel.takeHeapSnapshot();
340
276
  break;
@@ -344,7 +280,6 @@ command) {
344
280
  stream.destroy();
345
281
  });
346
282
  }
347
-
348
283
  if (isWatching) {
349
284
  ({
350
285
  unsubscribe
@@ -353,22 +288,19 @@ command) {
353
288
  throw err;
354
289
  }
355
290
  }));
356
-
357
291
  if (command.open && options.serveOptions) {
358
292
  await (0, _utils().openInBrowser)(`${options.serveOptions.https ? 'https' : 'http'}://${options.serveOptions.host || 'localhost'}:${options.serveOptions.port}`, command.open);
359
293
  }
360
-
361
294
  if (command.watchForStdin) {
362
295
  process.stdin.on('end', async () => {
363
296
  _logger().INTERNAL_ORIGINAL_CONSOLE.log('STDIN closed, ending');
364
-
365
297
  await exit();
366
298
  });
367
299
  process.stdin.resume();
368
- } // In non-tty cases, respond to SIGINT by cleaning up. Since we're watching,
369
- // a 0 success code is acceptable.
370
-
300
+ }
371
301
 
302
+ // In non-tty cases, respond to SIGINT by cleaning up. Since we're watching,
303
+ // a 0 success code is acceptable.
372
304
  process.on('SIGINT', exit);
373
305
  process.on('SIGTERM', exit);
374
306
  } else {
@@ -380,67 +312,56 @@ command) {
380
312
  if (!(err instanceof _core().BuildError)) {
381
313
  await logUncaughtError(err);
382
314
  }
383
-
384
315
  await exit(1);
385
316
  }
386
-
387
317
  await exit();
388
318
  }
389
319
  }
390
-
391
320
  function parsePort(portValue) {
392
- let parsedPort = Number(portValue); // Throw an error if port value is invalid...
321
+ let parsedPort = Number(portValue);
393
322
 
323
+ // Throw an error if port value is invalid...
394
324
  if (!Number.isInteger(parsedPort)) {
395
325
  throw new Error(`Port ${portValue} is not a valid integer.`);
396
326
  }
397
-
398
327
  return parsedPort;
399
328
  }
400
-
401
329
  function parseOptionInt(value) {
402
330
  const parsedValue = parseInt(value, 10);
403
-
404
331
  if (isNaN(parsedValue)) {
405
332
  throw new (_commander().default.InvalidOptionArgumentError)('Must be an integer.');
406
333
  }
407
-
408
334
  return parsedValue;
409
335
  }
410
-
411
336
  async function normalizeOptions(command, inputFS) {
412
337
  var _command$autoinstall, _command$sourceMaps;
413
-
414
338
  let nodeEnv;
415
-
416
339
  if (command.name() === 'build') {
417
- nodeEnv = process.env.NODE_ENV || 'production'; // Autoinstall unless explicitly disabled or we detect a CI environment.
418
-
340
+ nodeEnv = process.env.NODE_ENV || 'production';
341
+ // Autoinstall unless explicitly disabled or we detect a CI environment.
419
342
  command.autoinstall = !(command.autoinstall === false || process.env.CI);
420
343
  } else {
421
344
  nodeEnv = process.env.NODE_ENV || 'development';
422
- } // Set process.env.NODE_ENV to a default if undefined so that it is
423
- // available in JS configs and plugins.
424
-
345
+ }
425
346
 
347
+ // Set process.env.NODE_ENV to a default if undefined so that it is
348
+ // available in JS configs and plugins.
426
349
  process.env.NODE_ENV = nodeEnv;
427
350
  let https = !!command.https;
428
-
429
351
  if (command.cert && command.key) {
430
352
  https = {
431
353
  cert: command.cert,
432
354
  key: command.key
433
355
  };
434
356
  }
435
-
436
357
  let serveOptions = false;
437
358
  let {
438
359
  host
439
- } = command; // Ensure port is valid and available
360
+ } = command;
440
361
 
362
+ // Ensure port is valid and available
441
363
  let port = parsePort(command.port || '1234');
442
364
  let originalPort = port;
443
-
444
365
  if (command.name() === 'serve' || command.hmr) {
445
366
  try {
446
367
  port = await (0, _getPort().default)({
@@ -456,10 +377,8 @@ async function normalizeOptions(command, inputFS) {
456
377
  }
457
378
  });
458
379
  }
459
-
460
380
  if (port !== originalPort) {
461
381
  let errorMessage = `Port "${originalPort}" could not be used`;
462
-
463
382
  if (command.port != null) {
464
383
  // Throw the error if the user defined a custom port
465
384
  throw new Error(errorMessage);
@@ -469,7 +388,6 @@ async function normalizeOptions(command, inputFS) {
469
388
  }
470
389
  }
471
390
  }
472
-
473
391
  if (command.name() === 'serve') {
474
392
  let {
475
393
  publicUrl
@@ -481,9 +399,7 @@ async function normalizeOptions(command, inputFS) {
481
399
  publicUrl
482
400
  };
483
401
  }
484
-
485
402
  let hmrOptions = null;
486
-
487
403
  if (command.name() !== 'build' && command.hmr !== false) {
488
404
  let hmrport = command.hmrPort ? parsePort(command.hmrPort) : port;
489
405
  let hmrhost = command.hmrHost ? command.hmrHost : host;
@@ -492,11 +408,9 @@ async function normalizeOptions(command, inputFS) {
492
408
  host: hmrhost
493
409
  };
494
410
  }
495
-
496
411
  if (command.detailedReport === true) {
497
412
  command.detailedReport = '10';
498
413
  }
499
-
500
414
  let additionalReporters = [{
501
415
  packageName: '@parcel/reporter-cli',
502
416
  resolveFrom: __filename
@@ -504,6 +418,12 @@ async function normalizeOptions(command, inputFS) {
504
418
  packageName,
505
419
  resolveFrom: _path().default.join(inputFS.cwd(), 'index')
506
420
  }))];
421
+ if (command.trace) {
422
+ additionalReporters.unshift({
423
+ packageName: '@parcel/reporter-tracer',
424
+ resolveFrom: __filename
425
+ });
426
+ }
507
427
  let mode = command.name() === 'build' ? 'production' : 'development';
508
428
  return {
509
429
  shouldDisableCache: command.cache === false,
@@ -517,6 +437,7 @@ async function normalizeOptions(command, inputFS) {
517
437
  shouldAutoInstall: (_command$autoinstall = command.autoinstall) !== null && _command$autoinstall !== void 0 ? _command$autoinstall : true,
518
438
  logLevel: command.logLevel,
519
439
  shouldProfile: command.profile,
440
+ shouldTrace: command.trace,
520
441
  shouldBuildLazily: command.lazy,
521
442
  shouldBundleIncrementally: process.env.PARCEL_INCREMENTAL_BUNDLING === 'false' ? false : true,
522
443
  detailedReport: command.detailedReport != null ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parcel",
3
- "version": "2.8.3",
3
+ "version": "2.9.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -21,24 +21,24 @@
21
21
  "node": ">= 12.0.0"
22
22
  },
23
23
  "dependencies": {
24
- "@parcel/config-default": "2.8.3",
25
- "@parcel/core": "2.8.3",
26
- "@parcel/diagnostic": "2.8.3",
27
- "@parcel/events": "2.8.3",
28
- "@parcel/fs": "2.8.3",
29
- "@parcel/logger": "2.8.3",
30
- "@parcel/package-manager": "2.8.3",
31
- "@parcel/reporter-cli": "2.8.3",
32
- "@parcel/reporter-dev-server": "2.8.3",
33
- "@parcel/utils": "2.8.3",
24
+ "@parcel/config-default": "2.9.0",
25
+ "@parcel/core": "2.9.0",
26
+ "@parcel/diagnostic": "2.9.0",
27
+ "@parcel/events": "2.9.0",
28
+ "@parcel/fs": "2.9.0",
29
+ "@parcel/logger": "2.9.0",
30
+ "@parcel/package-manager": "2.9.0",
31
+ "@parcel/reporter-cli": "2.9.0",
32
+ "@parcel/reporter-dev-server": "2.9.0",
33
+ "@parcel/reporter-tracer": "2.9.0",
34
+ "@parcel/utils": "2.9.0",
34
35
  "chalk": "^4.1.0",
35
36
  "commander": "^7.0.0",
36
- "get-port": "^4.2.0",
37
- "v8-compile-cache": "^2.0.0"
37
+ "get-port": "^4.2.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@babel/core": "^7.0.0",
41
- "@parcel/babel-register": "2.8.3"
41
+ "@parcel/babel-register": "2.9.0"
42
42
  },
43
- "gitHead": "349a6caf40ec8abb6a49fcae0765f8f8deb2073d"
43
+ "gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
44
44
  }
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
@@ -88,7 +86,8 @@ const commonOptions = {
88
86
  '--dist-dir <dir>':
89
87
  'output directory to write to when unspecified by targets',
90
88
  '--no-autoinstall': 'disable autoinstall',
91
- '--profile': 'enable build profiling',
89
+ '--profile': 'enable sampling build profiling',
90
+ '--trace': 'enable build tracing',
92
91
  '-V, --version': 'output the version number',
93
92
  '--detailed-report [count]': [
94
93
  'print the asset timings and sizes in the build report',
@@ -233,7 +232,7 @@ async function run(
233
232
  defaultConfig: require.resolve('@parcel/config-default', {
234
233
  paths: [fs.cwd(), __dirname],
235
234
  }),
236
- shouldPatchConsole: true,
235
+ shouldPatchConsole: false,
237
236
  ...options,
238
237
  });
239
238
 
@@ -464,6 +463,13 @@ async function normalizeOptions(
464
463
  })),
465
464
  ];
466
465
 
466
+ if (command.trace) {
467
+ additionalReporters.unshift({
468
+ packageName: '@parcel/reporter-tracer',
469
+ resolveFrom: __filename,
470
+ });
471
+ }
472
+
467
473
  let mode = command.name() === 'build' ? 'production' : 'development';
468
474
  return {
469
475
  shouldDisableCache: command.cache === false,
@@ -477,6 +483,7 @@ async function normalizeOptions(
477
483
  shouldAutoInstall: command.autoinstall ?? true,
478
484
  logLevel: command.logLevel,
479
485
  shouldProfile: command.profile,
486
+ shouldTrace: command.trace,
480
487
  shouldBuildLazily: command.lazy,
481
488
  shouldBundleIncrementally:
482
489
  process.env.PARCEL_INCREMENTAL_BUNDLING === 'false' ? false : true,