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/28 04:07:42 UTC
[incubator-echarts] branch next-npm-env updated: chore(prepublish):
transform entry root folder to esm and lib
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
The following commit(s) were added to refs/heads/next-npm-env by this push:
new ee0b8f3 chore(prepublish): transform entry root folder to esm and lib
ee0b8f3 is described below
commit ee0b8f3aa5a7eade8ca4687f32c09f7e2bafd51c
Author: pissang <bm...@gmail.com>
AuthorDate: Tue Jul 28 12:07:26 2020 +0800
chore(prepublish): transform entry root folder to esm and lib
---
.eslintignore | 10 +++++++++-
build/pre-publish.js | 31 +++++++++++++++++++++++++++----
2 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/.eslintignore b/.eslintignore
index 8da5fc2..ce77b6f 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -4,4 +4,12 @@
/extension-esm
/extension
/lib
-/esm
\ No newline at end of file
+/esm
+/index.js
+/index.blank.js
+/index.common.js
+/index.simple.js
+/echarts.all.js
+/echarts.blank.js
+/echarts.common.js
+/echarts.simple.js
\ No newline at end of file
diff --git a/build/pre-publish.js b/build/pre-publish.js
index 7aa73b8..2f40c2d 100644
--- a/build/pre-publish.js
+++ b/build/pre-publish.js
@@ -104,6 +104,12 @@ const compileWorkList = [
fs.renameSync(nodePath.resolve(tmpDir, 'echarts.common.js'), nodePath.resolve(ecDir, 'index.common.js'));
fs.renameSync(nodePath.resolve(tmpDir, 'echarts.simple.js'), nodePath.resolve(ecDir, 'index.simple.js'));
fs.renameSync(nodePath.resolve(tmpDir, 'src'), nodePath.resolve(ecDir, 'lib'));
+
+ transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.js'), 'lib');
+ transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.blank.js'), 'lib');
+ transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.common.js'), 'lib');
+ transformRootFolderInEntry(nodePath.resolve(ecDir, 'index.simple.js'), 'lib');
+
fsExtra.removeSync(tmpDir);
}
},
@@ -136,6 +142,12 @@ const compileWorkList = [
fs.renameSync(nodePath.resolve(tmpDir, 'echarts.common.js'), nodePath.resolve(ecDir, 'echarts.common.js'));
fs.renameSync(nodePath.resolve(tmpDir, 'echarts.simple.js'), nodePath.resolve(ecDir, 'echarts.simple.js'));
fs.renameSync(nodePath.resolve(tmpDir, 'src'), nodePath.resolve(ecDir, 'esm'));
+
+ transformRootFolderInEntry(nodePath.resolve(ecDir, 'echarts.all.js'), 'esm');
+ transformRootFolderInEntry(nodePath.resolve(ecDir, 'echarts.blank.js'), 'esm');
+ transformRootFolderInEntry(nodePath.resolve(ecDir, 'echarts.common.js'), 'esm');
+ transformRootFolderInEntry(nodePath.resolve(ecDir, 'echarts.simple.js'), 'esm');
+
fsExtra.removeSync(tmpDir);
}
},
@@ -254,7 +266,18 @@ async function tsCompile(compilerOptionsOverride, srcPathList) {
}
});
assert(!emitResult.emitSkipped, 'ts compile failed.');
+}
+/**
+ * Transform `src` root in the entry file to `esm` or `lib`
+ */
+async function transformRootFolderInEntry(entryFile, replacement) {
+ let code = fs.readFileSync(entryFile, 'utf-8');
+ // Simple regex replacement
+ // TODO More robust way?
+ code = code.replace(/([\"\'])\.\/src\//g, `$1./${replacement}/`)
+ .replace(/([\"\'])src\//g, `$1${replacement}/`);
+ fs.writeFileSync(entryFile, code, 'utf-8');
}
/**
@@ -267,8 +290,8 @@ async function transformCode({filesGlobby, preamble, removeDEV}) {
let filePaths = await readFilePaths(filesGlobby);
- await Promise.all(filePaths.map(async filePath => {
- let code = await readFileAsync(filePath, {encoding: 'utf8'});
+ filePaths.map(filePath => {
+ let code = fs.readFileSync(filePath, 'utf8');
if (removeDEV) {
let result = removeDEVUtil.transform(code, false);
@@ -281,8 +304,8 @@ async function transformCode({filesGlobby, preamble, removeDEV}) {
code = preamble + code;
}
- await writeFileAsync(filePath, code, {encoding: 'utf8'});
- }));
+ fs.writeFileSync(filePath, code, 'utf8');
+ });
}
async function readFilePaths({patterns, cwd}) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org