Skip to main content

Yarn

Index

Namespaces

Type Aliases

Namespaces

Constraints

Constraints:

Context

Context: { Yarn: Yarn }

Type declaration

  • Yarn: Yarn

Dependency

Dependency: { ident: string; range: string; resolution: Package | null; type: DependencyType; workspace: Workspace; delete: any; error: any; update: any }

Type declaration

  • ident: string

    Dependency name.

  • range: string

    Dependency range. Note that it doesn’t have to be a semver value - it can also be a git repository, and http url, etc.

  • resolution: Package | null

    Package currently used to resolve the dependency. May be null if the dependency couldn’t be resolved. This can happen in those cases:

    • The dependency is a peer dependency; workspaces don’t have ancestors to satisfy their peer dependencies, so they’re always unresolved. This is why we recommend to list a dev dependency for each non-optional peer dependency you list, so that Yarn can fallback to it.
    • The dependency is a prod dependency, and there’s a dev dependency of the same name (in which case there will be a separate dependency entry for the dev dependency, which will have the resolution).
  • type: DependencyType

    Name of the field under which this dependency can be found.

  • workspace: Workspace

    Reference to the owning workspace.

  • delete: function
    • delete(): void

    • Report an error (useful when you want to forbid a specific package from being added to the dependencies). If --fix is set, Yarn will silently remove the dependency from the package.json instead of reporting an error.


      Returns void

  • error: function
    • error(message: string): void

    • Report a non-recoverable custom error.


      Parameters

      • message: string

        Error message

      Returns void

  • update: function
    • update(range: undefined | string): void

    • Report an error unless the dependency has the expected range. If --fix is set, Yarn will silently update the package.json instead of reporting an error.


      Parameters

      • range: undefined | string

        New range for the dependency.

      Returns void

DependencyFilter

DependencyFilter: { ident?: string; type?: DependencyType; workspace?: Workspace }

Type declaration

  • optionalident?: string

    Only return dependencies with the given name.

  • optionaltype?: DependencyType

    Only return dependencies listed in the following set.

  • optionalworkspace?: Workspace

    Only return dependencies from the given workspace.

DependencyType

DependencyType: dependencies | devDependencies | peerDependencies

Package

Package: { dependencies: Map<string, Package>; ident: string; optionalPeerDependencies: Map<string, string>; peerDependencies: Map<string, string>; version: string | null; workspace: Workspace | null }

Type declaration

  • dependencies: Map<string, Package>

    A map of the dependencies the package is allowed to access. There’s no distinction between prod dependencies and dev dependencies.

  • ident: string

    Package name.

  • optionalPeerDependencies: Map<string, string>

    A map of the optional peer dependencies declared in the package.

  • peerDependencies: Map<string, string>

    A map of the required peer dependencies declared in the package.

  • version: string | null

    Package version.

  • workspace: Workspace | null

    If the package is a workspace, return the corresponding workspace

PackageFilter

PackageFilter: { ident?: string; reference?: string; workspace?: Workspace }

Type declaration

  • optionalident?: string

    Only return packages with the given name.

  • optionalreference?: string

    Only return packages with the given reference.

  • optionalworkspace?: Workspace

    Only return packages from the given workspace.

PartialObject

PartialObject: {} | string | number | null

Workspace

Workspace: { cwd: string; ident: string | null; manifest: any; pkg: Package; error: any; set: any; unset: any }

Type declaration

  • cwd: string

    Relative path from the project root to the workspace. The root workspace always has a cwd equal to ..

  • ident: string | null

    Workspace name.

  • manifest: any

    Raw manifest object for the workspace.

  • pkg: Package

    The resolved information for the workspace.

  • error: function
    • error(message: string): void

    • Report a non-recoverable custom error.


      Parameters

      • message: string

        Error message

      Returns void

  • set: function
    • set(path: string | string[], value: any): void

    • Report an error unless the workspace lists the specified property with the specified value. If --fix is set, Yarn will silently update the package.json instead of reporting an error.


      Parameters

      • path: string | string[]

        Property path

      • value: any

        Expected value

      Returns void

  • unset: function
    • unset(path: string | string[]): void

    • Report an error if the workspace lists the specified property. If --fix is set, Yarn will silently remove the field from the package.json instead of reporting an error.


      Parameters

      • path: string | string[]

        Property path

      Returns void

WorkspaceFilter

WorkspaceFilter: { cwd?: string; ident?: string }

Type declaration

  • optionalcwd?: string

    Only return the workspace with the given relative path.

    Note: This doesn’t currently support glob patterns. Help welcome!

  • optionalident?: string

    Only return the workspace with the given package name.

    Note: This doesn’t currently support glob patterns. Help welcome!

Yarn

Yarn: { dependencies: any; dependency: any; package: any; packages: any; workspace: any; workspaces: any }

Type declaration

  • dependencies: function
    • dependencies(filter?: DependencyFilter): Dependency[]

    • Select all dependencies according to the provided filter.


      Parameters

      • optionalfilter: DependencyFilter

      Returns Dependency[]

  • dependency: function
    • dependency(filter: DependencyFilter): null | Dependency

    • Select a unique workspace according to the provided filter.


      Parameters

      • filter: DependencyFilter

      Returns null | Dependency

  • package: function
    • package(filter: DependencyFilter): null | Package

    • Select a unique workspace according to the provided filter.


      Parameters

      • filter: DependencyFilter

      Returns null | Package

  • packages: function
    • packages(filter: DependencyFilter): Package[]

    • Select all dependencies according to the provided filter.


      Parameters

      • filter: DependencyFilter

      Returns Package[]

  • workspace: function
    • workspace(): Workspace
    • workspace(filter?: WorkspaceFilter): null | Workspace

    • Select a unique workspace according to the provided filter.


      Returns Workspace

  • workspaces: function
    • workspaces(filter?: WorkspaceFilter): Workspace[]

    • Select all matching workspaces according to the provided filter.


      Parameters

      • optionalfilter: WorkspaceFilter

      Returns Workspace[]

Type Aliases

Config

Config: { constraints: (ctx: Constraints.Context) => Promise<void> }

Type declaration

  • constraints: (ctx: Constraints.Context) => Promise<void>
      • (ctx: Constraints.Context): Promise<void>
      • Called each time the constraints engine runs. You can then use the methods from the provided context to assert values on any of your workspaces’ definitions.

        The constraints engine is declarative, and you don’t need to compare values yourself except in some specific situations. For instance, if you wish to ensure that all workspaces define a specific license, you would write something like this:

        // Yes: declarative
        for (const w of Yarn.workspaces()) {
        w.set(`license`, `MIT`);
        }

        // No: imperative
        for (const w of Yarn.workspaces()) {
        if (w.manifest.license !== `MIT`) {
        w.set(`license`, `MIT`);
        }
        }

        Note that the presence of this field will disable any evaluation of the constraints.pro file, although no warning is currently emitted.


        Parameters

        • ctx: Constraints.Context

          Context

        Returns Promise<void>