-
-
Notifications
You must be signed in to change notification settings - Fork 602
/
cli.js
executable file
·51 lines (38 loc) · 1.48 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
'use strict';
require('v8-compile-cache');
const execa = require('execa');
const importLocal = require('import-local');
// eslint-disable-next-line node/no-unpublished-require
const logger = require('../lib/utils/logger');
// eslint-disable-next-line node/no-unpublished-require
const parseArgs = require('../lib/utils/parse-args');
// Prefer the local installation of webpack-cli
if (importLocal(__filename)) {
// return;
}
process.title = 'webpack';
const updateNotifier = require('update-notifier');
const packageJson = require('../package.json');
const notifier = updateNotifier({
pkg: packageJson,
updateCheckInterval: 1000 * 60 * 60 * 24 * 30, // 1 month
});
if (notifier.update) {
logger.info(`Update available: ${notifier.update.latest}`);
}
const semver = require('semver');
const version = packageJson.engines.node;
if (!semver.satisfies(process.version, version)) {
const rawVersion = version.replace(/[^\d\.]*/, '');
logger.error(`webpack CLI requires at least Node v ${rawVersion}. You have ${process.version}.`);
logger.error('See https://webpack.js.org/ for migration help and similar.');
process.exit(1);
}
const [, , ...rawArgs] = process.argv;
const { cliArgs, nodeArgs } = parseArgs(rawArgs);
// eslint-disable-next-line node/no-unpublished-require
const bootstrapPath = require.resolve('../lib/bootstrap');
execa('node', [...nodeArgs, bootstrapPath, ...cliArgs], { stdio: 'inherit' }).catch(e => {
process.exit(e.exitCode);
});