Skip to content

Instantly share code, notes, and snippets.

@emkis
Created January 23, 2023 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emkis/3d626b20e75727e2e0712a98736c874b to your computer and use it in GitHub Desktop.
Save emkis/3d626b20e75727e2e0712a98736c874b to your computer and use it in GitHub Desktop.
Script to clean `package.json` properties before publishing a package
import packageJson from '../package.json'
import { writeFile } from 'fs/promises'
import { resolve } from 'node:path'
const unwantedProperties = ['keywords', 'files', 'scripts', 'devDependencies']
unwantedProperties.forEach(deleteProperty)
rewritePackageJson()
function deleteProperty(key: string) {
delete packageJson[key]
}
async function rewritePackageJson() {
try {
const packagePath = resolve(__dirname, '..', 'package.json')
const content = JSON.stringify(packageJson)
await writeFile(packagePath, content)
} catch {
console.log(`Failed to rewrite the cleaned package.json file`)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment