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/07/27 12:28:29 UTC

[incubator-echarts] 01/01: chore: fix prepublish to generate lib and esm

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

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

commit 0f8fa84ddab2e951e850d6be61afc2183fb0f4b0
Author: pissang <bm...@gmail.com>
AuthorDate: Mon Jul 27 20:27:57 2020 +0800

    chore: fix prepublish to generate lib and esm
---
 .gitignore           |  4 ++-
 build/build.js       | 85 +---------------------------------------------------
 build/pre-publish.js | 42 +++++---------------------
 package.json         |  6 +---
 4 files changed, 13 insertions(+), 124 deletions(-)

diff --git a/.gitignore b/.gitignore
index 320e95b..779d723 100644
--- a/.gitignore
+++ b/.gitignore
@@ -187,4 +187,6 @@ todo
 /index.js
 /index.simple.js
 /index.common.js
-/index.blank.js
\ No newline at end of file
+/index.blank.js
+/extension-esm
+/extension
\ No newline at end of file
diff --git a/build/build.js b/build/build.js
index f88d256..75254f2 100755
--- a/build/build.js
+++ b/build/build.js
@@ -92,7 +92,7 @@ async function run() {
         )
         .option(
             '--removedev',
-            'Remove __DEV__ code. If --min, __DEV__ always be removed.'
+            'Transform __DEV__ code into process.env="production".'
         )
         .option(
             '--min',
@@ -123,10 +123,6 @@ async function run() {
             '--clean',
             'If cleaning build without cache. Maybe useful if some unexpected happens.'
         )
-        // .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;
@@ -373,83 +369,6 @@ function getTimeString() {
 }
 
 
-// Symbol link do not work currently. So have to copy code manually.
-// See: https://github.com/ezolenko/rollup-plugin-typescript2/issues/188
-var ensureZRenderCode = (function () {
-
-    const nodeModulesZr = getPath('./node_modules/zrender');
-    // const nodeModulesZrDirTmp = getPath('./node_modules/zrender-dir-tmp');
-    const nodeModulesZrSymlinkTmp = getPath('./node_modules/zrender-symlink-tmp');
-    const nodeModulesZrSrcDir = getPath('./node_modules/zrender/src');
-    const zrSrcDir = getPath('../zrender/src')
-
-    let stats = 'cleared';
-
-    function doClear() {
-        if (!fs.existsSync(nodeModulesZrSymlinkTmp)
-            || !fs.lstatSync(nodeModulesZrSymlinkTmp).isSymbolicLink()
-        ) {
-            return;
-        }
-
-        if (fs.existsSync(nodeModulesZr)
-            && fs.lstatSync(nodeModulesZr).isDirectory()
-        ) {
-            console.log(chalk.blue(`rm -rf dir: ${nodeModulesZr}`));
-            // ensure save for rm -rf.
-            assert(nodeModulesZr.includes('node_modules') && nodeModulesZr.includes('zrender'));
-            fsExtra.removeSync(nodeModulesZr);
-        }
-
-        // recover the symbollink so that vs code can continue to visit the zrender source code.
-        console.log(chalk.blue(`mv symbol link: ${nodeModulesZrSymlinkTmp} => ${nodeModulesZr}`));
-        fs.renameSync(nodeModulesZrSymlinkTmp, nodeModulesZr);
-    }
-
-    return {
-        prepare: function () {
-            // Calling guard
-            assert(stats === 'cleared');
-            stats = 'prepared';
-
-            console.time('ensure zr code cost');
-            // In case that the last build terminated manually.
-            doClear();
-
-            if (!fs.existsSync(nodeModulesZr)
-                || !fs.lstatSync(nodeModulesZr).isSymbolicLink()
-            ) {
-                return;
-            }
-
-            if (!fs.existsSync(zrSrcDir)
-                || !fs.lstatSync(zrSrcDir).isDirectory()
-            ) {
-                throw new Error(`${zrSrcDir} does not exist.`);
-            }
-
-            console.log(chalk.blue(`mv symbol link: ${nodeModulesZr} => ${nodeModulesZrSymlinkTmp}`));
-            fs.renameSync(nodeModulesZr, nodeModulesZrSymlinkTmp);
-
-            fsExtra.ensureDirSync(nodeModulesZr);
-            fsExtra.copySync(zrSrcDir, nodeModulesZrSrcDir);
-            console.log(chalk.blue(`copied: ${nodeModulesZrSrcDir} => ${zrSrcDir}`));
-
-            console.timeEnd('ensure zr code cost');
-        },
-
-        clear: function () {
-            // Calling guard
-            if (stats === 'cleared') {
-                return;
-            }
-            stats = 'cleared';
-            doClear();
-        }
-    }
-})();
-
-
 async function main() {
     try {
         await run();
@@ -473,8 +392,6 @@ async function main() {
             err.plugin != null && console.warn(chalk.red(`plugin: ${err.plugin}`));
         }
         // console.log(err);
-
-        // ensureZRenderCode.clear();
     }
 }
 
diff --git a/build/pre-publish.js b/build/pre-publish.js
index 1d58395..7aa73b8 100644
--- a/build/pre-publish.js
+++ b/build/pre-publish.js
@@ -88,8 +88,7 @@ const compileWorkList = [
         transformOptions: {
             filesGlobby: {patterns: ['**/*.js'], cwd: tmpDir},
             preamble: preamble.js,
-            removeDEV: true,
-            cjsEntryCompat: cjsEntryCompat
+            removeDEV: true
         },
         before: async function () {
             fsExtra.removeSync(tmpDir);
@@ -142,7 +141,7 @@ const compileWorkList = [
     },
     {
         logLabel: 'extension ts -> js-cjs',
-        compilerOptions: {
+        compilerOptionsOverride: {
             module: 'CommonJS',
             rootDir: extensionSrcDir,
             outDir: extensionCJSDir
@@ -151,8 +150,7 @@ const compileWorkList = [
         transformOptions: {
             filesGlobby: {patterns: ['**/*.js'], cwd: extensionCJSDir},
             preamble: preamble.js,
-            removeDEV: true,
-            cjsEntryCompat: cjsEntryCompat
+            removeDEV: true
         },
         before: async function () {
             fsExtra.removeSync(extensionCJSDir);
@@ -160,7 +158,7 @@ const compileWorkList = [
     },
     {
         logLabel: 'extension ts -> js-esm',
-        compilerOptions: {
+        compilerOptionsOverride: {
             module: 'ES2015',
             rootDir: extensionSrcDir,
             outDir: extensionESMDir
@@ -208,7 +206,7 @@ module.exports = async function () {
         process.stdout.write(chalk.green.dim(` done \n`));
     }
 
-    console.log(chalk.green.bright('All done.'));
+    console.log(chalk.green.dim('All done.'));
 };
 
 async function tsCompile(compilerOptionsOverride, srcPathList) {
@@ -256,18 +254,18 @@ async function tsCompile(compilerOptionsOverride, srcPathList) {
         }
     });
     assert(!emitResult.emitSkipped, 'ts compile failed.');
+
 }
 
 /**
  * @param {Object} transformOptions
  * @param {Object} transformOptions.filesGlobby {patterns: string[], cwd: string}
  * @param {string} [transformOptions.preamble] See './preamble.js'
- * @param {Function} [transformOptions.cjsEntryCompat]
  * @param {boolean} [transformOptions.removeDEV]
  */
-async function transformCode({filesGlobby, preamble, cjsEntryCompat, removeDEV}) {
+async function transformCode({filesGlobby, preamble, removeDEV}) {
 
-    let filePaths = readFilePaths(filesGlobby);
+    let filePaths = await readFilePaths(filesGlobby);
 
     await Promise.all(filePaths.map(async filePath => {
         let code = await readFileAsync(filePath, {encoding: 'utf8'});
@@ -275,11 +273,6 @@ async function transformCode({filesGlobby, preamble, cjsEntryCompat, removeDEV})
         if (removeDEV) {
             let result = removeDEVUtil.transform(code, false);
             code = result.code;
-            removeDEVPlugin.recheckDEV(code);
-        }
-
-        if (cjsEntryCompat) {
-            code = cjsEntryCompat({code, filePath});
         }
 
         code = autoGeneratedFileAlert + code;
@@ -292,25 +285,6 @@ async function transformCode({filesGlobby, preamble, cjsEntryCompat, removeDEV})
     }));
 }
 
-function cjsEntryCompat({code, filePath}) {
-    if (filePath === nodePath.resolve(ecDir, 'src/echarts.js')) {
-        // For backward compat.
-        // Using `echarts/echarts.blank.js` to overwrite `echarts/lib/echarts.js`
-        // for including exports API.
-        code += `
-var ___ec_export = require("./export");
-(function () {
-for (var key in ___ec_export) {
-    if (___ec_export.hasOwnProperty(key)) {
-        exports[key] = ___ec_export[key];
-    }
-}
-})();`;
-    }
-
-    return code;
-}
-
 async function readFilePaths({patterns, cwd}) {
     assert(patterns && cwd);
     return (
diff --git a/package.json b/package.json
index 18b43e4..3b42938 100644
--- a/package.json
+++ b/package.json
@@ -33,10 +33,6 @@
   },
   "devDependencies": {
     "@babel/core": "7.3.4",
-    "@babel/helper-module-transforms": "7.0.0-beta.31",
-    "@babel/helper-simple-access": "7.0.0-beta.31",
-    "@babel/template": "7.0.0-beta.31",
-    "@babel/types": "7.0.0-beta.31",
     "@microsoft/api-extractor": "7.7.2",
     "@typescript-eslint/eslint-plugin": "^2.15.0",
     "@typescript-eslint/parser": "^2.18.0",
@@ -71,6 +67,6 @@
     "serve-handler": "6.1.1",
     "slugify": "1.3.4",
     "socket.io": "2.2.0",
-    "typescript": "^3.8.3"
+    "typescript": "3.8.3"
   }
 }


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