Socket
Socket
Sign inDemoInstall

parent-package-json

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parent-package-json - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

.editorconfig

12

lib/index.js
'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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc