mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
9f4820ee98
* wip * build - breakout sentry-install bundle * deps - move new build sys deps to published versions * chore: lint fix * clean - remove unused file * clean - remove unsused package script * lavamoat - update build system policy * build - render html to all platforms * development - improve sourcemap debugger output * deps - update lavapack * lint - fix * deps - update lavapack for bugfix * deps - update lavapack for bugfix * deps - bump lavapack for line ending normalization * sourcemap explorer - disable boundary validation * ci - reset normal ci flow * build - re-enable minification on prod * build - remove noisy log about html dest * build - update terser and remove gulp wrapper for sourcemap fix * Revert "sourcemap explorer - disable boundary validation" This reverts commit 94112209ed880a6ebf4ee2ded411e59db6908162. * build - reenable react-devtools in dev mode * wip * build - breakout sentry-install bundle * deps - move new build sys deps to published versions * chore: lint fix * clean - remove unused file * clean - remove unsused package script * lavamoat - update build system policy * build - render html to all platforms * development - improve sourcemap debugger output * deps - update lavapack * lint - fix * deps - update lavapack for bugfix * deps - update lavapack for bugfix * deps - bump lavapack for line ending normalization * sourcemap explorer - disable boundary validation * ci - reset normal ci flow * build - re-enable minification on prod * build - remove noisy log about html dest * build - update terser and remove gulp wrapper for sourcemap fix * Revert "sourcemap explorer - disable boundary validation" This reverts commit 94112209ed880a6ebf4ee2ded411e59db6908162. * build - reenable react-devtools in dev mode * Updating lockfile * lint fix * build/dev - patch watchifys incompatible binary stats output * ui - add comment about conditional import * build - improve comment * Update development/stream-flat-map.js Co-authored-by: Brad Decker <git@braddecker.dev> * Outputting all bundle file links (metamaskbot) Co-authored-by: ryanml <ryanlanese@gmail.com> Co-authored-by: Brad Decker <git@braddecker.dev>
138 lines
3.6 KiB
JavaScript
138 lines
3.6 KiB
JavaScript
const EventEmitter = require('events');
|
|
const spawn = require('cross-spawn');
|
|
|
|
const tasks = {};
|
|
const taskEvents = new EventEmitter();
|
|
|
|
module.exports = {
|
|
detectAndRunEntryTask,
|
|
tasks,
|
|
taskEvents,
|
|
createTask,
|
|
runTask,
|
|
composeSeries,
|
|
composeParallel,
|
|
runInChildProcess,
|
|
};
|
|
|
|
const { setupTaskDisplay } = require('./display');
|
|
|
|
function detectAndRunEntryTask() {
|
|
// get requested task name and execute
|
|
const taskName = process.argv[2];
|
|
if (!taskName) {
|
|
throw new Error(`MetaMask build: No task name specified`);
|
|
}
|
|
const skipStats = process.argv.includes('--skip-stats');
|
|
|
|
runTask(taskName, { skipStats });
|
|
}
|
|
|
|
async function runTask(taskName, { skipStats } = {}) {
|
|
if (!(taskName in tasks)) {
|
|
throw new Error(`MetaMask build: Unrecognized task name "${taskName}"`);
|
|
}
|
|
if (!skipStats) {
|
|
setupTaskDisplay(taskEvents);
|
|
console.log(`running task "${taskName}"...`);
|
|
}
|
|
try {
|
|
await tasks[taskName]();
|
|
} catch (err) {
|
|
console.error(
|
|
`MetaMask build: Encountered an error while running task "${taskName}".`,
|
|
);
|
|
console.error(err);
|
|
process.exit(1);
|
|
}
|
|
taskEvents.emit('complete');
|
|
}
|
|
|
|
function createTask(taskName, taskFn) {
|
|
if (taskName in tasks) {
|
|
throw new Error(
|
|
`MetaMask build: task "${taskName}" already exists. Refusing to redefine`,
|
|
);
|
|
}
|
|
const task = instrumentForTaskStats(taskName, taskFn);
|
|
task.taskName = taskName;
|
|
tasks[taskName] = task;
|
|
return task;
|
|
}
|
|
|
|
function runInChildProcess(task) {
|
|
const taskName = typeof task === 'string' ? task : task.taskName;
|
|
if (!taskName) {
|
|
throw new Error(
|
|
`MetaMask build: runInChildProcess unable to identify task name`,
|
|
);
|
|
}
|
|
return instrumentForTaskStats(taskName, async () => {
|
|
let childProcess;
|
|
// don't run subprocesses in lavamoat for dev mode if main process not run in lavamoat
|
|
if (
|
|
process.env.npm_lifecycle_event === 'build:dev' ||
|
|
(taskName.includes('scripts:core:dev') &&
|
|
!process.argv[0].includes('lavamoat'))
|
|
) {
|
|
childProcess = spawn('yarn', ['build:dev', taskName, '--skip-stats'], {
|
|
env: process.env,
|
|
});
|
|
} else {
|
|
childProcess = spawn('yarn', ['build', taskName, '--skip-stats'], {
|
|
env: process.env,
|
|
});
|
|
}
|
|
// forward logs to main process
|
|
// skip the first stdout event (announcing the process command)
|
|
childProcess.stdout.once('data', () => {
|
|
childProcess.stdout.on('data', (data) =>
|
|
process.stdout.write(`${taskName}: ${data}`),
|
|
);
|
|
});
|
|
childProcess.stderr.on('data', (data) =>
|
|
process.stderr.write(`${taskName}: ${data}`),
|
|
);
|
|
// await end of process
|
|
await new Promise((resolve, reject) => {
|
|
childProcess.once('exit', (errCode) => {
|
|
if (errCode !== 0) {
|
|
reject(
|
|
new Error(
|
|
`MetaMask build: runInChildProcess for task "${taskName}" encountered an error ${errCode}`,
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
resolve();
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function instrumentForTaskStats(taskName, asyncFn) {
|
|
return async () => {
|
|
const start = Date.now();
|
|
taskEvents.emit('start', [taskName, start]);
|
|
await asyncFn();
|
|
const end = Date.now();
|
|
taskEvents.emit('end', [taskName, start, end]);
|
|
};
|
|
}
|
|
|
|
function composeSeries(...subtasks) {
|
|
return async () => {
|
|
const realTasks = subtasks;
|
|
for (const subtask of realTasks) {
|
|
await subtask();
|
|
}
|
|
};
|
|
}
|
|
|
|
function composeParallel(...subtasks) {
|
|
return async () => {
|
|
const realTasks = subtasks;
|
|
await Promise.all(realTasks.map((subtask) => subtask()));
|
|
};
|
|
}
|