1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02: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,
].map((subtask) =>
runInChildProcess(subtask, {
applyLavaMoat,
buildType,
isLavaMoat,
policyOnly,

View File

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

View File

@ -9,11 +9,11 @@
"scripts": {
"setup": "yarn install && yarn setup:postinstall",
"setup:postinstall": "yarn patch-package && yarn allow-scripts",
"start": "yarn build:dev --apply-lavamoat=false",
"start:lavamoat": "yarn build:dev --apply-lavamoat=true",
"start": "yarn build:dev dev --apply-lavamoat=false",
"start:lavamoat": "yarn build:dev dev --apply-lavamoat=true",
"dist": "yarn build prod",
"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",
"benchmark:chrome": "SELENIUM_BROWSER=chrome node test/e2e/benchmark.js",
"benchmark:firefox": "SELENIUM_BROWSER=firefox node test/e2e/benchmark.js",