mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-14 03:26:13 -04:00
Read package.json before updating (#284)
* Read package.json before updating Using the cached version of package.json can cause ovewriting of changes close #280 * Skip GitHub test on CI The GitHub test fails frequently with 403 error with no good no reason
This commit is contained in:
@@ -4,9 +4,10 @@ var cache = {}
|
||||
* Works identically to require('/path/to/file.json'), but safer.
|
||||
*/
|
||||
|
||||
module.exports = function requireJson (path) {
|
||||
module.exports = function requireJson (path, opts) {
|
||||
opts = opts || {}
|
||||
path = require('path').resolve(path)
|
||||
if (cache[path]) return cache[path]
|
||||
if (!opts.ignoreCache && cache[path]) return cache[path]
|
||||
cache[path] = JSON.parse(require('fs').readFileSync(path, 'utf-8'))
|
||||
return cache[path]
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ var writeJson = require('./fs/write_json')
|
||||
var sortedObject = require('sorted-object')
|
||||
|
||||
module.exports = function save (pkg, installedPackages, saveType, useExactVersion) {
|
||||
var packageJson = requireJson(pkg.path)
|
||||
// Read the latest version of package.json to avoid accidental overwriting
|
||||
var packageJson = requireJson(pkg.path, { ignoreCache: true })
|
||||
packageJson[saveType] = packageJson[saveType] || {}
|
||||
installedPackages.forEach(function (dependency) {
|
||||
var semverCharacter = useExactVersion ? '' : '^'
|
||||
|
||||
@@ -207,18 +207,21 @@ test('local file', function (t) {
|
||||
}, t.end)
|
||||
})
|
||||
|
||||
test('from a github repo', function (t) {
|
||||
prepare()
|
||||
install(['kevva/is-negative'], { quiet: true })
|
||||
.then(function () {
|
||||
var localPkg = require(
|
||||
join(process.cwd(), 'node_modules', 'is-negative'))
|
||||
// Skipping on CI as failing frequently there, due to environment issues
|
||||
if (!process.env.CI) {
|
||||
test('from a github repo', function (t) {
|
||||
prepare()
|
||||
install(['kevva/is-negative'], { quiet: true })
|
||||
.then(function () {
|
||||
var localPkg = require(
|
||||
join(process.cwd(), 'node_modules', 'is-negative'))
|
||||
|
||||
t.ok(localPkg, 'isNegative() is available')
|
||||
t.ok(localPkg, 'isNegative() is available')
|
||||
|
||||
t.end()
|
||||
}, t.end)
|
||||
})
|
||||
t.end()
|
||||
}, t.end)
|
||||
})
|
||||
}
|
||||
|
||||
test('shrinkwrap compatibility', function (t) {
|
||||
prepare()
|
||||
|
||||
Reference in New Issue
Block a user