@atlaspack/cli 2.12.1-dev.3450 → 2.12.1-dev.3466

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 +9 -6
  2. package/package.json +14 -14
  3. package/src/cli.js +25 -14
package/lib/cli.js CHANGED
@@ -217,10 +217,10 @@ function applyOptions(cmd, options) {
217
217
  }
218
218
  }
219
219
  }
220
- 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 [includes]', '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').option('--lazy-exclude <excludes>', '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').action(runCommand);
220
+ 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 [includes]', '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').option('--lazy-exclude <excludes>', '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').option('--production', 'Run with production mode defaults').action(runCommand);
221
221
  applyOptions(serve, hmrOptions);
222
222
  applyOptions(serve, commonOptions);
223
- 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);
223
+ 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').option('--production', 'Run with production mode defaults').action(runCommand);
224
224
  applyOptions(watch, hmrOptions);
225
225
  applyOptions(watch, commonOptions);
226
226
  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);
@@ -415,9 +415,12 @@ function parseOptionInt(value) {
415
415
  }
416
416
  return parsedValue;
417
417
  }
418
+ function shouldUseProductionDefaults(command) {
419
+ return command.name() === 'build' || command.production === true;
420
+ }
418
421
  async function normalizeOptions(command, inputFS) {
419
422
  let nodeEnv;
420
- if (command.name() === 'build') {
423
+ if (shouldUseProductionDefaults(command)) {
421
424
  nodeEnv = process.env.NODE_ENV || 'production';
422
425
  // Autoinstall unless explicitly disabled or we detect a CI environment.
423
426
  command.autoinstall = !(command.autoinstall === false || process.env.CI);
@@ -443,7 +446,7 @@ async function normalizeOptions(command, inputFS) {
443
446
  // Ensure port is valid and available
444
447
  let port = parsePort(command.port || '1234');
445
448
  let originalPort = port;
446
- if (command.name() === 'serve' || command.hmr) {
449
+ if (!shouldUseProductionDefaults(command) && (command.name() === 'serve' || command.hmr)) {
447
450
  try {
448
451
  port = await (0, _getPort().default)({
449
452
  port,
@@ -481,7 +484,7 @@ async function normalizeOptions(command, inputFS) {
481
484
  };
482
485
  }
483
486
  let hmrOptions = null;
484
- if (command.name() !== 'build' && command.hmr !== false) {
487
+ if (!shouldUseProductionDefaults(command) && command.hmr !== false) {
485
488
  let hmrport = command.hmrPort ? parsePort(command.hmrPort) : port;
486
489
  let hmrhost = command.hmrHost ? command.hmrHost : host;
487
490
  hmrOptions = {
@@ -505,7 +508,7 @@ async function normalizeOptions(command, inputFS) {
505
508
  resolveFrom: __filename
506
509
  });
507
510
  }
508
- let mode = command.name() === 'build' ? 'production' : 'development';
511
+ let mode = shouldUseProductionDefaults(command) ? 'production' : 'development';
509
512
  const normalizeIncludeExcludeList = input => {
510
513
  if (typeof input !== 'string') return [];
511
514
  return input.split(',').map(value => value.trim());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/cli",
3
- "version": "2.12.1-dev.3450+58845ef87",
3
+ "version": "2.12.1-dev.3466+9a12fb8bd",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -23,18 +23,18 @@
23
23
  "node": ">= 16.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@atlaspack/config-default": "2.12.1-dev.3450+58845ef87",
27
- "@atlaspack/core": "2.12.1-dev.3450+58845ef87",
28
- "@atlaspack/diagnostic": "2.12.1-dev.3450+58845ef87",
29
- "@atlaspack/events": "2.12.1-dev.3450+58845ef87",
30
- "@atlaspack/feature-flags": "2.12.1-dev.3450+58845ef87",
31
- "@atlaspack/fs": "2.12.1-dev.3450+58845ef87",
32
- "@atlaspack/logger": "2.12.1-dev.3450+58845ef87",
33
- "@atlaspack/package-manager": "2.12.1-dev.3450+58845ef87",
34
- "@atlaspack/reporter-cli": "2.12.1-dev.3450+58845ef87",
35
- "@atlaspack/reporter-dev-server": "2.12.1-dev.3450+58845ef87",
36
- "@atlaspack/reporter-tracer": "2.12.1-dev.3450+58845ef87",
37
- "@atlaspack/utils": "2.12.1-dev.3450+58845ef87",
26
+ "@atlaspack/config-default": "2.12.1-dev.3466+9a12fb8bd",
27
+ "@atlaspack/core": "2.12.1-dev.3466+9a12fb8bd",
28
+ "@atlaspack/diagnostic": "2.12.1-dev.3466+9a12fb8bd",
29
+ "@atlaspack/events": "2.12.1-dev.3466+9a12fb8bd",
30
+ "@atlaspack/feature-flags": "2.12.1-dev.3466+9a12fb8bd",
31
+ "@atlaspack/fs": "2.12.1-dev.3466+9a12fb8bd",
32
+ "@atlaspack/logger": "2.12.1-dev.3466+9a12fb8bd",
33
+ "@atlaspack/package-manager": "2.12.1-dev.3466+9a12fb8bd",
34
+ "@atlaspack/reporter-cli": "2.12.1-dev.3466+9a12fb8bd",
35
+ "@atlaspack/reporter-dev-server": "2.12.1-dev.3466+9a12fb8bd",
36
+ "@atlaspack/reporter-tracer": "2.12.1-dev.3466+9a12fb8bd",
37
+ "@atlaspack/utils": "2.12.1-dev.3466+9a12fb8bd",
38
38
  "chalk": "^4.1.0",
39
39
  "commander": "^7.0.0",
40
40
  "get-port": "^4.2.0"
@@ -44,5 +44,5 @@
44
44
  "@babel/core": "^7.22.11",
45
45
  "rimraf": "^5.0.5"
46
46
  },
47
- "gitHead": "58845ef87446fcedb7d7d8876440c64184645cbb"
47
+ "gitHead": "9a12fb8bd1b72e407ed043e20337dc60fbec9cbe"
48
48
  }
package/src/cli.js CHANGED
@@ -47,10 +47,10 @@ async function logUncaughtError(e: mixed) {
47
47
  }
48
48
 
49
49
  // A hack to definitely ensure we logged the uncaught exception
50
- await new Promise(resolve => setTimeout(resolve, 100));
50
+ await new Promise((resolve) => setTimeout(resolve, 100));
51
51
  }
52
52
 
53
- const handleUncaughtException = async exception => {
53
+ const handleUncaughtException = async (exception) => {
54
54
  try {
55
55
  await logUncaughtError(exception);
56
56
  } catch (err) {
@@ -100,7 +100,7 @@ const commonOptions = {
100
100
  'set the root watch directory. defaults to nearest lockfile or source control dir.',
101
101
  '--watch-ignore [path]': [
102
102
  `list of directories watcher should not be tracking for changes. defaults to ['.git', '.hg']`,
103
- dirs => dirs.split(','),
103
+ (dirs) => dirs.split(','),
104
104
  ],
105
105
  '--watch-backend': new commander.Option(
106
106
  '--watch-backend <name>',
@@ -203,6 +203,7 @@ let serve = program
203
203
  '--lazy-exclude <excludes>',
204
204
  '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',
205
205
  )
206
+ .option('--production', 'Run with production mode defaults')
206
207
  .action(runCommand);
207
208
 
208
209
  applyOptions(serve, hmrOptions);
@@ -214,6 +215,7 @@ let watch = program
214
215
  .option('--public-url <url>', 'the path prefix for absolute urls')
215
216
  .option('--no-content-hash', 'disable content hashing')
216
217
  .option('--watch-for-stdin', 'exit when stdin closes')
218
+ .option('--production', 'Run with production mode defaults')
217
219
  .action(runCommand);
218
220
 
219
221
  applyOptions(watch, hmrOptions);
@@ -243,7 +245,7 @@ function makeDebugCommand() {
243
245
  if (entries.length === 0) {
244
246
  entries = ['.'];
245
247
  }
246
- entries = entries.map(entry => path.resolve(entry));
248
+ entries = entries.map((entry) => path.resolve(entry));
247
249
 
248
250
  Object.assign(command, opts);
249
251
 
@@ -281,7 +283,7 @@ program
281
283
  .command('help [command]')
282
284
  .description('display help information for a command')
283
285
  .action(function (command) {
284
- let cmd = program.commands.find(c => c.name() === command) || program;
286
+ let cmd = program.commands.find((c) => c.name() === command) || program;
285
287
  cmd.help();
286
288
  });
287
289
 
@@ -310,7 +312,7 @@ commander.Command.prototype.optionMissingArgument = function (option) {
310
312
  var args = process.argv;
311
313
  if (args[2] === '--help' || args[2] === '-h') args[2] = 'help';
312
314
 
313
- if (!args[2] || !program.commands.some(c => c.name() === args[2])) {
315
+ if (!args[2] || !program.commands.some((c) => c.name() === args[2])) {
314
316
  args.splice(2, 0, 'serve');
315
317
  }
316
318
 
@@ -329,7 +331,7 @@ async function run(
329
331
  entries = ['.'];
330
332
  }
331
333
 
332
- entries = entries.map(entry => path.resolve(entry));
334
+ entries = entries.map((entry) => path.resolve(entry));
333
335
 
334
336
  let Atlaspack = require('@atlaspack/core').default;
335
337
  let fs = new NodeFS();
@@ -411,7 +413,7 @@ async function run(
411
413
  }
412
414
 
413
415
  if (isWatching) {
414
- ({unsubscribe} = await atlaspack.watch(err => {
416
+ ({unsubscribe} = await atlaspack.watch((err) => {
415
417
  if (err) {
416
418
  throw err;
417
419
  }
@@ -474,12 +476,16 @@ function parseOptionInt(value) {
474
476
  return parsedValue;
475
477
  }
476
478
 
479
+ function shouldUseProductionDefaults(command) {
480
+ return command.name() === 'build' || command.production === true;
481
+ }
482
+
477
483
  async function normalizeOptions(
478
484
  command,
479
485
  inputFS,
480
486
  ): Promise<InitialAtlaspackOptions> {
481
487
  let nodeEnv;
482
- if (command.name() === 'build') {
488
+ if (shouldUseProductionDefaults(command)) {
483
489
  nodeEnv = process.env.NODE_ENV || 'production';
484
490
  // Autoinstall unless explicitly disabled or we detect a CI environment.
485
491
  command.autoinstall = !(command.autoinstall === false || process.env.CI);
@@ -505,7 +511,10 @@ async function normalizeOptions(
505
511
  // Ensure port is valid and available
506
512
  let port = parsePort(command.port || '1234');
507
513
  let originalPort = port;
508
- if (command.name() === 'serve' || command.hmr) {
514
+ if (
515
+ !shouldUseProductionDefaults(command) &&
516
+ (command.name() === 'serve' || command.hmr)
517
+ ) {
509
518
  try {
510
519
  port = await getPort({port, host});
511
520
  } catch (err) {
@@ -542,7 +551,7 @@ async function normalizeOptions(
542
551
  }
543
552
 
544
553
  let hmrOptions = null;
545
- if (command.name() !== 'build' && command.hmr !== false) {
554
+ if (!shouldUseProductionDefaults(command) && command.hmr !== false) {
546
555
  let hmrport = command.hmrPort ? parsePort(command.hmrPort) : port;
547
556
  let hmrhost = command.hmrHost ? command.hmrHost : host;
548
557
 
@@ -558,7 +567,7 @@ async function normalizeOptions(
558
567
 
559
568
  let additionalReporters = [
560
569
  {packageName: '@atlaspack/reporter-cli', resolveFrom: __filename},
561
- ...(command.reporter: Array<string>).map(packageName => ({
570
+ ...(command.reporter: Array<string>).map((packageName) => ({
562
571
  packageName,
563
572
  resolveFrom: path.join(inputFS.cwd(), 'index'),
564
573
  })),
@@ -571,11 +580,13 @@ async function normalizeOptions(
571
580
  });
572
581
  }
573
582
 
574
- let mode = command.name() === 'build' ? 'production' : 'development';
583
+ let mode = shouldUseProductionDefaults(command)
584
+ ? 'production'
585
+ : 'development';
575
586
 
576
587
  const normalizeIncludeExcludeList = (input?: string): string[] => {
577
588
  if (typeof input !== 'string') return [];
578
- return input.split(',').map(value => value.trim());
589
+ return input.split(',').map((value) => value.trim());
579
590
  };
580
591
 
581
592
  return {