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).
feature/default_network_editable
Erik Marks 3 years ago committed by GitHub
parent 3b3a680682
commit 6915dd1a57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      development/build/scripts.js
  2. 57
      development/build/task.js
  3. 6
      package.json

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

@ -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)

@ -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",

Loading…
Cancel
Save