Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sets the default compression to 0 #5526

Merged
merged 11 commits into from Jun 26, 2023
34 changes: 34 additions & 0 deletions .yarn/versions/6c7747db.yml
@@ -0,0 +1,34 @@
releases:
"@yarnpkg/cli": major
"@yarnpkg/core": major
"@yarnpkg/plugin-essentials": major

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@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/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
29 changes: 18 additions & 11 deletions .yarnrc.yml
@@ -1,22 +1,18 @@
changesetIgnorePatterns:
- ".github/**"
- ".yarn/cache/**"
- .github/**
- .yarn/cache/**
- "**/*.test.{js,ts}"
- "packages/*/tests/**"
- "packages/plugin-compat/extra/**"
- "packages/gatsby/**"
- packages/*/tests/**
- packages/plugin-compat/extra/**
- packages/gatsby/**

enableGlobalCache: false
compressionLevel: mixed

pnpEnableEsmLoader: true
enableGlobalCache: false

immutablePatterns:
- .pnp.*

supportedArchitectures:
os: [darwin, linux, win32]
cpu: [x64, arm64]

initScope: yarnpkg

npmPublishAccess: public
Expand Down Expand Up @@ -73,8 +69,19 @@ packageExtensions:
typedoc-plugin-yarn:
optional: true

pnpEnableEsmLoader: true

preferInteractive: true

supportedArchitectures:
cpu:
- x64
- arm64
os:
- darwin
- linux
- win32

telemetryUserId: yarnpkg/berry

yarnPath: scripts/run-yarn.js
6 changes: 6 additions & 0 deletions packages/gatsby/content/advanced/error-codes.md
Expand Up @@ -424,3 +424,9 @@ To use it, simply pass it the `p`-prefixed code provided in the original peer re
```
yarn explain peer-requirements pf649cd
```

## YN0087 - `MIGRATION_SUCCESS`

When migrating from a major version to the next, some default values may change. When that's the case, Yarn will attempt to temporarily keep the old default by pinning their values in your configuration settings.

To see the exact changes applied when this message appears, check the content of the `.yarnrc.yml` file and any other file that may appear modified in your repository checkout.
92 changes: 52 additions & 40 deletions packages/plugin-essentials/sources/commands/install.ts
@@ -1,10 +1,28 @@
import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli';
import {Configuration, Cache, MessageName, Project, ReportError, StreamReport, formatUtils, InstallMode, execUtils, structUtils, LEGACY_PLUGINS} from '@yarnpkg/core';
import {xfs, ppath, Filename, PortablePath} from '@yarnpkg/fslib';
import {parseSyml, stringifySyml} from '@yarnpkg/parsers';
import CI from 'ci-info';
import {Command, Option, Usage, UsageError} from 'clipanion';
import * as t from 'typanion';
import {BaseCommand, WorkspaceRequiredError} from '@yarnpkg/cli';
import {Configuration, Cache, MessageName, Project, ReportError, StreamReport, formatUtils, InstallMode, execUtils, structUtils, LEGACY_PLUGINS, ConfigurationValueMap} from '@yarnpkg/core';
import {xfs, ppath, Filename, PortablePath} from '@yarnpkg/fslib';
import {parseSyml, stringifySyml} from '@yarnpkg/parsers';
import CI from 'ci-info';
import {Command, Option, Usage, UsageError} from 'clipanion';
import * as t from 'typanion';

const LOCKFILE_MIGRATION_RULES: Array<{
selector: (version: number) => boolean;
name: keyof ConfigurationValueMap;
value: any;
}> = [{
selector: v => v === -1,
name: `nodeLinker`,
value: `node-modules`,
}, {
selector: v => v < 8,
name: `enableGlobalCache`,
value: false,
}, {
selector: v => v < 8,
name: `compressionLevel`,
value: `mixed`,
}];

// eslint-disable-next-line arca/no-default-export
export default class YarnCommand extends BaseCommand {
Expand Down Expand Up @@ -264,39 +282,6 @@ export default class YarnCommand extends BaseCommand {
}
}

if (configuration.projectCwd !== null && typeof configuration.sources.get(`nodeLinker`) === `undefined`) {
const projectCwd = configuration.projectCwd;

let content;
try {
content = await xfs.readFilePromise(ppath.join(projectCwd, Filename.lockfile), `utf8`);
} catch {}

// If migrating from a v1 install, we automatically enable the node-modules linker,
// since that's likely what the author intended to do.
if (content?.includes(`yarn lockfile v1`)) {
const nmReport = await StreamReport.start({
configuration,
json: this.json,
stdout: this.context.stdout,
includeFooter: false,
}, async report => {
report.reportInfo(MessageName.AUTO_NM_SUCCESS, `Migrating from Yarn 1; automatically enabling the compatibility node-modules linker 👍`);
report.reportSeparator();

configuration.use(`<compat>`, {nodeLinker: `node-modules`}, projectCwd, {overwrite: true});

await Configuration.updateConfiguration(projectCwd, {
nodeLinker: `node-modules`,
});
});

if (nmReport.hasErrors()) {
return nmReport.exitCode();
}
}
}

if (configuration.projectCwd !== null) {
const telemetryReport = await StreamReport.start({
configuration,
Expand All @@ -317,6 +302,33 @@ export default class YarnCommand extends BaseCommand {
}

const {project, workspace} = await Project.find(configuration, this.context.cwd);

const compatReport = await StreamReport.start({
configuration,
json: this.json,
stdout: this.context.stdout,
includeFooter: false,
}, async report => {
const newSettings: Record<string, any> = {};

for (const rule of LOCKFILE_MIGRATION_RULES) {
if (rule.selector(project.lockfileLastVersion) && typeof configuration.sources.get(rule.name) === `undefined`) {
configuration.use(`<compat>`, {[rule.name]: rule.value}, project.cwd, {overwrite: true});
newSettings[rule.name] = rule.value;
}
}

if (Object.keys(newSettings).length > 0) {
await Configuration.updateConfiguration(project.cwd, newSettings);

report.reportInfo(MessageName.MIGRATION_SUCCESS, `Migrated your project to the latest Yarn version 🚀`);
report.reportSeparator();
}
});

if (compatReport.hasErrors())
return compatReport.exitCode();

const cache = await Cache.find(configuration, {immutable: immutableCache, check: this.checkCache});

if (!workspace)
Expand Down
3 changes: 1 addition & 2 deletions packages/yarnpkg-core/sources/Configuration.ts
@@ -1,5 +1,4 @@
import {Filename, PortablePath, npath, ppath, xfs} from '@yarnpkg/fslib';
import {DEFAULT_COMPRESSION_LEVEL} from '@yarnpkg/libzip';
import {parseSyml, stringifySyml} from '@yarnpkg/parsers';
import camelcase from 'camelcase';
import {isCI, isPR, GITHUB_ACTIONS} from 'ci-info';
Expand Down Expand Up @@ -221,7 +220,7 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
description: `Zip files compression level, from 0 to 9 or mixed (a variant of 9, which stores some files uncompressed, when compression doesn't yield good results)`,
type: SettingsType.NUMBER,
values: [`mixed`, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
default: DEFAULT_COMPRESSION_LEVEL,
default: 0,
},
virtualFolder: {
description: `Folder where the virtual packages (cf doc) will be mapped on the disk (must be named __virtual__)`,
Expand Down
1 change: 1 addition & 0 deletions packages/yarnpkg-core/sources/MessageName.ts
Expand Up @@ -98,6 +98,7 @@ export enum MessageName {
CONSTRAINTS_CHECK_FAILED = 84,
UPDATED_RESOLUTION_RECORD = 85,
EXPLAIN_PEER_DEPENDENCIES_CTA = 86,
MIGRATION_SUCCESS = 87,
}

export function stringifyMessageName(name: MessageName | number): string {
Expand Down
6 changes: 5 additions & 1 deletion packages/yarnpkg-core/sources/Project.ts
Expand Up @@ -44,7 +44,7 @@ import {IdentHash, DescriptorHash, LocatorHash, PackageExtensionStatus} from './
// When upgraded, the lockfile entries have to be resolved again (but the specific
// versions are still pinned, no worry). Bump it when you change the fields within
// the Package type; no more no less.
const LOCKFILE_VERSION = 7;
const LOCKFILE_VERSION = 8;
merceyz marked this conversation as resolved.
Show resolved Hide resolved

// Same thing but must be bumped when the members of the Project class changes (we
// don't recommend our users to check-in this file, so it's fine to bump it even
Expand Down Expand Up @@ -232,6 +232,7 @@ export class Project {
* If true, the data contained within `originalPackages` are from a different
* lockfile version and need to be refreshed.
*/
public lockfileLastVersion: number = 0;
public lockfileNeedsRefresh: boolean = false;

/**
Expand Down Expand Up @@ -340,6 +341,7 @@ export class Project {
const lockfileVersion = parsed.__metadata.version;
const cacheKey = parsed.__metadata.cacheKey;

this.lockfileLastVersion = lockfileVersion;
this.lockfileNeedsRefresh = lockfileVersion < LOCKFILE_VERSION;

for (const key of Object.keys(parsed)) {
Expand Down Expand Up @@ -395,6 +397,8 @@ export class Project {
this.storedResolutions.set(descriptor.descriptorHash, locator.locatorHash);
}
}
} else if (content.includes(`yarn lockfile v1`)) {
this.lockfileLastVersion = -1;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -2,7 +2,7 @@
# Manual changes might be lost - proceed with caution!

__metadata:
version: 7
version: 8
cacheKey: 10

"@actions/core@npm:^1.2.6":
Expand Down