@automattic/vip 3.25.3-dev.0 → 4.0.1

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.
@@ -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,233 @@ 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
+ function isOptionToken(arg) {
111
+ return arg !== '-' && arg.startsWith('-');
112
+ }
113
+ class CommanderArgsCompat {
114
+ constructor(opts) {
115
+ this.details = {
116
+ commands: []
117
+ };
118
+ this.sub = [];
119
+ this.examplesList = [];
120
+ this.usedShortNames = new Set();
121
+ this._opts = opts;
122
+ this.program = new _commander.Command();
123
+ this.program.allowUnknownOption(true);
124
+ this.program.allowExcessArguments(true);
125
+ this.program.helpOption(false);
126
+ normalizeUsage(this.program, this._opts.usage);
127
+ }
128
+ option(name, description, defaultValue, parseFn) {
129
+ const definition = createOptionDefinition(name, description, defaultValue, parseFn, this.usedShortNames);
130
+ const {
131
+ flags,
132
+ parser
133
+ } = definition;
134
+ if (parser && defaultValue !== undefined) {
135
+ this.program.option(flags, description, parser, defaultValue);
136
+ } else if (parser) {
137
+ this.program.option(flags, description, parser);
138
+ } else if (defaultValue !== undefined) {
139
+ this.program.option(flags, description, defaultValue);
140
+ } else {
141
+ this.program.option(flags, description);
142
+ }
143
+ return this;
144
+ }
145
+ command(name, description = '') {
146
+ this.details.commands.push({
147
+ usage: name,
148
+ description
149
+ });
150
+ return this;
151
+ }
152
+ example(usage, description) {
153
+ this.examplesList.push({
154
+ usage,
155
+ description
156
+ });
157
+ return this;
158
+ }
159
+ examples(examples = []) {
160
+ for (const example of examples) {
161
+ this.example(example.usage, example.description);
162
+ }
163
+ return this;
164
+ }
165
+ showVersion() {
166
+ console.log(_package.default.version);
167
+ process.exit(0);
168
+ }
169
+ showHelp() {
170
+ const lines = [this.program.helpInformation().trimEnd()];
171
+ if (this.details.commands.length) {
172
+ lines.push('');
173
+ lines.push('Commands:');
174
+ for (const entry of this.details.commands) {
175
+ const commandName = entry.usage.padEnd(26, ' ');
176
+ lines.push(` ${commandName}${entry.description}`);
177
+ }
178
+ }
179
+ if (this.examplesList.length) {
180
+ lines.push('');
181
+ lines.push('Examples:');
182
+ for (const example of this.examplesList) {
183
+ lines.push(` - ${example.description}`);
184
+ lines.push(` $ ${example.usage}`);
185
+ }
186
+ }
187
+ console.log(lines.join('\n'));
188
+ process.exit(0);
189
+ }
190
+ isDefined(value, key) {
191
+ if (key !== 'commands') {
192
+ return false;
193
+ }
194
+ return this.details.commands.some(entry => entry.usage === value);
195
+ }
196
+ parse(argv) {
197
+ this.program.parse(argv, {
198
+ from: 'node'
199
+ });
200
+ this.sub = this.program.args.slice();
201
+ return this.program.opts();
202
+ }
203
+ findSubcommand(argv) {
204
+ const dashDashIndex = argv.indexOf('--', 2);
205
+ const searchEnd = dashDashIndex === -1 ? argv.length : dashDashIndex;
206
+ for (let index = 2; index < searchEnd; index++) {
207
+ const arg = argv[index];
208
+ if (this.isDefined(arg, 'commands')) {
209
+ return {
210
+ index,
211
+ name: arg
212
+ };
213
+ }
214
+ if (!isOptionToken(arg)) {
215
+ return null;
216
+ }
217
+ const nextArg = argv[index + 1];
218
+ const optionHasInlineValue = arg.includes('=');
219
+ const nextArgCouldBeOptionValue = nextArg && !isOptionToken(nextArg) && !this.isDefined(nextArg, 'commands');
220
+ if (!optionHasInlineValue && nextArgCouldBeOptionValue) {
221
+ index++;
222
+ }
223
+ }
224
+ return null;
225
+ }
226
+ async executeSubcommand(argv, parsedAlias, subcommand) {
227
+ const currentScript = argv[1];
228
+ const subcommandName = subcommand.name;
229
+ const extension = _nodePath.default.extname(currentScript);
230
+ const baseScriptPath = extension ? currentScript.slice(0, -extension.length) : currentScript;
231
+ const childScriptPath = extension ? `${baseScriptPath}-${subcommandName}${extension}` : `${baseScriptPath}-${subcommandName}`;
232
+ const aliasFromRawArgv = argv.slice(2).find(arg => (0, _envAlias.isAlias)(arg));
233
+ let childArgs = [...parsedAlias.argv.slice(2, subcommand.index), ...parsedAlias.argv.slice(subcommand.index + 1)];
234
+ if (aliasFromRawArgv) {
235
+ childArgs = [aliasFromRawArgv, ...childArgs];
236
+ }
237
+ let runResult;
238
+ if (_nodeFs.default.existsSync(childScriptPath)) {
239
+ runResult = (0, _nodeChild_process.spawnSync)(process.execPath, [childScriptPath, ...childArgs], {
240
+ stdio: 'inherit',
241
+ env: process.env
242
+ });
243
+ } else {
244
+ const fallbackCommand = `${_nodePath.default.basename(baseScriptPath)}-${subcommandName}`;
245
+ if (process.env.VIP_CLI_SEA_MODE === '1' && (0, _internalBinLoader.hasInternalBin)(fallbackCommand)) {
246
+ process.argv = [process.argv[0], process.argv[1], ...childArgs];
247
+ const loaded = await (0, _internalBinLoader.loadInternalBin)(fallbackCommand);
248
+ if (!loaded) {
249
+ throw new Error(`Unable to load SEA subcommand "${fallbackCommand}"`);
250
+ }
251
+ return;
252
+ }
253
+ runResult = (0, _nodeChild_process.spawnSync)(fallbackCommand, childArgs, {
254
+ stdio: 'inherit',
255
+ env: process.env,
256
+ shell: process.platform === 'win32'
257
+ });
258
+ }
259
+ if (runResult.error) {
260
+ throw runResult.error;
261
+ }
262
+ process.exit(runResult.status ?? 1);
263
+ }
264
+ }
40
265
 
