Skip to content

Commit

Permalink
Fix (intentionally) mismatched react versions
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed Aug 5, 2022
1 parent d3f41b5 commit 6ef2876
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 48 deletions.
18 changes: 9 additions & 9 deletions apps/v3/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name": "@synthetixio/staking-v2",
"name": "@synthetixio/v3-ui",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "webpack-cli serve --open",
"build": "webpack --mode production"
},
"dependencies": {
"react": "^18.1.0",
"react-dom": "^18.1.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@babel/core": "^7.18.10",
"@babel/plugin-transform-runtime": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@babel/core": "^7.11.0",
"@babel/plugin-transform-runtime": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@babel/preset-typescript": "^7.13.0",
"@svgr/webpack": "^6.3.1",
"@types/react": "^18.0.10",
"@types/react": "^17.0.11",
"babel-loader": "^8.2.5",
"css-loader": "^6.7.1",
"html-webpack-plugin": "^5.5.0",
"style-loader": "^3.3.1",
"webpack": "^5.74.0",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.9.3"
}
Expand Down
42 changes: 34 additions & 8 deletions tools/deps/mismatched.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,31 @@ const { fgReset, fgRed, fgGreen, fgYellow, fgCyan } = require('./lib/colors');

const isFix = process.argv.includes('--fix');

// ignore certain deps that are explicitly mismatched versions
function ignored({ parent, name, _version, _location }) {
return (
parent === '@synthetixio/v3-ui' && ['react', 'react-dom'].includes(name)
);
}

async function run() {
const workspaces = await require('./lib/workspaces')();
const ROOT = await require('./lib/exec')('yarn workspace root exec pwd');

const { unique, mismatched } = workspaces
const { unique, mismatched: mismatchedUnfiltered } = workspaces
.flatMap((p) => {
const location = path.join(ROOT, p.location);
const packageJson = require(`${location}/package.json`);
const { dependencies, devDependencies } = packageJson;
return Object.entries(dependencies || {})
.map(([name, version]) => [name, version, p])
.concat(Object.entries(devDependencies || {}).map(([name, version]) => [name, version, p]));
.concat(
Object.entries(devDependencies || {}).map(([name, version]) => [
name,
version,
p,
])
);
})
.sort((a, b) => a[1].localeCompare(b[1]))
.sort((a, b) => a[0].localeCompare(b[0]))
Expand Down Expand Up @@ -55,7 +68,8 @@ async function run() {
},
{ unique: {}, mismatched: [] }
);
// return

const mismatched = mismatchedUnfiltered.filter((item) => !ignored(item));

