Script generator for deps updating
PoC
To implement deps updating in form of git patches. As a part of Hackathon We Make QIWI 2.0 2023.
git
echo
-
sed
optional -
nodejs
for generation phase only
npm i upkeeper
import {upkeeper} from 'upkeeper'
const config = {
granularity: 'proposal', // Granularity level: 'proposal' | 'same' | 'resource' | 'all-in'
keepers: [
['npm', {
resources: 'package.json', // package.json,packages/*/package.json
scopes: ['dependencies', 'devDependencies'],
exlude: 'react',
}]
],
dryrun: true, // Do not apply changes
combine: false, // Join all patches into one script
diff: 'sed', // Diff-patch provider: git or sed
output: 'patches', // a directory to store patches
pre: '', // a scripts to run before & after each patch
post: 'yarn install && git add . && git commit -m "chore(deps): update deps" && git push origin HEAD:refs/heads/up-deps'
}
const {scripts, proposals} = await upkeeper(config)
Choose a scripts aggregation strategy to produce appropriate patches. Default is proposal
.
Level | Description |
---|---|
proposal |
Produces a patch for each proposal: resource + dep name + dep version |
same |
Generates script for each common proposal: dep name + dep version. Useful for monorepos. |
resource |
Joins changes for each resource entry |
all-in |
A single patch for all deps in all resources |
dot is used as a template engine for pre
and post
options, so you can inject proposal metadata into your scripts.
{
pre: 'echo "updated {{=it.data.name}} to {{=it.data.version}}"'
}
// 'echo "updated @emotion/css to ^11.2.0"
npx upkeeper --config=config.json --output='patches'
sh patches/upkeeper.sh
#!/usr/bin/env bash
set -e
echo pre
echo $'diff --git a/packages/blank/package.json b/packages/blank/package.json\n--- a/packages/blank/package.json\n+++ b/packages/blank/package.json\n@@ -46,6 +46,6 @@\n "homepage": "https://github.com/antongolub/misc#readme",\n "devDependencies": {\n "@antongolub/infra": "workspace:*",\n- "@types/node": "^20.10.3"\n+ "@types/node": "^20.10.4"\n }\n }\n' | git apply --whitespace=fix --inaccurate-eof
echo post
echo pre
echo $'diff --git a/packages/infra/package.json b/packages/infra/package.json\n--- a/packages/infra/package.json\n+++ b/packages/infra/package.json\n@@ -23,7 +23,7 @@\n "@semrel-extra/topo": "^1.14.0",\n "c8": "^8.0.1",\n "concurrently": "^8.2.2",\n- "esbuild": "^0.19.8",\n+ "esbuild": "^0.19.9",\n "esbuild-node-externals": "^1.11.0",\n "eslint": "^8.55.0",\n "eslint-config-qiwi": "^2.1.3",\n' | git apply --whitespace=fix --inaccurate-eof
echo post
# ...
Option | Description | Default |
---|---|---|
--cwd |
Working directory | process.cwd() |
--config |
Path to config file | |
--combine |
Join all patches into one script | false |
--diff |
Diff-patch provider: git or sed
|
git |
--dryrun |
Do not apply changes. |
true if --ouput option is set |
--granularity |
Granularity level | proposal |
--output |
Output directory |