Skip to content

Commit a0f5b80

Browse files
committed
chore: update core hooks
1 parent 56703af commit a0f5b80

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

packages/yarnpkg-core/sources/CorePlugin.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Descriptor, Locator} from './types';
88

99
export const CorePlugin: Plugin = {
1010
hooks: {
11-
reduceDependency: (dependency: Descriptor, project: Project, locator: Locator, initialDependency: Descriptor, {resolver, resolveOptions}: {resolver: Resolver, resolveOptions: ResolveOptions}) => {
11+
reduceDependency: ({ dependency, project, locator, initialDependency, resolver, resolveOptions }: { dependency: Descriptor, project: Project, locator: Locator, initialDependency: Descriptor, resolver: Resolver, resolveOptions: ResolveOptions }) => {
1212
for (const {pattern, reference} of project.topLevelWorkspace.manifest.resolutions) {
1313
if (pattern.from && pattern.from.fullName !== structUtils.stringifyIdent(locator))
1414
continue;
@@ -32,26 +32,29 @@ export const CorePlugin: Plugin = {
3232
return dependency;
3333
},
3434

35-
validateProject: async (project: Project, report: {
35+
validateProject: async ({ project, report}: { project: Project, report: {
3636
reportWarning: (name: MessageName, text: string) => void;
3737
reportError: (name: MessageName, text: string) => void;
38-
}) => {
38+
}}) => {
3939
for (const workspace of project.workspaces) {
4040
const workspaceName = structUtils.prettyWorkspace(project.configuration, workspace);
4141

4242
await project.configuration.triggerHook(hooks => {
4343
return hooks.validateWorkspace;
44-
}, workspace, {
45-
reportWarning: (name: MessageName, text: string) => report.reportWarning(name, `${workspaceName}: ${text}`),
46-
reportError: (name: MessageName, text: string) => report.reportError(name, `${workspaceName}: ${text}`),
44+
}, {
45+
workspace,
46+
report: {
47+
reportWarning: (name: MessageName, text: string) => report.reportWarning(name, `${workspaceName}: ${text}`),
48+
reportError: (name: MessageName, text: string) => report.reportError(name, `${workspaceName}: ${text}`),
49+
},
4750
});
4851
}
4952
},
5053

51-
validateWorkspace: async (workspace: Workspace, report: {
54+
validateWorkspace: async ({ workspace, report }: { workspace: Workspace, report: {
5255
reportWarning: (name: MessageName, text: string) => void;
5356
reportError: (name: MessageName, text: string) => void;
54-
}) => {
57+
}}) => {
5558
// Validate manifest
5659
const {manifest} = workspace;
5760

packages/yarnpkg-core/sources/Project.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,11 @@ export class Project {
672672
for (const [identHash, descriptor] of pkg.dependencies) {
673673
const dependency = await this.configuration.reduceHook(hooks => {
674674
return hooks.reduceDependency;
675-
}, descriptor, this, pkg, descriptor, {
675+
}, {
676+
dependency: descriptor,
677+
project: this,
678+
locator: pkg,
679+
initialDependency: descriptor,
676680
resolver,
677681
resolveOptions,
678682
});
@@ -1510,9 +1514,12 @@ export class Project {
15101514
}, async () => {
15111515
await this.configuration.triggerHook(hooks => {
15121516
return hooks.validateProject;
1513-
}, this, {
1514-
reportWarning: opts.report.reportWarning.bind(opts.report),
1515-
reportError: opts.report.reportError.bind(opts.report),
1517+
}, {
1518+
project: this,
1519+
report: {
1520+
reportWarning: opts.report.reportWarning.bind(opts.report),
1521+
reportError: opts.report.reportError.bind(opts.report),
1522+
},
15161523
});
15171524
});
15181525

packages/yarnpkg-core/sources/httpUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ export async function request(target: string | URL, body: Body, {configuration,
181181

182182
const executor = await configuration.reduceHook(hooks => {
183183
return hooks.wrapNetworkRequest;
184-
}, realRequest, {target, body, configuration, headers, jsonRequest, jsonResponse, method});
184+
}, {
185+
executor: realRequest,
186+
extra: {target, body, configuration, headers, jsonRequest, jsonResponse, method},
187+
});
185188

186189
return await executor();
187190
}

packages/yarnpkg-core/sources/scriptUtils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,14 @@ export async function executePackageScript(locator: Locator, scriptName: string,
431431

432432
const executor = await project.configuration.reduceHook(hooks => {
433433
return hooks.wrapScriptExecution;
434-
}, realExecutor, project, locator, scriptName, {
435-
script, args, cwd: realCwd, env, stdin, stdout, stderr,
434+
}, {
435+
executor: realExecutor,
436+
project,
437+
locator,
438+
scriptName,
439+
extra: {
440+
script, args, cwd: realCwd, env, stdin, stdout, stderr,
441+
}
436442
});
437443

438444
return await executor();

0 commit comments

Comments
 (0)