Created
December 28, 2022 06:10
-
-
Save rohangeorge91/260c93a58cb6a5575f78cf5d17a08c4f to your computer and use it in GitHub Desktop.
A nodejs script to read and upgrade all dependencies (please check if the project works properly after this since this might break peer dependencies)
This file contains 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
const fs = require('fs/promises') | |
const { execSync } = require('node:child_process') | |
const readJsonFile = async (filepath, encoding = 'utf8') => | |
JSON.parse(await fs.readFile(filepath, { encoding })) | |
const upgradePackage = (dependency, type = 'non-dev') => { | |
const addFlags = type === 'non-dev' ? '' : ' --dev' | |
execSync(`yarn remove ${dependency}`); | |
execSync(`yarn add ${dependency}${addFlags}`); | |
} | |
const processPackageJson = async () => { | |
const fileData = await readJsonFile('./package.json') | |
Object.keys(fileData.dependencies).forEach(dependency => | |
upgradePackage(dependency), | |
) | |
Object.keys(fileData.devDependencies).forEach(dependency => | |
upgradePackage(dependency, 'dev'), | |
) | |
} | |
processPackageJson() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment