From a37923769ac7c7517fef5bbd5502288697ed21dc Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 20 Apr 2021 13:09:00 +0800 Subject: [PATCH 1/6] style: format code --- src/chart/pie/PieView.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/chart/pie/PieView.ts b/src/chart/pie/PieView.ts index 30a21ddd7d..e7e575f568 100644 --- a/src/chart/pie/PieView.ts +++ b/src/chart/pie/PieView.ts @@ -191,19 +191,19 @@ class PiePiece extends graphic.Sector { const labelPosition = seriesModel.get(['label', 'position']); if (labelPosition !== 'outside' && labelPosition !== 'outer') { sector.removeTextGuideLine(); - return; - } else { - let polyline = this.getTextGuideLine(); - if (!polyline) { - polyline = new graphic.Polyline(); - this.setTextGuideLine(polyline); - } - - // Default use item visual color - setLabelLineStyle(this, getLabelLineStatesModels(itemModel), { - stroke: visualColor, - opacity: retrieve3(labelLineModel.get(['lineStyle', 'opacity']), visualOpacity, 1) - }); + } + else { + let polyline = this.getTextGuideLine(); + if (!polyline) { + polyline = new graphic.Polyline(); + this.setTextGuideLine(polyline); + } + + // Default use item visual color + setLabelLineStyle(this, getLabelLineStatesModels(itemModel), { + stroke: visualColor, + opacity: retrieve3(labelLineModel.get(['lineStyle', 'opacity']), visualOpacity, 1) + }); } } } From fa9ece7792b4da573da73c71e887986b3fd5b2b2 Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 20 Apr 2021 20:12:12 +0800 Subject: [PATCH 2/6] test: fix ts-jest don't work on zrender. remove canvas dependency --- package.json | 1 - src/chart/helper/EffectSymbol.ts | 1 - test/ut/core/setup.ts | 10 +--------- test/ut/index.d.ts | 3 +++ test/ut/jest.config.js | 4 ++++ test/ut/tsconfig.json | 12 ++---------- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 1fc1c5b80d..35ff260640 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,6 @@ "@types/jest": "^26.0.14", "@typescript-eslint/eslint-plugin": "^4.9.1", "@typescript-eslint/parser": "^4.9.1", - "canvas": "^2.6.0", "chalk": "^3.0.0", "commander": "2.11.0", "dtslint": "^4.0.5", diff --git a/src/chart/helper/EffectSymbol.ts b/src/chart/helper/EffectSymbol.ts index 34f0a02289..31c6179473 100644 --- a/src/chart/helper/EffectSymbol.ts +++ b/src/chart/helper/EffectSymbol.ts @@ -250,6 +250,5 @@ class EffectSymbol extends Group { }; } -zrUtil.inherits(EffectSymbol, Group); export default EffectSymbol; diff --git a/test/ut/core/setup.ts b/test/ut/core/setup.ts index 479ea92b05..eadc8aa583 100644 --- a/test/ut/core/setup.ts +++ b/test/ut/core/setup.ts @@ -17,12 +17,4 @@ * under the License. */ -// import { JSDOM } from 'jsdom'; -import { Image } from 'canvas'; - -// const { window } = new JSDOM(); - -// (global as any).window = window; -// (global as any).navigator = window.navigator; -// (global as any).document = window.document; -(global as any).Image = Image; +export {}; \ No newline at end of file diff --git a/test/ut/index.d.ts b/test/ut/index.d.ts index b1eb5a9e13..c486c8ea7f 100644 --- a/test/ut/index.d.ts +++ b/test/ut/index.d.ts @@ -20,6 +20,9 @@ export {}; declare global { + + const __DEV__: boolean; + namespace jest { interface Matchers { toBeFinite(): R diff --git a/test/ut/jest.config.js b/test/ut/jest.config.js index bc09902808..9946de2a14 100644 --- a/test/ut/jest.config.js +++ b/test/ut/jest.config.js @@ -32,6 +32,10 @@ module.exports = { globals: { '__DEV__': true }, + // Not exclude node_modules because zrender also needs to be transformed. + transformIgnorePatterns: [ + "node_modules/(?!zrender/)" + ], testMatch: [ '**/spec/api/*.test.ts', '**/spec/component/**/*.test.ts', diff --git a/test/ut/tsconfig.json b/test/ut/tsconfig.json index ff8304bd3a..0cdbc3d770 100644 --- a/test/ut/tsconfig.json +++ b/test/ut/tsconfig.json @@ -1,22 +1,14 @@ { "compilerOptions": { - "target": "ES3", + "target": "ES6", "noImplicitAny": true, "noImplicitThis": true, "strictBindCallApply": true, - "removeComments": true, - "sourceMap": true, - // https://github.com/ezolenko/rollup-plugin-typescript2/issues/12#issuecomment-536173372 - "moduleResolution": "node", - - "importHelpers": true, - - "pretty": true + "esModuleInterop": true }, "include": [ - "../../src/global.d.ts", "**/*.ts" ], "exclude": [ From 5919ce5143e9cd99831b8f0edccdd1cc5c010e9d Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 20 Apr 2021 20:13:08 +0800 Subject: [PATCH 3/6] chore: not install from github zrender in the ci test. --- .github/workflows/nodejs.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 1a2c1d2a75..20354b8ff1 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -21,14 +21,7 @@ jobs: node-version: ${{ matrix.node-version }} - name: npm install run: | - npm install - npm install git+https://github.com/ecomfe/zrender.git - - name: build zrender - run: | - cd node_modules/zrender - npm install - npm run prepublish - cd ../.. + npm ci - name: check type run: | npm run checktype From 92e3416ee5b8253bc5753b6da5e04e99a33c3fef Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 20 Apr 2021 20:22:02 +0800 Subject: [PATCH 4/6] fix(type): remove template string in exported type. #14716 --- src/util/types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util/types.ts b/src/util/types.ts index 50d255f9f4..62ddb56ef5 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -1355,8 +1355,6 @@ export type ComponentItemTooltipLabelFormatterParams = { name: string // properies key array like ['name'] $vars: string[] -} & { - [key in `${ComponentMainType}Index`]: number } & { // Other properties [key in string]: unknown From 017a90ce374a1a55df065d0b830cec0b92ce2b84 Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 20 Apr 2021 20:23:03 +0800 Subject: [PATCH 5/6] chore: add DTS test in the workflow. Also throw error when TS compile error. --- .github/workflows/nodejs.yml | 3 +++ build/pre-publish.js | 24 +++--------------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 20354b8ff1..38c7ce58fa 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -28,6 +28,9 @@ jobs: - name: build release run: | npm run release + - name: test generated DTS + run: | + npm run test:dts # test: # runs-on: ubuntu-latest diff --git a/build/pre-publish.js b/build/pre-publish.js index b4f1097b6d..0c5e3507cf 100644 --- a/build/pre-publish.js +++ b/build/pre-publish.js @@ -206,7 +206,9 @@ async function runTsCompile(localTs, compilerOptions, srcPathList) { console.log(chalk.red(localTs.flattenDiagnosticMessageText(diagnostic.messageText, '\n'))); } }); - assert(!emitResult.emitSkipped, 'ts compile failed.'); + if (allDiagnostics.length > 0) { + throw new Error('TypeScript Compile Failed') + } } module.exports.runTsCompile = runTsCompile; @@ -270,26 +272,6 @@ async function transformDistributionFiles(rooltFolder, replacement) { } } -/** - * Remove __esModule mark. - * - * In the 4.x version. The exported CJS don't have __esModule mark. - * Developers can use `import echarts from 'echarts/lib/echarts' instead of - * `import * as echarts from 'echarts/lib/echarts'` to import all the exported methods. - * It's not recommand but developers may still have the chance to do it. - * But in the tsc export with __esModule mark. This will get an undefined export. - * To avoid breaking this kind of code. We remove __esModule mark manually here. - */ -function removeESmoduleMark() { - const filePath = nodePath.resolve(ecDir, 'lib/echarts.js'); - const code = fs.readFileSync(filePath, 'utf-8') - .replace('\nexports.__esModule = true;\n', ''); - if (code.indexOf('__esModule') >= 0) { - throw new Error('Seems still has __esModule mark'); - } - fs.writeFileSync(filePath, code, 'utf-8'); -} - function singleTransformZRRootFolder(code, replacement) { return code.replace(/([\"\'])zrender\/src\//g, `$1zrender/${replacement}/`); } From 88de34707657b3c2554b1e55cb526c61a235f856 Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 20 Apr 2021 20:27:01 +0800 Subject: [PATCH 6/6] chore: add node modules cache --- .github/workflows/nodejs.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 38c7ce58fa..c9495d87b5 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -19,6 +19,16 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} + + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + - name: npm install run: | npm ci