diff --git a/packages/frontend-embed/.gitignore b/packages/frontend-embed/.gitignore index 1aa0ac14e8..c9047f496e 100644 --- a/packages/frontend-embed/.gitignore +++ b/packages/frontend-embed/.gitignore @@ -1 +1,2 @@ /storybook-static +tsconfig.json.bak diff --git a/packages/frontend-embed/eslint.config.js b/packages/frontend-embed/eslint.config.js index 054b8b7d75..002471ee7f 100644 --- a/packages/frontend-embed/eslint.config.js +++ b/packages/frontend-embed/eslint.config.js @@ -41,7 +41,7 @@ export default [ parserOptions: { extraFileExtensions: ['.vue'], parser: tsParser, - project: ['./tsconfig.vue.json'], + project: ['tsconfig.vue.json'], sourceType: 'module', tsconfigRootDir: import.meta.dirname, }, @@ -99,11 +99,31 @@ export default [ }, }, { - files: ['*.js', '*.ts'], + files: [ + '*.js', + '*.ts', + 'lib/**/*.ts', + 'lib/**/*.js', + 'scripts/**/*.ts', + 'scripts/**/*.js', + 'scripts/**/*.mjs', + 'scripts/**/*.cjs', + ], + ignores: [ + 'node_modules', + 'vue-shims.d.ts', + 'src', + 'test', + '@types', + 'assets', + ], + globals: { + ...globals.node, + }, languageOptions: { parserOptions: { parser: tsParser, - project: ['./tsconfig.scripts.json'], + project: ['tsconfig.scripts.json'], sourceType: 'module', tsconfigRootDir: import.meta.dirname, }, @@ -119,7 +139,7 @@ export default [ '**/built/', '**/coverage/', '**/node_modules/', - 'vue-shims.d.ts' + 'vue-shims.d.ts', ], }, ]; diff --git a/packages/frontend-embed/package.json b/packages/frontend-embed/package.json index 06e7e05037..7c04a60b80 100644 --- a/packages/frontend-embed/package.json +++ b/packages/frontend-embed/package.json @@ -3,8 +3,9 @@ "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 sw build && pnpm run --filter frontend_shared build", "typecheck-all": "pnpm run --no-bail typecheck:vue && pnpm run --no-bail typecheck:scripts", "typecheck": "pnpm run typecheck:vue && pnpm run typecheck:scripts", "typecheck:vue": "vue-tsc -p tsconfig.vue.json --noEmit", diff --git a/packages/frontend-embed/scripts/build.mjs b/packages/frontend-embed/scripts/build.mjs new file mode 100644 index 0000000000..5c748f4b25 --- /dev/null +++ b/packages/frontend-embed/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-embed/tsconfig.scripts.json b/packages/frontend-embed/tsconfig.scripts.json index 69dfb6129c..77ab85f761 100644 --- a/packages/frontend-embed/tsconfig.scripts.json +++ b/packages/frontend-embed/tsconfig.scripts.json @@ -1,23 +1,20 @@ { "$schema": "https://json.schemastore.org/tsconfig", "extends": "../shared/tsconfig.scripts.jsonc", - "compilerOptions": { - "typeRoots": [ - "./@types", - "./node_modules/@vue-macros", - "./node_modules/@types", - "./node_modules" - ], - "types": [ - "vite/client", - ] - }, "include": [ "*.js", - "*.ts" + "*.ts", + "scripts/**/*.ts", + "scripts/**/*.js", + "scripts/**/*.mjs", + "scripts/**/*.cjs" ], "exclude": [ "node_modules", - "vue-shims.d.ts" + "vue-shims.d.ts", + "src", + "test", + "@types", + "assets" ] } diff --git a/packages/frontend-embed/tsconfig.vue.json b/packages/frontend-embed/tsconfig.vue.json index 210460442f..36e05cb151 100644 --- a/packages/frontend-embed/tsconfig.vue.json +++ b/packages/frontend-embed/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/*"] diff --git a/packages/frontend-embed/vite.config.ts b/packages/frontend-embed/vite.config.ts index 3fdabc4eaa..52c6d12cea 100644 --- a/packages/frontend-embed/vite.config.ts +++ b/packages/frontend-embed/vite.config.ts @@ -6,9 +6,7 @@ import { localesVersion } from '../../locales/version.js'; import locales from '../../locales/index.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 pluginJson5 from './vite.json5.js'; -import type { TsconfigRaw } from 'esbuild'; const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue']; @@ -117,12 +115,6 @@ export function getConfig(): UserConfig { __VUE_PROD_DEVTOOLS__: false, }, - esbuild: { - // https://github.com/vitejs/vite/discussions/8483#discussioncomment-14485974 - // https://esbuild.github.io/api/#tsconfig-raw - tsconfigRaw: tsconfigVue as TsconfigRaw, - }, - build: { target: [ 'chrome116',