Build task runner: preserve this context (#35950) (#36277)

* Build task runner: preserve this context

* Review comments
This commit is contained in:
Rudolf Meijering 2019-05-08 21:00:29 +02:00 committed by GitHub
parent fc64522614
commit 1b1f6e30bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 10 deletions

View file

@ -24,7 +24,7 @@ import { isErrorLogged, markErrorLogged } from './errors';
import { createBuild } from './build';
export function createRunner({ config, log, buildOssDist, buildDefaultDist }) {
async function execTask(desc, fn, ...args) {
async function execTask(desc, task, ...args) {
log.info(desc);
log.indent(4);
@ -37,7 +37,7 @@ export function createRunner({ config, log, buildOssDist, buildDefaultDist }) {
};
try {
await fn(config, log, ...args);
await task.run(config, log, ...args);
log.success(chalk.green('✓'), time());
} catch (error) {
if (!isErrorLogged(error)) {
@ -82,10 +82,10 @@ export function createRunner({ config, log, buildOssDist, buildDefaultDist }) {
*/
return async function run(task) {
if (task.global) {
await execTask(chalk`{dim [ global ]} ${task.description}`, task.run, builds);
await execTask(chalk`{dim [ global ]} ${task.description}`, task, builds);
} else {
for (const build of builds) {
await execTask(`${build.getLogTag()} ${task.description}`, task.run, build);
await execTask(`${build.getLogTag()} ${task.description}`, task, build);
}
}
};

View file

@ -19,7 +19,7 @@
import { dirname, resolve } from 'path';
import fs from 'fs';
import { promisify } from 'bluebird';
import { promisify } from 'util';
import mkdirp from 'mkdirp';
import { untar } from '../../lib';
@ -29,7 +29,7 @@ const statAsync = promisify(fs.stat);
const mkdirpAsync = promisify(mkdirp);
const copyFileAsync = promisify(fs.copyFile);
const ExtractNodeBuildsTask = {
export const ExtractNodeBuildsTask = {
global: true,
description: 'Extracting node.js builds for all platforms',
async run(config) {
@ -55,7 +55,3 @@ const ExtractNodeBuildsTask = {
return await copyFileAsync(source, destination, fs.constants.COPYFILE_FICLONE);
},
};
ExtractNodeBuildsTask.run = ExtractNodeBuildsTask.run.bind(ExtractNodeBuildsTask);
export { ExtractNodeBuildsTask };