modernize frontend-embed to target the same ES and TS standards as the rest of the app

This commit is contained in:
Hazelnoot 2025-10-05 23:59:31 -04:00
parent 73481990ea
commit 0a5c9f79e5
9 changed files with 109 additions and 79 deletions

View file

@ -15,7 +15,7 @@ export default [
},
...pluginVue.configs['flat/recommended'],
{
files: ['{src,test,js,@types}/**/*.{ts,vue}'],
files: ['{src,test,js,@types}/**/*.{ts,vue}', 'vue-shims.d.ts'],
plugins: { sharkey: { rules: { locale: localeRule } } },
languageOptions: {
globals: {
@ -41,7 +41,7 @@ export default [
parserOptions: {
extraFileExtensions: ['.vue'],
parser: tsParser,
project: ['./tsconfig.json'],
project: ['./tsconfig.vue.json'],
sourceType: 'module',
tsconfigRootDir: import.meta.dirname,
},
@ -98,14 +98,28 @@ export default [
'vue/attribute-hyphenation': ['error', 'never'],
},
},
{
files: ['*.js', '*.ts'],
languageOptions: {
parserOptions: {
parser: tsParser,
project: ['./tsconfig.scripts.json'],
sourceType: 'module',
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'import/no-default-export': 'off',
},
},
{
ignores: [
"**/lib/",
"**/temp/",
"**/built/",
"**/coverage/",
"**/node_modules/",
"*.*",
]
'**/lib/',
'**/temp/',
'**/built/',
'**/coverage/',
'**/node_modules/',
'vue-shims.d.ts'
],
},
];

View file

@ -5,8 +5,11 @@
"scripts": {
"watch": "vite",
"build": "vite build",
"typecheck": "vue-tsc --noEmit",
"eslint": "eslint --quiet \"{src,test,js,@types}/**/*.{js,jsx,ts,tsx,vue}\" --cache",
"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",
"typecheck:scripts": "tsc -p tsconfig.scripts.json --noEmit",
"eslint": "eslint --quiet --cache -c eslint.config.js .",
"lint": "pnpm typecheck && pnpm eslint"
},
"dependencies": {
@ -24,6 +27,7 @@
"vue": "3.5.21"
},
"devDependencies": {
"@misskey-dev/eslint-plugin": "2.1.0",
"@misskey-dev/summaly": "npm:@transfem-org/summaly@5.2.3",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-replace": "6.0.2",

View file

@ -195,7 +195,7 @@ async function init(): Promise<void> {
fetching.value = true;
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
...params,
...params as object,
limit: props.pagination.limit ?? 10,
allowPartial: true,
}).then(res => {
@ -231,7 +231,7 @@ const fetchMore = async (): Promise<void> => {
moreFetching.value = true;
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
...params,
...params as object,
limit: SECOND_FETCH_LIMIT,
...(props.pagination.offsetMode ? {
offset: offset.value,
@ -295,7 +295,7 @@ const fetchMoreAhead = async (): Promise<void> => {
moreFetching.value = true;
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
...params,
...params as object,
limit: SECOND_FETCH_LIMIT,
...(props.pagination.offsetMode ? {
offset: offset.value,

View file

@ -1,6 +1,6 @@
{
"compilerOptions": {
"lib": ["esnext", "webworker"],
"lib": ["ES2022", "WebWorker", "Webworker.Iterable"],
"incremental": true
}
}

View file

@ -1,58 +1,9 @@
{
"compilerOptions": {
"allowJs": true,
"noEmitOnError": false,
"noImplicitAny": false,
"noImplicitReturns": true,
"noUnusedParameters": false,
"noUnusedLocals": false,
"noFallthroughCasesInSwitch": true,
"declaration": false,
"sourceMap": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler",
"removeComments": false,
"noLib": false,
"strict": true,
"strictNullChecks": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"isolatedModules": true,
"useDefineForClassFields": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true,
"incremental": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@@/*": ["../frontend-shared/*"]
},
"typeRoots": [
"./@types",
"./node_modules/@types",
"./node_modules/@vue-macros",
"./node_modules"
],
"types": [
"vite/client"
],
"lib": [
"esnext",
"dom",
"dom.iterable"
],
"jsx": "preserve"
},
"compileOnSave": false,
"include": [
"./src/**/*.ts",
"./src/**/*.vue",
"./@types/**/*.ts"
],
"exclude": [
"node_modules",
".storybook/**/*"
"$schema": "https://json.schemastore.org/tsconfig",
"files": [],
// WebStorm only reads one tsconfig per directory, so this tricks it into loading both.
"references": [
{ "path": "./tsconfig.scripts.json" },
{ "path": "./tsconfig.vue.json" }
]
}

View file

@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../shared/tsconfig.node.json",
"compilerOptions": {
"noImplicitAny": false,
"typeRoots": [
"./@types",
"./node_modules/@vue-macros",
"./node_modules/@types",
"./node_modules"
],
"types": [
"vite/client",
]
},
"include": [
"*.js",
"*.ts"
],
"exclude": [
"node_modules",
"vue-shims.d.ts"
]
}

View file

@ -0,0 +1,30 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../shared/tsconfig.web.json",
"compilerOptions": {
"paths": {
"@/*": ["./src/*"],
"@@/*": ["../frontend-shared/*"]
},
"typeRoots": [
"./@types",
"./node_modules/@types",
"./node_modules/@vue-macros",
"./node_modules"
],
"types": [
"vite/client"
],
"jsx": "preserve"
},
"include": [
"./src/**/*.ts",
"./src/**/*.vue",
"./@types/**/*.ts",
"./vue-shims.d.ts"
],
"exclude": [
"node_modules",
".storybook/**/*"
]
}

View file

@ -1,13 +1,14 @@
import path from 'path';
import pluginVue from '@vitejs/plugin-vue';
import { type UserConfig, defineConfig } from 'vite';
import { pluginReplaceIcons } from 'frontend-shared/util/vite.replaceIcons.js';
import { localesVersion } from '../../locales/version.js';
import locales from '../../locales/index.js';
import meta from '../../package.json';
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 { pluginReplaceIcons } from '../frontend/vite.replaceIcons.js';
import type { TsconfigRaw } from 'esbuild';
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue'];
@ -85,13 +86,13 @@ export function getConfig(): UserConfig {
'@/': __dirname + '/src/',
'@@/': __dirname + '/../frontend-shared/',
'/client-assets/': __dirname + '/assets/',
'/static-assets/': __dirname + '/../backend/assets/'
'/static-assets/': __dirname + '/../backend/assets/',
},
},
css: {
modules: {
generateScopedName(name, filename, _css): string {
generateScopedName(name, filename): string {
const id = (path.relative(__dirname, filename.split('?')[0]) + '-' + name).replace(/[\\\/\.\?&=]/g, '-').replace(/(src-|vue-)/g, '');
const shortId = id.replace(/^(components(-global)?|widgets|ui(-_common_)?)-/, '');
return shortId + '-' + toBase62(hash(id)).substring(0, 4);
@ -99,6 +100,7 @@ export function getConfig(): UserConfig {
},
preprocessorOptions: {
scss: {
// @ts-expect-error not sure why this happens
api: 'modern-compiler',
},
},
@ -115,6 +117,12 @@ 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',
@ -163,6 +171,6 @@ export function getConfig(): UserConfig {
};
}
const config = defineConfig(({ command, mode }) => getConfig());
const config = defineConfig(() => getConfig());
export default config;

View file

@ -1,9 +1,9 @@
// Original: https://github.com/rollup/plugins/tree/8835dd2aed92f408d7dc72d7cc25a9728e16face/packages/json
import JSON5 from 'json5';
import { Plugin } from 'rollup';
import { createFilter, dataToEsm } from '@rollup/pluginutils';
import { RollupJsonOptions } from '@rollup/plugin-json';
import type { Plugin } from 'rollup';
import type { RollupJsonOptions } from '@rollup/plugin-json';
// json5 extends SyntaxError with additional fields (without subclassing)
// https://github.com/json5/json5/blob/de344f0619bda1465a6e25c76f1c0c3dda8108d9/lib/parse.js#L1111-L1112
@ -19,7 +19,6 @@ export default function json5(options: RollupJsonOptions = {}): Plugin {
return {
name: 'json5',
// eslint-disable-next-line no-shadow
transform(json, id) {
if (id.slice(-6) !== '.json5' || !filter(id)) return null;