ui-next: move to a seperate tsconfig

This commit is contained in:
undefined committed 2025-03-18 01:07:34 +08:00
1 parent 80d2137cbb
commit 74a3ee90c7
13 files changed
+93 -34

No files matched your search

-4
View File
@@ -1,4 +0,0 @@
dist
*.d.ts
node_modules
public/**/*.js
+18 -2
View File
@@ -4,6 +4,9 @@ extends:
ignorePatterns: ignorePatterns:
- public/**/*.js - public/**/*.js
- packages/ui-default - packages/ui-default
- dist
- '*.d.ts'
- node_modules
overrides: overrides:
- files: - files:
- '**/{public,frontend}/**/*.{ts,tsx,page.js}' - '**/{public,frontend}/**/*.{ts,tsx,page.js}'
@@ -24,6 +27,15 @@ overrides:
externalModules: true externalModules: true
LOCALES: true LOCALES: true
LANGS: true LANGS: true
- files:
- 'packages/ui-next/src/**/*.{ts,tsx}'
rules:
'@stylistic/indent':
- warn
- 2
env:
browser: true
es6: true
rules: rules:
'@typescript-eslint/no-invalid-this': 1 '@typescript-eslint/no-invalid-this': 1
simple-import-sort/imports: simple-import-sort/imports:
@@ -42,9 +54,13 @@ settings:
- .ts - .ts
- .js - .js
- .jsx - .jsx
- .tsx
import/resolver: import/resolver:
typescript: webpack:
alwaysTryTypes: true config:
resolve:
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue']
parserOptions: parserOptions:
sourceType: module sourceType: module
# project: # project:
+50 -9
View File
@@ -34,6 +34,7 @@ const config = {
compilerOptions: compilerOptionsBase, compilerOptions: compilerOptionsBase,
references: [ references: [
{ path: 'tsconfig.ui.json' }, { path: 'tsconfig.ui.json' },
{ path: 'tsconfig.ui-next.json' },
{ path: 'plugins/tsconfig.json' }, { path: 'plugins/tsconfig.json' },
], ],
files: [], files: [],
@@ -89,8 +90,7 @@ const UIConfig = {
include: ['ts', 'tsx', 'vue', 'json'] include: ['ts', 'tsx', 'vue', 'json']
.flatMap((ext) => ['plugins'] .flatMap((ext) => ['plugins']
.flatMap((name) => [`${name}/**/public/**/*.${ext}`, `${name}/**/frontend/**/*.${ext}`]) .flatMap((name) => [`${name}/**/public/**/*.${ext}`, `${name}/**/frontend/**/*.${ext}`])
.concat(`packages/ui-default/**/*.${ext}`) .concat(`packages/ui-default/**/*.${ext}`)),
.concat(`packages/ui-next/src/**/*.${ext}`)),
compilerOptions: { compilerOptions: {
...compilerOptionsBase, ...compilerOptionsBase,
module: 'ESNext', module: 'ESNext',
@@ -120,6 +120,48 @@ const UIConfig = {
}, },
}; };
const UINextConfig = {
exclude: [
'**/node_modules',
],
include: ['ts', 'tsx', 'vue', 'json'].map((ext) => `packages/ui-next/src/**/*.${ext}`),
compilerOptions: {
...compilerOptionsBase,
module: 'ESNext',
skipLibCheck: true,
allowSyntheticDefaultImports: true,
baseUrl: '.',
jsx: 'react-jsx',
outDir: path.join(baseOutDir, 'ui-next'),
strict: true,
useDefineForClassFields: true,
lib: ['es2022', 'DOM', 'DOM.Iterable'],
/* Bundler mode */
moduleResolution: 'bundler',
moduleDetection: 'force',
noEmit: true,
/* Linting */
noFallthroughCasesInSwitch: true,
noUncheckedSideEffectImports: true,
paths: {
'@/*': [
'./packages/ui-next/*',
],
},
},
};
const tryUpdate = (location, content) => {
const current = fs.existsSync(location) ? fs.readFileSync(location, 'utf-8') : '';
const expected = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
if (expected !== current) fs.writeFileSync(location, expected);
};
const nm = path.resolve(__dirname, '../node_modules'); const nm = path.resolve(__dirname, '../node_modules');
fs.ensureDirSync(path.join(nm, '@hydrooj')); fs.ensureDirSync(path.join(nm, '@hydrooj'));
try { try {
@@ -148,7 +190,7 @@ const pluginsConfig = {
}, },
}, },
}; };
fs.writeFileSync(path.resolve(process.cwd(), 'plugins', 'tsconfig.json'), JSON.stringify(pluginsConfig)); tryUpdate(path.resolve(process.cwd(), 'plugins', 'tsconfig.json'), pluginsConfig);
for (const pkg of modules) { for (const pkg of modules) {
const basedir = path.resolve(process.cwd(), pkg); const basedir = path.resolve(process.cwd(), pkg);
@@ -162,9 +204,7 @@ for (const pkg of modules) {
config.references.push({ path: pkg }); config.references.push({ path: pkg });
const origConfig = (files.includes('src') ? configSrc : configFlat)(pkg); const origConfig = (files.includes('src') ? configSrc : configFlat)(pkg);
const expectedConfig = JSON.stringify(pkg.startsWith('modules/') ? withoutTypes(origConfig) : origConfig); const expectedConfig = JSON.stringify(pkg.startsWith('modules/') ? withoutTypes(origConfig) : origConfig);
const configPath = path.resolve(basedir, 'tsconfig.json'); tryUpdate(path.resolve(basedir, 'tsconfig.json'), expectedConfig);
const currentConfig = fs.existsSync(configPath) ? fs.readFileSync(configPath, 'utf-8') : '';
if (expectedConfig !== currentConfig) fs.writeFileSync(configPath, expectedConfig);
if (!files.includes('src')) continue; if (!files.includes('src')) continue;
// Create mapping entry // Create mapping entry
for (const file of fs.readdirSync(path.resolve(basedir, 'src'))) { for (const file of fs.readdirSync(path.resolve(basedir, 'src'))) {
@@ -172,9 +212,10 @@ for (const pkg of modules) {
const name = file.split('.')[0]; const name = file.split('.')[0];
const filePath = path.resolve(basedir, `${name}.js`); const filePath = path.resolve(basedir, `${name}.js`);
if (name === 'index' && !fs.existsSync(filePath)) { if (name === 'index' && !fs.existsSync(filePath)) {
fs.writeFileSync(filePath, 'module.exports = require("./src/index");\n'); tryUpdate(filePath, 'module.exports = require("./src/index");\n');
} }
} }
} }
fs.writeFileSync(path.resolve(process.cwd(), 'tsconfig.ui.json'), JSON.stringify(UIConfig)); tryUpdate(path.resolve(process.cwd(), 'tsconfig.ui.json'), UIConfig);
fs.writeFileSync(path.resolve(process.cwd(), 'tsconfig.json'), JSON.stringify(config)); tryUpdate(path.resolve(process.cwd(), 'tsconfig.ui-next.json'), UINextConfig);
tryUpdate(path.resolve(process.cwd(), 'tsconfig.json'), config);
+1
View File
@@ -4,6 +4,7 @@ extends:
plugins: plugins:
- react - react
- react-refresh - react-refresh
- react-hooks
- jsx-a11y - jsx-a11y
rules: rules:
react-hooks/exhaustive-deps: 0 react-hooks/exhaustive-deps: 0
+1 -1
View File
@@ -46,7 +46,7 @@
"cross-spawn": "^7.0.6", "cross-spawn": "^7.0.6",
"esbuild": "0.25.0", "esbuild": "0.25.0",
"eslint": "^8.57.1", "eslint": "^8.57.1",
"eslint-import-resolver-typescript": "^3.9.1", "eslint-import-resolver-typescript": "^4.1.1",
"eslint-import-resolver-webpack": "^0.13.10", "eslint-import-resolver-webpack": "^0.13.10",
"fs-extra": "^11.3.0", "fs-extra": "^11.3.0",
"globby": "~14.0.2", "globby": "~14.0.2",
+1 -1
View File
@@ -16,7 +16,7 @@
"@aws-sdk/lib-storage": "3.726.1", "@aws-sdk/lib-storage": "3.726.1",
"@aws-sdk/s3-presigned-post": "3.726.1", "@aws-sdk/s3-presigned-post": "3.726.1",
"@aws-sdk/s3-request-presigner": "3.726.1", "@aws-sdk/s3-request-presigner": "3.726.1",
"@cordisjs/core": "4.0.0-alpha.5", "@cordisjs/core": "4.0.0-alpha.6",
"@cordisjs/logger": "1.0.0-alpha.3", "@cordisjs/logger": "1.0.0-alpha.3",
"@cordisjs/plugin-timer": "1.0.0-alpha.0", "@cordisjs/plugin-timer": "1.0.0-alpha.0",
"@graphql-tools/schema": "^10.0.23", "@graphql-tools/schema": "^10.0.23",
+1 -2
View File
@@ -13,7 +13,7 @@ const descriptions: Record<string, Record<string, string>> = Object.create(null)
const handlers: Record<string, Record<string, any>> = { const handlers: Record<string, Record<string, any>> = {
Query: Object.create(null), Query: Object.create(null),
}; };
let root: Record<string, any> = Object.create(null); const root: Record<string, any> = handlers.Query;
interface ApiContext extends ApiHandler { interface ApiContext extends ApiHandler {
[key: string]: any; [key: string]: any;
@@ -31,7 +31,6 @@ function setDescription(desc: string) {
let schema: GraphQLSchema; let schema: GraphQLSchema;
let schemaStr = ''; let schemaStr = '';
root = handlers.Query;
const applyAuthDirective = (s) => mapSchema(s, { const applyAuthDirective = (s) => mapSchema(s, {
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
@@ -90,7 +90,7 @@ declare module '../../api' {
export async function downloadProblemSet(pids, name = 'Export') { export async function downloadProblemSet(pids, name = 'Export') {
Notification.info(i18n('Downloading...')); Notification.info(i18n('Downloading...'));
const targets = []; const targets: { filename: string; url?: string; content?: string }[] = [];
try { try {
await ctx.serial('problemset/download', pids, name, targets); await ctx.serial('problemset/download', pids, name, targets);
for (const pid of pids) { for (const pid of pids) {
+4 -4
View File
@@ -15,7 +15,7 @@
}, },
"devDependencies": { "devDependencies": {
"@blueprintjs/core": "^5.17.6", "@blueprintjs/core": "^5.17.6",
"@cordisjs/core": "4.0.0-alpha.5", "@cordisjs/core": "4.0.0-alpha.6",
"@fontsource/dm-mono": "^5.2.5", "@fontsource/dm-mono": "^5.2.5",
"@fontsource/fira-code": "^5.2.5", "@fontsource/fira-code": "^5.2.5",
"@fontsource/inconsolata": "^5.2.5", "@fontsource/inconsolata": "^5.2.5",
@@ -25,7 +25,7 @@
"@fontsource/source-code-pro": "^5.2.5", "@fontsource/source-code-pro": "^5.2.5",
"@fontsource/ubuntu-mono": "^5.2.5", "@fontsource/ubuntu-mono": "^5.2.5",
"@hydrooj/utils": "workspace:^", "@hydrooj/utils": "workspace:^",
"@sentry/browser": "^9.5.0", "@sentry/browser": "^9.6.0",
"@sentry/webpack-plugin": "^3.2.2", "@sentry/webpack-plugin": "^3.2.2",
"@simplewebauthn/browser": "13.1.0", "@simplewebauthn/browser": "13.1.0",
"@svgr/webpack": "^8.1.0", "@svgr/webpack": "^8.1.0",
@@ -52,7 +52,7 @@
"classnames": "^2.5.1", "classnames": "^2.5.1",
"clean-webpack-plugin": "^4.0.0", "clean-webpack-plugin": "^4.0.0",
"clipboard": "^2.0.11", "clipboard": "^2.0.11",
"copy-webpack-plugin": "^12.0.2", "copy-webpack-plugin": "^13.0.0",
"core-js": "^3.41.0", "core-js": "^3.41.0",
"core-js-compat": "^3.41.0", "core-js-compat": "^3.41.0",
"css-loader": "^6.11.0", "css-loader": "^6.11.0",
@@ -70,7 +70,7 @@
"jquery.easing": "^1.4.1", "jquery.easing": "^1.4.1",
"jquery.transit": "^0.9.12", "jquery.transit": "^0.9.12",
"matchmedia-polyfill": "^0.3.2", "matchmedia-polyfill": "^0.3.2",
"md-editor-rt": "^5.4.1", "md-editor-rt": "^5.4.2",
"mini-css-extract-plugin": "^2.9.2", "mini-css-extract-plugin": "^2.9.2",
"moment": "^2.30.1", "moment": "^2.30.1",
"monaco-editor": "0.52.2", "monaco-editor": "0.52.2",
+15
View File
@@ -3,3 +3,18 @@ declare module '*.svg?react' {
const content: ComponentType; const content: ComponentType;
export default content; export default content;
} }
declare module '*.vue' {
export default {} as any;
}
declare module '*.css' {
const content: string;
export default content;
}
declare module '*.styl' {
const content: string;
export default content;
}
declare module '*.scss' {
const content: string;
export default content;
}
-3
View File
@@ -1,3 +0,0 @@
declare module '*.vue' {
export default {} as any;
}
-6
View File
@@ -5,7 +5,6 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc -b && vite build", "build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
@@ -18,12 +17,7 @@
"@types/react": "^19.0.10", "@types/react": "^19.0.10",
"@types/react-dom": "^19.0.4", "@types/react-dom": "^19.0.4",
"@vitejs/plugin-react-swc": "^3.8.0", "@vitejs/plugin-react-swc": "^3.8.0",
"eslint": "^9.22.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"typescript": "~5.8.2", "typescript": "~5.8.2",
"typescript-eslint": "^8.26.1",
"vite": "^6.2.2" "vite": "^6.2.2"
} }
} }
+1 -1
View File
@@ -3,5 +3,5 @@ import { createRoot } from 'react-dom/client';
import App from './App'; import App from './App';
createRoot(document.getElementById('root')!).render(<StrictMode> createRoot(document.getElementById('root')!).render(<StrictMode>
<App /> <App />
</StrictMode>); </StrictMode>);