Ejdjdososs/fable-ai
0
1import path from 'node:path';2import fs__default from 'node:fs';3import { performance } from 'node:perf_hooks';4import { EventEmitter } from 'events';5import { B as colors, v as createLogger, r as resolveConfig } from './chunks/dep-BK3b2jBa.js';6import { VERSION } from './constants.js';7import 'node:fs/promises';8import 'node:url';9import 'node:util';10import 'node:module';11import 'node:crypto';12import 'tty';13import 'path';14import 'esbuild';15import 'fs';16import 'node:events';17import 'node:stream';18import 'node:string_decoder';19import 'node:child_process';20import 'node:http';21import 'node:https';22import 'util';23import 'net';24import 'url';25import 'http';26import 'stream';27import 'os';28import 'child_process';29import 'node:os';30import 'node:dns';31import 'crypto';32import 'module';33import 'node:assert';34import 'node:v8';35import 'node:worker_threads';36import 'node:buffer';37import 'rollup/parseAst';38import 'querystring';39import 'node:readline';40import 'zlib';41import 'buffer';42import 'https';43import 'tls';44import 'node:net';45import 'assert';46import 'node:zlib';47 48function toArr(any) {49 return any == null ? [] : Array.isArray(any) ? any : [any];50}51 52function toVal(out, key, val, opts) {53 var x, old=out[key], nxt=(54 !!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))55 : typeof val === 'boolean' ? val56 : !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))57 : (x = +val,x * 0 === 0) ? x : val58 );59 out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);60}61 62function mri2 (args, opts) {63 args = args || [];64 opts = opts || {};65 66 var k, arr, arg, name, val, out={ _:[] };67 var i=0, j=0, idx=0, len=args.length;68 69 const alibi = opts.alias !== void 0;70 const strict = opts.unknown !== void 0;71 const defaults = opts.default !== void 0;72 73 opts.alias = opts.alias || {};74 opts.string = toArr(opts.string);75 opts.boolean = toArr(opts.boolean);76 77 if (alibi) {78 for (k in opts.alias) {79 arr = opts.alias[k] = toArr(opts.alias[k]);80 for (i=0; i < arr.length; i++) {81 (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);82 }83 }84 }85 86 for (i=opts.boolean.length; i-- > 0;) {87 arr = opts.alias[opts.boolean[i]] || [];88 for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);89 }90 91 for (i=opts.string.length; i-- > 0;) {92 arr = opts.alias[opts.string[i]] || [];93 for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);94 }95 96 if (defaults) {97 for (k in opts.default) {98 name = typeof opts.default[k];99 arr = opts.alias[k] = opts.alias[k] || [];100 if (opts[name] !== void 0) {101 opts[name].push(k);102 for (i=0; i < arr.length; i++) {103 opts[name].push(arr[i]);104 }105 }106 }107 }108 109 const keys = strict ? Object.keys(opts.alias) : [];110 111 for (i=0; i < len; i++) {112 arg = args[i];113 114 if (arg === '--') {115 out._ = out._.concat(args.slice(++i));116 break;117 }118 119 for (j=0; j < arg.length; j++) {120 if (arg.charCodeAt(j) !== 45) break; // "-"121 }122 123 if (j === 0) {124 out._.push(arg);125 } else if (arg.substring(j, j + 3) === 'no-') {126 name = arg.substring(j + 3);127 if (strict && !~keys.indexOf(name)) {128 return opts.unknown(arg);129 }130 out[name] = false;131 } else {132 for (idx=j+1; idx < arg.length; idx++) {133 if (arg.charCodeAt(idx) === 61) break; // "="134 }135 136 name = arg.substring(j, idx);137 val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);138 arr = (j === 2 ? [name] : name);139 140 for (idx=0; idx < arr.length; idx++) {141 name = arr[idx];142 if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);143 toVal(out, name, (idx + 1 < arr.length) || val, opts);144 }145 }146 }147 148 if (defaults) {149 for (k in opts.default) {150 if (out[k] === void 0) {151 out[k] = opts.default[k];152 }153 }154 }155 156 if (alibi) {157 for (k in out) {158 arr = opts.alias[k] || [];159 while (arr.length > 0) {160 out[arr.shift()] = out[k];161 }162 }163 }164 165 return out;166}167 168const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();169const findAllBrackets = (v) => {170 const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;171 const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;172 const res = [];173 const parse = (match) => {174 let variadic = false;175 let value = match[1];176 if (value.startsWith("...")) {177 value = value.slice(3);178 variadic = true;179 }180 return {181 required: match[0].startsWith("<"),182 value,183 variadic184 };185 };186 let angledMatch;187 while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {188 res.push(parse(angledMatch));189 }190 let squareMatch;191 while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {192 res.push(parse(squareMatch));193 }194 return res;195};196const getMriOptions = (options) => {197 const result = {alias: {}, boolean: []};198 for (const [index, option] of options.entries()) {199 if (option.names.length > 1) {200 result.alias[option.names[0]] = option.names.slice(1);201 }202 if (option.isBoolean) {203 if (option.negated) {204 const hasStringTypeOption = options.some((o, i) => {205 return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";206 });207 if (!hasStringTypeOption) {208 result.boolean.push(option.names[0]);209 }210 } else {211 result.boolean.push(option.names[0]);212 }213 }214 }215 return result;216};217const findLongest = (arr) => {218 return arr.sort((a, b) => {219 return a.length > b.length ? -1 : 1;220 })[0];221};222const padRight = (str, length) => {223 return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;224};225const camelcase = (input) => {226 return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {227 return p1 + p2.toUpperCase();228 });229};230const setDotProp = (obj, keys, val) => {231 let i = 0;232 let length = keys.length;233 let t = obj;234 let x;235 for (; i < length; ++i) {236 x = t[keys[i]];237 t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];238 }239};240const setByType = (obj, transforms) => {241 for (const key of Object.keys(transforms)) {242 const transform = transforms[key];243 if (transform.shouldTransform) {244 obj[key] = Array.prototype.concat.call([], obj[key]);245 if (typeof transform.transformFunction === "function") {246 obj[key] = obj[key].map(transform.transformFunction);247 }248 }249 }250};251const getFileName = (input) => {252 const m = /([^\\\/]+)$/.exec(input);253 return m ? m[1] : "";254};255const camelcaseOptionName = (name) => {256 return name.split(".").map((v, i) => {257 return i === 0 ? camelcase(v) : v;258 }).join(".");259};260class CACError extends Error {261 constructor(message) {262 super(message);263 this.name = this.constructor.name;264 if (typeof Error.captureStackTrace === "function") {265 Error.captureStackTrace(this, this.constructor);266 } else {267 this.stack = new Error(message).stack;268 }269 }270}271 272class Option {273 constructor(rawName, description, config) {274 this.rawName = rawName;275 this.description = description;276 this.config = Object.assign({}, config);277 rawName = rawName.replace(/\.\*/g, "");278 this.negated = false;279 this.names = removeBrackets(rawName).split(",").map((v) => {280 let name = v.trim().replace(/^-{1,2}/, "");281 if (name.startsWith("no-")) {282 this.negated = true;283 name = name.replace(/^no-/, "");284 }285 return camelcaseOptionName(name);286 }).sort((a, b) => a.length > b.length ? 1 : -1);287 this.name = this.names[this.names.length - 1];288 if (this.negated && this.config.default == null) {289 this.config.default = true;290 }291 if (rawName.includes("<")) {292 this.required = true;293 } else if (rawName.includes("[")) {294 this.required = false;295 } else {296 this.isBoolean = true;297 }298 }299}300 301const processArgs = process.argv;302const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;303 304class Command {305 constructor(rawName, description, config = {}, cli) {306 this.rawName = rawName;307 this.description = description;308 this.config = config;309 this.cli = cli;310 this.options = [];311 this.aliasNames = [];312 this.name = removeBrackets(rawName);313 this.args = findAllBrackets(rawName);314 this.examples = [];315 }316 usage(text) {317 this.usageText = text;318 return this;319 }320 allowUnknownOptions() {321 this.config.allowUnknownOptions = true;322 return this;323 }324 ignoreOptionDefaultValue() {325 this.config.ignoreOptionDefaultValue = true;326 return this;327 }328 version(version, customFlags = "-v, --version") {329 this.versionNumber = version;330 this.option(customFlags, "Display version number");331 return this;332 }333 example(example) {334 this.examples.push(example);335 return this;336 }337 option(rawName, description, config) {338 const option = new Option(rawName, description, config);339 this.options.push(option);340 return this;341 }342 alias(name) {343 this.aliasNames.push(name);344 return this;345 }346 action(callback) {347 this.commandAction = callback;348 return this;349 }350 isMatched(name) {351 return this.name === name || this.aliasNames.includes(name);352 }353 get isDefaultCommand() {354 return this.name === "" || this.aliasNames.includes("!");355 }356 get isGlobalCommand() {357 return this instanceof GlobalCommand;358 }359 hasOption(name) {360 name = name.split(".")[0];361 return this.options.find((option) => {362 return option.names.includes(name);363 });364 }365 outputHelp() {366 const {name, commands} = this.cli;367 const {368 versionNumber,369 options: globalOptions,370 helpCallback371 } = this.cli.globalCommand;372 let sections = [373 {374 body: `${name}${versionNumber ? `/${versionNumber}` : ""}`375 }376 ];377 sections.push({378 title: "Usage",379 body: ` $ ${name} ${this.usageText || this.rawName}`380 });381 const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;382 if (showCommands) {383 const longestCommandName = findLongest(commands.map((command) => command.rawName));384 sections.push({385 title: "Commands",386 body: commands.map((command) => {387 return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;388 }).join("\n")389 });390 sections.push({391 title: `For more info, run any command with the \`--help\` flag`,392 body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")393 });394 }395 let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];396 if (!this.isGlobalCommand && !this.isDefaultCommand) {397 options = options.filter((option) => option.name !== "version");398 }399 if (options.length > 0) {400 const longestOptionName = findLongest(options.map((option) => option.rawName));401 sections.push({402 title: "Options",403 body: options.map((option) => {404 return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;405 }).join("\n")406 });407 }408 if (this.examples.length > 0) {409 sections.push({410 title: "Examples",411 body: this.examples.map((example) => {412 if (typeof example === "function") {413 return example(name);414 }415 return example;416 }).join("\n")417 });418 }419 if (helpCallback) {420 sections = helpCallback(sections) || sections;421 }422 console.log(sections.map((section) => {423 return section.title ? `${section.title}:424${section.body}` : section.body;425 }).join("\n\n"));426 }427 outputVersion() {428 const {name} = this.cli;429 const {versionNumber} = this.cli.globalCommand;430 if (versionNumber) {431 console.log(`${name}/${versionNumber} ${platformInfo}`);432 }433 }434 checkRequiredArgs() {435 const minimalArgsCount = this.args.filter((arg) => arg.required).length;436 if (this.cli.args.length < minimalArgsCount) {437 throw new CACError(`missing required args for command \`${this.rawName}\``);438 }439 }440 checkUnknownOptions() {441 const {options, globalCommand} = this.cli;442 if (!this.config.allowUnknownOptions) {443 for (const name of Object.keys(options)) {444 if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {445 throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);446 }447 }448 }449 }450 checkOptionValue() {451 const {options: parsedOptions, globalCommand} = this.cli;452 const options = [...globalCommand.options, ...this.options];453 for (const option of options) {454 const value = parsedOptions[option.name.split(".")[0]];455 if (option.required) {456 const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));457 if (value === true || value === false && !hasNegated) {458 throw new CACError(`option \`${option.rawName}\` value is missing`);459 }460 }461 }462 }463}464class GlobalCommand extends Command {465 constructor(cli) {466 super("@@global@@", "", {}, cli);467 }468}469 470var __assign = Object.assign;471class CAC extends EventEmitter {472 constructor(name = "") {473 super();474 this.name = name;475 this.commands = [];476 this.rawArgs = [];477 this.args = [];478 this.options = {};479 this.globalCommand = new GlobalCommand(this);480 this.globalCommand.usage("<command> [options]");481 }482 usage(text) {483 this.globalCommand.usage(text);484 return this;485 }486 command(rawName, description, config) {487 const command = new Command(rawName, description || "", config, this);488 command.globalCommand = this.globalCommand;489 this.commands.push(command);490 return command;491 }492 option(rawName, description, config) {493 this.globalCommand.option(rawName, description, config);494 return this;495 }496 help(callback) {497 this.globalCommand.option("-h, --help", "Display this message");498 this.globalCommand.helpCallback = callback;499 this.showHelpOnExit = true;500 return this;501 }502 version(version, customFlags = "-v, --version") {503 this.globalCommand.version(version, customFlags);504 this.showVersionOnExit = true;505 return this;506 }507 example(example) {508 this.globalCommand.example(example);509 return this;510 }511 outputHelp() {512 if (this.matchedCommand) {513 this.matchedCommand.outputHelp();514 } else {515 this.globalCommand.outputHelp();516 }517 }518 outputVersion() {519 this.globalCommand.outputVersion();520 }521 setParsedInfo({args, options}, matchedCommand, matchedCommandName) {522 this.args = args;523 this.options = options;524 if (matchedCommand) {525 this.matchedCommand = matchedCommand;526 }527 if (matchedCommandName) {528 this.matchedCommandName = matchedCommandName;529 }530 return this;531 }532 unsetMatchedCommand() {533 this.matchedCommand = void 0;534 this.matchedCommandName = void 0;535 }536 parse(argv = processArgs, {537 run = true538 } = {}) {539 this.rawArgs = argv;540 if (!this.name) {541 this.name = argv[1] ? getFileName(argv[1]) : "cli";542 }543 let shouldParse = true;544 for (const command of this.commands) {545 const parsed = this.mri(argv.slice(2), command);546 const commandName = parsed.args[0];547 if (command.isMatched(commandName)) {548 shouldParse = false;549 const parsedInfo = __assign(__assign({}, parsed), {550 args: parsed.args.slice(1)551 });552 this.setParsedInfo(parsedInfo, command, commandName);553 this.emit(`command:${commandName}`, command);554 }555 }556 if (shouldParse) {557 for (const command of this.commands) {558 if (command.name === "") {559 shouldParse = false;560 const parsed = this.mri(argv.slice(2), command);561 this.setParsedInfo(parsed, command);562 this.emit(`command:!`, command);563 }564 }565 }566 if (shouldParse) {567 const parsed = this.mri(argv.slice(2));568 this.setParsedInfo(parsed);569 }570 if (this.options.help && this.showHelpOnExit) {571 this.outputHelp();572 run = false;573 this.unsetMatchedCommand();574 }575 if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {576 this.outputVersion();577 run = false;578 this.unsetMatchedCommand();579 }580 const parsedArgv = {args: this.args, options: this.options};581 if (run) {582 this.runMatchedCommand();583 }584 if (!this.matchedCommand && this.args[0]) {585 this.emit("command:*");586 }587 return parsedArgv;588 }589 mri(argv, command) {590 const cliOptions = [591 ...this.globalCommand.options,592 ...command ? command.options : []593 ];594 const mriOptions = getMriOptions(cliOptions);595 let argsAfterDoubleDashes = [];596 const doubleDashesIndex = argv.indexOf("--");597 if (doubleDashesIndex > -1) {598 argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);599 argv = argv.slice(0, doubleDashesIndex);600 }601 let parsed = mri2(argv, mriOptions);602 parsed = Object.keys(parsed).reduce((res, name) => {603 return __assign(__assign({}, res), {604 [camelcaseOptionName(name)]: parsed[name]605 });606 }, {_: []});607 const args = parsed._;608 const options = {609 "--": argsAfterDoubleDashes610 };611 const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;612 let transforms = Object.create(null);613 for (const cliOption of cliOptions) {614 if (!ignoreDefault && cliOption.config.default !== void 0) {615 for (const name of cliOption.names) {616 options[name] = cliOption.config.default;617 }618 }619 if (Array.isArray(cliOption.config.type)) {620 if (transforms[cliOption.name] === void 0) {621 transforms[cliOption.name] = Object.create(null);622 transforms[cliOption.name]["shouldTransform"] = true;623 transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];624 }625 }626 }627 for (const key of Object.keys(parsed)) {628 if (key !== "_") {629 const keys = key.split(".");630 setDotProp(options, keys, parsed[key]);631 setByType(options, transforms);632 }633 }634 return {635 args,636 options637 };638 }639 runMatchedCommand() {640 const {args, options, matchedCommand: command} = this;641 if (!command || !command.commandAction)642 return;643 command.checkUnknownOptions();644 command.checkOptionValue();645 command.checkRequiredArgs();646 const actionArgs = [];647 command.args.forEach((arg, index) => {648 if (arg.variadic) {649 actionArgs.push(args.slice(index));650 } else {651 actionArgs.push(args[index]);652 }653 });654 actionArgs.push(options);655 return command.commandAction.apply(this, actionArgs);656 }657}658 659const cac = (name = "") => new CAC(name);660 661const cli = cac("vite");662let profileSession = global.__vite_profile_session;663let profileCount = 0;664const stopProfiler = (log) => {665 if (!profileSession) return;666 return new Promise((res, rej) => {667 profileSession.post("Profiler.stop", (err, { profile }) => {668 if (!err) {669 const outPath = path.resolve(670 `./vite-profile-${profileCount++}.cpuprofile`671 );672 fs__default.writeFileSync(outPath, JSON.stringify(profile));673 log(674 colors.yellow(675 `CPU profile written to ${colors.white(colors.dim(outPath))}`676 )677 );678 profileSession = void 0;679 res();680 } else {681 rej(err);682 }683 });684 });685};686const filterDuplicateOptions = (options) => {687 for (const [key, value] of Object.entries(options)) {688 if (Array.isArray(value)) {689 options[key] = value[value.length - 1];690 }691 }692};693function cleanOptions(options) {694 const ret = { ...options };695 delete ret["--"];696 delete ret.c;697 delete ret.config;698 delete ret.base;699 delete ret.l;700 delete ret.logLevel;701 delete ret.clearScreen;702 delete ret.d;703 delete ret.debug;704 delete ret.f;705 delete ret.filter;706 delete ret.m;707 delete ret.mode;708 if ("sourcemap" in ret) {709 const sourcemap = ret.sourcemap;710 ret.sourcemap = sourcemap === "true" ? true : sourcemap === "false" ? false : ret.sourcemap;711 }712 return ret;713}714const convertHost = (v) => {715 if (typeof v === "number") {716 return String(v);717 }718 return v;719};720const convertBase = (v) => {721 if (v === 0) {722 return "";723 }724 return v;725};726cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {727 type: [convertBase]728}).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);729cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--open [path]", `[boolean | string] open browser on startup`).option("--cors", `[boolean] enable CORS`).option("--strictPort", `[boolean] exit if specified port is already in use`).option(730 "--force",731 `[boolean] force the optimizer to ignore the cache and re-bundle`732).action(async (root, options) => {733 filterDuplicateOptions(options);734 const { createServer } = await import('./chunks/dep-BK3b2jBa.js').then(function (n) { return n.F; });735 try {736 const server = await createServer({737 root,738 base: options.base,739 mode: options.mode,740 configFile: options.config,741 logLevel: options.logLevel,742 clearScreen: options.clearScreen,743 optimizeDeps: { force: options.force },744 server: cleanOptions(options)745 });746 if (!server.httpServer) {747 throw new Error("HTTP server not available");748 }749 await server.listen();750 const info = server.config.logger.info;751 const viteStartTime = global.__vite_start_time ?? false;752 const startupDurationString = viteStartTime ? colors.dim(753 `ready in ${colors.reset(754 colors.bold(Math.ceil(performance.now() - viteStartTime))755 )} ms`756 ) : "";757 const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;758 info(759 `760 ${colors.green(761 `${colors.bold("VITE")} v${VERSION}`762 )} ${startupDurationString}763`,764 {765 clear: !hasExistingLogs766 }767 );768 server.printUrls();769 const customShortcuts = [];770 if (profileSession) {771 customShortcuts.push({772 key: "p",773 description: "start/stop the profiler",774 async action(server2) {775 if (profileSession) {776 await stopProfiler(server2.config.logger.info);777 } else {778 const inspector = await import('node:inspector').then(779 (r) => r.default780 );781 await new Promise((res) => {782 profileSession = new inspector.Session();783 profileSession.connect();784 profileSession.post("Profiler.enable", () => {785 profileSession.post("Profiler.start", () => {786 server2.config.logger.info("Profiler started");787 res();788 });789 });790 });791 }792 }793 });794 }795 server.bindCLIShortcuts({ print: true, customShortcuts });796 } catch (e) {797 const logger = createLogger(options.logLevel);798 logger.error(colors.red(`error when starting dev server:799${e.stack}`), {800 error: e801 });802 stopProfiler(logger.info);803 process.exit(1);804 }805});806cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(807 "--assetsDir <dir>",808 `[string] directory under outDir to place assets in (default: assets)`809).option(810 "--assetsInlineLimit <number>",811 `[number] static asset base64 inline threshold in bytes (default: 4096)`812).option(813 "--ssr [entry]",814 `[string] build specified entry for server-side rendering`815).option(816 "--sourcemap [output]",817 `[boolean | "inline" | "hidden"] output source maps for build (default: false)`818).option(819 "--minify [minifier]",820 `[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`821).option("--manifest [name]", `[boolean | string] emit build manifest json`).option("--ssrManifest [name]", `[boolean | string] emit ssr manifest json`).option(822 "--emptyOutDir",823 `[boolean] force empty outDir when it's outside of root`824).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).action(async (root, options) => {825 filterDuplicateOptions(options);826 const { build } = await import('./chunks/dep-BK3b2jBa.js').then(function (n) { return n.G; });827 const buildOptions = cleanOptions(options);828 try {829 await build({830 root,831 base: options.base,832 mode: options.mode,833 configFile: options.config,834 logLevel: options.logLevel,835 clearScreen: options.clearScreen,836 build: buildOptions837 });838 } catch (e) {839 createLogger(options.logLevel).error(840 colors.red(`error during build:841${e.stack}`),842 { error: e }843 );844 process.exit(1);845 } finally {846 stopProfiler((message) => createLogger(options.logLevel).info(message));847 }848});849cli.command("optimize [root]", "pre-bundle dependencies").option(850 "--force",851 `[boolean] force the optimizer to ignore the cache and re-bundle`852).action(853 async (root, options) => {854 filterDuplicateOptions(options);855 const { optimizeDeps } = await import('./chunks/dep-BK3b2jBa.js').then(function (n) { return n.E; });856 try {857 const config = await resolveConfig(858 {859 root,860 base: options.base,861 configFile: options.config,862 logLevel: options.logLevel,863 mode: options.mode864 },865 "serve"866 );867 await optimizeDeps(config, options.force, true);868 } catch (e) {869 createLogger(options.logLevel).error(870 colors.red(`error when optimizing deps:871${e.stack}`),872 { error: e }873 );874 process.exit(1);875 }876 }877);878cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--open [path]", `[boolean | string] open browser on startup`).option("--outDir <dir>", `[string] output directory (default: dist)`).action(879 async (root, options) => {880 filterDuplicateOptions(options);881 const { preview } = await import('./chunks/dep-BK3b2jBa.js').then(function (n) { return n.H; });882 try {883 const server = await preview({884 root,885 base: options.base,886 configFile: options.config,887 logLevel: options.logLevel,888 mode: options.mode,889 build: {890 outDir: options.outDir891 },892 preview: {893 port: options.port,894 strictPort: options.strictPort,895 host: options.host,896 open: options.open897 }898 });899 server.printUrls();900 server.bindCLIShortcuts({ print: true });901 } catch (e) {902 createLogger(options.logLevel).error(903 colors.red(`error when starting preview server:904${e.stack}`),905 { error: e }906 );907 process.exit(1);908 } finally {909 stopProfiler((message) => createLogger(options.logLevel).info(message));910 }911 }912);913cli.help();914cli.version(VERSION);915cli.parse();916 917export { stopProfiler };918 