Skip to content

Commit 98ac165

Browse files
authored
chore: 优化类型声明文件打包配置 (#1396)
* chore: 使用api-extractor 生成 core 声明文件 * chore: 关闭tsdoc警告 * feat: s2-react 适配 api-extractor * feat: s2-vue 适配 api-extractor * fix: 去除s2-shared误加入到dependencies
1 parent 78070b4 commit 98ac165

File tree

22 files changed

+392
-54
lines changed

22 files changed

+392
-54
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package.json
66
esm
77
lib
88
dist
9+
temp
910
.idea
1011
*.d.ts
1112
.eslintrc*
13+
/scripts/*

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ temp/
2121
s2-site/.cache/
2222
s2-site/public
2323

24-
# s2-core
24+
# packages
2525
packages/s2-*/lib/
2626
packages/s2-*/esm/
2727
packages/s2-*/dist/
28+
packages/s2-*/temp/
2829
packages/s2-*/coverage/
2930
packages/s2-*/stats.html
3031

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"@babel/core": "^7.17.9",
9494
"@commitlint/cli": "^16.2.3",
9595
"@commitlint/config-conventional": "^16.2.1",
96+
"@microsoft/api-extractor": "^7.24.2",
9697
"@originjs/vite-plugin-commonjs": "^1.0.3",
9798
"@rollup/plugin-alias": "^3.1.9",
9899
"@rollup/plugin-commonjs": "^21.1.0",

packages/s2-core/__tests__/unit/interaction/root-spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ describe('RootInteraction Tests', () => {
241241
let flag = false;
242242
const hoverTimer = setTimeout(() => {
243243
flag = true;
244-
}, 100);
244+
}, 100) as unknown as number;
245245

246246
rootInteraction.setState({
247247
cells: [getCellMeta(mockCell)],
@@ -272,7 +272,7 @@ describe('RootInteraction Tests', () => {
272272
let flag = false;
273273
const hoverTimer = setTimeout(() => {
274274
flag = true;
275-
}, 100);
275+
}, 100) as unknown as number;
276276

277277
rootInteraction.setState({
278278
cells: [getCellMeta(mockCell)],
@@ -475,7 +475,7 @@ describe('RootInteraction Tests', () => {
475475

476476
describe('RootInteraction Hover Timer Tests', () => {
477477
test('should save hover timer', () => {
478-
const timer = setTimeout(() => jest.fn(), 200);
478+
const timer = setTimeout(() => jest.fn(), 200) as unknown as number;
479479

480480
rootInteraction.setHoverTimer(timer);
481481

@@ -486,7 +486,7 @@ describe('RootInteraction Tests', () => {
486486
let flag = false;
487487
const timer = setTimeout(() => {
488488
flag = true;
489-
}, 200);
489+
}, 200) as unknown as number;
490490

491491
rootInteraction.setHoverTimer(timer);
492492
rootInteraction.clearHoverTimer();

packages/s2-core/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@
3838
],
3939
"scripts": {
4040
"start": "yarn test:live",
41-
"clean": "rimraf lib esm dist",
42-
"build": "run-s clean build:esm build:cjs build:umd",
43-
"build:esm": "cross-env FORMAT=esm rollup -c rollup.config.js",
41+
"clean": "rimraf lib esm dist temp",
42+
"build": "npm-run-all clean --parallel build:umd build:cjs build:esm --sequential build:dts",
43+
"build:esm": "cross-env FORMAT=es rollup -c rollup.config.js",
4444
"build:cjs": "cross-env FORMAT=cjs rollup -c rollup.config.js",
4545
"build:umd": "cross-env FORMAT=umd rollup -c rollup.config.js",
4646
"build:analysis": "cross-env FORMAT=esm ANALYSIS=true rollup -c rollup.config.js",
47+
"build:dts": "run-s dts:*",
48+
"dts:build":"ttsc -p tsconfig.declaration.json",
49+
"dts:extract":"cross-env LIB=s2-core node ../../scripts/dts.js",
50+
"dts:clean":"rimraf temp",
4751
"bundle:size": "bundlesize",
4852
"watch": "rimraf esm && yarn build:esm -w",
4953
"test:live": "node ./scripts/test-live.mjs",

packages/s2-core/rollup.config.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@ import { terser } from 'rollup-plugin-terser';
88
import typescript from 'rollup-plugin-typescript2';
99
import { visualizer } from 'rollup-plugin-visualizer';
1010
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
11-
import ttypescript from 'ttypescript';
1211

1312
const format = process.env.FORMAT;
1413
const enableAnalysis = process.env.ANALYSIS;
1514

1615
const OUT_DIR_NAME_MAP = {
17-
esm: 'esm',
16+
es: 'esm',
1817
cjs: 'lib',
1918
umd: 'dist',
2019
};
2120

2221
const outDir = OUT_DIR_NAME_MAP[format];
23-
const isEsmFormat = format === 'esm';
22+
2423
const isUmdFormat = format === 'umd';
2524

2625
const output = {
@@ -42,17 +41,12 @@ const plugins = [
4241
commonjs(),
4342
resolve(),
4443
typescript({
45-
outDir,
4644
abortOnError: true,
4745
tsconfig: 'tsconfig.json',
4846
tsconfigOverride: {
49-
exclude: ['__tests__'],
50-
compilerOptions: {
51-
declaration: isEsmFormat,
52-
declarationMap: isEsmFormat,
53-
},
47+
outDir,
48+
include: ['src'],
5449
},
55-
typescript: ttypescript,
5650
}),
5751
postcss({
5852
minimize: isUmdFormat,

packages/s2-core/src/interaction/base-interaction/hover.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Event as CanvasEvent } from '@antv/g-canvas';
22
import { getCellMeta } from 'src/utils/interaction/select-event';
3-
import { isEmpty, forEach, isEqual, isBoolean } from 'lodash';
3+
import { isEmpty, forEach, isBoolean } from 'lodash';
44
import { BaseEvent, BaseEventImplement } from '../base-event';
55
import { ColCell, RowCell } from '@/cell';
66
import { S2Event } from '@/common/constant';
@@ -95,7 +95,7 @@ export class HoverEvent extends BaseEvent implements BaseEventImplement {
9595
if (hoverFocusDuration === 0) {
9696
handleHoverFocus();
9797
} else {
98-
const hoverTimer = setTimeout(
98+
const hoverTimer: number = window.setTimeout(
9999
() => handleHoverFocus(),
100100
hoverFocusDuration,
101101
);

packages/s2-core/src/interaction/root.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class RootInteraction {
5050

5151
// hover有keep-hover态,是个计时器,hover后800毫秒还在当前cell的情况下,该cell进入keep-hover状态
5252
// 在任何触发点击,或者点击空白区域时,说明已经不是hover了,因此需要取消这个计时器。
53-
private hoverTimer: NodeJS.Timeout = null;
53+
private hoverTimer: number = null;
5454

5555
public eventController: EventController;
5656

@@ -503,7 +503,7 @@ export class RootInteraction {
503503
clearTimeout(this.hoverTimer);
504504
}
505505

506-
public setHoverTimer(timer: NodeJS.Timeout) {
506+
public setHoverTimer(timer: number) {
507507
this.hoverTimer = timer;
508508
}
509509

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"declarationDir": "temp",
5+
"declaration": true,
6+
"emitDeclarationOnly": true
7+
},
8+
"include": ["src"]
9+
}

packages/s2-core/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"src/*": ["./src/*"],
88
"tests/*": ["./__tests__/*"],
99
}
10-
}
10+
},
11+
"exclude": ["node_modules", "coverage", "esm", "lib", "dist","temp"]
1112
}

0 commit comments

Comments
 (0)