Last active
May 12, 2022 20:27
-
-
Save wbern/1f560e2ea3fc7093743c8107a0e105e2 to your computer and use it in GitHub Desktop.
Update caniuse-lite i pnpm-lock.yaml (mostly for Rush users) - PUT INSIDE `scripts/` IN THE REPO ROOT FOR PATHS TO WORK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/node | |
// Script bumps caniuse-lite in common/config/rush/pnpm-lock.yaml | |
const path = require("path"); | |
const fs = require("fs"); | |
const { execSync } = require("child_process"); | |
async function main() { | |
const repoRoot = path.join(__dirname, "../"); | |
const pathToPnpmLockFile = path.join(repoRoot, "common/config/rush/pnpm-lock.yaml"); | |
const pnpmLockfileText = fs.readFileSync(pathToPnpmLockFile).toString(); | |
const latestCanIUseLiteVersion = execSync("npm view caniuse-lite version").toString().trim(); | |
if (!/\d+\.\d+\.\d+/.test(latestCanIUseLiteVersion)) { | |
throw new Error('did not get a suitable version from "npm view" command'); | |
} | |
const canIUseLiteRegex = /caniuse-lite: \d+\.\d+\.\d+/g; | |
const matches = pnpmLockfileText.match(canIUseLiteRegex); | |
console.log( | |
`Found ${matches.length} matches of caniuse-lite in pnpm-lock.yaml, to replace with ${latestCanIUseLiteVersion}.` | |
); | |
const updatedPnpmLockfile = pnpmLockfileText.replace( | |
canIUseLiteRegex, | |
"caniuse-lite: " + latestCanIUseLiteVersion | |
); | |
fs.writeFileSync(pathToPnpmLockFile, updatedPnpmLockfile); | |
console.log( | |
`Updated pnpm-lock.yaml with latest caniuse-lite version ${latestCanIUseLiteVersion}. Now you can run rush update and/or commit this change to get rid of annyong caniuse-lite warnings.` | |
); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment