@atlaspack/cli 2.12.1-dev.3502 → 2.12.1-dev.3520
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/applyOptions.js +26 -0
- package/lib/cli.js +15 -377
- package/lib/handleUncaughtException.js +78 -0
- package/lib/makeDebugCommand.js +100 -0
- package/lib/normalizeOptions.js +183 -0
- package/lib/options.js +111 -0
- package/package.json +14 -14
- package/src/applyOptions.js +26 -0
- package/src/cli.js +9 -426
- package/src/handleUncaughtException.js +46 -0
- package/src/makeDebugCommand.js +99 -0
- package/src/normalizeOptions.js +220 -0
- package/src/options.js +123 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.normalizeOptions = normalizeOptions;
|
|
7
|
+
function _diagnostic() {
|
|
8
|
+
const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
|
|
9
|
+
_diagnostic = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _getPort() {
|
|
15
|
+
const data = _interopRequireDefault(require("get-port"));
|
|
16
|
+
_getPort = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _logger() {
|
|
22
|
+
const data = require("@atlaspack/logger");
|
|
23
|
+
_logger = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _path() {
|
|
29
|
+
const data = _interopRequireDefault(require("path"));
|
|
30
|
+
_path = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
|
+
function parsePort(portValue) {
|
|
37
|
+
let parsedPort = Number(portValue);
|
|
38
|
+
|
|
39
|
+
// Throw an error if port value is invalid...
|
|
40
|
+
if (!Number.isInteger(parsedPort)) {
|
|
41
|
+
throw new Error(`Port ${portValue} is not a valid integer.`);
|
|
42
|
+
}
|
|
43
|
+
return parsedPort;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// $FlowFixMe
|
|
47
|
+
|
|
48
|
+
// $FlowFixMe
|
|
49
|
+
function shouldUseProductionDefaults(command) {
|
|
50
|
+
return command.name() === 'build' || command.production === true;
|
|
51
|
+
}
|
|
52
|
+
async function normalizeOptions(command, inputFS) {
|
|
53
|
+
let nodeEnv;
|
|
54
|
+
if (shouldUseProductionDefaults(command)) {
|
|
55
|
+
nodeEnv = process.env.NODE_ENV ?? 'production';
|
|
56
|
+
// Autoinstall unless explicitly disabled or we detect a CI environment.
|
|
57
|
+
command.autoinstall = !(command.autoinstall === false || process.env.CI);
|
|
58
|
+
} else {
|
|
59
|
+
nodeEnv = process.env.NODE_ENV ?? 'development';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Set process.env.NODE_ENV to a default if undefined so that it is
|
|
63
|
+
// available in JS configs and plugins.
|
|
64
|
+
process.env.NODE_ENV = nodeEnv;
|
|
65
|
+
let https = !!command.https;
|
|
66
|
+
if (command.cert != null && command.key != null) {
|
|
67
|
+
https = {
|
|
68
|
+
cert: command.cert,
|
|
69
|
+
key: command.key
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
let serveOptions = false;
|
|
73
|
+
let {
|
|
74
|
+
host
|
|
75
|
+
} = command;
|
|
76
|
+
|
|
77
|
+
// Ensure port is valid and available
|
|
78
|
+
let port = parsePort(command.port != null ? String(command.port) : '1234');
|
|
79
|
+
let originalPort = port;
|
|
80
|
+
if (!shouldUseProductionDefaults(command) && (command.name() === 'serve' || Boolean(command.hmr))) {
|
|
81
|
+
try {
|
|
82
|
+
port = await (0, _getPort().default)({
|
|
83
|
+
port,
|
|
84
|
+
host
|
|
85
|
+
});
|
|
86
|
+
} catch (err) {
|
|
87
|
+
throw new (_diagnostic().default)({
|
|
88
|
+
diagnostic: {
|
|
89
|
+
message: `Could not get available port: ${err.message}`,
|
|
90
|
+
origin: 'atlaspack',
|
|
91
|
+
stack: err.stack
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (port !== originalPort) {
|
|
96
|
+
let errorMessage = `Port "${originalPort}" could not be used`;
|
|
97
|
+
if (command.port != null) {
|
|
98
|
+
// Throw the error if the user defined a custom port
|
|
99
|
+
throw new Error(errorMessage);
|
|
100
|
+
} else {
|
|
101
|
+
// Atlaspack logger is not set up at this point, so just use native INTERNAL_ORIGINAL_CONSOLE
|
|
102
|
+
_logger().INTERNAL_ORIGINAL_CONSOLE.warn(errorMessage);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (command.name() === 'serve') {
|
|
107
|
+
let {
|
|
108
|
+
publicUrl
|
|
109
|
+
} = command;
|
|
110
|
+
serveOptions = {
|
|
111
|
+
https,
|
|
112
|
+
port,
|
|
113
|
+
host,
|
|
114
|
+
publicUrl
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
let hmrOptions = null;
|
|
118
|
+
if (!shouldUseProductionDefaults(command) && command.hmr !== false) {
|
|
119
|
+
let hmrport = command.hmrPort != null ? parsePort(command.hmrPort) : port;
|
|
120
|
+
let hmrhost = command.hmrHost != null ? String(command.hmrHost) : host;
|
|
121
|
+
hmrOptions = {
|
|
122
|
+
port: hmrport,
|
|
123
|
+
host: hmrhost
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (command.detailedReport === true) {
|
|
127
|
+
command.detailedReport = '10';
|
|
128
|
+
}
|
|
129
|
+
let additionalReporters = [{
|
|
130
|
+
packageName: '@atlaspack/reporter-cli',
|
|
131
|
+
resolveFrom: __filename
|
|
132
|
+
}, ...command.reporter.map(packageName => ({
|
|
133
|
+
packageName,
|
|
134
|
+
resolveFrom: _path().default.join(inputFS.cwd(), 'index')
|
|
135
|
+
}))];
|
|
136
|
+
if (command.trace) {
|
|
137
|
+
additionalReporters.unshift({
|
|
138
|
+
packageName: '@atlaspack/reporter-tracer',
|
|
139
|
+
resolveFrom: __filename
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
let mode = shouldUseProductionDefaults(command) ? 'production' : 'development';
|
|
143
|
+
const normalizeIncludeExcludeList = input => {
|
|
144
|
+
if (typeof input !== 'string') return [];
|
|
145
|
+
return input.split(',').map(value => value.trim());
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
shouldDisableCache: command.cache === false,
|
|
149
|
+
cacheDir: command.cacheDir,
|
|
150
|
+
watchDir: command.watchDir,
|
|
151
|
+
watchBackend: command.watchBackend,
|
|
152
|
+
watchIgnore: command.watchIgnore,
|
|
153
|
+
config: command.config,
|
|
154
|
+
mode,
|
|
155
|
+
hmrOptions,
|
|
156
|
+
shouldContentHash: hmrOptions ? false : command.contentHash,
|
|
157
|
+
serveOptions,
|
|
158
|
+
targets: command.target.length > 0 ? command.target : null,
|
|
159
|
+
shouldAutoInstall: command.autoinstall ?? true,
|
|
160
|
+
logLevel: command.logLevel,
|
|
161
|
+
shouldProfile: command.profile,
|
|
162
|
+
shouldTrace: command.trace,
|
|
163
|
+
shouldBuildLazily: typeof command.lazy !== 'undefined',
|
|
164
|
+
lazyIncludes: normalizeIncludeExcludeList(command.lazy),
|
|
165
|
+
lazyExcludes: normalizeIncludeExcludeList(command.lazyExclude),
|
|
166
|
+
shouldBundleIncrementally: process.env.ATLASPACK_INCREMENTAL_BUNDLING === 'false' ? false : true,
|
|
167
|
+
detailedReport: command.detailedReport != null ? {
|
|
168
|
+
assetsPerBundle: parseInt(command.detailedReport, 10)
|
|
169
|
+
} : null,
|
|
170
|
+
env: {
|
|
171
|
+
NODE_ENV: nodeEnv
|
|
172
|
+
},
|
|
173
|
+
additionalReporters,
|
|
174
|
+
defaultTargetOptions: {
|
|
175
|
+
shouldOptimize: command.optimize != null ? command.optimize : mode === 'production',
|
|
176
|
+
sourceMaps: command.sourceMaps ?? true,
|
|
177
|
+
shouldScopeHoist: command.scopeHoist,
|
|
178
|
+
publicUrl: command.publicUrl,
|
|
179
|
+
distDir: command.distDir
|
|
180
|
+
},
|
|
181
|
+
featureFlags: command.featureFlag
|
|
182
|
+
};
|
|
183
|
+
}
|
package/lib/options.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.watcherBackendChoices = exports.hmrOptions = exports.commonOptions = void 0;
|
|
7
|
+
function _logger() {
|
|
8
|
+
const data = require("@atlaspack/logger");
|
|
9
|
+
_logger = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _commander() {
|
|
15
|
+
const data = _interopRequireDefault(require("commander"));
|
|
16
|
+
_commander = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _featureFlags() {
|
|
22
|
+
const data = require("@atlaspack/feature-flags");
|
|
23
|
+
_featureFlags = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
// Only display choices available to callers OS
|
|
30
|
+
let watcherBackendChoices = exports.watcherBackendChoices = ['brute-force'];
|
|
31
|
+
switch (process.platform) {
|
|
32
|
+
case 'darwin':
|
|
33
|
+
{
|
|
34
|
+
watcherBackendChoices.push('watchman', 'fs-events');
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case 'linux':
|
|
38
|
+
{
|
|
39
|
+
watcherBackendChoices.push('watchman', 'inotify');
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'win32':
|
|
43
|
+
{
|
|
44
|
+
watcherBackendChoices.push('watchman', 'windows');
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'freebsd' || 'openbsd':
|
|
48
|
+
{
|
|
49
|
+
watcherBackendChoices.push('watchman');
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
default:
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// --no-cache, --cache-dir, --no-source-maps, --no-autoinstall, --global?, --public-url, --log-level
|
|
57
|
+
// --no-content-hash, --experimental-scope-hoisting, --detailed-report
|
|
58
|
+
const commonOptions = exports.commonOptions = {
|
|
59
|
+
'--no-cache': 'disable the filesystem cache',
|
|
60
|
+
'--config <path>': 'specify which config to use. can be a path or a package name',
|
|
61
|
+
'--cache-dir <path>': 'set the cache directory. defaults to ".parcel-cache"',
|
|
62
|
+
'--watch-dir <path>': 'set the root watch directory. defaults to nearest lockfile or source control dir.',
|
|
63
|
+
'--watch-ignore [path]': [`list of directories watcher should not be tracking for changes. defaults to ['.git', '.hg']`, dirs => dirs.split(',')],
|
|
64
|
+
'--watch-backend': new (_commander().default.Option)('--watch-backend <name>', 'set watcher backend').choices(watcherBackendChoices),
|
|
65
|
+
'--no-source-maps': 'disable sourcemaps',
|
|
66
|
+
'--target [name]': ['only build given target(s)', (val, list) => list.concat([val]), []],
|
|
67
|
+
'--log-level <level>': new (_commander().default.Option)('--log-level <level>', 'set the log level').choices(['none', 'error', 'warn', 'info', 'verbose']),
|
|
68
|
+
'--dist-dir <dir>': 'output directory to write to when unspecified by targets',
|
|
69
|
+
'--no-autoinstall': 'disable autoinstall',
|
|
70
|
+
'--profile': 'enable sampling build profiling',
|
|
71
|
+
'--trace': 'enable build tracing',
|
|
72
|
+
'-V, --version': 'output the version number',
|
|
73
|
+
'--detailed-report [count]': ['print the asset timings and sizes in the build report', parseOptionInt],
|
|
74
|
+
'--reporter <name>': ['additional reporters to run', (val, acc) => {
|
|
75
|
+
acc.push(val);
|
|
76
|
+
return acc;
|
|
77
|
+
}, []],
|
|
78
|
+
'--feature-flag <name=value>': ['sets the value of a feature flag', (value, previousValue) => {
|
|
79
|
+
let [name, val] = value.split('=');
|
|
80
|
+
if (name in _featureFlags().DEFAULT_FEATURE_FLAGS) {
|
|
81
|
+
let featureFlagValue;
|
|
82
|
+
if (typeof _featureFlags().DEFAULT_FEATURE_FLAGS[name] === 'boolean') {
|
|
83
|
+
if (val !== 'true' && val !== 'false') {
|
|
84
|
+
throw new Error(`Feature flag ${name} must be set to true or false`);
|
|
85
|
+
}
|
|
86
|
+
featureFlagValue = val === 'true';
|
|
87
|
+
}
|
|
88
|
+
previousValue[name] = featureFlagValue ?? String(val);
|
|
89
|
+
} else {
|
|
90
|
+
_logger().INTERNAL_ORIGINAL_CONSOLE.warn(`Unknown feature flag ${name} specified, it will be ignored`);
|
|
91
|
+
}
|
|
92
|
+
return previousValue;
|
|
93
|
+
}, {}]
|
|
94
|
+
};
|
|
95
|
+
const hmrOptions = exports.hmrOptions = {
|
|
96
|
+
'--no-hmr': 'disable hot module replacement',
|
|
97
|
+
'-p, --port <port>': ['set the port to serve on. defaults to $PORT or 1234', process.env.PORT],
|
|
98
|
+
'--host <host>': 'set the host to listen on, defaults to listening on all interfaces',
|
|
99
|
+
'--https': 'serves files over HTTPS',
|
|
100
|
+
'--cert <path>': 'path to certificate to use with HTTPS',
|
|
101
|
+
'--key <path>': 'path to private key to use with HTTPS',
|
|
102
|
+
'--hmr-port <port>': ['hot module replacement port', process.env.HMR_PORT],
|
|
103
|
+
'--hmr-host <host>': ['hot module replacement host', process.env.HMR_HOST]
|
|
104
|
+
};
|
|
105
|
+
function parseOptionInt(value) {
|
|
106
|
+
const parsedValue = parseInt(value, 10);
|
|
107
|
+
if (isNaN(parsedValue)) {
|
|
108
|
+
throw new (_commander().default.InvalidOptionArgumentError)('Must be an integer.');
|
|
109
|
+
}
|
|
110
|
+
return parsedValue;
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/cli",
|
|
3
|
-
"version": "2.12.1-dev.
|
|
3
|
+
"version": "2.12.1-dev.3520+8a5346e28",
|
|
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.
|
|
27
|
-
"@atlaspack/core": "2.12.1-dev.
|
|
28
|
-
"@atlaspack/diagnostic": "2.12.1-dev.
|
|
29
|
-
"@atlaspack/events": "2.12.1-dev.
|
|
30
|
-
"@atlaspack/feature-flags": "2.12.1-dev.
|
|
31
|
-
"@atlaspack/fs": "2.12.1-dev.
|
|
32
|
-
"@atlaspack/logger": "2.12.1-dev.
|
|
33
|
-
"@atlaspack/package-manager": "2.12.1-dev.
|
|
34
|
-
"@atlaspack/reporter-cli": "2.12.1-dev.
|
|
35
|
-
"@atlaspack/reporter-dev-server": "2.12.1-dev.
|
|
36
|
-
"@atlaspack/reporter-tracer": "2.12.1-dev.
|
|
37
|
-
"@atlaspack/utils": "2.12.1-dev.
|
|
26
|
+
"@atlaspack/config-default": "2.12.1-dev.3520+8a5346e28",
|
|
27
|
+
"@atlaspack/core": "2.12.1-dev.3520+8a5346e28",
|
|
28
|
+
"@atlaspack/diagnostic": "2.12.1-dev.3520+8a5346e28",
|
|
29
|
+
"@atlaspack/events": "2.12.1-dev.3520+8a5346e28",
|
|
30
|
+
"@atlaspack/feature-flags": "2.12.1-dev.3520+8a5346e28",
|
|
31
|
+
"@atlaspack/fs": "2.12.1-dev.3520+8a5346e28",
|
|
32
|
+
"@atlaspack/logger": "2.12.1-dev.3520+8a5346e28",
|
|
33
|
+
"@atlaspack/package-manager": "2.12.1-dev.3520+8a5346e28",
|
|
34
|
+
"@atlaspack/reporter-cli": "2.12.1-dev.3520+8a5346e28",
|
|
35
|
+
"@atlaspack/reporter-dev-server": "2.12.1-dev.3520+8a5346e28",
|
|
36
|
+
"@atlaspack/reporter-tracer": "2.12.1-dev.3520+8a5346e28",
|
|
37
|
+
"@atlaspack/utils": "2.12.1-dev.3520+8a5346e28",
|
|
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": "
|
|
47
|
+
"gitHead": "8a5346e28c1bb3b9cd40f1c4e77c66dd6666f1e4"
|
|
48
48
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import commander, {
|
|
4
|
+
type commander$Command,
|
|
5
|
+
type commander$Option,
|
|
6
|
+
} from 'commander';
|
|
7
|
+
|
|
8
|
+
export interface OptionsDefinition {
|
|
9
|
+
[key: string]: string | mixed[] | commander$Option;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function applyOptions(
|
|
13
|
+
cmd: commander$Command,
|
|
14
|
+
options: OptionsDefinition,
|
|
15
|
+
) {
|
|
16
|
+
for (let opt in options) {
|
|
17
|
+
const option = options[opt];
|
|
18
|
+
if (option instanceof commander.Option) {
|
|
19
|
+
cmd.addOption(option);
|
|
20
|
+
} else if (Array.isArray(option)) {
|
|
21
|
+
cmd.option(opt, ...option);
|
|
22
|
+
} else if (typeof option === 'string') {
|
|
23
|
+
cmd.option(opt, option);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|