Recently tap
bumped to v15! 🎉
If you are overwhelmed by all your failing workflows, here a snipped to upgrade them all in once!!
I used the old and dirty massive-wax
module that I made some time ago to open PRs like this one:
https://github.com/Eomm/fastify-405/pull/36
You need to:
Install massive-wax
npm i massive-wax -g
Write a processor
A processor is just a set of functions executed to edit the repository's files.
So create a new tap-15.js
file like this (it is sync
but async
is supported too:
const fs = require('fs')
const path = require('path')
module.exports = function factory (args, logger) {
return {
onRepo (repo) {
const repoPath = path.join(repo.owner, repo.repo)
const pkjPath = path.join(repoPath, './package.json')
const pkj = JSON.parse(fs.readFileSync(pkjPath, 'utf-8'))
pkj.devDependencies.tap = '^15.0.1'
fs.writeFileSync(pkjPath, JSON.stringify(pkj, null, 2))
const tapRcPath = path.join(repoPath, '.taprc')
if (fs.existsSync(tapRcPath)) {
const tapRc = fs.readFileSync(tapRcPath, 'utf-8')
let newTapRc = tapRc.replace(/esm: (true|false)\n/i, '')
if (!pkj.scripts.test.includes('100')) {
newTapRc += '\ncheck-coverage: false'
}
fs.writeFileSync(tapRcPath, newTapRc)
} else {
fs.writeFileSync(tapRcPath, 'check-coverage: false\n')
}
},
onFile (file) {
const fileContent = fs.readFileSync(file, 'utf-8')
const result = fileContent
.replace(/tearDown/g, 'teardown')
.replace(/strictEqual/g, 'equal')
.replace(/deepEqual/g, 'same')
.replace(/false\(/g, 'notOk(')
.replace(/notStrictEqual/g, 'not')
.replace(/similar/g, 'match')
.replace(/strictDeepEqual/g, 'strictSame')
.replace(/is\(/g, 'equal(')
.replace(/throw\(/g, 'throws(')
.replace(/like\(/g, 'match(')
.replace(/contains\(/g, 'has(')
.replace(/equals\(/g, 'equal(')
.replace(/true\(/g, 'ok(')
.replace(/notThrow\(/g, 'doesNotThrow(')
fs.writeFileSync(file, result)
}
}
}
This script is updated here
Write the repositories list
Create a text file called repo-list
with the list of the repositories you want to upgrade:
https://github.com/fastify/fastify-multipart
https://github.com/fastify/fastify-mysql
https://github.com/fastify/light-my-request
Run the magic
Now, let's run massive-wax
!!
massive-wax upgrade -L -R -m 'test(/|\\).*\.js$' -t 'chore tap 15' -r repo-list -p ./tap-15.js -K <GH-TOKEN>
Cloning https://github.com/fastify/fastify-multipart/ to fastify/fastify-multipart
Cloning https://github.com/fastify/fastify-mysql/ to fastify/fastify-mysql
Cloning https://github.com/fastify/light-my-request/ to fastify/light-my-request
Walking C:\Users\behem\workspace\massive-wax\fastify\fastify-multipart
Commit done for fastify-multipart
Walking C:\Users\behem\workspace\massive-wax\fastify\fastify-mysql
Commit done for fastify-mysql
Walking C:\Users\behem\workspace\massive-wax\fastify\light-my-request
Commit done for light-my-request
Push done for fastify-multipart
Push done for fastify-mysql
Opened PR: https://github.com/fastify/fastify-multipart/pull/218
Opened PR: https://github.com/fastify/fastify-mysql/pull/50
Push done for light-my-request
Opened PR: https://github.com/fastify/light-my-request/pull/129
Check out the docs for more options and settings!!
For more content, follow me on Twitter!
Thanks to Matteo Collina for inspiring me this snippet with his gist
Image credits to boscdanjou