mismatched.forEach(({ parent, name, version, location }) => {
console.log(
Expand All @@ -64,28 +78,40 @@ async function run() {
`(expected ${fgGreen}${unique[name]}${fgReset})`
);
if (isFix) {
const packageJson = JSON.parse(fs.readFileSync(`${ROOT}/${location}/package.json`, 'utf-8'));
const packageJson = JSON.parse(
fs.readFileSync(`${ROOT}/${location}/package.json`, 'utf-8')
);
if ('dependencies' in packageJson && name in packageJson.dependencies) {
packageJson.dependencies[name] = unique[name];
}
if ('devDependencies' in packageJson && name in packageJson.devDependencies) {
if (
'devDependencies' in packageJson &&
name in packageJson.devDependencies
) {
packageJson.devDependencies[name] = unique[name];
}
console.log(`...FIXING ${fgYellow}${location}/package.json${fgReset}`);
fs.writeFileSync(`${ROOT}/${location}/package.json`, JSON.stringify(packageJson, null, '\t'));
fs.writeFileSync(
`${ROOT}/${location}/package.json`,
JSON.stringify(packageJson, null, '\t')
);
}
});

if (mismatched.length > 0 && isFix) {
console.log('');
console.log(`${fgGreen}Packages fixed: ${fgGreen}${mismatched.length}${fgReset}`);
console.log(
`${fgGreen}Packages fixed: ${fgGreen}${mismatched.length}${fgReset}`
);
cp.execSync('yarn install', { encoding: 'utf-8', stdio: 'inherit' });
return;
}

if (mismatched.length > 0) {
console.log('');
console.log(`${fgRed}Versions need fixing: ${fgGreen}${mismatched.length}${fgReset}`);
console.log(
`${fgRed}Versions need fixing: ${fgGreen}${mismatched.length}${fgReset}`
);
console.log(`${fgCyan}Run ${fgGreen}deps-mismatched --fix${fgReset}`);
throw new Error(`Versions need fixing: ${mismatched.length}`);
}
Expand Down
62 changes: 31 additions & 31 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/core@npm:^7.1.0, @babel/core@npm:^7.11.0, @babel/core@npm:^7.12.3, @babel/core@npm:^7.18.10, @babel/core@npm:^7.18.5, @babel/core@npm:^7.7.2, @babel/core@npm:^7.8.0":
"@babel/core@npm:^7.1.0, @babel/core@npm:^7.11.0, @babel/core@npm:^7.12.3, @babel/core@npm:^7.18.5, @babel/core@npm:^7.7.2, @babel/core@npm:^7.8.0":
version: 7.18.10
resolution: "@babel/core@npm:7.18.10"
dependencies:
Expand Down Expand Up @@ -1147,7 +1147,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-transform-runtime@npm:^7.13.10, @babel/plugin-transform-runtime@npm:^7.18.10":
"@babel/plugin-transform-runtime@npm:^7.13.10":
version: 7.18.10
resolution: "@babel/plugin-transform-runtime@npm:7.18.10"
dependencies:
Expand Down Expand Up @@ -1255,7 +1255,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/preset-env@npm:^7.13.10, @babel/preset-env@npm:^7.18.10, @babel/preset-env@npm:^7.18.2":
"@babel/preset-env@npm:^7.13.10, @babel/preset-env@npm:^7.18.2":
version: 7.18.10
resolution: "@babel/preset-env@npm:7.18.10"
dependencies:
Expand Down Expand Up @@ -1371,7 +1371,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/preset-typescript@npm:^7.13.0, @babel/preset-typescript@npm:^7.17.12, @babel/preset-typescript@npm:^7.18.6":
"@babel/preset-typescript@npm:^7.13.0, @babel/preset-typescript@npm:^7.17.12":
version: 7.18.6
resolution: "@babel/preset-typescript@npm:7.18.6"
dependencies:
Expand Down Expand Up @@ -2655,29 +2655,6 @@ __metadata:
languageName: unknown
linkType: soft

"@synthetixio/staking-v2@workspace:apps/v3":
version: 0.0.0-use.local
resolution: "@synthetixio/staking-v2@workspace:apps/v3"
dependencies:
"@babel/core": ^7.18.10
"@babel/plugin-transform-runtime": ^7.18.10
"@babel/preset-env": ^7.18.10
"@babel/preset-react": ^7.18.6
"@babel/preset-typescript": ^7.18.6
"@svgr/webpack": ^6.3.1
"@types/react": ^18.0.10
babel-loader: ^8.2.5
css-loader: ^6.7.1
html-webpack-plugin: ^5.5.0
react: ^18.1.0
react-dom: ^18.1.0
style-loader: ^3.3.1
webpack: ^5.74.0
webpack-cli: ^4.10.0
webpack-dev-server: ^4.9.3
languageName: unknown
linkType: soft

"@synthetixio/transaction-notifier@workspace:packages/transaction-notifier":
version: 0.0.0-use.local
resolution: "@synthetixio/transaction-notifier@workspace:packages/transaction-notifier"
Expand All @@ -2696,6 +2673,29 @@ __metadata:
languageName: unknown
linkType: soft

"@synthetixio/v3-ui@workspace:apps/v3":
version: 0.0.0-use.local
resolution: "@synthetixio/v3-ui@workspace:apps/v3"
dependencies:
"@babel/core": ^7.11.0
"@babel/plugin-transform-runtime": ^7.13.10
"@babel/preset-env": ^7.13.10
"@babel/preset-react": ^7.18.6
"@babel/preset-typescript": ^7.13.0
"@svgr/webpack": ^6.3.1
"@types/react": ^17.0.11
babel-loader: ^8.2.5
css-loader: ^6.7.1
html-webpack-plugin: ^5.5.0
react: ^18.0.0
react-dom: ^18.0.0
style-loader: ^3.3.1
webpack: ^5.73.0
webpack-cli: ^4.10.0
webpack-dev-server: ^4.9.3
languageName: unknown
linkType: soft

"@synthetixio/wei@workspace:*, @synthetixio/wei@workspace:packages/wei":
version: 0.0.0-use.local
resolution: "@synthetixio/wei@workspace:packages/wei"
Expand Down Expand Up @@ -3160,7 +3160,7 @@ __metadata:
languageName: node
linkType: hard

"@types/react@npm:*, @types/react@npm:>=16.9.0, @types/react@npm:^18.0.10":
"@types/react@npm:*, @types/react@npm:>=16.9.0":
version: 18.0.15
resolution: "@types/react@npm:18.0.15"
dependencies:
Expand Down Expand Up @@ -9680,7 +9680,7 @@ __metadata:
languageName: node
linkType: hard

"react-dom@npm:^18.1.0":
"react-dom@npm:^18.0.0":
version: 18.2.0
resolution: "react-dom@npm:18.2.0"
dependencies:
Expand Down Expand Up @@ -9771,7 +9771,7 @@ __metadata:
languageName: node
linkType: hard

"react@npm:^18.1.0":
"react@npm:^18.0.0":
version: 18.2.0
resolution: "react@npm:18.2.0"
dependencies:
Expand Down Expand Up @@ -11717,7 +11717,7 @@ __metadata:
languageName: node
linkType: hard

"webpack@npm:^5.73.0, webpack@npm:^5.74.0":
"webpack@npm:^5.73.0":
version: 5.74.0
resolution: "webpack@npm:5.74.0"
dependencies:
Expand Down

0 comments on commit 6ef2876

Please sign in to comment.