-
Notifications
You must be signed in to change notification settings - Fork 45.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prune NPM metadata fields from packages before re-publishing
- Loading branch information
Brian Vaughn
committed
Jan 17, 2019
1 parent
4feab7f
commit 925989d
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
scripts/release/prepare-stable-commands/prune-package-registry-metadata.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const {logPromise} = require('../utils'); | ||
const {readJson, writeJson} = require('fs-extra'); | ||
const {join} = require('path'); | ||
|
||
const run = async ({cwd, packages}) => { | ||
const nodeModulesPath = join(cwd, 'build/node_modules'); | ||
|
||
for (let i = 0; i < packages.length; i++) { | ||
const packageName = packages[i]; | ||
const packageJSONPath = join(nodeModulesPath, packageName, 'package.json'); | ||
const packageJSON = await readJson(packageJSONPath); | ||
|
||
// NPM adds a lot of metadata fields on checkout. | ||
// It's nice to strip these before re-publishing the package. | ||
for (let key in packageJSON) { | ||
if (key.startsWith('_')) { | ||
delete packageJSON[key]; | ||
} | ||
} | ||
|
||
await writeJson(packageJSONPath, packageJSON, {spaces: 2}); | ||
} | ||
}; | ||
|
||
module.exports = async params => { | ||
return logPromise(run(params), 'Pruning package registry metadata'); | ||
}; |
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