提交 fc225d2f 编写于 作者: S sushuang

Back compat.

上级 7f1392ca
此差异已折叠。
const assert = require('assert');
function plugin({types, template}, options) {
return {
visitor: {
IfStatement: {
exit(path) {
removeDEV(path);
}
}
}
};
}
plugin.recheckDEV = function (code) {
const index = code.indexOf('__DEV__');
assert(index < 0, `Still has __DEV__, position: ${index}`);
};
module.exports = plugin;
function removeDEV(path) {
if (path.node.test.name === '__DEV__') {
path.remove();
}
}
......@@ -7,6 +7,7 @@ const config = require('./config.js');
const commander = require('commander');
const {build, watch, color} = require('./helper');
const ecLangPlugin = require('./rollup-plugin-ec-lang');
const prePublish = require('./pre-publish');
function run() {
......@@ -141,10 +142,7 @@ function run() {
build(configs).then(function () {
checkCode(configForCheck);
// Compatible with prevoius folder structure: `echarts/lib` exists in `node_modules`
// npm run prepublish: `rm -r lib; cp -r src lib`
fsExtra.removeSync(getPath('./lib'));
fsExtra.copySync(getPath('./src'), getPath('./lib'));
prePublish();
});
}
else {
......
......@@ -62,6 +62,7 @@ function getPlugins(min, lang, addBundleVersion) {
*/
exports.createECharts = function (opt) {
opt = opt || {};
let srcType = opt.type ? '.' + opt.type : '.all';
let postfixType = opt.type ? '.' + opt.type : '';
let postfixMin = opt.min ? '.min' : '';
let postfixLang = opt.lang ? '-' + opt.lang.toLowerCase() : '';
......@@ -78,10 +79,10 @@ exports.createECharts = function (opt) {
output = resolve(output);
}
else {
input = getPathBasedOnECharts(`./index${postfixType}.js`);
input = getPathBasedOnECharts(`./echarts${srcType}.js`);
output = getPathBasedOnECharts(`dist/echarts${postfixLang}${postfixType}${postfixMin}.js`);
if (sourcemap == null) {
sourcemap = !opt.min && !postfixType;
sourcemap = !opt.min && !opt.type;
}
}
......@@ -99,7 +100,7 @@ exports.createECharts = function (opt) {
watch: {
include: [
getPathBasedOnECharts('./src/**'),
getPathBasedOnECharts('./index*.js'),
getPathBasedOnECharts('./echarts*.js'),
getPathBasedOnECharts('../zrender/src/**')
]
}
......
let path = require('path');
let babel = require('@babel/core');
let fs = require('fs');
let transformPluginPath = path.resolve(__dirname, './babel-plugin-transform-modules-commonjs-ec');
// let transformPluginPath = '@babel/plugin-transform-modules-commonjs';
// let fileName = path.resolve(__dirname, '../src/ExtensionAPI.js');
// let fileName = path.resolve(__dirname, '../src/util/graphic.js');
// let fileName = path.resolve(__dirname, '../index.blank.js');
// let fileName = path.resolve(__dirname, '../src/chart/bar/BarSeries.js');
// let fileName = path.resolve(__dirname, '../test/esm2cjs/a.js');
let fileName = path.resolve(__dirname, '../test/esm2cjs/a.js');
let result = babel.transformFileSync(fileName, {
plugins: [
[transformPluginPath, {
// strict: true
loose: true
}]
]
});
let outputFile = path.resolve(__dirname, '../../tmp/babel.output.js');
// console.log(outputFile);
fs.writeFileSync(outputFile, result.code, {encoding:'utf-8'});
/**
* Compatible with prevoius folder structure: `echarts/lib` exists in `node_modules`
* (1) Build all files to CommonJS to `echarts/lib`.
* (2) Remove __DEV__.
* (3) Mount `echarts/src/export` to `echarts/lib/echarts`.
*/
const {resolve, join} = require('path');
const fsExtra = require('fs-extra');
const fs = require('fs');
const babel = require('@babel/core');
const esm2cjsPlugin = require('./babel-plugin-transform-modules-commonjs-ec');
const removeDEVPlugin = require('./babel-plugin-transform-remove-dev');
const {color} = require('./helper');
const ecDir = resolve(__dirname, '..');
const srcDir = resolve(__dirname, '../src');
const libDir = resolve(__dirname, '../lib');
const REG_SRC = /^[^.].*[.]js$/;
const REG_DIR = /^[^.].*$/;
module.exports = function () {
fsExtra.removeSync(libDir);
fsExtra.ensureDirSync(libDir);
// fsExtra.copySync(getPath('./src'), getPath('./lib'));
travelSrcDir('.', ({fileName, basePath, absolutePath, outputPath}) => {
outputPath = resolve(ecDir, 'lib', basePath, fileName);
transform(absolutePath, outputPath);
});
transform(resolve(ecDir, 'echarts.all.js'), resolve(ecDir, 'index.js'));
transform(resolve(ecDir, 'echarts.common.js'), resolve(ecDir, 'index.common.js'));
transform(resolve(ecDir, 'echarts.simple.js'), resolve(ecDir, 'index.simple.js'));
function transform(inputPath, outputPath) {
console.log(
color('fgGreen', 'dim')('[transform] '),
color('fgGreen')(inputPath),
color('fgGreen', 'dim')('...')
);
let {code} = babel.transformFileSync(inputPath, {
plugins: [removeDEVPlugin, esm2cjsPlugin]
});
if (inputPath !== resolve(ecDir, 'src/config.js')) {
removeDEVPlugin.recheckDEV(code);
}
if (inputPath === resolve(ecDir, 'src/echarts.js')) {
// Using `echarts/echarts.blank.js` to overwrite `echarts/lib/echarts.js`
// for including exports API.
code +=
`var ___export = require("./export");
(function () {
for (var key in ___export) {
if (!_export.hasOwnProperty(key) || key === 'default' || key === '__esModule') return;
exports[key] = ___export[key];
}
})();`;
}
fs.writeFileSync(outputPath, code, {encoding:'utf-8'});
}
console.log(color('fgGreen', 'bright')('All done.'));
};
function travelSrcDir(basePath, cb) {
const absolutePath = resolve(srcDir, basePath);
fs.readdirSync(absolutePath).forEach(fileName => {
const childAbsolutePath = resolve(absolutePath, fileName);
const stat = fs.statSync(childAbsolutePath);
if (stat.isDirectory()) {
if (REG_DIR.test(fileName)) {
travelSrcDir(join(basePath, fileName), cb);
}
}
else if (stat.isFile()) {
if (REG_SRC.test(fileName)) {
cb({fileName, basePath: basePath, absolutePath: childAbsolutePath});
}
}
});
}
export * from './src/echarts';
export * from './src/export';
import * as dataTool from './extension/dataTool/index';
export {dataTool};
// Import all charts and components
import './src/chart/line';
import './src/chart/bar';
import './src/chart/pie';
import './src/chart/scatter';
import './src/chart/radar';
import './src/chart/map';
import './src/chart/tree';
import './src/chart/treemap';
import './src/chart/graph';
import './src/chart/gauge';
import './src/chart/funnel';
import './src/chart/parallel';
import './src/chart/sankey';
import './src/chart/boxplot';
import './src/chart/candlestick';
import './src/chart/effectScatter';
import './src/chart/lines';
import './src/chart/heatmap';
import './src/chart/pictorialBar';
import './src/chart/themeRiver';
import './src/chart/custom';
import './src/component/graphic';
import './src/component/grid';
import './src/component/legendScroll';
import './src/component/tooltip';
import './src/component/axisPointer';
import './src/component/polar';
import './src/component/geo';
import './src/component/parallel';
import './src/component/singleAxis';
import './src/component/brush';
import './src/component/calendar';
import './src/component/title';
import './src/component/dataZoom';
import './src/component/visualMap';
import './src/component/markPoint';
import './src/component/markLine';
import './src/component/markArea';
import './src/component/timeline';
import './src/component/toolbox';
import 'zrender/src/vml/vml';
import 'zrender/src/svg/svg';
export * from './src/echarts';
export * from './src/export';
export * from './src/echarts';
export * from './src/export';
import './src/chart/line';
import './src/chart/bar';
import './src/chart/pie';
import './src/chart/scatter';
import './src/component/graphic';
import './src/component/tooltip';
import './src/component/axisPointer';
import './src/component/legendScroll';
import './src/component/grid';
import './src/component/title';
import './src/component/markPoint';
import './src/component/markLine';
import './src/component/markArea';
import './src/component/dataZoom';
import './src/component/toolbox';
import 'zrender/src/vml/vml';
import 'zrender/src/svg/svg';
\ No newline at end of file
export * from './src/echarts';
import './src/chart/line';
import './src/chart/bar';
import './src/chart/pie';
import './src/component/gridSimple';
\ No newline at end of file
{
"bitwise": false,
"camelcase": true,
"curly": true,
"eqeqeq": false,
"forin": false,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": false,
"noempty": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"regexp": false,
"undef": true,
"unused": "vars",
"strict": false,
"trailing": false,
"maxparams": 20,
"maxdepth": 6,
"maxlen": 200,
"asi": false,
"boss": false,
"debug": false,
"eqnull": true,
"esversion": 6,
"module": true,
"evil": true,
"expr": true,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": false,
"multistr": false,
"onecase": false,
"proto": false,
"regexdash": false,
"scripturl": false,
"smarttabs": false,
"shadow": true,
"sub": true,
"supernew": false,
"validthis": true,
"browser": true,
"couch": false,
"devel": true,
"dojo": false,
"jquery": true,
"mootools": false,
"node": false,
"nonstandard": false,
"prototypejs": false,
"rhino": false,
"wsh": false,
"nomen": false,
"onevar": false,
"passfail": false,
"white": false,
"predef": [
"__dirname",
"require"
]
}
\ No newline at end of file
{
"bitwise": false,
"camelcase": true,
"curly": true,
"eqeqeq": false,
"forin": false,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": false,
"noempty": true,
"nonew": true,
"plusplus": false,
"quotmark": false,
"regexp": false,
"undef": true,
"unused": "vars",
"strict": false,
"trailing": false,
"maxparams": 20,
"maxdepth": 6,
"maxlen": 200,
"asi": false,
"boss": false,
"debug": false,
"eqnull": true,
"esversion": 3,
"evil": true,
"expr": true,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": false,
"multistr": false,
"onecase": false,
"proto": false,
"regexdash": false,
"scripturl": false,
"smarttabs": false,
"shadow": true,
"sub": true,
"supernew": false,
"validthis": true,
"browser": true,
"couch": false,
"devel": true,
"dojo": false,
"jquery": true,
"mootools": false,
"node": false,
"nonstandard": false,
"prototypejs": false,
"rhino": false,
"wsh": false,
"nomen": false,
"onevar": false,
"passfail": false,
"white": false,
"predef": [
"require",
"exports",
"module"
]
}
\ No newline at end of file
var util = require("./a/b/util");
var zrUtil = require("zrender/core/util");
var someInZrUtil1Alias = zrUtil.someInZrUtil1;
var zz = zrUtil.zz;
exports.zrUtil = zrUtil;
var _color = require("zrender/core/color");
var color2Alias = _color.color2;
var color = _color.color;
var color3 = _color.color3;
var color4 = _color.color4;
exports.color2Alias = _color.color2;
exports.color = _color.color;
var Some = require("some");
exports.Some = Some;
var Some2 = require("some2");
var _util3 = require("zrender/lib/core/util");
exports.someInZrUtil2 = _util3.someInZrUtil2;
var _echarts = require("./echarts");
(function () {
for (var key in _echarts) {
if (_echarts == null || !_echarts.hasOwnProperty(key) || key === 'default' || key === '__esModule') return;
exports[key] = _echarts[key];
}
})();
var _yy = require("./xx/yy");
exports.defaultAsBB = _yy;
exports.exportSingle = _yy.exportSingle;
require("ssssss");
var propInZrUtil = zrUtil.some;
someInZrUtil1Alias();
zz();
var color4Renamed = color4;
function exportSingleFn() {}
var b = util.b;
var c = Some;
c(b);
color2Alias();
color3();
var ss = new Some2();
ss();
var pureLocalVar = 'pure'; // jshint ignore:line
function b() {
a++;
innerSingleVarRenamed = innerSingleVar;
}
var exportSingleVar = 'aa';
var innerSingleVar = 'cc';
var innerSingleVarRenamed;
exports.propInZrUtil = propInZrUtil;
exports.color4Renamed = color4Renamed;
exports.exportSingleFn = exportSingleFn;
exports.exportSingleVar = exportSingleVar;
exports.innerSingleVarAlias = innerSingleVar;
exports.innerSingleVarAlias2 = innerSingleVar;
exports.innerSingleVarRenamed = innerSingleVarRenamed;
\ No newline at end of file
var zrUtil = require("zrender/core/util");
function _default() {
zrUtil();
}
module.exports = _default;
\ No newline at end of file
var zrUtil = require("zrender/core/util");
function bb() {
zrUtil();
}
var _default = bb;
module.exports = _default;
\ No newline at end of file
var xx = require("zrender/core/util");
// export * from './echarts';
// export {default as defaultAsBB} from './xx/yy';
// export {exportSingle} from './xx/yy';
var _default = xx;
module.exports = _default;
\ No newline at end of file
var zrUtil = require("zrender/core/util");
var Chart = zrUtil.extend({
zrUtil: zrUtil
});
var _default = Chart;
module.exports = _default;
\ No newline at end of file
import * as util from './a/b/util';
export var exportSingleVar = 'aa';
var b = util;
export { b };
function SomeDefault() {}
export default SomeDefault;
\ No newline at end of file
import * as util from './a/b/util';
import * as zrUtil from 'zrender/core/util';
import {someInZrUtil1 as someInZrUtil1Alias, zz} from 'zrender/core/util';
import {color2 as color2Alias, color, color3, color4} from 'zrender/core/color';
import Some from 'some';
import Some2 from 'some2';
export {someInZrUtil2} from 'zrender/src/core/util';
export * from './echarts';
export {default as defaultAsBB} from './xx/yy';
export {exportSingle} from './xx/yy';
export {zrUtil};
var propInZrUtil = zrUtil.some;
export {propInZrUtil};
export {color};
export {Some};
export {color2Alias};
import 'ssssss';
someInZrUtil1Alias();
zz();
var color4Renamed = color4;
export {color4Renamed};
export function exportSingleFn() {
}
var b = util.b;
var c = Some;
c(b);
if (__DEV__) {
console.log('asdfasdf', Some);
assert(b, 'asdfasd');
}
color2Alias();
color3();
var ss = new Some2();
ss();
var pureLocalVar = 'pure'; // jshint ignore:line
function b() {
a++;
innerSingleVarRenamed = innerSingleVar;
if (__DEV__ ) {
console.log('zvcx');
alert('v44');
}
}
export var exportSingleVar = 'aa';
var innerSingleVar = 'cc';
var innerSingleVarRenamed
export {innerSingleVar as innerSingleVarAlias, innerSingleVarRenamed};
export {innerSingleVar as innerSingleVarAlias2};
import * as zrUtil from 'zrender/core/util';
export default function () {
zrUtil();
}
import * as zrUtil from 'zrender/core/util';
function bb() {
zrUtil();
}
export default bb;
\ No newline at end of file
import xx from 'zrender/core/util';
// export * from './echarts';
// export {default as defaultAsBB} from './xx/yy';
// export {exportSingle} from './xx/yy';
export default xx;
import * as zrUtil from 'zrender/core/util';
var Chart = zrUtil.extend({
zrUtil: zrUtil
});
export default Chart;
\ No newline at end of file
import * as util from './a/b/util';
export var exportSingleVar = 'aa';
var b = util;
export {b};
function SomeDefault() {
}
export default SomeDefault;
var a = 112;
a++;
a++;
a++;
a--;
function b() {
a++;
}
a += 12;
\ No newline at end of file
var a = 112;
if (__DEV__ ) {
alert('vzxczxcvzx');
console.log('zxcvzxvvx');
}
a++;
a++;
a++;
if (__DEV__ ) {
alert('v2332x');
console.log('v23232x');
}
a--;
function b() {
a++;
if (__DEV__ ) {
console.log('211');
alert('12');
}
}
a+=12;
\ No newline at end of file
const prePublish = require('../../build/pre-publish');
prePublish();
const path = require('path');
const babel = require('@babel/core');
const fs = require('fs');
// See require('@babel/plugin-transform-modules-commonjs')
const esm2cjsPlugin = path.resolve(__dirname, '../../build/babel-plugin-transform-modules-commonjs-ec');
const removeDEVPlugin = path.resolve(__dirname, '../../build/babel-plugin-transform-remove-dev');
function run() {
removeDEV();
esm2cjs();
}
function removeDEV() {
const suite = makeSuite('removeDEV');
suite.eachSrcFile(({fileName, filePath}) => {
let result = babel.transformFileSync(filePath, {
plugins: [removeDEVPlugin]
});
suite.writeToExpectFile(fileName, result.code);
console.log(`removing dev ${fileName} ...`);
});
console.log('All done.');
}
function esm2cjs() {
const suite = makeSuite('esm2cjs');
suite.eachSrcFile(({fileName, filePath}) => {
console.log(`transforming to cjs ${fileName} ...`);
if (/^forbiden/.test(fileName)) {
try {
transformSingle();
throw new Error('Should fail.');
}
catch (e) {
console.log(`${fileName} failed as expected.`);
}
}
else {
transformSingle();
}
function transformSingle() {
let result = babel.transformFileSync(filePath, {
plugins: [removeDEVPlugin, esm2cjsPlugin]
});
suite.writeToExpectFile(fileName, result.code);
}
});
console.log('All done.');
}
const makeSuite = suiteName => {
const srcDir = path.resolve(__dirname, `./${suiteName}/src`);
const expectDir = path.resolve(__dirname, `./${suiteName}/expect`);
return {
srcDir,
expectDir,
eachSrcFile(cb) {
fs.readdirSync(srcDir).forEach(fileName => {
if (!/^[^.].*[.]src[.]js$/.test(fileName)) {
return;
}
const filePath = path.resolve(srcDir, fileName);
cb({fileName, filePath, suiteName, srcDir, expectDir});
});
},
writeToExpectFile(srcFileName, content) {
let outputPath = path.resolve(expectDir, srcFileName.replace('.src.', '.expect.'));
fs.writeFileSync(outputPath, content, {encoding:'utf-8'});
}
};
};
run();
\ No newline at end of file
......@@ -17,7 +17,7 @@
</style>
<div id="main"></div>
<script>
var chart;
require([
'echarts'
// 'echarts/chart/pie',
......@@ -27,7 +27,7 @@
// 'echarts/component/toolbox'
], function (echarts) {
var chart = echarts.init(document.getElementById('main'));
chart = echarts.init(document.getElementById('main'));
// Pencil sketch texture
var patternSrc = window.pieTexture;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册