1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fix development build scripts (#14594)

#14583 broke the development build scripts (e.g. `yarn start`) by adding a positional argument to a package script (`build:dev`) that is used and passed positional arguments in the build script itself. This PR removes the positional argument from the `build:dev` script and `yarn start` now works again. In addition, the `--apply-lavamoat` flag is properly forwarded to child processes, which was not the case in the original implementation.

To test, `yarn start` should work and LavaMoat should _not_ be applied, in distinction to `yarn build:dev dev --apply-lavamoat=true`. Whether LavaMoat is applied can be determined by checking whether `Object.isFrozen(Object.prototype)` is `true` (with LavaMoat) or `false` (without LavaMoat).
This commit is contained in:
Erik Marks 2022-05-02 15:35:52 -07:00 committed by Dan Miller
parent fda057637e
commit ada427af6d
3 changed files with 22 additions and 42 deletions

View File

@ -285,6 +285,7 @@ function createScriptTasks({
installSentrySubtask, installSentrySubtask,
].map((subtask) => ].map((subtask) =>
runInChildProcess(subtask, { runInChildProcess(subtask, {
applyLavaMoat,
buildType, buildType,
isLavaMoat, isLavaMoat,
policyOnly, policyOnly,

View File

@ -50,7 +50,7 @@ function createTask(taskName, taskFn) {
function runInChildProcess( function runInChildProcess(
task, task,
{ buildType, isLavaMoat, policyOnly, shouldLintFenceFiles }, { applyLavaMoat, buildType, isLavaMoat, policyOnly, shouldLintFenceFiles },
) { ) {
const taskName = typeof task === 'string' ? task : task.taskName; const taskName = typeof task === 'string' ? task : task.taskName;
if (!taskName) { if (!taskName) {
@ -60,44 +60,23 @@ function runInChildProcess(
} }
return instrumentForTaskStats(taskName, async () => { return instrumentForTaskStats(taskName, async () => {
let childProcess; const childProcess = spawn(
// Use the same build type for subprocesses, and only run them in LavaMoat 'yarn',
// if the parent process also ran in LavaMoat. [
if (isLavaMoat) { // Use the same build type for subprocesses, and only run them in
childProcess = spawn( // LavaMoat if the parent process also ran in LavaMoat.
'yarn', isLavaMoat ? 'build' : 'build:dev',
[ taskName,
'build', `--apply-lavamoat=${applyLavaMoat ? 'true' : 'false'}`,
taskName, `--build-type=${buildType}`,
'--build-type', `--lint-fence-files=${shouldLintFenceFiles ? 'true' : 'false'}`,
buildType, `--policyOnly=${policyOnly ? 'true' : 'false'}`,
'--lint-fence-files', '--skip-stats=true',
shouldLintFenceFiles, ],
'--skip-stats', {
...(policyOnly ? ['--policy-only'] : []), env: process.env,
], },
{ );
env: process.env,
},
);
} else {
childProcess = spawn(
'yarn',
[
'build:dev',
taskName,
'--build-type',
buildType,
'--lint-fence-files',
shouldLintFenceFiles,
'--skip-stats',
...(policyOnly ? ['--policy-only'] : []),
],
{
env: process.env,
},
);
}
// forward logs to main process // forward logs to main process
// skip the first stdout event (announcing the process command) // skip the first stdout event (announcing the process command)

View File

@ -9,11 +9,11 @@
"scripts": { "scripts": {
"setup": "yarn install && yarn setup:postinstall", "setup": "yarn install && yarn setup:postinstall",
"setup:postinstall": "yarn patch-package && yarn allow-scripts", "setup:postinstall": "yarn patch-package && yarn allow-scripts",
"start": "yarn build:dev --apply-lavamoat=false", "start": "yarn build:dev dev --apply-lavamoat=false",
"start:lavamoat": "yarn build:dev --apply-lavamoat=true", "start:lavamoat": "yarn build:dev dev --apply-lavamoat=true",
"dist": "yarn build prod", "dist": "yarn build prod",
"build": "yarn lavamoat:build", "build": "yarn lavamoat:build",
"build:dev": "node development/build/index.js dev", "build:dev": "node development/build/index.js",
"start:test": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' yarn build testDev", "start:test": "SEGMENT_HOST='https://api.segment.io' SEGMENT_WRITE_KEY='FAKE' yarn build testDev",
"benchmark:chrome": "SELENIUM_BROWSER=chrome node test/e2e/benchmark.js", "benchmark:chrome": "SELENIUM_BROWSER=chrome node test/e2e/benchmark.js",
"benchmark:firefox": "SELENIUM_BROWSER=firefox node test/e2e/benchmark.js", "benchmark:firefox": "SELENIUM_BROWSER=firefox node test/e2e/benchmark.js",