Skip to content

Commit

Permalink
[fix] tweak ssr ts type, impl, exports and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
100pah committed Jan 22, 2024
1 parent 23545a6 commit abe29f0
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .eslintrc-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ rules:
- "error"
prefer-const: 1
no-constant-condition: 0
comma-dangle: 2
comma-dangle: 0
no-debugger: 2
no-dupe-keys: 2
no-empty-character-class: 2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ todo
/extension-esm
/extension
/ssr/client/lib
/ssr/client/types
/ssr/client/index.js
/ssr/client/index.d.ts
/core.js
/core.d.ts
/charts.js
Expand Down
21 changes: 13 additions & 8 deletions build/pre-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const ssrClientGlobby = {
};
const ssrClientSrcDir = nodePath.resolve(ecDir, 'ssr/client/src');
const ssrClientESMDir = nodePath.resolve(ecDir, 'ssr/client/lib');
const ssrClientTypeDir = nodePath.resolve(ecDir, 'ssr/client/types');

const typesDir = nodePath.resolve(ecDir, 'types');
const esmDir = 'lib';
Expand Down Expand Up @@ -148,9 +149,10 @@ const compileWorkList = [
logLabel: 'ssr client ts -> js-esm',
compilerOptionsOverride: {
module: 'ES2015',
declaration: false,
declaration: true,
rootDir: ssrClientSrcDir,
outDir: ssrClientESMDir
outDir: ssrClientESMDir,
declarationDir: ssrClientTypeDir
},
srcGlobby: ssrClientGlobby,
transformOptions: {
Expand Down Expand Up @@ -372,6 +374,7 @@ async function readFilePaths({patterns, cwd}) {
);
}

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

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


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

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

Expand Down
20 changes: 20 additions & 0 deletions build/template/ssr/client/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './types/index';
20 changes: 20 additions & 0 deletions build/template/ssr/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './lib/index.js';
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"mktest": "node test/build/mktest.js",
"mktest:help": "node test/build/mktest.js -h",
"checktype": "tsc --noEmit",
"lint": "npx eslint --cache --cache-location node_modules/.cache/eslint src/**/*.ts extension-src/**/*.ts",
"lint": "npx eslint --cache --cache-location node_modules/.cache/eslint src/**/*.ts ssr/client/src/**/*.ts extension-src/**/*.ts",
"lint:fix": "npx eslint --fix src/**/*.ts extension-src/**/*.ts",
"lint:dist": "echo 'It might take a while. Please wait ...' && npx jshint --config .jshintrc-dist dist/echarts.js"
},
Expand Down Expand Up @@ -107,7 +107,7 @@
".": {
"types": "./index.d.ts",
"import": "./index.js",
"require": "./dist/echarts.js"
"require": "./index.js"
},
"./core": "./core.js",
"./core.js": "./core.js",
Expand Down Expand Up @@ -136,6 +136,11 @@
"./lib/echarts.js": "./lib/echarts.js",
"./lib/extension": "./lib/extension.js",
"./lib/extension.js": "./lib/extension.js",
"./ssr/client/index": {
"types": "./ssr/client/index.d.ts",
"import": "./ssr/client/index.js",
"require": "./ssr/client/dist/index.js"
},
"./*.js": "./*.js",
"./*.ts": "./*.ts",
"./*.json": "./*.json",
Expand Down
73 changes: 35 additions & 38 deletions ssr/client/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ssr/client/dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions ssr/client/src/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Note:
# If eslint does not work in VSCode, please check:
# (1) Whether "@typescript-eslint/eslint-plugin" and "@typescript-eslint/parser"
# are npm installed locally. Should better in the same version.
# (2) Whether "VSCode ESlint extension" is installed.
# (3) If the project folder is not the root folder of your working space, please
# config the "VSCode ESlint extension" in "settings":
# ```json
# "eslint.workingDirectories": [{"mode": "auto"}]
# ```
# Note that it should be "workingDirectories" rather than "WorkingDirectories".

parser: "@typescript-eslint/parser"
parserOptions:
ecmaVersion: 6
sourceType: module
ecmaFeatures:
modules: true
project: "tsconfig.json"
plugins: ["@typescript-eslint"]
env:
es6: false
globals:
jQuery: false
Promise: false
console: true
setTimeout: true
clearTimeout: true
__DEV__: true
extends: '../../../.eslintrc-common.yaml'
Loading

0 comments on commit abe29f0

Please sign in to comment.