Skip to main content

Hooks

Index

Properties

optionalafterAllInstalled

afterAllInstalled?: (project: Project, options: InstallOptions) => void

Called after the install method from the Project class successfully completed.


Type declaration

    • (project: Project, options: InstallOptions): void
    • Called after the install method from the Project class successfully completed.


      Parameters

      • project: Project
      • options: InstallOptions

      Returns void

optionalcleanGlobalArtifacts

cleanGlobalArtifacts?: (configuration: Configuration) => Promise<void>

Called when the user requests to clean the global cache. Plugins should use this hook to remove their own global artifacts.


Type declaration

    • Called when the user requests to clean the global cache. Plugins should use this hook to remove their own global artifacts.


      Parameters

      Returns Promise<void>

optionalglobalHashGeneration

globalHashGeneration?: (project: Project, contributeHash: (data: string | Buffer) => void) => Promise<void>

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).


Type declaration

    • (project: Project, contributeHash: (data: string | Buffer) => void): Promise<void>
    • 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).


      Parameters

      • project: Project
      • contributeHash: (data: string | Buffer) => void

      Returns Promise<void>

optionalpopulateYarnPaths

populateYarnPaths?: (project: Project, definePath: (path: null | PortablePath) => void) => Promise<void>

Used to notify the core of all the potential artifacts of the available linkers.


Type declaration

    • Used to notify the core of all the potential artifacts of the available linkers.


      Parameters

      Returns Promise<void>

optionalreduceDependency

reduceDependency?: (dependency: Descriptor, project: Project, locator: Locator, initialDependency: Descriptor, extra: { resolveOptions: ResolveOptions; resolver: Resolver }) => Promise<Descriptor>

Called during the resolution, once for each resolved package and each of their dependencies. By returning a new dependency descriptor you can replace the original one by a different range.

Note that when multiple plugins are registered on reduceDependency they will be executed in definition order. In that case, dependency will always refer to the dependency as it currently is, whereas initialDependency will be the descriptor before any plugin attempted to change it.


Type declaration

    • Called during the resolution, once for each resolved package and each of their dependencies. By returning a new dependency descriptor you can replace the original one by a different range.

      Note that when multiple plugins are registered on reduceDependency they will be executed in definition order. In that case, dependency will always refer to the dependency as it currently is, whereas initialDependency will be the descriptor before any plugin attempted to change it.


      Parameters

      Returns Promise<Descriptor>

optionalregisterPackageExtensions

registerPackageExtensions?: (configuration: Configuration, registerPackageExtension: (descriptor: Descriptor, extensionData: { dependencies?: {}; peerDependencies?: {}; peerDependenciesMeta?: {} }) => void) => Promise<void>

Called when the package extensions are setup. Can be used to inject new ones. That's for example what the compat plugin uses to automatically fix packages with known flaws.


Type declaration

    • (configuration: Configuration, registerPackageExtension: (descriptor: Descriptor, extensionData: { dependencies?: {}; peerDependencies?: {}; peerDependenciesMeta?: {} }) => void): Promise<void>
    • Called when the package extensions are setup. Can be used to inject new ones. That's for example what the compat plugin uses to automatically fix packages with known flaws.


      Parameters

      • configuration: Configuration
      • registerPackageExtension: (descriptor: Descriptor, extensionData: { dependencies?: {}; peerDependencies?: {}; peerDependenciesMeta?: {} }) => void

      Returns Promise<void>

optionalsetupScriptEnvironment

setupScriptEnvironment?: (project: Project, env: ProcessEnv, makePathWrapper: (name: string, argv0: string, args: string[]) => Promise<void>) => Promise<void>

