Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 优化类型声明文件打包配置 #1396

Merged
merged 5 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package.json
esm
lib
dist
temp
.idea
*.d.ts
.eslintrc*
/scripts/*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ temp/
s2-site/.cache/
s2-site/public

# s2-core
# packages
packages/s2-*/lib/
packages/s2-*/esm/
packages/s2-*/dist/
packages/s2-*/temp/
packages/s2-*/coverage/
packages/s2-*/stats.html

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"@babel/core": "^7.17.9",
"@commitlint/cli": "^16.2.3",
"@commitlint/config-conventional": "^16.2.1",
"@microsoft/api-extractor": "^7.24.2",
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^21.1.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/s2-core/__tests__/unit/interaction/root-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ describe('RootInteraction Tests', () => {
let flag = false;
const hoverTimer = setTimeout(() => {
flag = true;
}, 100);
}, 100) as unknown as number;

rootInteraction.setState({
cells: [getCellMeta(mockCell)],
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('RootInteraction Tests', () => {
let flag = false;
const hoverTimer = setTimeout(() => {
flag = true;
}, 100);
}, 100) as unknown as number;

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

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

rootInteraction.setHoverTimer(timer);

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

rootInteraction.setHoverTimer(timer);
rootInteraction.clearHoverTimer();
Expand Down
10 changes: 7 additions & 3 deletions packages/s2-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
],
"scripts": {
"start": "yarn test:live",
"clean": "rimraf lib esm dist",
"build": "run-s clean build:esm build:cjs build:umd",
"build:esm": "cross-env FORMAT=esm rollup -c rollup.config.js",
"clean": "rimraf lib esm dist temp",
"build": "npm-run-all clean --parallel build:umd build:cjs build:esm --sequential build:dts",
"build:esm": "cross-env FORMAT=es rollup -c rollup.config.js",
"build:cjs": "cross-env FORMAT=cjs rollup -c rollup.config.js",
"build:umd": "cross-env FORMAT=umd rollup -c rollup.config.js",
"build:analysis": "cross-env FORMAT=esm ANALYSIS=true rollup -c rollup.config.js",
"build:dts": "run-s dts:*",
"dts:build":"ttsc -p tsconfig.declaration.json",
"dts:extract":"cross-env LIB=s2-core node ../../scripts/dts.js",
"dts:clean":"rimraf temp",
"bundle:size": "bundlesize",
"watch": "rimraf esm && yarn build:esm -w",
"test:live": "node ./scripts/test-live.mjs",
Expand Down
14 changes: 4 additions & 10 deletions packages/s2-core/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import { visualizer } from 'rollup-plugin-visualizer';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import ttypescript from 'ttypescript';

const format = process.env.FORMAT;
const enableAnalysis = process.env.ANALYSIS;

const OUT_DIR_NAME_MAP = {
esm: 'esm',
es: 'esm',
cjs: 'lib',
umd: 'dist',
};

const outDir = OUT_DIR_NAME_MAP[format];
const isEsmFormat = format === 'esm';

const isUmdFormat = format === 'umd';

const output = {
Expand All @@ -42,17 +41,12 @@ const plugins = [
commonjs(),
resolve(),
typescript({
outDir,
abortOnError: true,
tsconfig: 'tsconfig.json',
tsconfigOverride: {
exclude: ['__tests__'],
compilerOptions: {
declaration: isEsmFormat,
declarationMap: isEsmFormat,
},
outDir,
include: ['src'],
},
typescript: ttypescript,
}),
postcss({
minimize: isUmdFormat,
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/src/interaction/base-interaction/hover.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Event as CanvasEvent } from '@antv/g-canvas';
import { getCellMeta } from 'src/utils/interaction/select-event';
import { isEmpty, forEach, isEqual, isBoolean } from 'lodash';
import { isEmpty, forEach, isBoolean } from 'lodash';
import { BaseEvent, BaseEventImplement } from '../base-event';
import { ColCell, RowCell } from '@/cell';
import { S2Event } from '@/common/constant';
Expand Down Expand Up @@ -95,7 +95,7 @@ export class HoverEvent extends BaseEvent implements BaseEventImplement {
if (hoverFocusDuration === 0) {
handleHoverFocus();
} else {
const hoverTimer = setTimeout(
const hoverTimer: number = window.setTimeout(
() => handleHoverFocus(),
hoverFocusDuration,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/src/interaction/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class RootInteraction {

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

public eventController: EventController;

Expand Down Expand Up @@ -503,7 +503,7 @@ export class RootInteraction {
clearTimeout(this.hoverTimer);
}

public setHoverTimer(timer: NodeJS.Timeout) {
public setHoverTimer(timer: number) {
this.hoverTimer = timer;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/s2-core/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declarationDir": "temp",
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["src"]
}
3 changes: 2 additions & 1 deletion packages/s2-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"src/*": ["./src/*"],
"tests/*": ["./__tests__/*"],
}
}
},
"exclude": ["node_modules", "coverage", "esm", "lib", "dist","temp"]
}
15 changes: 10 additions & 5 deletions packages/s2-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@
],
"scripts": {
"start": "cross-env PLAYGROUND=true vite",
"clean": "rimraf lib esm dist",
"build": "run-s clean build:esm build:cjs build:umd build:declaration",
"clean": "rimraf lib esm dist temp",
"build": "npm-run-all clean --parallel build:umd build:cjs build:esm --sequential build:dts",
"build:esm": "cross-env FORMAT=es vite build",
"build:cjs": "cross-env FORMAT=cjs vite build",
"build:umd": "cross-env FORMAT=umd vite build",
"build:analysis": "cross-env FORMAT=es ANALYSIS=true vite build",
"build:declaration": "ttsc -p tsconfig.declaration.json",
"build:dts": "run-s dts:*",
"dts:build-shared":"yarn workspace @antv/s2-shared build:dts",
"dts:build":"ttsc -p tsconfig.declaration.json",
"dts:extract":"cross-env LIB=s2-react node ../../scripts/dts.js",
"dts:clean":"rimraf temp",
"bundle:size": "bundlesize",
"watch": "rimraf esm && concurrently \"yarn build:esm -w\" \"yarn build:declaration -w\"",
"test": "jest --passWithNoTests",
"test:coverage": "yarn test --coverage",
"test:ci": "yarn test --maxWorkers=3",
Expand All @@ -65,7 +68,9 @@
"ahooks": "^3.1.13",
"classnames": "^2.3.1",
"lodash": "^4.17.21",
"react-beautiful-dnd": "^13.1.0"
"react-beautiful-dnd": "^13.1.0",
"@antv/s2-shared":"*"
wjgogogo marked this conversation as resolved.
Show resolved Hide resolved

},
"devDependencies": {
"@antv/s2": "*",
Expand Down
11 changes: 8 additions & 3 deletions packages/s2-react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ export { BaseSheet } from './sheets/base-sheet';
export { TableSheet } from './sheets/table-sheet';
export { GridAnalysisSheet } from './sheets/grid-analysis-sheet';
export { StrategySheet } from './sheets/strategy-sheet';
export { AdvancedSort } from './advanced-sort';
export { DrillDown } from './drill-down';
export {
AdvancedSort,
type AdvancedSortProps,
type AdvancedSortCfgProps,
} from './advanced-sort';
export { DrillDown, type DrillDownProps, type DataSet } from './drill-down';
export { TooltipComponent } from './tooltip';
export { Switcher } from './switcher';
export type { TooltipRenderProps } from './tooltip/interface';
export { Switcher, type SwitcherProps } from './switcher';
export * from './sheets';
export * from './sheets/interface';
7 changes: 3 additions & 4 deletions packages/s2-react/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"compilerOptions": {
"declarationDir": "esm",
"declarationDir": "temp",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true
}
},
"include": ["src"]
}
9 changes: 5 additions & 4 deletions packages/s2-shared/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"private":"true",
"private": "true",
"name": "@antv/s2-shared",
"version": "1.0.0",
"main": "./src/index.ts",
"types": "./src/index.ts",
"description": "internal utility functions and constants shared across s2 packages.",
"license": "MIT",
"scripts": {
"build":"echo 'no need to build'",
"test":"jest"
"build": "echo 'no need to build'",
"build:dts": "tsc -p tsconfig.declaration.json",
"test": "jest"
},
"devDependencies": {
"@antv/s2":"*",
"@antv/s2": "*",
"lodash": "^4.17.21"
}
}
9 changes: 9 additions & 0 deletions packages/s2-shared/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declarationDir": "temp",
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["src"]
}
11 changes: 7 additions & 4 deletions packages/s2-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@
],
"scripts": {
"start": "cross-env PLAYGROUND=true vite",
"clean": "rimraf lib esm dist",
"build": "run-s clean build:esm build:cjs build:umd build:declaration",
"clean": "rimraf lib esm dist temp",
"build": "npm-run-all clean --parallel build:umd build:cjs build:esm --sequential build:dts",
"build:esm": "cross-env FORMAT=es vite build",
"build:cjs": "cross-env FORMAT=cjs vite build",
"build:umd": "cross-env FORMAT=umd vite build",
"build:analysis": "cross-env FORMAT=es ANALYSIS=true vite build",
"build:declaration": "vue-tsc -p tsconfig.declaration.json",
"build:dts": "run-s dts:*",
"dts:build-shared":"yarn workspace @antv/s2-shared build:dts",
"dts:build":"vue-tsc -p tsconfig.declaration.json",
"dts:extract":"cross-env LIB=s2-vue node ../../scripts/dts.js",
"dts:clean":"rimraf temp",
"bundle:size": "bundlesize",
"watch": "rimraf esm && concurrently \"yarn build:esm -w\" \"yarn build:declaration -w\"",
"test": "jest --passWithNoTests",
"test:coverage": "yarn test --coverage",
"test:ci": "yarn test --maxWorkers=3",
Expand Down
7 changes: 3 additions & 4 deletions packages/s2-vue/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"compilerOptions": {
"declarationDir": "temp",
"declaration": true,
"declarationDir": "esm",
"declarationMap": true,
"emitDeclarationOnly": true
}
},
"include": ["src"]
}
56 changes: 56 additions & 0 deletions scripts/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",

"mainEntryPointFilePath": "<projectFolder>/temp/index.d.ts",

"bundledPackages": ["@antv/s2-shared"],

"compiler": {
"tsconfigFilePath": "<projectFolder>/tsconfig.json"
},

"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "<projectFolder>/esm/index.d.ts"
},

"apiReport": {
"enabled": false
},

"docModel": {
"enabled": true
},
"tsdocMetadata": {
"enabled": false
},

"messages": {
"compilerMessageReporting": {
"default": {
"logLevel": "warning"
}
},

"tsdocMessageReporting": {
"default": {
"logLevel": "none"
}
},

"extractorMessageReporting": {
"default": {
"logLevel": "warning"
},

"ae-missing-release-tag": {
"logLevel": "none"
},

"ae-extra-release-tag": {
"logLevel": "none"
}
}
}
}
Loading