modernize sw to target the same ES and TS standards as the rest of the app

This commit is contained in:
Hazelnoot 2025-10-05 23:58:08 -04:00
parent 7cbe8eb629
commit df1766e6b5
6 changed files with 66 additions and 49 deletions

View file

@ -37,7 +37,7 @@ const buildOptions = {
outbase: `${__dirname}/src`,
outdir: `${__dirname}/../../built/_sw_dist_`,
treeShaking: true,
tsconfig: `${__dirname}/tsconfig.json`,
tsconfig: `${__dirname}/tsconfig.sw.json`,
};
(async () => {

View file

@ -5,7 +5,7 @@ import sharedConfig from '../shared/eslint.config.js';
export default [
...sharedConfig,
{
ignores: ['build.js'],
ignores: ['*.js'],
languageOptions: {
globals: {
...Object.fromEntries(Object.entries(globals.node).map(([key]) => [key, 'off'])),
@ -17,14 +17,20 @@ export default [
_ENV_: false,
_PERF_PREFIX_: false,
},
parserOptions: {
parser: tsParser,
project: ['./jsconfig.scripts.json'],
sourceType: 'module',
tsconfigRootDir: import.meta.dirname,
},
},
},
{
files: ['**/*.ts', '**/*.tsx'],
files: ['src/**/*.ts', 'src/**/*.tsx'],
languageOptions: {
parserOptions: {
parser: tsParser,
project: ['./tsconfig.json'],
project: ['./tsconfig.sw.json'],
sourceType: 'module',
tsconfigRootDir: import.meta.dirname,
},

View file

@ -0,0 +1,16 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../shared/jsconfig.node.json",
"compilerOptions": {
"typeRoots": [
"./node_modules/@types",
"./src/@types"
]
},
"include": [
"*.js"
],
"exclude": [
"node_modules"
]
}

View file

@ -4,18 +4,22 @@
"scripts": {
"watch": "nodemon -w ../../package.json -e json --exec \"node build.js watch\"",
"build": "node build.js",
"typecheck": "tsc --noEmit",
"eslint": "eslint --quiet \"{src,test,js,@types}/**/*.{js,jsx,ts,tsx,vue}\" --cache",
"typecheck-all": "pnpm run --no-bail typecheck:sw && pnpm run --no-bail typecheck:scripts",
"typecheck": "pnpm run typecheck:sw && pnpm run typecheck:scripts",
"typecheck:sw": "tsc -p tsconfig.sw.json --noEmit",
"typecheck:scripts": "tsc -p jsconfig.scripts.json --noEmit",
"eslint": "eslint --quiet --cache -c eslint.config.js",
"lint": "pnpm typecheck && pnpm eslint"
},
"dependencies": {
"esbuild": "0.25.10",
"idb-keyval": "6.2.2",
"misskey-js": "workspace:*"
},
"devDependencies": {
"@types/node": "22.18.1",
"@typescript-eslint/parser": "8.44.1",
"@typescript/lib-webworker": "npm:@types/serviceworker@0.0.153",
"esbuild": "0.25.10",
"eslint-plugin-import": "2.32.0",
"nodemon": "3.1.10",
"typescript": "5.9.2"

View file

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

View file

@ -0,0 +1,27 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../shared/tsconfig.webworker.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"inlineSources": true,
"removeComments": false,
"baseUrl": ".",
"outDir": "../../built/_sw_dist_",
"paths": {
"@/*": ["./src/*"],
"@@/*": ["../frontend-shared/*"]
},
"typeRoots": [
"./node_modules/@types",
"./src/@types"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}