Options
All
  • Public
  • Public/Protected
  • All
Menu

Package plugin-constraints

@yarnpkg/plugin-constraints

This plugin adds support for constraints to Yarn.

Install

yarn plugin import constraints

Type aliases

EnforcedDependency

EnforcedDependency: object

Type declaration

EnforcedField

EnforcedField: object

Type declaration

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

Variables

Const DEPENDENCY_TYPES

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

isAtom

isAtom: is_atom

isInstantiatedList

isInstantiatedList: is_instantiated_list

isVariable

isVariable: is_variable

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

escape

  • escape(what: string | null): string

extractError

  • extractError(val: any): any

extractErrorImpl

  • extractErrorImpl(value: any): any

getLinePrefix

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

getProject

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

linkProjectToSession

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

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

processDependencyConstraints

  • processDependencyConstraints(toSave: Set<Workspace>, errors: Array<[]>, enforcedDependencies: Array<EnforcedDependency>, __namedParameters: object): Promise<void>

processFieldConstraints

  • processFieldConstraints(toSave: Set<Workspace>, errors: Array<[]>, enforcedFields: Array<EnforcedField>, __namedParameters: object): Promise<void>

setWorkspaceField

  • setWorkspaceField(workspace: Workspace, fieldPath: string, value: string | null): Promise<void>

valueToString

  • valueToString(value: string | null): string

Object literals

Const plugin

plugin: object

commands

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

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

Generated using TypeDoc