Skip to content

Commit

Permalink
chore: remove cjs modules. change to esm format in the lib folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Dec 28, 2020
1 parent 6e38bc5 commit 273d963
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 121 deletions.
70 changes: 11 additions & 59 deletions build/pre-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ const extensionSrcGlobby = {
cwd: ecDir
};
const extensionSrcDir = nodePath.resolve(ecDir, 'extension-src');
const extensionCJSDir = nodePath.resolve(ecDir, 'extension');
const extensionESMDir = nodePath.resolve(ecDir, 'extension-esm');
const extensionESMDir = nodePath.resolve(ecDir, 'extension');

const typesDir = nodePath.resolve(ecDir, 'types');
const esmDir = 'lib';


const compileWorkList = [
Expand All @@ -93,7 +93,7 @@ const compileWorkList = [
before: async function () {
fsExtra.removeSync(tmpDir);
fsExtra.removeSync(nodePath.resolve(ecDir, 'types'));
fsExtra.removeSync(nodePath.resolve(ecDir, 'esm'));
fsExtra.removeSync(nodePath.resolve(ecDir, esmDir));
fsExtra.removeSync(nodePath.resolve(ecDir, 'index.js'));
fsExtra.removeSync(nodePath.resolve(ecDir, 'index.blank.js'));
fsExtra.removeSync(nodePath.resolve(ecDir, 'index.common.js'));
Expand All @@ -104,66 +104,18 @@ const compileWorkList = [
fs.renameSync(nodePath.resolve(tmpDir, 'src/echarts.blank.js'), nodePath.resolve(ecDir, 'index.blank.js'));
fs.renameSync(nodePath.resolve(tmpDir, 'src/echarts.common.js'), nodePath.resolve(ecDir, 'index.common.js'));
fs.renameSync(nodePath.resolve(tmpDir, 'src/echarts.simple.js'), nodePath.resolve(ecDir, 'index.simple.js'));
fs.renameSync(nodePath.resolve(tmpDir, 'src'), nodePath.resolve(ecDir, 'esm'));
fs.renameSync(nodePath.resolve(tmpDir, 'src'), nodePath.resolve(ecDir, esmDir));

transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.js'), 'esm');
transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.blank.js'), 'esm');
transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.common.js'), 'esm');
transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.simple.js'), 'esm');
transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.js'), esmDir);
transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.blank.js'), esmDir);
transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.common.js'), esmDir);
transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.simple.js'), esmDir);

await transformDistributionFiles(nodePath.resolve(ecDir, 'esm'), 'esm');
await transformDistributionFiles(nodePath.resolve(ecDir, 'types'), 'esm');
await transformDistributionFiles(nodePath.resolve(ecDir, esmDir), esmDir);
await transformDistributionFiles(nodePath.resolve(ecDir, 'types'), esmDir);
fsExtra.removeSync(tmpDir);
}
},
{
logLabel: 'main ts -> js-cjs',
compilerOptionsOverride: {
module: 'CommonJS',
// `rootDir` Only use to control the output
// directory structure with --outDir.
rootDir: ecDir,
outDir: tmpDir
},
srcGlobby: mainSrcGlobby,
transformOptions: {
filesGlobby: {patterns: ['**/*.js'], cwd: tmpDir},
preamble: preamble.js,
transformDEV: true
},
before: async function () {
fsExtra.removeSync(tmpDir);
fsExtra.removeSync(nodePath.resolve(ecDir, 'lib'));
},
after: async function () {
fs.renameSync(nodePath.resolve(tmpDir, 'src'), nodePath.resolve(ecDir, 'lib'));
await transformDistributionFiles(nodePath.resolve(ecDir, 'lib'), 'lib');

removeESmoduleMark();

fsExtra.removeSync(tmpDir);
}
},
{
logLabel: 'extension ts -> js-cjs',
compilerOptionsOverride: {
module: 'CommonJS',
rootDir: extensionSrcDir,
outDir: extensionCJSDir
},
srcGlobby: extensionSrcGlobby,
transformOptions: {
filesGlobby: {patterns: ['**/*.js'], cwd: extensionCJSDir},
preamble: preamble.js,
transformDEV: true
},
before: async function () {
fsExtra.removeSync(extensionCJSDir);
},
after: async function () {
await transformDistributionFiles(extensionCJSDir, 'lib');
}
},
{
logLabel: 'extension ts -> js-esm',
compilerOptionsOverride: {
Expand All @@ -181,7 +133,7 @@ const compileWorkList = [
fsExtra.removeSync(extensionESMDir);
},
after: async function () {
await transformDistributionFiles(extensionESMDir, 'esm');
await transformDistributionFiles(extensionESMDir, 'lib');
}
}
];
Expand Down
2 changes: 1 addition & 1 deletion build/template/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
// import * as LineChart_1 './chart/line/install'; export {LineChart_1 as LineChart};
// Treeshaking in webpack will not work even if we configured sideEffects to false in package.json

export * from './esm/export/charts';
export * from './lib/export/charts';
2 changes: 1 addition & 1 deletion build/template/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from './esm/export/components';
export * from './lib/export/components';
2 changes: 1 addition & 1 deletion build/template/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from './esm/export/core';
export * from './lib/export/core';
2 changes: 1 addition & 1 deletion build/template/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from './esm/export/renderers';
export * from './lib/export/renderers';
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"canvas",
"svg"
],
"main": "lib/echarts.all.js",
"main": "dist/echarts.js",
"module": "index.js",
"jsdelivr": "dist/echarts.min.js",
"types": "index.d.ts",
Expand All @@ -32,8 +32,10 @@
"index.blank.js",
"index.common.js",
"index.simple.js",
"esm/chart/*.js",
"esm/components/*.js"
"lib/chart/*.js",
"lib/components/*.js",
"theme/*.js",
"i18n/*.js"
],
"scripts": {
"prepublish": "node build/build.js --prepublish",
Expand Down
7 changes: 5 additions & 2 deletions src/chart/treemap/TreemapSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
OptionName,
DecalObject,
SeriesLabelOption,
DefaultEmphasisFocus
DefaultEmphasisFocus,
AriaOptionMixin
} from '../../util/types';
import GlobalModel from '../../model/Global';
import { LayoutRect } from '../../util/layout';
Expand Down Expand Up @@ -535,7 +536,9 @@ function completeTreeValue(dataNode: TreemapSeriesNodeItemOption) {
*/
function setDefault(levels: TreemapSeriesLevelOption[], ecModel: GlobalModel) {
const globalColorList = normalizeToArray(ecModel.get('color')) as ColorString[];
const globalDecalList = normalizeToArray(ecModel.get(['aria', 'decal', 'decals'])) as DecalObject[];
const globalDecalList = normalizeToArray(
(ecModel as Model<AriaOptionMixin>).get(['aria', 'decal', 'decals'])
) as DecalObject[];

if (!globalColorList) {
return;
Expand Down
48 changes: 0 additions & 48 deletions src/component/aria/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,6 @@
import { EChartsExtensionInstallRegisters } from '../../extension';
import ariaVisual from '../../visual/aria';
import ariaPreprocessor from './preprocessor';
import { DecalObject } from '../../util/types';

export interface AriaLabelOption {
enabled?: boolean;
description?: string;
general?: {
withTitle?: string;
withoutTitle?: string;
};
series?: {
maxCount?: number;
single?: {
prefix?: string;
withName?: string;
withoutName?: string;
};
multiple?: {
prefix?: string;
withName?: string;
withoutName?: string;
separator?: {
middle?: string;
end?: string;
}
}
};
data?: {
maxCount?: number;
allData?: string;
partialData?: string;
withName?: string;
withoutName?: string;
separator?: {
middle?: string;
end?: string;
}
}
}

// Extending is for compating ECharts 4
export interface AriaOption extends AriaLabelOption {
enabled?: boolean;
label?: AriaLabelOption;
decal?: {
show?: boolean;
decals?: DecalObject | DecalObject[];
};
}

export function install(registers: EChartsExtensionInstallRegisters) {
registers.registerPreprocessor(ariaPreprocessor);
Expand Down
3 changes: 1 addition & 2 deletions src/export/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ import type {ThemeRiverSeriesOption as ThemeRiverSeriesOptionInner} from '../cha
import type {SunburstSeriesOption as SunburstSeriesOptionInner} from '../chart/sunburst/SunburstSeries';
import type {CustomSeriesOption as CustomSeriesOptionInner} from '../chart/custom/install';
import type { GraphicComponentLooseOption as GraphicComponentOption } from '../component/graphic/install';
import type { AriaOption as AriaComponentOption } from '../component/aria/install';
import type { DatasetOption as DatasetComponentOption } from '../component/dataset/install';

import type {ToolboxBrushFeatureOption} from '../component/toolbox/feature/Brush';
Expand All @@ -91,7 +90,7 @@ import type {ToolboxSaveAsImageFeatureOption} from '../component/toolbox/feature
import type {ToolboxFeatureOption} from '../component/toolbox/featureManager';


import type { ECBasicOption, SeriesTooltipOption } from '../util/types';
import type { ECBasicOption, SeriesTooltipOption, AriaOption as AriaComponentOption } from '../util/types';

interface ToolboxComponentOption extends ToolboxOption {
feature?: {
Expand Down
48 changes: 47 additions & 1 deletion src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { PathStyleProps } from 'zrender/src/graphic/Path';
import { ImageStyleProps } from 'zrender/src/graphic/Image';
import ZRText, { TextStyleProps } from 'zrender/src/graphic/Text';
import { Source } from '../data/Source';
import { AriaOption } from './../component/aria/install';



Expand Down Expand Up @@ -719,6 +718,53 @@ export interface ColorPaletteOptionMixin {
colorLayer?: ZRColor[][]
}

export interface AriaLabelOption {
enabled?: boolean;
description?: string;
general?: {
withTitle?: string;
withoutTitle?: string;
};
series?: {
maxCount?: number;
single?: {
prefix?: string;
withName?: string;
withoutName?: string;
};
multiple?: {
prefix?: string;
withName?: string;
withoutName?: string;
separator?: {
middle?: string;
end?: string;
}
}
};
data?: {
maxCount?: number;
allData?: string;
partialData?: string;
withName?: string;
withoutName?: string;
separator?: {
middle?: string;
end?: string;
}
}
}

// Extending is for compating ECharts 4
export interface AriaOption extends AriaLabelOption {
enabled?: boolean;
label?: AriaLabelOption;
decal?: {
show?: boolean;
decals?: DecalObject | DecalObject[];
};
}

export interface AriaOptionMixin {
aria?: AriaOption
}
Expand Down
3 changes: 1 addition & 2 deletions src/visual/aria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ import GlobalModel from '../model/Global';
import Model from '../model/Model';
import SeriesModel from '../model/Series';
import {makeInner} from '../util/model';
import {Dictionary, DecalObject, InnerDecalObject} from '../util/types';
import {Dictionary, DecalObject, InnerDecalObject, AriaOption} from '../util/types';
import {LocaleOption} from '../locale';
import { getDecalFromPalette } from '../model/mixin/palette';
import type {AriaOption} from '../component/aria/install';
import type {TitleOption} from '../component/title/install';

const DEFAULT_OPTION: AriaOption = {
Expand Down

0 comments on commit 273d963

Please sign in to comment.