41
266
  /**
42
267
  * @param {string[]} argv
43
268
  */
44
269
  // eslint-disable-next-line complexity
45
- _args.default.argv = async function (argv, cb) {
46
- if (process.platform !== 'win32' && argv[1]?.endsWith('.js')) {
47
- argv[1] = argv[1].slice(0, -3);
48
- }
270
+ CommanderArgsCompat.prototype.argv = async function (argv, cb) {
49
271
  if (process.execArgv.includes('--inspect') && !alreadyConfirmedDebugAttachment) {
50
272
  await (0, _enquirer.prompt)({
51
273
  type: 'confirm',
@@ -55,25 +277,14 @@ _args.default.argv = async function (argv, cb) {
55
277
  alreadyConfirmedDebugAttachment = true;
56
278
  }
57
279
  const parsedAlias = (0, _envAlias.parseEnvAliasFromArgv)(argv);
280
+ const options = this.parse(parsedAlias.argv);
58
281
 
59
- // A usage option allows us to override the default usage text, which isn't
60
- // accurate for subcommands. By default, it will display something like (note
61
- // the hyphen):
62
- // Usage: vip command-subcommand [options]
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
- });
282
+ // If there's a sub-command, run that instead
283
+ const dispatchSubcommand = this.findSubcommand(parsedAlias.argv);
284
+ if (dispatchSubcommand) {
285
+ await this.executeSubcommand(argv, parsedAlias, dispatchSubcommand);
286
+ return {};
287
+ }
77
288
  if (_opts.format && !options.format) {
78
289
  options.format = 'table';
79
290
  }
@@ -105,12 +316,7 @@ _args.default.argv = async function (argv, cb) {
105
316
  });
106
317
  exit.withError(error);
107
318
  }
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') {
319
+ if (process.env.NODE_ENV !== 'test' && process.env.VIP_CLI_SEA_MODE !== '1') {
114
320
  const {
115
321
  default: updateNotifier
116
322
  } = await import('update-notifier');
@@ -121,18 +327,7 @@ _args.default.argv = async function (argv, cb) {
121
327
  isGlobal: true
122
328
  });
123
329
  }
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
- });
330
+ const customCommands = this.details.commands;
136
331
 
137
332
  // Show help if no args passed
