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/09/16 05:30:12 UTC

[incubator-echarts] branch next updated: chore: remove __esModule mark in cjs export.

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

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


The following commit(s) were added to refs/heads/next by this push:
     new 948f1d8  chore: remove __esModule mark in cjs export.
     new 705e7e6  Merge branch 'next' of https://github.com/apache/incubator-echarts into next
948f1d8 is described below

commit 948f1d83dffeb62985100c773f00dcad5225f9e1
Author: pissang <bm...@gmail.com>
AuthorDate: Tue Sep 15 16:53:43 2020 +0800

    chore: remove __esModule mark in cjs export.
    
    To compatitable with the original `import echarts from 'echarts/lib/echarts'` code. If __esModule mark exists. It will get an undefined export.
---
 build/pre-publish.js | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/build/pre-publish.js b/build/pre-publish.js
index efc9e39..12577ca 100644
--- a/build/pre-publish.js
+++ b/build/pre-publish.js
@@ -110,7 +110,8 @@ const compileWorkList = [
             transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.common.js'), 'lib');
             transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.simple.js'), 'lib');
 
-            transformDistributionFiles(nodePath.resolve(ecDir, 'lib'), 'lib');
+            await transformDistributionFiles(nodePath.resolve(ecDir, 'lib'), 'lib');
+            removeESmoduleMark();
 
             fsExtra.removeSync(tmpDir);
         }
@@ -317,6 +318,26 @@ async function transformDistributionFiles(rooltFolder, replacement) {
     }
 }
 
+/**
+ * Remove __esModule mark.
+ *
+ * In the 4.x version. The exported CJS don't have __esModule mark.
+ * Developers can use `import echarts from 'echarts/lib/echarts' instead of
+ * `import * as echarts from 'echarts/lib/echarts'` to import all the exported methods.
+ * It's not recommand but developers may still have the chance to do it.
+ * But in the tsc export with __esModule mark. This will get an undefined export.
+ * To avoid breaking this kind of code. We remove __esModule mark manually here.
+ */
+function removeESmoduleMark() {
+    const filePath = nodePath.resolve(ecDir, 'lib/echarts.js');
+    const code = fs.readFileSync(filePath, 'utf-8')
+        .replace('\nexports.__esModule = true;\n', '');
+    if (code.indexOf('__esModule') >= 0) {
+        throw new Error('Seems still has __esModule mark');
+    }
+    fs.writeFileSync(filePath, code, 'utf-8');
+}
+
 function singleTransformZRRootFolder(code, replacement) {
     return code.replace(/([\"\'])zrender\/src\//g, `$1zrender/${replacement}/`);
 }


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