Skip to content
Draft
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
32 changes: 32 additions & 0 deletions .yarn/versions/2ea03f30.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
releases:
"@yarnpkg/builder": patch
"@yarnpkg/cli": patch
"@yarnpkg/core": major
"@yarnpkg/doctor": patch
"@yarnpkg/extensions": patch
"@yarnpkg/nm": patch
"@yarnpkg/plugin-compat": major
"@yarnpkg/plugin-constraints": patch
"@yarnpkg/plugin-dlx": patch
"@yarnpkg/plugin-essentials": major
"@yarnpkg/plugin-exec": patch
"@yarnpkg/plugin-file": patch
"@yarnpkg/plugin-git": major
"@yarnpkg/plugin-github": major
"@yarnpkg/plugin-http": patch
"@yarnpkg/plugin-init": patch
"@yarnpkg/plugin-interactive-tools": patch
"@yarnpkg/plugin-link": patch
"@yarnpkg/plugin-nm": patch
"@yarnpkg/plugin-npm": major
"@yarnpkg/plugin-npm-cli": patch
"@yarnpkg/plugin-pack": major
"@yarnpkg/plugin-patch": major
"@yarnpkg/plugin-pnp": major
"@yarnpkg/plugin-pnpm": patch
"@yarnpkg/plugin-stage": major
"@yarnpkg/plugin-typescript": major
"@yarnpkg/plugin-version": patch
"@yarnpkg/plugin-workspace-tools": patch
"@yarnpkg/pnpify": patch
"@yarnpkg/sdks": patch
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The following changes only affect people writing Yarn plugins:

- The `getCustomDataKey` function in `Installer` from `@yarnpkg/core` has been moved to `Linker`.

- All hooks now accept an object instead of positional parameters.

### Compatibility

