From 555b4136b8dea87abc82975de5f273f5c4676d43 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 2 Aug 2017 13:13:30 -0700 Subject: [PATCH] Remove lerna, revert postinstall script to Nov 2016 version --- lerna.json | 4 - package.json | 5 +- packages/README.md | 10 -- scripts/postinstall.es6 | 137 ------------------ scripts/postinstall.js | 35 +++++ .../{ => unused}/benchmark-initial-sync.sh | 0 scripts/{ => unused}/benchmark-new-commits.sh | 0 scripts/{ => unused}/daily.js | 2 +- .../{ => unused}/drop-data-except-accounts.sh | 0 scripts/{ => unused}/requirements.txt | 0 scripts/{ => unused}/run-once-per-day.sh | 0 scripts/{ => unused}/upload-benchmark-data.py | 0 scripts/utils/child-process-wrapper.js | 46 ++++++ 13 files changed, 84 insertions(+), 155 deletions(-) delete mode 100644 lerna.json delete mode 100644 packages/README.md delete mode 100644 scripts/postinstall.es6 create mode 100644 scripts/postinstall.js rename scripts/{ => unused}/benchmark-initial-sync.sh (100%) rename scripts/{ => unused}/benchmark-new-commits.sh (100%) rename scripts/{ => unused}/daily.js (99%) rename scripts/{ => unused}/drop-data-except-accounts.sh (100%) rename scripts/{ => unused}/requirements.txt (100%) rename scripts/{ => unused}/run-once-per-day.sh (100%) rename scripts/{ => unused}/upload-benchmark-data.py (100%) create mode 100644 scripts/utils/child-process-wrapper.js diff --git a/lerna.json b/lerna.json deleted file mode 100644 index 43177a933..000000000 --- a/lerna.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "lerna": "2.0.0-beta.38", - "version": "0.0.1" -} diff --git a/package.json b/package.json index 45c4019c1..1b21fd126 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "grunt-contrib-less": "0.8.x", "grunt-lesslint": "0.13.x", "jasmine": "2.x.x", - "lerna": "emorikawa/lerna#v2.0.0-beta.38.forked", "load-grunt-parent-tasks": "0.1.1", "mkdirp": "^0.5.1", "pm2": "2.4.0", @@ -59,8 +58,8 @@ "stop": "npm run stop-cloud", "stop-cloud": "pm2 stop all; pm2 delete all;", "build-cloud": "docker build .", - "postinstall": "babel-node scripts/postinstall.es6", - "daily": "babel-node scripts/daily.js" + "postinstall": "node scripts/postinstall.js", + "daily": "node scripts/daily.js" }, "repository": { "type": "git", diff --git a/packages/README.md b/packages/README.md deleted file mode 100644 index 9734203d9..000000000 --- a/packages/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Monorepo Packages - -Each folder here is designed to act as its own repository. For development -convenience, they are all included here in one monorepo. This allows us to grep -across multiple codebases, not use submodules, and keep a unified commit -history. - -We use [Lerna](https://github.com/lerna/lerna) to manage the monorepo and tie -them all together with the main `nylas-mail-all/scripts/postinstall.es6` script, -which in turn, calls `lerna bootstrap` diff --git a/scripts/postinstall.es6 b/scripts/postinstall.es6 deleted file mode 100644 index d42bf802d..000000000 --- a/scripts/postinstall.es6 +++ /dev/null @@ -1,137 +0,0 @@ -import fs from 'fs-plus' -import path from 'path' -import childProcess from 'child_process' - -const TARGET_ALL = 'all' -const TARGET_CLOUD = 'cloud' -const TARGET_CLIENT = 'client' - -async function spawn(cmd, args, opts = {}) { - return new Promise((resolve, reject) => { - const options = Object.assign({stdio: 'inherit'}, opts); - const proc = childProcess.spawn(cmd, args, options) - proc.on("error", reject) - proc.on("exit", resolve) - }) -} - -function unlinkIfExistsSync(p) { - try { - if (fs.lstatSync(p)) { - fs.removeSync(p); - } - } catch (err) { - return - } -} - -function copyErrorLoggerExtensions(privateDir) { - const from = path.join(privateDir, 'src') - const to = path.resolve(path.join('packages', 'client-app', 'src')) - unlinkIfExistsSync(path.join(to, 'error-logger-extensions')); - fs.copySync(from, to); -} - -function installPrivateResources() { - console.log("\n---> Linking private plugins") - const privateDir = path.resolve(path.join('packages', 'client-private-plugins')) - if (!fs.existsSync(privateDir)) { - console.log("\n---> No client app to link. Moving on") - return; - } - - copyErrorLoggerExtensions(privateDir) - - // link private plugins - for (const plugin of fs.readdirSync(path.join(privateDir, 'packages'))) { - const from = path.resolve(path.join(privateDir, 'packages', plugin)); - const to = path.resolve(path.join('packages', 'client-app', 'internal_packages', plugin)); - unlinkIfExistsSync(to); - fs.symlinkSync(from, to, 'dir'); - } -} - -async function lernaBootstrap(installTarget) { - console.log("\n---> Installing packages"); - const lernaCmd = process.platform === 'win32' ? 'lerna.cmd' : 'lerna'; - const args = ["bootstrap"] - switch (installTarget) { - case TARGET_CLIENT: - args.push(`--ignore='cloud-*'`) - break - case TARGET_CLOUD: - args.push(`--ignore='client-*'`) - break - default: - break - } - await spawn(path.join('node_modules', '.bin', lernaCmd), args) -} - -const npmEnvs = { - system: process.env, - electron: Object.assign({}, process.env, { - NPM_CONFIG_TARGET: '1.7.3', - NPM_CONFIG_ARCH: process.arch, - NPM_CONFIG_TARGET_ARCH: process.arch, - NPM_CONFIG_DISTURL: 'https://atom.io/download/electron', - NPM_CONFIG_RUNTIME: 'electron', - NPM_CONFIG_BUILD_FROM_SOURCE: true, - }), -}; - -async function npm(cmd, options) { - const {cwd, env} = Object.assign({cwd: '.', env: 'system'}, options); - const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm' - await spawn(npmCmd, [cmd], { - cwd: path.resolve(__dirname, '..', cwd), - env: npmEnvs[env], - }) -} - -async function electronRebuild() { - await npm('rebuild', { - cwd: path.join('packages', 'client-app'), - env: 'electron', - }) -} - -function getInstallTarget() { - const {INSTALL_TARGET} = process.env - if (!INSTALL_TARGET) { - return TARGET_ALL - } - if (![TARGET_ALL, TARGET_CLIENT, TARGET_CLOUD].includes(INSTALL_TARGET)) { - throw new Error(`postinstall: INSTALL_TARGET must be one of client, cloud, or all. It was set to ${INSTALL_TARGET}`) - } - return INSTALL_TARGET -} - -async function main() { - try { - const installTarget = getInstallTarget() - console.log(`\n---> Installing for target ${installTarget}`); - - if ([TARGET_ALL, TARGET_CLIENT].includes(installTarget)) { - installPrivateResources() - } - - await lernaBootstrap(installTarget); - - if ([TARGET_ALL, TARGET_CLIENT].includes(installTarget)) { - if (process.platform === "darwin") { - // Given that `lerna bootstrap` does not install optional dependencies, we - // need to manually run `npm install` inside `client-app` so - // `node-mac-notifier` get's correctly installed and included in the build - // See https://github.com/lerna/lerna/issues/121 - console.log("\n---> Reinstalling client-app dependencies to include optional dependencies"); - await npm('install', {cwd: 'packages/client-app', env: 'electron'}) - } - await electronRebuild(); - } - } catch (err) { - console.error(err); - process.exit(1); - } -} -main() diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 000000000..712bedb7d --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,35 @@ +#!/usr/bin/env node +/* eslint global-require: 0 */ +/* eslint quote-props: 0 */ +const path = require('path'); +const safeExec = require('./utils/child-process-wrapper.js').safeExec; + +const npmEnvs = { + system: process.env, + electron: Object.assign({}, process.env, { + 'npm_config_target': require('../packages/client-app/package.json').dependencies.electron, + 'npm_config_arch': process.arch, + 'npm_config_target_arch': process.arch, + 'npm_config_disturl': 'https://atom.io/download/atom-shell', + 'npm_config_runtime': 'electron', + 'npm_config_build_from_source': true, + }), +}; + +function npm(cmd, options) { + const {cwd, env} = Object.assign({cwd: '.', env: 'system'}, options); + + return new Promise((resolve, reject) => { + console.log(`\n-- Running npm ${cmd} in ./${cwd} with ${env} config --`) + + safeExec(`npm ${cmd}`, { + cwd: path.resolve(__dirname, '..', cwd), + env: npmEnvs[env], + }, (err) => { + return err ? reject(err) : resolve(null); + }); + }); +} + +npm('install', {cwd: './packages/client-app', env: 'electron'}) +.then(() => npm('dedupe', {cwd: './packages/client-app', env: 'electron'})) diff --git a/scripts/benchmark-initial-sync.sh b/scripts/unused/benchmark-initial-sync.sh similarity index 100% rename from scripts/benchmark-initial-sync.sh rename to scripts/unused/benchmark-initial-sync.sh diff --git a/scripts/benchmark-new-commits.sh b/scripts/unused/benchmark-new-commits.sh similarity index 100% rename from scripts/benchmark-new-commits.sh rename to scripts/unused/benchmark-new-commits.sh diff --git a/scripts/daily.js b/scripts/unused/daily.js similarity index 99% rename from scripts/daily.js rename to scripts/unused/daily.js index 8aa92d068..f16aed0d4 100644 --- a/scripts/daily.js +++ b/scripts/unused/daily.js @@ -1,4 +1,4 @@ -#!/usr/bin/env babel-node +#!/usr/bin/env node const childProcess = require('child_process') const path = require('path') const mkdirp = require('mkdirp') diff --git a/scripts/drop-data-except-accounts.sh b/scripts/unused/drop-data-except-accounts.sh similarity index 100% rename from scripts/drop-data-except-accounts.sh rename to scripts/unused/drop-data-except-accounts.sh diff --git a/scripts/requirements.txt b/scripts/unused/requirements.txt similarity index 100% rename from scripts/requirements.txt rename to scripts/unused/requirements.txt diff --git a/scripts/run-once-per-day.sh b/scripts/unused/run-once-per-day.sh similarity index 100% rename from scripts/run-once-per-day.sh rename to scripts/unused/run-once-per-day.sh diff --git a/scripts/upload-benchmark-data.py b/scripts/unused/upload-benchmark-data.py similarity index 100% rename from scripts/upload-benchmark-data.py rename to scripts/unused/upload-benchmark-data.py diff --git a/scripts/utils/child-process-wrapper.js b/scripts/utils/child-process-wrapper.js new file mode 100644 index 000000000..05d3da901 --- /dev/null +++ b/scripts/utils/child-process-wrapper.js @@ -0,0 +1,46 @@ +var childProcess = require('child_process'); + +// Exit the process if the command failed and only call the callback if the +// command succeed, output of the command would also be piped. +exports.safeExec = function(command, options, callback) { + if (!callback) { + callback = options; + options = {}; + } + if (!options) + options = {}; + + // This needed to be increased for `apm test` runs that generate many failures + // The default is 200KB. + options.maxBuffer = 1024 * 1024; + + options.stdio = "inherit" + var child = childProcess.exec(command, options, function(error, stdout, stderr) { + if (error && !options.ignoreStderr) + process.exit(error.code || 1); + else + callback(null); + }); + child.stderr.pipe(process.stderr); + if (!options.ignoreStdout) + child.stdout.pipe(process.stdout); +} + +// Same with safeExec but call child_process.spawn instead. +exports.safeSpawn = function(command, args, options, callback) { + if (!callback) { + callback = options; + options = {}; + } + options.stdio = "inherit" + var child = childProcess.spawn(command, args, options); + child.on('error', function(error) { + console.error('Command \'' + command + '\' failed: ' + error.message); + }); + child.on('exit', function(code) { + if (code != 0) + process.exit(code); + else + callback(null); + }); +} \ No newline at end of file