-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve
package.json
and npm-shrinkwrap.json
formatting
- Loading branch information
Showing
2 changed files
with
36 additions
and
12 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,15 +1,18 @@ | ||
const {readJson, writeJson, pathExists} = require('fs-extra'); | ||
const {readFile, writeFile, pathExists} = require('fs-extra'); | ||
|
||
module.exports = async (version, logger) => { | ||
const pkg = await readJson('./package.json'); | ||
const pkg = (await readFile('./package.json')).toString(); | ||
|
||
await writeJson('./package.json', Object.assign(pkg, {version})); | ||
await writeFile('./package.json', replaceVersion(pkg, version)); | ||
logger.log('Wrote version %s to package.json', version); | ||
|
||
if (await pathExists('./npm-shrinkwrap.json')) { | ||
const shrinkwrap = await readJson('./npm-shrinkwrap.json'); | ||
shrinkwrap.version = version; | ||
await writeJson('./npm-shrinkwrap.json', shrinkwrap); | ||
const shrinkwrap = (await readFile('./npm-shrinkwrap.json')).toString(); | ||
await writeFile('./npm-shrinkwrap.json', replaceVersion(shrinkwrap, version)); | ||
logger.log('Wrote version %s to npm-shrinkwrap.json', version); | ||
} | ||
}; | ||
|
||
function replaceVersion(json, version) { | ||
return json.replace(/("version"\s*:\s*")\S+?(\s*")/, `$1${version}$2`); | ||
} |
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