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

feat: change to default ESM package. For developer testing and node usage in the module customization scenario. #19513

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 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
3 changes: 3 additions & 0 deletions build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
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';
3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 3 additions & 0 deletions i18n/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
48 changes: 46 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 @@ -101,5 +101,49 @@
"terser": "^5.16.1",
"ts-jest": "^26.4.3",
"typescript": "4.4.3"
},
"type": "module",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.js",
"require": "./index.js"
},
"./core": "./core.js",
"./core.js": "./core.js",
"./charts": "./charts.js",
"./charts.js": "./charts.js",
"./components": "./components.js",
"./components.js": "./components.js",
"./features": "./features.js",
"./features.js": "./features.js",
"./renderers": "./renderers.js",
"./renderers.js": "./renderers.js",
"./index.blank": "./index.blank.js",
"./index.blank.js": "./index.blank.js",
"./index.common": "./index.common.js",
"./index.common.js": "./index.common.js",
"./index.simple": "./index.simple.js",
"./index.simple.js": "./index.simple.js",
"./index": "./index.js",
"./index.js": "./index.js",
"./extension/dataTool": "./extension/dataTool/index.js",
"./extension/dataTool/index": "./extension/dataTool/index.js",
"./extension/dataTool/index.js": "./extension/dataTool/index.js",
"./extension/bmap/bmap": "./extension/bmap/bmap.js",
"./extension/bmap/bmap.js": "./extension/bmap/bmap.js",
"./lib/echarts": "./lib/echarts.js",
"./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",
"./*": "./*.js"
}
}
}
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.

3 changes: 3 additions & 0 deletions ssr/client/dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
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