parent-package-json
Advanced tools
Comparing version 2.0.0 to 2.0.1
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
module.exports = function findPackageJSON(startPath, ignore) { | ||
module.exports = function (startPath, ignore) { | ||
startPath = startPath || process.cwd(); | ||
@@ -26,3 +27,6 @@ ignore = ignore || 0; | ||
nextPath = path.join(searchPath + '/..'); | ||
if (nextPath === path.normalize('/') || nextPath === '.' || nextPath === '..') { | ||
// Linux root is "/" | ||
// Windows root is "C:\" or any other drive letter | ||
const root = (os.platform() === 'win32') ? nextPath.split(path.sep)[0] + path.sep : path.normalize('/'); | ||
if (nextPath === root || nextPath === '.' || nextPath === '..') { | ||
break; | ||
@@ -34,6 +38,6 @@ } | ||
return { | ||
read: function () { | ||
read() { | ||
return fs.readFileSync(path.join(searchPath + '/package.json'), 'utf8'); | ||
}, | ||
parse: function () { | ||
parse() { | ||
return JSON.parse(fs.readFileSync(path.join(searchPath + '/package.json'), 'utf8')); | ||
@@ -40,0 +44,0 @@ }, |
{ | ||
"name": "parent-package-json", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Find, read and parse the package.json of the parent module", | ||
@@ -23,6 +23,6 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"ava": "^0.16.0", | ||
"ava": "^0.22.0", | ||
"coveralls": "2.x.x", | ||
"nyc": "^8.1.0", | ||
"xo": "^0.16.0" | ||
"nyc": "^11.0.3", | ||
"xo": "^0.19.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "engines": { |
@@ -6,15 +6,15 @@ const path = require('path'); | ||
test('find right package.json', t => { | ||
t.is(parent('./fixtures/firstFolder/secondFolder').path, path.normalize('fixtures/firstFolder/package.json')); | ||
t.is(parent('./test/fixtures/firstFolder/secondFolder').path, path.normalize('test/fixtures/firstFolder/package.json')); | ||
}); | ||
test('ignore one package.json', t => { | ||
t.is(parent('./fixtures/firstFolder/secondFolder/thirdFolder/fourthFolder', 1).path, path.normalize('fixtures/firstFolder/package.json')); | ||
t.is(parent('./test/fixtures/firstFolder/secondFolder/thirdFolder/fourthFolder', 1).path, path.normalize('test/fixtures/firstFolder/package.json')); | ||
}); | ||
test('read package.json', t => { | ||
t.deepEqual(JSON.parse(parent('./fixtures/firstFolder/secondFolder').read()), {version: '1.0.0'}); | ||
t.deepEqual(JSON.parse(parent('./test/fixtures/firstFolder/secondFolder').read()), {version: '1.0.0'}); | ||
}); | ||
test('parse package.json', t => { | ||
t.deepEqual(parent('./fixtures/firstFolder/secondFolder').parse(), {version: '1.0.0'}); | ||
t.deepEqual(parent('./test/fixtures/firstFolder/secondFolder').parse(), {version: '1.0.0'}); | ||
}); | ||
@@ -21,0 +21,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
145563
13
59