Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Add option to get package.json content (#534)
Browse files Browse the repository at this point in the history
* Add packageJson option to get package.json

* Wrap require statement with try catch and rename packageJson

* Revert pkgJson to packageJson

* Nits

* Remove extra blank line
* Destructure out join
* Use null instead of undefined for options.packageJson
  • Loading branch information
helfi92 authored Dec 5, 2017
1 parent 77d239a commit a653992
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = (neutrino, opts = {}) => {
}

try {
const pkg = require(join(neutrino.options.root, 'package.json')); // eslint-disable-line global-require
const pkg = neutrino.options.packageJson;
const hasSourceMap = (pkg.dependencies && 'source-map-support' in pkg.dependencies) ||
(pkg.devDependencies && 'source-map-support' in pkg.devDependencies);

Expand Down
7 changes: 7 additions & 0 deletions packages/neutrino/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Config = require('webpack-chain');
const merge = require('deepmerge');
const Future = require('fluture');
const mitt = require('mitt');
const { join } = require('path');
const {
defaultTo, is, map, omit, replace
} = require('ramda');
Expand Down Expand Up @@ -50,6 +51,12 @@ class Api {
});
});

try {
options.packageJson = require(join(options.root, 'package.json')); // eslint-disable-line global-require
} catch (err) {
options.packageJson = null;
}

Object.defineProperty(options, 'extensions', {
enumerable: true,
get() {
Expand Down
9 changes: 1 addition & 8 deletions packages/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ const {

const MODULES = join(__dirname, 'node_modules');
const NEUTRINO_MODULES = join(__dirname, '../../node_modules');
const getPackageJson = (root) => {
try {
return require(join(root, 'package.json')); // eslint-disable-line
} catch (err) {
return {};
}
};
const getOutputForEntry = pipe(
parse,
omit(['base']),
Expand All @@ -32,7 +25,7 @@ const getOutputForEntry = pipe(
);

module.exports = (neutrino, opts = {}) => {
const pkg = getPackageJson(neutrino.options.root);
const pkg = neutrino.options.packageJson;
const staticDir = join(neutrino.options.source, 'static');
const sourceMap = pathOr(
pathOr(false, ['dependencies', 'source-map-support'], pkg),
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = (neutrino, options = {}) => {
neutrino.options.output;

try {
const pkg = require(join(neutrino.options.root, 'package.json')); // eslint-disable-line global-require
const pkg = neutrino.options.packageJson;
const hasSourceMap = (pkg.dependencies && 'source-map-support' in pkg.dependencies) ||
(pkg.devDependencies && 'source-map-support' in pkg.devDependencies);

Expand Down

0 comments on commit a653992

Please sign in to comment.