Skip to content

Commit

Permalink
add constraint checks to repo (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas authored Feb 4, 2025
1 parent 1306572 commit b7dad99
Show file tree
Hide file tree
Showing 12 changed files with 1,652 additions and 151 deletions.
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ nodeLinker: node-modules
npmAuthToken: "${NODE_AUTH_TOKEN-}"

yarnPath: .yarn/releases/yarn-4.2.2.cjs

enableConstraintsChecks: true
3 changes: 3 additions & 0 deletions integration-test/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.5.2",
"@types/react": "*",
"@types/react-dom": "*",
"babel-jest": "^29.7.0",
"graphql": "*",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fixed-jsdom": "^0.0.9"
Expand Down
1 change: 1 addition & 0 deletions integration-test/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"autoprefixer": "^10.4.20",
"graphql": "*",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.15",
"typescript": "^5.6.3",
Expand Down
10 changes: 8 additions & 2 deletions integration-test/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"version": "0.0.0",
"private": true,
"peerDependencies": {
"@apollo/client": "*",
"graphql": "*"
"@apollo/client": "*"
},
"devDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"graphql": "*",
"react": "*",
"react-dom": "*"
}
}
3 changes: 3 additions & 0 deletions integration-test/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"devDependencies": {
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^16.1.0",
"@types/react": "*",
"@types/react-dom": "*",
"@vitejs/plugin-react": "^4.2.1",
"graphql": "*",
"vitest": "^1.3.1"
}
}
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"main": "package.json",
"dependencies": {
"@changesets/cli": "^2.27.10",
"@yarnpkg/types": "^4.0.0",
"prettier": "^3.0.0",
"semver": "^7.6.0"
},
Expand All @@ -32,14 +33,19 @@
"react-router": "patch:react-router@npm%3A7.0.2#~/.yarn/patches/react-router-npm-7.0.2-b96f2bd13c.patch",
"@tanstack/react-router": "patch:@tanstack/react-router@npm%3A1.97.3#~/.yarn/patches/@tanstack-react-router-npm-1.97.3-ad16343f36.patch",
"@tanstack/start": "patch:@tanstack/start@npm%3A1.97.3#~/.yarn/patches/@tanstack-start-npm-1.97.3-da273c2822.patch",
"@types/react": "19.0.2"
"@types/react": "19.0.2",
"@types/react-dom": "19.0.2",
"react": "19.0.0",
"react-dom": "19.0.0"
},
"devDependencies": {
"@microsoft/api-documenter": "7.24.3",
"@size-limit/file": "11.1.2",
"@size-limit/webpack": "11.1.2",
"@size-limit/webpack-why": "11.1.2",
"@types/node": "^22.10.9",
"@yarnpkg/cli": "^4.6.0",
"@yarnpkg/core": "^4.2.0",
"knip": "^5.43.1",
"size-limit": "11.1.2",
"typescript": "^5.7.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/client-react-streaming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"@tsconfig/recommended": "1.0.6",
"@types/node": "20.12.11",
"@types/react": "^19.0.0",
"@types/react-dom": "*",
"concurrently": "8.2.2",
"esbuild": "^0.24.2",
"eslint": "8.57.0",
Expand All @@ -149,6 +150,7 @@
"jsdom": "24.0.0",
"publint": "0.2.7",
"react": "^19.0.0",
"react-dom": "*",
"react-error-boundary": "4.0.13",
"react-server-dom-webpack": "^19.0.0",
"rimraf": "5.0.5",
Expand Down
2 changes: 2 additions & 0 deletions packages/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@
"@tsconfig/recommended": "1.0.6",
"@types/node": "20.12.11",
"@types/react": "^19.0.0",
"@types/react-dom": "*",
"concurrently": "8.2.2",
"esbuild": "0.24.2",
"eslint": "8.57.0",
"graphql": "16.8.1",
"publint": "0.2.7",
"react": "^19.0.0",
"react-dom": "*",
"react-router": "patch:react-router@npm%3A7.0.2#~/.yarn/patches/react-router-npm-7.0.2-b96f2bd13c.patch",
"rimraf": "5.0.5",
"tsup": "8.0.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/tanstack-start/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@
"@tsconfig/recommended": "1.0.6",
"@types/node": "20.12.11",
"@types/react": "^19.0.0",
"@types/react-dom": "*",
"concurrently": "8.2.2",
"esbuild": "0.24.2",
"eslint": "8.57.0",
"graphql": "16.8.1",
"publint": "0.2.7",
"react": "^19.0.0",
"react-dom": "*",
"react-error-boundary": "5.0.0",
"rimraf": "5.0.5",
"tsup": "8.0.2",
Expand Down
6 changes: 5 additions & 1 deletion packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"react-dom": "^19.0.0",
"typescript": "^5.7.3"
},
"type": "module"
"type": "module",
"devDependencies": {
"@types/react": "*",
"@types/react-dom": "*"
}
}
83 changes: 83 additions & 0 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// @ts-check
/** @type {import('@yarnpkg/types')} */
const { defineConfig } = require("@yarnpkg/types");
const { Configuration, Project } = require("@yarnpkg/core");
const { getPluginConfiguration } = require("@yarnpkg/cli");

module.exports = defineConfig({
async constraints({ Yarn }) {
const config = await Configuration.find(
__dirname,
getPluginConfiguration()
);
const { project } = await Project.find(config, __dirname);
await project.restoreInstallState();

function getCandidates(/** @type string */ ident) {
const [scope, name] = ident.startsWith("@")
? ident.substring(1).split("/")
: [null, ident];
return Object.fromEntries(
Array.from(project.storedPackages.values())
.filter(
(pkg) =>
pkg.scope == scope &&
pkg.name == name &&
pkg.reference.startsWith(`virtual:`)
)
.map((pkg) => [
pkg.reference.replace(/^virtual:/, "").substring(0, 5),
pkg,
])
);
}

const packagesWithFixedPeers = {
"@apollo/client": [
"graphql",
"react",
"react-dom",
"@types/react",
"@types/react-dom",
],
react: ["react-dom", "@types/react", "@types/react-dom"],
};
const shouldBeUnique = new Set([
"@apollo/client",
"graphql",
"react",
"react-dom",
"@types/react",
"@types/react-dom",
]);

for (const [ident, peers] of Object.entries(packagesWithFixedPeers)) {
const deps = Yarn.dependencies({ ident });
for (const dep of deps) {
for (const peer of peers) {
if (
dep.workspace.manifest.dependencies?.[peer] ||
dep.workspace.manifest.devDependencies?.[peer]
) {
continue;
}
dep.workspace.set(["devDependencies", peer], "*");
shouldBeUnique.delete(ident);
}
}
}
for (const ident of Array.from(shouldBeUnique.values())) {
if (Object.keys(getCandidates(ident)).length > 1) {
console.log(getCandidates(ident));
Yarn.dependency({ ident }).workspace?.error(`
The package ${ident} has multiple versions installed, which will cause problems.
This could not be autofixed, so you need to manually fix it.
Run this command to see how these installations differ from each other and fix them:
yarn info -AR --dependents --virtuals ${ident}
`);
process.exitCode = 1;
}
}
},
});
Loading

0 comments on commit b7dad99

Please sign in to comment.