Skip to content

Commit e0d35a1

Browse files
committed
fix: updated TypeScript configuration for better source map handling
1 parent 6214590 commit e0d35a1

File tree

7 files changed

+3236
-2837
lines changed

7 files changed

+3236
-2837
lines changed

.fatherrc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export default defineConfig({
55
umd: { entry: 'src', output: 'umd' },
66
sourcemap: true,
77
targets: { chrome: 80 },
8-
plugins: ['./scripts/legacy-mode.ts'],
8+
plugins: ['./scripts/plugin-legacy-mode.ts'],
99
});

jest-legacy.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ module.exports = {
55
preset: 'ts-jest',
66
testEnvironment: 'node',
77
testMatch: ['<rootDir>/tslib/test/**/*.{spec,test}.js'],
8-
setupFiles: ['./tslib/test/jest.setup.js'],
8+
setupFilesAfterEnv: ['<rootDir>/tslib/test/jest.setup.js'],
99
collectCoverage: true,
10-
collectCoverageFrom: ['tslib/src/**/*.js'],
11-
coveragePathIgnorePatterns: ['tslib/src/types.js'],
10+
collectCoverageFrom: ['<rootDir>/lib/**/*.js'],
11+
coveragePathIgnorePatterns: ['<rootDir>/lib/types.js'],
1212
moduleNameMapper: {
13-
'^@enum-plus': '<rootDir>/tslib/src',
14-
'^@enum-plus/(.*)$': '<rootDir>/tslib/src/$1',
13+
'^@enum-plus': '<rootDir>/lib',
14+
'^@enum-plus/(.*)$': '<rootDir>/lib/$1',
1515
},
1616
};

package-lock.json

Lines changed: 3194 additions & 2803 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,61 +86,59 @@
8686
"packages/*"
8787
],
8888
"scripts": {
89+
"add-umd-header": "tsx scripts/add-umd-header-comments.ts",
8990
"build": "run-p build:*",
90-
"build:lib": "run-s ts2lib copy-dts copy-lib",
91+
"build-task-es": "father build",
92+
"build:es": "run-s build-task-es add-umd-header",
9193
"build:es-legacy": "cross-env LEGACY=1 father build",
92-
"build:es": "run-s build-es-only add-umd-header",
93-
"build-es-only": "father build",
94-
"build-for-e2e": "run-s ts2lib build:es build:es-legacy",
95-
"ts2lib": "tsc -p tsconfig.lib.json",
94+
"build:lib": "run-s ts2lib copy-dts copy-lib",
9695
"copy-dts": "shx cp ./src/*.d.ts ./lib",
9796
"copy-lib": "tsx scripts/copy-lib.ts",
98-
"add-umd-header": "tsx scripts/add-umd-header-comments.ts",
99-
"prepublishOnly": "npm run build && npm run test",
100-
"test": "npm run jest",
101-
"jest": "jest --coverage",
102-
"jest:legacy": "jest --coverage -c jest-legacy.config.js",
10397
"e2e": "run-s test:e2e:bundle test:e2e",
104-
"e2e:ui": "run-s test:e2e:bundle test:e2e:ui",
10598
"e2e:debug": "run-s test:e2e:bundle test:e2e:debug",
106-
"test:e2e": "playwright test",
107-
"test:e2e:ui": "playwright test --ui",
108-
"test:e2e:debug": "playwright test --debug",
109-
"test:e2e:bundle": "tsx scripts/make-e2e-bundle.ts",
99+
"e2e:ui": "run-s test:e2e:bundle test:e2e:ui",
100+
"jest": "jest --coverage",
101+
"jest:legacy": "jest --coverage -c jest-legacy.config.js",
110102
"prepare": "husky",
111103
"prepare-legacy-node13": "node ./scripts/prepare-legacy.js node13",
112-
"prepare-legacy-node15": "node ./scripts/prepare-legacy.js node15"
104+
"prepare-legacy-node15": "node ./scripts/prepare-legacy.js node15",
105+
"prepublishOnly": "run-s build test",
106+
"test": "npm run jest",
107+
"test-legacy": "run-s ts2lib jest:legacy",
108+
"test:e2e": "playwright test",
109+
"test:e2e:bundle": "tsx scripts/make-e2e-bundle.ts",
110+
"test:e2e:debug": "playwright test --debug",
111+
"test:e2e:ui": "playwright test --ui",
112+
"ts2lib": "tsc -p tsconfig.lib.json"
113+
},
114+
"overrides": {
115+
"esbuild": "^0.25.0"
113116
},
114117
"devDependencies": {
115118
"@playwright/test": "^1.52.0",
116119
"@rollup/plugin-node-resolve": "^16.0.1",
117120
"@swc/core": "^1.3.53",
118121
"@tiny-codes/code-style-all-in-one": "^1.1.4",
119-
"@types/fs-extra": "^11.0.4",
120122
"@types/jest": "^29.5.14",
121123
"@types/node": "^22.15.3",
122124
"codecov": "^3.8.2",
123125
"cross-env": "^7.0.3",
124126
"esbuild": "^0.25.0",
125127
"father": "^4.5.2",
126-
"fs-extra": "^11.3.0",
127128
"jest": "^29.7.0",
128-
"npm-run-all2": "^7.0.2",
129+
"npm-run-all2": "^8.0.3",
129130
"playwright": "^1.52.0",
130131
"rollup": "^4.40.0",
131132
"shx": "^0.4.0",
132133
"ts-jest": "^29.3.0",
133134
"tsx": "^4.19.4",
134135
"typescript": "^5.8.2"
135136
},
136-
"packageManager": "npm@10.9.2",
137+
"packageManager": "npm@11.4.1",
137138
"engines": {
138139
"node": ">=7.10.1"
139140
},
140141
"publishConfig": {
141142
"registry": "https://registry.npmjs.org/"
142-
},
143-
"overrides": {
144-
"esbuild": "^0.25.0"
145143
}
146144
}

scripts/copy-lib.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// This script copies the contents of the `tslib/src` directory to the `lib` directory.
2-
// 遍历lib目录下的所有的.map文件,把"sources":["../../src/*.ts"]替换为"sources":["../src/*.ts"]
3-
import { copySync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs-extra';
1+
import { cpSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
42
import { join } from 'path';
53

64
const libDir = 'lib';
@@ -10,8 +8,9 @@ rmSync(libDir, {
108
force: true,
119
});
1210

13-
copySync('tslib/src', libDir, {
14-
overwrite: true,
11+
cpSync('tslib/src', libDir, {
12+
recursive: true,
13+
force: true,
1514
errorOnExist: false,
1615
});
1716

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default (api: IApi) => {
1212

1313
api.modifyConfig((memo) => {
1414
const isLegacy = process.env.LEGACY === '1';
15+
const isLib = process.env.LIB === '1';
1516
if (isLegacy) {
1617
if (memo.esm) {
1718
memo.esm.output = 'es-legacy';
@@ -20,6 +21,12 @@ export default (api: IApi) => {
2021
memo.targets = {
2122
ie: 11,
2223
};
24+
} else if (isLib) {
25+
delete memo.esm;
26+
delete memo.umd;
27+
memo.targets = {
28+
node: 7,
29+
};
2330
}
2431
return memo;
2532
});

tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"moduleResolution": "NodeNext",
88
"lib": ["ES2016", "DOM"],
99
"sourceMap": true,
10+
"sourceRoot": "/",
11+
"mapRoot": "./",
12+
"inlineSourceMap": false,
13+
"inlineSources": true,
1014
"jsx": "react-jsx",
1115
"strict": true,
1216
"skipLibCheck": true,

0 commit comments

Comments
 (0)