@atlaspack/cli 2.13.7-canary.43 → 2.13.7-canary.430
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/CHANGELOG.md +786 -0
- package/bin/atlaspack.js +12 -1
- package/dist/applyOptions.js +23 -0
- package/dist/cli.js +206 -0
- package/dist/handleUncaughtException.js +48 -0
- package/dist/makeDebugCommand.js +98 -0
- package/dist/normalizeOptions.js +176 -0
- package/dist/options.js +113 -0
- package/lib/applyOptions.js +3 -0
- package/lib/bin.js +3 -3
- package/lib/cli.js +6 -3
- package/lib/makeDebugCommand.js +2 -0
- package/lib/normalizeOptions.js +26 -4
- package/lib/options.js +4 -0
- package/lib/types/applyOptions.d.ts +5 -0
- package/lib/types/cli.d.ts +1 -0
- package/lib/types/handleUncaughtException.d.ts +2 -0
- package/lib/types/makeDebugCommand.d.ts +2 -0
- package/lib/types/normalizeOptions.d.ts +42 -0
- package/lib/types/options.d.ts +4 -0
- package/package.json +20 -20
- package/src/{applyOptions.js → applyOptions.ts} +5 -8
- package/src/bin.js +2 -12
- package/src/{cli.js → cli.ts} +8 -8
- package/src/{handleUncaughtException.js → handleUncaughtException.ts} +7 -6
- package/src/{makeDebugCommand.js → makeDebugCommand.ts} +12 -9
- package/src/{normalizeOptions.js → normalizeOptions.ts} +28 -7
- package/src/{options.js → options.ts} +9 -5
- package/tsconfig.json +45 -0
- package/tsconfig.tsbuildinfo +1 -0
package/bin/atlaspack.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
if (
|
|
5
|
+
process.env.ATLASPACK_REGISTER_USE_SRC === 'true' ||
|
|
6
|
+
process.env.ATLASPACK_BUILD_ENV === 'test' ||
|
|
7
|
+
process.env.ATLASPACK_SELF_BUILD
|
|
8
|
+
) {
|
|
9
|
+
require('@atlaspack/babel-register');
|
|
10
|
+
require('../src/cli');
|
|
11
|
+
} else {
|
|
12
|
+
require('../lib/cli');
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.applyOptions = applyOptions;
|
|
7
|
+
// @ts-expect-error TS2305
|
|
8
|
+
const commander_1 = __importDefault(require("commander"));
|
|
9
|
+
function applyOptions(cmd, options) {
|
|
10
|
+
for (let opt in options) {
|
|
11
|
+
const option = options[opt];
|
|
12
|
+
if (option instanceof commander_1.default.Option) {
|
|
13
|
+
cmd.addOption(option);
|
|
14
|
+
}
|
|
15
|
+
else if (Array.isArray(option)) {
|
|
16
|
+
// @ts-expect-error TS2345
|
|
17
|
+
cmd.option(opt, ...option);
|
|
18
|
+
}
|
|
19
|
+
else if (typeof option === 'string') {
|
|
20
|
+
cmd.option(opt, option);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@atlaspack/core");
|
|
7
|
+
const fs_1 = require("@atlaspack/fs");
|
|
8
|
+
const utils_1 = require("@atlaspack/utils");
|
|
9
|
+
const events_1 = require("@atlaspack/events");
|
|
10
|
+
const logger_1 = require("@atlaspack/logger");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const commander_1 = __importDefault(require("commander"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const package_json_1 = require("../package.json");
|
|
15
|
+
const applyOptions_1 = require("./applyOptions");
|
|
16
|
+
const makeDebugCommand_1 = require("./makeDebugCommand");
|
|
17
|
+
const normalizeOptions_1 = require("./normalizeOptions");
|
|
18
|
+
const handleUncaughtException_1 = require("./handleUncaughtException");
|
|
19
|
+
const options_1 = require("./options");
|
|
20
|
+
const program = new commander_1.default.Command();
|
|
21
|
+
// Exit codes in response to signals are traditionally
|
|
22
|
+
// 128 + signal value
|
|
23
|
+
// https://tldp.org/LDP/abs/html/exitcodes.html
|
|
24
|
+
const SIGINT_EXIT_CODE = 130;
|
|
25
|
+
process.on('unhandledRejection', handleUncaughtException_1.handleUncaughtException);
|
|
26
|
+
program.storeOptionsAsProperties();
|
|
27
|
+
program.version(package_json_1.version);
|
|
28
|
+
let serve = program
|
|
29
|
+
.command('serve [input...]')
|
|
30
|
+
.description('starts a development server')
|
|
31
|
+
.option('--public-url <url>', 'the path prefix for absolute urls')
|
|
32
|
+
.option('--open [browser]', 'automatically open in specified browser, defaults to default browser')
|
|
33
|
+
.option('--watch-for-stdin', 'exit when stdin closes')
|
|
34
|
+
.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')
|
|
35
|
+
.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')
|
|
36
|
+
.option('--production', 'Run with production mode defaults')
|
|
37
|
+
.action(runCommand);
|
|
38
|
+
(0, applyOptions_1.applyOptions)(serve, options_1.hmrOptions);
|
|
39
|
+
(0, applyOptions_1.applyOptions)(serve, options_1.commonOptions);
|
|
40
|
+
let watch = program
|
|
41
|
+
.command('watch [input...]')
|
|
42
|
+
.description('starts the bundler in watch mode')
|
|
43
|
+
.option('--public-url <url>', 'the path prefix for absolute urls')
|
|
44
|
+
.option('--no-content-hash', 'disable content hashing')
|
|
45
|
+
.option('--watch-for-stdin', 'exit when stdin closes')
|
|
46
|
+
.option('--production', 'Run with production mode defaults')
|
|
47
|
+
.action(runCommand);
|
|
48
|
+
(0, applyOptions_1.applyOptions)(watch, options_1.hmrOptions);
|
|
49
|
+
(0, applyOptions_1.applyOptions)(watch, options_1.commonOptions);
|
|
50
|
+
let build = program
|
|
51
|
+
.command('build [input...]')
|
|
52
|
+
.description('bundles for production')
|
|
53
|
+
.option('--no-optimize', 'disable minification')
|
|
54
|
+
.option('--no-scope-hoist', 'disable scope-hoisting')
|
|
55
|
+
.option('--public-url <url>', 'the path prefix for absolute urls')
|
|
56
|
+
.option('--no-content-hash', 'disable content hashing')
|
|
57
|
+
.action(runCommand);
|
|
58
|
+
(0, applyOptions_1.applyOptions)(build, options_1.commonOptions);
|
|
59
|
+
program.addCommand((0, makeDebugCommand_1.makeDebugCommand)());
|
|
60
|
+
program
|
|
61
|
+
.command('help [command]')
|
|
62
|
+
.description('display help information for a command')
|
|
63
|
+
.action(function (command) {
|
|
64
|
+
let cmd = program.commands.find((c) => c.name() === command) || program;
|
|
65
|
+
cmd.help();
|
|
66
|
+
});
|
|
67
|
+
program.on('--help', function () {
|
|
68
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.log('');
|
|
69
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.log(' Run `' +
|
|
70
|
+
chalk_1.default.bold('atlaspack help <command>') +
|
|
71
|
+
'` for more information on specific commands');
|
|
72
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.log('');
|
|
73
|
+
});
|
|
74
|
+
// Override to output option description if argument was missing
|
|
75
|
+
commander_1.default.Command.prototype.optionMissingArgument = function (option) {
|
|
76
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error("error: option `%s' argument missing", option.flags);
|
|
77
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.log(program.createHelp().optionDescription(option));
|
|
78
|
+
process.exit(1);
|
|
79
|
+
};
|
|
80
|
+
// Make serve the default command except for --help
|
|
81
|
+
var args = process.argv;
|
|
82
|
+
if (args[2] === '--help' || args[2] === '-h')
|
|
83
|
+
args[2] = 'help';
|
|
84
|
+
if (!args[2] || !program.commands.some((c) => c.name() === args[2])) {
|
|
85
|
+
args.splice(2, 0, 'serve');
|
|
86
|
+
}
|
|
87
|
+
program.parse(args);
|
|
88
|
+
// @ts-expect-error TS7019
|
|
89
|
+
function runCommand(...args) {
|
|
90
|
+
// @ts-expect-error TS2556
|
|
91
|
+
run(...args).catch(handleUncaughtException_1.handleUncaughtException);
|
|
92
|
+
}
|
|
93
|
+
async function run(entries, _opts, // using pre v7 Commander options as properties
|
|
94
|
+
command) {
|
|
95
|
+
if (entries.length === 0) {
|
|
96
|
+
entries = ['.'];
|
|
97
|
+
}
|
|
98
|
+
entries = entries.map((entry) => path_1.default.resolve(entry));
|
|
99
|
+
let Atlaspack = require('@atlaspack/core').default;
|
|
100
|
+
let fs = new fs_1.NodeFS();
|
|
101
|
+
let options = await (0, normalizeOptions_1.normalizeOptions)(command, fs);
|
|
102
|
+
let atlaspack = new Atlaspack({
|
|
103
|
+
entries,
|
|
104
|
+
defaultConfig: require.resolve('@atlaspack/config-default', {
|
|
105
|
+
paths: [fs.cwd(), __dirname],
|
|
106
|
+
}),
|
|
107
|
+
shouldPatchConsole: false,
|
|
108
|
+
...options,
|
|
109
|
+
});
|
|
110
|
+
let disposable = new events_1.Disposable();
|
|
111
|
+
let unsubscribe;
|
|
112
|
+
// @ts-expect-error TS7034
|
|
113
|
+
let isExiting;
|
|
114
|
+
async function exit(exitCode = 0) {
|
|
115
|
+
// @ts-expect-error TS7005
|
|
116
|
+
if (isExiting) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
isExiting = true;
|
|
120
|
+
if (unsubscribe != null) {
|
|
121
|
+
await unsubscribe();
|
|
122
|
+
}
|
|
123
|
+
else if (atlaspack.isProfiling) {
|
|
124
|
+
await atlaspack.stopProfiling();
|
|
125
|
+
}
|
|
126
|
+
if (process.stdin.isTTY && process.stdin.isRaw) {
|
|
127
|
+
process.stdin.setRawMode(false);
|
|
128
|
+
}
|
|
129
|
+
disposable.dispose();
|
|
130
|
+
process.exit(exitCode);
|
|
131
|
+
}
|
|
132
|
+
const isWatching = command.name() === 'watch' || command.name() === 'serve';
|
|
133
|
+
if (process.stdin.isTTY) {
|
|
134
|
+
process.stdin.setRawMode(true);
|
|
135
|
+
require('readline').emitKeypressEvents(process.stdin);
|
|
136
|
+
let stream = process.stdin.on('keypress', async (char, key) => {
|
|
137
|
+
if (!key.ctrl) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
switch (key.name) {
|
|
141
|
+
case 'c':
|
|
142
|
+
// Detect the ctrl+c key, and gracefully exit after writing the asset graph to the cache.
|
|
143
|
+
// This is mostly for tools that wrap Atlaspack as a child process like yarn and npm.
|
|
144
|
+
//
|
|
145
|
+
// Setting raw mode prevents SIGINT from being sent in response to ctrl-c:
|
|
146
|
+
// https://nodejs.org/api/tty.html#tty_readstream_setrawmode_mode
|
|
147
|
+
//
|
|
148
|
+
// We don't use the SIGINT event for this because when run inside yarn, the parent
|
|
149
|
+
// yarn process ends before Atlaspack and it appears that Atlaspack has ended while it may still
|
|
150
|
+
// be cleaning up. Handling events from stdin prevents this impression.
|
|
151
|
+
//
|
|
152
|
+
// When watching, a 0 success code is acceptable when Atlaspack is interrupted with ctrl-c.
|
|
153
|
+
// When building, fail with a code as if we received a SIGINT.
|
|
154
|
+
await exit(isWatching ? 0 : SIGINT_EXIT_CODE);
|
|
155
|
+
break;
|
|
156
|
+
case 'e':
|
|
157
|
+
await (atlaspack.isProfiling
|
|
158
|
+
? atlaspack.stopProfiling()
|
|
159
|
+
: atlaspack.startProfiling());
|
|
160
|
+
break;
|
|
161
|
+
case 'y':
|
|
162
|
+
await atlaspack.takeHeapSnapshot();
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
disposable.add(() => {
|
|
167
|
+
stream.destroy();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (isWatching) {
|
|
171
|
+
// @ts-expect-error TS7006
|
|
172
|
+
({ unsubscribe } = await atlaspack.watch((err) => {
|
|
173
|
+
if (err) {
|
|
174
|
+
throw err;
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
if (command.open && options.serveOptions) {
|
|
178
|
+
await (0, utils_1.openInBrowser)(`${options.serveOptions.https ? 'https' : 'http'}://${options.serveOptions.host || 'localhost'}:${options.serveOptions.port}`, command.open);
|
|
179
|
+
}
|
|
180
|
+
if (command.watchForStdin) {
|
|
181
|
+
process.stdin.on('end', async () => {
|
|
182
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.log('STDIN closed, ending');
|
|
183
|
+
await exit();
|
|
184
|
+
});
|
|
185
|
+
process.stdin.resume();
|
|
186
|
+
}
|
|
187
|
+
// In non-tty cases, respond to SIGINT by cleaning up. Since we're watching,
|
|
188
|
+
// a 0 success code is acceptable.
|
|
189
|
+
process.on('SIGINT', () => exit());
|
|
190
|
+
process.on('SIGTERM', () => exit());
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
try {
|
|
194
|
+
await atlaspack.run();
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
// If an exception is thrown during Atlaspack.build, it is given to reporters in a
|
|
198
|
+
// buildFailure event, and has been shown to the user.
|
|
199
|
+
if (!(err instanceof core_1.BuildError)) {
|
|
200
|
+
await (0, handleUncaughtException_1.logUncaughtError)(err);
|
|
201
|
+
}
|
|
202
|
+
await exit(1);
|
|
203
|
+
}
|
|
204
|
+
await exit();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logUncaughtError = logUncaughtError;
|
|
7
|
+
exports.handleUncaughtException = handleUncaughtException;
|
|
8
|
+
const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
|
|
9
|
+
const utils_1 = require("@atlaspack/utils");
|
|
10
|
+
const logger_1 = require("@atlaspack/logger");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
async function logUncaughtError(e) {
|
|
13
|
+
if (e instanceof diagnostic_1.default) {
|
|
14
|
+
for (let diagnostic of e.diagnostics) {
|
|
15
|
+
let { message, codeframe, stack, hints, documentation } = await (0, utils_1.prettyDiagnostic)(diagnostic);
|
|
16
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error(chalk_1.default.red(message));
|
|
17
|
+
if (codeframe || stack) {
|
|
18
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error('');
|
|
19
|
+
}
|
|
20
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error(codeframe);
|
|
21
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error(stack);
|
|
22
|
+
if ((stack || codeframe) && hints.length > 0) {
|
|
23
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error('');
|
|
24
|
+
}
|
|
25
|
+
for (let h of hints) {
|
|
26
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error(chalk_1.default.blue(h));
|
|
27
|
+
}
|
|
28
|
+
if (documentation) {
|
|
29
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error(chalk_1.default.magenta.bold(documentation));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.error(e);
|
|
35
|
+
}
|
|
36
|
+
// A hack to definitely ensure we logged the uncaught exception
|
|
37
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
38
|
+
}
|
|
39
|
+
async function handleUncaughtException(exception) {
|
|
40
|
+
try {
|
|
41
|
+
await logUncaughtError(exception);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
console.error(exception);
|
|
45
|
+
console.error(err);
|
|
46
|
+
}
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeDebugCommand = makeDebugCommand;
|
|
7
|
+
const fs_1 = require("@atlaspack/fs");
|
|
8
|
+
const logger_1 = __importDefault(require("@atlaspack/logger"));
|
|
9
|
+
// @ts-expect-error TS2305
|
|
10
|
+
const commander_1 = __importDefault(require("commander"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const normalizeOptions_1 = require("./normalizeOptions");
|
|
13
|
+
const applyOptions_1 = require("./applyOptions");
|
|
14
|
+
const options_1 = require("./options");
|
|
15
|
+
const handleUncaughtException_1 = require("./handleUncaughtException");
|
|
16
|
+
function makeDebugCommand() {
|
|
17
|
+
const debug = new commander_1.default.Command('debug').description('Debug commands for atlaspack');
|
|
18
|
+
const getInstance = async (args, opts, command) => {
|
|
19
|
+
let entries = args;
|
|
20
|
+
if (entries.length === 0) {
|
|
21
|
+
entries = ['.'];
|
|
22
|
+
}
|
|
23
|
+
entries = entries.map((entry) => path_1.default.resolve(entry));
|
|
24
|
+
Object.assign(command, opts);
|
|
25
|
+
const fs = new fs_1.NodeFS();
|
|
26
|
+
const options = await (0, normalizeOptions_1.normalizeOptions)(command, fs);
|
|
27
|
+
const Atlaspack = require('@atlaspack/core').default;
|
|
28
|
+
const atlaspack = new Atlaspack({
|
|
29
|
+
entries,
|
|
30
|
+
defaultConfig: require.resolve('@atlaspack/config-default', {
|
|
31
|
+
paths: [fs.cwd(), __dirname],
|
|
32
|
+
}),
|
|
33
|
+
shouldPatchConsole: false,
|
|
34
|
+
shouldBuildLazily: false,
|
|
35
|
+
...options,
|
|
36
|
+
watchBackend: 'watchman',
|
|
37
|
+
});
|
|
38
|
+
logger_1.default.info({
|
|
39
|
+
message: 'Created atlaspack instance',
|
|
40
|
+
origin: '@atlaspack/cli',
|
|
41
|
+
});
|
|
42
|
+
return atlaspack;
|
|
43
|
+
};
|
|
44
|
+
const invalidate = debug
|
|
45
|
+
.command('invalidate [input...]')
|
|
46
|
+
.description('Run cache invalidation, then exit')
|
|
47
|
+
.action(async (args, opts, command) => {
|
|
48
|
+
try {
|
|
49
|
+
const atlaspack = await getInstance(args, opts, command);
|
|
50
|
+
await atlaspack.unstable_invalidate();
|
|
51
|
+
logger_1.default.info({
|
|
52
|
+
message: 'Done invalidating cache',
|
|
53
|
+
origin: '@atlaspack/cli',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
(0, handleUncaughtException_1.handleUncaughtException)(err);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
(0, applyOptions_1.applyOptions)(invalidate, options_1.commonOptions);
|
|
61
|
+
const buildAssetGraph = debug
|
|
62
|
+
.command('build-asset-graph [input...]')
|
|
63
|
+
.description('Build the asset graph then exit')
|
|
64
|
+
.action(async (args, opts, command) => {
|
|
65
|
+
try {
|
|
66
|
+
const atlaspack = await getInstance(args, opts, command);
|
|
67
|
+
await atlaspack.unstable_buildAssetGraph();
|
|
68
|
+
logger_1.default.info({
|
|
69
|
+
message: 'Done building asset graph',
|
|
70
|
+
origin: '@atlaspack/cli',
|
|
71
|
+
});
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
(0, handleUncaughtException_1.handleUncaughtException)(err);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
(0, applyOptions_1.applyOptions)(buildAssetGraph, options_1.commonOptions);
|
|
79
|
+
const compactCache = debug
|
|
80
|
+
.command('compact-cache [input...]')
|
|
81
|
+
.description('Compact the cache')
|
|
82
|
+
.action(async (args, opts, command) => {
|
|
83
|
+
const atlaspack = await getInstance(args, opts, command);
|
|
84
|
+
try {
|
|
85
|
+
await atlaspack.unstable_compactCache();
|
|
86
|
+
logger_1.default.info({
|
|
87
|
+
message: 'Done compacting cache',
|
|
88
|
+
origin: '@atlaspack/cli',
|
|
89
|
+
});
|
|
90
|
+
process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
(0, handleUncaughtException_1.handleUncaughtException)(err);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
(0, applyOptions_1.applyOptions)(compactCache, options_1.commonOptions);
|
|
97
|
+
return debug;
|
|
98
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizeOptions = normalizeOptions;
|
|
7
|
+
const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
|
|
8
|
+
const get_port_1 = __importDefault(require("get-port"));
|
|
9
|
+
const logger_1 = require("@atlaspack/logger");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const os_1 = __importDefault(require("os"));
|
|
12
|
+
function parsePort(portValue) {
|
|
13
|
+
let parsedPort = Number(portValue);
|
|
14
|
+
// Throw an error if port value is invalid...
|
|
15
|
+
if (!Number.isInteger(parsedPort)) {
|
|
16
|
+
throw new Error(`Port ${portValue} is not a valid integer.`);
|
|
17
|
+
}
|
|
18
|
+
return parsedPort;
|
|
19
|
+
}
|
|
20
|
+
function shouldUseProductionDefaults(command) {
|
|
21
|
+
return command.name() === 'build' || command.production === true;
|
|
22
|
+
}
|
|
23
|
+
async function normalizeOptions(command, inputFS) {
|
|
24
|
+
let nodeEnv;
|
|
25
|
+
if (shouldUseProductionDefaults(command)) {
|
|
26
|
+
nodeEnv = process.env.NODE_ENV ?? 'production';
|
|
27
|
+
// Autoinstall unless explicitly disabled or we detect a CI environment.
|
|
28
|
+
command.autoinstall = !(command.autoinstall === false || process.env.CI);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
nodeEnv = process.env.NODE_ENV ?? 'development';
|
|
32
|
+
}
|
|
33
|
+
// Set process.env.NODE_ENV to a default if undefined so that it is
|
|
34
|
+
// available in JS configs and plugins.
|
|
35
|
+
process.env.NODE_ENV = nodeEnv;
|
|
36
|
+
let https = !!command.https;
|
|
37
|
+
if (command.cert != null && command.key != null) {
|
|
38
|
+
// @ts-expect-error TS2322
|
|
39
|
+
https = {
|
|
40
|
+
cert: command.cert,
|
|
41
|
+
key: command.key,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
let serveOptions = false;
|
|
45
|
+
let { host } = command;
|
|
46
|
+
// Ensure port is valid and available
|
|
47
|
+
let port = parsePort(command.port != null ? String(command.port) : '1234');
|
|
48
|
+
let originalPort = port;
|
|
49
|
+
if (!shouldUseProductionDefaults(command) &&
|
|
50
|
+
(command.name() === 'serve' || Boolean(command.hmr))) {
|
|
51
|
+
try {
|
|
52
|
+
port = await (0, get_port_1.default)({ port, host });
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
throw new diagnostic_1.default({
|
|
56
|
+
diagnostic: {
|
|
57
|
+
message: `Could not get available port: ${err.message}`,
|
|
58
|
+
origin: 'atlaspack',
|
|
59
|
+
stack: err.stack,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (port !== originalPort) {
|
|
64
|
+
let errorMessage = `Port "${originalPort}" could not be used`;
|
|
65
|
+
if (command.port != null) {
|
|
66
|
+
// Throw the error if the user defined a custom port
|
|
67
|
+
throw new Error(errorMessage);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Atlaspack logger is not set up at this point, so just use native INTERNAL_ORIGINAL_CONSOLE
|
|
71
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.warn(errorMessage);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (command.name() === 'serve') {
|
|
76
|
+
let { publicUrl } = command;
|
|
77
|
+
// @ts-expect-error TS2322
|
|
78
|
+
serveOptions = {
|
|
79
|
+
https,
|
|
80
|
+
port,
|
|
81
|
+
host,
|
|
82
|
+
publicUrl,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
let hmrOptions = null;
|
|
86
|
+
if (!shouldUseProductionDefaults(command) && command.hmr !== false) {
|
|
87
|
+
let hmrport = command.hmrPort != null ? parsePort(command.hmrPort) : port;
|
|
88
|
+
let hmrhost = command.hmrHost != null ? String(command.hmrHost) : host;
|
|
89
|
+
hmrOptions = {
|
|
90
|
+
port: hmrport,
|
|
91
|
+
host: hmrhost,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (command.detailedReport === true) {
|
|
95
|
+
command.detailedReport = '10';
|
|
96
|
+
}
|
|
97
|
+
let additionalReporters = [
|
|
98
|
+
{ packageName: '@atlaspack/reporter-cli', resolveFrom: __filename },
|
|
99
|
+
...command.reporter.map((packageName) => ({
|
|
100
|
+
packageName,
|
|
101
|
+
resolveFrom: path_1.default.join(inputFS.cwd(), 'index'),
|
|
102
|
+
})),
|
|
103
|
+
];
|
|
104
|
+
if (command.trace) {
|
|
105
|
+
additionalReporters.unshift({
|
|
106
|
+
packageName: '@atlaspack/reporter-tracer',
|
|
107
|
+
resolveFrom: __filename,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
let mode = shouldUseProductionDefaults(command)
|
|
111
|
+
? 'production'
|
|
112
|
+
: 'development';
|
|
113
|
+
const normalizeIncludeExcludeList = (input) => {
|
|
114
|
+
if (typeof input !== 'string')
|
|
115
|
+
return [];
|
|
116
|
+
return input.split(',').map((value) => value.trim());
|
|
117
|
+
};
|
|
118
|
+
let nativeProfiler;
|
|
119
|
+
if (typeof command.profileNative === 'string') {
|
|
120
|
+
if (command.profileNative === 'instruments' ||
|
|
121
|
+
command.profileNative === 'samply') {
|
|
122
|
+
nativeProfiler = command.profileNative;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
nativeProfiler = undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (command.profileNative) {
|
|
129
|
+
nativeProfiler = os_1.default.platform() === 'darwin' ? 'instruments' : 'samply';
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
nativeProfiler = undefined;
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
shouldDisableCache: command.cache === false,
|
|
136
|
+
cacheDir: command.cacheDir,
|
|
137
|
+
projectRoot: command.projectRoot,
|
|
138
|
+
watchDir: command.watchDir,
|
|
139
|
+
watchBackend: command.watchBackend,
|
|
140
|
+
watchIgnore: command.watchIgnore,
|
|
141
|
+
config: command.config,
|
|
142
|
+
mode,
|
|
143
|
+
hmrOptions,
|
|
144
|
+
shouldContentHash: hmrOptions ? false : command.contentHash,
|
|
145
|
+
// @ts-expect-error TS2322
|
|
146
|
+
serveOptions,
|
|
147
|
+
targets: command.target.length > 0 ? command.target : null,
|
|
148
|
+
shouldAutoInstall: command.autoinstall ?? true,
|
|
149
|
+
logLevel: command.logLevel,
|
|
150
|
+
shouldProfile: command.profile,
|
|
151
|
+
nativeProfiler,
|
|
152
|
+
shouldTrace: command.trace,
|
|
153
|
+
shouldBuildLazily: typeof command.lazy !== 'undefined',
|
|
154
|
+
lazyIncludes: normalizeIncludeExcludeList(command.lazy),
|
|
155
|
+
lazyExcludes: normalizeIncludeExcludeList(command.lazyExclude),
|
|
156
|
+
shouldBundleIncrementally: process.env.ATLASPACK_INCREMENTAL_BUNDLING === 'false' ? false : true,
|
|
157
|
+
detailedReport: command.detailedReport != null
|
|
158
|
+
? {
|
|
159
|
+
// @ts-expect-error TS2345
|
|
160
|
+
assetsPerBundle: parseInt(command.detailedReport, 10),
|
|
161
|
+
}
|
|
162
|
+
: null,
|
|
163
|
+
env: {
|
|
164
|
+
NODE_ENV: nodeEnv,
|
|
165
|
+
},
|
|
166
|
+
additionalReporters,
|
|
167
|
+
defaultTargetOptions: {
|
|
168
|
+
shouldOptimize: command.optimize != null ? command.optimize : mode === 'production',
|
|
169
|
+
sourceMaps: command.sourceMaps ?? true,
|
|
170
|
+
shouldScopeHoist: command.scopeHoist,
|
|
171
|
+
publicUrl: command.publicUrl,
|
|
172
|
+
distDir: command.distDir,
|
|
173
|
+
},
|
|
174
|
+
featureFlags: command.featureFlag,
|
|
175
|
+
};
|
|
176
|
+
}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.hmrOptions = exports.commonOptions = exports.watcherBackendChoices = void 0;
|
|
7
|
+
const logger_1 = require("@atlaspack/logger");
|
|
8
|
+
const commander_1 = __importDefault(require("commander"));
|
|
9
|
+
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
10
|
+
// Only display choices available to callers OS
|
|
11
|
+
exports.watcherBackendChoices = ['brute-force'];
|
|
12
|
+
switch (process.platform) {
|
|
13
|
+
case 'darwin': {
|
|
14
|
+
exports.watcherBackendChoices.push('watchman', 'fs-events');
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case 'linux': {
|
|
18
|
+
exports.watcherBackendChoices.push('watchman', 'inotify');
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case 'win32': {
|
|
22
|
+
exports.watcherBackendChoices.push('watchman', 'windows');
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
// @ts-expect-error TS2367
|
|
26
|
+
case 'freebsd' || 'openbsd': {
|
|
27
|
+
exports.watcherBackendChoices.push('watchman');
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
// --no-cache, --cache-dir, --no-source-maps, --no-autoinstall, --global?, --public-url, --log-level
|
|
34
|
+
// --no-content-hash, --experimental-scope-hoisting, --detailed-report
|
|
35
|
+
exports.commonOptions = {
|
|
36
|
+
'--no-cache': 'disable the filesystem cache',
|
|
37
|
+
'--config <path>': 'specify which config to use. can be a path or a package name',
|
|
38
|
+
'--cache-dir <path>': 'set the cache directory. defaults to ".parcel-cache"',
|
|
39
|
+
'--project-root <path>': 'set the project root directory. defaults to nearest directory with lockfiles or version control, falls back to cwd',
|
|
40
|
+
'--watch-dir <path>': 'set the root watch directory. defaults to nearest lockfile or source control dir.',
|
|
41
|
+
'--watch-ignore [path]': [
|
|
42
|
+
`list of directories watcher should not be tracking for changes. defaults to ['.git', '.hg']`,
|
|
43
|
+
(dirs) => dirs.split(','),
|
|
44
|
+
],
|
|
45
|
+
'--watch-backend': new commander_1.default.Option('--watch-backend <name>', 'set watcher backend').choices(exports.watcherBackendChoices),
|
|
46
|
+
'--no-source-maps': 'disable sourcemaps',
|
|
47
|
+
'--target [name]': [
|
|
48
|
+
'only build given target(s)',
|
|
49
|
+
(val, list) => list.concat([val]),
|
|
50
|
+
[],
|
|
51
|
+
],
|
|
52
|
+
'--log-level <level>': new commander_1.default.Option('--log-level <level>', 'set the log level').choices(['none', 'error', 'warn', 'info', 'verbose']),
|
|
53
|
+
'--dist-dir <dir>': 'output directory to write to when unspecified by targets',
|
|
54
|
+
'--no-autoinstall': 'disable autoinstall',
|
|
55
|
+
'--profile': 'enable sampling build profiling',
|
|
56
|
+
'--profile-native [instruments|samply]': 'enable native build profiling (defaults to instruments on macOS, samply otherwise)',
|
|
57
|
+
'--trace': 'enable build tracing',
|
|
58
|
+
'-V, --version': 'output the version number',
|
|
59
|
+
'--detailed-report [count]': [
|
|
60
|
+
'print the asset timings and sizes in the build report',
|
|
61
|
+
parseOptionInt,
|
|
62
|
+
],
|
|
63
|
+
'--reporter <name>': [
|
|
64
|
+
'additional reporters to run',
|
|
65
|
+
(val, acc) => {
|
|
66
|
+
acc.push(val);
|
|
67
|
+
return acc;
|
|
68
|
+
},
|
|
69
|
+
[],
|
|
70
|
+
],
|
|
71
|
+
'--feature-flag <name=value>': [
|
|
72
|
+
'sets the value of a feature flag',
|
|
73
|
+
(value, previousValue) => {
|
|
74
|
+
let [name, val] = value.split('=');
|
|
75
|
+
if (name in feature_flags_1.DEFAULT_FEATURE_FLAGS) {
|
|
76
|
+
let featureFlagValue;
|
|
77
|
+
// @ts-expect-error TS7053
|
|
78
|
+
if (typeof feature_flags_1.DEFAULT_FEATURE_FLAGS[name] === 'boolean') {
|
|
79
|
+
if (val !== 'true' && val !== 'false') {
|
|
80
|
+
throw new Error(`Feature flag ${name} must be set to true or false`);
|
|
81
|
+
}
|
|
82
|
+
featureFlagValue = val === 'true';
|
|
83
|
+
}
|
|
84
|
+
previousValue[name] = featureFlagValue ?? String(val);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
logger_1.INTERNAL_ORIGINAL_CONSOLE.warn(`Unknown feature flag ${name} specified, it will be ignored`);
|
|
88
|
+
}
|
|
89
|
+
return previousValue;
|
|
90
|
+
},
|
|
91
|
+
{},
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
exports.hmrOptions = {
|
|
95
|
+
'--no-hmr': 'disable hot module replacement',
|
|
96
|
+
'-p, --port <port>': [
|
|
97
|
+
'set the port to serve on. defaults to $PORT or 1234',
|
|
98
|
+
process.env.PORT,
|
|
99
|
+
],
|
|
100
|
+
'--host <host>': 'set the host to listen on, defaults to listening on all interfaces',
|
|
101
|
+
'--https': 'serves files over HTTPS',
|
|
102
|
+
'--cert <path>': 'path to certificate to use with HTTPS',
|
|
103
|
+
'--key <path>': 'path to private key to use with HTTPS',
|
|
104
|
+
'--hmr-port <port>': ['hot module replacement port', process.env.HMR_PORT],
|
|
105
|
+
'--hmr-host <host>': ['hot module replacement host', process.env.HMR_HOST],
|
|
106
|
+
};
|
|
107
|
+
function parseOptionInt(value) {
|
|
108
|
+
const parsedValue = parseInt(value, 10);
|
|
109
|
+
if (isNaN(parsedValue)) {
|
|
110
|
+
throw new commander_1.default.InvalidOptionArgumentError('Must be an integer.');
|
|
111
|
+
}
|
|
112
|
+
return parsedValue;
|
|
113
|
+
}
|