Skip to content

Commit

Permalink
fix: use parseOptionalBoolean on YARN_IGNORE_NODE (#4052)
Browse files Browse the repository at this point in the history
* fix: use parseOptionalBoolean on YARN_IGNORE_NODE

* chore: add comment

* chore: versions

* chore: changelog
  • Loading branch information
paul-soporan committed Feb 1, 2022
1 parent d4968ad commit d64baeb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
23 changes: 23 additions & 0 deletions .yarn/versions/a1a4200d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Various improvements have been made in the core to improve performance. Addition
- Fixed a crash caused by a bad interaction between aliased packages and peer dependencies.
- The ESBuild plugin will no longer allow access to Node.js builtins if the `platform` isn't set to Node.
- SemVer ranges with build metadata can now be resolved.
- The `YARN_IGNORE_NODE` environment variable will now be parsed using the same mechanism as env variable configuration settings (i.e. both `1`/`0` and `true`/`false` will be accepted)

### ZipFS Extension

Expand Down
20 changes: 12 additions & 8 deletions packages/yarnpkg-cli/sources/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Configuration, CommandContext, PluginConfiguration, TelemetryManager, semverUtils} from '@yarnpkg/core';
import {PortablePath, npath, xfs} from '@yarnpkg/fslib';
import {execFileSync} from 'child_process';
import {isCI} from 'ci-info';
import {Cli, UsageError} from 'clipanion';
import {realpathSync} from 'fs';
import {Configuration, CommandContext, PluginConfiguration, TelemetryManager, semverUtils, miscUtils} from '@yarnpkg/core';
import {PortablePath, npath, xfs} from '@yarnpkg/fslib';
import {execFileSync} from 'child_process';
import {isCI} from 'ci-info';
import {Cli, UsageError} from 'clipanion';
import {realpathSync} from 'fs';

import {pluginCommands} from './pluginCommands';
import {pluginCommands} from './pluginCommands';

function runBinary(path: PortablePath) {
const physicalPath = npath.fromPortablePath(path);
Expand Down Expand Up @@ -60,7 +60,11 @@ export async function main({binaryVersion, pluginConfiguration}: {binaryVersion:
const version = process.versions.node;
const range = `>=12 <14 || 14.2 - 14.9 || >14.10.0`;

if (process.env.YARN_IGNORE_NODE !== `1` && !semverUtils.satisfiesWithPrereleases(version, range))
// YARN_IGNORE_NODE is special because this code needs to execute as early as possible.
// It's not a regular core setting because Configuration.find may use functions not available
// on older Node versions.
const ignoreNode = miscUtils.parseOptionalBoolean(process.env.YARN_IGNORE_NODE);
if (!ignoreNode && !semverUtils.satisfiesWithPrereleases(version, range))
throw new UsageError(`This tool requires a Node version compatible with ${range} (got ${version}). Upgrade Node, or set \`YARN_IGNORE_NODE=1\` in your environment.`);

// Since we only care about a few very specific settings (yarn-path and ignore-path) we tolerate extra configuration key.
Expand Down

0 comments on commit d64baeb

Please sign in to comment.