@cordy/electro-cli 1.2.20 → 1.3.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/index.mjs +81 -1672
- package/package.json +13 -16
package/dist/index.mjs
CHANGED
|
@@ -1,498 +1,17 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
import { builtinModules } from "node:module";
|
|
3
|
-
import
|
|
3
|
+
import cac from "cac";
|
|
4
4
|
import { access, mkdir, readFile, rm, unlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
6
6
|
import { generate, scan } from "@cordy/electro-generator";
|
|
7
7
|
import { build, createLogger, createServer, mergeConfig, version } from "vite";
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
|
+
import MagicString from "magic-string";
|
|
9
10
|
import { tmpdir } from "node:os";
|
|
10
11
|
import { spawn } from "node:child_process";
|
|
11
12
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
12
|
-
|
|
13
|
-
//#region ../../node_modules/.bun/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
14
|
-
function toArr(any) {
|
|
15
|
-
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
16
|
-
}
|
|
17
|
-
function toVal(out, key, val, opts) {
|
|
18
|
-
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
19
|
-
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
20
|
-
}
|
|
21
|
-
function mri2(args, opts) {
|
|
22
|
-
args = args || [];
|
|
23
|
-
opts = opts || {};
|
|
24
|
-
var k, arr, arg, name, val, out = { _: [] };
|
|
25
|
-
var i = 0, j = 0, idx = 0, len = args.length;
|
|
26
|
-
const alibi = opts.alias !== void 0;
|
|
27
|
-
const strict = opts.unknown !== void 0;
|
|
28
|
-
const defaults = opts.default !== void 0;
|
|
29
|
-
opts.alias = opts.alias || {};
|
|
30
|
-
opts.string = toArr(opts.string);
|
|
31
|
-
opts.boolean = toArr(opts.boolean);
|
|
32
|
-
if (alibi) for (k in opts.alias) {
|
|
33
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
34
|
-
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
35
|
-
}
|
|
36
|
-
for (i = opts.boolean.length; i-- > 0;) {
|
|
37
|
-
arr = opts.alias[opts.boolean[i]] || [];
|
|
38
|
-
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
39
|
-
}
|
|
40
|
-
for (i = opts.string.length; i-- > 0;) {
|
|
41
|
-
arr = opts.alias[opts.string[i]] || [];
|
|
42
|
-
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
43
|
-
}
|
|
44
|
-
if (defaults) for (k in opts.default) {
|
|
45
|
-
name = typeof opts.default[k];
|
|
46
|
-
arr = opts.alias[k] = opts.alias[k] || [];
|
|
47
|
-
if (opts[name] !== void 0) {
|
|
48
|
-
opts[name].push(k);
|
|
49
|
-
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const keys = strict ? Object.keys(opts.alias) : [];
|
|
53
|
-
for (i = 0; i < len; i++) {
|
|
54
|
-
arg = args[i];
|
|
55
|
-
if (arg === "--") {
|
|
56
|
-
out._ = out._.concat(args.slice(++i));
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
60
|
-
if (j === 0) out._.push(arg);
|
|
61
|
-
else if (arg.substring(j, j + 3) === "no-") {
|
|
62
|
-
name = arg.substring(j + 3);
|
|
63
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
64
|
-
out[name] = false;
|
|
65
|
-
} else {
|
|
66
|
-
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
67
|
-
name = arg.substring(j, idx);
|
|
68
|
-
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
69
|
-
arr = j === 2 ? [name] : name;
|
|
70
|
-
for (idx = 0; idx < arr.length; idx++) {
|
|
71
|
-
name = arr[idx];
|
|
72
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
73
|
-
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (defaults) {
|
|
78
|
-
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
79
|
-
}
|
|
80
|
-
if (alibi) for (k in out) {
|
|
81
|
-
arr = opts.alias[k] || [];
|
|
82
|
-
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
83
|
-
}
|
|
84
|
-
return out;
|
|
85
|
-
}
|
|
86
|
-
const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
|
87
|
-
const findAllBrackets = (v) => {
|
|
88
|
-
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
89
|
-
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
90
|
-
const res = [];
|
|
91
|
-
const parse = (match) => {
|
|
92
|
-
let variadic = false;
|
|
93
|
-
let value = match[1];
|
|
94
|
-
if (value.startsWith("...")) {
|
|
95
|
-
value = value.slice(3);
|
|
96
|
-
variadic = true;
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
required: match[0].startsWith("<"),
|
|
100
|
-
value,
|
|
101
|
-
variadic
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
let angledMatch;
|
|
105
|
-
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
|
106
|
-
let squareMatch;
|
|
107
|
-
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
|
108
|
-
return res;
|
|
109
|
-
};
|
|
110
|
-
const getMriOptions = (options) => {
|
|
111
|
-
const result = {
|
|
112
|
-
alias: {},
|
|
113
|
-
boolean: []
|
|
114
|
-
};
|
|
115
|
-
for (const [index, option] of options.entries()) {
|
|
116
|
-
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
117
|
-
if (option.isBoolean) if (option.negated) {
|
|
118
|
-
if (!options.some((o, i) => {
|
|
119
|
-
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
120
|
-
})) result.boolean.push(option.names[0]);
|
|
121
|
-
} else result.boolean.push(option.names[0]);
|
|
122
|
-
}
|
|
123
|
-
return result;
|
|
124
|
-
};
|
|
125
|
-
const findLongest = (arr) => {
|
|
126
|
-
return arr.sort((a, b) => {
|
|
127
|
-
return a.length > b.length ? -1 : 1;
|
|
128
|
-
})[0];
|
|
129
|
-
};
|
|
130
|
-
const padRight = (str, length) => {
|
|
131
|
-
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
132
|
-
};
|
|
133
|
-
const camelcase = (input) => {
|
|
134
|
-
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
135
|
-
return p1 + p2.toUpperCase();
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
const setDotProp = (obj, keys, val) => {
|
|
139
|
-
let i = 0;
|
|
140
|
-
let length = keys.length;
|
|
141
|
-
let t = obj;
|
|
142
|
-
let x;
|
|
143
|
-
for (; i < length; ++i) {
|
|
144
|
-
x = t[keys[i]];
|
|
145
|
-
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
const setByType = (obj, transforms) => {
|
|
149
|
-
for (const key of Object.keys(transforms)) {
|
|
150
|
-
const transform = transforms[key];
|
|
151
|
-
if (transform.shouldTransform) {
|
|
152
|
-
obj[key] = Array.prototype.concat.call([], obj[key]);
|
|
153
|
-
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const getFileName = (input) => {
|
|
158
|
-
const m = /([^\\\/]+)$/.exec(input);
|
|
159
|
-
return m ? m[1] : "";
|
|
160
|
-
};
|
|
161
|
-
const camelcaseOptionName = (name) => {
|
|
162
|
-
return name.split(".").map((v, i) => {
|
|
163
|
-
return i === 0 ? camelcase(v) : v;
|
|
164
|
-
}).join(".");
|
|
165
|
-
};
|
|
166
|
-
var CACError = class extends Error {
|
|
167
|
-
constructor(message) {
|
|
168
|
-
super(message);
|
|
169
|
-
this.name = this.constructor.name;
|
|
170
|
-
if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, this.constructor);
|
|
171
|
-
else this.stack = new Error(message).stack;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
var Option = class {
|
|
175
|
-
constructor(rawName, description, config) {
|
|
176
|
-
this.rawName = rawName;
|
|
177
|
-
this.description = description;
|
|
178
|
-
this.config = Object.assign({}, config);
|
|
179
|
-
rawName = rawName.replace(/\.\*/g, "");
|
|
180
|
-
this.negated = false;
|
|
181
|
-
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
182
|
-
let name = v.trim().replace(/^-{1,2}/, "");
|
|
183
|
-
if (name.startsWith("no-")) {
|
|
184
|
-
this.negated = true;
|
|
185
|
-
name = name.replace(/^no-/, "");
|
|
186
|
-
}
|
|
187
|
-
return camelcaseOptionName(name);
|
|
188
|
-
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
189
|
-
this.name = this.names[this.names.length - 1];
|
|
190
|
-
if (this.negated && this.config.default == null) this.config.default = true;
|
|
191
|
-
if (rawName.includes("<")) this.required = true;
|
|
192
|
-
else if (rawName.includes("[")) this.required = false;
|
|
193
|
-
else this.isBoolean = true;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
const processArgs = process.argv;
|
|
197
|
-
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
198
|
-
var Command = class {
|
|
199
|
-
constructor(rawName, description, config = {}, cli) {
|
|
200
|
-
this.rawName = rawName;
|
|
201
|
-
this.description = description;
|
|
202
|
-
this.config = config;
|
|
203
|
-
this.cli = cli;
|
|
204
|
-
this.options = [];
|
|
205
|
-
this.aliasNames = [];
|
|
206
|
-
this.name = removeBrackets(rawName);
|
|
207
|
-
this.args = findAllBrackets(rawName);
|
|
208
|
-
this.examples = [];
|
|
209
|
-
}
|
|
210
|
-
usage(text) {
|
|
211
|
-
this.usageText = text;
|
|
212
|
-
return this;
|
|
213
|
-
}
|
|
214
|
-
allowUnknownOptions() {
|
|
215
|
-
this.config.allowUnknownOptions = true;
|
|
216
|
-
return this;
|
|
217
|
-
}
|
|
218
|
-
ignoreOptionDefaultValue() {
|
|
219
|
-
this.config.ignoreOptionDefaultValue = true;
|
|
220
|
-
return this;
|
|
221
|
-
}
|
|
222
|
-
version(version, customFlags = "-v, --version") {
|
|
223
|
-
this.versionNumber = version;
|
|
224
|
-
this.option(customFlags, "Display version number");
|
|
225
|
-
return this;
|
|
226
|
-
}
|
|
227
|
-
example(example) {
|
|
228
|
-
this.examples.push(example);
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
option(rawName, description, config) {
|
|
232
|
-
const option = new Option(rawName, description, config);
|
|
233
|
-
this.options.push(option);
|
|
234
|
-
return this;
|
|
235
|
-
}
|
|
236
|
-
alias(name) {
|
|
237
|
-
this.aliasNames.push(name);
|
|
238
|
-
return this;
|
|
239
|
-
}
|
|
240
|
-
action(callback) {
|
|
241
|
-
this.commandAction = callback;
|
|
242
|
-
return this;
|
|
243
|
-
}
|
|
244
|
-
isMatched(name) {
|
|
245
|
-
return this.name === name || this.aliasNames.includes(name);
|
|
246
|
-
}
|
|
247
|
-
get isDefaultCommand() {
|
|
248
|
-
return this.name === "" || this.aliasNames.includes("!");
|
|
249
|
-
}
|
|
250
|
-
get isGlobalCommand() {
|
|
251
|
-
return this instanceof GlobalCommand;
|
|
252
|
-
}
|
|
253
|
-
hasOption(name) {
|
|
254
|
-
name = name.split(".")[0];
|
|
255
|
-
return this.options.find((option) => {
|
|
256
|
-
return option.names.includes(name);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
outputHelp() {
|
|
260
|
-
const { name, commands } = this.cli;
|
|
261
|
-
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
262
|
-
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
|
263
|
-
sections.push({
|
|
264
|
-
title: "Usage",
|
|
265
|
-
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
266
|
-
});
|
|
267
|
-
if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
|
|
268
|
-
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
269
|
-
sections.push({
|
|
270
|
-
title: "Commands",
|
|
271
|
-
body: commands.map((command) => {
|
|
272
|
-
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
273
|
-
}).join("\n")
|
|
274
|
-
});
|
|
275
|
-
sections.push({
|
|
276
|
-
title: `For more info, run any command with the \`--help\` flag`,
|
|
277
|
-
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
281
|
-
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
|
282
|
-
if (options.length > 0) {
|
|
283
|
-
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
284
|
-
sections.push({
|
|
285
|
-
title: "Options",
|
|
286
|
-
body: options.map((option) => {
|
|
287
|
-
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
288
|
-
}).join("\n")
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
if (this.examples.length > 0) sections.push({
|
|
292
|
-
title: "Examples",
|
|
293
|
-
body: this.examples.map((example) => {
|
|
294
|
-
if (typeof example === "function") return example(name);
|
|
295
|
-
return example;
|
|
296
|
-
}).join("\n")
|
|
297
|
-
});
|
|
298
|
-
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
299
|
-
console.log(sections.map((section) => {
|
|
300
|
-
return section.title ? `${section.title}:
|
|
301
|
-
${section.body}` : section.body;
|
|
302
|
-
}).join("\n\n"));
|
|
303
|
-
}
|
|
304
|
-
outputVersion() {
|
|
305
|
-
const { name } = this.cli;
|
|
306
|
-
const { versionNumber } = this.cli.globalCommand;
|
|
307
|
-
if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
308
|
-
}
|
|
309
|
-
checkRequiredArgs() {
|
|
310
|
-
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
311
|
-
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
312
|
-
}
|
|
313
|
-
checkUnknownOptions() {
|
|
314
|
-
const { options, globalCommand } = this.cli;
|
|
315
|
-
if (!this.config.allowUnknownOptions) {
|
|
316
|
-
for (const name of Object.keys(options)) if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
checkOptionValue() {
|
|
320
|
-
const { options: parsedOptions, globalCommand } = this.cli;
|
|
321
|
-
const options = [...globalCommand.options, ...this.options];
|
|
322
|
-
for (const option of options) {
|
|
323
|
-
const value = parsedOptions[option.name.split(".")[0]];
|
|
324
|
-
if (option.required) {
|
|
325
|
-
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
326
|
-
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
var GlobalCommand = class extends Command {
|
|
332
|
-
constructor(cli) {
|
|
333
|
-
super("@@global@@", "", {}, cli);
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
var __assign = Object.assign;
|
|
337
|
-
var CAC = class extends EventEmitter {
|
|
338
|
-
constructor(name = "") {
|
|
339
|
-
super();
|
|
340
|
-
this.name = name;
|
|
341
|
-
this.commands = [];
|
|
342
|
-
this.rawArgs = [];
|
|
343
|
-
this.args = [];
|
|
344
|
-
this.options = {};
|
|
345
|
-
this.globalCommand = new GlobalCommand(this);
|
|
346
|
-
this.globalCommand.usage("<command> [options]");
|
|
347
|
-
}
|
|
348
|
-
usage(text) {
|
|
349
|
-
this.globalCommand.usage(text);
|
|
350
|
-
return this;
|
|
351
|
-
}
|
|
352
|
-
command(rawName, description, config) {
|
|
353
|
-
const command = new Command(rawName, description || "", config, this);
|
|
354
|
-
command.globalCommand = this.globalCommand;
|
|
355
|
-
this.commands.push(command);
|
|
356
|
-
return command;
|
|
357
|
-
}
|
|
358
|
-
option(rawName, description, config) {
|
|
359
|
-
this.globalCommand.option(rawName, description, config);
|
|
360
|
-
return this;
|
|
361
|
-
}
|
|
362
|
-
help(callback) {
|
|
363
|
-
this.globalCommand.option("-h, --help", "Display this message");
|
|
364
|
-
this.globalCommand.helpCallback = callback;
|
|
365
|
-
this.showHelpOnExit = true;
|
|
366
|
-
return this;
|
|
367
|
-
}
|
|
368
|
-
version(version, customFlags = "-v, --version") {
|
|
369
|
-
this.globalCommand.version(version, customFlags);
|
|
370
|
-
this.showVersionOnExit = true;
|
|
371
|
-
return this;
|
|
372
|
-
}
|
|
373
|
-
example(example) {
|
|
374
|
-
this.globalCommand.example(example);
|
|
375
|
-
return this;
|
|
376
|
-
}
|
|
377
|
-
outputHelp() {
|
|
378
|
-
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
379
|
-
else this.globalCommand.outputHelp();
|
|
380
|
-
}
|
|
381
|
-
outputVersion() {
|
|
382
|
-
this.globalCommand.outputVersion();
|
|
383
|
-
}
|
|
384
|
-
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
385
|
-
this.args = args;
|
|
386
|
-
this.options = options;
|
|
387
|
-
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
388
|
-
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
389
|
-
return this;
|
|
390
|
-
}
|
|
391
|
-
unsetMatchedCommand() {
|
|
392
|
-
this.matchedCommand = void 0;
|
|
393
|
-
this.matchedCommandName = void 0;
|
|
394
|
-
}
|
|
395
|
-
parse(argv = processArgs, { run = true } = {}) {
|
|
396
|
-
this.rawArgs = argv;
|
|
397
|
-
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
398
|
-
let shouldParse = true;
|
|
399
|
-
for (const command of this.commands) {
|
|
400
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
401
|
-
const commandName = parsed.args[0];
|
|
402
|
-
if (command.isMatched(commandName)) {
|
|
403
|
-
shouldParse = false;
|
|
404
|
-
const parsedInfo = __assign(__assign({}, parsed), { args: parsed.args.slice(1) });
|
|
405
|
-
this.setParsedInfo(parsedInfo, command, commandName);
|
|
406
|
-
this.emit(`command:${commandName}`, command);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
if (shouldParse) {
|
|
410
|
-
for (const command of this.commands) if (command.name === "") {
|
|
411
|
-
shouldParse = false;
|
|
412
|
-
const parsed = this.mri(argv.slice(2), command);
|
|
413
|
-
this.setParsedInfo(parsed, command);
|
|
414
|
-
this.emit(`command:!`, command);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
if (shouldParse) {
|
|
418
|
-
const parsed = this.mri(argv.slice(2));
|
|
419
|
-
this.setParsedInfo(parsed);
|
|
420
|
-
}
|
|
421
|
-
if (this.options.help && this.showHelpOnExit) {
|
|
422
|
-
this.outputHelp();
|
|
423
|
-
run = false;
|
|
424
|
-
this.unsetMatchedCommand();
|
|
425
|
-
}
|
|
426
|
-
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
427
|
-
this.outputVersion();
|
|
428
|
-
run = false;
|
|
429
|
-
this.unsetMatchedCommand();
|
|
430
|
-
}
|
|
431
|
-
const parsedArgv = {
|
|
432
|
-
args: this.args,
|
|
433
|
-
options: this.options
|
|
434
|
-
};
|
|
435
|
-
if (run) this.runMatchedCommand();
|
|
436
|
-
if (!this.matchedCommand && this.args[0]) this.emit("command:*");
|
|
437
|
-
return parsedArgv;
|
|
438
|
-
}
|
|
439
|
-
mri(argv, command) {
|
|
440
|
-
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
|
441
|
-
const mriOptions = getMriOptions(cliOptions);
|
|
442
|
-
let argsAfterDoubleDashes = [];
|
|
443
|
-
const doubleDashesIndex = argv.indexOf("--");
|
|
444
|
-
if (doubleDashesIndex > -1) {
|
|
445
|
-
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
446
|
-
argv = argv.slice(0, doubleDashesIndex);
|
|
447
|
-
}
|
|
448
|
-
let parsed = mri2(argv, mriOptions);
|
|
449
|
-
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
450
|
-
return __assign(__assign({}, res), { [camelcaseOptionName(name)]: parsed[name] });
|
|
451
|
-
}, { _: [] });
|
|
452
|
-
const args = parsed._;
|
|
453
|
-
const options = { "--": argsAfterDoubleDashes };
|
|
454
|
-
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
455
|
-
let transforms = Object.create(null);
|
|
456
|
-
for (const cliOption of cliOptions) {
|
|
457
|
-
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
|
458
|
-
if (Array.isArray(cliOption.config.type)) {
|
|
459
|
-
if (transforms[cliOption.name] === void 0) {
|
|
460
|
-
transforms[cliOption.name] = Object.create(null);
|
|
461
|
-
transforms[cliOption.name]["shouldTransform"] = true;
|
|
462
|
-
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
for (const key of Object.keys(parsed)) if (key !== "_") {
|
|
467
|
-
setDotProp(options, key.split("."), parsed[key]);
|
|
468
|
-
setByType(options, transforms);
|
|
469
|
-
}
|
|
470
|
-
return {
|
|
471
|
-
args,
|
|
472
|
-
options
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
runMatchedCommand() {
|
|
476
|
-
const { args, options, matchedCommand: command } = this;
|
|
477
|
-
if (!command || !command.commandAction) return;
|
|
478
|
-
command.checkUnknownOptions();
|
|
479
|
-
command.checkOptionValue();
|
|
480
|
-
command.checkRequiredArgs();
|
|
481
|
-
const actionArgs = [];
|
|
482
|
-
command.args.forEach((arg, index) => {
|
|
483
|
-
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
484
|
-
else actionArgs.push(args[index]);
|
|
485
|
-
});
|
|
486
|
-
actionArgs.push(options);
|
|
487
|
-
return command.commandAction.apply(this, actionArgs);
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
const cac = (name = "") => new CAC(name);
|
|
491
|
-
|
|
492
|
-
//#endregion
|
|
493
13
|
//#region package.json
|
|
494
|
-
var version$1 = "1.
|
|
495
|
-
|
|
14
|
+
var version$1 = "1.3.0";
|
|
496
15
|
//#endregion
|
|
497
16
|
//#region src/dev/bridge-types.ts
|
|
498
17
|
const GENERATED_BRIDGE_DIRS = ["views", "windows"];
|
|
@@ -521,7 +40,6 @@ function isGeneratedBridgeTypesPath(path) {
|
|
|
521
40
|
function generatedBridgeTypesPaths(viewName) {
|
|
522
41
|
return GENERATED_BRIDGE_DIRS.map((dir) => `generated/${dir}/${viewName}.bridge.d.ts`);
|
|
523
42
|
}
|
|
524
|
-
|
|
525
43
|
//#endregion
|
|
526
44
|
//#region src/dev/logger.ts
|
|
527
45
|
const yellow$1 = "\x1B[33m";
|
|
@@ -749,7 +267,6 @@ function createBuildLogger() {
|
|
|
749
267
|
};
|
|
750
268
|
return logger;
|
|
751
269
|
}
|
|
752
|
-
|
|
753
270
|
//#endregion
|
|
754
271
|
//#region src/validate.ts
|
|
755
272
|
const VALID_SOURCEMAP_VALUES = [
|
|
@@ -832,7 +349,6 @@ function validateViteVersion(viteVersion) {
|
|
|
832
349
|
process.exit(1);
|
|
833
350
|
}
|
|
834
351
|
}
|
|
835
|
-
|
|
836
352
|
//#endregion
|
|
837
353
|
//#region src/dev/config-loader.ts
|
|
838
354
|
async function loadConfig(configPath) {
|
|
@@ -853,7 +369,6 @@ async function loadConfig(configPath) {
|
|
|
853
369
|
root
|
|
854
370
|
};
|
|
855
371
|
}
|
|
856
|
-
|
|
857
372
|
//#endregion
|
|
858
373
|
//#region src/dev/externals.ts
|
|
859
374
|
/**
|
|
@@ -915,7 +430,6 @@ function hasImportCondition(value) {
|
|
|
915
430
|
for (const nested of Object.values(record)) if (hasImportCondition(nested)) return true;
|
|
916
431
|
return false;
|
|
917
432
|
}
|
|
918
|
-
|
|
919
433
|
//#endregion
|
|
920
434
|
//#region src/dev/node-format.ts
|
|
921
435
|
/**
|
|
@@ -955,1019 +469,6 @@ async function pathExists(filePath) {
|
|
|
955
469
|
return false;
|
|
956
470
|
}
|
|
957
471
|
}
|
|
958
|
-
|
|
959
|
-
//#endregion
|
|
960
|
-
//#region ../../node_modules/.bun/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
961
|
-
var comma = ",".charCodeAt(0);
|
|
962
|
-
var semicolon = ";".charCodeAt(0);
|
|
963
|
-
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
964
|
-
var intToChar = new Uint8Array(64);
|
|
965
|
-
var charToInt = new Uint8Array(128);
|
|
966
|
-
for (let i = 0; i < chars.length; i++) {
|
|
967
|
-
const c = chars.charCodeAt(i);
|
|
968
|
-
intToChar[i] = c;
|
|
969
|
-
charToInt[c] = i;
|
|
970
|
-
}
|
|
971
|
-
function encodeInteger(builder, num, relative) {
|
|
972
|
-
let delta = num - relative;
|
|
973
|
-
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
974
|
-
do {
|
|
975
|
-
let clamped = delta & 31;
|
|
976
|
-
delta >>>= 5;
|
|
977
|
-
if (delta > 0) clamped |= 32;
|
|
978
|
-
builder.write(intToChar[clamped]);
|
|
979
|
-
} while (delta > 0);
|
|
980
|
-
return num;
|
|
981
|
-
}
|
|
982
|
-
var bufLength = 1024 * 16;
|
|
983
|
-
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
|
|
984
|
-
return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
|
|
985
|
-
} } : { decode(buf) {
|
|
986
|
-
let out = "";
|
|
987
|
-
for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
|
|
988
|
-
return out;
|
|
989
|
-
} };
|
|
990
|
-
var StringWriter = class {
|
|
991
|
-
constructor() {
|
|
992
|
-
this.pos = 0;
|
|
993
|
-
this.out = "";
|
|
994
|
-
this.buffer = new Uint8Array(bufLength);
|
|
995
|
-
}
|
|
996
|
-
write(v) {
|
|
997
|
-
const { buffer } = this;
|
|
998
|
-
buffer[this.pos++] = v;
|
|
999
|
-
if (this.pos === bufLength) {
|
|
1000
|
-
this.out += td.decode(buffer);
|
|
1001
|
-
this.pos = 0;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
flush() {
|
|
1005
|
-
const { buffer, out, pos } = this;
|
|
1006
|
-
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
1007
|
-
}
|
|
1008
|
-
};
|
|
1009
|
-
function encode(decoded) {
|
|
1010
|
-
const writer = new StringWriter();
|
|
1011
|
-
let sourcesIndex = 0;
|
|
1012
|
-
let sourceLine = 0;
|
|
1013
|
-
let sourceColumn = 0;
|
|
1014
|
-
let namesIndex = 0;
|
|
1015
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
1016
|
-
const line = decoded[i];
|
|
1017
|
-
if (i > 0) writer.write(semicolon);
|
|
1018
|
-
if (line.length === 0) continue;
|
|
1019
|
-
let genColumn = 0;
|
|
1020
|
-
for (let j = 0; j < line.length; j++) {
|
|
1021
|
-
const segment = line[j];
|
|
1022
|
-
if (j > 0) writer.write(comma);
|
|
1023
|
-
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
1024
|
-
if (segment.length === 1) continue;
|
|
1025
|
-
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
1026
|
-
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
1027
|
-
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
1028
|
-
if (segment.length === 4) continue;
|
|
1029
|
-
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
return writer.flush();
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
//#endregion
|
|
1036
|
-
//#region ../../node_modules/.bun/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs
|
|
1037
|
-
var BitSet = class BitSet {
|
|
1038
|
-
constructor(arg) {
|
|
1039
|
-
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
1040
|
-
}
|
|
1041
|
-
add(n) {
|
|
1042
|
-
this.bits[n >> 5] |= 1 << (n & 31);
|
|
1043
|
-
}
|
|
1044
|
-
has(n) {
|
|
1045
|
-
return !!(this.bits[n >> 5] & 1 << (n & 31));
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
var Chunk = class Chunk {
|
|
1049
|
-
constructor(start, end, content) {
|
|
1050
|
-
this.start = start;
|
|
1051
|
-
this.end = end;
|
|
1052
|
-
this.original = content;
|
|
1053
|
-
this.intro = "";
|
|
1054
|
-
this.outro = "";
|
|
1055
|
-
this.content = content;
|
|
1056
|
-
this.storeName = false;
|
|
1057
|
-
this.edited = false;
|
|
1058
|
-
this.previous = null;
|
|
1059
|
-
this.next = null;
|
|
1060
|
-
}
|
|
1061
|
-
appendLeft(content) {
|
|
1062
|
-
this.outro += content;
|
|
1063
|
-
}
|
|
1064
|
-
appendRight(content) {
|
|
1065
|
-
this.intro = this.intro + content;
|
|
1066
|
-
}
|
|
1067
|
-
clone() {
|
|
1068
|
-
const chunk = new Chunk(this.start, this.end, this.original);
|
|
1069
|
-
chunk.intro = this.intro;
|
|
1070
|
-
chunk.outro = this.outro;
|
|
1071
|
-
chunk.content = this.content;
|
|
1072
|
-
chunk.storeName = this.storeName;
|
|
1073
|
-
chunk.edited = this.edited;
|
|
1074
|
-
return chunk;
|
|
1075
|
-
}
|
|
1076
|
-
contains(index) {
|
|
1077
|
-
return this.start < index && index < this.end;
|
|
1078
|
-
}
|
|
1079
|
-
eachNext(fn) {
|
|
1080
|
-
let chunk = this;
|
|
1081
|
-
while (chunk) {
|
|
1082
|
-
fn(chunk);
|
|
1083
|
-
chunk = chunk.next;
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
eachPrevious(fn) {
|
|
1087
|
-
let chunk = this;
|
|
1088
|
-
while (chunk) {
|
|
1089
|
-
fn(chunk);
|
|
1090
|
-
chunk = chunk.previous;
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
edit(content, storeName, contentOnly) {
|
|
1094
|
-
this.content = content;
|
|
1095
|
-
if (!contentOnly) {
|
|
1096
|
-
this.intro = "";
|
|
1097
|
-
this.outro = "";
|
|
1098
|
-
}
|
|
1099
|
-
this.storeName = storeName;
|
|
1100
|
-
this.edited = true;
|
|
1101
|
-
return this;
|
|
1102
|
-
}
|
|
1103
|
-
prependLeft(content) {
|
|
1104
|
-
this.outro = content + this.outro;
|
|
1105
|
-
}
|
|
1106
|
-
prependRight(content) {
|
|
1107
|
-
this.intro = content + this.intro;
|
|
1108
|
-
}
|
|
1109
|
-
reset() {
|
|
1110
|
-
this.intro = "";
|
|
1111
|
-
this.outro = "";
|
|
1112
|
-
if (this.edited) {
|
|
1113
|
-
this.content = this.original;
|
|
1114
|
-
this.storeName = false;
|
|
1115
|
-
this.edited = false;
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
split(index) {
|
|
1119
|
-
const sliceIndex = index - this.start;
|
|
1120
|
-
const originalBefore = this.original.slice(0, sliceIndex);
|
|
1121
|
-
const originalAfter = this.original.slice(sliceIndex);
|
|
1122
|
-
this.original = originalBefore;
|
|
1123
|
-
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
1124
|
-
newChunk.outro = this.outro;
|
|
1125
|
-
this.outro = "";
|
|
1126
|
-
this.end = index;
|
|
1127
|
-
if (this.edited) {
|
|
1128
|
-
newChunk.edit("", false);
|
|
1129
|
-
this.content = "";
|
|
1130
|
-
} else this.content = originalBefore;
|
|
1131
|
-
newChunk.next = this.next;
|
|
1132
|
-
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
1133
|
-
newChunk.previous = this;
|
|
1134
|
-
this.next = newChunk;
|
|
1135
|
-
return newChunk;
|
|
1136
|
-
}
|
|
1137
|
-
toString() {
|
|
1138
|
-
return this.intro + this.content + this.outro;
|
|
1139
|
-
}
|
|
1140
|
-
trimEnd(rx) {
|
|
1141
|
-
this.outro = this.outro.replace(rx, "");
|
|
1142
|
-
if (this.outro.length) return true;
|
|
1143
|
-
const trimmed = this.content.replace(rx, "");
|
|
1144
|
-
if (trimmed.length) {
|
|
1145
|
-
if (trimmed !== this.content) {
|
|
1146
|
-
this.split(this.start + trimmed.length).edit("", void 0, true);
|
|
1147
|
-
if (this.edited) this.edit(trimmed, this.storeName, true);
|
|
1148
|
-
}
|
|
1149
|
-
return true;
|
|
1150
|
-
} else {
|
|
1151
|
-
this.edit("", void 0, true);
|
|
1152
|
-
this.intro = this.intro.replace(rx, "");
|
|
1153
|
-
if (this.intro.length) return true;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
trimStart(rx) {
|
|
1157
|
-
this.intro = this.intro.replace(rx, "");
|
|
1158
|
-
if (this.intro.length) return true;
|
|
1159
|
-
const trimmed = this.content.replace(rx, "");
|
|
1160
|
-
if (trimmed.length) {
|
|
1161
|
-
if (trimmed !== this.content) {
|
|
1162
|
-
const newChunk = this.split(this.end - trimmed.length);
|
|
1163
|
-
if (this.edited) newChunk.edit(trimmed, this.storeName, true);
|
|
1164
|
-
this.edit("", void 0, true);
|
|
1165
|
-
}
|
|
1166
|
-
return true;
|
|
1167
|
-
} else {
|
|
1168
|
-
this.edit("", void 0, true);
|
|
1169
|
-
this.outro = this.outro.replace(rx, "");
|
|
1170
|
-
if (this.outro.length) return true;
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
};
|
|
1174
|
-
function getBtoa() {
|
|
1175
|
-
if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
1176
|
-
else if (typeof Buffer === "function") return (str) => Buffer.from(str, "utf-8").toString("base64");
|
|
1177
|
-
else return () => {
|
|
1178
|
-
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
|
-
const btoa = /* @__PURE__ */ getBtoa();
|
|
1182
|
-
var SourceMap = class {
|
|
1183
|
-
constructor(properties) {
|
|
1184
|
-
this.version = 3;
|
|
1185
|
-
this.file = properties.file;
|
|
1186
|
-
this.sources = properties.sources;
|
|
1187
|
-
this.sourcesContent = properties.sourcesContent;
|
|
1188
|
-
this.names = properties.names;
|
|
1189
|
-
this.mappings = encode(properties.mappings);
|
|
1190
|
-
if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
1191
|
-
if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
|
|
1192
|
-
}
|
|
1193
|
-
toString() {
|
|
1194
|
-
return JSON.stringify(this);
|
|
1195
|
-
}
|
|
1196
|
-
toUrl() {
|
|
1197
|
-
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
|
|
1198
|
-
}
|
|
1199
|
-
};
|
|
1200
|
-
function guessIndent(code) {
|
|
1201
|
-
const lines = code.split("\n");
|
|
1202
|
-
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
1203
|
-
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
1204
|
-
if (tabbed.length === 0 && spaced.length === 0) return null;
|
|
1205
|
-
if (tabbed.length >= spaced.length) return " ";
|
|
1206
|
-
const min = spaced.reduce((previous, current) => {
|
|
1207
|
-
const numSpaces = /^ +/.exec(current)[0].length;
|
|
1208
|
-
return Math.min(numSpaces, previous);
|
|
1209
|
-
}, Infinity);
|
|
1210
|
-
return new Array(min + 1).join(" ");
|
|
1211
|
-
}
|
|
1212
|
-
function getRelativePath(from, to) {
|
|
1213
|
-
const fromParts = from.split(/[/\\]/);
|
|
1214
|
-
const toParts = to.split(/[/\\]/);
|
|
1215
|
-
fromParts.pop();
|
|
1216
|
-
while (fromParts[0] === toParts[0]) {
|
|
1217
|
-
fromParts.shift();
|
|
1218
|
-
toParts.shift();
|
|
1219
|
-
}
|
|
1220
|
-
if (fromParts.length) {
|
|
1221
|
-
let i = fromParts.length;
|
|
1222
|
-
while (i--) fromParts[i] = "..";
|
|
1223
|
-
}
|
|
1224
|
-
return fromParts.concat(toParts).join("/");
|
|
1225
|
-
}
|
|
1226
|
-
const toString = Object.prototype.toString;
|
|
1227
|
-
function isObject(thing) {
|
|
1228
|
-
return toString.call(thing) === "[object Object]";
|
|
1229
|
-
}
|
|
1230
|
-
function getLocator(source) {
|
|
1231
|
-
const originalLines = source.split("\n");
|
|
1232
|
-
const lineOffsets = [];
|
|
1233
|
-
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
1234
|
-
lineOffsets.push(pos);
|
|
1235
|
-
pos += originalLines[i].length + 1;
|
|
1236
|
-
}
|
|
1237
|
-
return function locate(index) {
|
|
1238
|
-
let i = 0;
|
|
1239
|
-
let j = lineOffsets.length;
|
|
1240
|
-
while (i < j) {
|
|
1241
|
-
const m = i + j >> 1;
|
|
1242
|
-
if (index < lineOffsets[m]) j = m;
|
|
1243
|
-
else i = m + 1;
|
|
1244
|
-
}
|
|
1245
|
-
const line = i - 1;
|
|
1246
|
-
return {
|
|
1247
|
-
line,
|
|
1248
|
-
column: index - lineOffsets[line]
|
|
1249
|
-
};
|
|
1250
|
-
};
|
|
1251
|
-
}
|
|
1252
|
-
const wordRegex = /\w/;
|
|
1253
|
-
var Mappings = class {
|
|
1254
|
-
constructor(hires) {
|
|
1255
|
-
this.hires = hires;
|
|
1256
|
-
this.generatedCodeLine = 0;
|
|
1257
|
-
this.generatedCodeColumn = 0;
|
|
1258
|
-
this.raw = [];
|
|
1259
|
-
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
1260
|
-
this.pending = null;
|
|
1261
|
-
}
|
|
1262
|
-
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
1263
|
-
if (content.length) {
|
|
1264
|
-
const contentLengthMinusOne = content.length - 1;
|
|
1265
|
-
let contentLineEnd = content.indexOf("\n", 0);
|
|
1266
|
-
let previousContentLineEnd = -1;
|
|
1267
|
-
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
1268
|
-
const segment = [
|
|
1269
|
-
this.generatedCodeColumn,
|
|
1270
|
-
sourceIndex,
|
|
1271
|
-
loc.line,
|
|
1272
|
-
loc.column
|
|
1273
|
-
];
|
|
1274
|
-
if (nameIndex >= 0) segment.push(nameIndex);
|
|
1275
|
-
this.rawSegments.push(segment);
|
|
1276
|
-
this.generatedCodeLine += 1;
|
|
1277
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
1278
|
-
this.generatedCodeColumn = 0;
|
|
1279
|
-
previousContentLineEnd = contentLineEnd;
|
|
1280
|
-
contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
|
|
1281
|
-
}
|
|
1282
|
-
const segment = [
|
|
1283
|
-
this.generatedCodeColumn,
|
|
1284
|
-
sourceIndex,
|
|
1285
|
-
loc.line,
|
|
1286
|
-
loc.column
|
|
1287
|
-
];
|
|
1288
|
-
if (nameIndex >= 0) segment.push(nameIndex);
|
|
1289
|
-
this.rawSegments.push(segment);
|
|
1290
|
-
this.advance(content.slice(previousContentLineEnd + 1));
|
|
1291
|
-
} else if (this.pending) {
|
|
1292
|
-
this.rawSegments.push(this.pending);
|
|
1293
|
-
this.advance(content);
|
|
1294
|
-
}
|
|
1295
|
-
this.pending = null;
|
|
1296
|
-
}
|
|
1297
|
-
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
1298
|
-
let originalCharIndex = chunk.start;
|
|
1299
|
-
let first = true;
|
|
1300
|
-
let charInHiresBoundary = false;
|
|
1301
|
-
while (originalCharIndex < chunk.end) {
|
|
1302
|
-
if (original[originalCharIndex] === "\n") {
|
|
1303
|
-
loc.line += 1;
|
|
1304
|
-
loc.column = 0;
|
|
1305
|
-
this.generatedCodeLine += 1;
|
|
1306
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
1307
|
-
this.generatedCodeColumn = 0;
|
|
1308
|
-
first = true;
|
|
1309
|
-
charInHiresBoundary = false;
|
|
1310
|
-
} else {
|
|
1311
|
-
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
1312
|
-
const segment = [
|
|
1313
|
-
this.generatedCodeColumn,
|
|
1314
|
-
sourceIndex,
|
|
1315
|
-
loc.line,
|
|
1316
|
-
loc.column
|
|
1317
|
-
];
|
|
1318
|
-
if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
|
|
1319
|
-
if (!charInHiresBoundary) {
|
|
1320
|
-
this.rawSegments.push(segment);
|
|
1321
|
-
charInHiresBoundary = true;
|
|
1322
|
-
}
|
|
1323
|
-
} else {
|
|
1324
|
-
this.rawSegments.push(segment);
|
|
1325
|
-
charInHiresBoundary = false;
|
|
1326
|
-
}
|
|
1327
|
-
else this.rawSegments.push(segment);
|
|
1328
|
-
}
|
|
1329
|
-
loc.column += 1;
|
|
1330
|
-
this.generatedCodeColumn += 1;
|
|
1331
|
-
first = false;
|
|
1332
|
-
}
|
|
1333
|
-
originalCharIndex += 1;
|
|
1334
|
-
}
|
|
1335
|
-
this.pending = null;
|
|
1336
|
-
}
|
|
1337
|
-
advance(str) {
|
|
1338
|
-
if (!str) return;
|
|
1339
|
-
const lines = str.split("\n");
|
|
1340
|
-
if (lines.length > 1) {
|
|
1341
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
1342
|
-
this.generatedCodeLine++;
|
|
1343
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
1344
|
-
}
|
|
1345
|
-
this.generatedCodeColumn = 0;
|
|
1346
|
-
}
|
|
1347
|
-
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
1348
|
-
}
|
|
1349
|
-
};
|
|
1350
|
-
const n = "\n";
|
|
1351
|
-
const warned = {
|
|
1352
|
-
insertLeft: false,
|
|
1353
|
-
insertRight: false,
|
|
1354
|
-
storeName: false
|
|
1355
|
-
};
|
|
1356
|
-
var MagicString = class MagicString {
|
|
1357
|
-
constructor(string, options = {}) {
|
|
1358
|
-
const chunk = new Chunk(0, string.length, string);
|
|
1359
|
-
Object.defineProperties(this, {
|
|
1360
|
-
original: {
|
|
1361
|
-
writable: true,
|
|
1362
|
-
value: string
|
|
1363
|
-
},
|
|
1364
|
-
outro: {
|
|
1365
|
-
writable: true,
|
|
1366
|
-
value: ""
|
|
1367
|
-
},
|
|
1368
|
-
intro: {
|
|
1369
|
-
writable: true,
|
|
1370
|
-
value: ""
|
|
1371
|
-
},
|
|
1372
|
-
firstChunk: {
|
|
1373
|
-
writable: true,
|
|
1374
|
-
value: chunk
|
|
1375
|
-
},
|
|
1376
|
-
lastChunk: {
|
|
1377
|
-
writable: true,
|
|
1378
|
-
value: chunk
|
|
1379
|
-
},
|
|
1380
|
-
lastSearchedChunk: {
|
|
1381
|
-
writable: true,
|
|
1382
|
-
value: chunk
|
|
1383
|
-
},
|
|
1384
|
-
byStart: {
|
|
1385
|
-
writable: true,
|
|
1386
|
-
value: {}
|
|
1387
|
-
},
|
|
1388
|
-
byEnd: {
|
|
1389
|
-
writable: true,
|
|
1390
|
-
value: {}
|
|
1391
|
-
},
|
|
1392
|
-
filename: {
|
|
1393
|
-
writable: true,
|
|
1394
|
-
value: options.filename
|
|
1395
|
-
},
|
|
1396
|
-
indentExclusionRanges: {
|
|
1397
|
-
writable: true,
|
|
1398
|
-
value: options.indentExclusionRanges
|
|
1399
|
-
},
|
|
1400
|
-
sourcemapLocations: {
|
|
1401
|
-
writable: true,
|
|
1402
|
-
value: new BitSet()
|
|
1403
|
-
},
|
|
1404
|
-
storedNames: {
|
|
1405
|
-
writable: true,
|
|
1406
|
-
value: {}
|
|
1407
|
-
},
|
|
1408
|
-
indentStr: {
|
|
1409
|
-
writable: true,
|
|
1410
|
-
value: void 0
|
|
1411
|
-
},
|
|
1412
|
-
ignoreList: {
|
|
1413
|
-
writable: true,
|
|
1414
|
-
value: options.ignoreList
|
|
1415
|
-
},
|
|
1416
|
-
offset: {
|
|
1417
|
-
writable: true,
|
|
1418
|
-
value: options.offset || 0
|
|
1419
|
-
}
|
|
1420
|
-
});
|
|
1421
|
-
this.byStart[0] = chunk;
|
|
1422
|
-
this.byEnd[string.length] = chunk;
|
|
1423
|
-
}
|
|
1424
|
-
addSourcemapLocation(char) {
|
|
1425
|
-
this.sourcemapLocations.add(char);
|
|
1426
|
-
}
|
|
1427
|
-
append(content) {
|
|
1428
|
-
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
1429
|
-
this.outro += content;
|
|
1430
|
-
return this;
|
|
1431
|
-
}
|
|
1432
|
-
appendLeft(index, content) {
|
|
1433
|
-
index = index + this.offset;
|
|
1434
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
1435
|
-
this._split(index);
|
|
1436
|
-
const chunk = this.byEnd[index];
|
|
1437
|
-
if (chunk) chunk.appendLeft(content);
|
|
1438
|
-
else this.intro += content;
|
|
1439
|
-
return this;
|
|
1440
|
-
}
|
|
1441
|
-
appendRight(index, content) {
|
|
1442
|
-
index = index + this.offset;
|
|
1443
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
1444
|
-
this._split(index);
|
|
1445
|
-
const chunk = this.byStart[index];
|
|
1446
|
-
if (chunk) chunk.appendRight(content);
|
|
1447
|
-
else this.outro += content;
|
|
1448
|
-
return this;
|
|
1449
|
-
}
|
|
1450
|
-
clone() {
|
|
1451
|
-
const cloned = new MagicString(this.original, {
|
|
1452
|
-
filename: this.filename,
|
|
1453
|
-
offset: this.offset
|
|
1454
|
-
});
|
|
1455
|
-
let originalChunk = this.firstChunk;
|
|
1456
|
-
let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
1457
|
-
while (originalChunk) {
|
|
1458
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
1459
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
1460
|
-
const nextOriginalChunk = originalChunk.next;
|
|
1461
|
-
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
1462
|
-
if (nextClonedChunk) {
|
|
1463
|
-
clonedChunk.next = nextClonedChunk;
|
|
1464
|
-
nextClonedChunk.previous = clonedChunk;
|
|
1465
|
-
clonedChunk = nextClonedChunk;
|
|
1466
|
-
}
|
|
1467
|
-
originalChunk = nextOriginalChunk;
|
|
1468
|
-
}
|
|
1469
|
-
cloned.lastChunk = clonedChunk;
|
|
1470
|
-
if (this.indentExclusionRanges) cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
1471
|
-
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
1472
|
-
cloned.intro = this.intro;
|
|
1473
|
-
cloned.outro = this.outro;
|
|
1474
|
-
return cloned;
|
|
1475
|
-
}
|
|
1476
|
-
generateDecodedMap(options) {
|
|
1477
|
-
options = options || {};
|
|
1478
|
-
const sourceIndex = 0;
|
|
1479
|
-
const names = Object.keys(this.storedNames);
|
|
1480
|
-
const mappings = new Mappings(options.hires);
|
|
1481
|
-
const locate = getLocator(this.original);
|
|
1482
|
-
if (this.intro) mappings.advance(this.intro);
|
|
1483
|
-
this.firstChunk.eachNext((chunk) => {
|
|
1484
|
-
const loc = locate(chunk.start);
|
|
1485
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
1486
|
-
if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
|
|
1487
|
-
else mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
1488
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1489
|
-
});
|
|
1490
|
-
if (this.outro) mappings.advance(this.outro);
|
|
1491
|
-
return {
|
|
1492
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
1493
|
-
sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
|
|
1494
|
-
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
1495
|
-
names,
|
|
1496
|
-
mappings: mappings.raw,
|
|
1497
|
-
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
1498
|
-
};
|
|
1499
|
-
}
|
|
1500
|
-
generateMap(options) {
|
|
1501
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
1502
|
-
}
|
|
1503
|
-
_ensureindentStr() {
|
|
1504
|
-
if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
|
|
1505
|
-
}
|
|
1506
|
-
_getRawIndentString() {
|
|
1507
|
-
this._ensureindentStr();
|
|
1508
|
-
return this.indentStr;
|
|
1509
|
-
}
|
|
1510
|
-
getIndentString() {
|
|
1511
|
-
this._ensureindentStr();
|
|
1512
|
-
return this.indentStr === null ? " " : this.indentStr;
|
|
1513
|
-
}
|
|
1514
|
-
indent(indentStr, options) {
|
|
1515
|
-
const pattern = /^[^\r\n]/gm;
|
|
1516
|
-
if (isObject(indentStr)) {
|
|
1517
|
-
options = indentStr;
|
|
1518
|
-
indentStr = void 0;
|
|
1519
|
-
}
|
|
1520
|
-
if (indentStr === void 0) {
|
|
1521
|
-
this._ensureindentStr();
|
|
1522
|
-
indentStr = this.indentStr || " ";
|
|
1523
|
-
}
|
|
1524
|
-
if (indentStr === "") return this;
|
|
1525
|
-
options = options || {};
|
|
1526
|
-
const isExcluded = {};
|
|
1527
|
-
if (options.exclude) (typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
|
|
1528
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
|
|
1529
|
-
});
|
|
1530
|
-
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
1531
|
-
const replacer = (match) => {
|
|
1532
|
-
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
1533
|
-
shouldIndentNextCharacter = true;
|
|
1534
|
-
return match;
|
|
1535
|
-
};
|
|
1536
|
-
this.intro = this.intro.replace(pattern, replacer);
|
|
1537
|
-
let charIndex = 0;
|
|
1538
|
-
let chunk = this.firstChunk;
|
|
1539
|
-
while (chunk) {
|
|
1540
|
-
const end = chunk.end;
|
|
1541
|
-
if (chunk.edited) {
|
|
1542
|
-
if (!isExcluded[charIndex]) {
|
|
1543
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
1544
|
-
if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
1545
|
-
}
|
|
1546
|
-
} else {
|
|
1547
|
-
charIndex = chunk.start;
|
|
1548
|
-
while (charIndex < end) {
|
|
1549
|
-
if (!isExcluded[charIndex]) {
|
|
1550
|
-
const char = this.original[charIndex];
|
|
1551
|
-
if (char === "\n") shouldIndentNextCharacter = true;
|
|
1552
|
-
else if (char !== "\r" && shouldIndentNextCharacter) {
|
|
1553
|
-
shouldIndentNextCharacter = false;
|
|
1554
|
-
if (charIndex === chunk.start) chunk.prependRight(indentStr);
|
|
1555
|
-
else {
|
|
1556
|
-
this._splitChunk(chunk, charIndex);
|
|
1557
|
-
chunk = chunk.next;
|
|
1558
|
-
chunk.prependRight(indentStr);
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
charIndex += 1;
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
charIndex = chunk.end;
|
|
1566
|
-
chunk = chunk.next;
|
|
1567
|
-
}
|
|
1568
|
-
this.outro = this.outro.replace(pattern, replacer);
|
|
1569
|
-
return this;
|
|
1570
|
-
}
|
|
1571
|
-
insert() {
|
|
1572
|
-
throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
|
|
1573
|
-
}
|
|
1574
|
-
insertLeft(index, content) {
|
|
1575
|
-
if (!warned.insertLeft) {
|
|
1576
|
-
console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead");
|
|
1577
|
-
warned.insertLeft = true;
|
|
1578
|
-
}
|
|
1579
|
-
return this.appendLeft(index, content);
|
|
1580
|
-
}
|
|
1581
|
-
insertRight(index, content) {
|
|
1582
|
-
if (!warned.insertRight) {
|
|
1583
|
-
console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead");
|
|
1584
|
-
warned.insertRight = true;
|
|
1585
|
-
}
|
|
1586
|
-
return this.prependRight(index, content);
|
|
1587
|
-
}
|
|
1588
|
-
move(start, end, index) {
|
|
1589
|
-
start = start + this.offset;
|
|
1590
|
-
end = end + this.offset;
|
|
1591
|
-
index = index + this.offset;
|
|
1592
|
-
if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
1593
|
-
this._split(start);
|
|
1594
|
-
this._split(end);
|
|
1595
|
-
this._split(index);
|
|
1596
|
-
const first = this.byStart[start];
|
|
1597
|
-
const last = this.byEnd[end];
|
|
1598
|
-
const oldLeft = first.previous;
|
|
1599
|
-
const oldRight = last.next;
|
|
1600
|
-
const newRight = this.byStart[index];
|
|
1601
|
-
if (!newRight && last === this.lastChunk) return this;
|
|
1602
|
-
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
1603
|
-
if (oldLeft) oldLeft.next = oldRight;
|
|
1604
|
-
if (oldRight) oldRight.previous = oldLeft;
|
|
1605
|
-
if (newLeft) newLeft.next = first;
|
|
1606
|
-
if (newRight) newRight.previous = last;
|
|
1607
|
-
if (!first.previous) this.firstChunk = last.next;
|
|
1608
|
-
if (!last.next) {
|
|
1609
|
-
this.lastChunk = first.previous;
|
|
1610
|
-
this.lastChunk.next = null;
|
|
1611
|
-
}
|
|
1612
|
-
first.previous = newLeft;
|
|
1613
|
-
last.next = newRight || null;
|
|
1614
|
-
if (!newLeft) this.firstChunk = first;
|
|
1615
|
-
if (!newRight) this.lastChunk = last;
|
|
1616
|
-
return this;
|
|
1617
|
-
}
|
|
1618
|
-
overwrite(start, end, content, options) {
|
|
1619
|
-
options = options || {};
|
|
1620
|
-
return this.update(start, end, content, {
|
|
1621
|
-
...options,
|
|
1622
|
-
overwrite: !options.contentOnly
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
update(start, end, content, options) {
|
|
1626
|
-
start = start + this.offset;
|
|
1627
|
-
end = end + this.offset;
|
|
1628
|
-
if (typeof content !== "string") throw new TypeError("replacement content must be a string");
|
|
1629
|
-
if (this.original.length !== 0) {
|
|
1630
|
-
while (start < 0) start += this.original.length;
|
|
1631
|
-
while (end < 0) end += this.original.length;
|
|
1632
|
-
}
|
|
1633
|
-
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
1634
|
-
if (start === end) throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");
|
|
1635
|
-
this._split(start);
|
|
1636
|
-
this._split(end);
|
|
1637
|
-
if (options === true) {
|
|
1638
|
-
if (!warned.storeName) {
|
|
1639
|
-
console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string");
|
|
1640
|
-
warned.storeName = true;
|
|
1641
|
-
}
|
|
1642
|
-
options = { storeName: true };
|
|
1643
|
-
}
|
|
1644
|
-
const storeName = options !== void 0 ? options.storeName : false;
|
|
1645
|
-
const overwrite = options !== void 0 ? options.overwrite : false;
|
|
1646
|
-
if (storeName) {
|
|
1647
|
-
const original = this.original.slice(start, end);
|
|
1648
|
-
Object.defineProperty(this.storedNames, original, {
|
|
1649
|
-
writable: true,
|
|
1650
|
-
value: true,
|
|
1651
|
-
enumerable: true
|
|
1652
|
-
});
|
|
1653
|
-
}
|
|
1654
|
-
const first = this.byStart[start];
|
|
1655
|
-
const last = this.byEnd[end];
|
|
1656
|
-
if (first) {
|
|
1657
|
-
let chunk = first;
|
|
1658
|
-
while (chunk !== last) {
|
|
1659
|
-
if (chunk.next !== this.byStart[chunk.end]) throw new Error("Cannot overwrite across a split point");
|
|
1660
|
-
chunk = chunk.next;
|
|
1661
|
-
chunk.edit("", false);
|
|
1662
|
-
}
|
|
1663
|
-
first.edit(content, storeName, !overwrite);
|
|
1664
|
-
} else {
|
|
1665
|
-
const newChunk = new Chunk(start, end, "").edit(content, storeName);
|
|
1666
|
-
last.next = newChunk;
|
|
1667
|
-
newChunk.previous = last;
|
|
1668
|
-
}
|
|
1669
|
-
return this;
|
|
1670
|
-
}
|
|
1671
|
-
prepend(content) {
|
|
1672
|
-
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
1673
|
-
this.intro = content + this.intro;
|
|
1674
|
-
return this;
|
|
1675
|
-
}
|
|
1676
|
-
prependLeft(index, content) {
|
|
1677
|
-
index = index + this.offset;
|
|
1678
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
1679
|
-
this._split(index);
|
|
1680
|
-
const chunk = this.byEnd[index];
|
|
1681
|
-
if (chunk) chunk.prependLeft(content);
|
|
1682
|
-
else this.intro = content + this.intro;
|
|
1683
|
-
return this;
|
|
1684
|
-
}
|
|
1685
|
-
prependRight(index, content) {
|
|
1686
|
-
index = index + this.offset;
|
|
1687
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
1688
|
-
this._split(index);
|
|
1689
|
-
const chunk = this.byStart[index];
|
|
1690
|
-
if (chunk) chunk.prependRight(content);
|
|
1691
|
-
else this.outro = content + this.outro;
|
|
1692
|
-
return this;
|
|
1693
|
-
}
|
|
1694
|
-
remove(start, end) {
|
|
1695
|
-
start = start + this.offset;
|
|
1696
|
-
end = end + this.offset;
|
|
1697
|
-
if (this.original.length !== 0) {
|
|
1698
|
-
while (start < 0) start += this.original.length;
|
|
1699
|
-
while (end < 0) end += this.original.length;
|
|
1700
|
-
}
|
|
1701
|
-
if (start === end) return this;
|
|
1702
|
-
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
1703
|
-
if (start > end) throw new Error("end must be greater than start");
|
|
1704
|
-
this._split(start);
|
|
1705
|
-
this._split(end);
|
|
1706
|
-
let chunk = this.byStart[start];
|
|
1707
|
-
while (chunk) {
|
|
1708
|
-
chunk.intro = "";
|
|
1709
|
-
chunk.outro = "";
|
|
1710
|
-
chunk.edit("");
|
|
1711
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
1712
|
-
}
|
|
1713
|
-
return this;
|
|
1714
|
-
}
|
|
1715
|
-
reset(start, end) {
|
|
1716
|
-
start = start + this.offset;
|
|
1717
|
-
end = end + this.offset;
|
|
1718
|
-
if (this.original.length !== 0) {
|
|
1719
|
-
while (start < 0) start += this.original.length;
|
|
1720
|
-
while (end < 0) end += this.original.length;
|
|
1721
|
-
}
|
|
1722
|
-
if (start === end) return this;
|
|
1723
|
-
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
1724
|
-
if (start > end) throw new Error("end must be greater than start");
|
|
1725
|
-
this._split(start);
|
|
1726
|
-
this._split(end);
|
|
1727
|
-
let chunk = this.byStart[start];
|
|
1728
|
-
while (chunk) {
|
|
1729
|
-
chunk.reset();
|
|
1730
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
1731
|
-
}
|
|
1732
|
-
return this;
|
|
1733
|
-
}
|
|
1734
|
-
lastChar() {
|
|
1735
|
-
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
1736
|
-
let chunk = this.lastChunk;
|
|
1737
|
-
do {
|
|
1738
|
-
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
1739
|
-
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
1740
|
-
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
1741
|
-
} while (chunk = chunk.previous);
|
|
1742
|
-
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
1743
|
-
return "";
|
|
1744
|
-
}
|
|
1745
|
-
lastLine() {
|
|
1746
|
-
let lineIndex = this.outro.lastIndexOf(n);
|
|
1747
|
-
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
1748
|
-
let lineStr = this.outro;
|
|
1749
|
-
let chunk = this.lastChunk;
|
|
1750
|
-
do {
|
|
1751
|
-
if (chunk.outro.length > 0) {
|
|
1752
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
1753
|
-
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
1754
|
-
lineStr = chunk.outro + lineStr;
|
|
1755
|
-
}
|
|
1756
|
-
if (chunk.content.length > 0) {
|
|
1757
|
-
lineIndex = chunk.content.lastIndexOf(n);
|
|
1758
|
-
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
1759
|
-
lineStr = chunk.content + lineStr;
|
|
1760
|
-
}
|
|
1761
|
-
if (chunk.intro.length > 0) {
|
|
1762
|
-
lineIndex = chunk.intro.lastIndexOf(n);
|
|
1763
|
-
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
1764
|
-
lineStr = chunk.intro + lineStr;
|
|
1765
|
-
}
|
|
1766
|
-
} while (chunk = chunk.previous);
|
|
1767
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
1768
|
-
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
1769
|
-
return this.intro + lineStr;
|
|
1770
|
-
}
|
|
1771
|
-
slice(start = 0, end = this.original.length - this.offset) {
|
|
1772
|
-
start = start + this.offset;
|
|
1773
|
-
end = end + this.offset;
|
|
1774
|
-
if (this.original.length !== 0) {
|
|
1775
|
-
while (start < 0) start += this.original.length;
|
|
1776
|
-
while (end < 0) end += this.original.length;
|
|
1777
|
-
}
|
|
1778
|
-
let result = "";
|
|
1779
|
-
let chunk = this.firstChunk;
|
|
1780
|
-
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
1781
|
-
if (chunk.start < end && chunk.end >= end) return result;
|
|
1782
|
-
chunk = chunk.next;
|
|
1783
|
-
}
|
|
1784
|
-
if (chunk && chunk.edited && chunk.start !== start) throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
1785
|
-
const startChunk = chunk;
|
|
1786
|
-
while (chunk) {
|
|
1787
|
-
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) result += chunk.intro;
|
|
1788
|
-
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
1789
|
-
if (containsEnd && chunk.edited && chunk.end !== end) throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
1790
|
-
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
1791
|
-
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
1792
|
-
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1793
|
-
if (chunk.outro && (!containsEnd || chunk.end === end)) result += chunk.outro;
|
|
1794
|
-
if (containsEnd) break;
|
|
1795
|
-
chunk = chunk.next;
|
|
1796
|
-
}
|
|
1797
|
-
return result;
|
|
1798
|
-
}
|
|
1799
|
-
snip(start, end) {
|
|
1800
|
-
const clone = this.clone();
|
|
1801
|
-
clone.remove(0, start);
|
|
1802
|
-
clone.remove(end, clone.original.length);
|
|
1803
|
-
return clone;
|
|
1804
|
-
}
|
|
1805
|
-
_split(index) {
|
|
1806
|
-
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1807
|
-
let chunk = this.lastSearchedChunk;
|
|
1808
|
-
let previousChunk = chunk;
|
|
1809
|
-
const searchForward = index > chunk.end;
|
|
1810
|
-
while (chunk) {
|
|
1811
|
-
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1812
|
-
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
1813
|
-
if (chunk === previousChunk) return;
|
|
1814
|
-
previousChunk = chunk;
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
_splitChunk(chunk, index) {
|
|
1818
|
-
if (chunk.edited && chunk.content.length) {
|
|
1819
|
-
const loc = getLocator(this.original)(index);
|
|
1820
|
-
throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`);
|
|
1821
|
-
}
|
|
1822
|
-
const newChunk = chunk.split(index);
|
|
1823
|
-
this.byEnd[index] = chunk;
|
|
1824
|
-
this.byStart[index] = newChunk;
|
|
1825
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
1826
|
-
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1827
|
-
this.lastSearchedChunk = chunk;
|
|
1828
|
-
return true;
|
|
1829
|
-
}
|
|
1830
|
-
toString() {
|
|
1831
|
-
let str = this.intro;
|
|
1832
|
-
let chunk = this.firstChunk;
|
|
1833
|
-
while (chunk) {
|
|
1834
|
-
str += chunk.toString();
|
|
1835
|
-
chunk = chunk.next;
|
|
1836
|
-
}
|
|
1837
|
-
return str + this.outro;
|
|
1838
|
-
}
|
|
1839
|
-
isEmpty() {
|
|
1840
|
-
let chunk = this.firstChunk;
|
|
1841
|
-
do
|
|
1842
|
-
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
|
|
1843
|
-
while (chunk = chunk.next);
|
|
1844
|
-
return true;
|
|
1845
|
-
}
|
|
1846
|
-
length() {
|
|
1847
|
-
let chunk = this.firstChunk;
|
|
1848
|
-
let length = 0;
|
|
1849
|
-
do
|
|
1850
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
1851
|
-
while (chunk = chunk.next);
|
|
1852
|
-
return length;
|
|
1853
|
-
}
|
|
1854
|
-
trimLines() {
|
|
1855
|
-
return this.trim("[\\r\\n]");
|
|
1856
|
-
}
|
|
1857
|
-
trim(charType) {
|
|
1858
|
-
return this.trimStart(charType).trimEnd(charType);
|
|
1859
|
-
}
|
|
1860
|
-
trimEndAborted(charType) {
|
|
1861
|
-
const rx = new RegExp((charType || "\\s") + "+$");
|
|
1862
|
-
this.outro = this.outro.replace(rx, "");
|
|
1863
|
-
if (this.outro.length) return true;
|
|
1864
|
-
let chunk = this.lastChunk;
|
|
1865
|
-
do {
|
|
1866
|
-
const end = chunk.end;
|
|
1867
|
-
const aborted = chunk.trimEnd(rx);
|
|
1868
|
-
if (chunk.end !== end) {
|
|
1869
|
-
if (this.lastChunk === chunk) this.lastChunk = chunk.next;
|
|
1870
|
-
this.byEnd[chunk.end] = chunk;
|
|
1871
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1872
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1873
|
-
}
|
|
1874
|
-
if (aborted) return true;
|
|
1875
|
-
chunk = chunk.previous;
|
|
1876
|
-
} while (chunk);
|
|
1877
|
-
return false;
|
|
1878
|
-
}
|
|
1879
|
-
trimEnd(charType) {
|
|
1880
|
-
this.trimEndAborted(charType);
|
|
1881
|
-
return this;
|
|
1882
|
-
}
|
|
1883
|
-
trimStartAborted(charType) {
|
|
1884
|
-
const rx = new RegExp("^" + (charType || "\\s") + "+");
|
|
1885
|
-
this.intro = this.intro.replace(rx, "");
|
|
1886
|
-
if (this.intro.length) return true;
|
|
1887
|
-
let chunk = this.firstChunk;
|
|
1888
|
-
do {
|
|
1889
|
-
const end = chunk.end;
|
|
1890
|
-
const aborted = chunk.trimStart(rx);
|
|
1891
|
-
if (chunk.end !== end) {
|
|
1892
|
-
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
1893
|
-
this.byEnd[chunk.end] = chunk;
|
|
1894
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1895
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1896
|
-
}
|
|
1897
|
-
if (aborted) return true;
|
|
1898
|
-
chunk = chunk.next;
|
|
1899
|
-
} while (chunk);
|
|
1900
|
-
return false;
|
|
1901
|
-
}
|
|
1902
|
-
trimStart(charType) {
|
|
1903
|
-
this.trimStartAborted(charType);
|
|
1904
|
-
return this;
|
|
1905
|
-
}
|
|
1906
|
-
hasChanged() {
|
|
1907
|
-
return this.original !== this.toString();
|
|
1908
|
-
}
|
|
1909
|
-
_replaceRegexp(searchValue, replacement) {
|
|
1910
|
-
function getReplacement(match, str) {
|
|
1911
|
-
if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
1912
|
-
if (i === "$") return "$";
|
|
1913
|
-
if (i === "&") return match[0];
|
|
1914
|
-
if (+i < match.length) return match[+i];
|
|
1915
|
-
return `$${i}`;
|
|
1916
|
-
});
|
|
1917
|
-
else return replacement(...match, match.index, str, match.groups);
|
|
1918
|
-
}
|
|
1919
|
-
function matchAll(re, str) {
|
|
1920
|
-
let match;
|
|
1921
|
-
const matches = [];
|
|
1922
|
-
while (match = re.exec(str)) matches.push(match);
|
|
1923
|
-
return matches;
|
|
1924
|
-
}
|
|
1925
|
-
if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
|
|
1926
|
-
if (match.index != null) {
|
|
1927
|
-
const replacement = getReplacement(match, this.original);
|
|
1928
|
-
if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1929
|
-
}
|
|
1930
|
-
});
|
|
1931
|
-
else {
|
|
1932
|
-
const match = this.original.match(searchValue);
|
|
1933
|
-
if (match && match.index != null) {
|
|
1934
|
-
const replacement = getReplacement(match, this.original);
|
|
1935
|
-
if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
return this;
|
|
1939
|
-
}
|
|
1940
|
-
_replaceString(string, replacement) {
|
|
1941
|
-
const { original } = this;
|
|
1942
|
-
const index = original.indexOf(string);
|
|
1943
|
-
if (index !== -1) {
|
|
1944
|
-
if (typeof replacement === "function") replacement = replacement(string, index, original);
|
|
1945
|
-
if (string !== replacement) this.overwrite(index, index + string.length, replacement);
|
|
1946
|
-
}
|
|
1947
|
-
return this;
|
|
1948
|
-
}
|
|
1949
|
-
replace(searchValue, replacement) {
|
|
1950
|
-
if (typeof searchValue === "string") return this._replaceString(searchValue, replacement);
|
|
1951
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1952
|
-
}
|
|
1953
|
-
_replaceAllString(string, replacement) {
|
|
1954
|
-
const { original } = this;
|
|
1955
|
-
const stringLength = string.length;
|
|
1956
|
-
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
1957
|
-
const previous = original.slice(index, index + stringLength);
|
|
1958
|
-
let _replacement = replacement;
|
|
1959
|
-
if (typeof replacement === "function") _replacement = replacement(previous, index, original);
|
|
1960
|
-
if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
|
|
1961
|
-
}
|
|
1962
|
-
return this;
|
|
1963
|
-
}
|
|
1964
|
-
replaceAll(searchValue, replacement) {
|
|
1965
|
-
if (typeof searchValue === "string") return this._replaceAllString(searchValue, replacement);
|
|
1966
|
-
if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
|
|
1967
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1968
|
-
}
|
|
1969
|
-
};
|
|
1970
|
-
|
|
1971
472
|
//#endregion
|
|
1972
473
|
//#region src/plugins/cjs-external-interop.ts
|
|
1973
474
|
const STATIC_IMPORT_RE = /(?<=\s|^|;)import\s*([\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu;
|
|
@@ -2057,7 +558,6 @@ function parseImportClause(clause) {
|
|
|
2057
558
|
named
|
|
2058
559
|
};
|
|
2059
560
|
}
|
|
2060
|
-
|
|
2061
561
|
//#endregion
|
|
2062
562
|
//#region src/plugins/esm-shim.ts
|
|
2063
563
|
const CJSYNTAX_RE = /__filename|__dirname|require\(|require\.resolve\(/;
|
|
@@ -2099,7 +599,6 @@ function esmShimPlugin() {
|
|
|
2099
599
|
}
|
|
2100
600
|
};
|
|
2101
601
|
}
|
|
2102
|
-
|
|
2103
602
|
//#endregion
|
|
2104
603
|
//#region src/plugins/import-meta.ts
|
|
2105
604
|
/**
|
|
@@ -2119,7 +618,6 @@ function importMetaPlugin() {
|
|
|
2119
618
|
}
|
|
2120
619
|
};
|
|
2121
620
|
}
|
|
2122
|
-
|
|
2123
621
|
//#endregion
|
|
2124
622
|
//#region src/dev/vite-node-config.ts
|
|
2125
623
|
function resolveSourcemap$1(mode) {
|
|
@@ -2192,7 +690,6 @@ function createNodeConfig(opts) {
|
|
|
2192
690
|
}
|
|
2193
691
|
return config;
|
|
2194
692
|
}
|
|
2195
|
-
|
|
2196
693
|
//#endregion
|
|
2197
694
|
//#region src/dev/vite-renderer-config.ts
|
|
2198
695
|
function resolveSourcemap(mode) {
|
|
@@ -2210,7 +707,10 @@ function createRendererConfig(opts) {
|
|
|
2210
707
|
root: opts.root,
|
|
2211
708
|
customLogger: opts.customLogger,
|
|
2212
709
|
envPrefix: ["RENDERER_VITE_", "VITE_"],
|
|
2213
|
-
...!isBuild && { server: {
|
|
710
|
+
...!isBuild && { server: {
|
|
711
|
+
host: "127.0.0.1",
|
|
712
|
+
strictPort: false
|
|
713
|
+
} },
|
|
2214
714
|
...isBuild && { base: "./" },
|
|
2215
715
|
build: {
|
|
2216
716
|
rolldownOptions: { input },
|
|
@@ -2255,7 +755,6 @@ function deduplicatePlugins(plugins) {
|
|
|
2255
755
|
}
|
|
2256
756
|
return result;
|
|
2257
757
|
}
|
|
2258
|
-
|
|
2259
758
|
//#endregion
|
|
2260
759
|
//#region src/plugins/utils.ts
|
|
2261
760
|
/** Strip query and hash from a URL/path. */
|
|
@@ -2267,7 +766,6 @@ function toRelativePath(from, to) {
|
|
|
2267
766
|
const rel = relative(dirname(from), to);
|
|
2268
767
|
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
2269
768
|
}
|
|
2270
|
-
|
|
2271
769
|
//#endregion
|
|
2272
770
|
//#region src/plugins/asset.ts
|
|
2273
771
|
const ASSET_QUERY_RE = /[?&]asset(?:&|$)/;
|
|
@@ -2315,7 +813,6 @@ function assetPlugin() {
|
|
|
2315
813
|
}
|
|
2316
814
|
};
|
|
2317
815
|
}
|
|
2318
|
-
|
|
2319
816
|
//#endregion
|
|
2320
817
|
//#region src/dev/electron-launcher.ts
|
|
2321
818
|
async function fileExists(path) {
|
|
@@ -2396,7 +893,6 @@ async function launchElectron(opts) {
|
|
|
2396
893
|
})
|
|
2397
894
|
};
|
|
2398
895
|
}
|
|
2399
|
-
|
|
2400
896
|
//#endregion
|
|
2401
897
|
//#region src/plugins/bytecode.ts
|
|
2402
898
|
const BYTECODE_LOADER_FILE = "bytecode-loader.cjs";
|
|
@@ -2660,73 +1156,6 @@ async function cleanup(filePath) {
|
|
|
2660
1156
|
await Bun.file(filePath).delete();
|
|
2661
1157
|
} catch {}
|
|
2662
1158
|
}
|
|
2663
|
-
|
|
2664
|
-
//#endregion
|
|
2665
|
-
//#region src/plugins/isolate-entries.ts
|
|
2666
|
-
const VIRTUAL_ENTRY_ID = "\0electro:isolate-entries";
|
|
2667
|
-
/**
|
|
2668
|
-
* Isolates multiple entry points into separate sub-builds.
|
|
2669
|
-
* Dormant (no-op) if only one entry detected.
|
|
2670
|
-
*/
|
|
2671
|
-
function isolateEntriesPlugin(subBuildConfig) {
|
|
2672
|
-
const emitted = /* @__PURE__ */ new Set();
|
|
2673
|
-
let entries = null;
|
|
2674
|
-
return {
|
|
2675
|
-
name: "electro:isolate-entries",
|
|
2676
|
-
apply: "build",
|
|
2677
|
-
options(opts) {
|
|
2678
|
-
const { input } = opts;
|
|
2679
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) return;
|
|
2680
|
-
if (Object.keys(input).length <= 1) return;
|
|
2681
|
-
entries = Object.entries(input).map(([k, v]) => ({ [k]: v }));
|
|
2682
|
-
opts.input = VIRTUAL_ENTRY_ID;
|
|
2683
|
-
},
|
|
2684
|
-
resolveId(id) {
|
|
2685
|
-
if (id === VIRTUAL_ENTRY_ID) return id;
|
|
2686
|
-
return null;
|
|
2687
|
-
},
|
|
2688
|
-
async load(id) {
|
|
2689
|
-
if (id !== VIRTUAL_ENTRY_ID || !entries) return;
|
|
2690
|
-
for (const entry of entries) {
|
|
2691
|
-
const config = mergeConfig(subBuildConfig, {
|
|
2692
|
-
build: {
|
|
2693
|
-
write: false,
|
|
2694
|
-
watch: null
|
|
2695
|
-
},
|
|
2696
|
-
plugins: [{
|
|
2697
|
-
name: "electro:entry-file-name",
|
|
2698
|
-
outputOptions(output) {
|
|
2699
|
-
if (output.entryFileNames && typeof output.entryFileNames === "string") output.entryFileNames = `[name]${extname(output.entryFileNames)}`;
|
|
2700
|
-
}
|
|
2701
|
-
}],
|
|
2702
|
-
logLevel: "warn",
|
|
2703
|
-
configFile: false
|
|
2704
|
-
});
|
|
2705
|
-
if (config.build) config.build.rolldownOptions = {
|
|
2706
|
-
...config.build.rolldownOptions,
|
|
2707
|
-
input: entry
|
|
2708
|
-
};
|
|
2709
|
-
const result = await build(config);
|
|
2710
|
-
for (const chunk of result.output) {
|
|
2711
|
-
if (emitted.has(chunk.fileName)) continue;
|
|
2712
|
-
const source = chunk.type === "chunk" ? chunk.code : chunk.source;
|
|
2713
|
-
if (source == null) continue;
|
|
2714
|
-
this.emitFile({
|
|
2715
|
-
type: "asset",
|
|
2716
|
-
fileName: chunk.fileName,
|
|
2717
|
-
source
|
|
2718
|
-
});
|
|
2719
|
-
emitted.add(chunk.fileName);
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
return "// virtual entry — removed in generateBundle";
|
|
2723
|
-
},
|
|
2724
|
-
generateBundle(_, bundle) {
|
|
2725
|
-
for (const name in bundle) if (name.includes("isolate-entries")) delete bundle[name];
|
|
2726
|
-
}
|
|
2727
|
-
};
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
1159
|
//#endregion
|
|
2731
1160
|
//#region src/plugins/module-path.ts
|
|
2732
1161
|
const MODULE_PATH_RE = /__ELECTRO_MODULE_PATH__([\w$]+)__/g;
|
|
@@ -2869,7 +1298,6 @@ async function bundleModulePath(input, config, watch) {
|
|
|
2869
1298
|
watchFiles
|
|
2870
1299
|
};
|
|
2871
1300
|
}
|
|
2872
|
-
|
|
2873
1301
|
//#endregion
|
|
2874
1302
|
//#region src/plugins/worker.ts
|
|
2875
1303
|
const WORKER_PLACEHOLDER_RE = /__ELECTRO_WORKER__([\w$]+)__/g;
|
|
@@ -2928,7 +1356,6 @@ function workerPlugin() {
|
|
|
2928
1356
|
}
|
|
2929
1357
|
};
|
|
2930
1358
|
}
|
|
2931
|
-
|
|
2932
1359
|
//#endregion
|
|
2933
1360
|
//#region src/commands/build.ts
|
|
2934
1361
|
async function build$1(options) {
|
|
@@ -3091,42 +1518,21 @@ async function buildMain(args) {
|
|
|
3091
1518
|
}
|
|
3092
1519
|
async function buildPreload(args) {
|
|
3093
1520
|
const views = (args.config.views ?? []).filter((v) => v.entry);
|
|
3094
|
-
const input = {};
|
|
3095
|
-
for (const view of views) input[view.name] = resolve(args.codegenDir, `generated/preload/${view.name}.gen.ts`);
|
|
3096
|
-
const firstEntry = Object.values(input)[0];
|
|
3097
1521
|
const preloadOutDir = resolve(args.outDir, "preload");
|
|
3098
|
-
const
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
modulePathPlugin(),
|
|
3102
|
-
...args.bytecode ? [bytecodePlugin()] : []
|
|
3103
|
-
];
|
|
3104
|
-
const baseConfig = createNodeConfig({
|
|
3105
|
-
scope: "preload",
|
|
3106
|
-
root: args.root,
|
|
3107
|
-
entry: firstEntry,
|
|
3108
|
-
externals: args.externals,
|
|
3109
|
-
outDir: preloadOutDir,
|
|
3110
|
-
watch: false,
|
|
3111
|
-
plugins: preloadPlugins,
|
|
3112
|
-
sourcemap: args.sourcemap,
|
|
3113
|
-
customLogger: args.logger,
|
|
3114
|
-
logLevel: "info",
|
|
3115
|
-
format: "cjs",
|
|
3116
|
-
cjsInteropDeps: args.cjsInteropDeps
|
|
3117
|
-
});
|
|
3118
|
-
if (Object.keys(input).length > 1) {
|
|
3119
|
-
const subBuildConfig = createNodeConfig({
|
|
1522
|
+
for (const [index, view] of views.entries()) {
|
|
1523
|
+
const entry = resolve(args.codegenDir, `generated/preload/${view.name}.gen.ts`);
|
|
1524
|
+
const config = createNodeConfig({
|
|
3120
1525
|
scope: "preload",
|
|
3121
1526
|
root: args.root,
|
|
3122
|
-
entry
|
|
1527
|
+
entry,
|
|
3123
1528
|
externals: args.externals,
|
|
3124
1529
|
outDir: preloadOutDir,
|
|
3125
1530
|
watch: false,
|
|
3126
1531
|
plugins: [
|
|
3127
1532
|
assetPlugin(),
|
|
3128
1533
|
workerPlugin(),
|
|
3129
|
-
modulePathPlugin()
|
|
1534
|
+
modulePathPlugin(),
|
|
1535
|
+
...args.bytecode ? [bytecodePlugin()] : []
|
|
3130
1536
|
],
|
|
3131
1537
|
sourcemap: args.sourcemap,
|
|
3132
1538
|
customLogger: args.logger,
|
|
@@ -3134,13 +1540,22 @@ async function buildPreload(args) {
|
|
|
3134
1540
|
format: "cjs",
|
|
3135
1541
|
cjsInteropDeps: args.cjsInteropDeps
|
|
3136
1542
|
});
|
|
3137
|
-
|
|
1543
|
+
if (config.build) {
|
|
1544
|
+
const existingOutput = config.build.rolldownOptions?.output;
|
|
1545
|
+
config.build.emptyOutDir = index === 0;
|
|
1546
|
+
config.build.rolldownOptions = {
|
|
1547
|
+
...config.build.rolldownOptions,
|
|
1548
|
+
output: Array.isArray(existingOutput) ? existingOutput.map((output) => ({
|
|
1549
|
+
...output,
|
|
1550
|
+
entryFileNames: `${view.name}.cjs`
|
|
1551
|
+
})) : {
|
|
1552
|
+
...existingOutput ?? {},
|
|
1553
|
+
entryFileNames: `${view.name}.cjs`
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
await build(config);
|
|
3138
1558
|
}
|
|
3139
|
-
if (baseConfig.build) baseConfig.build.rolldownOptions = {
|
|
3140
|
-
...baseConfig.build.rolldownOptions,
|
|
3141
|
-
input
|
|
3142
|
-
};
|
|
3143
|
-
await build(baseConfig);
|
|
3144
1559
|
}
|
|
3145
1560
|
function sanitizeRuntimeWebPreferences$1(webPreferences) {
|
|
3146
1561
|
const prefs = { ...webPreferences ?? {} };
|
|
@@ -3177,13 +1592,13 @@ async function flattenRendererOutput(rendererDir, views, root) {
|
|
|
3177
1592
|
force: true
|
|
3178
1593
|
});
|
|
3179
1594
|
}
|
|
3180
|
-
|
|
3181
1595
|
//#endregion
|
|
3182
1596
|
//#region src/dev/dev-server.ts
|
|
3183
1597
|
const MAIN_RESTART_DEBOUNCE_MS = 80;
|
|
3184
1598
|
const CONFIG_DEBOUNCE_MS = 300;
|
|
3185
1599
|
const MAIN_ENTRY_WAIT_TIMEOUT_MS = 1e4;
|
|
3186
1600
|
const MAIN_ENTRY_WAIT_INTERVAL_MS = 50;
|
|
1601
|
+
const RENDERER_DEV_HOST = "127.0.0.1";
|
|
3187
1602
|
var DevServer = class {
|
|
3188
1603
|
rendererServer = null;
|
|
3189
1604
|
electronProcess = null;
|
|
@@ -3395,7 +1810,7 @@ var DevServer = class {
|
|
|
3395
1810
|
patchLogger(this.rendererServer.config.logger, "renderer");
|
|
3396
1811
|
await this.rendererServer.listen();
|
|
3397
1812
|
const addr = this.rendererServer.httpServer?.address();
|
|
3398
|
-
this.rendererUrl = `http
|
|
1813
|
+
this.rendererUrl = `http://${RENDERER_DEV_HOST}:${typeof addr === "object" && addr ? addr.port : 5173}`;
|
|
3399
1814
|
}
|
|
3400
1815
|
async buildPreload(externals, cjsInteropDeps) {
|
|
3401
1816
|
const views = (this.config.views ?? []).filter((v) => v.entry);
|
|
@@ -3406,35 +1821,22 @@ var DevServer = class {
|
|
|
3406
1821
|
this.resolvePreloadInitialBuild = null;
|
|
3407
1822
|
};
|
|
3408
1823
|
});
|
|
3409
|
-
const
|
|
3410
|
-
|
|
3411
|
-
const
|
|
3412
|
-
const
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
plugins: [
|
|
3420
|
-
assetPlugin(),
|
|
3421
|
-
workerPlugin(),
|
|
3422
|
-
modulePathPlugin()
|
|
3423
|
-
],
|
|
3424
|
-
logLevel: this.logLevel,
|
|
3425
|
-
clearScreen: this.clearScreen,
|
|
3426
|
-
sourcemap: this.sourcemap,
|
|
3427
|
-
format: "cjs",
|
|
3428
|
-
cjsInteropDeps
|
|
3429
|
-
});
|
|
3430
|
-
if (Object.keys(input).length > 1) {
|
|
3431
|
-
const subBuildConfig = createNodeConfig({
|
|
1824
|
+
const self = this;
|
|
1825
|
+
let pendingInitialBuilds = views.length;
|
|
1826
|
+
const watchers = [];
|
|
1827
|
+
const markInitialBuildComplete = () => {
|
|
1828
|
+
pendingInitialBuilds -= 1;
|
|
1829
|
+
if (pendingInitialBuilds === 0) self.resolvePreloadInitialBuild?.();
|
|
1830
|
+
};
|
|
1831
|
+
for (const [index, view] of views.entries()) {
|
|
1832
|
+
const entry = resolve(this.outputDir, `generated/preload/${view.name}.gen.ts`);
|
|
1833
|
+
const config = createNodeConfig({
|
|
3432
1834
|
scope: "preload",
|
|
3433
1835
|
root: this.root,
|
|
3434
|
-
entry
|
|
1836
|
+
entry,
|
|
3435
1837
|
externals,
|
|
3436
1838
|
outDir: preloadOutDir,
|
|
3437
|
-
watch:
|
|
1839
|
+
watch: true,
|
|
3438
1840
|
plugins: [
|
|
3439
1841
|
assetPlugin(),
|
|
3440
1842
|
workerPlugin(),
|
|
@@ -3446,30 +1848,42 @@ var DevServer = class {
|
|
|
3446
1848
|
format: "cjs",
|
|
3447
1849
|
cjsInteropDeps
|
|
3448
1850
|
});
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
},
|
|
3463
|
-
closeBundle() {
|
|
3464
|
-
if (firstBuild) {
|
|
3465
|
-
firstBuild = false;
|
|
3466
|
-
self.resolvePreloadInitialBuild?.();
|
|
3467
|
-
return;
|
|
3468
|
-
}
|
|
3469
|
-
if (self.rendererServer) self.rendererServer.ws.send({ type: "full-reload" });
|
|
1851
|
+
if (config.build) {
|
|
1852
|
+
const existingOutput = config.build.rolldownOptions?.output;
|
|
1853
|
+
config.build.emptyOutDir = index === 0;
|
|
1854
|
+
config.build.rolldownOptions = {
|
|
1855
|
+
...config.build.rolldownOptions,
|
|
1856
|
+
output: Array.isArray(existingOutput) ? existingOutput.map((output) => ({
|
|
1857
|
+
...output,
|
|
1858
|
+
entryFileNames: `${view.name}.cjs`
|
|
1859
|
+
})) : {
|
|
1860
|
+
...existingOutput ?? {},
|
|
1861
|
+
entryFileNames: `${view.name}.cjs`
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
3470
1864
|
}
|
|
3471
|
-
|
|
3472
|
-
|
|
1865
|
+
let firstBuild = true;
|
|
1866
|
+
config.plugins.push({
|
|
1867
|
+
name: `electro:preload-watch:${view.name}`,
|
|
1868
|
+
apply: "build",
|
|
1869
|
+
watchChange(id) {
|
|
1870
|
+
if (!firstBuild) runtimeLog("preload", "rebuild → page reload", relative(self.root, id));
|
|
1871
|
+
},
|
|
1872
|
+
closeBundle() {
|
|
1873
|
+
if (firstBuild) {
|
|
1874
|
+
firstBuild = false;
|
|
1875
|
+
markInitialBuildComplete();
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
if (self.rendererServer) self.rendererServer.ws.send({ type: "full-reload" });
|
|
1879
|
+
}
|
|
1880
|
+
});
|
|
1881
|
+
const watcher = await build(config);
|
|
1882
|
+
watchers.push(watcher);
|
|
1883
|
+
}
|
|
1884
|
+
this.preloadWatch = { close() {
|
|
1885
|
+
for (const watcher of watchers) watcher.close();
|
|
1886
|
+
} };
|
|
3473
1887
|
}
|
|
3474
1888
|
async buildMain(externals, cjsInteropDeps) {
|
|
3475
1889
|
const runtimeEntry = this.config.runtime.entry;
|
|
@@ -3567,12 +1981,12 @@ var DevServer = class {
|
|
|
3567
1981
|
if (this.rendererServer) {
|
|
3568
1982
|
const addr = this.rendererServer.httpServer?.address();
|
|
3569
1983
|
const port = typeof addr === "object" && addr ? addr.port : 5173;
|
|
3570
|
-
env.ELECTRO_RENDERER_BASE = `http
|
|
1984
|
+
env.ELECTRO_RENDERER_BASE = `http://${RENDERER_DEV_HOST}:${port}`;
|
|
3571
1985
|
for (const view of this.config.views ?? []) {
|
|
3572
1986
|
if (!view.entry) continue;
|
|
3573
1987
|
const entryPath = resolve(dirname(view.__source), view.entry);
|
|
3574
1988
|
const relPath = relative(this.root, entryPath);
|
|
3575
|
-
env[`ELECTRO_DEV_URL_${view.name}`] = `http
|
|
1989
|
+
env[`ELECTRO_DEV_URL_${view.name}`] = `http://${RENDERER_DEV_HOST}:${port}/${relPath}`;
|
|
3576
1990
|
}
|
|
3577
1991
|
}
|
|
3578
1992
|
const proc = await launchElectron({
|
|
@@ -3691,7 +2105,6 @@ function sanitizeRuntimeWebPreferences(webPreferences) {
|
|
|
3691
2105
|
delete prefs.preload;
|
|
3692
2106
|
return prefs;
|
|
3693
2107
|
}
|
|
3694
|
-
|
|
3695
2108
|
//#endregion
|
|
3696
2109
|
//#region src/commands/dev.ts
|
|
3697
2110
|
async function dev(options) {
|
|
@@ -3738,7 +2151,6 @@ async function dev(options) {
|
|
|
3738
2151
|
await startWithRestart();
|
|
3739
2152
|
await new Promise(() => {});
|
|
3740
2153
|
}
|
|
3741
|
-
|
|
3742
2154
|
//#endregion
|
|
3743
2155
|
//#region src/commands/generate.ts
|
|
3744
2156
|
async function generate$1(options) {
|
|
@@ -3796,7 +2208,6 @@ async function writeFileIfChanged(filePath, content) {
|
|
|
3796
2208
|
} catch {}
|
|
3797
2209
|
await writeFile(filePath, content);
|
|
3798
2210
|
}
|
|
3799
|
-
|
|
3800
2211
|
//#endregion
|
|
3801
2212
|
//#region src/commands/preview.ts
|
|
3802
2213
|
async function preview(options) {
|
|
@@ -3831,7 +2242,6 @@ async function preview(options) {
|
|
|
3831
2242
|
process.exit(1);
|
|
3832
2243
|
}
|
|
3833
2244
|
}
|
|
3834
|
-
|
|
3835
2245
|
//#endregion
|
|
3836
2246
|
//#region src/index.ts
|
|
3837
2247
|
const cli = cac("electro");
|
|
@@ -3842,6 +2252,5 @@ cli.command("dev", "Start development server with Electron").option("--config <p
|
|
|
3842
2252
|
cli.help();
|
|
3843
2253
|
cli.version(version$1);
|
|
3844
2254
|
cli.parse();
|
|
3845
|
-
|
|
3846
2255
|
//#endregion
|
|
3847
|
-
export {
|
|
2256
|
+
export {};
|