You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/02/17 12:29:30 UTC

[incubator-echarts] branch typescript updated: ts: fix zrender symlink can't be resolved bug in rollup-plugin-typescript2. add build progress

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch typescript
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git


The following commit(s) were added to refs/heads/typescript by this push:
     new fc7022c  ts: fix zrender symlink can't be resolved bug in rollup-plugin-typescript2. add build progress
fc7022c is described below

commit fc7022c474c78244e9b69949c55bd73ff6798612
Author: pissang <bm...@gmail.com>
AuthorDate: Mon Feb 17 20:28:52 2020 +0800

    ts: fix zrender symlink can't be resolved bug in rollup-plugin-typescript2. add build progress
---
 build/build.js        |  22 +++---
 build/config.js       |  32 +++++----
 build/mangleString.js | 184 --------------------------------------------------
 build/optimize.js     |  59 ----------------
 package-lock.json     |  31 +++++++++
 package.json          |   1 +
 tsconfig.json         |   4 +-
 7 files changed, 68 insertions(+), 265 deletions(-)

diff --git a/build/build.js b/build/build.js
index 12f3f82..c270406 100755
--- a/build/build.js
+++ b/build/build.js
@@ -119,6 +119,10 @@ async function run() {
             '-o, --output <output file path>',
             'If output file path is specified, input file path must be specified too.'
         )
+        // .option(
+        //     '--zrender <zrender>',
+        //     'Local zrender path. Used when you want to use develop version of zrender instead of npm version.'
+        // )
         .parse(process.argv);
 
     let isWatch = !!commander.watch;
