From 0ce9156248f271fe05e36bc2c86166f8e4a709dc Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 22 Jul 2021 09:59:01 -0300 Subject: [PATCH 1/2] introduce helper functions for inserting offline flags for use with yarn --- script/post-install.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/script/post-install.ts b/script/post-install.ts index dac221dc8d2..23cc815de4a 100644 --- a/script/post-install.ts +++ b/script/post-install.ts @@ -12,6 +12,22 @@ const options: SpawnSyncOptions = { stdio: 'inherit', } +/** Check if the caller has set the OFFLINe environment variable */ +function isOffline() { + return process.env.OFFLINE === '1' +} + +/** Format the arguments to ensure these work offline */ +function getYarnArgs(baseArgs: Array): Array { + const args = baseArgs + + if (isOffline()) { + args.splice(1, 0, '--offline') + } + + return args +} + function findYarnVersion(callback: (path: string) => void) { glob('vendor/yarn-*.js', (error, files) => { if (error != null) { From b78b7421530980275000e9adeaf7dc7d7cec9e4a Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 22 Jul 2021 09:59:33 -0300 Subject: [PATCH 2/2] wrap postinstall steps so that these yarn usages work with offline --- script/post-install.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/script/post-install.ts b/script/post-install.ts index 23cc815de4a..961503feba9 100644 --- a/script/post-install.ts +++ b/script/post-install.ts @@ -45,33 +45,33 @@ function findYarnVersion(callback: (path: string) => void) { } findYarnVersion(path => { - let result = spawnSync( - 'node', - [path, '--cwd', 'app', 'install', '--force'], - options - ) + const installArgs = getYarnArgs([path, '--cwd', 'app', 'install', '--force']) + + let result = spawnSync('node', installArgs, options) if (result.status !== 0) { process.exit(result.status || 1) } - result = spawnSync( - 'git', - ['submodule', 'update', '--recursive', '--init'], - options - ) - - if (result.status !== 0) { - process.exit(result.status || 1) + if (isOffline()) { + result = spawnSync( + 'git', + ['submodule', 'update', '--recursive', '--init'], + options + ) + + if (result.status !== 0) { + process.exit(result.status || 1) + } } - result = spawnSync('node', [path, 'compile:tslint'], options) + result = spawnSync('node', getYarnArgs([path, 'compile:tslint']), options) if (result.status !== 0) { process.exit(result.status || 1) } - result = spawnSync('node', [path, 'compile:script'], options) + result = spawnSync('node', getYarnArgs([path, 'compile:script']), options) if (result.status !== 0) { process.exit(result.status || 1)