Skip to content

Commit efdccc1

Browse files
arcanisclhuang
andauthored
Hotfixes for the 1.22.20 (#9009)
* Prepares for the 1.22.20 release * Cleanup * Update child.js * Prevents crashes when .yarnrc.yml is empty * Couple of tweaks * Bumps version --------- Co-authored-by: Calvin Huang <c@lvin.me>
1 parent 015b20b commit efdccc1

File tree

7 files changed

+63
-65
lines changed

7 files changed

+63
-65
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "yarn",
33
"installationMethod": "unknown",
4-
"version": "1.22.19",
4+
"version": "1.22.20",
55
"packageManager": "yarn@1.22.17",
66
"license": "BSD-2-Clause",
77
"preferGlobal": true,
@@ -40,6 +40,7 @@
4040
"object-path": "^0.11.2",
4141
"proper-lockfile": "^2.0.0",
4242
"puka": "^1.0.0",
43+
"punycode": "1.4.1",
4344
"read": "^1.0.7",
4445
"request": "^2.87.0",
4546
"request-capture-har": "^1.2.2",

scripts/build-webpack.js

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const resolve = require('resolve');
77
const util = require('util');
88
const fs = require('fs');
99

10+
// Otherwise Webpack 4 will be "helpful" and automatically mark the `punycode` package as external,
11+
// despite us wanting to bundle it since it will be removed from future Node.js versions.
12+
delete process.binding("natives").punycode;
13+
1014
const version = require('../package.json').version;
1115
const basedir = path.join(__dirname, '../');
1216
const babelRc = JSON.parse(fs.readFileSync(path.join(basedir, '.babelrc'), 'utf8'));
@@ -74,6 +78,11 @@ const compiler = webpack({
7478
[`artifacts/yarn-${version}.js`]: path.join(basedir, 'src/cli/index.js'),
7579
'packages/lockfile/index.js': path.join(basedir, 'src/lockfile/index.js'),
7680
},
81+
resolve: {
82+
alias: {
83+
punycode: require.resolve(`punycode/`),
84+
},
85+
},
7786
module: {
7887
rules: [
7988
{
@@ -126,6 +135,11 @@ compiler.run((err, stats) => {
126135
const compilerLegacy = webpack({
127136
// devtool: 'inline-source-map',
128137
entry: path.join(basedir, 'src/cli/index.js'),
138+
resolve: {
139+
alias: {
140+
punycode: require.resolve(`punycode/`),
141+
},
142+
},
129143
module: {
130144
rules: [
131145
{

src/cli/commands/policies.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const {run, setFlags, examples} = buildSubCommands('policies', {
157157
bundleUrl = 'https://nightly.yarnpkg.com/latest.js';
158158
bundleVersion = 'nightly';
159159
} else if (V2_NAMES.includes(range) || isLocalFile(range) || isV2Version(range)) {
160-
const normalizedRange = range === `canary` ? `canary` : `stable`;
160+
const normalizedRange = isV2Version(range) ? range : range === `canary` ? `canary` : `stable`;
161161

162162
if (process.env.COREPACK_ROOT) {
163163
await child.spawn(

src/cli/index.js

+35-57
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import handleSignals from '../util/signal-handler.js';
2626
import {boolify, boolifyWithDefault} from '../util/conversion.js';
2727
import {ProcessTermError} from '../errors';
2828

29+
const chalk = require('chalk');
30+
2931
process.stdout.prependListener('error', err => {
3032
// swallow err only if downstream consumer process closed pipe early
3133
if (err.code === 'EPIPE' || err.code === 'ERR_STREAM_DESTROYED') {
@@ -263,6 +265,39 @@ export async function main({
263265
reporter.initPeakMemoryCounter();
264266

265267
const config = new Config(reporter);
268+
269+
const projectRoot = findProjectRoot(commander.cwd);
270+
const cwd = command.shouldRunInCurrentCwd ? commander.cwd : projectRoot;
271+
272+
if (!process.env.COREPACK_ROOT) {
273+
const rootManifest = await config.readRootManifest(projectRoot);
274+
if (typeof rootManifest.packageManager === `string`) {
275+
if (!rootManifest.packageManager.match(/^yarn@[01]\./)) {
276+
reporter.error(
277+
`This project's package.json defines ${chalk.gray('"packageManager": "yarn@')}${chalk.yellow(
278+
`${rootManifest.packageManager.replace(/^yarn@/, ``).replace(/\+.*/, ``)}`,
279+
)}${chalk.gray(`"`)}. However the current global version of Yarn is ${chalk.yellow(version)}.`,
280+
);
281+
282+
process.stderr.write(`\n`);
283+
process.stderr.write(
284+
`Presence of the ${chalk.gray(
285+
`"packageManager"`,
286+
)} field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.\n`,
287+
);
288+
289+
process.stderr.write(
290+
`Corepack must currently be enabled by running ${chalk.magenta(
291+
`corepack enable`,
292+
)} in your terminal. For more information, check out ${chalk.blueBright(`https://yarnpkg.com/corepack`)}.\n`,
293+
);
294+
295+
exit(1);
296+
return;
297+
}
298+
}
299+
}
300+
266301
const outputWrapperEnabled = boolifyWithDefault(process.env.YARN_WRAP_OUTPUT, true);
267302
const shouldWrapOutput =
268303
outputWrapperEnabled &&
@@ -466,61 +501,6 @@ export async function main({
466501
});
467502
};
468503

469-
function onUnexpectedError(err: Error) {
470-
function indent(str: string): string {
471-
return '\n ' + str.trim().split('\n').join('\n ');
472-
}
473-
474-
const log = [];
475-
log.push(`Arguments: ${indent(process.argv.join(' '))}`);
476-
log.push(`PATH: ${indent(process.env.PATH || 'undefined')}`);
477-
log.push(`Yarn version: ${indent(version)}`);
478-
log.push(`Node version: ${indent(process.versions.node)}`);
479-
log.push(`Platform: ${indent(process.platform + ' ' + process.arch)}`);
480-
481-
log.push(`Trace: ${indent(err.stack)}`);
482-
483-
// add manifests
484-
for (const registryName of registryNames) {
485-
const possibleLoc = path.join(config.cwd, registries[registryName].filename);
486-
const manifest = fs.existsSync(possibleLoc) ? fs.readFileSync(possibleLoc, 'utf8') : 'No manifest';
487-
log.push(`${registryName} manifest: ${indent(manifest)}`);
488-
}
489-
490-
// lockfile
491-
const lockLoc = path.join(
492-
config.lockfileFolder || config.cwd, // lockfileFolder might not be set at this point
493-
constants.LOCKFILE_FILENAME,
494-
);
495-
const lockfile = fs.existsSync(lockLoc) ? fs.readFileSync(lockLoc, 'utf8') : 'No lockfile';
496-
log.push(`Lockfile: ${indent(lockfile)}`);
497-
498-
const errorReportLoc = writeErrorReport(log);
499-
500-
reporter.error(reporter.lang('unexpectedError', err.message));
501-
502-
if (errorReportLoc) {
503-
reporter.info(reporter.lang('bugReport', errorReportLoc));
504-
}
505-
}
506-
507-
function writeErrorReport(log): ?string {
508-
const errorReportLoc = config.enableMetaFolder
509-
? path.join(config.cwd, constants.META_FOLDER, 'yarn-error.log')
510-
: path.join(config.cwd, 'yarn-error.log');
511-
512-
try {
513-
fs.writeFileSync(errorReportLoc, log.join('\n\n') + '\n');
514-
} catch (err) {
515-
reporter.error(reporter.lang('fileWriteError', errorReportLoc, err.message));
516-
return undefined;
517-
}
518-
519-
return errorReportLoc;
520-
}
521-
522-
const cwd = command.shouldRunInCurrentCwd ? commander.cwd : findProjectRoot(commander.cwd);
523-
524504
const folderOptionKeys = ['linkFolder', 'globalFolder', 'preferredCacheFolder', 'cacheFolder', 'modulesFolder'];
525505

526506
// Resolve all folder options relative to cwd
@@ -608,8 +588,6 @@ export async function main({
608588

609589
if (err instanceof MessageError) {
610590
reporter.error(err.message);
611-
} else {
612-
onUnexpectedError(err);
613591
}
614592

615593
if (command.getDocsInfo) {

src/rc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function getRcConfigForFolder(cwd: string): {[key: string]: string} {
5555
function loadRcFile(fileText: string, filePath: string): {[key: string]: string} {
5656
let {object: values} = parse(fileText, filePath);
5757

58-
if (filePath.match(/\.yml$/) && typeof values.yarnPath === 'string') {
58+
if (filePath.match(/\.yml$/) && values && typeof values.yarnPath === 'string') {
5959
values = {'yarn-path': values.yarnPath};
6060
}
6161

src/util/child.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import BlockingQueue from './blocking-queue.js';
66
import {ProcessSpawnError, ProcessTermError} from '../errors.js';
77
import {promisify} from './promise.js';
88

9+
const os = require('os');
910
const child = require('child_process');
1011
const fs = require('fs');
1112
const path = require('path');
@@ -46,8 +47,10 @@ export function forkp(program: string, args: Array<string>, opts?: Object): Prom
4647
reject(error);
4748
});
4849

49-
proc.on('close', exitCode => {
50-
resolve(exitCode);
50+
proc.on('close', (exitCode: number, signal: string) => {
51+
const finalExitCode =
52+
typeof exitCode !== `undefined` && exitCode !== null ? exitCode : 128 + os.constants.signals[signal];
53+
resolve(finalExitCode);
5154
});
5255
});
5356
}
@@ -63,8 +66,10 @@ export function spawnp(program: string, args: Array<string>, opts?: Object): Pro
6366
reject(error);
6467
});
6568

66-
proc.on('close', exitCode => {
67-
resolve(exitCode);
69+
proc.on('close', (exitCode: number, signal: string) => {
70+
const finalExitCode =
71+
typeof exitCode !== `undefined` && exitCode !== null ? exitCode : 128 + os.constants.signals[signal];
72+
resolve(finalExitCode);
6873
});
6974
});
7075
}

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -6140,7 +6140,7 @@ punycode@1.3.2:
61406140
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d"
61416141
integrity sha1-llOgNvt8HuQjQvIyXM7v6jkmxI0=
61426142

6143-
punycode@^1.2.4, punycode@^1.4.1:
6143+
punycode@1.4.1, punycode@^1.2.4, punycode@^1.4.1:
61446144
version "1.4.1"
61456145
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
61466146
integrity sha1-wNWmOycYgArY4esPpSachN1BhF4=

0 commit comments

Comments
 (0)