From 1815afdc22e53621e402c6e5e463a21222be4ebd Mon Sep 17 00:00:00 2001 From: Joshua David Date: Sun, 5 Jun 2022 17:51:36 +1000 Subject: [PATCH 1/5] chore!: update hooks to accept objects --- .yarn/versions/2ea03f30.yml | 32 +++++++++++++ CHANGELOG.md | 2 + .../content/advanced/plugin-tutorial.mdx | 2 +- packages/plugin-compat/sources/index.ts | 6 +-- .../plugin-essentials/sources/commands/add.ts | 40 ++++++++--------- .../sources/commands/info.ts | 2 +- .../sources/commands/remove.ts | 16 +++---- packages/plugin-essentials/sources/index.ts | 16 +++---- packages/plugin-git/sources/GitFetcher.ts | 6 +-- packages/plugin-git/sources/gitUtils.ts | 11 +++-- packages/plugin-git/sources/index.ts | 6 +-- packages/plugin-github/sources/index.ts | 6 +-- packages/plugin-npm/sources/index.ts | 10 +++-- packages/plugin-npm/sources/npmHttpUtils.ts | 2 +- packages/plugin-pack/sources/index.ts | 6 +-- packages/plugin-pack/sources/packUtils.ts | 10 +++-- packages/plugin-patch/sources/index.ts | 4 +- packages/plugin-patch/sources/patchUtils.ts | 2 +- packages/plugin-pnp/sources/index.ts | 4 +- .../plugin-stage/sources/commands/stage.ts | 7 ++- packages/plugin-stage/sources/index.ts | 4 +- packages/plugin-typescript/sources/index.ts | 10 ++--- .../yarnpkg-core/sources/Configuration.ts | 2 +- packages/yarnpkg-core/sources/Plugin.ts | 45 +++++++++---------- packages/yarnpkg-core/sources/scriptUtils.ts | 11 ++--- 25 files changed, 153 insertions(+), 109 deletions(-) create mode 100644 .yarn/versions/2ea03f30.yml diff --git a/.yarn/versions/2ea03f30.yml b/.yarn/versions/2ea03f30.yml new file mode 100644 index 000000000000..ba09e64996d7 --- /dev/null +++ b/.yarn/versions/2ea03f30.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0581fd76a0..24adbd852b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/packages/gatsby/content/advanced/plugin-tutorial.mdx b/packages/gatsby/content/advanced/plugin-tutorial.mdx index 2b6f4781badf..318a1c4d65d8 100644 --- a/packages/gatsby/content/advanced/plugin-tutorial.mdx +++ b/packages/gatsby/content/advanced/plugin-tutorial.mdx @@ -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!`; }, }, diff --git a/packages/plugin-compat/sources/index.ts b/packages/plugin-compat/sources/index.ts index 3cd3d4461530..519a4acd8198 100644 --- a/packages/plugin-compat/sources/index.ts +++ b/packages/plugin-compat/sources/index.ts @@ -14,13 +14,13 @@ const PATCHES = new Map([ const plugin: Plugin = { hooks: { - registerPackageExtensions: async (configuration, registerPackageExtension) => { + registerPackageExtensions: async ({ configuration, registerPackageExtension }) => { for (const [descriptorStr, extensionData] of packageExtensions) { registerPackageExtension(structUtils.parseDescriptor(descriptorStr, true), extensionData); } }, - getBuiltinPatch: async (project, name) => { + getBuiltinPatch: async ({ project, name }) => { const TAG = `compat/`; if (!name.startsWith(TAG)) return undefined; @@ -31,7 +31,7 @@ const plugin: Plugin = { return typeof patch !== `undefined` ? patch : null; }, - reduceDependency: async (dependency, project, locator, initialDescriptor) => { + reduceDependency: async ({ dependency, project, locator, initialDescriptor }) => { const patch = PATCHES.get(dependency.identHash); if (typeof patch === `undefined`) return dependency; diff --git a/packages/plugin-essentials/sources/commands/add.ts b/packages/plugin-essentials/sources/commands/add.ts index 5ea8ed8d2f27..6f5a034ab1bf 100644 --- a/packages/plugin-essentials/sources/commands/add.ts +++ b/packages/plugin-essentials/sources/commands/add.ts @@ -210,19 +210,19 @@ export default class AddCommand extends BaseCommand { let askedQuestions = false; - const afterWorkspaceDependencyAdditionList: Array<[ - Workspace, - suggestUtils.Target, - Descriptor, - Array, - ]> = []; - - const afterWorkspaceDependencyReplacementList: Array<[ - Workspace, - suggestUtils.Target, - Descriptor, - Descriptor, - ]> = []; + const afterWorkspaceDependencyAdditionList: Array<{ + workspace: Workspace, + target: suggestUtils.Target, + descriptor: Descriptor, + strategies: Array, + }> = []; + + const afterWorkspaceDependencyReplacementList: Array<{ + workspace: Workspace, + target: suggestUtils.Target, + fromDescriptor: Descriptor, + toDescriptor: Descriptor, + }> = []; for (const [/*request*/, {suggestions}, target] of allSuggestions) { let selected: Descriptor; @@ -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, + }); } } } diff --git a/packages/plugin-essentials/sources/commands/info.ts b/packages/plugin-essentials/sources/commands/info.ts index 94c97fba4a4a..2e0dd6fe6cd2 100644 --- a/packages/plugin-essentials/sources/commands/info.ts +++ b/packages/plugin-essentials/sources/commands/info.ts @@ -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) { diff --git a/packages/plugin-essentials/sources/commands/remove.ts b/packages/plugin-essentials/sources/commands/remove.ts index d0b0112fb50f..ad80a2db3d3a 100644 --- a/packages/plugin-essentials/sources/commands/remove.ts +++ b/packages/plugin-essentials/sources/commands/remove.ts @@ -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; @@ -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; diff --git a/packages/plugin-essentials/sources/index.ts b/packages/plugin-essentials/sources/index.ts index 8142e5c54a72..dce86d363dd6 100644 --- a/packages/plugin-essentials/sources/index.ts +++ b/packages/plugin-essentials/sources/index.ts @@ -53,12 +53,12 @@ export interface Hooks { * dependencies into the manifest and running `yarn install` won't trigger * it. */ - afterWorkspaceDependencyAddition?: ( + afterWorkspaceDependencyAddition?: ({ workspace, target, descriptor, strategies }: { workspace: Workspace, target: suggestUtils.Target, descriptor: Descriptor, strategies: Array - ) => Promise; + }) => Promise; /** * Called when a dependency range is replaced inside a workspace. Note that @@ -66,12 +66,12 @@ export interface Hooks { * updating the dependencies from the manifest and running `yarn install` * won't trigger it. */ - afterWorkspaceDependencyReplacement?: ( + afterWorkspaceDependencyReplacement?: ({ workspace, target, fromDescriptor, toDescriptor }: { workspace: Workspace, target: suggestUtils.Target, fromDescriptor: Descriptor, toDescriptor: Descriptor, - ) => Promise; + }) => Promise; /** * Called when a dependency range is removed from a workspace. Note that @@ -79,11 +79,11 @@ export interface Hooks { * removing the dependencies from the manifest and running `yarn install` * won't trigger it. */ - afterWorkspaceDependencyRemoval?: ( + afterWorkspaceDependencyRemoval?: ({ workspace, target, descriptor }: { workspace: Workspace, target: suggestUtils.Target, descriptor: Descriptor, - ) => Promise; + }) => Promise; /** * Called by `yarn info`. The `extra` field is the set of parameters passed @@ -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?: ( + fetchPackageInfo?: ({ pkg, extra, registerData }: { pkg: Package, extra: Set, registerData: (namespace: string, data: Array | {[key: string]: formatUtils.Tuple | undefined}) => void, - ) => Promise; + }) => Promise; } declare module '@yarnpkg/core' { diff --git a/packages/plugin-git/sources/GitFetcher.ts b/packages/plugin-git/sources/GitFetcher.ts index fe2a4fce86f0..488e9ef2b299 100644 --- a/packages/plugin-git/sources/GitFetcher.ts +++ b/packages/plugin-git/sources/GitFetcher.ts @@ -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}); } async cloneFromRemote(locator: Locator, opts: FetchOptions) { diff --git a/packages/plugin-git/sources/gitUtils.ts b/packages/plugin-git/sources/gitUtils.ts index 2dddc0b27562..7f2f0baa4468 100644 --- a/packages/plugin-git/sources/gitUtils.ts +++ b/packages/plugin-git/sources/gitUtils.ts @@ -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); diff --git a/packages/plugin-git/sources/index.ts b/packages/plugin-git/sources/index.ts index c89f04909f77..f76d378caa80 100644 --- a/packages/plugin-git/sources/index.ts +++ b/packages/plugin-git/sources/index.ts @@ -15,11 +15,11 @@ export interface Hooks { * supports downloading repository tarballs, which are more efficient than * cloning the repository (even without its history). */ - fetchHostedRepository?: ( + fetchHostedRepository?: ({ current, locator, options }: { current: FetchResult | null, locator: Locator, - opts: FetchOptions, - ) => Promise; + options: FetchOptions, + }) => Promise; } declare module '@yarnpkg/core' { diff --git a/packages/plugin-github/sources/index.ts b/packages/plugin-github/sources/index.ts index 15cf15e09a73..51ee35887b40 100644 --- a/packages/plugin-github/sources/index.ts +++ b/packages/plugin-github/sources/index.ts @@ -5,16 +5,16 @@ import {GithubFetcher} from './GithubFetcher'; const plugin: Plugin = { 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; } diff --git a/packages/plugin-npm/sources/index.ts b/packages/plugin-npm/sources/index.ts index ec0bee623991..9a1c7a7350d9 100644 --- a/packages/plugin-npm/sources/index.ts +++ b/packages/plugin-npm/sources/index.ts @@ -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; + getNpmAuthenticationHeader?: ({ currentHeader, registry, configuration, ident }: { + currentHeader: string | undefined, + registry: string, + configuration: Configuration, + ident?: Ident, + }) => Promise; } diff --git a/packages/plugin-npm/sources/npmHttpUtils.ts b/packages/plugin-npm/sources/npmHttpUtils.ts index 17bcb6b53ce9..18a100639681 100644 --- a/packages/plugin-npm/sources/npmHttpUtils.ts +++ b/packages/plugin-npm/sources/npmHttpUtils.ts @@ -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}); + }, {currentHeader: undefined, registry, configuration, ident}); if (header) return header; diff --git a/packages/plugin-pack/sources/index.ts b/packages/plugin-pack/sources/index.ts index 0bd76598a8aa..259fdb48865b 100644 --- a/packages/plugin-pack/sources/index.ts +++ b/packages/plugin-pack/sources/index.ts @@ -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?: ( + beforeWorkspacePacking?: ({ workspace, rawManifest }: { workspace: Workspace, rawManifest: object, - ) => Promise | void; + }) => Promise | 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; diff --git a/packages/plugin-pack/sources/packUtils.ts b/packages/plugin-pack/sources/packUtils.ts index 0613f7ffda2d..cfe30a7bea8c 100644 --- a/packages/plugin-pack/sources/packUtils.ts +++ b/packages/plugin-pack/sources/packUtils.ts @@ -146,8 +146,7 @@ export async function genPackageManifest(workspace: Workspace): Promise await workspace.project.configuration.triggerHook( (hooks: Hooks) => hooks.beforeWorkspacePacking, - workspace, - data, + {workspace, rawManifest: data}, ); return data; @@ -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 diff --git a/packages/plugin-patch/sources/index.ts b/packages/plugin-patch/sources/index.ts index 816826ba03f8..9a7eb7b19873 100644 --- a/packages/plugin-patch/sources/index.ts +++ b/packages/plugin-patch/sources/index.ts @@ -15,10 +15,10 @@ export interface Hooks { * syntax: `patch:builtin`. This is for instance how the TypeScript * patch is automatically registered. */ - getBuiltinPatch?: ( + getBuiltinPatch?: ({ project, name }: { project: Project, name: string, - ) => Promise; + }) => Promise; } declare module '@yarnpkg/core' { diff --git a/packages/plugin-patch/sources/patchUtils.ts b/packages/plugin-patch/sources/patchUtils.ts index 11945905f266..082c719f0ce4 100644 --- a/packages/plugin-patch/sources/patchUtils.ts +++ b/packages/plugin-patch/sources/patchUtils.ts @@ -198,7 +198,7 @@ export async function loadPatchFiles(parentLocator: Locator | null, patchPaths: onBuiltin: async name => { return await opts.project.configuration.firstHook((hooks: PatchHooks) => { return hooks.getBuiltinPatch; - }, opts.project, name); + }, {project: opts.project, name}); }, }, patchPath); diff --git a/packages/plugin-pnp/sources/index.ts b/packages/plugin-pnp/sources/index.ts index b01ebd2ebcdc..adcb2f0611a7 100644 --- a/packages/plugin-pnp/sources/index.ts +++ b/packages/plugin-pnp/sources/index.ts @@ -24,7 +24,7 @@ export const quotePathIfNeeded = (path: string) => { return /\s/.test(path) ? JSON.stringify(path) : path; }; -async function setupScriptEnvironment(project: Project, env: {[key: string]: string}, makePathWrapper: (name: string, argv0: string, args: Array) => Promise) { +async function setupScriptEnvironment({ project, env }: { project: Project, env: {[key: string]: string}, makePathWrapper: (name: string, argv0: string, args: Array) => Promise }) { const pnpPath = getPnpPath(project); let pnpRequire = `--require ${quotePathIfNeeded(npath.fromPortablePath(pnpPath.cjs))}`; @@ -49,7 +49,7 @@ async function setupScriptEnvironment(project: Project, env: {[key: string]: str } } -async function populateYarnPaths(project: Project, definePath: (path: PortablePath | null) => void) { +async function populateYarnPaths({ project, definePath }: { project: Project, definePath: (path: PortablePath | null) => void }) { const pnpPath = getPnpPath(project); definePath(pnpPath.cjs); definePath(pnpPath.esmLoader); diff --git a/packages/plugin-stage/sources/commands/stage.ts b/packages/plugin-stage/sources/commands/stage.ts index 2e9f04f20494..d5c5884a294d 100644 --- a/packages/plugin-stage/sources/commands/stage.ts +++ b/packages/plugin-stage/sources/commands/stage.ts @@ -69,8 +69,11 @@ export default class StageCommand extends BaseCommand { await configuration.triggerHook((hooks: Hooks) => { return hooks.populateYarnPaths; - }, project, (path: PortablePath | null) => { - basePaths.push(path); + }, { + project, + definePath: (path: PortablePath | null) => { + basePaths.push(path); + }, }); const yarnPaths = new Set(); diff --git a/packages/plugin-stage/sources/index.ts b/packages/plugin-stage/sources/index.ts index b3424d76db96..86aa91de21be 100644 --- a/packages/plugin-stage/sources/index.ts +++ b/packages/plugin-stage/sources/index.ts @@ -4,10 +4,10 @@ import {PortablePath} from '@yarnpkg/fslib'; import stage from './commands/stage'; export interface Hooks { - populateYarnPaths?: ( + populateYarnPaths?: ({ project, definePath }: { project: Project, definePath: (path: PortablePath | null) => void, - ) => Promise; + }) => Promise; } const plugin: Plugin = { diff --git a/packages/plugin-typescript/sources/index.ts b/packages/plugin-typescript/sources/index.ts index 5bc58afa389a..638b39ce299c 100644 --- a/packages/plugin-typescript/sources/index.ts +++ b/packages/plugin-typescript/sources/index.ts @@ -14,12 +14,12 @@ const getTypesName = (descriptor: Descriptor) => { : `${descriptor.name}`; }; -const afterWorkspaceDependencyAddition = async ( +const afterWorkspaceDependencyAddition = async ({ workspace, dependencyTarget, descriptor, strategies }: { workspace: Workspace, dependencyTarget: suggestUtils.Target, descriptor: Descriptor, strategies: Array, -) => { +}) => { if (descriptor.scope === `types`) return; @@ -107,11 +107,11 @@ const afterWorkspaceDependencyAddition = async ( } }; -const afterWorkspaceDependencyRemoval = async ( +const afterWorkspaceDependencyRemoval = async ({ workspace, dependencyTarget, descriptor }: { workspace: Workspace, dependencyTarget: suggestUtils.Target, descriptor: Descriptor, -) => { +}) => { if (descriptor.scope === `types`) return; @@ -138,7 +138,7 @@ const afterWorkspaceDependencyRemoval = async ( } }; -const beforeWorkspacePacking = (workspace: Workspace, rawManifest: any) => { +const beforeWorkspacePacking = ({ workspace, rawManifest }: { workspace: Workspace, rawManifest: any }) => { if (rawManifest.publishConfig && rawManifest.publishConfig.typings) rawManifest.typings = rawManifest.publishConfig.typings; diff --git a/packages/yarnpkg-core/sources/Configuration.ts b/packages/yarnpkg-core/sources/Configuration.ts index 554158cf9256..7b3aceb50a94 100644 --- a/packages/yarnpkg-core/sources/Configuration.ts +++ b/packages/yarnpkg-core/sources/Configuration.ts @@ -1553,7 +1553,7 @@ export class Configuration { await this.triggerHook(hooks => { return hooks.registerPackageExtensions; - }, this, registerPackageExtension); + }, {configuration: this, registerPackageExtension}); for (const [descriptorString, extensionData] of this.get(`packageExtensions`)) { registerPackageExtension(structUtils.parseDescriptor(descriptorString, true), miscUtils.convertMapsToIndexableObjects(extensionData), {userProvided: true}); diff --git a/packages/yarnpkg-core/sources/Plugin.ts b/packages/yarnpkg-core/sources/Plugin.ts index 81b92997a12c..674991648f3e 100644 --- a/packages/yarnpkg-core/sources/Plugin.ts +++ b/packages/yarnpkg-core/sources/Plugin.ts @@ -49,10 +49,10 @@ export interface Hooks { * ones. That's for example what the compat plugin uses to automatically fix * packages with known flaws. */ - registerPackageExtensions?: ( + registerPackageExtensions?: ({ configuration, registerPackageExtension }: { configuration: Configuration, registerPackageExtension: (descriptor: Descriptor, extensionData: PackageExtensionData) => void, - ) => Promise; + }) => Promise; /** * Called before a script is executed. The hooks are allowed to modify the @@ -64,11 +64,10 @@ export interface Hooks { * suggest you adopt this convention for any new key added to the env (we * might enforce it later on). */ - setupScriptEnvironment?: ( + setupScriptEnvironment?: ({ project, env }: { project: Project, env: ProcessEnvironment, - makePathWrapper: (name: string, argv0: string, args: Array) => Promise, - ) => Promise; + }) => Promise; /** * Called as a script is getting executed. The `executor` function parameter, @@ -76,13 +75,13 @@ export interface Hooks { * script executions, for example to run some validation or add some * performance monitoring. */ - wrapScriptExecution?: ( + wrapScriptExecution?: ({ project, locator, scriptName, extra }: { executor: () => Promise, project: Project, locator: Locator, scriptName: string, extra: {script: string, args: Array, cwd: PortablePath, env: ProcessEnvironment, stdin: Readable | null, stdout: Writable, stderr: Writable}, - ) => Promise<() => Promise>; + }) => Promise<() => Promise>; /** * Called when a network request is being made. The `executor` function @@ -90,20 +89,20 @@ export interface Hooks { * mechanism to wrap network requests, for example to run some validation or * add some logging. */ - wrapNetworkRequest?: ( + wrapNetworkRequest?: ({ executor, extra }: { executor: () => Promise, extra: WrapNetworkRequestInfo - ) => Promise<() => Promise>; + }) => Promise<() => Promise>; /** * Called before the build, to compute a global hash key that we will use * to detect whether packages must be rebuilt (typically when the Node * version changes). */ - globalHashGeneration?: ( + globalHashGeneration?: ({ project, contributeHash }: { project: Project, contributeHash: (data: string | Buffer) => void, - ) => Promise; + }) => Promise; /** * Called during the resolution, once for each resolved package and each of @@ -116,63 +115,63 @@ export interface Hooks { * `initialDependency` will be the descriptor before any plugin attempted to * change it. */ - reduceDependency?: ( + reduceDependency?: ({ dependency, project, locator, initialDependency, extra }: { dependency: Descriptor, project: Project, locator: Locator, initialDependency: Descriptor, extra: {resolver: Resolver, resolveOptions: ResolveOptions}, - ) => Promise; + }) => Promise; /** * Called after the `install` method from the `Project` class successfully * completed. */ - afterAllInstalled?: ( + afterAllInstalled?: ({ project, options }: { project: Project, options: InstallOptions - ) => void; + }) => void; /** * Called during the `Validation step` of the `install` method from the * `Project` class. */ - validateProject?: ( + validateProject?: ({ project, report }: { project: Project, report: { reportWarning: (name: MessageName, text: string) => void; reportError: (name: MessageName, text: string) => void; } - ) => void; + }) => void; /** * Called during the `Validation step` of the `install` method from the * `Project` class by the `validateProject` hook. */ - validateWorkspace?: ( + validateWorkspace?: ({ workspace, report }: { workspace: Workspace, report: { reportWarning: (name: MessageName, text: string) => void; reportError: (name: MessageName, text: string) => void; } - ) => void; + }) => void; /** * Used to notify the core of all the potential artifacts of the available * linkers. */ - populateYarnPaths?: ( + populateYarnPaths?: ({ project, definePath }: { project: Project, definePath: (path: PortablePath | null) => void, - ) => Promise; + }) => Promise; /** * Called when the user requests to clean the global cache. Plugins should * use this hook to remove their own global artifacts. */ - cleanGlobalArtifacts?: ( + cleanGlobalArtifacts?: ({ configuration }: { configuration: Configuration, - ) => Promise; + }) => Promise; } export type Plugin = { diff --git a/packages/yarnpkg-core/sources/scriptUtils.ts b/packages/yarnpkg-core/sources/scriptUtils.ts index 6aa4fdd3ea8a..4f21b28c8684 100644 --- a/packages/yarnpkg-core/sources/scriptUtils.ts +++ b/packages/yarnpkg-core/sources/scriptUtils.ts @@ -172,11 +172,12 @@ export async function makeScriptEnv({project, locator, binFolder, lifecycleScrip if (project) { await project.configuration.triggerHook( - hook => hook.setupScriptEnvironment, - project, - scriptEnv, - async (name: string, argv0: string, args: Array) => { - return await makePathWrapper(binFolder, toFilename(name), argv0, args); + hook => hook.setupScriptEnvironment, { + project, + env: scriptEnv, + makePathWrapper: async (name: string, argv0: string, args: Array) => { + return await makePathWrapper(binFolder, toFilename(name), argv0, args); + }, }, ); } From 56703af6f54e71b5cd035c25526289cd0b7d9c84 Mon Sep 17 00:00:00 2001 From: Joshua David Date: Sun, 5 Jun 2022 17:56:22 +1000 Subject: [PATCH 2/5] chore: remove unused attributes --- packages/plugin-compat/sources/index.ts | 6 +++--- packages/plugin-npm/sources/index.ts | 2 +- packages/plugin-npm/sources/npmHttpUtils.ts | 2 +- packages/plugin-typescript/sources/index.ts | 9 +++------ 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/plugin-compat/sources/index.ts b/packages/plugin-compat/sources/index.ts index 519a4acd8198..943259ad2a3c 100644 --- a/packages/plugin-compat/sources/index.ts +++ b/packages/plugin-compat/sources/index.ts @@ -14,13 +14,13 @@ const PATCHES = new Map([ const plugin: Plugin = { 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; @@ -31,7 +31,7 @@ const plugin: Plugin = { 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; diff --git a/packages/plugin-npm/sources/index.ts b/packages/plugin-npm/sources/index.ts index 9a1c7a7350d9..f4d21e3729c3 100644 --- a/packages/plugin-npm/sources/index.ts +++ b/packages/plugin-npm/sources/index.ts @@ -20,7 +20,7 @@ export interface Hooks { * specific registry. */ getNpmAuthenticationHeader?: ({ currentHeader, registry, configuration, ident }: { - currentHeader: string | undefined, + currentHeader?: string, registry: string, configuration: Configuration, ident?: Ident, diff --git a/packages/plugin-npm/sources/npmHttpUtils.ts b/packages/plugin-npm/sources/npmHttpUtils.ts index 18a100639681..3099b311c474 100644 --- a/packages/plugin-npm/sources/npmHttpUtils.ts +++ b/packages/plugin-npm/sources/npmHttpUtils.ts @@ -203,7 +203,7 @@ async function getAuthenticationHeader(registry: string, {authType = AuthType.CO const header = await configuration.reduceHook((hooks: Hooks) => { return hooks.getNpmAuthenticationHeader; - }, {currentHeader: undefined, registry, configuration, ident}); + }, {registry, configuration, ident}); if (header) return header; diff --git a/packages/plugin-typescript/sources/index.ts b/packages/plugin-typescript/sources/index.ts index 638b39ce299c..a0b1200213e2 100644 --- a/packages/plugin-typescript/sources/index.ts +++ b/packages/plugin-typescript/sources/index.ts @@ -14,11 +14,9 @@ const getTypesName = (descriptor: Descriptor) => { : `${descriptor.name}`; }; -const afterWorkspaceDependencyAddition = async ({ workspace, dependencyTarget, descriptor, strategies }: { +const afterWorkspaceDependencyAddition = async ({ workspace, descriptor }: { workspace: Workspace, - dependencyTarget: suggestUtils.Target, descriptor: Descriptor, - strategies: Array, }) => { if (descriptor.scope === `types`) return; @@ -107,9 +105,8 @@ const afterWorkspaceDependencyAddition = async ({ workspace, dependencyTarget, d } }; -const afterWorkspaceDependencyRemoval = async ({ workspace, dependencyTarget, descriptor }: { +const afterWorkspaceDependencyRemoval = async ({ workspace, descriptor }: { workspace: Workspace, - dependencyTarget: suggestUtils.Target, descriptor: Descriptor, }) => { if (descriptor.scope === `types`) @@ -138,7 +135,7 @@ const afterWorkspaceDependencyRemoval = async ({ workspace, dependencyTarget, de } }; -const beforeWorkspacePacking = ({ workspace, rawManifest }: { workspace: Workspace, rawManifest: any }) => { +const beforeWorkspacePacking = ({ rawManifest }: { rawManifest: any }) => { if (rawManifest.publishConfig && rawManifest.publishConfig.typings) rawManifest.typings = rawManifest.publishConfig.typings; From a0f5b8021f5949561a71b2d6fd0475dad37ce1a4 Mon Sep 17 00:00:00 2001 From: Joshua David Date: Sun, 5 Jun 2022 18:24:47 +1000 Subject: [PATCH 3/5] chore: update core hooks --- packages/yarnpkg-core/sources/CorePlugin.ts | 19 +++++++++++-------- packages/yarnpkg-core/sources/Project.ts | 15 +++++++++++---- packages/yarnpkg-core/sources/httpUtils.ts | 5 ++++- packages/yarnpkg-core/sources/scriptUtils.ts | 10 ++++++++-- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/packages/yarnpkg-core/sources/CorePlugin.ts b/packages/yarnpkg-core/sources/CorePlugin.ts index 5e025a7544f8..07e969938144 100644 --- a/packages/yarnpkg-core/sources/CorePlugin.ts +++ b/packages/yarnpkg-core/sources/CorePlugin.ts @@ -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; @@ -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; diff --git a/packages/yarnpkg-core/sources/Project.ts b/packages/yarnpkg-core/sources/Project.ts index 29d8f7e2c0c5..2482ae3586ea 100644 --- a/packages/yarnpkg-core/sources/Project.ts +++ b/packages/yarnpkg-core/sources/Project.ts @@ -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, }); @@ -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), + }, }); }); diff --git a/packages/yarnpkg-core/sources/httpUtils.ts b/packages/yarnpkg-core/sources/httpUtils.ts index 13bd2e6c94d0..a65a55f9c974 100644 --- a/packages/yarnpkg-core/sources/httpUtils.ts +++ b/packages/yarnpkg-core/sources/httpUtils.ts @@ -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(); } diff --git a/packages/yarnpkg-core/sources/scriptUtils.ts b/packages/yarnpkg-core/sources/scriptUtils.ts index 4f21b28c8684..38d1318a5baa 100644 --- a/packages/yarnpkg-core/sources/scriptUtils.ts +++ b/packages/yarnpkg-core/sources/scriptUtils.ts @@ -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(); From 799130b876c79e32a889894e1ae5203cd19a0a7f Mon Sep 17 00:00:00 2001 From: Joshua David Date: Mon, 6 Jun 2022 22:41:05 +1000 Subject: [PATCH 4/5] fix: reduce hooks w/ attribute --- packages/plugin-git/sources/GitFetcher.ts | 2 +- packages/plugin-npm/sources/npmHttpUtils.ts | 2 +- packages/yarnpkg-core/sources/Configuration.ts | 8 ++++---- packages/yarnpkg-core/sources/Project.ts | 2 +- packages/yarnpkg-core/sources/httpUtils.ts | 2 +- packages/yarnpkg-core/sources/scriptUtils.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/plugin-git/sources/GitFetcher.ts b/packages/plugin-git/sources/GitFetcher.ts index 488e9ef2b299..3a59c12910d3 100644 --- a/packages/plugin-git/sources/GitFetcher.ts +++ b/packages/plugin-git/sources/GitFetcher.ts @@ -46,7 +46,7 @@ export class GitFetcher implements Fetcher { async downloadHosted(locator: Locator, options: FetchOptions) { return options.project.configuration.reduceHook((hooks: Hooks) => { return hooks.fetchHostedRepository; - }, {current: null as FetchResult | null, locator, options}); + }, {current: null as FetchResult | null, locator, options}, "current"); } async cloneFromRemote(locator: Locator, opts: FetchOptions) { diff --git a/packages/plugin-npm/sources/npmHttpUtils.ts b/packages/plugin-npm/sources/npmHttpUtils.ts index 3099b311c474..cbda6c550d94 100644 --- a/packages/plugin-npm/sources/npmHttpUtils.ts +++ b/packages/plugin-npm/sources/npmHttpUtils.ts @@ -203,7 +203,7 @@ async function getAuthenticationHeader(registry: string, {authType = AuthType.CO const header = await configuration.reduceHook((hooks: Hooks) => { return hooks.getNpmAuthenticationHeader; - }, {registry, configuration, ident}); + }, {registry, configuration, ident}, "currentHeader"); if (header) return header; diff --git a/packages/yarnpkg-core/sources/Configuration.ts b/packages/yarnpkg-core/sources/Configuration.ts index 7b3aceb50a94..21f2d8b747eb 100644 --- a/packages/yarnpkg-core/sources/Configuration.ts +++ b/packages/yarnpkg-core/sources/Configuration.ts @@ -1710,8 +1710,8 @@ export class Configuration { } } - async reduceHook, V, HooksDefinition = Hooks>(get: (hooks: HooksDefinition) => ((reduced: V, ...args: U) => Promise) | undefined, initialValue: V, ...args: U): Promise { - let value = initialValue; + async reduceHook, V, HooksDefinition = Hooks>(get: (hooks: HooksDefinition) => ((reduced: V, ...args: U) => Promise) | undefined, value: V, attribute: string, ...args: U): Promise { + let accumulator = value?.[attribute]; for (const plugin of this.plugins.values()) { const hooks = plugin.hooks as HooksDefinition; @@ -1722,10 +1722,10 @@ export class Configuration { if (!hook) continue; - value = await hook(value, ...args); + accumulator = await hook({ ...value, [attribute]: accumulator }, ...args); } - return value; + return accumulator; } async firstHook, V, HooksDefinition = Hooks>(get: (hooks: HooksDefinition) => ((...args: U) => Promise) | undefined, ...args: U): Promise | null> { diff --git a/packages/yarnpkg-core/sources/Project.ts b/packages/yarnpkg-core/sources/Project.ts index 2482ae3586ea..800529be6ee3 100644 --- a/packages/yarnpkg-core/sources/Project.ts +++ b/packages/yarnpkg-core/sources/Project.ts @@ -679,7 +679,7 @@ export class Project { initialDependency: descriptor, resolver, resolveOptions, - }); + }, "dependency"); if (!structUtils.areIdentsEqual(descriptor, dependency)) throw new Error(`Assertion failed: The descriptor ident cannot be changed through aliases`); diff --git a/packages/yarnpkg-core/sources/httpUtils.ts b/packages/yarnpkg-core/sources/httpUtils.ts index a65a55f9c974..431ff070a891 100644 --- a/packages/yarnpkg-core/sources/httpUtils.ts +++ b/packages/yarnpkg-core/sources/httpUtils.ts @@ -184,7 +184,7 @@ export async function request(target: string | URL, body: Body, {configuration, }, { executor: realRequest, extra: {target, body, configuration, headers, jsonRequest, jsonResponse, method}, - }); + }, "executor"); return await executor(); } diff --git a/packages/yarnpkg-core/sources/scriptUtils.ts b/packages/yarnpkg-core/sources/scriptUtils.ts index 38d1318a5baa..a027e3b82d4b 100644 --- a/packages/yarnpkg-core/sources/scriptUtils.ts +++ b/packages/yarnpkg-core/sources/scriptUtils.ts @@ -439,7 +439,7 @@ export async function executePackageScript(locator: Locator, scriptName: string, extra: { script, args, cwd: realCwd, env, stdin, stdout, stderr, } - }); + }, "executor"); return await executor(); }); From e7a1cbdad1c204b1278bc86706bf23a888b35db1 Mon Sep 17 00:00:00 2001 From: Joshua David Date: Tue, 7 Jun 2022 00:19:15 +1000 Subject: [PATCH 5/5] chore: lint --- packages/plugin-compat/sources/index.ts | 6 +- .../plugin-essentials/sources/commands/add.ts | 16 ++-- .../sources/commands/remove.ts | 6 +- packages/plugin-essentials/sources/index.ts | 36 ++++----- packages/plugin-git/sources/GitFetcher.ts | 2 +- packages/plugin-git/sources/index.ts | 8 +- packages/plugin-github/sources/index.ts | 2 +- packages/plugin-npm/sources/index.ts | 10 +-- packages/plugin-npm/sources/npmHttpUtils.ts | 2 +- packages/plugin-pack/sources/index.ts | 8 +- packages/plugin-pack/sources/packUtils.ts | 2 +- packages/plugin-patch/sources/index.ts | 6 +- packages/plugin-pnp/sources/index.ts | 4 +- packages/plugin-stage/sources/index.ts | 6 +- packages/plugin-typescript/sources/index.ts | 14 ++-- .../yarnpkg-core/sources/Configuration.ts | 2 +- packages/yarnpkg-core/sources/CorePlugin.ts | 10 +-- packages/yarnpkg-core/sources/Plugin.ts | 76 +++++++++---------- packages/yarnpkg-core/sources/Project.ts | 2 +- packages/yarnpkg-core/sources/httpUtils.ts | 2 +- packages/yarnpkg-core/sources/scriptUtils.ts | 4 +- 21 files changed, 112 insertions(+), 112 deletions(-) diff --git a/packages/plugin-compat/sources/index.ts b/packages/plugin-compat/sources/index.ts index 943259ad2a3c..92dec252ad0e 100644 --- a/packages/plugin-compat/sources/index.ts +++ b/packages/plugin-compat/sources/index.ts @@ -14,13 +14,13 @@ const PATCHES = new Map([ const plugin: Plugin = { hooks: { - registerPackageExtensions: async ({ registerPackageExtension }) => { + registerPackageExtensions: async ({registerPackageExtension}) => { for (const [descriptorStr, extensionData] of packageExtensions) { registerPackageExtension(structUtils.parseDescriptor(descriptorStr, true), extensionData); } }, - getBuiltinPatch: async ({ name }) => { + getBuiltinPatch: async ({name}) => { const TAG = `compat/`; if (!name.startsWith(TAG)) return undefined; @@ -31,7 +31,7 @@ const plugin: Plugin = { return typeof patch !== `undefined` ? patch : null; }, - reduceDependency: async ({ dependency }) => { + reduceDependency: async ({dependency}) => { const patch = PATCHES.get(dependency.identHash); if (typeof patch === `undefined`) return dependency; diff --git a/packages/plugin-essentials/sources/commands/add.ts b/packages/plugin-essentials/sources/commands/add.ts index 6f5a034ab1bf..846826f6cf65 100644 --- a/packages/plugin-essentials/sources/commands/add.ts +++ b/packages/plugin-essentials/sources/commands/add.ts @@ -211,17 +211,17 @@ export default class AddCommand extends BaseCommand { let askedQuestions = false; const afterWorkspaceDependencyAdditionList: Array<{ - workspace: Workspace, - target: suggestUtils.Target, - descriptor: Descriptor, - strategies: Array, + workspace: Workspace; + target: suggestUtils.Target; + descriptor: Descriptor; + strategies: Array; }> = []; const afterWorkspaceDependencyReplacementList: Array<{ - workspace: Workspace, - target: suggestUtils.Target, - fromDescriptor: Descriptor, - toDescriptor: Descriptor, + workspace: Workspace; + target: suggestUtils.Target; + fromDescriptor: Descriptor; + toDescriptor: Descriptor; }> = []; for (const [/*request*/, {suggestions}, target] of allSuggestions) { diff --git a/packages/plugin-essentials/sources/commands/remove.ts b/packages/plugin-essentials/sources/commands/remove.ts index ad80a2db3d3a..5927cf893fb4 100644 --- a/packages/plugin-essentials/sources/commands/remove.ts +++ b/packages/plugin-essentials/sources/commands/remove.ts @@ -83,9 +83,9 @@ export default class RemoveCommand extends BaseCommand { let hasChanged = false; const afterWorkspaceDependencyRemovalList: Array<{ - workspace: Workspace, - target: suggestUtils.Target, - descriptor: Descriptor, + workspace: Workspace; + target: suggestUtils.Target; + descriptor: Descriptor; }> = []; for (const pattern of this.patterns) { diff --git a/packages/plugin-essentials/sources/index.ts b/packages/plugin-essentials/sources/index.ts index dce86d363dd6..0161c46dc393 100644 --- a/packages/plugin-essentials/sources/index.ts +++ b/packages/plugin-essentials/sources/index.ts @@ -53,11 +53,11 @@ export interface Hooks { * dependencies into the manifest and running `yarn install` won't trigger * it. */ - afterWorkspaceDependencyAddition?: ({ workspace, target, descriptor, strategies }: { - workspace: Workspace, - target: suggestUtils.Target, - descriptor: Descriptor, - strategies: Array + afterWorkspaceDependencyAddition?: ({workspace, target, descriptor, strategies}: { + workspace: Workspace; + target: suggestUtils.Target; + descriptor: Descriptor; + strategies: Array; }) => Promise; /** @@ -66,11 +66,11 @@ export interface Hooks { * updating the dependencies from the manifest and running `yarn install` * won't trigger it. */ - afterWorkspaceDependencyReplacement?: ({ workspace, target, fromDescriptor, toDescriptor }: { - workspace: Workspace, - target: suggestUtils.Target, - fromDescriptor: Descriptor, - toDescriptor: Descriptor, + afterWorkspaceDependencyReplacement?: ({workspace, target, fromDescriptor, toDescriptor}: { + workspace: Workspace; + target: suggestUtils.Target; + fromDescriptor: Descriptor; + toDescriptor: Descriptor; }) => Promise; /** @@ -79,10 +79,10 @@ export interface Hooks { * removing the dependencies from the manifest and running `yarn install` * won't trigger it. */ - afterWorkspaceDependencyRemoval?: ({ workspace, target, descriptor }: { - workspace: Workspace, - target: suggestUtils.Target, - descriptor: Descriptor, + afterWorkspaceDependencyRemoval?: ({workspace, target, descriptor}: { + workspace: Workspace; + target: suggestUtils.Target; + descriptor: Descriptor; }) => Promise; /** @@ -94,10 +94,10 @@ export interface Hooks { * requested audit information (via `-X audit`), and call `registerData` * with those information (retrieved dynamically) if they did. */ - fetchPackageInfo?: ({ pkg, extra, registerData }: { - pkg: Package, - extra: Set, - registerData: (namespace: string, data: Array | {[key: string]: formatUtils.Tuple | undefined}) => void, + fetchPackageInfo?: ({pkg, extra, registerData}: { + pkg: Package; + extra: Set; + registerData: (namespace: string, data: Array | {[key: string]: formatUtils.Tuple | undefined}) => void; }) => Promise; } diff --git a/packages/plugin-git/sources/GitFetcher.ts b/packages/plugin-git/sources/GitFetcher.ts index 3a59c12910d3..01f22bde28f3 100644 --- a/packages/plugin-git/sources/GitFetcher.ts +++ b/packages/plugin-git/sources/GitFetcher.ts @@ -46,7 +46,7 @@ export class GitFetcher implements Fetcher { async downloadHosted(locator: Locator, options: FetchOptions) { return options.project.configuration.reduceHook((hooks: Hooks) => { return hooks.fetchHostedRepository; - }, {current: null as FetchResult | null, locator, options}, "current"); + }, {current: null as FetchResult | null, locator, options}, `current`); } async cloneFromRemote(locator: Locator, opts: FetchOptions) { diff --git a/packages/plugin-git/sources/index.ts b/packages/plugin-git/sources/index.ts index f76d378caa80..51222bf12607 100644 --- a/packages/plugin-git/sources/index.ts +++ b/packages/plugin-git/sources/index.ts @@ -15,10 +15,10 @@ export interface Hooks { * supports downloading repository tarballs, which are more efficient than * cloning the repository (even without its history). */ - fetchHostedRepository?: ({ current, locator, options }: { - current: FetchResult | null, - locator: Locator, - options: FetchOptions, + fetchHostedRepository?: ({current, locator, options}: { + current: FetchResult | null; + locator: Locator; + options: FetchOptions; }) => Promise; } diff --git a/packages/plugin-github/sources/index.ts b/packages/plugin-github/sources/index.ts index 51ee35887b40..f4f1e6b06245 100644 --- a/packages/plugin-github/sources/index.ts +++ b/packages/plugin-github/sources/index.ts @@ -5,7 +5,7 @@ import {GithubFetcher} from './GithubFetcher'; const plugin: Plugin = { hooks: { - async fetchHostedRepository({ previous, locator, options }) { + async fetchHostedRepository({previous, locator, options}) { if (previous !== null) return previous; diff --git a/packages/plugin-npm/sources/index.ts b/packages/plugin-npm/sources/index.ts index f4d21e3729c3..8de60c4432b4 100644 --- a/packages/plugin-npm/sources/index.ts +++ b/packages/plugin-npm/sources/index.ts @@ -19,11 +19,11 @@ export interface Hooks { * You can use this mechanism to dynamically query a CLI for the credentials for a * specific registry. */ - getNpmAuthenticationHeader?: ({ currentHeader, registry, configuration, ident }: { - currentHeader?: string, - registry: string, - configuration: Configuration, - ident?: Ident, + getNpmAuthenticationHeader?: ({currentHeader, registry, configuration, ident}: { + currentHeader?: string; + registry: string; + configuration: Configuration; + ident?: Ident; }) => Promise; } diff --git a/packages/plugin-npm/sources/npmHttpUtils.ts b/packages/plugin-npm/sources/npmHttpUtils.ts index cbda6c550d94..4482aa66d54f 100644 --- a/packages/plugin-npm/sources/npmHttpUtils.ts +++ b/packages/plugin-npm/sources/npmHttpUtils.ts @@ -203,7 +203,7 @@ async function getAuthenticationHeader(registry: string, {authType = AuthType.CO const header = await configuration.reduceHook((hooks: Hooks) => { return hooks.getNpmAuthenticationHeader; - }, {registry, configuration, ident}, "currentHeader"); + }, {registry, configuration, ident}, `currentHeader`); if (header) return header; diff --git a/packages/plugin-pack/sources/index.ts b/packages/plugin-pack/sources/index.ts index 259fdb48865b..8268404f9b34 100644 --- a/packages/plugin-pack/sources/index.ts +++ b/packages/plugin-pack/sources/index.ts @@ -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, rawManifest }: { - workspace: Workspace, - rawManifest: object, + beforeWorkspacePacking?: ({workspace, rawManifest}: { + workspace: Workspace; + rawManifest: object; }) => Promise | void; } const DEPENDENCY_TYPES = [`dependencies`, `devDependencies`, `peerDependencies`]; const WORKSPACE_PROTOCOL = `workspace:`; -const beforeWorkspacePacking = ({ workspace, rawManifest }: { workspace: Workspace, rawManifest: any }) => { +const beforeWorkspacePacking = ({workspace, rawManifest}: { workspace: Workspace, rawManifest: any }) => { if (rawManifest.publishConfig) { if (rawManifest.publishConfig.type) rawManifest.type = rawManifest.publishConfig.type; diff --git a/packages/plugin-pack/sources/packUtils.ts b/packages/plugin-pack/sources/packUtils.ts index cfe30a7bea8c..0d2918683495 100644 --- a/packages/plugin-pack/sources/packUtils.ts +++ b/packages/plugin-pack/sources/packUtils.ts @@ -193,7 +193,7 @@ export async function genPackList(workspace: Workspace) { project, definePath: (path: PortablePath | null) => { maybeRejectPath(path); - } + }, }); // All child workspaces are ignored diff --git a/packages/plugin-patch/sources/index.ts b/packages/plugin-patch/sources/index.ts index 9a7eb7b19873..0b5ab4c9a7a2 100644 --- a/packages/plugin-patch/sources/index.ts +++ b/packages/plugin-patch/sources/index.ts @@ -15,9 +15,9 @@ export interface Hooks { * syntax: `patch:builtin`. This is for instance how the TypeScript * patch is automatically registered. */ - getBuiltinPatch?: ({ project, name }: { - project: Project, - name: string, + getBuiltinPatch?: ({project, name}: { + project: Project; + name: string; }) => Promise; } diff --git a/packages/plugin-pnp/sources/index.ts b/packages/plugin-pnp/sources/index.ts index adcb2f0611a7..38f2af0f7de5 100644 --- a/packages/plugin-pnp/sources/index.ts +++ b/packages/plugin-pnp/sources/index.ts @@ -24,7 +24,7 @@ export const quotePathIfNeeded = (path: string) => { return /\s/.test(path) ? JSON.stringify(path) : path; }; -async function setupScriptEnvironment({ project, env }: { project: Project, env: {[key: string]: string}, makePathWrapper: (name: string, argv0: string, args: Array) => Promise }) { +async function setupScriptEnvironment({project, env}: { project: Project, env: {[key: string]: string}, makePathWrapper: (name: string, argv0: string, args: Array) => Promise }) { const pnpPath = getPnpPath(project); let pnpRequire = `--require ${quotePathIfNeeded(npath.fromPortablePath(pnpPath.cjs))}`; @@ -49,7 +49,7 @@ async function setupScriptEnvironment({ project, env }: { project: Project, env: } } -async function populateYarnPaths({ project, definePath }: { project: Project, definePath: (path: PortablePath | null) => void }) { +async function populateYarnPaths({project, definePath}: { project: Project, definePath: (path: PortablePath | null) => void }) { const pnpPath = getPnpPath(project); definePath(pnpPath.cjs); definePath(pnpPath.esmLoader); diff --git a/packages/plugin-stage/sources/index.ts b/packages/plugin-stage/sources/index.ts index 86aa91de21be..4e7ac598e71c 100644 --- a/packages/plugin-stage/sources/index.ts +++ b/packages/plugin-stage/sources/index.ts @@ -4,9 +4,9 @@ import {PortablePath} from '@yarnpkg/fslib'; import stage from './commands/stage'; export interface Hooks { - populateYarnPaths?: ({ project, definePath }: { - project: Project, - definePath: (path: PortablePath | null) => void, + populateYarnPaths?: ({project, definePath}: { + project: Project; + definePath: (path: PortablePath | null) => void; }) => Promise; } diff --git a/packages/plugin-typescript/sources/index.ts b/packages/plugin-typescript/sources/index.ts index a0b1200213e2..6669f8f4e091 100644 --- a/packages/plugin-typescript/sources/index.ts +++ b/packages/plugin-typescript/sources/index.ts @@ -14,9 +14,9 @@ const getTypesName = (descriptor: Descriptor) => { : `${descriptor.name}`; }; -const afterWorkspaceDependencyAddition = async ({ workspace, descriptor }: { - workspace: Workspace, - descriptor: Descriptor, +const afterWorkspaceDependencyAddition = async ({workspace, descriptor}: { + workspace: Workspace; + descriptor: Descriptor; }) => { if (descriptor.scope === `types`) return; @@ -105,9 +105,9 @@ const afterWorkspaceDependencyAddition = async ({ workspace, descriptor }: { } }; -const afterWorkspaceDependencyRemoval = async ({ workspace, descriptor }: { - workspace: Workspace, - descriptor: Descriptor, +const afterWorkspaceDependencyRemoval = async ({workspace, descriptor}: { + workspace: Workspace; + descriptor: Descriptor; }) => { if (descriptor.scope === `types`) return; @@ -135,7 +135,7 @@ const afterWorkspaceDependencyRemoval = async ({ workspace, descriptor }: { } }; -const beforeWorkspacePacking = ({ rawManifest }: { rawManifest: any }) => { +const beforeWorkspacePacking = ({rawManifest}: { rawManifest: any }) => { if (rawManifest.publishConfig && rawManifest.publishConfig.typings) rawManifest.typings = rawManifest.publishConfig.typings; diff --git a/packages/yarnpkg-core/sources/Configuration.ts b/packages/yarnpkg-core/sources/Configuration.ts index 21f2d8b747eb..25112f79ab62 100644 --- a/packages/yarnpkg-core/sources/Configuration.ts +++ b/packages/yarnpkg-core/sources/Configuration.ts @@ -1722,7 +1722,7 @@ export class Configuration { if (!hook) continue; - accumulator = await hook({ ...value, [attribute]: accumulator }, ...args); + accumulator = await hook({...value, [attribute]: accumulator}, ...args); } return accumulator; diff --git a/packages/yarnpkg-core/sources/CorePlugin.ts b/packages/yarnpkg-core/sources/CorePlugin.ts index 07e969938144..138c3c6d2990 100644 --- a/packages/yarnpkg-core/sources/CorePlugin.ts +++ b/packages/yarnpkg-core/sources/CorePlugin.ts @@ -8,7 +8,7 @@ import {Descriptor, Locator} from './types'; export const CorePlugin: Plugin = { hooks: { - reduceDependency: ({ dependency, project, locator, initialDependency, resolver, resolveOptions }: { dependency: Descriptor, project: Project, locator: Locator, initialDependency: Descriptor, 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; @@ -32,10 +32,10 @@ export const CorePlugin: Plugin = { return dependency; }, - validateProject: async ({ project, report}: { 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); @@ -51,10 +51,10 @@ export const CorePlugin: Plugin = { } }, - validateWorkspace: async ({ workspace, report }: { 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; diff --git a/packages/yarnpkg-core/sources/Plugin.ts b/packages/yarnpkg-core/sources/Plugin.ts index 674991648f3e..8845de16b808 100644 --- a/packages/yarnpkg-core/sources/Plugin.ts +++ b/packages/yarnpkg-core/sources/Plugin.ts @@ -49,9 +49,9 @@ export interface Hooks { * ones. That's for example what the compat plugin uses to automatically fix * packages with known flaws. */ - registerPackageExtensions?: ({ configuration, registerPackageExtension }: { - configuration: Configuration, - registerPackageExtension: (descriptor: Descriptor, extensionData: PackageExtensionData) => void, + registerPackageExtensions?: ({configuration, registerPackageExtension}: { + configuration: Configuration; + registerPackageExtension: (descriptor: Descriptor, extensionData: PackageExtensionData) => void; }) => Promise; /** @@ -64,9 +64,9 @@ export interface Hooks { * suggest you adopt this convention for any new key added to the env (we * might enforce it later on). */ - setupScriptEnvironment?: ({ project, env }: { - project: Project, - env: ProcessEnvironment, + setupScriptEnvironment?: ({project, env}: { + project: Project; + env: ProcessEnvironment; }) => Promise; /** @@ -75,12 +75,12 @@ export interface Hooks { * script executions, for example to run some validation or add some * performance monitoring. */ - wrapScriptExecution?: ({ project, locator, scriptName, extra }: { - executor: () => Promise, - project: Project, - locator: Locator, - scriptName: string, - extra: {script: string, args: Array, cwd: PortablePath, env: ProcessEnvironment, stdin: Readable | null, stdout: Writable, stderr: Writable}, + wrapScriptExecution?: ({project, locator, scriptName, extra}: { + executor: () => Promise; + project: Project; + locator: Locator; + scriptName: string; + extra: {script: string, args: Array, cwd: PortablePath, env: ProcessEnvironment, stdin: Readable | null, stdout: Writable, stderr: Writable}; }) => Promise<() => Promise>; /** @@ -89,9 +89,9 @@ export interface Hooks { * mechanism to wrap network requests, for example to run some validation or * add some logging. */ - wrapNetworkRequest?: ({ executor, extra }: { - executor: () => Promise, - extra: WrapNetworkRequestInfo + wrapNetworkRequest?: ({executor, extra}: { + executor: () => Promise; + extra: WrapNetworkRequestInfo; }) => Promise<() => Promise>; /** @@ -99,9 +99,9 @@ export interface Hooks { * to detect whether packages must be rebuilt (typically when the Node * version changes). */ - globalHashGeneration?: ({ project, contributeHash }: { - project: Project, - contributeHash: (data: string | Buffer) => void, + globalHashGeneration?: ({project, contributeHash}: { + project: Project; + contributeHash: (data: string | Buffer) => void; }) => Promise; /** @@ -115,62 +115,62 @@ export interface Hooks { * `initialDependency` will be the descriptor before any plugin attempted to * change it. */ - reduceDependency?: ({ dependency, project, locator, initialDependency, extra }: { - dependency: Descriptor, - project: Project, - locator: Locator, - initialDependency: Descriptor, - extra: {resolver: Resolver, resolveOptions: ResolveOptions}, + reduceDependency?: ({dependency, project, locator, initialDependency, extra}: { + dependency: Descriptor; + project: Project; + locator: Locator; + initialDependency: Descriptor; + extra: {resolver: Resolver, resolveOptions: ResolveOptions}; }) => Promise; /** * Called after the `install` method from the `Project` class successfully * completed. */ - afterAllInstalled?: ({ project, options }: { - project: Project, - options: InstallOptions + afterAllInstalled?: ({project, options}: { + project: Project; + options: InstallOptions; }) => void; /** * Called during the `Validation step` of the `install` method from the * `Project` class. */ - validateProject?: ({ project, report }: { - project: Project, + validateProject?: ({project, report}: { + project: Project; report: { reportWarning: (name: MessageName, text: string) => void; reportError: (name: MessageName, text: string) => void; - } + }; }) => void; /** * Called during the `Validation step` of the `install` method from the * `Project` class by the `validateProject` hook. */ - validateWorkspace?: ({ workspace, report }: { - workspace: Workspace, + validateWorkspace?: ({workspace, report}: { + workspace: Workspace; report: { reportWarning: (name: MessageName, text: string) => void; reportError: (name: MessageName, text: string) => void; - } + }; }) => void; /** * Used to notify the core of all the potential artifacts of the available * linkers. */ - populateYarnPaths?: ({ project, definePath }: { - project: Project, - definePath: (path: PortablePath | null) => void, + populateYarnPaths?: ({project, definePath}: { + project: Project; + definePath: (path: PortablePath | null) => void; }) => Promise; /** * Called when the user requests to clean the global cache. Plugins should * use this hook to remove their own global artifacts. */ - cleanGlobalArtifacts?: ({ configuration }: { - configuration: Configuration, + cleanGlobalArtifacts?: ({configuration}: { + configuration: Configuration; }) => Promise; } diff --git a/packages/yarnpkg-core/sources/Project.ts b/packages/yarnpkg-core/sources/Project.ts index 800529be6ee3..e1ea06fd40c7 100644 --- a/packages/yarnpkg-core/sources/Project.ts +++ b/packages/yarnpkg-core/sources/Project.ts @@ -679,7 +679,7 @@ export class Project { initialDependency: descriptor, resolver, resolveOptions, - }, "dependency"); + }, `dependency`); if (!structUtils.areIdentsEqual(descriptor, dependency)) throw new Error(`Assertion failed: The descriptor ident cannot be changed through aliases`); diff --git a/packages/yarnpkg-core/sources/httpUtils.ts b/packages/yarnpkg-core/sources/httpUtils.ts index 431ff070a891..92deb5cf04fe 100644 --- a/packages/yarnpkg-core/sources/httpUtils.ts +++ b/packages/yarnpkg-core/sources/httpUtils.ts @@ -184,7 +184,7 @@ export async function request(target: string | URL, body: Body, {configuration, }, { executor: realRequest, extra: {target, body, configuration, headers, jsonRequest, jsonResponse, method}, - }, "executor"); + }, `executor`); return await executor(); } diff --git a/packages/yarnpkg-core/sources/scriptUtils.ts b/packages/yarnpkg-core/sources/scriptUtils.ts index a027e3b82d4b..436b02d685a4 100644 --- a/packages/yarnpkg-core/sources/scriptUtils.ts +++ b/packages/yarnpkg-core/sources/scriptUtils.ts @@ -438,8 +438,8 @@ export async function executePackageScript(locator: Locator, scriptName: string, scriptName, extra: { script, args, cwd: realCwd, env, stdin, stdout, stderr, - } - }, "executor"); + }, + }, `executor`); return await executor(); });