@@ -264,7 +268,7 @@ function getPath(relativePath) {
  */
 async function build(configs) {
 
-    ensureZRenderCode.prepare();
+    // ensureZRenderCode.prepare();
 
     for (let singleConfig of configs) {
         console.log(
@@ -288,7 +292,7 @@ async function build(configs) {
         );
     }
 
-    ensureZRenderCode.clear();
+    // ensureZRenderCode.clear();
 }
 
 /**
@@ -327,12 +331,12 @@ function watch(singleConfig) {
         if (event.code === 'BUNDLE_END') {
             printWatchResult(event);
         }
-        if (event.code === 'START') {
-            ensureZRenderCode.prepare();
-        }
-        if (event.code === 'END' || event.code === 'ERROR' || event.code === 'FATAL') {
-            ensureZRenderCode.clear();
-        }
+        // if (event.code === 'START') {
+        //     ensureZRenderCode.prepare();
+        // }
+        // if (event.code === 'END' || event.code === 'ERROR' || event.code === 'FATAL') {
+        //     ensureZRenderCode.clear();
+        // }
     });
 }
 
@@ -470,7 +474,7 @@ async function main() {
         }
         // console.log(err);
 
-        ensureZRenderCode.clear();
+        // ensureZRenderCode.clear();
     }
 }
 
diff --git a/build/config.js b/build/config.js
index 8cd69bd..8c48351 100644
--- a/build/config.js
+++ b/build/config.js
@@ -18,7 +18,7 @@
 */
 
 const assert = require('assert');
-// const nodeResolvePlugin = require('rollup-plugin-node-resolve');
+const nodeResolvePlugin = require('rollup-plugin-node-resolve');
 const uglifyPlugin = require('rollup-plugin-uglify');
 const ecRemoveDevPlugin = require('./remove-dev-rollup-plugin');
 const ecLangPlugin = require('./ec-lang-rollup-plugin');
@@ -26,11 +26,19 @@ const nodePath = require('path');
 const preamble = require('./preamble');
 const ecDir = nodePath.resolve(__dirname, '..');
 const typescriptPlugin = require('rollup-plugin-typescript2');
+const progress = require('rollup-plugin-progress');
+const fs = require('fs');
 
 function preparePlugins({min, lang, sourcemap, removeDev, addBundleVersion}, {include, exclude}) {
     assert(include);
+    // In case node_modules/zrender is a symlink
+    const zrNodeModulePath = nodePath.resolve(ecDir, 'node_modules/zrender');
+    const zrRealPath = fs.realpathSync(zrNodeModulePath);
+    if (zrRealPath !== zrNodeModulePath) {
+        include.push(zrRealPath + '/**/*.ts');
+    }
+
     let plugins = [
-        // nodeResolvePlugin(),
         typescriptPlugin({
             tsconfig: nodePath.resolve(ecDir, 'tsconfig.json'),
             tsconfigOverride: {
@@ -42,11 +50,15 @@ function preparePlugins({min, lang, sourcemap, removeDev, addBundleVersion}, {in
                     sourceMap: !!sourcemap,
                     // Use the esm d.ts
                     declaration: false
-                },
-                include: include,
-                exclude: exclude || []
-            }
-        })
+                }
+                // include: include,
+                // exclude: exclude || []
+            },
+            include: include,
+            exclude: exclude || []
+        }),
+        nodeResolvePlugin(),
+        progress()
     ];
 
     removeDev && plugins.push(
@@ -57,10 +69,6 @@ function preparePlugins({min, lang, sourcemap, removeDev, addBundleVersion}, {in
         ecLangPlugin({lang})
     );
 
-    // plugins.push(
-    //     nodeResolvePlugin()
-    // );
-
     addBundleVersion && plugins.push({
         outro: function () {
             return 'exports.bundleVersion = \'' + (+new Date()) + '\';';
@@ -123,7 +131,7 @@ exports.createECharts = function (opt = {}) {
         plugins: preparePlugins(opt, {
             include: [
                 nodePath.resolve(ecDir, 'src/**/*.ts'),
-                nodePath.resolve(ecDir, 'echarts*.ts'),
+                nodePath.resolve(ecDir, 'echarts*.ts')
                 // nodePath.resolve(ecDir, '/Users/s/sushuangwork/met/act/tigall/echarts/zrender/src/**/*.ts')
                 // nodePath.resolve(ecDir, '../zrender/src/**/*.ts')
             ]
diff --git a/build/mangleString.js b/build/mangleString.js
deleted file mode 100644
index 48f8aad..0000000
--- a/build/mangleString.js
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
-* 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.
-*/
-
-var esprima = require('esprima');
-var escodegen = require('escodegen');
-var estraverse = require('estraverse');
-
-var SYNTAX = estraverse.Syntax;
-
-var STR_MIN_LENGTH = 5;
-var STR_MIN_DIST = 1000;
-var STR_MIN_COUNT = 2;
-
-function createDeclaration(declarations) {
-    return {
-        type: SYNTAX.VariableDeclaration,
-        declarations: declarations,
-        kind: 'var'
-    };
-}
-
-function createDeclarator(id, init) {
-    return {
-        type: SYNTAX.VariableDeclarator,
-        id: {
-            type: SYNTAX.Identifier,
-            name: id
-        },
-        init: {
-            type: SYNTAX.Literal,
-            value: init
-        }
-    };
-}
-
-function base54Digits() {
-    return 'etnrisouaflchpdvmgybwESxTNCkLAOM_DPHBjFIqRUzWXV$JKQGYZ0516372984';
-}
-
-var base54 = (function(){
-    var DIGITS = base54Digits();
-    return function(num) {
-        var ret = '';
-        var base = 54;
-        do {
-            ret += DIGITS.charAt(num % base);
-            num = Math.floor(num / base);
-            base = 64;
-        } while (num > 0);
-        return ret;
-    };
-})();
-
-function mangleString(source) {
-
-    var ast = esprima.parse(source, {
-        loc: true
-    });
-
-    var stringVariables = {};
-
-    var stringRelaceCount = 0;
-
-    estraverse.traverse(ast, {
-        enter: function (node, parent) {
-            if (node.type === SYNTAX.Literal
-                && typeof node.value === 'string'
-            ) {
-                // Ignore if string is the key of property
-                if (parent.type === SYNTAX.Property) {
-                    return;
-                }
-                var value = node.value;
-                if (value.length > STR_MIN_LENGTH) {
-                    if (!stringVariables[value]) {
-                        stringVariables[value] = {
-                            count: 0,
-                            lastLoc: node.loc.start.line,
-                            name: '__echartsString__' + base54(stringRelaceCount++)
-                        };
-                    }
-                    var diff = node.loc.start.line - stringVariables[value].lastLoc;
-                    // GZIP ?
-                    if (diff >= STR_MIN_DIST) {
-                        stringVariables[value].lastLoc = node.loc.start.line;
-                        stringVariables[value].count++;
-                    }
-                }
-            }
-
-            if (node.type === SYNTAX.MemberExpression && !node.computed) {
-                if (node.property.type === SYNTAX.Identifier) {
-                    var value = node.property.name;
-                    if (value.length > STR_MIN_LENGTH) {
-                        if (!stringVariables[value]) {
-                            stringVariables[value] = {
-                                count: 0,
-                                lastLoc: node.loc.start.line,
-                                name: '__echartsString__' + base54(stringRelaceCount++)
-                            };
-                        }
-                        var diff = node.loc.start.line - stringVariables[value].lastLoc;
-                        if (diff >= STR_MIN_DIST) {
-                            stringVariables[value].lastLoc = node.loc.start.line;
-                            stringVariables[value].count++;
-                        }
-                    }
-                }
-            }
-        }
-    });
-
-    estraverse.replace(ast, {
-        enter: function (node, parent) {
-            if ((node.type === SYNTAX.Literal
-                && typeof node.value === 'string')
-            ) {
-                // Ignore if string is the key of property
-                if (parent.type === SYNTAX.Property) {
-                    return;
-                }
-                var str = node.value;
-                if (stringVariables[str] && stringVariables[str].count > STR_MIN_COUNT) {
-                    return {
-                        type: SYNTAX.Identifier,
-                        name: stringVariables[str].name
-                    };
-                }
-            }
-            if (node.type === SYNTAX.MemberExpression && !node.computed) {
-                if (node.property.type === SYNTAX.Identifier) {
-                    var str = node.property.name;
-                    if (stringVariables[str] && stringVariables[str].count > STR_MIN_COUNT) {
-                        return {
-                            type: SYNTAX.MemberExpression,
-                            object: node.object,
-                            property: {
-                                type: SYNTAX.Identifier,
-                                name: stringVariables[str].name
-                            },
-                            computed: true
-                        };
-                    }
-                }
-            }
-        }
-    });
-
-    // Add variables in the top
-    for (var str in stringVariables) {
-        // Used more than once
-        if (stringVariables[str].count > STR_MIN_COUNT) {
-            ast.body.unshift(createDeclaration([
-                createDeclarator(stringVariables[str].name, str)
-            ]));
-        }
-    }
-
-    return escodegen.generate(
-        ast,
-        {
-            format: {escapeless: true},
-            comment: true
-        }
-    );
-}
-
-exports = module.exports = mangleString;
\ No newline at end of file
diff --git a/build/optimize.js b/build/optimize.js
deleted file mode 100644
index c97578a..0000000
--- a/build/optimize.js
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
-* 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.
-*/
-
-var UglifyJS = require('uglify-js');
-var fs = require('fs');
-var etpl = require('etpl');
-var argv = require('optimist').argv;
-
-etpl.config({
-    commandOpen: '/**',
-    commandClose: '*/'
-});
-
-var mode = argv.m || 'all';
-var configPath = mode === 'all' ? 'config/echarts.js' : 'config/echarts.' + mode + '.js';
-var outPath = mode === 'all' ? '../dist/echarts.js' : '../dist/echarts.' + mode + '.js';
-
-var config = eval('(' + fs.readFileSync(configPath, 'utf-8') + ')');
-var mainCode = fs.readFileSync(outPath, 'utf-8');
-var startCode = fs.readFileSync('wrap/start.js', 'utf-8');
-var nutCode = fs.readFileSync('wrap/nut.js', 'utf-8');
-var endCode = fs.readFileSync('wrap/end.js', 'utf-8');
-
-endCode = etpl.compile(endCode)({
-    parts: config.include
-});
-
-// FIXME
-var sourceCode = [startCode, nutCode, require('./mangleString')(mainCode), endCode].join('\n');
-
-var ast = UglifyJS.parse(sourceCode);
-/* jshint camelcase: false */
-// compressor needs figure_out_scope too
-ast.figure_out_scope();
-ast = ast.transform(UglifyJS.Compressor( {} ));
-
-// need to figure out scope again so mangler works optimally
-ast.figure_out_scope();
-ast.compute_char_frequency();
-ast.mangle_names();
-
-fs.writeFileSync(outPath, [startCode, nutCode, mainCode, endCode].join('\n'), 'utf-8');
-fs.writeFileSync(outPath.replace('.js', '.min.js'), ast.print_to_string(), 'utf-8');
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 57c236e..fb9a8ab 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6985,6 +6985,37 @@
         "resolve": "^1.1.6"
       }
     },
+    "rollup-plugin-progress": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/rollup-plugin-progress/-/rollup-plugin-progress-1.1.1.tgz",
+      "integrity": "sha512-RIs2bnk/O2fylGN0F2w38U4PhAGIt8/N2noZ3i2tDOF0qg0PPZLKMMFp24MQUyND/w9nu61DRSanwpXOoJhxIA==",
+      "dev": true,
+      "requires": {
+        "chalk": "^2.4.2"
+      },
+      "dependencies": {
+        "chalk": {
+          "version": "2.4.2",
+          "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
+          "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
+          "dev": true,
+          "requires": {
+            "ansi-styles": "^3.2.1",
+            "escape-string-regexp": "^1.0.5",
+            "supports-color": "^5.3.0"
+          }
+        },
+        "supports-color": {
+          "version": "5.5.0",
+          "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
+          "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
+          "dev": true,
+          "requires": {
+            "has-flag": "^3.0.0"
+          }
+        }
+      }
+    },
     "rollup-plugin-typescript2": {
       "version": "0.25.3",
       "resolved": "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.25.3.tgz",
diff --git a/package.json b/package.json
index 10ccec3..ee1a7dd 100644
--- a/package.json
+++ b/package.json
@@ -59,6 +59,7 @@
     "rollup": "1.28.0",
     "rollup-plugin-commonjs": "8.4.1",
     "rollup-plugin-node-resolve": "3.0.0",
+    "rollup-plugin-progress": "^1.1.1",
     "rollup-plugin-typescript2": "0.25.3",
     "rollup-plugin-uglify": "6.0.4",
     "seedrandom": "3.0.3",
diff --git a/tsconfig.json b/tsconfig.json
index 0140bdb..5457b91 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -14,7 +14,9 @@
         "declaration": true,
         "declarationMap": false,
 
-        "importHelpers": true
+        "importHelpers": true,
+
+        "pretty": true
     },
     "include": [
         "src/**/*.ts",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org