Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: update core hooks
  • Loading branch information
jdanil committed Jun 5, 2022
commit a0f5b8021f5949561a71b2d6fd0475dad37ce1a4
19 changes: 11 additions & 8 deletions packages/yarnpkg-core/sources/CorePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Descriptor, Locator} from './types';

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

validateProject: async (project: Project, report: {
validateProject: async ({ project, report}: { project: Project, report: {
reportWarning: (name: MessageName, text: string) => void;
reportError: (name: MessageName, text: string) => void;
}) => {
}}) => {
for (const workspace of project.workspaces) {
const workspaceName = structUtils.prettyWorkspace(project.configuration, workspace);

await project.configuration.triggerHook(hooks => {
return hooks.validateWorkspace;
}, workspace, {
reportWarning: (name: MessageName, text: string) => report.reportWarning(name, `${workspaceName}: ${text}`),
reportError: (name: MessageName, text: string) => report.reportError(name, `${workspaceName}: ${text}`),
}, {
workspace,
report: {
reportWarning: (name: MessageName, text: string) => report.reportWarning(name, `${workspaceName}: ${text}`),
reportError: (name: MessageName, text: string) => report.reportError(name, `${workspaceName}: ${text}`),
},
});
}
},

validateWorkspace: async (workspace: Workspace, report: {
validateWorkspace: async ({ workspace, report }: { workspace: Workspace, report: {
reportWarning: (name: MessageName, text: string) => void;
reportError: (name: MessageName, text: string) => void;
}) => {
}}) => {
// Validate manifest
const {manifest} = workspace;

Expand Down
15 changes: 11 additions & 4 deletions packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,11 @@ export class Project {
for (const [identHash, descriptor] of pkg.dependencies) {
const dependency = await this.configuration.reduceHook(hooks => {
return hooks.reduceDependency;
}, descriptor, this, pkg, descriptor, {
}, {
dependency: descriptor,
project: this,
locator: pkg,
initialDependency: descriptor,
resolver,
resolveOptions,
});
Expand Down Expand Up @@ -1510,9 +1514,12 @@ export class Project {
}, async () => {
await this.configuration.triggerHook(hooks => {
return hooks.validateProject;
}, this, {
reportWarning: opts.report.reportWarning.bind(opts.report),
reportError: opts.report.reportError.bind(opts.report),
}, {
project: this,
report: {
reportWarning: opts.report.reportWarning.bind(opts.report),
reportError: opts.report.reportError.bind(opts.report),
},
});
});

Expand Down
5 changes: 4 additions & 1 deletion packages/yarnpkg-core/sources/httpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ export async function request(target: string | URL, body: Body, {configuration,

const executor = await configuration.reduceHook(hooks => {
return hooks.wrapNetworkRequest;
}, realRequest, {target, body, configuration, headers, jsonRequest, jsonResponse, method});
}, {
executor: realRequest,
extra: {target, body, configuration, headers, jsonRequest, jsonResponse, method},
});

return await executor();
}
Expand Down
10 changes: 8 additions & 2 deletions packages/yarnpkg-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,14 @@ export async function executePackageScript(locator: Locator, scriptName: string,

const executor = await project.configuration.reduceHook(hooks => {
return hooks.wrapScriptExecution;
}, realExecutor, project, locator, scriptName, {
script, args, cwd: realCwd, env, stdin, stdout, stderr,
}, {
executor: realExecutor,
project,
locator,
scriptName,
extra: {
script, args, cwd: realCwd, env, stdin, stdout, stderr,
}
});

return await executor();
Expand Down