-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Rationalise DCR's env checking scripts (#9400)"
This reverts commit 7d623b9.
- Loading branch information
Showing
13 changed files
with
136 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const { join } = require('node:path'); | ||
const { promisify } = require('node:util'); | ||
const readFile = promisify(require('node:fs').readFile); | ||
const ensure = require('./ensure'); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
(async () => { | ||
try { | ||
const [semver] = await ensure('semver'); | ||
|
||
const nodeVersion = /^v(\d+\.\d+\.\d+)/.exec(process.version)[1]; | ||
const nvmrcVersion = ( | ||
await readFile(join(__dirname, '..', '..', '..', '.nvmrc'), 'utf8') | ||
).trim(); | ||
|
||
if (!semver.satisfies(nodeVersion, nvmrcVersion)) { | ||
const { warn, prompt, log } = require('./log'); | ||
warn( | ||
`dotcom-rendering requires Node v${nvmrcVersion}`, | ||
`You are using v${nodeVersion ?? '(unknown)'}`, | ||
); | ||
if (process.env.NVM_DIR) { | ||
prompt('Run `nvm install` from the repo root and try again.'); | ||
log( | ||
'See also: https://gist.github.com/sndrs/5940e9e8a3f506b287233ed65365befb', | ||
); | ||
} else if (process.env.FNM_DIR) { | ||
prompt( | ||
'It looks like you have fnm installed', | ||
'Run `fnm use` from the repo root and try again.', | ||
); | ||
} else { | ||
prompt( | ||
`Using a Node version manager can make things easier.`, | ||
`Our recommendation is fnm: https://github.com/Schniz/fnm`, | ||
); | ||
} | ||
process.exit(1); | ||
} | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.log(e); | ||
process.exit(1); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { promisify } = require('node:util'); | ||
const exec = promisify(require('node:child_process').execFile); | ||
const ensure = require('./ensure'); | ||
|
||
// Yarn v1.x support .yarnrc, so we can use a local (check-in) copy of yarn | ||
const YARN_MIN_VERSION = '1.x'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
(async () => { | ||
try { | ||
// This will fail if yarn isn't installed, and force into the catch, | ||
// where we install yarn with NPM (mainly for CI) | ||
const { stdout: version } = await exec('yarn', ['--version']); | ||
|
||
const [semver] = await ensure('semver'); | ||
|
||
if (!semver.satisfies(version, YARN_MIN_VERSION)) { | ||
const { warn, prompt, log } = require('./log'); | ||
warn( | ||
`dotcom-rendering requires Yarn >=${YARN_MIN_VERSION}`, | ||
`You are using v${version}`, | ||
); | ||
prompt('Please upgrade yarn'); | ||
log('https://classic.yarnpkg.com/en/docs/install'); | ||
|
||
process.exit(1); | ||
} | ||
} catch (e) { | ||
require('./log').log(`Installing yarn`); | ||
await exec('npm', ['i', '-g', `yarn@${YARN_MIN_VERSION}`]); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// provides a way to use packages in scripts when we don't know | ||
// if they've been installed yet (with yarn) by temporarily | ||
// installing with npm if node cannot resolve the package | ||
|
||
const { log } = require('./log'); | ||
|
||
module.exports = (...packages) => | ||
new Promise((resolve) => { | ||
try { | ||
resolve(packages.map(require)); | ||
} catch (e) { | ||
log(`Pre-installing dependency (${packages.join(', ')})...`); | ||
const npmInstallProcess = require('node:child_process') | ||
.spawn('npm', [ | ||
'i', | ||
...packages, | ||
'--no-save', | ||
'--legacy-peer-deps', | ||
'--package-lock=false', | ||
]) | ||
.on('close', (code) => { | ||
if (code !== 0) { | ||
process.exit(code); | ||
} | ||
try { | ||
resolve(packages.map(require)); | ||
} catch (e2) { | ||
// eslint-disable-next-line no-console | ||
console.log(e2); | ||
process.exit(1); | ||
} | ||
}) | ||
.stderr.on('data', (data) => | ||
console.error(Buffer.from(data).toString()), | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.