This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch gh-pages in repository https://gitbox.apache.org/repos/asf/echarts-examples.git
commit b5cfaaeee9aaac4a3c03f02ebe87009300258067 Author: 100pah <sushuang0...@gmail.com> AuthorDate: Tue Sep 13 01:49:01 2022 +0800 fix: (1). add back the e2e/package.json, otherwise the dependent packages will be installed into echarts-examples/node_modules. And make some process to prevent it from committing modifications. (2). Fix some dependency install (of zrender, which is the dependency of echarts and echarts-gl). --- .gitignore | 2 ++ e2e/main.js | 98 +++++++++++++++++++++++++++++++++++++--------------- e2e/package.tpl.json | 12 +++++++ 3 files changed, 85 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 5e01c252..158ffaee 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ public/vendors/echarts/map/raw /public/data-gl/option /public/examples/js /e2e/package-lock.json +/e2e/package.json +/e2e/node_modules tmp .webm \ No newline at end of file diff --git a/e2e/main.js b/e2e/main.js index 2d114367..cb8de9a5 100644 --- a/e2e/main.js +++ b/e2e/main.js @@ -129,6 +129,10 @@ async function prepare() { fse.removeSync(REPO_DIR); fse.removeSync(PACKAGE_DIR); + fse.removeSync(nodePath.join(__dirname, 'package.json')); + fse.removeSync(nodePath.join(__dirname, 'package-lock.json')); + fse.copySync(nodePath.join(__dirname, 'package.tpl.json'), nodePath.join(__dirname, 'package.json')); + fse.ensureDirSync(TMP_DIR); fse.ensureDirSync(RUN_CODE_DIR); fse.ensureDirSync(BUNDLE_DIR); @@ -175,45 +179,82 @@ async function installPackages(config) { shell.cd(pkg.dir); - const packageJson = JSON.parse( - fs.readFileSync(nodePath.join(pkg.dir, 'package.json')) - ); + const packageJsonPath = nodePath.join(pkg.dir, 'package.json'); + const packageJsonRaw = fs.readFileSync(packageJsonPath, {encoding: 'utf-8'}); + const packageJson = JSON.parse(packageJsonRaw); const tgzFileName = `${packageJson.name}-${packageJson.version}.tgz`; const targetTgzFilePath = nodePath.join(PACKAGE_DIR, tgzFileName); + let needModifyPackageJSON = false; + + function doesConfigIncludesDepPkg(depPkgName) { + return !!config.packages.find((a) => a.name === depPkgName) + } if (packageJson.dependencies) { for (let depPkgName in packageJson.dependencies) { - const depPkg = config.packages.find((a) => a.name === depPkgName); - if (depPkg && !publishedPackages[depPkgName]) { - publishPackage(depPkg); - // Come back. - shell.cd(pkg.dir); + if (!doesConfigIncludesDepPkg(depPkgName) || publishedPackages[depPkgName]) { + continue; } + publishPackage(depPkg); + // Come back. + shell.cd(pkg.dir); + } - shell.exec(`npm install`); + if (shell.exec(`npm install`).code !== 0) { + console.error(`shell fail: npm install in ${pkg.dir}`); + process.exit(1); + } - if (depPkg) { - console.log( - chalk.gray( - `Installing dependency ${depPkgName} from "${publishedPackages[depPkgName]}" ...` - ) - ); - shell.exec(`npm install ${publishedPackages[depPkgName]} --no-save`); - console.log(chalk.gray(`Install dependency ${depPkgName} done.`)); + for (let depPkgName in packageJson.dependencies) { + if (!doesConfigIncludesDepPkg(depPkgName)) { + continue; } + console.log( + chalk.gray( + `Installing dependency ${depPkgName} from "${publishedPackages[depPkgName].targetTgzFilePath}" ...` + ) + ); + if (shell.exec(`npm install ${publishedPackages[depPkgName].targetTgzFilePath}`).code !== 0) { + console.error(`shell fail: npm install ${publishedPackages[depPkgName].targetTgzFilePath}`); + process.exit(1); + } + // After the npm install above, the package.json will be modifiedt to like: + // "dependencies": ["zredner": "file:../echarts-examples/e2e/tmp/packages/zrender-5.3.2.tgz"] + // which is a relative path and not correct if the tgz is copied to another place in + // the latter process. + // If we use --no-save, the latter npm install by tgz may not use the version of zrender that + // config.js specified. + // So we modifiy the version mandatorily to the version that config.js specified. + // In the latter npm install by tgz, the zrender will be installed firstly. And when echarts + // is installing, it found the right version of zrender has been installed, and do not install + // zrender separately. + needModifyPackageJSON = true; + packageJson.dependencies[depPkgName] = publishedPackages[depPkgName].version; + console.log(chalk.gray(`Install dependency ${depPkgName} done.`)); } } - shell.exec(`npm pack`); + if (needModifyPackageJSON) { + // Modify package.json for npm pack. + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson), {encoding: 'utf-8'}); + } + if (shell.exec(`npm pack`).code !== 0) { + console.error(`shell fail: npm pack in ${pkg.dir}`); + shell.exit(1); + } fs.renameSync(nodePath.join(pkg.dir, tgzFileName), targetTgzFilePath); - publishedPackages[packageJson.name] = targetTgzFilePath; + publishedPackages[packageJson.name] = {targetTgzFilePath, version: packageJson.version}; + + if (needModifyPackageJSON) { + // Restore modified package.json + fs.writeFileSync(packageJsonPath, packageJsonRaw, {encoding: 'utf-8'}); + } } for (let pkg of config.packages) { if (!checkFolder(pkg)) { - return; + process.exit(1); } - publishPackage(pkg); } @@ -221,10 +262,13 @@ async function installPackages(config) { for (let pkg of config.packages) { console.log( chalk.gray( - `Installing ${pkg.name} from "${publishedPackages[pkg.name]}" ...` + `Installing ${pkg.name} from "${publishedPackages[pkg.name].targetTgzFilePath}" ...` ) ); - shell.exec(`npm install ${publishedPackages[pkg.name]} --no-save`); + if (shell.exec(`npm install ${publishedPackages[pkg.name].targetTgzFilePath}`).code !== 0) { + console.log(`shell fail: npm install ${publishedPackages[pkg.name].targetTgzFilePath}`); + process.exit(1); + } console.log(chalk.gray(`Install ${pkg.name} done.`)); } @@ -783,8 +827,8 @@ async function main() { fs.readFileSync(__dirname + '/tmp/result.json', 'utf-8') ); } catch (e) { - console.error(e); - throw 'Must run full e2e test without --skip and --tests at least once.'; + console.log(`Can not find ${__dirname}/tmp/result.json. Make a new one.`); + result = {}; } } @@ -882,7 +926,7 @@ async function main() { main() .catch((e) => { console.error(e); - process.exit(); + process.exit(1); }) .then(() => { process.exit(); @@ -891,5 +935,5 @@ main() process.on('SIGINT', function () { console.log('Closing'); // Close through ctrl + c; - process.exit(); + process.exit(1); }); diff --git a/e2e/package.tpl.json b/e2e/package.tpl.json new file mode 100644 index 00000000..ce3fba7b --- /dev/null +++ b/e2e/package.tpl.json @@ -0,0 +1,12 @@ +{ + "description": "DO NOT remove this file, otherwise when e2e/main.js execute npm install, packages will be installed in echarst-examples/node_modules and will be removed because --no-save is used.", + "name": "echarts-examples-e2e", + "version": "1.0.0", + "main": "main.js", + "scripts": {}, + "author": "", + "license": "ISC", + "dependencies": { + "zrender": "file:tmp/packages/zrender-5.3.2.tgz" + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org