Skip to content

Commit 06c8042

Browse files
committed
build: auto resolve tsconfig.json
1 parent 9391c1b commit 06c8042

File tree

5 files changed

+18
-46
lines changed

5 files changed

+18
-46
lines changed

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
"javascript.format.insertSpaceAfterCommaDelimiter": true,
1010
"javascript.preferences.quoteStyle": "single",
1111
"javascript.format.semicolons": "remove",
12-
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
12+
"javascript.format.insertSpaceBeforeFunctionParenthesis": false,
13+
"typescript.format.insertSpaceAfterCommaDelimiter": true,
14+
"typescript.preferences.quoteStyle": "single",
15+
"typescript.format.semicolons": "remove",
16+
"typescript.format.insertSpaceBeforeFunctionParenthesis": false,
1317
"files.eol": "\n",
1418
"cSpell.words": [
1519
"Arrayable",

jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type Config } from "@jest/types"
2-
import tsConfig from './tsconfig.json'
2+
import { compilerOptions } from './tsconfig.json'
33

4-
const paths = tsConfig.compilerOptions.paths
4+
const { paths } = compilerOptions
55

66
const aliasPattern = /^(@.*)\/\*$/
77
const sourcePattern = /^(.*)\/\*$/

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
3232
"@babel/preset-env": "^7.27.2",
3333
"@crowdin/crowdin-api-client": "^1.45.0",
34-
"@rsdoctor/rspack-plugin": "^1.1.3",
34+
"@rsdoctor/rspack-plugin": "^1.1.4",
3535
"@rspack/cli": "^1.3.15",
3636
"@rspack/core": "^1.3.15",
37-
"@swc/core": "^1.12.1",
37+
"@swc/core": "^1.12.4",
3838
"@swc/jest": "^0.2.38",
3939
"@types/chrome": "0.0.326",
4040
"@types/decompress": "^4.2.7",
@@ -47,13 +47,13 @@
4747
"css-loader": "^7.1.2",
4848
"decompress": "^4.2.1",
4949
"husky": "^9.1.7",
50-
"jest": "^30.0.0",
51-
"jest-environment-jsdom": "^30.0.0",
50+
"jest": "^30.0.2",
51+
"jest-environment-jsdom": "^30.0.2",
5252
"jest-junit": "^16.0.0",
5353
"postcss": "^8.5.6",
5454
"postcss-loader": "^8.1.1",
5555
"postcss-rtlcss": "^5.7.1",
56-
"puppeteer": "^24.10.1",
56+
"puppeteer": "^24.10.2",
5757
"sass": "^1.89.2",
5858
"sass-loader": "^16.0.5",
5959
"style-loader": "^4.0.0",
@@ -64,18 +64,18 @@
6464
"url-loader": "^4.1.1"
6565
},
6666
"optionalDependencies": {
67-
"web-ext": "^8.7.1"
67+
"web-ext": "^8.8.0"
6868
},
6969
"dependencies": {
7070
"@element-plus/icons-vue": "^2.3.1",
71-
"@vueuse/core": "^13.3.0",
71+
"@vueuse/core": "^13.4.0",
7272
"countup.js": "^2.9.0",
7373
"echarts": "^5.6.0",
7474
"element-plus": "2.10.2",
7575
"js-base64": "^3.7.7",
7676
"punycode": "^2.3.1",
7777
"stream-browserify": "^3.0.0",
78-
"vue": "^3.5.16",
78+
"vue": "^3.5.17",
7979
"vue-router": "^4.5.1"
8080
},
8181
"engines": {

rspack/rspack.common.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,20 @@ import {
44
type RspackPluginInstance,
55
type RuleSetRule
66
} from "@rspack/core"
7-
import path from "path"
7+
import path, { join } from "path"
88
import postcssRTLCSS from 'postcss-rtlcss'
99
import i18nChrome from "../src/i18n/chrome"
10-
import tsConfig from '../tsconfig.json'
1110
import { GenerateJsonPlugin } from "./plugins/generate-json"
1211

1312
export const MANIFEST_JSON_NAME = "manifest.json"
1413

15-
const tsPathAlias = tsConfig.compilerOptions.paths
16-
1714
const generateJsonPlugins: RspackPluginInstance[] = []
1815

1916
const localeJsonFiles = Object.entries(i18nChrome)
2017
.map(([locale, message]) => new GenerateJsonPlugin(`_locales/${locale}/messages.json`, message))
2118
.map(plugin => plugin as unknown as RspackPluginInstance)
2219
generateJsonPlugins.push(...localeJsonFiles)
2320

24-
// Process the alias of typescript modules
25-
const resolveAlias: { [index: string]: string | false | string[] } = {}
26-
const aliasPattern = /^(@.*)\/\*$/
27-
const sourcePattern = /^(src(\/.*)?)\/\*$/
28-
Object.entries(tsPathAlias).forEach(([alias, sourceArr]) => {
29-
if (!sourceArr.length) {
30-
return
31-
}
32-
const aliasMatchRes = alias.match(aliasPattern)
33-
if (!aliasMatchRes) {
34-
// Only process the alias starts with '@'
35-
return
36-
}
37-
const [, index] = aliasMatchRes
38-
const rspackSourceArr: string[] = []
39-
sourceArr.forEach(source => {
40-
const matchRes = source.match(sourcePattern)
41-
if (!matchRes) {
42-
// Only set alias which is in /src folder
43-
return
44-
}
45-
const [, folder] = matchRes
46-
rspackSourceArr.push(path.resolve(__dirname, '..', folder))
47-
})
48-
resolveAlias[index] = rspackSourceArr
49-
})
50-
console.log("Alias of typescript: ")
51-
console.log(resolveAlias)
52-
5321
type EntryConfig = {
5422
name: string
5523
path: string
@@ -140,7 +108,7 @@ const staticOptions: Configuration = {
140108
},
141109
resolve: {
142110
extensions: ['.ts', '.tsx', ".js", '.css', '.scss', '.sass'],
143-
alias: resolveAlias,
111+
tsConfig: join(__dirname, '..', 'tsconfig.json'),
144112
fallback: {
145113
// fallbacks of axios's dependencies start
146114
stream: require.resolve('stream-browserify'),

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@
7878
"tsconfig-paths/register"
7979
]
8080
}
81-
}
81+
}

0 commit comments

Comments
 (0)