Called before a script is executed. The hooks are allowed to modify the env object as they see fit, and any call to makePathWrapper will cause a binary of the given name to be injected somewhere within the PATH (we recommend you don't alter the PATH yourself unless required).

The keys you get in the env are guaranteed to be uppercase. We strongly suggest you adopt this convention for any new key added to the env (we might enforce it later on).


Type declaration

    • (project: Project, env: ProcessEnv, makePathWrapper: (name: string, argv0: string, args: string[]) => Promise<void>): Promise<void>
    • Called before a script is executed. The hooks are allowed to modify the env object as they see fit, and any call to makePathWrapper will cause a binary of the given name to be injected somewhere within the PATH (we recommend you don't alter the PATH yourself unless required).

      The keys you get in the env are guaranteed to be uppercase. We strongly suggest you adopt this convention for any new key added to the env (we might enforce it later on).


      Parameters

      • project: Project
      • env: ProcessEnv
      • makePathWrapper: (name: string, argv0: string, args: string[]) => Promise<void>

      Returns Promise<void>

optionalvalidateProject

validateProject?: (project: Project, report: { reportError: (name: MessageName, text: string) => void; reportWarning: (name: MessageName, text: string) => void }) => void

Called during the Validation step of the install method from the Project class.


Type declaration

    • (project: Project, report: { reportError: (name: MessageName, text: string) => void; reportWarning: (name: MessageName, text: string) => void }): void
    • Called during the Validation step of the install method from the Project class.


      Parameters

      Returns void

optionalvalidateProjectAfterInstall

validateProjectAfterInstall?: (project: Project, report: { reportError: (name: MessageName, text: string) => void; reportWarning: (name: MessageName, text: string) => void }) => void

Called during the Post-install validation step of the install method from the Project class.


Type declaration

    • (project: Project, report: { reportError: (name: MessageName, text: string) => void; reportWarning: (name: MessageName, text: string) => void }): void
    • Called during the Post-install validation step of the install method from the Project class.


      Parameters

      Returns void

optionalvalidateWorkspace

validateWorkspace?: (workspace: Workspace, report: { reportError: (name: MessageName, text: string) => void; reportWarning: (name: MessageName, text: string) => void }) => void

Called during the Validation step of the install method from the Project class by the validateProject hook.


Type declaration

    • Called during the Validation step of the install method from the Project class by the validateProject hook.


      Parameters

      Returns void

optionalwrapNetworkRequest

wrapNetworkRequest?: (executor: () => Promise<Response>, extra: WrapNetworkRequestInfo) => Promise<() => Promise<Response>>

Called when a network request is being made. The executor function parameter, when called, will trigger the network request. You can use this mechanism to wrap network requests, for example to run some validation or add some logging.


Type declaration

    • Called when a network request is being made. The executor function parameter, when called, will trigger the network request. You can use this mechanism to wrap network requests, for example to run some validation or add some logging.


      Parameters

      Returns Promise<() => Promise<Response>>

optionalwrapScriptExecution

wrapScriptExecution?: (executor: () => Promise<number>, project: Project, locator: Locator, scriptName: string, extra: { args: string[]; cwd: PortablePath; env: ProcessEnv; script: string; stderr: Writable; stdin: null | Readable; stdout: Writable }) => Promise<() => Promise<number>>

Called as a script is getting executed. The executor function parameter, when called, will execute the script. You can use this mechanism to wrap script executions, for example to run some validation or add some performance monitoring.


Type declaration

    • (executor: () => Promise<number>, project: Project, locator: Locator, scriptName: string, extra: { args: string[]; cwd: PortablePath; env: ProcessEnv; script: string; stderr: Writable; stdin: null | Readable; stdout: Writable }): Promise<() => Promise<number>>
    • Called as a script is getting executed. The executor function parameter, when called, will execute the script. You can use this mechanism to wrap script executions, for example to run some validation or add some performance monitoring.


      Parameters

      • executor: () => Promise<number>
      • project: Project
      • locator: Locator
      • scriptName: string
      • extra: { args: string[]; cwd: PortablePath; env: ProcessEnv; script: string; stderr: Writable; stdin: null | Readable; stdout: Writable }

      Returns Promise<() => Promise<number>>