Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves JS constraints #5341

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions .yarn/versions/d3698af2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
releases:
"@yarnpkg/cli": major
"@yarnpkg/core": minor
"@yarnpkg/plugin-constraints": major
"@yarnpkg/types": major

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnp"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
9 changes: 4 additions & 5 deletions packages/plugin-constraints/sources/ModernEngine.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {Manifest, miscUtils, nodeUtils, Project, structUtils} from '@yarnpkg/core';

import * as context from './ModernEngineContext';
import * as constraintUtils from './constraintUtils';

export class ModernEngine implements constraintUtils.Engine {
constructor(private project: Project) {
}

private createEnvironment() {
const workspaces = new constraintUtils.Index<context.Workspace>([`cwd`, `ident`]);
const dependencies = new constraintUtils.Index<context.Dependency>([`type`, `ident`]);
const workspaces = new constraintUtils.Index<Yarn.Constraints.Workspace>([`cwd`, `ident`]);
const dependencies = new constraintUtils.Index<Yarn.Constraints.Dependency>([`type`, `ident`]);

const result: constraintUtils.ProcessResult = {
manifestUpdates: new Map(),
Expand Down Expand Up @@ -85,7 +84,7 @@ export class ModernEngine implements constraintUtils.Engine {
async process() {
const env = this.createEnvironment();

const context: context.Context = {
const context: Yarn.Constraints.Context = {
Yarn: {
workspace: filter => {
return env.workspaces.find(filter)[0] ?? null;
Expand All @@ -103,7 +102,7 @@ export class ModernEngine implements constraintUtils.Engine {
if (!userConfig?.constraints)
return null;

userConfig.constraints(context);
await userConfig.constraints(context);

return env.result;
}
Expand Down
39 changes: 0 additions & 39 deletions packages/plugin-constraints/sources/ModernEngineContext.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plugin-constraints/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const plugin: Plugin<Hooks> = {
ConstraintsCheckCommand,
],
hooks: {
async validateProject(project, {reportError}) {
async validateProjectAfterInstall(project, {reportError}) {
if (!project.configuration.get(`enableConstraintsChecks`))
return;

Expand Down
12 changes: 12 additions & 0 deletions packages/yarnpkg-core/sources/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ export interface Hooks {
}
) => void;

/**
* Called during the `Post-install validation step` of the `install` method
* from the `Project` class.
*/
validateProjectAfterInstall?: (
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.
Expand Down
26 changes: 23 additions & 3 deletions packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ export class Project {
const nodeLinker = this.configuration.get(`nodeLinker`);
Configuration.telemetry?.reportInstall(nodeLinker);

let hasErrors = false;
let hasPreErrors = false;
await opts.report.startTimerPromise(`Project validation`, {
skipIfEmpty: true,
}, async () => {
Expand All @@ -1528,12 +1528,12 @@ export class Project {
},
reportError: (name, text) => {
opts.report.reportError(name, text);
hasErrors = true;
hasPreErrors = true;
},
});
});

if (hasErrors)
if (hasPreErrors)
return;

for (const extensionsByIdent of this.configuration.packageExtensions.values())
Expand Down Expand Up @@ -1661,6 +1661,26 @@ export class Project {

await this.persistInstallStateFile();

let hasPostErrors = false;
await opts.report.startTimerPromise(`Post-install validation`, {
skipIfEmpty: true,
}, async () => {
await this.configuration.triggerHook(hooks => {
return hooks.validateProjectAfterInstall;
}, this, {
reportWarning: (name, text) => {
opts.report.reportWarning(name, text);
},
reportError: (name, text) => {
opts.report.reportError(name, text);
hasPostErrors = true;
},
});
});

if (hasPostErrors)
return;

await this.configuration.triggerHook(hooks => {
return hooks.afterAllInstalled;
}, this, opts);
Expand Down
1 change: 0 additions & 1 deletion packages/yarnpkg-pnp/sources/generatePnpScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Filename} from '@yarnpkg/fslib';

import {generatePrettyJson} from './generatePrettyJson';
import {generateSerializedState} from './generateSerializedState';
// @ts-expect-error
import getTemplate from './hook';
import {SerializedState} from './types';
import {PnpSettings} from './types';
Expand Down
33 changes: 33 additions & 0 deletions packages/yarnpkg-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@yarnpkg/types",
"version": "4.0.0-rc.40",
"stableVersion": "3.4.1",
"license": "BSD-2-Clause",
"main": "./sources/index.ts",
"exports": {
".": "./sources/index.ts",
"./package.json": "./package.json"
},
"repository": {
"type": "git",
"url": "ssh://[email protected]/yarnpkg/berry.git",
"directory": "packages/yarnpkg-types"
},
"scripts": {
"postpack": "rm -rf lib",
"prepack": "run build:compile \"$(pwd)\""
},
"publishConfig": {
"main": "./lib/index.js",
"exports": {
".": "./lib/index.js",
"./package.json": "./package.json"
}
},
"files": [
"/lib/**/*"
],
"engines": {
"node": ">=14.15.0"
}
}
Loading