Skip to content

Commit abe29f0

Browse files
committed
[fix] tweak ssr ts type, impl, exports and eslint
1 parent 23545a6 commit abe29f0

12 files changed

+216
-96
lines changed

.eslintrc-common.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ rules:
3939
- "error"
4040
prefer-const: 1
4141
no-constant-condition: 0
42-
comma-dangle: 2
42+
comma-dangle: 0
4343
no-debugger: 2
4444
no-dupe-keys: 2
4545
no-empty-character-class: 2

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ todo
196196
/extension-esm
197197
/extension
198198
/ssr/client/lib
199+
/ssr/client/types
200+
/ssr/client/index.js
201+
/ssr/client/index.d.ts
199202
/core.js
200203
/core.d.ts
201204
/charts.js

build/pre-publish.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const ssrClientGlobby = {
7575
};
7676
const ssrClientSrcDir = nodePath.resolve(ecDir, 'ssr/client/src');
7777
const ssrClientESMDir = nodePath.resolve(ecDir, 'ssr/client/lib');
78+
const ssrClientTypeDir = nodePath.resolve(ecDir, 'ssr/client/types');
7879

7980
const typesDir = nodePath.resolve(ecDir, 'types');
8081
const esmDir = 'lib';
@@ -148,9 +149,10 @@ const compileWorkList = [
148149
logLabel: 'ssr client ts -> js-esm',
149150
compilerOptionsOverride: {
150151
module: 'ES2015',
151-
declaration: false,
152+
declaration: true,
152153
rootDir: ssrClientSrcDir,
153-
outDir: ssrClientESMDir
154+
outDir: ssrClientESMDir,
155+
declarationDir: ssrClientTypeDir
154156
},
155157
srcGlobby: ssrClientGlobby,
156158
transformOptions: {
@@ -372,6 +374,7 @@ async function readFilePaths({patterns, cwd}) {
372374
);
373375
}
374376

377+
// Bundle can be used in echarts-examples.
375378
async function bundleDTS() {
376379

377380
const outDir = nodePath.resolve(__dirname, '../types/dist');
@@ -442,14 +445,16 @@ function readTSConfig() {
442445

443446

444447
function generateEntries() {
445-
['charts', 'components', 'renderers', 'core', 'features'].forEach(entryName => {
446-
if (entryName !== 'option') {
447-
const jsCode = fs.readFileSync(nodePath.join(__dirname, `template/${entryName}.js`), 'utf-8');
448-
fs.writeFileSync(nodePath.join(__dirname, `../${entryName}.js`), jsCode, 'utf-8');
448+
['charts', 'components', 'renderers', 'core', 'features', 'ssr/client/index'].forEach(entryPath => {
449+
if (entryPath !== 'option') {
450+
const jsCode = fs.readFileSync(nodePath.join(__dirname, `template/${entryPath}.js`), 'utf-8');
451+
fs.writeFileSync(nodePath.join(__dirname, `../${entryPath}.js`), jsCode, 'utf-8');
449452
}
450453

451-
const dtsCode = fs.readFileSync(nodePath.join(__dirname, `/template/${entryName}.d.ts`), 'utf-8');
452-
fs.writeFileSync(nodePath.join(__dirname, `../${entryName}.d.ts`), dtsCode, 'utf-8');
454+
// Make the d.ts in the same dir as .js, so that the can be found by tsc.
455+
// package.json "types" in "exports" does not always seam to work.
456+
const dtsCode = fs.readFileSync(nodePath.join(__dirname, `/template/${entryPath}.d.ts`), 'utf-8');
457+
fs.writeFileSync(nodePath.join(__dirname, `../${entryPath}.d.ts`), dtsCode, 'utf-8');
453458
});
454459
}
455460

build/template/ssr/client/index.d.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export * from './types/index';

build/template/ssr/client/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export * from './lib/index.js';

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"mktest": "node test/build/mktest.js",
6060
"mktest:help": "node test/build/mktest.js -h",
6161
"checktype": "tsc --noEmit",
62-
"lint": "npx eslint --cache --cache-location node_modules/.cache/eslint src/**/*.ts extension-src/**/*.ts",
62+
"lint": "npx eslint --cache --cache-location node_modules/.cache/eslint src/**/*.ts ssr/client/src/**/*.ts extension-src/**/*.ts",
6363
"lint:fix": "npx eslint --fix src/**/*.ts extension-src/**/*.ts",
6464
"lint:dist": "echo 'It might take a while. Please wait ...' && npx jshint --config .jshintrc-dist dist/echarts.js"
6565
},
@@ -107,7 +107,7 @@
107107
".": {
108108
"types": "./index.d.ts",
109109
"import": "./index.js",
110-
"require": "./dist/echarts.js"
110+
"require": "./index.js"
111111
},
112112
"./core": "./core.js",
113113
"./core.js": "./core.js",
@@ -136,6 +136,11 @@
136136
"./lib/echarts.js": "./lib/echarts.js",
137137
"./lib/extension": "./lib/extension.js",
138138
"./lib/extension.js": "./lib/extension.js",
139+
"./ssr/client/index": {
140+
"types": "./ssr/client/index.d.ts",
141+
"import": "./ssr/client/index.js",
142+
"require": "./ssr/client/dist/index.js"
143+
},
139144
"./*.js": "./*.js",
140145
"./*.ts": "./*.ts",
141146
"./*.json": "./*.json",

ssr/client/dist/index.js

+35-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssr/client/dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ssr/client/src/.eslintrc.yaml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
# Note:
20+
# If eslint does not work in VSCode, please check:
21+
# (1) Whether "@typescript-eslint/eslint-plugin" and "@typescript-eslint/parser"
22+
# are npm installed locally. Should better in the same version.
23+
# (2) Whether "VSCode ESlint extension" is installed.
24+
# (3) If the project folder is not the root folder of your working space, please
25+
# config the "VSCode ESlint extension" in "settings":
26+
# ```json
27+
# "eslint.workingDirectories": [{"mode": "auto"}]
28+
# ```
29+
# Note that it should be "workingDirectories" rather than "WorkingDirectories".
30+
31+
parser: "@typescript-eslint/parser"
32+
parserOptions:
33+
ecmaVersion: 6
34+
sourceType: module
35+
ecmaFeatures:
36+
modules: true
37+
project: "tsconfig.json"
38+
plugins: ["@typescript-eslint"]
39+
env:
40+
es6: false
41+
globals:
42+
jQuery: false
43+
Promise: false
44+
console: true
45+
setTimeout: true
46+
clearTimeout: true
47+
__DEV__: true
48+
extends: '../../../.eslintrc-common.yaml'

0 commit comments

Comments
 (0)