138
333
  if (Boolean(customCommands.length) && !this.sub.length) {
@@ -152,7 +347,7 @@ _args.default.argv = async function (argv, cb) {
152
347
 
153
348
  // Show help if subcommand is invalid
154
349
  const subCommands = this.details.commands.map(cmd => cmd.usage);
155
- if (!_opts.wildcardCommand && this.sub[_opts.requiredArgs] && 0 > subCommands.indexOf(this.sub[_opts.requiredArgs])) {
350
+ if (!_opts.wildcardCommand && this.sub[_opts.requiredArgs] && subCommands.length && 0 > subCommands.indexOf(this.sub[_opts.requiredArgs])) {
156
351
  const subcommand = this.sub.join(' ');
157
352
  await (0, _tracker.trackEvent)('command_validation_error', {
158
353
  error: `Invalid subcommand: ${subcommand}`
@@ -368,7 +563,7 @@ _args.default.argv = async function (argv, cb) {
368
563
  value: `${_chalk.default.cyan(launched)}`
369
564
  });
370
565
  }
371
- if (this.sub) {
566
+ if (this.sub.length) {
372
567
  info.push({
373
568
  key: 'SQL File',
374
569
  value: `${_chalk.default.blueBright(this.sub)}`
@@ -441,7 +636,7 @@ _args.default.argv = async function (argv, cb) {
441
636
  }
442
637
  case 'import-media':
443
638
  {
444
- const isUrl = this.sub && (String(this.sub).startsWith('http://') || String(this.sub).startsWith('https://'));
639
+ const isUrl = this.sub.length && (String(this.sub).startsWith('http://') || String(this.sub).startsWith('https://'));
445
640
  const archiveLabel = isUrl ? 'Archive URL' : 'Archive Path';
446
641
  info.push({
447
642
  key: archiveLabel,
@@ -536,7 +731,7 @@ function validateOpts(opts) {
536
731
  }
537
732
 
538
733
  /**
539
- * @returns {args}
734
+ * @returns {CommanderArgsCompat}
540
735
  */
541
736
  function _default(opts) {
542
737
  _opts = {
@@ -550,24 +745,25 @@ function _default(opts) {
550
745
  wildcardCommand: false,
551
746
  ...opts
552
747
  };
748
+ const args = new CommanderArgsCompat(_opts);
553
749
  if (_opts.appContext || _opts.requireConfirm) {
554
- _args.default.option('app', 'Target an application. Accepts a string value for the application name or an integer for the application ID.');
750
+ args.option('app', 'Target an application. Accepts a string value for the application name or an integer for the application ID.');
555
751
  }
556
752
  if (_opts.envContext || _opts.childEnvContext) {
557
- _args.default.option('env', 'Target an environment. Accepts a string value for the environment type.');
753
+ args.option('env', 'Target an environment. Accepts a string value for the environment type.');
558
754
  }
559
755
  if (_opts.requireConfirm) {
560
- _args.default.option('force', 'Skip confirmation.', false);
756
+ args.option('force', 'Skip confirmation.', false);
561
757
  }
562
758
  if (_opts.format) {
563
- _args.default.option('format', 'Render output in a particular format. Accepts “table“ (default), “csv“, and “json“.');
759
+ args.option('format', 'Render output in a particular format. Accepts “table“ (default), “csv“, and “json“.');
564
760
  }
565
761
 
566
762
  // Add help and version to all subcommands
567
- _args.default.option('help', 'Retrieve a description, examples, and available options for a (sub)command.');
568
- _args.default.option('version', 'Retrieve the version number of VIP-CLI currently installed on the local machine.');
569
- _args.default.option('debug', 'Generate verbose output during command execution to help identify or fix errors or bugs.');
570
- return _args.default;
763
+ args.option(['h', 'help'], 'Retrieve a description, examples, and available options for a (sub)command.', false);
764
+ args.option(['v', 'version'], 'Retrieve the version number of VIP-CLI currently installed on the local machine.', false);
765
+ args.option(['d', 'debug'], 'Generate verbose output during command execution to help identify or fix errors or bugs.');
766
+ return args;
571
767
  }
572
768
  function getEnvIdentifier(env) {
573
769
  let identifier = env.type;
@@ -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 = (0, _nodeFs.readFileSync)(filePath, 'utf-8');
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
- if (!(err instanceof Error) || !('code' in err) || err.code !== 'ENOENT') {
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;
@@ -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
+ }