Skip to content

Commit

Permalink
fix(CONFIG): Fix package.json configuration for edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Jan 13, 2019
1 parent eb3dc50 commit 5ddc915
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 54 deletions.
2 changes: 2 additions & 0 deletions DEPENDENCIES.mmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
graph TD
program-->packageConf
parser-->CONFIG{CONFIG}
CONFIG{CONFIG}-->PROJECT_DIR{PROJECT_DIR}
jsArch((jsArch))-->CONFIG{CONFIG}
jsArch((jsArch))-->EOL{EOL}
jsArch((jsArch))-->glob
Expand All @@ -14,6 +15,7 @@ graph TD
class packageConf others;
class CONFIG config;
class parser others;
class PROJECT_DIR config;
class jsArch jsarch;
class EOL config;
class glob others;
Expand Down
Binary file modified DEPENDENCIES.mmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
188 changes: 136 additions & 52 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
"bluebird": "^3.5.3",
"commander": "^2.19.0",
"debug": "^4.1.1",
"deep-extend": "^0.6.0",
"glob": "^7.1.3",
"knifecycle": "^5.0.4",
"packagerc": "^1.1.0",
"pkg-dir": "^3.0.0",
"yerror": "^2.1.3"
},
"devDependencies": {
Expand Down
29 changes: 27 additions & 2 deletions src/runJSArch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ To see its options, run:
jsarch -h
```
*/
import Knifecycle, { constant, autoService } from 'knifecycle';
import Knifecycle, {
constant,
name,
service,
autoInject,
autoService,
} from 'knifecycle';
import initDebug from 'debug';
import initParser from './parser';
import fs from 'fs';
Expand All @@ -17,7 +23,9 @@ import path from 'path';
import glob from 'glob';
import program from 'commander';
import Promise from 'bluebird';
import deepExtend from 'deep-extend';
import packagerc from 'packagerc';
import pkgDir from 'pkg-dir';

import initJSArch, { DEFAULT_CONFIG } from './jsarch';

Expand Down Expand Up @@ -97,7 +105,24 @@ async function prepareJSArch($ = new Knifecycle()) {
$.register(constant('fs', Promise.promisifyAll(fs)));
$.register(constant('EOL', os.EOL));
$.register(constant('ENV', process.env));
$.register(constant('CONFIG', packagerc('jsarch', DEFAULT_CONFIG)));
$.register(name('PROJECT_DIR', service(async () => pkgDir())));
$.register(
name(
'CONFIG',
service(
autoInject(async function initConfig({ PROJECT_DIR }) {
const packageJSON = require(path.join(PROJECT_DIR, 'package.json'));
const baseConfig = packageJSON.jsarch || DEFAULT_CONFIG;

if (packageJSON.jsarch) {
deepExtend(packageJSON.jsarch, DEFAULT_CONFIG);
}

return packagerc('jsarch', baseConfig);
}),
),
),
);
$.register(constant('glob', Promise.promisify(glob)));
$.register(
constant('log', (type, ...args) => {
Expand Down

0 comments on commit 5ddc915

Please sign in to comment.