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 1740726  chore: fix sourcemap after add umd wrapper in esbuild
1740726 is described below

commit 174072664a19198ca0f653b817f0625e8f40398e
Author: pissang <bm2736...@gmail.com>
AuthorDate: Wed May 27 11:04:23 2020 +0800

    chore: fix sourcemap after add umd wrapper in esbuild
---
 build/dev-fast.js | 28 ++++++++++++++++++++--------
 package-lock.json | 30 +++++++++++++++++++++++++++---
 package.json      |  2 ++
 3 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/build/dev-fast.js b/build/dev-fast.js
index 891789a..412eb82 100644
--- a/build/dev-fast.js
+++ b/build/dev-fast.js
@@ -2,6 +2,8 @@ const chokidar = require('chokidar');
 const path = require('path');
 const {build} = require('esbuild');
 const fs = require('fs');
+const debounce = require('lodash.debounce');
+const sourceMap = require('source-map');
 
 const outFilePath = path.resolve(__dirname, '../dist/echarts.js');
 
@@ -23,9 +25,18 @@ const umdWrapperHead = `
 const umdWrapperTail = `
 }));`;
 
-// attach properties to the exports object to define
-// the exported module properties.
-exports.action = function () {};
+async function wrapUMDCode() {
+    const consumer = await new 
sourceMap.SourceMapConsumer(fs.readFileSync(outFilePath + '.map', 'utf8'));
+    const node = 
sourceMap.SourceNode.fromStringWithSourceMap(fs.readFileSync(outFilePath, 
'utf-8'), consumer);
+    // add six empty lines
+    node.prepend(umdWrapperHead);
+    node.add(umdWrapperTail);
+    const res = node.toStringWithSourceMap({
+        file: outFilePath
+    });
+    fs.writeFileSync(outFilePath, res.code, 'utf-8');
+    fs.writeFileSync(outFilePath + '.map', res.map.toString(), 'utf-8');
+}
 
 function rebuild() {
     build({
@@ -38,16 +49,17 @@ function rebuild() {
     }).catch(e => {
         console.error(e.toString());
     }).then(() => {
-        const mainCode = fs.readFileSync(outFilePath, 'utf-8');
-        fs.writeFileSync(outFilePath, umdWrapperHead + mainCode + 
umdWrapperTail)
+        console.time('Wrap UMD');
+        wrapUMDCode();
+        console.timeEnd('Wrap UMD');
     })
 }
 
+const debouncedRebuild = debounce(rebuild, 200);
+
 chokidar.watch([
     path.resolve(__dirname, '../src/**/*.ts'),
     path.resolve(__dirname, '../node_modules/zrender/src/**/*.ts'),
 ], {
     persistent: true
-}).on('change', rebuild).on('ready', function () {
-    rebuild();
-})
\ No newline at end of file
+}).on('all', debouncedRebuild);
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 5514063..9fbae77 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -70,6 +70,12 @@
           "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz";,
           "integrity": 
"sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
           "dev": true
+        },
+        "source-map": {
+          "version": "0.5.7",
+          "resolved": 
"https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz";,
+          "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=",
+          "dev": true
         }
       }
     },
@@ -96,6 +102,12 @@
             "lodash": "^4.17.13",
             "to-fast-properties": "^2.0.0"
           }
+        },
+        "source-map": {
+          "version": "0.5.7",
+          "resolved": 
"https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz";,
+          "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=",
+          "dev": true
         }
       }
     },
@@ -5822,6 +5834,12 @@
       "integrity": 
"sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
       "dev": true
     },
+    "lodash.debounce": {
+      "version": "4.0.8",
+      "resolved": 
"https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz";,
+      "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=",
+      "dev": true
+    },
     "lodash.get": {
       "version": "4.4.2",
       "resolved": 
"https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz";,
@@ -7441,6 +7459,12 @@
           "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz";,
           "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
           "dev": true
+        },
+        "source-map": {
+          "version": "0.5.7",
+          "resolved": 
"https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz";,
+          "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=",
+          "dev": true
         }
       }
     },
@@ -7603,9 +7627,9 @@
       }
     },
     "source-map": {
-      "version": "0.5.7",
-      "resolved": 
"https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz";,
-      "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=",
+      "version": "0.7.3",
+      "resolved": 
"https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz";,
+      "integrity": 
"sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==",
       "dev": true
     },
     "source-map-resolve": {
diff --git a/package.json b/package.json
index 113298f..84c3d9a 100644
--- a/package.json
+++ b/package.json
@@ -57,6 +57,7 @@
     "jest-canvas-mock": "^2.2.0",
     "jsdom": "^15.2.1",
     "jshint": "2.10.2",
+    "lodash.debounce": "^4.0.8",
     "open": "6.4.0",
     "pixelmatch": "5.0.2",
     "pngjs": "3.4.0",
@@ -70,6 +71,7 @@
     "serve-handler": "6.1.1",
     "slugify": "1.3.4",
     "socket.io": "2.2.0",
+    "source-map": "^0.7.3",
     "typescript": "^3.8.3"
   }
 }


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

Reply via email to