Skip to content

Commit 6b8fae8

Browse files
authored
Merge pull request #19513 from apache/module_default_esm
feat: change to default ESM package. For developer testing and node usage in customization module scenario.
2 parents 9c3fc0e + 80172d6 commit 6b8fae8

File tree

18 files changed

+273
-96
lines changed

18 files changed

+273
-96
lines changed

.eslintrc-common.yaml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

build/pre-publish.js

Lines changed: 13 additions & 8 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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';

dist/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

i18n/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

package.json

Lines changed: 46 additions & 2 deletions
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
},
@@ -101,5 +101,49 @@
101101
"terser": "^5.16.1",
102102
"ts-jest": "^26.4.3",
103103
"typescript": "4.4.3"
104+
},
105+
"type": "module",
106+
"exports": {
107+
".": {
108+
"types": "./index.d.ts",
109+
"import": "./index.js",
110+
"require": "./index.js"
111+
},
112+
"./core": "./core.js",
113+
"./core.js": "./core.js",
114+
"./charts": "./charts.js",
115+
"./charts.js": "./charts.js",
116+
"./components": "./components.js",
117+
"./components.js": "./components.js",
118+
"./features": "./features.js",
119+
"./features.js": "./features.js",
120+
"./renderers": "./renderers.js",
121+
"./renderers.js": "./renderers.js",
122+
"./index.blank": "./index.blank.js",
123+
"./index.blank.js": "./index.blank.js",
124+
"./index.common": "./index.common.js",
125+
"./index.common.js": "./index.common.js",
126+
"./index.simple": "./index.simple.js",
127+
"./index.simple.js": "./index.simple.js",
128+
"./index": "./index.js",
129+
"./index.js": "./index.js",
130+
"./extension/dataTool": "./extension/dataTool/index.js",
131+
"./extension/dataTool/index": "./extension/dataTool/index.js",
132+
"./extension/dataTool/index.js": "./extension/dataTool/index.js",
133+
"./extension/bmap/bmap": "./extension/bmap/bmap.js",
134+
"./extension/bmap/bmap.js": "./extension/bmap/bmap.js",
135+
"./lib/echarts": "./lib/echarts.js",
136+
"./lib/echarts.js": "./lib/echarts.js",
137+
"./lib/extension": "./lib/extension.js",
138+
"./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+
},
144+
"./*.js": "./*.js",
145+
"./*.ts": "./*.ts",
146+
"./*.json": "./*.json",
147+
"./*": "./*.js"
104148
}
105-
}
149+
}

ssr/client/dist/index.js

Lines changed: 35 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)