@lynx-js/rspeedy
Version:
A webpack/rspack-based frontend toolchain for Lynx
358 lines (357 loc) • 17 kB
JavaScript
import * as __rspack_external__rsbuild_core_1b356efc from "@rsbuild/core";
import * as __rspack_external_node_process_786449bf from "node:process";
var __webpack_modules__ = {
"../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js" (module) {
let p = process || {}, argv = p.argv || [], env = p.env || {};
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || "win32" === p.platform || (p.stdout || {}).isTTY && "dumb" !== env.TERM || !!env.CI);
let formatter = (open, close, replace = open)=>(input)=>{
let string = "" + input, index = string.indexOf(close, open.length);
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
};
let replaceClose = (string, close, replace, index)=>{
let result = "", cursor = 0;
do {
result += string.substring(cursor, index) + replace;
cursor = index + close.length;
index = string.indexOf(close, cursor);
}while (~index);
return result + string.substring(cursor);
};
let createColors = (enabled = isColorSupported)=>{
let f = enabled ? formatter : ()=>String;
return {
isColorSupported: enabled,
reset: f("\x1b[0m", "\x1b[0m"),
bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
italic: f("\x1b[3m", "\x1b[23m"),
underline: f("\x1b[4m", "\x1b[24m"),
inverse: f("\x1b[7m", "\x1b[27m"),
hidden: f("\x1b[8m", "\x1b[28m"),
strikethrough: f("\x1b[9m", "\x1b[29m"),
black: f("\x1b[30m", "\x1b[39m"),
red: f("\x1b[31m", "\x1b[39m"),
green: f("\x1b[32m", "\x1b[39m"),
yellow: f("\x1b[33m", "\x1b[39m"),
blue: f("\x1b[34m", "\x1b[39m"),
magenta: f("\x1b[35m", "\x1b[39m"),
cyan: f("\x1b[36m", "\x1b[39m"),
white: f("\x1b[37m", "\x1b[39m"),
gray: f("\x1b[90m", "\x1b[39m"),
bgBlack: f("\x1b[40m", "\x1b[49m"),
bgRed: f("\x1b[41m", "\x1b[49m"),
bgGreen: f("\x1b[42m", "\x1b[49m"),
bgYellow: f("\x1b[43m", "\x1b[49m"),
bgBlue: f("\x1b[44m", "\x1b[49m"),
bgMagenta: f("\x1b[45m", "\x1b[49m"),
bgCyan: f("\x1b[46m", "\x1b[49m"),
bgWhite: f("\x1b[47m", "\x1b[49m"),
blackBright: f("\x1b[90m", "\x1b[39m"),
redBright: f("\x1b[91m", "\x1b[39m"),
greenBright: f("\x1b[92m", "\x1b[39m"),
yellowBright: f("\x1b[93m", "\x1b[39m"),
blueBright: f("\x1b[94m", "\x1b[39m"),
magentaBright: f("\x1b[95m", "\x1b[39m"),
cyanBright: f("\x1b[96m", "\x1b[39m"),
whiteBright: f("\x1b[97m", "\x1b[39m"),
bgBlackBright: f("\x1b[100m", "\x1b[49m"),
bgRedBright: f("\x1b[101m", "\x1b[49m"),
bgGreenBright: f("\x1b[102m", "\x1b[49m"),
bgYellowBright: f("\x1b[103m", "\x1b[49m"),
bgBlueBright: f("\x1b[104m", "\x1b[49m"),
bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
bgCyanBright: f("\x1b[106m", "\x1b[49m"),
bgWhiteBright: f("\x1b[107m", "\x1b[49m")
};
};
module.exports = createColors();
module.exports.createColors = createColors;
},
"./src/cli/exit.ts" (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
exit: ()=>exit_exit
});
var core_ = __webpack_require__("@rsbuild/core");
var external_node_process_ = __webpack_require__("node:process");
const asyncCallbacks = new Set();
const callbacks = new Set();
let isCalled = false;
let isRegistered = false;
async function exit(shouldManuallyExit, isSynchronous, signal) {
if (isCalled) return;
isCalled = true;
if (asyncCallbacks.size > 0 && isSynchronous) console.error("SYNCHRONOUS TERMINATION NOTICE: When explicitly exiting the process via process.exit or via a parent process, asynchronous tasks in your exitHooks will not run. Either remove these tasks, use gracefulExit() instead of process.exit(), or ensure your parent process sends a SIGINT to the process running this code.");
const exitCode = 128 + signal;
const done = (force = false)=>{
if (true === force || true === shouldManuallyExit) external_node_process_["default"].exit(exitCode);
};
for (const callback of callbacks)callback(exitCode);
if (isSynchronous) return void done();
const promises = [];
let forceAfter = 0;
for (const [callback, wait] of asyncCallbacks){
forceAfter = Math.max(forceAfter, wait);
promises.push(Promise.resolve(callback(exitCode)));
}
const asyncTimer = setTimeout(()=>{
done(true);
}, forceAfter);
await Promise.all(promises);
clearTimeout(asyncTimer);
done();
}
function addHook(options) {
const { onExit, wait, isSynchronous } = options;
const asyncCallbackConfig = [
onExit,
wait
];
if (isSynchronous) callbacks.add(onExit);
else asyncCallbacks.add(asyncCallbackConfig);
if (!isRegistered) {
isRegistered = true;
external_node_process_["default"].once('beforeExit', exit.bind(void 0, true, false, -128));
external_node_process_["default"].once('SIGINT', exit.bind(void 0, true, false, 2));
external_node_process_["default"].once('SIGTERM', exit.bind(void 0, true, false, 15));
external_node_process_["default"].once('exit', exit.bind(void 0, false, true, 0));
external_node_process_["default"].on('message', (message)=>{
if ('shutdown' === message) exit(true, true, -128);
});
}
return ()=>{
if (isSynchronous) callbacks.delete(onExit);
else asyncCallbacks.delete(asyncCallbackConfig);
};
}
function asyncExitHook(onExit, options = {}) {
if ('function' != typeof onExit) throw new TypeError('onExit must be a function');
if (!('number' == typeof options.wait && options.wait > 0)) throw new TypeError('wait must be set to a positive numeric value');
return addHook({
onExit,
wait: options.wait,
isSynchronous: false
});
}
function gracefulExit(signal = 0) {
exit(true, false, -128 + signal);
}
var picocolors = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
var debug = __webpack_require__("./src/debug.ts");
const start = Date.now();
const exitPromises = [];
const unsubscribe = asyncExitHook(exit_onExit, {
wait: 1000
});
process.on('unhandledRejection', async (reason)=>{
core_.logger.error('Unhandled Rejection with reason:', reason instanceof Error ? reason : new Error(JSON.stringify(reason)));
unsubscribe();
await exit_onExit(1);
process.exit(1);
});
let interrupted = false;
process.on('SIGINT', ()=>{
if (interrupted) {
core_.logger.info("Force exiting Rspeedy.");
return process.exit(130);
}
interrupted = true;
core_.logger.info(`Gracefully shutting down. Please wait... (Press ${picocolors_default().cyan('Ctrl+C')} again to force exit)`);
exit_exit(130);
});
let previousSignal = null;
const exit_exit = (signal = 0)=>{
if (null !== previousSignal) (0, debug.Yz)(`graceful exit called multiple times, current: ${signal}, previous: ${previousSignal}`);
previousSignal = signal;
(0, debug.Yz)(`graceful exit process with signal: ${signal}`);
gracefulExit(signal);
};
async function exit_onExit(signal) {
const duration = Date.now() - start;
(0, debug.Yz)(`exit hook fired with signal: ${signal}, duration: ${duration}`);
(0, debug.Yz)(`awaiting exit promises(length: ${exitPromises.length})...`);
await Promise.allSettled(exitPromises);
}
},
"./src/debug.ts" (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Iv: ()=>debugList,
Yz: ()=>debug,
_o: ()=>isDebug
});
var _rsbuild_core__rspack_import_0 = __webpack_require__("@rsbuild/core");
var picocolors__rspack_import_1 = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
var picocolors__rspack_import_1_default = /*#__PURE__*/ __webpack_require__.n(picocolors__rspack_import_1);
const isDebug = ()=>{
if (!process.env['DEBUG']) return false;
const values = process.env['DEBUG'].toLocaleLowerCase().split(',');
return [
'rsbuild',
'rspeedy',
'*'
].some((key)=>values.includes(key));
};
const label = picocolors__rspack_import_1_default().bgCyan('lynx');
const debug = (message)=>{
if (isDebug()) {
const result = 'string' == typeof message ? message : message();
_rsbuild_core__rspack_import_0.logger.level = 'verbose';
_rsbuild_core__rspack_import_0.logger.debug(`${label} ${result}`);
}
};
const debugList = (prefix, messages)=>debug(()=>`${prefix} ${[
''
].concat(messages).join('\n - ')}`);
},
"@rsbuild/core" (module) {
module.exports = __rspack_external__rsbuild_core_1b356efc;
},
"node:process" (module) {
module.exports = __rspack_external_node_process_786449bf;
}
};
var __webpack_module_cache__ = {};
function __webpack_require__(moduleId) {
var cachedModule = __webpack_module_cache__[moduleId];
if (void 0 !== cachedModule) return cachedModule.exports;
var module = __webpack_module_cache__[moduleId] = {
exports: {}
};
__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
return module.exports;
}
__webpack_require__.m = __webpack_modules__;
(()=>{
__webpack_require__.n = (module)=>{
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
__webpack_require__.d(getter, {
a: getter
});
return getter;
};
})();
(()=>{
var getProto = Object.getPrototypeOf ? (obj)=>Object.getPrototypeOf(obj) : (obj)=>obj.__proto__;
var leafPrototypes;
__webpack_require__.t = function(value, mode) {
if (1 & mode) value = this(value);
if (8 & mode) return value;
if ('object' == typeof value && value) {
if (4 & mode && value.__esModule) return value;
if (16 & mode && 'function' == typeof value.then) return value;
}
var ns = Object.create(null);
__webpack_require__.r(ns);
var def = {};
leafPrototypes = leafPrototypes || [
null,
getProto({}),
getProto([]),
getProto(getProto)
];
for(var current = 2 & mode && value; ('object' == typeof current || 'function' == typeof current) && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach((key)=>{
def[key] = ()=>value[key];
});
def['default'] = ()=>value;
__webpack_require__.d(ns, def);
return ns;
};
})();
(()=>{
__webpack_require__.d = (exports, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.f = {};
__webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{
__webpack_require__.f[key](chunkId, promises);
return promises;
}, []));
})();
(()=>{
__webpack_require__.u = (chunkId)=>"1~" + chunkId + ".js";
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports)=>{
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports, '__esModule', {
value: true
});
};
})();
(()=>{
var installedChunks = {
"cli/main": 0
};
var installChunk = (data)=>{
var __rspack_esm_ids = data.__rspack_esm_ids;
var __webpack_modules__ = data.__webpack_modules__;
var __rspack_esm_runtime = data.__rspack_esm_runtime;
var moduleId, chunkId, i = 0;
for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
if (__rspack_esm_runtime) __rspack_esm_runtime(__webpack_require__);
for(; i < __rspack_esm_ids.length; i++){
chunkId = __rspack_esm_ids[i];
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
installedChunks[__rspack_esm_ids[i]] = 0;
}
};
__webpack_require__.f.j = function(chunkId, promises) {
var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
if (0 !== installedChunkData) if (installedChunkData) promises.push(installedChunkData[1]);
else {
var promise = import("../" + __webpack_require__.u(chunkId)).then(installChunk, (e)=>{
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
throw e;
});
var promise = Promise.race([
promise,
new Promise((resolve)=>{
installedChunkData = installedChunks[chunkId] = [
resolve
];
})
]);
promises.push(installedChunkData[1] = promise);
}
};
})();
var core_ = __webpack_require__("@rsbuild/core");
var exit = __webpack_require__("./src/cli/exit.ts");
var debug = __webpack_require__("./src/debug.ts");
function initNodeEnv(argv) {
if (!process.env['NODE_ENV']) {
const NODE_ENV = argv.includes('dev') || argv.includes('preview') ? 'development' : 'production';
process.env['NODE_ENV'] = NODE_ENV;
(0, debug.Yz)(`No NODE_ENV found, set to ${NODE_ENV}`);
}
}
async function main(argv) {
initNodeEnv(argv);
const { npm_execpath } = process.env;
if (!npm_execpath || npm_execpath.includes('npm-cli.js') || npm_execpath.includes('npx-cli.js')) console.log();
const { version, rsbuildVersion, rspackVersion } = await __webpack_require__.e("src_version_ts").then(__webpack_require__.bind(__webpack_require__, "./src/version.ts"));
core_.logger.greet(` Rspeedy v${version} (Rsbuild v${rsbuildVersion}, Rspack v${rspackVersion})\n`);
try {
const [{ Command }, { apply }] = await Promise.all([
Promise.all([
__webpack_require__.e("vendors-node_modules_pnpm_commander_13_1_0_node_modules_commander_esm_mjs"),
__webpack_require__.e("node_child_process-node_events-node_fs-node_path")
]).then(__webpack_require__.bind(__webpack_require__, "../../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/esm.mjs")),
__webpack_require__.e("src_cli_commands_ts").then(__webpack_require__.bind(__webpack_require__, "./src/cli/commands.ts"))
]);
apply(new Command('rspeedy')).parse(argv);
} catch {
return (0, exit.exit)(1);
}
}
export { main };