vite-node 0.26.3 → 0.27.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/dist/chunk-hmr.cjs +5 -4
- package/dist/chunk-hmr.mjs +4 -4
- package/dist/cli.cjs +10 -619
- package/dist/cli.mjs +6 -620
- package/dist/client.cjs +9 -4
- package/dist/client.mjs +9 -4
- package/dist/hmr.cjs +1 -2
- package/dist/hmr.mjs +1 -2
- package/dist/server.cjs +33 -5
- package/dist/server.mjs +32 -5
- package/dist/utils.cjs +0 -4
- package/dist/utils.d.ts +1 -2
- package/dist/utils.mjs +1 -4
- package/package.json +4 -3
- package/dist/chunk-picocolors.cjs +0 -70
- package/dist/chunk-picocolors.mjs +0 -64
package/dist/cli.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import cac from 'cac';
|
|
2
|
+
import c from 'picocolors';
|
|
3
3
|
import { createServer } from 'vite';
|
|
4
4
|
import { ViteNodeServer } from './server.mjs';
|
|
5
5
|
import { ViteNodeRunner } from './client.mjs';
|
|
6
6
|
import { toArray } from './utils.mjs';
|
|
7
|
-
import { v as viteNodeHmrPlugin, c as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
|
|
8
7
|
import { installSourcemapsSupport } from './source-map.mjs';
|
|
9
|
-
import '
|
|
8
|
+
import { v as viteNodeHmrPlugin, c as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
|
|
10
9
|
import 'node:perf_hooks';
|
|
11
10
|
import 'pathe';
|
|
12
11
|
import 'debug';
|
|
@@ -19,620 +18,7 @@ import 'node:path';
|
|
|
19
18
|
import 'node:vm';
|
|
20
19
|
import 'node:events';
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function toVal(out, key, val, opts) {
|
|
27
|
-
var x, old=out[key], nxt=(
|
|
28
|
-
!!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
|
|
29
|
-
: typeof val === 'boolean' ? val
|
|
30
|
-
: !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
|
|
31
|
-
: (x = +val,x * 0 === 0) ? x : val
|
|
32
|
-
);
|
|
33
|
-
out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function mri2 (args, opts) {
|
|
37
|
-
args = args || [];
|
|
38
|
-
opts = opts || {};
|
|
39
|
-
|
|
40
|
-
var k, arr, arg, name, val, out={ _:[] };
|
|
41
|
-
var i=0, j=0, idx=0, len=args.length;
|
|
42
|
-
|
|
43
|
-
const alibi = opts.alias !== void 0;
|
|
44
|
-
const strict = opts.unknown !== void 0;
|
|
45
|
-
const defaults = opts.default !== void 0;
|
|
46
|
-
|
|
47
|
-
opts.alias = opts.alias || {};
|
|
48
|
-
opts.string = toArr(opts.string);
|
|
49
|
-
opts.boolean = toArr(opts.boolean);
|
|
50
|
-
|
|
51
|
-
if (alibi) {
|
|
52
|
-
for (k in opts.alias) {
|
|
53
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
54
|
-
for (i=0; i < arr.length; i++) {
|
|
55
|
-
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
for (i=opts.boolean.length; i-- > 0;) {
|
|
61
|
-
arr = opts.alias[opts.boolean[i]] || [];
|
|
62
|
-
for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
for (i=opts.string.length; i-- > 0;) {
|
|
66
|
-
arr = opts.alias[opts.string[i]] || [];
|
|
67
|
-
for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (defaults) {
|
|
71
|
-
for (k in opts.default) {
|
|
72
|
-
name = typeof opts.default[k];
|
|
73
|
-
arr = opts.alias[k] = opts.alias[k] || [];
|
|
74
|
-
if (opts[name] !== void 0) {
|
|
75
|
-
opts[name].push(k);
|
|
76
|
-
for (i=0; i < arr.length; i++) {
|
|
77
|
-
opts[name].push(arr[i]);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const keys = strict ? Object.keys(opts.alias) : [];
|
|
84
|
-
|
|
85
|
-
for (i=0; i < len; i++) {
|
|
86
|
-
arg = args[i];
|
|
87
|
-
|
|
88
|
-
if (arg === '--') {
|
|
89
|
-
out._ = out._.concat(args.slice(++i));
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
for (j=0; j < arg.length; j++) {
|
|
94
|
-
if (arg.charCodeAt(j) !== 45) break; // "-"
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (j === 0) {
|
|
98
|
-
out._.push(arg);
|
|
99
|
-
} else if (arg.substring(j, j + 3) === 'no-') {
|
|
100
|
-
name = arg.substring(j + 3);
|
|
101
|
-
if (strict && !~keys.indexOf(name)) {
|
|
102
|
-
return opts.unknown(arg);
|
|
103
|
-
}
|
|
104
|
-
out[name] = false;
|
|
105
|
-
} else {
|
|
106
|
-
for (idx=j+1; idx < arg.length; idx++) {
|
|
107
|
-
if (arg.charCodeAt(idx) === 61) break; // "="
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
name = arg.substring(j, idx);
|
|
111
|
-
val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
|
|
112
|
-
arr = (j === 2 ? [name] : name);
|
|
113
|
-
|
|
114
|
-
for (idx=0; idx < arr.length; idx++) {
|
|
115
|
-
name = arr[idx];
|
|
116
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
|
|
117
|
-
toVal(out, name, (idx + 1 < arr.length) || val, opts);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (defaults) {
|
|
123
|
-
for (k in opts.default) {
|
|
124
|
-
if (out[k] === void 0) {
|
|
125
|
-
out[k] = opts.default[k];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (alibi) {
|
|
131
|
-
for (k in out) {
|
|
132
|
-
arr = opts.alias[k] || [];
|
|
133
|
-
while (arr.length > 0) {
|
|
134
|
-
out[arr.shift()] = out[k];
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return out;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
|
143
|
-
const findAllBrackets = (v) => {
|
|
144
|
-
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
145
|
-
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
146
|
-
const res = [];
|
|
147
|
-
const parse = (match) => {
|
|
148
|
-
let variadic = false;
|
|
149
|
-
let value = match[1];
|
|
150
|
-
if (value.startsWith("...")) {
|
|
151
|
-
value = value.slice(3);
|
|
152
|
-
variadic = true;
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
required: match[0].startsWith("<"),
|
|
156
|
-
value,
|
|
157
|
-
variadic
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
let angledMatch;
|
|
161
|
-
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
|
|
162
|
-
res.push(parse(angledMatch));
|
|
163
|
-
}
|
|
164
|
-
let squareMatch;
|
|
165
|
-
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
|
|
166
|
-
res.push(parse(squareMatch));
|
|
167
|
-
}
|
|
168
|
-
return res;
|
|
169
|
-
};
|
|
170
|
-
const getMriOptions = (options) => {
|
|
171
|
-
const result = {alias: {}, boolean: []};
|
|
172
|
-
for (const [index, option] of options.entries()) {
|
|
173
|
-
if (option.names.length > 1) {
|
|
174
|
-
result.alias[option.names[0]] = option.names.slice(1);
|
|
175
|
-
}
|
|
176
|
-
if (option.isBoolean) {
|
|
177
|
-
if (option.negated) {
|
|
178
|
-
const hasStringTypeOption = options.some((o, i) => {
|
|
179
|
-
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
180
|
-
});
|
|
181
|
-
if (!hasStringTypeOption) {
|
|
182
|
-
result.boolean.push(option.names[0]);
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
result.boolean.push(option.names[0]);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return result;
|
|
190
|
-
};
|
|
191
|
-
const findLongest = (arr) => {
|
|
192
|
-
return arr.sort((a, b) => {
|
|
193
|
-
return a.length > b.length ? -1 : 1;
|
|
194
|
-
})[0];
|
|
195
|
-
};
|
|
196
|
-
const padRight = (str, length) => {
|
|
197
|
-
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
198
|
-
};
|
|
199
|
-
const camelcase = (input) => {
|
|
200
|
-
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
201
|
-
return p1 + p2.toUpperCase();
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
const setDotProp = (obj, keys, val) => {
|
|
205
|
-
let i = 0;
|
|
206
|
-
let length = keys.length;
|
|
207
|
-
let t = obj;
|
|
208
|
-
let x;
|
|
209
|
-
for (; i < length; ++i) {
|
|
210
|
-
x = t[keys[i]];
|
|
211
|
-
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
const setByType = (obj, transforms) => {
|
|
215
|
-
for (const key of Object.keys(transforms)) {
|
|
216
|
-
const transform = transforms[key];
|
|
217
|
-
if (transform.shouldTransform) {
|
|
218
|
-
obj[key] = Array.prototype.concat.call([], obj[key]);
|
|
219
|
-
if (typeof transform.transformFunction === "function") {
|
|
220
|
-
obj[key] = obj[key].map(transform.transformFunction);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
const getFileName = (input) => {
|
|
226
|
-
const m = /([^\\\/]+)$/.exec(input);
|
|
227
|
-
return m ? m[1] : "";
|
|
228
|
-
};
|
|
229
|
-
const camelcaseOptionName = (name) => {
|
|
230
|
-
return name.split(".").map((v, i) => {
|
|
231
|
-
return i === 0 ? camelcase(v) : v;
|
|
232
|
-
}).join(".");
|
|
233
|
-
};
|
|
234
|
-
class CACError extends Error {
|
|
235
|
-
constructor(message) {
|
|
236
|
-
super(message);
|
|
237
|
-
this.name = this.constructor.name;
|
|
238
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
239
|
-
Error.captureStackTrace(this, this.constructor);
|
|
240
|
-
} else {
|
|
241
|
-
this.stack = new Error(message).stack;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
class Option {
|
|
247
|
-
constructor(rawName, description, config) {
|
|
248
|
-
this.rawName = rawName;
|
|
249
|
-
this.description = description;
|
|
250
|
-
this.config = Object.assign({}, config);
|
|
251
|
-
rawName = rawName.replace(/\.\*/g, "");
|
|
252
|
-
this.negated = false;
|
|
253
|
-
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
254
|
-
let name = v.trim().replace(/^-{1,2}/, "");
|
|
255
|
-
if (name.startsWith("no-")) {
|
|
256
|
-
this.negated = true;
|
|
257
|
-
name = name.replace(/^no-/, "");
|
|
258
|
-
}
|
|
259
|
-
return camelcaseOptionName(name);
|
|
260
|
-
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
261
|
-
this.name = this.names[this.names.length - 1];
|
|
262
|
-
if (this.negated && this.config.default == null) {
|
|
263
|
-
this.config.default = true;
|
|
264
|
-
}
|
|
265
|
-
if (rawName.includes("<")) {
|
|
266
|
-
this.required = true;
|
|
267
|
-
} else if (rawName.includes("[")) {
|
|
268
|
-
this.required = false;
|
|
269
|
-
} else {
|
|
270
|
-
this.isBoolean = true;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const processArgs = process.argv;
|
|
276
|
-
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
277
|
-
|
|
278
|
-
class Command {
|
|
279
|
-
constructor(rawName, description, config = {}, cli) {
|
|
280
|
-
this.rawName = rawName;
|
|
281
|
-
this.description = description;
|
|
282
|
-
this.config = config;
|
|
283
|
-
this.cli = cli;
|
|
284
|
-
this.options = [];
|
|
285
|
-
this.aliasNames = [];
|
|
286
|
-
this.name = removeBrackets(rawName);
|
|
287
|
-
this.args = findAllBrackets(rawName);
|
|
288
|
-
this.examples = [];
|
|
289
|
-
}
|
|
290
|
-
usage(text) {
|
|
291
|
-
this.usageText = text;
|
|
292
|
-
return this;
|
|
293
|
-
}
|
|
294
|
-
allowUnknownOptions() {
|
|
295
|
-
this.config.allowUnknownOptions = true;
|
|
296
|
-
return this;
|
|
297
|
-
}
|
|
298
|
-
ignoreOptionDefaultValue() {
|
|
299
|
-
this.config.ignoreOptionDefaultValue = true;
|
|
300
|
-
return this;
|
|
301
|
-
}
|
|
302
|
-
version(version, customFlags = "-v, --version") {
|
|
303
|
-
this.versionNumber = version;
|
|
304
|
-
this.option(customFlags, "Display version number");
|
|
305
|
-
return this;
|
|
306
|
-
}
|
|
307
|
-
example(example) {
|
|
308
|
-
this.examples.push(example);
|
|
309
|
-
return this;
|
|
310
|
-
}
|
|
311
|
-
option(rawName, description, config) {
|
|
312
|
-
const option = new Option(rawName, description, config);
|
|
313
|
-
this.options.push(option);
|
|
314
|
-
return this;
|
|
315
|
-
}
|
|
316
|
-
alias(name) {
|
|
317
|
-
this.aliasNames.push(name);
|
|
318
|
-
return this;
|
|
319
|
-
}
|
|
320
|
-
action(callback) {
|
|
321
|
-
this.commandAction = callback;
|
|
322
|
-
return this;
|
|
323
|
-
}
|
|
324
|
-
isMatched(name) {
|
|
325
|
-
return this.name === name || this.aliasNames.includes(name);
|
|
326
|
-
}
|
|
327
|
-
get isDefaultCommand() {
|
|
328
|
-
return this.name === "" || this.aliasNames.includes("!");
|
|
329
|
-
}
|
|
330
|
-
get isGlobalCommand() {
|
|
331
|
-
return this instanceof GlobalCommand;
|
|
332
|
-
}
|
|
333
|
-
hasOption(name) {
|
|
334
|
-
name = name.split(".")[0];
|
|
335
|
-
return this.options.find((option) => {
|
|
336
|
-
return option.names.includes(name);
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
outputHelp() {
|
|
340
|
-
const {name, commands} = this.cli;
|
|
341
|
-
const {
|
|
342
|
-
versionNumber,
|
|
343
|
-
options: globalOptions,
|
|
344
|
-
helpCallback
|
|
345
|
-
} = this.cli.globalCommand;
|
|
346
|
-
let sections = [
|
|
347
|
-
{
|
|
348
|
-
body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
|
|
349
|
-
}
|
|
350
|
-
];
|
|
351
|
-
sections.push({
|
|
352
|
-
title: "Usage",
|
|
353
|
-
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
354
|
-
});
|
|
355
|
-
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
356
|
-
if (showCommands) {
|
|
357
|
-
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
358
|
-
sections.push({
|
|
359
|
-
title: "Commands",
|
|
360
|
-
body: commands.map((command) => {
|
|
361
|
-
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
362
|
-
}).join("\n")
|
|
363
|
-
});
|
|
364
|
-
sections.push({
|
|
365
|
-
title: `For more info, run any command with the \`--help\` flag`,
|
|
366
|
-
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
370
|
-
if (!this.isGlobalCommand && !this.isDefaultCommand) {
|
|
371
|
-
options = options.filter((option) => option.name !== "version");
|
|
372
|
-
}
|
|
373
|
-
if (options.length > 0) {
|
|
374
|
-
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
375
|
-
sections.push({
|
|
376
|
-
title: "Options",
|
|
377
|
-
body: options.map((option) => {
|
|
378
|
-
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
379
|
-
}).join("\n")
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
if (this.examples.length > 0) {
|
|
383
|
-
sections.push({
|
|
384
|
-
title: "Examples",
|
|
385
|
-
body: this.examples.map((example) => {
|
|
386
|
-
if (typeof example === "function") {
|
|
387
|
-
return example(name);
|
|
388
|
-
}
|
|
389
|
-
return example;
|
|
390
|
-
}).join("\n")
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
if (helpCallback) {
|
|
394
|
-
sections = helpCallback(sections) || sections;
|
|
395
|
-
}
|
|
396
|
-
console.log(sections.map((section) => {
|
|
397
|
-
return section.title ? `${section.title}:
|
|
398
|
-
${section.body}` : section.body;
|
|
399
|
-
}).join("\n\n"));
|
|
400
|
-
}
|
|
401
|
-
outputVersion() {
|
|
402
|
-
const {name} = this.cli;
|
|
403
|
-
const {versionNumber} = this.cli.globalCommand;
|
|
404
|
-
if (versionNumber) {
|
|
405
|
-
console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
checkRequiredArgs() {
|
|
409
|
-
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
410
|
-
if (this.cli.args.length < minimalArgsCount) {
|
|
411
|
-
throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
checkUnknownOptions() {
|
|
415
|
-
const {options, globalCommand} = this.cli;
|
|
416
|
-
if (!this.config.allowUnknownOptions) {
|
|
417
|
-
for (const name of Object.keys(options)) {
|
|
418
|
-
if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
|
|
419
|
-
throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
checkOptionValue() {
|
|
425
|
-
const {options: parsedOptions, globalCommand} = this.cli;
|
|
426
|
-
const options = [...globalCommand.options, ...this.options];
|
|
427
|
-
for (const option of options) {
|
|
428
|
-
const value = parsedOptions[option.name.split(".")[0]];
|
|
429
|
-
if (option.required) {
|
|
430
|
-
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
431
|
-
if (value === true || value === false && !hasNegated) {
|
|
432
|
-
throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
class GlobalCommand extends Command {
|
|
439
|
-
constructor(cli) {
|
|
440
|
-
super("@@global@@", "", {}, cli);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
var __assign = Object.assign;
|
|
445
|
-
class CAC extends EventEmitter {
|
|
446
|
-
constructor(name = "") {
|
|
447
|
-
super();
|
|
448
|
-
this.name = name;
|
|
449
|
-
this.commands = [];
|
|
450
|
-
this.rawArgs = [];
|
|
451
|
-
this.args = [];
|
|
452
|
-
this.options = {};
|
|
453
|
-
this.globalCommand = new GlobalCommand(this);
|
|
454
|
-
this.globalCommand.usage("<command> [options]");
|
|
455
|
-
}
|
|
456
|
-
usage(text) {
|
|
457
|
-
this.globalCommand.usage(text);
|
|
458
|
-
return this;
|
|
459
|
-
}
|
|
460
|
-
command(rawName, description, config) {
|
|
461
|
-
const command = new Command(rawName, description || "", config, this);
|
|
462
|
-
command.globalCommand = this.globalCommand;
|
|
463
|
-
this.commands.push(command);
|
|
464
|
-
return command;
|
|
465
|
-
}
|
|
466
|
-
option(rawName, description, config) {
|
|
467
|
-
this.globalCommand.option(rawName, description, config);
|
|
468
|
-
return this;
|
|
469
|
-
}
|
|
470
|
-
help(callback) {
|
|
471
|
-
this.globalCommand.option("-h, --help", "Display this message");
|
|
472
|
-
this.globalCommand.helpCallback = callback;
|
|
473
|
-
this.showHelpOnExit = true;
|
|
474
|
-
return this;
|
|
475
|
-
}
|
|
476
|
-
version(version, customFlags = "-v, --version") {
|
|
477
|
-
this.globalCommand.version(version, customFlags);
|
|
478
|
-
this.showVersionOnExit = true;
|
|
479
|
-
return this;
|
|
480
|
-
}
|
|
481
|
-
example(example) {
|
|
482
|
-
this.globalCommand.example(example);
|
|
483
|
-
return this;
|
|
484
|
-
}
|
|
485
|
-
outputHelp() {
|
|
486
|
-
if (this.matchedCommand) {
|
|
487
|
-
this.matchedCommand.outputHelp();
|
|
488
|
-
} else {
|
|
489
|
-
this.globalCommand.outputHelp();
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
outputVersion() {
|
|
493
|
-
this.globalCommand.outputVersion();
|
|
494
|
-
}
|
|
495
|
-
setParsedInfo({args, options}, matchedCommand, matchedCommandName) {
|
|
496
|
-
this.args = args;
|
|
497
|
-
this.options = options;
|
|
498
|
-
if (matchedCommand) {
|
|
499
|
-
this.matchedCommand = matchedCommand;
|
|
500
|
-
}
|
|
501
|
-
if (matchedCommandName) {
|
|
502
|
-
this.matchedCommandName = matchedCommandName;
|
|
503
|
-
}
|
|
504
|
-
return this;
|
|
505
|
-
}
|
|
506
|
-
unsetMatchedCommand() {
|
|
507
|
-
this.matchedCommand = void 0;
|
|
508
|
-
this.matchedCommandName = void 0;
|
|
509
|
-
}
|
|
510
|
-
parse(argv = processArgs, {
|
|
511
|
-
run = true
|
|
512
|
-
} = {}) {
|
|
513
|
-
this.rawArgs = argv;
|
|
514
|
-
if (!this.name) {
|
|
515
|
-
this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
516
|
-
}
|
|
517
|
-
let shouldParse = true;
|
|
518
|
-
for (const command of this.commands) {
|
|
519
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
520
|
-
const commandName = parsed.args[0];
|
|
521
|
-
if (command.isMatched(commandName)) {
|
|
522
|
-
shouldParse = false;
|
|
523
|
-
const parsedInfo = __assign(__assign({}, parsed), {
|
|
524
|
-
args: parsed.args.slice(1)
|
|
525
|
-
});
|
|
526
|
-
this.setParsedInfo(parsedInfo, command, commandName);
|
|
527
|
-
this.emit(`command:${commandName}`, command);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
if (shouldParse) {
|
|
531
|
-
for (const command of this.commands) {
|
|
532
|
-
if (command.name === "") {
|
|
533
|
-
shouldParse = false;
|
|
534
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
535
|
-
this.setParsedInfo(parsed, command);
|
|
536
|
-
this.emit(`command:!`, command);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
if (shouldParse) {
|
|
541
|
-
const parsed = this.mri(argv.slice(2));
|
|
542
|
-
this.setParsedInfo(parsed);
|
|
543
|
-
}
|
|
544
|
-
if (this.options.help && this.showHelpOnExit) {
|
|
545
|
-
this.outputHelp();
|
|
546
|
-
run = false;
|
|
547
|
-
this.unsetMatchedCommand();
|
|
548
|
-
}
|
|
549
|
-
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
550
|
-
this.outputVersion();
|
|
551
|
-
run = false;
|
|
552
|
-
this.unsetMatchedCommand();
|
|
553
|
-
}
|
|
554
|
-
const parsedArgv = {args: this.args, options: this.options};
|
|
555
|
-
if (run) {
|
|
556
|
-
this.runMatchedCommand();
|
|
557
|
-
}
|
|
558
|
-
if (!this.matchedCommand && this.args[0]) {
|
|
559
|
-
this.emit("command:*");
|
|
560
|
-
}
|
|
561
|
-
return parsedArgv;
|
|
562
|
-
}
|
|
563
|
-
mri(argv, command) {
|
|
564
|
-
const cliOptions = [
|
|
565
|
-
...this.globalCommand.options,
|
|
566
|
-
...command ? command.options : []
|
|
567
|
-
];
|
|
568
|
-
const mriOptions = getMriOptions(cliOptions);
|
|
569
|
-
let argsAfterDoubleDashes = [];
|
|
570
|
-
const doubleDashesIndex = argv.indexOf("--");
|
|
571
|
-
if (doubleDashesIndex > -1) {
|
|
572
|
-
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
573
|
-
argv = argv.slice(0, doubleDashesIndex);
|
|
574
|
-
}
|
|
575
|
-
let parsed = mri2(argv, mriOptions);
|
|
576
|
-
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
577
|
-
return __assign(__assign({}, res), {
|
|
578
|
-
[camelcaseOptionName(name)]: parsed[name]
|
|
579
|
-
});
|
|
580
|
-
}, {_: []});
|
|
581
|
-
const args = parsed._;
|
|
582
|
-
const options = {
|
|
583
|
-
"--": argsAfterDoubleDashes
|
|
584
|
-
};
|
|
585
|
-
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
586
|
-
let transforms = Object.create(null);
|
|
587
|
-
for (const cliOption of cliOptions) {
|
|
588
|
-
if (!ignoreDefault && cliOption.config.default !== void 0) {
|
|
589
|
-
for (const name of cliOption.names) {
|
|
590
|
-
options[name] = cliOption.config.default;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
if (Array.isArray(cliOption.config.type)) {
|
|
594
|
-
if (transforms[cliOption.name] === void 0) {
|
|
595
|
-
transforms[cliOption.name] = Object.create(null);
|
|
596
|
-
transforms[cliOption.name]["shouldTransform"] = true;
|
|
597
|
-
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
for (const key of Object.keys(parsed)) {
|
|
602
|
-
if (key !== "_") {
|
|
603
|
-
const keys = key.split(".");
|
|
604
|
-
setDotProp(options, keys, parsed[key]);
|
|
605
|
-
setByType(options, transforms);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
return {
|
|
609
|
-
args,
|
|
610
|
-
options
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
runMatchedCommand() {
|
|
614
|
-
const {args, options, matchedCommand: command} = this;
|
|
615
|
-
if (!command || !command.commandAction)
|
|
616
|
-
return;
|
|
617
|
-
command.checkUnknownOptions();
|
|
618
|
-
command.checkOptionValue();
|
|
619
|
-
command.checkRequiredArgs();
|
|
620
|
-
const actionArgs = [];
|
|
621
|
-
command.args.forEach((arg, index) => {
|
|
622
|
-
if (arg.variadic) {
|
|
623
|
-
actionArgs.push(args.slice(index));
|
|
624
|
-
} else {
|
|
625
|
-
actionArgs.push(args[index]);
|
|
626
|
-
}
|
|
627
|
-
});
|
|
628
|
-
actionArgs.push(options);
|
|
629
|
-
return command.commandAction.apply(this, actionArgs);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
const cac = (name = "") => new CAC(name);
|
|
634
|
-
|
|
635
|
-
var version = "0.26.3";
|
|
21
|
+
var version = "0.27.0";
|
|
636
22
|
|
|
637
23
|
const cli = cac("vite-node");
|
|
638
24
|
cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
|
|
@@ -641,7 +27,7 @@ cli.parse();
|
|
|
641
27
|
async function run(files, options = {}) {
|
|
642
28
|
var _a;
|
|
643
29
|
if (!files.length) {
|
|
644
|
-
console.error(
|
|
30
|
+
console.error(c.red("No files specified."));
|
|
645
31
|
cli.outputHelp();
|
|
646
32
|
process.exit(1);
|
|
647
33
|
}
|
|
@@ -683,7 +69,7 @@ async function run(files, options = {}) {
|
|
|
683
69
|
});
|
|
684
70
|
if (options.watch) {
|
|
685
71
|
process.on("uncaughtException", (err) => {
|
|
686
|
-
console.error(
|
|
72
|
+
console.error(c.red("[vite-node] Failed to execute file: \n"), err);
|
|
687
73
|
});
|
|
688
74
|
}
|
|
689
75
|
}
|
package/dist/client.cjs
CHANGED
|
@@ -344,6 +344,12 @@ ${getStack()}`), 2e3);
|
|
|
344
344
|
if (!this.shouldInterop(path, importedModule))
|
|
345
345
|
return importedModule;
|
|
346
346
|
const { mod, defaultExport } = interopModule(importedModule);
|
|
347
|
+
const modKeys = Reflect.ownKeys(mod);
|
|
348
|
+
let defaultKeys = !utils.isPrimitive(defaultExport) ? Reflect.ownKeys(defaultExport) : [];
|
|
349
|
+
if (typeof mod !== "function" && typeof defaultExport === "function") {
|
|
350
|
+
const reservedKeys = ["arguments", "caller", "prototype", "name", "length"];
|
|
351
|
+
defaultKeys = defaultKeys.filter((n) => typeof n === "string" && !reservedKeys.includes(n));
|
|
352
|
+
}
|
|
347
353
|
return new Proxy(mod, {
|
|
348
354
|
get(mod2, prop) {
|
|
349
355
|
if (prop === "default")
|
|
@@ -355,11 +361,10 @@ ${getStack()}`), 2e3);
|
|
|
355
361
|
return defaultExport !== void 0;
|
|
356
362
|
return prop in mod2 || defaultExport && prop in defaultExport;
|
|
357
363
|
},
|
|
358
|
-
ownKeys(
|
|
359
|
-
const keys = Reflect.ownKeys(mod2);
|
|
364
|
+
ownKeys() {
|
|
360
365
|
if (!defaultExport || utils.isPrimitive(defaultExport))
|
|
361
|
-
return
|
|
362
|
-
const allKeys = [...
|
|
366
|
+
return modKeys;
|
|
367
|
+
const allKeys = [...modKeys, "default", ...defaultKeys];
|
|
363
368
|
return Array.from(new Set(allKeys));
|
|
364
369
|
},
|
|
365
370
|
getOwnPropertyDescriptor(mod2, prop) {
|
package/dist/client.mjs
CHANGED
|
@@ -317,6 +317,12 @@ ${getStack()}`), 2e3);
|
|
|
317
317
|
if (!this.shouldInterop(path, importedModule))
|
|
318
318
|
return importedModule;
|
|
319
319
|
const { mod, defaultExport } = interopModule(importedModule);
|
|
320
|
+
const modKeys = Reflect.ownKeys(mod);
|
|
321
|
+
let defaultKeys = !isPrimitive(defaultExport) ? Reflect.ownKeys(defaultExport) : [];
|
|
322
|
+
if (typeof mod !== "function" && typeof defaultExport === "function") {
|
|
323
|
+
const reservedKeys = ["arguments", "caller", "prototype", "name", "length"];
|
|
324
|
+
defaultKeys = defaultKeys.filter((n) => typeof n === "string" && !reservedKeys.includes(n));
|
|
325
|
+
}
|
|
320
326
|
return new Proxy(mod, {
|
|
321
327
|
get(mod2, prop) {
|
|
322
328
|
if (prop === "default")
|
|
@@ -328,11 +334,10 @@ ${getStack()}`), 2e3);
|
|
|
328
334
|
return defaultExport !== void 0;
|
|
329
335
|
return prop in mod2 || defaultExport && prop in defaultExport;
|
|
330
336
|
},
|
|
331
|
-
ownKeys(
|
|
332
|
-
const keys = Reflect.ownKeys(mod2);
|
|
337
|
+
ownKeys() {
|
|
333
338
|
if (!defaultExport || isPrimitive(defaultExport))
|
|
334
|
-
return
|
|
335
|
-
const allKeys = [...
|
|
339
|
+
return modKeys;
|
|
340
|
+
const allKeys = [...modKeys, "default", ...defaultKeys];
|
|
336
341
|
return Array.from(new Set(allKeys));
|
|
337
342
|
},
|
|
338
343
|
getOwnPropertyDescriptor(mod2, prop) {
|