UNPKG

@lynx-js/rspeedy

Version:

A webpack/rspack-based frontend toolchain for Lynx

49 lines (48 loc) 2.75 kB
import { mkdir, writeFile } from "node:fs/promises"; export const __rspack_esm_id = "src_plugins_inspect_plugin_ts"; export const __rspack_esm_ids = [ "src_plugins_inspect_plugin_ts" ]; export const __webpack_modules__ = { "./src/config/output/dist-path.ts" (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.d(__webpack_exports__, { z: ()=>DEFAULT_DIST_PATH_INTERMEDIATE }); const DEFAULT_DIST_PATH_INTERMEDIATE = '.rspeedy'; }, "./src/plugins/inspect.plugin.ts" (__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.d(__webpack_exports__, { inspectRspeedyConfig: ()=>inspectRspeedyConfig, pluginInspect: ()=>pluginInspect }); var external_node_path_ = __webpack_require__("node:path"); var core_ = __webpack_require__("@rsbuild/core"); var dist = __webpack_require__("../../../node_modules/.pnpm/javascript-stringify@2.1.0/node_modules/javascript-stringify/dist/index.js"); 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 dist_path = __webpack_require__("./src/config/output/dist-path.ts"); var debug = __webpack_require__("./src/debug.ts"); function pluginInspect(config) { return { name: 'lynx:rsbuild:inspect', setup (api) { api.onBeforeBuild(async ()=>{ await inspectRspeedyConfig(config, external_node_path_["default"].join(api.context.distPath, dist_path.z, 'rspeedy.config.js'), false); }); } }; } async function inspectRspeedyConfig(config, path, verbose) { const stringifiedConfig = (0, dist.stringify)(config, (value, _, stringify)=>{ if ('function' == typeof value && !verbose && value.toString().length > 100) return "function () { /* omitted long function */ }"; return stringify(value); }, 2); if (!stringifiedConfig) return void (0, debug.Yz)('No Rspeedy config found, skip inspect config.'); await mkdir((0, external_node_path_.dirname)(path), { recursive: true }); await writeFile(path, `export default ${stringifiedConfig}`); core_.logger.success(`Inspect Rspeedy config succeed, open following files to view the content: \n\n - ${picocolors_default().bold(picocolors_default().yellow('Rspeedy'))}: ${picocolors_default().underline(path)}\n`); } } };