- The patched filesystem now supports `ftruncate`.
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/content/advanced/plugin-tutorial.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module.exports = {
name: `plugin-hello-world`,
factory: require => ({
hooks: {
setupScriptEnvironment(project, scriptEnv) {
setupScriptEnvironment({project, env: scriptEnv}) {
scriptEnv.HELLO_WORLD = `my first plugin!`;
},
},
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-compat/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const PATCHES = new Map([

const plugin: Plugin<CoreHooks & PatchHooks> = {
hooks: {
registerPackageExtensions: async (configuration, registerPackageExtension) => {
registerPackageExtensions: async ({registerPackageExtension}) => {
for (const [descriptorStr, extensionData] of packageExtensions) {
registerPackageExtension(structUtils.parseDescriptor(descriptorStr, true), extensionData);
}
},

getBuiltinPatch: async (project, name) => {
getBuiltinPatch: async ({name}) => {
const TAG = `compat/`;
if (!name.startsWith(TAG))
return undefined;
Expand All @@ -31,7 +31,7 @@ const plugin: Plugin<CoreHooks & PatchHooks> = {
return typeof patch !== `undefined` ? patch : null;
},

reduceDependency: async (dependency, project, locator, initialDescriptor) => {
reduceDependency: async ({dependency}) => {
const patch = PATCHES.get(dependency.identHash);
if (typeof patch === `undefined`)
return dependency;
Expand Down
40 changes: 20 additions & 20 deletions packages/plugin-essentials/sources/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,19 @@ export default class AddCommand extends BaseCommand {

let askedQuestions = false;

const afterWorkspaceDependencyAdditionList: Array<[
Workspace,
suggestUtils.Target,
Descriptor,
Array<suggestUtils.Strategy>,
]> = [];

const afterWorkspaceDependencyReplacementList: Array<[
Workspace,
suggestUtils.Target,
Descriptor,
Descriptor,
]> = [];
const afterWorkspaceDependencyAdditionList: Array<{
workspace: Workspace;
target: suggestUtils.Target;
descriptor: Descriptor;
strategies: Array<suggestUtils.Strategy>;
}> = [];

const afterWorkspaceDependencyReplacementList: Array<{
workspace: Workspace;
target: suggestUtils.Target;
fromDescriptor: Descriptor;
toDescriptor: Descriptor;
}> = [];

for (const [/*request*/, {suggestions}, target] of allSuggestions) {
let selected: Descriptor;
Expand Down Expand Up @@ -284,19 +284,19 @@ export default class AddCommand extends BaseCommand {
}

if (typeof current === `undefined`) {
afterWorkspaceDependencyAdditionList.push([
afterWorkspaceDependencyAdditionList.push({
workspace,
target,
selected,
descriptor: selected,
strategies,
]);
});
} else {
afterWorkspaceDependencyReplacementList.push([
afterWorkspaceDependencyReplacementList.push({
workspace,
target,
current,
selected,
]);
fromDescriptor: current,
toDescriptor: selected,
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-essentials/sources/commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export default class InfoCommand extends BaseCommand {

await configuration.triggerHook((hooks: Hooks) => {
return hooks.fetchPackageInfo;
}, pkg, extraSet, registerData);
}, {pkg, extra: extraSet, registerData});
}

if (pkg.bin.size > 0 && !isVirtual) {
Expand Down
16 changes: 8 additions & 8 deletions packages/plugin-essentials/sources/commands/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export default class RemoveCommand extends BaseCommand {
const unreferencedPatterns = [];
let hasChanged = false;

const afterWorkspaceDependencyRemovalList: Array<[
Workspace,
suggestUtils.Target,
Descriptor,
]> = [];
const afterWorkspaceDependencyRemovalList: Array<{
workspace: Workspace;
target: suggestUtils.Target;
descriptor: Descriptor;
}> = [];

for (const pattern of this.patterns) {
let isReferenced = false;
Expand Down Expand Up @@ -119,11 +119,11 @@ export default class RemoveCommand extends BaseCommand {

workspace.manifest[target].delete(identHash);

afterWorkspaceDependencyRemovalList.push([
afterWorkspaceDependencyRemovalList.push({
workspace,
target,
removedDescriptor,
]);
descriptor: removedDescriptor,
});

hasChanged = true;
isReferenced = true;
Expand Down
44 changes: 22 additions & 22 deletions packages/plugin-essentials/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,37 @@ export interface Hooks {
* dependencies into the manifest and running `yarn install` won't trigger
* it.
*/
afterWorkspaceDependencyAddition?: (
workspace: Workspace,
target: suggestUtils.Target,
descriptor: Descriptor,
strategies: Array<suggestUtils.Strategy>
) => Promise<void>;
afterWorkspaceDependencyAddition?: ({workspace, target, descriptor, strategies}: {
workspace: Workspace;
target: suggestUtils.Target;
descriptor: Descriptor;
strategies: Array<suggestUtils.Strategy>;
}) => Promise<void>;

/**
* Called when a dependency range is replaced inside a workspace. Note that
* this hook is only called by the CLI commands like `yarn add` - manually
* updating the dependencies from the manifest and running `yarn install`
* won't trigger it.
*/
afterWorkspaceDependencyReplacement?: (
workspace: Workspace,
target: suggestUtils.Target,
fromDescriptor: Descriptor,
toDescriptor: Descriptor,
) => Promise<void>;
afterWorkspaceDependencyReplacement?: ({workspace, target, fromDescriptor, toDescriptor}: {
workspace: Workspace;
target: suggestUtils.Target;
fromDescriptor: Descriptor;
toDescriptor: Descriptor;
}) => Promise<void>;

/**
* Called when a dependency range is removed from a workspace. Note that
* this hook is only called by the CLI commands like `yarn remove` - manually
* removing the dependencies from the manifest and running `yarn install`
* won't trigger it.
*/
afterWorkspaceDependencyRemoval?: (
workspace: Workspace,
target: suggestUtils.Target,
descriptor: Descriptor,
) => Promise<void>;
afterWorkspaceDependencyRemoval?: ({workspace, target, descriptor}: {
workspace: Workspace;
target: suggestUtils.Target;
descriptor: Descriptor;
}) => Promise<void>;

/**
* Called by `yarn info`. The `extra` field is the set of parameters passed
Expand All @@ -94,11 +94,11 @@ export interface Hooks {
* requested audit information (via `-X audit`), and call `registerData`
* with those information (retrieved dynamically) if they did.
*/
fetchPackageInfo?: (
pkg: Package,
extra: Set<string>,
registerData: (namespace: string, data: Array<formatUtils.Tuple> | {[key: string]: formatUtils.Tuple | undefined}) => void,
) => Promise<void>;
fetchPackageInfo?: ({pkg, extra, registerData}: {
pkg: Package;
extra: Set<string>;
registerData: (namespace: string, data: Array<formatUtils.Tuple> | {[key: string]: formatUtils.Tuple | undefined}) => void;
}) => Promise<void>;
}

declare module '@yarnpkg/core' {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-git/sources/GitFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export class GitFetcher implements Fetcher {
};
}

async downloadHosted(locator: Locator, opts: FetchOptions) {
return opts.project.configuration.reduceHook((hooks: Hooks) => {
async downloadHosted(locator: Locator, options: FetchOptions) {
return options.project.configuration.reduceHook((hooks: Hooks) => {
return hooks.fetchHostedRepository;
}, null as FetchResult | null, locator, opts);
}, {current: null as FetchResult | null, locator, options}, `current`);
}

async cloneFromRemote(locator: Locator, opts: FetchOptions) {
Expand Down
11 changes: 7 additions & 4 deletions packages/plugin-git/sources/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,13 @@ export async function fetchChangedWorkspaces({ref, project}: {ref: string | true
];
await project.configuration.triggerHook((hooks: Hooks) => {
return hooks.populateYarnPaths;
}, project, (path: PortablePath | null) => {
if (path != null) {
ignoredPaths.push(path);
}
}, {
project,
definePath: (path: PortablePath | null) => {
if (path != null) {
ignoredPaths.push(path);
}
},
});

const root = await fetchRoot(project.configuration.projectCwd);
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-git/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export interface Hooks {
* supports downloading repository tarballs, which are more efficient than
* cloning the repository (even without its history).
*/
fetchHostedRepository?: (
current: FetchResult | null,
locator: Locator,
opts: FetchOptions,
) => Promise<FetchResult | null>;
fetchHostedRepository?: ({current, locator, options}: {
current: FetchResult | null;
locator: Locator;
options: FetchOptions;
}) => Promise<FetchResult | null>;
}

declare module '@yarnpkg/core' {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-github/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {GithubFetcher} from './GithubFetcher';

const plugin: Plugin<GitHooks> = {
hooks: {
async fetchHostedRepository(previous, locator, opts) {
async fetchHostedRepository({previous, locator, options}) {
if (previous !== null)
return previous;

const fetcher = new GithubFetcher();
if (!fetcher.supports(locator, opts))
if (!fetcher.supports(locator, options))
return null;

try {
return await fetcher.fetch(locator, opts);
return await fetcher.fetch(locator, options);
} catch (error) {
return null;
}
Expand Down
10 changes: 6 additions & 4 deletions packages/plugin-npm/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ export interface Hooks {
* You can use this mechanism to dynamically query a CLI for the credentials for a
* specific registry.
*/
getNpmAuthenticationHeader?: (currentHeader: string | undefined, registry: string, {
configuration,
ident,
}: { configuration: Configuration, ident?: Ident }) => Promise<string | undefined>;
getNpmAuthenticationHeader?: ({currentHeader, registry, configuration, ident}: {
currentHeader?: string;
registry: string;
configuration: Configuration;
ident?: Ident;
}) => Promise<string | undefined>;
}


Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-npm/sources/npmHttpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async function getAuthenticationHeader(registry: string, {authType = AuthType.CO

const header = await configuration.reduceHook((hooks: Hooks) => {
return hooks.getNpmAuthenticationHeader;
}, undefined, registry, {configuration, ident});
}, {registry, configuration, ident}, `currentHeader`);

if (header)
return header;
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-pack/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export interface Hooks {
* parameter is allowed to be mutated at will, with the changes being only
* applied to the packed manifest (the original one won't be mutated).
*/
beforeWorkspacePacking?: (
workspace: Workspace,
rawManifest: object,
) => Promise<void> | void;
beforeWorkspacePacking?: ({workspace, rawManifest}: {
workspace: Workspace;
rawManifest: object;
}) => Promise<void> | void;
}

const DEPENDENCY_TYPES = [`dependencies`, `devDependencies`, `peerDependencies`];
const WORKSPACE_PROTOCOL = `workspace:`;

const beforeWorkspacePacking = (workspace: Workspace, rawManifest: any) => {
const beforeWorkspacePacking = ({workspace, rawManifest}: { workspace: Workspace, rawManifest: any }) => {
if (rawManifest.publishConfig) {
if (rawManifest.publishConfig.type)
rawManifest.type = rawManifest.publishConfig.type;
Expand Down
10 changes: 6 additions & 4 deletions packages/plugin-pack/sources/packUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ export async function genPackageManifest(workspace: Workspace): Promise<object>

await workspace.project.configuration.triggerHook(
(hooks: Hooks) => hooks.beforeWorkspacePacking,
workspace,
data,
{workspace, rawManifest: data},
);

return data;
Expand Down Expand Up @@ -190,8 +189,11 @@ export async function genPackList(workspace: Workspace) {

await configuration.triggerHook((hooks: StageHooks) => {
return hooks.populateYarnPaths;
}, project, (path: PortablePath | null) => {
maybeRejectPath(path);
}, {
project,
definePath: (path: PortablePath | null) => {
maybeRejectPath(path);
},
});

// All child workspaces are ignored
Expand Down
Loading