@automattic/vip 3.25.0 → 3.25.2-dev.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.
- package/AGENTS.md +6 -0
- package/CLAUDE.md +1 -0
- package/assets/dev-env.lando.template.yml.ejs +5 -0
- package/dist/bin/vip-dev-env-exec.js +18 -1
- package/dist/bin/vip-import.js +1 -1
- package/dist/bin/vip-sea.js +19 -0
- package/dist/bin/vip.js +111 -69
- package/dist/commands/dev-env-import-sql.js +1 -1
- package/dist/lib/cli/command.js +224 -53
- package/dist/lib/cli/config.js +13 -5
- package/dist/lib/cli/exit.js +2 -1
- package/dist/lib/cli/internal-bin-loader.js +81 -0
- package/dist/lib/cli/runtime-mode.js +21 -0
- package/dist/lib/cli/sea-dispatch.js +88 -0
- package/dist/lib/cli/sea-runtime.js +75 -0
- package/dist/lib/constants/dev-environment.js +1 -1
- package/dist/lib/dev-environment/dev-environment-cli.js +9 -2
- package/dist/lib/dev-environment/dev-environment-core.js +62 -4
- package/dist/lib/dev-environment/dev-environment-lando.js +47 -10
- package/dist/lib/dev-environment/lando-loader.js +48 -0
- package/docs/COMMANDER-MIGRATION.md +55 -0
- package/docs/SEA-BUILD-SIGNING.md +171 -0
- package/helpers/build-sea.js +167 -0
- package/npm-shrinkwrap.json +877 -627
- package/package.json +9 -6
package/dist/lib/cli/command.js
CHANGED
|
@@ -4,14 +4,18 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.containsAppEnvArgument = containsAppEnvArgument;
|
|
5
5
|
exports.default = _default;
|
|
6
6
|
exports.getEnvIdentifier = getEnvIdentifier;
|
|
7
|
-
var _args = _interopRequireDefault(require("args"));
|
|
8
7
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
8
|
+
var _commander = require("commander");
|
|
9
9
|
var _debug = _interopRequireDefault(require("debug"));
|
|
10
10
|
var _enquirer = require("enquirer");
|
|
11
11
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
12
|
+
var _nodeChild_process = require("node:child_process");
|
|
13
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
14
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
12
15
|
var _envAlias = require("./envAlias");
|
|
13
16
|
var exit = _interopRequireWildcard(require("./exit"));
|
|
14
17
|
var _format = require("./format");
|
|
18
|
+
var _internalBinLoader = require("./internal-bin-loader");
|
|
15
19
|
var _prompt = require("./prompt");
|
|
16
20
|
var _package = _interopRequireDefault(require("../../../package.json"));
|
|
17
21
|
var _api = _interopRequireDefault(require("../../lib/api"));
|
|
@@ -37,15 +41,209 @@ process.on('uncaughtException', uncaughtError);
|
|
|
37
41
|
process.on('unhandledRejection', uncaughtError);
|
|
38
42
|
let _opts = {};
|
|
39
43
|
let alreadyConfirmedDebugAttachment = false;
|
|
44
|
+
const RESERVED_AUTO_SHORT_ALIASES = new Set(['h', 'v', 'd']);
|
|
45
|
+
function normalizeUsage(program, usage) {
|
|
46
|
+
if (!usage) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const [rootCommand, ...rest] = usage.trim().split(/\s+/);
|
|
50
|
+
if (rootCommand) {
|
|
51
|
+
program.name(rootCommand);
|
|
52
|
+
}
|
|
53
|
+
if (rest.length) {
|
|
54
|
+
const usageString = rest.join(' ');
|
|
55
|
+
program.usage(usageString.includes('[options]') ? usageString : `${usageString} [options]`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function createOptionDefinition(name, description, defaultValue, parseFn, usedShortNames) {
|
|
59
|
+
const isArray = Array.isArray(name);
|
|
60
|
+
const shortName = isArray ? name[0] : null;
|
|
61
|
+
const longName = isArray ? name[1] : name;
|
|
62
|
+
const normalizedLongName = String(longName).trim().replace(/^--?/, '');
|
|
63
|
+
const explicitShortName = shortName ? String(shortName).trim().replace(/^-/, '') : null;
|
|
64
|
+
let normalizedShortName = explicitShortName;
|
|
65
|
+
if (!normalizedShortName) {
|
|
66
|
+
const autoShortName = normalizedLongName.charAt(0);
|
|
67
|
+
const canUseAutoShortName = autoShortName && !RESERVED_AUTO_SHORT_ALIASES.has(autoShortName) && !usedShortNames.has(autoShortName);
|
|
68
|
+
if (canUseAutoShortName) {
|
|
69
|
+
normalizedShortName = autoShortName;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (normalizedShortName) {
|
|
73
|
+
usedShortNames.add(normalizedShortName);
|
|
74
|
+
}
|
|
75
|
+
const isBooleanOption = typeof defaultValue === 'boolean';
|
|
76
|
+
const usesOptionalValue = !isBooleanOption;
|
|
77
|
+
const parseOptionValue = value => {
|
|
78
|
+
if (parseFn) {
|
|
79
|
+
return parseFn(value);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
};
|
|
83
|
+
let parser;
|
|
84
|
+
if (usesOptionalValue) {
|
|
85
|
+
parser = (value, previousValue) => {
|
|
86
|
+
const parsedValue = parseOptionValue(value);
|
|
87
|
+
if (previousValue === undefined) {
|
|
88
|
+
return parsedValue;
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(previousValue)) {
|
|
91
|
+
return [...previousValue, parsedValue];
|
|
92
|
+
}
|
|
93
|
+
return [previousValue, parsedValue];
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
let flags = `--${normalizedLongName}`;
|
|
97
|
+
if (usesOptionalValue) {
|
|
98
|
+
flags += ' [value]';
|
|
99
|
+
}
|
|
100
|
+
if (normalizedShortName) {
|
|
101
|
+
flags = `-${normalizedShortName}, ${flags}`;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
flags,
|
|
105
|
+
description,
|
|
106
|
+
defaultValue,
|
|
107
|
+
parser
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
class CommanderArgsCompat {
|
|
111
|
+
constructor(opts) {
|
|
112
|
+
this.details = {
|
|
113
|
+
commands: []
|
|
114
|
+
};
|
|
115
|
+
this.sub = [];
|
|
116
|
+
this.examplesList = [];
|
|
117
|
+
this.usedShortNames = new Set();
|
|
118
|
+
this._opts = opts;
|
|
119
|
+
this.program = new _commander.Command();
|
|
120
|
+
this.program.allowUnknownOption(true);
|
|
121
|
+
this.program.allowExcessArguments(true);
|
|
122
|
+
this.program.helpOption(false);
|
|
123
|
+
normalizeUsage(this.program, this._opts.usage);
|
|
124
|
+
}
|
|
125
|
+
option(name, description, defaultValue, parseFn) {
|
|
126
|
+
const definition = createOptionDefinition(name, description, defaultValue, parseFn, this.usedShortNames);
|
|
127
|
+
const {
|
|
128
|
+
flags,
|
|
129
|
+
parser
|
|
130
|
+
} = definition;
|
|
131
|
+
if (parser && defaultValue !== undefined) {
|
|
132
|
+
this.program.option(flags, description, parser, defaultValue);
|
|
133
|
+
} else if (parser) {
|
|
134
|
+
this.program.option(flags, description, parser);
|
|
135
|
+
} else if (defaultValue !== undefined) {
|
|
136
|
+
this.program.option(flags, description, defaultValue);
|
|
137
|
+
} else {
|
|
138
|
+
this.program.option(flags, description);
|
|
139
|
+
}
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
command(name, description = '') {
|
|
143
|
+
this.details.commands.push({
|
|
144
|
+
usage: name,
|
|
145
|
+
description
|
|
146
|
+
});
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
example(usage, description) {
|
|
150
|
+
this.examplesList.push({
|
|
151
|
+
usage,
|
|
152
|
+
description
|
|
153
|
+
});
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
examples(examples = []) {
|
|
157
|
+
for (const example of examples) {
|
|
158
|
+
this.example(example.usage, example.description);
|
|
159
|
+
}
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
showVersion() {
|
|
163
|
+
console.log(_package.default.version);
|
|
164
|
+
process.exit(0);
|
|
165
|
+
}
|
|
166
|
+
showHelp() {
|
|
167
|
+
const lines = [this.program.helpInformation().trimEnd()];
|
|
168
|
+
if (this.details.commands.length) {
|
|
169
|
+
lines.push('');
|
|
170
|
+
lines.push('Commands:');
|
|
171
|
+
for (const entry of this.details.commands) {
|
|
172
|
+
const commandName = entry.usage.padEnd(26, ' ');
|
|
173
|
+
lines.push(` ${commandName}${entry.description}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (this.examplesList.length) {
|
|
177
|
+
lines.push('');
|
|
178
|
+
lines.push('Examples:');
|
|
179
|
+
for (const example of this.examplesList) {
|
|
180
|
+
lines.push(` - ${example.description}`);
|
|
181
|
+
lines.push(` $ ${example.usage}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
console.log(lines.join('\n'));
|
|
185
|
+
process.exit(0);
|
|
186
|
+
}
|
|
187
|
+
isDefined(value, key) {
|
|
188
|
+
if (key !== 'commands') {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
return this.details.commands.some(entry => entry.usage === value);
|
|
192
|
+
}
|
|
193
|
+
parse(argv) {
|
|
194
|
+
this.program.parse(argv, {
|
|
195
|
+
from: 'node'
|
|
196
|
+
});
|
|
197
|
+
this.sub = this.program.args.slice();
|
|
198
|
+
return this.program.opts();
|
|
199
|
+
}
|
|
200
|
+
async executeSubcommand(argv, parsedAlias, subcommand) {
|
|
201
|
+
const currentScript = argv[1];
|
|
202
|
+
const extension = _nodePath.default.extname(currentScript);
|
|
203
|
+
const baseScriptPath = extension ? currentScript.slice(0, -extension.length) : currentScript;
|
|
204
|
+
const childScriptPath = extension ? `${baseScriptPath}-${subcommand}${extension}` : `${baseScriptPath}-${subcommand}`;
|
|
205
|
+
const aliasFromRawArgv = argv.slice(2).find(arg => (0, _envAlias.isAlias)(arg));
|
|
206
|
+
const subcommandIndex = parsedAlias.argv.findIndex((arg, index) => {
|
|
207
|
+
return index > 1 && arg === subcommand;
|
|
208
|
+
});
|
|
209
|
+
let childArgs = subcommandIndex > -1 ? parsedAlias.argv.slice(subcommandIndex + 1) : [];
|
|
210
|
+
if (aliasFromRawArgv) {
|
|
211
|
+
childArgs = [aliasFromRawArgv, ...childArgs];
|
|
212
|
+
}
|
|
213
|
+
let runResult;
|
|
214
|
+
if (_nodeFs.default.existsSync(childScriptPath)) {
|
|
215
|
+
runResult = (0, _nodeChild_process.spawnSync)(process.execPath, [childScriptPath, ...childArgs], {
|
|
216
|
+
stdio: 'inherit',
|
|
217
|
+
env: process.env
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
const fallbackCommand = `${_nodePath.default.basename(baseScriptPath)}-${subcommand}`;
|
|
221
|
+
if (process.env.VIP_CLI_SEA_MODE === '1' && (0, _internalBinLoader.hasInternalBin)(fallbackCommand)) {
|
|
222
|
+
process.argv = [process.argv[0], process.argv[1], ...childArgs];
|
|
223
|
+
const loaded = await (0, _internalBinLoader.loadInternalBin)(fallbackCommand);
|
|
224
|
+
if (!loaded) {
|
|
225
|
+
throw new Error(`Unable to load SEA subcommand "${fallbackCommand}"`);
|
|
226
|
+
}
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
runResult = (0, _nodeChild_process.spawnSync)(fallbackCommand, childArgs, {
|
|
230
|
+
stdio: 'inherit',
|
|
231
|
+
env: process.env,
|
|
232
|
+
shell: process.platform === 'win32'
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (runResult.error) {
|
|
236
|
+
throw runResult.error;
|
|
237
|
+
}
|
|
238
|
+
process.exit(runResult.status ?? 1);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
40
241
|
|
|
41
242
|
/**
|
|
42
243
|
* @param {string[]} argv
|
|
43
244
|
*/
|
|
44
245
|
// eslint-disable-next-line complexity
|
|
45
|
-
|
|
46
|
-
if (process.platform !== 'win32' && argv[1]?.endsWith('.js')) {
|
|
47
|
-
argv[1] = argv[1].slice(0, -3);
|
|
48
|
-
}
|
|
246
|
+
CommanderArgsCompat.prototype.argv = async function (argv, cb) {
|
|
49
247
|
if (process.execArgv.includes('--inspect') && !alreadyConfirmedDebugAttachment) {
|
|
50
248
|
await (0, _enquirer.prompt)({
|
|
51
249
|
type: 'confirm',
|
|
@@ -55,25 +253,13 @@ _args.default.argv = async function (argv, cb) {
|
|
|
55
253
|
alreadyConfirmedDebugAttachment = true;
|
|
56
254
|
}
|
|
57
255
|
const parsedAlias = (0, _envAlias.parseEnvAliasFromArgv)(argv);
|
|
256
|
+
const options = this.parse(parsedAlias.argv);
|
|
58
257
|
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// We can pass "vip command subcommand" to the name param for more accurate
|
|
65
|
-
// usage text:
|
|
66
|
-
// Usage: vip command subcommand [options]
|
|
67
|
-
//
|
|
68
|
-
// It also allows us to represent required args in usage text:
|
|
69
|
-
// Usage: vip command subcommand <arg1> <arg2> [options]
|
|
70
|
-
const name = _opts.usage || null;
|
|
71
|
-
const options = this.parse(parsedAlias.argv, {
|
|
72
|
-
help: false,
|
|
73
|
-
name,
|
|
74
|
-
version: false,
|
|
75
|
-
debug: false
|
|
76
|
-
});
|
|
258
|
+
// If there's a sub-command, run that instead
|
|
259
|
+
if (this.isDefined(this.sub[0], 'commands')) {
|
|
260
|
+
await this.executeSubcommand(argv, parsedAlias, this.sub[0]);
|
|
261
|
+
return {};
|
|
262
|
+
}
|
|
77
263
|
if (_opts.format && !options.format) {
|
|
78
264
|
options.format = 'table';
|
|
79
265
|
}
|
|
@@ -105,12 +291,7 @@ _args.default.argv = async function (argv, cb) {
|
|
|
105
291
|
});
|
|
106
292
|
exit.withError(error);
|
|
107
293
|
}
|
|
108
|
-
|
|
109
|
-
// If there's a sub-command, run that instead
|
|
110
|
-
if (this.isDefined(this.sub[0], 'commands')) {
|
|
111
|
-
return {};
|
|
112
|
-
}
|
|
113
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
294
|
+
if (process.env.NODE_ENV !== 'test' && process.env.VIP_CLI_SEA_MODE !== '1') {
|
|
114
295
|
const {
|
|
115
296
|
default: updateNotifier
|
|
116
297
|
} = await import('update-notifier');
|
|
@@ -121,18 +302,7 @@ _args.default.argv = async function (argv, cb) {
|
|
|
121
302
|
isGlobal: true
|
|
122
303
|
});
|
|
123
304
|
}
|
|
124
|
-
|
|
125
|
-
// `help` and `version` are always defined as subcommands
|
|
126
|
-
const customCommands = this.details.commands.filter(command => {
|
|
127
|
-
switch (command.usage) {
|
|
128
|
-
case 'help':
|
|
129
|
-
case 'version':
|
|
130
|
-
case 'debug':
|
|
131
|
-
return false;
|
|
132
|
-
default:
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
305
|
+
const customCommands = this.details.commands;
|
|
136
306
|
|
|
137
307
|
// Show help if no args passed
|
|
138
308
|
if (Boolean(customCommands.length) && !this.sub.length) {
|
|
@@ -152,7 +322,7 @@ _args.default.argv = async function (argv, cb) {
|
|
|
152
322
|
|
|
153
323
|
// Show help if subcommand is invalid
|
|
154
324
|
const subCommands = this.details.commands.map(cmd => cmd.usage);
|
|
155
|
-
if (!_opts.wildcardCommand && this.sub[_opts.requiredArgs] && 0 > subCommands.indexOf(this.sub[_opts.requiredArgs])) {
|
|
325
|
+
if (!_opts.wildcardCommand && this.sub[_opts.requiredArgs] && subCommands.length && 0 > subCommands.indexOf(this.sub[_opts.requiredArgs])) {
|
|
156
326
|
const subcommand = this.sub.join(' ');
|
|
157
327
|
await (0, _tracker.trackEvent)('command_validation_error', {
|
|
158
328
|
error: `Invalid subcommand: ${subcommand}`
|
|
@@ -368,7 +538,7 @@ _args.default.argv = async function (argv, cb) {
|
|
|
368
538
|
value: `${_chalk.default.cyan(launched)}`
|
|
369
539
|
});
|
|
370
540
|
}
|
|
371
|
-
if (this.sub) {
|
|
541
|
+
if (this.sub.length) {
|
|
372
542
|
info.push({
|
|
373
543
|
key: 'SQL File',
|
|
374
544
|
value: `${_chalk.default.blueBright(this.sub)}`
|
|
@@ -441,7 +611,7 @@ _args.default.argv = async function (argv, cb) {
|
|
|
441
611
|
}
|
|
442
612
|
case 'import-media':
|
|
443
613
|
{
|
|
444
|
-
const isUrl = this.sub && (String(this.sub).startsWith('http://') || String(this.sub).startsWith('https://'));
|
|
614
|
+
const isUrl = this.sub.length && (String(this.sub).startsWith('http://') || String(this.sub).startsWith('https://'));
|
|
445
615
|
const archiveLabel = isUrl ? 'Archive URL' : 'Archive Path';
|
|
446
616
|
info.push({
|
|
447
617
|
key: archiveLabel,
|
|
@@ -536,7 +706,7 @@ function validateOpts(opts) {
|
|
|
536
706
|
}
|
|
537
707
|
|
|
538
708
|
/**
|
|
539
|
-
* @returns {
|
|
709
|
+
* @returns {CommanderArgsCompat}
|
|
540
710
|
*/
|
|
541
711
|
function _default(opts) {
|
|
542
712
|
_opts = {
|
|
@@ -550,24 +720,25 @@ function _default(opts) {
|
|
|
550
720
|
wildcardCommand: false,
|
|
551
721
|
...opts
|
|
552
722
|
};
|
|
723
|
+
const args = new CommanderArgsCompat(_opts);
|
|
553
724
|
if (_opts.appContext || _opts.requireConfirm) {
|
|
554
|
-
|
|
725
|
+
args.option('app', 'Target an application. Accepts a string value for the application name or an integer for the application ID.');
|
|
555
726
|
}
|
|
556
727
|
if (_opts.envContext || _opts.childEnvContext) {
|
|
557
|
-
|
|
728
|
+
args.option('env', 'Target an environment. Accepts a string value for the environment type.');
|
|
558
729
|
}
|
|
559
730
|
if (_opts.requireConfirm) {
|
|
560
|
-
|
|
731
|
+
args.option('force', 'Skip confirmation.', false);
|
|
561
732
|
}
|
|
562
733
|
if (_opts.format) {
|
|
563
|
-
|
|
734
|
+
args.option('format', 'Render output in a particular format. Accepts “table“ (default), “csv“, and “json“.');
|
|
564
735
|
}
|
|
565
736
|
|
|
566
737
|
// Add help and version to all subcommands
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
return
|
|
738
|
+
args.option(['h', 'help'], 'Retrieve a description, examples, and available options for a (sub)command.', false);
|
|
739
|
+
args.option(['v', 'version'], 'Retrieve the version number of VIP-CLI currently installed on the local machine.', false);
|
|
740
|
+
args.option(['d', 'debug'], 'Generate verbose output during command execution to help identify or fix errors or bugs.');
|
|
741
|
+
return args;
|
|
571
742
|
}
|
|
572
743
|
function getEnvIdentifier(env) {
|
|
573
744
|
let identifier = env.type;
|
package/dist/lib/cli/config.js
CHANGED
|
@@ -4,8 +4,9 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.default = void 0;
|
|
5
5
|
exports.loadConfigFile = loadConfigFile;
|
|
6
6
|
var _debug = _interopRequireDefault(require("debug"));
|
|
7
|
-
var _nodeFs = require("node:fs");
|
|
7
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
8
8
|
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
9
|
+
var _configPublish = _interopRequireDefault(require("../../../config/config.publish.json"));
|
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
// I don't like using synchronous versions, but until we migrate to ESM, we have to.
|
|
11
12
|
|
|
@@ -14,26 +15,33 @@ function loadConfigFile() {
|
|
|
14
15
|
const paths = [
|
|
15
16
|
// Get `local` config first; this will only exist in dev as it's npmignore-d.
|
|
16
17
|
_nodePath.default.join(__dirname, '../../../config/config.local.json'), _nodePath.default.join(__dirname, '../../../config/config.publish.json')];
|
|
18
|
+
let hasNonEnoentError = false;
|
|
17
19
|
for (const filePath of paths) {
|
|
18
20
|
try {
|
|
19
|
-
const data =
|
|
21
|
+
const data = _nodeFs.default.readFileSync(filePath, 'utf-8');
|
|
20
22
|
debug(`Found config file at ${filePath}`);
|
|
21
23
|
return JSON.parse(data);
|
|
22
24
|
} catch (err) {
|
|
23
|
-
|
|
25
|
+
const isEnoent = err instanceof Error && 'code' in err && err.code === 'ENOENT';
|
|
26
|
+
if (!isEnoent) {
|
|
27
|
+
hasNonEnoentError = true;
|
|
24
28
|
debug(`Error reading config file at ${filePath}:`, err);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
}
|
|
32
|
+
|
|
33
|
+
// SEA builds can miss on-disk config files, so use the bundled publish config only for ENOENT.
|
|
34
|
+
if (!hasNonEnoentError) {
|
|
35
|
+
return _configPublish.default;
|
|
36
|
+
}
|
|
28
37
|
return null;
|
|
29
38
|
}
|
|
30
39
|
const configFromFile = loadConfigFile();
|
|
31
40
|
if (null === configFromFile) {
|
|
32
|
-
// This should not happen because `config/config.publish.json` is always present.
|
|
33
41
|
console.error('FATAL ERROR: Could not find a valid configuration file');
|
|
34
42
|
process.exit(1);
|
|
35
43
|
}
|
|
36
44
|
|
|
37
|
-
// Without this, TypeScript will export `configFromFile` as `Config | null
|
|
45
|
+
// Without this, TypeScript will export `configFromFile` as `Config | null`.
|
|
38
46
|
const exportedConfig = configFromFile;
|
|
39
47
|
var _default = exports.default = exportedConfig;
|
package/dist/lib/cli/exit.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.withError = withError;
|
|
5
5
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
6
6
|
var _debug = _interopRequireDefault(require("debug"));
|
|
7
|
+
var _runtimeMode = require("./runtime-mode");
|
|
7
8
|
var _env = _interopRequireDefault(require("../../lib/env"));
|
|
8
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
function withError(message) {
|
|
@@ -13,7 +14,7 @@ function withError(message) {
|
|
|
13
14
|
// Debug ouput is printed below error output both for information
|
|
14
15
|
// hierarchy and to make it more likely that the user copies it to their
|
|
15
16
|
// clipboard when dragging across output.
|
|
16
|
-
console.log(`${_chalk.default.yellow('Debug: ')} VIP-CLI v${_env.default.app.version}, Node ${_env.default.node.version}, ${_env.default.os.name} ${_env.default.os.version} ${_env.default.os.arch}`);
|
|
17
|
+
console.log(`${_chalk.default.yellow('Debug: ')} VIP-CLI v${_env.default.app.version}, Node ${_env.default.node.version}, ${_env.default.os.name} ${_env.default.os.version} ${_env.default.os.arch}, Runtime ${(0, _runtimeMode.getRuntimeModeLabel)()}`);
|
|
17
18
|
if (_debug.default.names.length > 0 && message instanceof Error) {
|
|
18
19
|
console.error(_chalk.default.yellow('Debug: '), message);
|
|
19
20
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.hasInternalBin = hasInternalBin;
|
|
5
|
+
exports.internalBinNames = void 0;
|
|
6
|
+
exports.loadInternalBin = loadInternalBin;
|
|
7
|
+
const internalBinLoaders = {
|
|
8
|
+
vip: () => import('../../bin/vip'),
|
|
9
|
+
'vip-app': () => import('../../bin/vip-app'),
|
|
10
|
+
'vip-app-deploy': () => import('../../bin/vip-app-deploy'),
|
|
11
|
+
'vip-app-deploy-validate': () => import('../../bin/vip-app-deploy-validate'),
|
|
12
|
+
'vip-app-list': () => import('../../bin/vip-app-list'),
|
|
13
|
+
'vip-backup': () => import('../../bin/vip-backup'),
|
|
14
|
+
'vip-backup-db': () => import('../../bin/vip-backup-db'),
|
|
15
|
+
'vip-cache': () => import('../../bin/vip-cache'),
|
|
16
|
+
'vip-cache-purge-url': () => import('../../bin/vip-cache-purge-url'),
|
|
17
|
+
'vip-config': () => import('../../bin/vip-config'),
|
|
18
|
+
'vip-config-envvar': () => import('../../bin/vip-config-envvar'),
|
|
19
|
+
'vip-config-envvar-delete': () => import('../../bin/vip-config-envvar-delete'),
|
|
20
|
+
'vip-config-envvar-get': () => import('../../bin/vip-config-envvar-get'),
|
|
21
|
+
'vip-config-envvar-get-all': () => import('../../bin/vip-config-envvar-get-all'),
|
|
22
|
+
'vip-config-envvar-list': () => import('../../bin/vip-config-envvar-list'),
|
|
23
|
+
'vip-config-envvar-set': () => import('../../bin/vip-config-envvar-set'),
|
|
24
|
+
'vip-config-software': () => import('../../bin/vip-config-software'),
|
|
25
|
+
'vip-config-software-get': () => import('../../bin/vip-config-software-get'),
|
|
26
|
+
'vip-config-software-update': () => import('../../bin/vip-config-software-update'),
|
|
27
|
+
'vip-db': () => import('../../bin/vip-db'),
|
|
28
|
+
'vip-db-phpmyadmin': () => import('../../bin/vip-db-phpmyadmin'),
|
|
29
|
+
'vip-dev-env': () => import('../../bin/vip-dev-env'),
|
|
30
|
+
'vip-dev-env-create': () => import('../../bin/vip-dev-env-create'),
|
|
31
|
+
'vip-dev-env-destroy': () => import('../../bin/vip-dev-env-destroy'),
|
|
32
|
+
'vip-dev-env-envvar': () => import('../../bin/vip-dev-env-envvar'),
|
|
33
|
+
'vip-dev-env-envvar-delete': () => import('../../bin/vip-dev-env-envvar-delete'),
|
|
34
|
+
'vip-dev-env-envvar-get': () => import('../../bin/vip-dev-env-envvar-get'),
|
|
35
|
+
'vip-dev-env-envvar-get-all': () => import('../../bin/vip-dev-env-envvar-get-all'),
|
|
36
|
+
'vip-dev-env-envvar-list': () => import('../../bin/vip-dev-env-envvar-list'),
|
|
37
|
+
'vip-dev-env-envvar-set': () => import('../../bin/vip-dev-env-envvar-set'),
|
|
38
|
+
'vip-dev-env-exec': () => import('../../bin/vip-dev-env-exec'),
|
|
39
|
+
'vip-dev-env-import': () => import('../../bin/vip-dev-env-import'),
|
|
40
|
+
'vip-dev-env-import-media': () => import('../../bin/vip-dev-env-import-media'),
|
|
41
|
+
'vip-dev-env-import-sql': () => import('../../bin/vip-dev-env-import-sql'),
|
|
42
|
+
'vip-dev-env-info': () => import('../../bin/vip-dev-env-info'),
|
|
43
|
+
'vip-dev-env-list': () => import('../../bin/vip-dev-env-list'),
|
|
44
|
+
'vip-dev-env-logs': () => import('../../bin/vip-dev-env-logs'),
|
|
45
|
+
'vip-dev-env-purge': () => import('../../bin/vip-dev-env-purge'),
|
|
46
|
+
'vip-dev-env-shell': () => import('../../bin/vip-dev-env-shell'),
|
|
47
|
+
'vip-dev-env-start': () => import('../../bin/vip-dev-env-start'),
|
|
48
|
+
'vip-dev-env-stop': () => import('../../bin/vip-dev-env-stop'),
|
|
49
|
+
'vip-dev-env-sync': () => import('../../bin/vip-dev-env-sync'),
|
|
50
|
+
'vip-dev-env-sync-sql': () => import('../../bin/vip-dev-env-sync-sql'),
|
|
51
|
+
'vip-dev-env-update': () => import('../../bin/vip-dev-env-update'),
|
|
52
|
+
'vip-export': () => import('../../bin/vip-export'),
|
|
53
|
+
'vip-export-sql': () => import('../../bin/vip-export-sql'),
|
|
54
|
+
'vip-import': () => import('../../bin/vip-import'),
|
|
55
|
+
'vip-import-media': () => import('../../bin/vip-import-media'),
|
|
56
|
+
'vip-import-media-abort': () => import('../../bin/vip-import-media-abort'),
|
|
57
|
+
'vip-import-media-status': () => import('../../bin/vip-import-media-status'),
|
|
58
|
+
'vip-import-sql': () => import('../../bin/vip-import-sql'),
|
|
59
|
+
'vip-import-sql-status': () => import('../../bin/vip-import-sql-status'),
|
|
60
|
+
'vip-import-validate-files': () => import('../../bin/vip-import-validate-files'),
|
|
61
|
+
'vip-import-validate-sql': () => import('../../bin/vip-import-validate-sql'),
|
|
62
|
+
'vip-logout': () => import('../../bin/vip-logout'),
|
|
63
|
+
'vip-logs': () => import('../../bin/vip-logs'),
|
|
64
|
+
'vip-search-replace': () => import('../../bin/vip-search-replace'),
|
|
65
|
+
'vip-slowlogs': () => import('../../bin/vip-slowlogs'),
|
|
66
|
+
'vip-sync': () => import('../../bin/vip-sync'),
|
|
67
|
+
'vip-whoami': () => import('../../bin/vip-whoami'),
|
|
68
|
+
'vip-wp': () => import('../../bin/vip-wp')
|
|
69
|
+
};
|
|
70
|
+
const internalBinNames = exports.internalBinNames = Object.freeze(Object.keys(internalBinLoaders));
|
|
71
|
+
async function loadInternalBin(binName) {
|
|
72
|
+
const loader = internalBinLoaders[binName];
|
|
73
|
+
if (!loader) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
await loader();
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
function hasInternalBin(binName) {
|
|
80
|
+
return Object.hasOwn(internalBinLoaders, binName);
|
|
81
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.getRuntimeModeLabel = getRuntimeModeLabel;
|
|
5
|
+
exports.isStandaloneExecutableRuntime = isStandaloneExecutableRuntime;
|
|
6
|
+
var _nodeModule = require("node:module");
|
|
7
|
+
const runtimeRequire = (0, _nodeModule.createRequire)(__filename);
|
|
8
|
+
function isStandaloneExecutableRuntime() {
|
|
9
|
+
if (process.env.VIP_CLI_SEA_MODE === '1') {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const sea = runtimeRequire('node:sea');
|
|
14
|
+
return Boolean(sea?.isSea?.());
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function getRuntimeModeLabel() {
|
|
20
|
+
return isStandaloneExecutableRuntime() ? 'standalone-sea' : 'node-script';
|
|
21
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.isSeaRuntime = isSeaRuntime;
|
|
5
|
+
exports.resolveInternalBinFromArgv = resolveInternalBinFromArgv;
|
|
6
|
+
exports.rewriteArgvForInternalBin = rewriteArgvForInternalBin;
|
|
7
|
+
var _envAlias = require("./envAlias");
|
|
8
|
+
var _internalBinLoader = require("./internal-bin-loader");
|
|
9
|
+
const internalBinSet = new Set(_internalBinLoader.internalBinNames);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the best matching internal bin for a command argv.
|
|
13
|
+
*
|
|
14
|
+
* @param {string[]} argv process.argv style array
|
|
15
|
+
* @returns {{ bin: string, start: number, length: number }}
|
|
16
|
+
*/
|
|
17
|
+
function resolveInternalBinFromArgv(argv) {
|
|
18
|
+
const args = argv.slice(2);
|
|
19
|
+
const dashDashIndex = args.indexOf('--');
|
|
20
|
+
const commandBoundary = dashDashIndex > -1 ? dashDashIndex : args.length;
|
|
21
|
+
let best = {
|
|
22
|
+
bin: 'vip',
|
|
23
|
+
start: 0,
|
|
24
|
+
length: 0
|
|
25
|
+
};
|
|
26
|
+
for (let start = 0; start < commandBoundary; start++) {
|
|
27
|
+
const firstToken = args[start];
|
|
28
|
+
if (!firstToken || firstToken.startsWith('-') || (0, _envAlias.isAlias)(firstToken)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const commandParts = [];
|
|
32
|
+
for (let index = start; index < commandBoundary; index++) {
|
|
33
|
+
const token = args[index];
|
|
34
|
+
if (!token || token.startsWith('-') || (0, _envAlias.isAlias)(token)) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
commandParts.push(token);
|
|
38
|
+
const candidateBin = `vip-${commandParts.join('-')}`;
|
|
39
|
+
if (internalBinSet.has(candidateBin)) {
|
|
40
|
+
const isLongerMatch = commandParts.length > best.length;
|
|
41
|
+
const isEarlierEqualMatch = commandParts.length === best.length && commandParts.length > 0 && start < best.start;
|
|
42
|
+
if (isLongerMatch || isEarlierEqualMatch) {
|
|
43
|
+
best = {
|
|
44
|
+
bin: candidateBin,
|
|
45
|
+
start,
|
|
46
|
+
length: commandParts.length
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return best;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Rewrites argv so the resolved command segment is removed and the target bin
|
|
57
|
+
* can parse its native flags/args shape.
|
|
58
|
+
*
|
|
59
|
+
* @param {string[]} argv process.argv style array
|
|
60
|
+
* @param {{ start: number, length: number }} resolution command resolution
|
|
61
|
+
* @returns {string[]} rewritten argv
|
|
62
|
+
*/
|
|
63
|
+
function rewriteArgvForInternalBin(argv, resolution) {
|
|
64
|
+
const args = argv.slice(2);
|
|
65
|
+
const start = resolution.start ?? 0;
|
|
66
|
+
const length = resolution.length ?? 0;
|
|
67
|
+
if (length <= 0) {
|
|
68
|
+
return argv.slice(0);
|
|
69
|
+
}
|
|
70
|
+
const rewrittenArgs = args.slice(0, start).concat(args.slice(start + length));
|
|
71
|
+
return [argv[0], argv[1], ...rewrittenArgs];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
function isSeaRuntime() {
|
|
78
|
+
try {
|
|
79
|
+
const runtimeRequire = typeof module !== 'undefined' && module?.require ? module.require.bind(module) : null;
|
|
80
|
+
if (!runtimeRequire) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const sea = runtimeRequire('node:sea');
|
|
84
|
+
return Boolean(sea?.isSea?.());
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|