From 93051d56a123c5a413086bd95090cdf516e6e334 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 7 Aug 2022 01:09:18 +0800 Subject: [PATCH] fix(client): set process.env.NODE_ENV to production bug introduced by vitejs/vite#8090 --- packages/client/package.json | 3 ++- packages/client/src/index.ts | 3 +++ packages/client/src/yakumo.ts | 23 +++++++++++++++++++++++ packages/status/build/vite.config.ts | 12 ++++++++++++ packages/status/package.json | 3 +++ tsconfig.json | 3 +++ 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/client/src/yakumo.ts create mode 100644 packages/status/build/vite.config.ts diff --git a/packages/client/package.json b/packages/client/package.json index b741d73c..61e91ea4 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,7 +1,7 @@ { "name": "@koishijs/client", "description": "Koishi Console Client", - "version": "4.3.2", + "version": "4.3.3", "main": "client/index.ts", "files": [ "app", @@ -43,6 +43,7 @@ "cosmokit": "^1.2.1", "element-plus": "2.2.11", "marked": "^4.0.18", + "ns-require": "^1.1.4", "sass": "^1.54.0", "schemastery": "^3.5.1", "schemastery-vue": "^1.3.0", diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 1ac13179..beeb12e6 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -41,6 +41,9 @@ export async function buildExtension(root: string, config: UserConfig = {}) { '@koishijs/client': root + '/client.js', }, }, + define: { + 'process.env.NODE_ENV': '"production"', + }, } as InlineConfig, config)) await fsp.rename(root + '/dist/index.mjs', root + '/dist/index.js') diff --git a/packages/client/src/yakumo.ts b/packages/client/src/yakumo.ts new file mode 100644 index 00000000..d15f5b52 --- /dev/null +++ b/packages/client/src/yakumo.ts @@ -0,0 +1,23 @@ +import { Module } from 'module' +import { UserConfig } from 'vite' +import { register } from 'yakumo' +import { buildExtension } from '.' +import ns from 'ns-require' + +declare module 'yakumo' { + interface Config { + client?: string + } +} + +register('client', async (project) => { + for (const path in project.targets) { + const meta = project.targets[path] + let config: UserConfig = {} + if (meta.yakumo?.client) { + const require = Module.createRequire(project.cwd + path + '/package.json') + config = ns.unwrapExports(require(meta.yakumo.client)) + } + await buildExtension(project.cwd + path, config) + } +}) diff --git a/packages/status/build/vite.config.ts b/packages/status/build/vite.config.ts new file mode 100644 index 00000000..810b0c92 --- /dev/null +++ b/packages/status/build/vite.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from 'vite' + +export default defineConfig({ + plugins: [{ + name: 'fuck-echarts', + renderChunk(code, chunk) { + if (chunk.fileName.includes('echarts')) { + return code.replace(/\bSymbol(?!\.toStringTag)/g, 'FuckSymbol') + } + }, + }], +}) diff --git a/packages/status/package.json b/packages/status/package.json index f91baa1c..5b6275a2 100644 --- a/packages/status/package.json +++ b/packages/status/package.json @@ -27,6 +27,9 @@ "status", "server" ], + "yakumo": { + "client": "./build/vite.config" + }, "koishi": { "description": { "en": "Display running status in the console", diff --git a/tsconfig.json b/tsconfig.json index 7868f00e..6fb3068a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,9 @@ "compilerOptions": { "baseUrl": ".", "paths": { + "@koishijs/client/lib/*": [ + "packages/client/src/*", + ], "@koishijs/plugin-*": [ "packages/*/src", ],