Options
All
  • Public
  • Public/Protected
  • All
Menu

Package plugin-constraints

@yarnpkg/plugin-constraints

This plugin adds support for constraints to Yarn.

Install

This plugin is included by default starting from Yarn 4.

Type aliases

EnforcedDependency

EnforcedDependency: object

Type declaration

EnforcedField

EnforcedField: object

Type declaration

  • fieldPath: string
  • fieldValue: string | null
  • workspace: Workspace

ProcessResult

ProcessResult: object

Type declaration

  • manifestUpdates: Map<PortablePath, Map<string, Map<any, Set<nodeUtils.Caller>>>>
  • reportedErrors: Map<PortablePath, Array<string>>

Variables

Const DEPENDENCY_TYPES

DEPENDENCY_TYPES: DependencyType[] = [DependencyType.Dependencies,DependencyType.DevDependencies,DependencyType.PeerDependencies,]

Const identifierRegExp

identifierRegExp: RegExp = /^[a-zA-Z0-9_]+$/

isAtom

isAtom: is_atom

isInstantiatedList

isInstantiatedList: is_instantiated_list

isVariable

isVariable: is_variable

Const knownDictKeys

knownDictKeys: Set<string> = new Set<string>([`scripts`, ...Manifest.allDependencies])

Const numberRegExp

numberRegExp: RegExp = /^[0-9]+$/

Const projects

projects: WeakMap<Session, Project> = new WeakMap<pl.type.Session, Project>()

Const tauModule

tauModule: Module = new pl.type.Module(`constraints`, {[`project_workspaces_by_descriptor/3`]: (thread, point, atom) => {const [descriptorIdent, descriptorRange, workspaceCwd] = atom.args;if (!isAtom(descriptorIdent) || !isAtom(descriptorRange)) {thread.throw_error(pl.error.instantiation(atom.indicator));return;}const ident = structUtils.parseIdent(descriptorIdent.id);const descriptor = structUtils.makeDescriptor(ident, descriptorRange.id);const project = getProject(thread);const workspace = project.tryWorkspaceByDescriptor(descriptor);if (isVariable(workspaceCwd)) {if (workspace !== null) {prependGoals(thread, point, [new pl.type.Term(`=`, [workspaceCwd,new pl.type.Term(String(workspace.relativeCwd)),])]);}}if (isAtom(workspaceCwd)) {if (workspace !== null && workspace.relativeCwd === workspaceCwd.id) {thread.success(point);}}},[`workspace_field/3`]: (thread, point, atom) => {const [workspaceCwd, fieldName, fieldValue] = atom.args;if (!isAtom(workspaceCwd) || !isAtom(fieldName)) {thread.throw_error(pl.error.instantiation(atom.indicator));return;}const project = getProject(thread);const workspace = project.tryWorkspaceByCwd(workspaceCwd.id as PortablePath);// Workspace not found => this predicate can never match// We might want to throw here? We can be pretty sure the user did// something wrong at this pointif (workspace == null)return;const value = getPath(workspace.manifest.raw!, fieldName.id);// Field is not present => this predicate can never matchif (typeof value === `undefined`)return;prependGoals(thread, point, [new pl.type.Term(`=`, [fieldValue,// TODO: Investigate whether we should JSON.stringify primitive values too.// For now we don't because it would be a breaking change.// https://github.com/yarnpkg/berry/issues/3584new pl.type.Term(typeof value === `object` ? JSON.stringify(value) : value),])]);},[`workspace_field_test/3`]: (thread, point, atom) => {const [workspaceCwd, fieldName, checkCode] = atom.args;thread.prepend([new pl.type.State(point.goal.replace(new pl.type.Term(`workspace_field_test`, [workspaceCwd,fieldName,checkCode,new pl.type.Term(`[]`, []),])),point.substitution,point,)]);},[`workspace_field_test/4`]: (thread, point, atom) => {const [workspaceCwd, fieldName, checkCode, checkArgv] = atom.args;if (!isAtom(workspaceCwd) || !isAtom(fieldName) || !isAtom(checkCode) || !isInstantiatedList(checkArgv)) {thread.throw_error(pl.error.instantiation(atom.indicator));return;}const project = getProject(thread);const workspace = project.tryWorkspaceByCwd(workspaceCwd.id as PortablePath);// Workspace not found => this predicate can never match// We might want to throw here? We can be pretty sure the user did// something wrong at this pointif (workspace == null)return;const value = getPath(workspace.manifest.raw!, fieldName.id);// Field is not present => this predicate can never matchif (typeof value === `undefined`)return;// Inject the variables into a sandboxconst vars: {[key: string]: any} = {$$: value};for (const [index, value] of (checkArgv.toJavaScript() as Array<string>).entries())vars[`$${index}`] = value;const result = vm.runInNewContext(checkCode.id, vars);if (result) {thread.success(point);}},}, [`project_workspaces_by_descriptor/3`,`workspace_field/3`,`workspace_field_test/3`,`workspace_field_test/4`,])

Functions

applyEngineReport

  • applyEngineReport(project: Project, __namedParameters: object, __namedParameters?: object): object

escape

  • escape(what: string | null): string

extractError

  • extractError(val: any): any

extractErrorImpl

  • extractErrorImpl(value: any): any

formatStackLine

  • formatStackLine(configuration: Configuration, caller: nodeUtils.Caller): string

getLinePrefix

  • getLinePrefix(index: number, count: number): string

getProject

  • getProject(thread: pl.type.Thread): Project

isKnownDict

  • isKnownDict(parts: Array<string>, index: number): boolean

linkProjectToSession

  • linkProjectToSession(session: pl.type.Session, project: Project): void

normalizePath

  • normalizePath(p: Array<string> | string): string

parseLink

  • parseLink(link: pl.Link): string | null

parseLinkToJson

  • parseLinkToJson(link: pl.Link): string | null

prependGoals

  • prependGoals(thread: pl.type.Thread, point: pl.type.State, goals: Array<pl.type.Term<number, string>>): void

valueToString

  • valueToString(value: string | null): string

Object literals

Const plugin

plugin: object

commands

commands: (ConstraintsQueryCommand | ConstraintsSourceCommand | ConstraintsCheckCommand)[] = [ConstraintsQueryCommand,ConstraintsSourceCommand,ConstraintsCheckCommand,]

configuration

configuration: object

constraintsPath

constraintsPath: object

default

default: string = `./constraints.pro`

description

description: string = `The path of the constraints file.`

type

type: ABSOLUTE_PATH = SettingsType.ABSOLUTE_PATH

enableConstraintsChecks

enableConstraintsChecks: object

default

default: boolean = false

description

description: string = `If true, constraints will run during installs`

type

type: BOOLEAN = SettingsType.BOOLEAN

hooks

hooks: object

validateProjectAfterInstall

  • validateProjectAfterInstall(project: Project, __namedParameters: object): Promise<void>

Generated using TypeDoc