diff --git a/script/build b/script/build index 62a7e3da879..cc7d280682d 100755 --- a/script/build +++ b/script/build @@ -56,11 +56,6 @@ const notarizeOnMac = require('./lib/notarize-on-mac') const packageApplication = require('./lib/package-application') const prebuildLessCache = require('./lib/prebuild-less-cache') const testSignOnMac = require('./lib/test-sign-on-mac') -const transpileBabelPaths = require('./lib/transpile-babel-paths') -const transpileCoffeeScriptPaths = require('./lib/transpile-coffee-script-paths') -const transpileCsonPaths = require('./lib/transpile-cson-paths') -const transpilePegJsPaths = require('./lib/transpile-peg-js-paths') -const transpilePackagesWithCustomTranspilerPaths = require('./lib/transpile-packages-with-custom-transpiler-paths.js') process.on('unhandledRejection', function (e) { console.error(e.stack || e) @@ -69,31 +64,41 @@ process.on('unhandledRejection', function (e) { process.env.ELECTRON_VERSION = CONFIG.appMetadata.electronVersion -let binariesPromise = Promise.resolve() - -if (!argv.existingBinaries) { - checkChromedriverVersion() - cleanOutputDirectory() - copyAssets() - transpilePackagesWithCustomTranspilerPaths() - transpileBabelPaths() - transpileCoffeeScriptPaths() - transpileCsonPaths() - transpilePegJsPaths() - generateModuleCache() - prebuildLessCache() - generateMetadata() - generateAPIDocs() - if (!argv.generateApiDocs) { - binariesPromise = dumpSymbols() - } +async function transpile() { + const { spawn, Thread, Worker } = require(`${CONFIG.scriptRunnerModulesPath}/threads`) + + const transpilePackagesWithCustomTranspilerPaths = await spawn(new Worker('./lib/transpile-packages-with-custom-transpiler-paths')) + const transpilePackagesWithCustomTranspilerPathsPromise = transpilePackagesWithCustomTranspilerPaths() + + const transpileBabelPaths = await spawn(new Worker('./lib/transpile-babel-paths')) + const transpileBabelPathsPromise = transpileBabelPaths() + + const transpileCoffeeScriptPaths = await spawn(new Worker('./lib/transpile-coffee-script-paths')) + const transpileCoffeeScriptPathsPromise = transpileCoffeeScriptPaths() + + const transpileCsonPaths = await spawn(new Worker('./lib/transpile-cson-paths')) + const transpileCsonPathsPromise = transpileCsonPaths() + + const transpilePegJsPaths = await spawn(new Worker('./lib/transpile-peg-js-paths')) + const transpilePegJsPathsPromise = transpilePegJsPaths() + + await transpilePackagesWithCustomTranspilerPathsPromise; + await Thread.terminate(transpilePackagesWithCustomTranspilerPaths) + + await transpileBabelPathsPromise; + await Thread.terminate(transpileBabelPaths) + + await transpileCoffeeScriptPathsPromise; + await Thread.terminate(transpileCoffeeScriptPaths) + + await transpileCsonPathsPromise; + await Thread.terminate(transpileCsonPaths) + + await transpilePegJsPathsPromise; + await Thread.terminate(transpilePegJsPaths) } -if (!argv.generateApiDocs) { - binariesPromise - .then(packageApplication) - .then(packagedAppPath => generateStartupSnapshot(packagedAppPath).then(() => packagedAppPath)) - .then(async packagedAppPath => { +async function singAndCreateInstaller(packagedAppPath) { switch (process.platform) { case 'darwin': { if (argv.codeSign) { @@ -148,7 +153,29 @@ if (!argv.generateApiDocs) { } return Promise.resolve(packagedAppPath) - }).then(packagedAppPath => { +} + + +async function build() { + + if (!argv.existingBinaries) { + checkChromedriverVersion() + cleanOutputDirectory() + copyAssets() + await transpile() + generateModuleCache() + prebuildLessCache() + generateMetadata() + generateAPIDocs() + if (!argv.generateApiDocs) { + await dumpSymbols() + } + } + + if (!argv.generateApiDocs) { + const packagedAppPath = await packageApplication() + await generateStartupSnapshot(packagedAppPath) + await singAndCreateInstaller(packagedAppPath) if (argv.compressArtifacts) { compressArtifacts(packagedAppPath) } else { @@ -160,5 +187,9 @@ if (!argv.generateApiDocs) { } else { console.log('Skipping installation. Specify the --install option to install Atom'.gray) } - }) + } + } + + +build().then(() => {process.exit(0)}).catch((e) => {throw e;}) diff --git a/script/config.js b/script/config.js index ed67e7fdcb6..b9b8c925496 100644 --- a/script/config.js +++ b/script/config.js @@ -126,4 +126,7 @@ function getNpmBinPath(external = false) { : npmBinName; } -process.env.JOBS = 'max'; // parallel build in node-gyp +// parallel build in node-gyp +if (!process.env.JOBS) { + process.env.JOBS = 'max'; +} diff --git a/script/lib/install-apm.js b/script/lib/install-apm.js index 1c5a7ed564e..03b47cff971 100644 --- a/script/lib/install-apm.js +++ b/script/lib/install-apm.js @@ -4,7 +4,7 @@ const childProcess = require('child_process'); const CONFIG = require('../config'); -function installApm(ci) { +function installApm(ci = false, showVersion = true) { console.log('Installing apm'); // npm ci leaves apm with a bunch of unmet dependencies childProcess.execFileSync( @@ -12,9 +12,11 @@ function installApm(ci) { ['--global-style', '--loglevel=error', 'install'], { env: process.env, cwd: CONFIG.apmRootPath } ); - childProcess.execFileSync(CONFIG.getApmBinPath(), ['--version'], { - stdio: 'inherit' - }); + if (showVersion) { + childProcess.execFileSync(CONFIG.getApmBinPath(), ['--version'], { + stdio: 'inherit' + }); + } } const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`); diff --git a/script/lib/install-script-runner-dependencies.js b/script/lib/install-script-runner-dependencies.js index 62b4f120872..5c4a4d6e629 100644 --- a/script/lib/install-script-runner-dependencies.js +++ b/script/lib/install-script-runner-dependencies.js @@ -4,8 +4,6 @@ const childProcess = require('child_process'); const CONFIG = require('../config'); -process.env.ELECTRON_CUSTOM_VERSION = CONFIG.appMetadata.electronVersion; - function installScriptRunnerDependencies(ci) { console.log('Installing script runner dependencies'); childProcess.execFileSync( diff --git a/script/lib/transpile-babel-paths.js b/script/lib/transpile-babel-paths.js index 50fad2aa2aa..c36049132aa 100644 --- a/script/lib/transpile-babel-paths.js +++ b/script/lib/transpile-babel-paths.js @@ -7,12 +7,12 @@ const path = require('path'); const CONFIG = require('../config'); -module.exports = function() { +function transpileBabelPaths() { console.log(`Transpiling Babel paths in ${CONFIG.intermediateAppPath}`); for (let path of getPathsToTranspile()) { transpileBabelPath(path); } -}; +} function getPathsToTranspile() { let paths = []; @@ -49,3 +49,7 @@ function transpileBabelPath(path) { CompileCache.addPathToCache(path, CONFIG.atomHomeDirPath) ); } + +const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`); +expose(transpileBabelPaths); +module.exports = transpileBabelPaths; diff --git a/script/lib/transpile-coffee-script-paths.js b/script/lib/transpile-coffee-script-paths.js index f88fe04a5dd..94453ecb515 100644 --- a/script/lib/transpile-coffee-script-paths.js +++ b/script/lib/transpile-coffee-script-paths.js @@ -7,14 +7,14 @@ const path = require('path'); const CONFIG = require('../config'); -module.exports = function() { +function transpileCoffeeScriptPaths() { console.log( `Transpiling CoffeeScript paths in ${CONFIG.intermediateAppPath}` ); for (let path of getPathsToTranspile()) { transpileCoffeeScriptPath(path); } -}; +} function getPathsToTranspile() { let paths = []; @@ -63,3 +63,7 @@ function transpileCoffeeScriptPath(coffeePath) { ); fs.unlinkSync(coffeePath); } + +const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`); +expose(transpileCoffeeScriptPaths); +module.exports = transpileCoffeeScriptPaths; diff --git a/script/lib/transpile-cson-paths.js b/script/lib/transpile-cson-paths.js index a4d8d95e931..554a7863878 100644 --- a/script/lib/transpile-cson-paths.js +++ b/script/lib/transpile-cson-paths.js @@ -7,12 +7,12 @@ const path = require('path'); const CONFIG = require('../config'); -module.exports = function() { +function transpileCsonPaths() { console.log(`Transpiling CSON paths in ${CONFIG.intermediateAppPath}`); for (let path of getPathsToTranspile()) { transpileCsonPath(path); } -}; +} function getPathsToTranspile() { let paths = []; @@ -53,3 +53,7 @@ function transpileCsonPath(csonPath) { ); fs.unlinkSync(csonPath); } + +const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`); +expose(transpileCsonPaths); +module.exports = transpileCsonPaths; diff --git a/script/lib/transpile-packages-with-custom-transpiler-paths.js b/script/lib/transpile-packages-with-custom-transpiler-paths.js index d176bcdf7f4..1b7e77ac62c 100644 --- a/script/lib/transpile-packages-with-custom-transpiler-paths.js +++ b/script/lib/transpile-packages-with-custom-transpiler-paths.js @@ -11,7 +11,7 @@ const runApmInstall = require('./run-apm-install'); require('colors'); -module.exports = function() { +function transpilePackagesWithCustomTranspilerPaths() { console.log( `Transpiling packages with custom transpiler configurations in ${ CONFIG.intermediateAppPath @@ -78,7 +78,7 @@ module.exports = function() { intermediatePackageBackup.restore(); } } -}; +} function transpilePath(path) { fs.writeFileSync( @@ -86,3 +86,7 @@ function transpilePath(path) { CompileCache.addPathToCache(path, CONFIG.atomHomeDirPath) ); } + +const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`); +expose(transpilePackagesWithCustomTranspilerPaths); +module.exports = transpilePackagesWithCustomTranspilerPaths; diff --git a/script/lib/transpile-peg-js-paths.js b/script/lib/transpile-peg-js-paths.js index 5d500e806c7..ffc31b58707 100644 --- a/script/lib/transpile-peg-js-paths.js +++ b/script/lib/transpile-peg-js-paths.js @@ -7,12 +7,12 @@ const path = require('path'); const CONFIG = require('../config'); -module.exports = function() { +function transpilePegJsPaths() { console.log(`Transpiling PEG.js paths in ${CONFIG.intermediateAppPath}`); for (let path of getPathsToTranspile()) { transpilePegJsPath(path); } -}; +} function getPathsToTranspile() { let paths = []; @@ -41,3 +41,7 @@ function transpilePegJsPath(pegJsPath) { fs.writeFileSync(jsPath, outputCode); fs.unlinkSync(pegJsPath); } + +const { expose } = require(`${CONFIG.scriptRunnerModulesPath}/threads/worker`); +expose(transpilePegJsPaths); +module.exports = transpilePegJsPaths;