From d06c07b97b06e90ba8abd0dc3e199cf85fe5299d Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Tue, 7 Oct 2025 19:55:08 -0400 Subject: [PATCH] fix frontend build --- packages/frontend/.gitignore | 1 + packages/frontend/eslint.config.js | 1 + packages/frontend/package.json | 11 +++++---- packages/frontend/scripts/build.mjs | 37 +++++++++++++++++++++++++++++ packages/frontend/tsconfig.vue.json | 12 ++++++---- packages/frontend/vite.config.ts | 8 ------- 6 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 packages/frontend/scripts/build.mjs diff --git a/packages/frontend/.gitignore b/packages/frontend/.gitignore index 1aa0ac14e8..c9047f496e 100644 --- a/packages/frontend/.gitignore +++ b/packages/frontend/.gitignore @@ -1 +1,2 @@ /storybook-static +tsconfig.json.bak diff --git a/packages/frontend/eslint.config.js b/packages/frontend/eslint.config.js index e11c371eaf..c925f7bbcf 100644 --- a/packages/frontend/eslint.config.js +++ b/packages/frontend/eslint.config.js @@ -170,6 +170,7 @@ export default [ autofix: true, }], 'vue/attribute-hyphenation': ['error', 'never'], + 'import/no-default-export': 'off', }, }, { diff --git a/packages/frontend/package.json b/packages/frontend/package.json index b61314186b..911dff36c4 100644 --- a/packages/frontend/package.json +++ b/packages/frontend/package.json @@ -3,19 +3,21 @@ "private": true, "type": "module", "scripts": { - "watch": "vite", - "build": "vite build", + "watch": "node scripts/build.mjs --watch", + "build": "node scripts/build.mjs", + "build:pre": "pnpm run --filter misskey-js build && pnpm run --filter misskey-reversi build && pnpm run --filter misskey-bubble-game build && pnpm run --filter sw build && pnpm run --filter frontend_shared build", "storybook-dev": "nodemon --verbose --watch src --ext \"mdx,ts,vue\" --ignore \"*.stories.ts\" --exec \"pnpm build-storybook-pre && pnpm exec storybook dev -p 6006 --ci\"", "build-storybook-pre": "(tsc -p .storybook || echo done.) && node .storybook/generate.js && node .storybook/preload-locale.js && node .storybook/preload-theme.js", "build-storybook": "pnpm build-storybook-pre && storybook build --webpack-stats-json storybook-static", "chromatic": "chromatic", "test": "vitest --run --globals", "test-and-coverage": "vitest --run --coverage --globals", - "typecheck-all": "pnpm run --no-bail typecheck:vue && pnpm run --no-bail typecheck:test && pnpm run --no-bail typecheck:scripts", - "typecheck": "pnpm run typecheck:vue && pnpm run typecheck:test && pnpm run typecheck:scripts", + "typecheck-all": "pnpm run --no-bail typecheck:vue && pnpm run --no-bail typecheck:test && pnpm run --no-bail typecheck:scripts && pnpm run --no-bail typecheck:storybook", + "typecheck": "pnpm run typecheck:vue && pnpm run typecheck:test && pnpm run typecheck:scripts && pnpm run typecheck:storybook", "typecheck:vue": "vue-tsc -p tsconfig.vue.json --noEmit", "typecheck:test": "vue-tsc -p test/tsconfig.json --noEmit", "typecheck:scripts": "tsc -p tsconfig.scripts.json --noEmit", + "typecheck:storybook": "tsc -p tsconfig.storybook.json --noEmit", "eslint": "eslint --quiet --cache -c eslint.config.js .", "lint": "pnpm typecheck && pnpm eslint" }, @@ -120,6 +122,7 @@ "eslint-plugin-import": "2.32.0", "eslint-plugin-vue": "10.5.0", "estree-walker": "3.0.3", + "execa": "9.6.0", "fast-glob": "3.3.3", "happy-dom": "18.0.1", "intersection-observer": "0.12.2", diff --git a/packages/frontend/scripts/build.mjs b/packages/frontend/scripts/build.mjs new file mode 100644 index 0000000000..5c748f4b25 --- /dev/null +++ b/packages/frontend/scripts/build.mjs @@ -0,0 +1,37 @@ +/** + * Hot-swaps tsconfig files to work around vite limitations. + * Based on idea from https://github.com/vitejs/vite/discussions/8483#discussioncomment-6830634 + */ + +import nodeFs from 'node:fs/promises'; +import nodePath from 'node:path'; +import { execa } from 'execa'; + +const rootDir = nodePath.resolve(import.meta.dirname, '../'); +const tsConfig = nodePath.resolve(rootDir, 'tsconfig.json'); +const tsConfigBak = nodePath.resolve(rootDir, 'tsconfig.json.bak'); +const tsConfigVue = nodePath.resolve(rootDir, 'tsconfig.vue.json'); + +const mode = process.argv.slice(2).includes('--watch') ? 'watch' : 'build'; + +console.log('Staging tsconfig.vue.json as tsconfig.json...'); +await nodeFs.rename(tsConfig, tsConfigBak); +await nodeFs.copyFile(tsConfigVue, tsConfig); + +try { + console.log('Starting vite...') + await execa( + 'vite', + mode === 'build' + ? ['build'] + : [], + { + stdout: process.stdout, + stderr: process.stderr, + }, + ); +} finally { + console.log('Restoring original tsconfig.json...'); + await nodeFs.rm(tsConfig); + await nodeFs.rename(tsConfigBak, tsConfig); +} diff --git a/packages/frontend/tsconfig.vue.json b/packages/frontend/tsconfig.vue.json index 720b3215bf..b91c3065a7 100644 --- a/packages/frontend/tsconfig.vue.json +++ b/packages/frontend/tsconfig.vue.json @@ -2,6 +2,12 @@ "$schema": "https://json.schemastore.org/tsconfig", "extends": "../shared/tsconfig.web.jsonc", "compilerOptions": { + "noImplicitAny": false, + "noUnusedLocals": false, + "noUnusedParameters": false, + "experimentalDecorators": true, + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, "paths": { "@/*": ["./src/*"], "@@/*": ["../frontend-shared/*"] @@ -24,12 +30,10 @@ "./src/**/*.vue", "./test/**/*.ts", "./test/**/*.vue", - "./@types/**/*.ts", - "./vue-shims.d.ts" + "./@types/**/*.ts" ], "exclude": [ "node_modules", - ".storybook/**/*", - "*.*" + ".storybook/**/*" ] } diff --git a/packages/frontend/vite.config.ts b/packages/frontend/vite.config.ts index 2b269f53da..250b8099e6 100644 --- a/packages/frontend/vite.config.ts +++ b/packages/frontend/vite.config.ts @@ -7,11 +7,9 @@ import locales from '../../locales/index.js'; import { localesVersion } from '../../locales/version.js'; import meta from '../../package.json' with { type: 'json' }; import packageInfo from './package.json' with { type: 'json' }; -import tsconfigVue from './tsconfig.vue.json' with { type: 'json' }; import pluginUnwindCssModuleClassName from './lib/rollup-plugin-unwind-css-module-class-name.js'; import pluginJson5 from './vite.json5.js'; import pluginCreateSearchIndex from './lib/vite-plugin-create-search-index.js'; -import type { TsconfigRaw } from 'esbuild'; import type { UserConfig } from 'vite'; import type { Options as SearchIndexOptions } from './lib/vite-plugin-create-search-index.js'; @@ -168,12 +166,6 @@ export function getConfig(): UserConfig { _RUFFLE_VERSION_: JSON.stringify(packageInfo.dependencies['@ruffle-rs/ruffle']), }, - esbuild: { - // https://github.com/vitejs/vite/discussions/8483#discussioncomment-14485974 - // https://esbuild.github.io/api/#tsconfig-raw - tsconfigRaw: tsconfigVue as TsconfigRaw, - }, - build: { target: [ 'chrome116',