Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .yarn/versions/b3d80a1d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
releases:
"@yarnpkg/cli": major
"@yarnpkg/core": major
"@yarnpkg/doctor": major
"@yarnpkg/plugin-essentials": major
"@yarnpkg/plugin-exec": major
"@yarnpkg/plugin-file": major
"@yarnpkg/plugin-git": major
"@yarnpkg/plugin-http": major
"@yarnpkg/plugin-link": major
"@yarnpkg/plugin-npm": major
"@yarnpkg/plugin-patch": major
"@yarnpkg/plugin-typescript": major

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ Yarn now accepts sponsorships! Please give a look at our [OpenCollective](https:
- Plugins cannot access the Clipanion 2 APIs anymore (upgrade to [Clipanion 3](https://github.com/arcanis/clipanion))
- Plugins cannot access the internal copy of Yup anymore (use [Typanion](https://github.com/arcanis/typanion) instead)

### **API Changes**

The following changes only affect people writing Yarn plugins:

- The `dependencies` field sent returned by `Resolver#resolve` must now be the result of a `Configuration#normalizeDependencyMap` call. This change is prompted by a refactoring of how default protocols (ie `npm:`) are injected into descriptors. The previous implementation caused various descriptors to never be normalized, which made it difficult to know what were the descriptors each function should expect.

- Similarly, the descriptors returned by `Resolve#getResolutionDependencies` are now expected to be the result of `Configuration#normalizeDependency` calls.

- Note that this only applies to the `dependencies` field; the `peerDependencies` field is unchanged, as it must only contains semver ranges without any protocol (with an exception for `workspace:`, but that's not relevant here).

- The `Resolve#getResolutionDependencies` function must now return an object of arbitrary string keys and descriptor values (instead of a map with `DescriptorHash` keys). Those descriptors will be resolved and assigned to the same keys as the initial object. This change allows resolvers to wrap resolution dependencies from other resolvers, which wasn't possible before since it'd have caused the key to change.

### Installs

- The pnpm linker no longer tries to remove `node_modules` directory, when `node-modules` linker is active
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ describe(`Commands`, () => {
expect(lock).toMatchObject({
[`inject-node-gyp@npm:^1.0.0`]: {
dependencies: {
[`node-gyp`]: `latest`,
[`node-gyp`]: `npm:latest`,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe(`Commands`, () => {
});

expect(manifest.resolutions).toEqual({
[`[email protected]`]: `patch:no-deps@npm%3A1.0.0#~/.yarn/patches/no-deps-npm-1.0.0-cf533b267a.patch`,
[`no-deps@npm:1.0.0`]: `patch:no-deps@npm%3A1.0.0#~/.yarn/patches/no-deps-npm-1.0.0-cf533b267a.patch`,
});
}),
);
Expand Down Expand Up @@ -196,7 +196,7 @@ describe(`Commands`, () => {
});

expect(manifest.resolutions).toEqual({
[`[email protected]`]: `patch:peer-deps-lvl1@npm%3A1.0.0#~/.yarn/patches/peer-deps-lvl1-npm-1.0.0-894d37389e.patch`,
[`peer-deps-lvl1@npm:1.0.0`]: `patch:peer-deps-lvl1@npm%3A1.0.0#~/.yarn/patches/peer-deps-lvl1-npm-1.0.0-894d37389e.patch`,
});
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`Features Merge Conflict Resolution it should properly fix merge conflic
# Manual changes might be lost - proceed with caution!

__metadata:
version: 6
version: 7
cacheKey: 0

\\"no-deps@npm:*\\":
Expand All @@ -25,7 +25,7 @@ __metadata:
version: 0.0.0-use.local
resolution: \\"root-workspace-0b6124@workspace:.\\"
dependencies:
no-deps: \\"*\\"
no-deps: \\"npm:*\\"
languageName: unknown
linkType: soft
"
Expand Down Expand Up @@ -54,7 +54,7 @@ exports[`Features Merge Conflict Resolution it should properly fix merge conflic
# Manual changes might be lost - proceed with caution!

__metadata:
version: 6
version: 7
cacheKey: 0

<<<<<<< HEAD
Expand All @@ -74,7 +74,7 @@ no-deps@*:
version: 0.0.0-use.local
resolution: \\"root-workspace-0b6124@workspace:.\\"
dependencies:
no-deps: \\"*\\"
no-deps: \\"npm:*\\"
languageName: unknown
linkType: soft
>>>>>>> yarn2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`Features Pruned native deps should resolve all dependencies, regardless
# Manual changes might be lost - proceed with caution!

__metadata:
version: 6
version: 7
cacheKey: 0

\\"native-bar-x64@npm:1.0.0\\":
Expand Down Expand Up @@ -47,11 +47,11 @@ __metadata:
version: 1.0.0
resolution: \\"optional-native@npm:1.0.0\\"
dependencies:
native-bar-x64: 1.0.0
native-foo-x64: 1.0.0
native-foo-x86: 1.0.0
native-libc-glibc: 1.0.0
native-libc-musl: 1.0.0
native-bar-x64: \\"npm:1.0.0\\"
native-foo-x64: \\"npm:1.0.0\\"
native-foo-x86: \\"npm:1.0.0\\"
native-libc-glibc: \\"npm:1.0.0\\"
native-libc-musl: \\"npm:1.0.0\\"
dependenciesMeta:
native-bar-x64:
optional: true
Expand All @@ -71,7 +71,7 @@ __metadata:
version: 0.0.0-use.local
resolution: \\"root-workspace-0b6124@workspace:.\\"
dependencies:
optional-native: 1.0.0
optional-native: \\"npm:1.0.0\\"
languageName: unknown
linkType: soft
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ describe(`Features`, () => {

await execFile(`git`, [`checkout`, `master`], {cwd: path});
await execFile(`git`, [`checkout`, `-b`, `1.0.0`], {cwd: path});
await run(`set`, `resolution`, `no-deps@npm:*`, `1.0.0`);
await run(`set`, `resolution`, `no-deps@npm:*`, `npm:1.0.0`);
await execFile(`git`, [`add`, `-A`], {cwd: path});
await execFile(`git`, [`commit`, `-a`, `-m`, `commit-1.0.0`], {cwd: path});

await execFile(`git`, [`checkout`, `master`], {cwd: path});
await execFile(`git`, [`checkout`, `-b`, `2.0.0`], {cwd: path});
await run(`set`, `resolution`, `no-deps@npm:*`, `2.0.0`);
await run(`set`, `resolution`, `no-deps@npm:*`, `npm:2.0.0`);
await execFile(`git`, [`add`, `-A`], {cwd: path});
await execFile(`git`, [`commit`, `-a`, `-m`, `commit-2.0.0`], {cwd: path});

Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-compat/tests/patches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async function getDescriptorCandidates(descriptor: Descriptor) {
const resolver = configuration.makeResolver();
const resolveOptions: ResolveOptions = {project, resolver, report: new ThrowReport()};

const candidates = await resolver.getCandidates(descriptor, new Map(), resolveOptions);
const normalizedDescriptor = configuration.normalizeDependency(descriptor);
const candidates = await resolver.getCandidates(normalizedDescriptor, {}, resolveOptions);

return candidates;
});
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-essentials/sources/suggestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export async function getSuggestedDescriptors(request: Descriptor, {project, wor
reason: formatUtils.pretty(project.configuration, `(unavailable because enableNetwork is toggled off)`, `grey`),
});
} else {
let latest = await fetchDescriptorFrom(request, requestTag, {project, cache, workspace, preserveModifier: false});
let latest = await fetchDescriptorFrom(request, `${project.configuration.get(`defaultProtocol`)}${requestTag}`, {project, cache, workspace, preserveModifier: false});

if (latest) {
latest = applyModifier(latest, modifier);
Expand Down Expand Up @@ -367,7 +367,7 @@ export async function fetchDescriptorFrom(ident: Ident, range: string, {project,
// If we didn't bind it, `yarn add ./folder` wouldn't work.
const boundDescriptor = resolver.bindDescriptor(latestDescriptor, workspace.anchoredLocator, resolveOptions);

const candidateLocators = await resolver.getCandidates(boundDescriptor, new Map(), resolveOptions);
const candidateLocators = await resolver.getCandidates(boundDescriptor, {}, resolveOptions);

if (candidateLocators.length === 0)
return null;
Expand Down
18 changes: 9 additions & 9 deletions packages/plugin-exec/sources/ExecResolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Resolver, ResolveOptions, MinimalResolveOptions} from '@yarnpkg/core';
import {Descriptor, Locator, Manifest, DescriptorHash, Package} from '@yarnpkg/core';
import {LinkType} from '@yarnpkg/core';
import {miscUtils, structUtils, hashUtils} from '@yarnpkg/core';
import {Resolver, ResolveOptions, MinimalResolveOptions} from '@yarnpkg/core';
import {Descriptor, Locator, Manifest, Package} from '@yarnpkg/core';
import {LinkType} from '@yarnpkg/core';
import {miscUtils, structUtils, hashUtils} from '@yarnpkg/core';

import {PROTOCOL} from './constants';
import * as execUtils from './execUtils';
import {PROTOCOL} from './constants';
import * as execUtils from './execUtils';

// We use this for the generators to be regenerated without bumping the whole cache
const CACHE_VERSION = 2;
Expand Down Expand Up @@ -35,10 +35,10 @@ export class ExecResolver implements Resolver {
}

getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) {
return [];
return {};
}

async getCandidates(descriptor: Descriptor, dependencies: Map<DescriptorHash, Package>, opts: ResolveOptions) {
async getCandidates(descriptor: Descriptor, dependencies: Record<string, Package>, opts: ResolveOptions) {
if (!opts.fetchOptions)
throw new Error(`Assertion failed: This resolver cannot be used unless a fetcher is configured`);

Expand Down Expand Up @@ -84,7 +84,7 @@ export class ExecResolver implements Resolver {

conditions: manifest.getConditions(),

dependencies: manifest.dependencies,
dependencies: opts.project.configuration.normalizeDependencyMap(manifest.dependencies),
peerDependencies: manifest.peerDependencies,

dependenciesMeta: manifest.dependenciesMeta,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-file/sources/FileResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FileResolver implements Resolver {
}

getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) {
return [];
return {};
}

async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
Expand Down Expand Up @@ -96,7 +96,7 @@ export class FileResolver implements Resolver {

conditions: manifest.getConditions(),

dependencies: manifest.dependencies,
dependencies: opts.project.configuration.normalizeDependencyMap(manifest.dependencies),
peerDependencies: manifest.peerDependencies,

dependenciesMeta: manifest.dependenciesMeta,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-file/sources/TarballFileResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class TarballFileResolver implements Resolver {
}

getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) {
return [];
return {};
}

async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
Expand Down Expand Up @@ -79,7 +79,7 @@ export class TarballFileResolver implements Resolver {

conditions: manifest.getConditions(),

dependencies: manifest.dependencies,
dependencies: opts.project.configuration.normalizeDependencyMap(manifest.dependencies),
peerDependencies: manifest.peerDependencies,

dependenciesMeta: manifest.dependenciesMeta,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-git/sources/GitResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class GitResolver implements Resolver {
}

getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) {
return [];
return {};
}

async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
Expand Down Expand Up @@ -57,7 +57,7 @@ export class GitResolver implements Resolver {

conditions: manifest.getConditions(),

dependencies: manifest.dependencies,
dependencies: opts.project.configuration.normalizeDependencyMap(manifest.dependencies),
peerDependencies: manifest.peerDependencies,

dependenciesMeta: manifest.dependenciesMeta,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-http/sources/TarballHttpResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class TarballHttpResolver implements Resolver {
}

getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) {
return [];
return {};
}

async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
Expand Down Expand Up @@ -66,7 +66,7 @@ export class TarballHttpResolver implements Resolver {

conditions: manifest.getConditions(),

dependencies: manifest.dependencies,
dependencies: opts.project.configuration.normalizeDependencyMap(manifest.dependencies),
peerDependencies: manifest.peerDependencies,

dependenciesMeta: manifest.dependenciesMeta,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-link/sources/LinkResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class LinkResolver implements Resolver {
}

getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) {
return [];
return {};
}

async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
Expand Down Expand Up @@ -65,7 +65,7 @@ export class LinkResolver implements Resolver {

conditions: manifest.getConditions(),

dependencies: new Map([...manifest.dependencies]),
dependencies: opts.project.configuration.normalizeDependencyMap(manifest.dependencies),
peerDependencies: manifest.peerDependencies,

dependenciesMeta: manifest.dependenciesMeta,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-link/sources/RawLinkResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class RawLinkResolver implements Resolver {
}

getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) {
return [];
return {};
}

async getCandidates(descriptor: Descriptor, dependencies: unknown, opts: ResolveOptions) {
Expand Down
20 changes: 13 additions & 7 deletions packages/plugin-npm/sources/NpmRemapResolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Descriptor, Locator, MinimalResolveOptions, ResolveOptions, Resolver, DescriptorHash, Package} from '@yarnpkg/core';
import {structUtils} from '@yarnpkg/core';
import {Descriptor, Locator, MinimalResolveOptions, ResolveOptions, Resolver, Package} from '@yarnpkg/core';
import {structUtils} from '@yarnpkg/core';

import {PROTOCOL} from './constants';
import {PROTOCOL} from './constants';

export class NpmRemapResolver implements Resolver {
supportsDescriptor(descriptor: Descriptor, opts: MinimalResolveOptions) {
Expand Down Expand Up @@ -29,19 +29,25 @@ export class NpmRemapResolver implements Resolver {
}

getResolutionDependencies(descriptor: Descriptor, opts: MinimalResolveOptions) {
const nextDescriptor = structUtils.parseDescriptor(descriptor.range.slice(PROTOCOL.length), true);
const nextDescriptor = opts.project.configuration.normalizeDependency(
structUtils.parseDescriptor(descriptor.range.slice(PROTOCOL.length), true),
);

return opts.resolver.getResolutionDependencies(nextDescriptor, opts);
}

async getCandidates(descriptor: Descriptor, dependencies: Map<DescriptorHash, Package>, opts: ResolveOptions) {
const nextDescriptor = structUtils.parseDescriptor(descriptor.range.slice(PROTOCOL.length), true);
async getCandidates(descriptor: Descriptor, dependencies: Record<string, Package>, opts: ResolveOptions) {
const nextDescriptor = opts.project.configuration.normalizeDependency(
structUtils.parseDescriptor(descriptor.range.slice(PROTOCOL.length), true),
);

return await opts.resolver.getCandidates(nextDescriptor, dependencies, opts);
}

async getSatisfying(descriptor: Descriptor, references: Array<string>, opts: ResolveOptions) {
const nextDescriptor = structUtils.parseDescriptor(descriptor.range.slice(PROTOCOL.length), true);
const nextDescriptor = opts.project.configuration.normalizeDependency(
structUtils.parseDescriptor(descriptor.range.slice(PROTOCOL.length), true),
);

return opts.resolver.getSatisfying(nextDescriptor, references, opts);
}
Expand Down
Loading