Skip to content

Commit

Permalink
refactor: migrate pkg read to use node fs
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Jun 9, 2019
1 parent d2c339f commit d106789
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 20 deletions.
112 changes: 97 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint-plugin-mocha": "^5.3.0",
"eslint-plugin-prettier": "^3.1.0",
"generate-changelog": "^1.7.1",
"handlebars": "^4.1.2",
"husky": "^2.4.0",
"lint-staged": "^8.2.0",
"mocha": "^6.1.4",
Expand All @@ -74,8 +75,8 @@
"lodash": ">=4.17.11",
"mime": ">=2.4.4",
"moment": ">=2.24.0",
"parse-json": ">=4.0.0",
"randomcolor": ">=0.5.4",
"read-pkg": ">=5.1.1",
"statuses": ">=1.5.0"
},
"engines": {
Expand Down
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve as resolvePath } from 'path';
import { readFileSync } from 'fs';
import {
arch,
cpus,
Expand Down Expand Up @@ -42,10 +44,10 @@ import {
words as wordify,
} from 'lodash';
import { getType as mimeTypeOf, getExtension as mimeExtensionOf } from 'mime';
import { sync as readPackage } from 'read-pkg';
import { STATUS_CODES } from 'statuses';
import generateColor from 'randomcolor';
import moment from 'moment';
import parseJson from 'parse-json';

/**
* @name RESOURCE_ACTIONS
Expand Down Expand Up @@ -328,7 +330,7 @@ export const mergeObjects = (...objects) => {
* @author lally elias <lallyelias87@mail.com>
* @license MIT
* @since 0.1.0
* @version 0.2.0
* @version 0.3.0
* @static
* @public
* @example
Expand All @@ -343,9 +345,13 @@ export const pkg = (path, ...field) => {
// try read from path or process cwd
const read = () => {
try {
return readPackage({ cwd: path });
const filePath = resolvePath(path, 'package.json');
const json = parseJson(readFileSync(filePath, 'utf8'));
return json;
} catch (e) {
return readPackage({ cwd: process.cwd() });
const filePath = resolvePath(process.cwd(), 'package.json');
const json = parseJson(readFileSync(filePath, 'utf8'));
return json;
}
};

Expand Down

0 comments on commit d106789

Please sign in to comment.