From b2876512d000449ba5412817df0747d985d6d8f3 Mon Sep 17 00:00:00 2001 From: plouc Date: Tue, 2 May 2023 21:46:26 +0900 Subject: [PATCH] feat(infrastructure): restore the fix to bump peer dependencies --- Makefile | 3 ++- package.json | 1 + scripts/bump-peer-deps.js | 32 ------------------------------- scripts/bump-peer-deps.mjs | 39 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 33 deletions(-) delete mode 100644 scripts/bump-peer-deps.js create mode 100644 scripts/bump-peer-deps.mjs diff --git a/Makefile b/Makefile index a109237de3..4fdd19c84d 100644 --- a/Makefile +++ b/Makefile @@ -181,11 +181,12 @@ pkgs-screenshots: ##@1 packages generate screenshots for packages readme (websit @node scripts/capture.mjs pkgs-publish-dry-run: ##@1 packages dry run for packages publication - @$(MAKE) pkgs-build + #@$(MAKE) pkgs-build @pnpm lerna publish \ --exact \ --no-git-tag-version \ --no-push \ + --force-publish \ --registry "http://localhost:4873" \ --loglevel verbose diff --git a/package.json b/package.json index 82282a01c1..74d2e5fe9a 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "scripts": { "make:init": "make init", "build": "echo 'nothing to do, please use make for available commands'", + "version": "node scripts/bump-peer-deps.mjs", "heroku-postbuild": "make pkgs-build && cd api && pnpm build" }, "engines": { diff --git a/scripts/bump-peer-deps.js b/scripts/bump-peer-deps.js deleted file mode 100644 index a16fb4eba3..0000000000 --- a/scripts/bump-peer-deps.js +++ /dev/null @@ -1,32 +0,0 @@ -const fs = require('fs') -const { join } = require('path') - -function parseFile(file) { - return JSON.parse(fs.readFileSync(file, 'utf-8')) -} - -fs.readdirSync('./packages', { withFileTypes: true }) - .filter(dirent => dirent.isDirectory()) - .map(dirent => join('packages', dirent.name, 'package.json')) - .map(file => [file, parseFile(file)]) - .forEach(([file, package]) => { - for (const [dependency, version] of Object.entries(package.devDependencies || {})) { - if ( - !dependency.startsWith('@nivo/') || - !( - dependency in (package.peerDependencies || {}) && - version !== package.peerDependencies[dependency] - ) - ) { - continue - } - - package.peerDependencies[dependency] = version - - console.log( - `Bumping peerDependency of '${dependency}' in '${package.name}' to ${version}.` - ) - } - - fs.writeFileSync(file, JSON.stringify(package, null, 2) + '\n', { encoding: 'utf-8' }) - }) diff --git a/scripts/bump-peer-deps.mjs b/scripts/bump-peer-deps.mjs new file mode 100644 index 0000000000..4efc3106a1 --- /dev/null +++ b/scripts/bump-peer-deps.mjs @@ -0,0 +1,39 @@ +import { readdirSync, readFileSync, writeFileSync } from 'node:fs' +import { join } from 'node:path' + +const files = {} +const packages = {} +const versions = {} + +readdirSync('./packages', { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => join('packages', dirent.name, 'package.json')) + .forEach(file => { + const pkg = JSON.parse(readFileSync(file, 'utf-8')) + files[pkg.name] = file + packages[pkg.name] = pkg + versions[pkg.name] = pkg.version + }) + +for (const [pkgName, pkg] of Object.entries(packages)) { + for (const [peerDep, currentVersion] of Object.entries(pkg.peerDependencies || {})) { + if (!peerDep.startsWith('@nivo/')) continue + + if (!(peerDep in versions)) { + throw new Error(`Unable to find ${peerDep} in packages`) + } + + const version = versions[peerDep] + pkg.peerDependencies[peerDep] = version + + console.log( + `Bumping peerDependency ${peerDep} in ${pkgName} to ${version} (was ${currentVersion})` + ) + } + + writeFileSync( + files[pkgName], + JSON.stringify(pkg, null, 4) + '\n', + { encoding: 'utf-8' } + ) +}