Skip to content

Commit

Permalink
Use load-jsonic-sync to load json with comments and report position a…
Browse files Browse the repository at this point in the history
…nd filename in error messages
  • Loading branch information
aredridel committed Jul 29, 2015
1 parent fe8b9fd commit adca7a6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
│ limitations under the License. │
\*───────────────────────────────────────────────────────────────────────────*/
import Path from 'path';
import shush from 'shush';
import loadJsonicSync from 'load-jsonic-sync';
import debuglog from 'debuglog';
import Thing from 'core-util-is';
import Config from './config';
Expand All @@ -34,13 +34,13 @@ export default class Factory {
.then(store => Common.merge(Provider.convenience(), store))
.then(Factory.conditional(store => {
let file = Path.join(this.basedir, defaults);
return Handlers.resolveImport(shush(file), this.basedir)
return Handlers.resolveImport(loadJsonicSync(file), this.basedir)
.then(data => Common.merge(data, store));
}))
.then(Factory.conditional(store => {
let file = Path.join(this.basedir, `${store.env.env}.json`);
return Handlers.resolveImport(shush(file), this.basedir)
.then(data => Common.merge(shush(file), store));
return Handlers.resolveImport(loadJsonicSync(file), this.basedir)
.then(data => Common.merge(loadJsonicSync(file), store));
}))
.then(store => Common.merge(Provider.env(), store))
.then(store => Common.merge(Provider.argv(), store));
Expand Down Expand Up @@ -73,7 +73,7 @@ export default class Factory {
_resolveFile(path) {
if (Thing.isString(path)) {
let file = Common.isAbsolute(path) ? path : Path.join(this.basedir, path);
return shush(file);
return loadJsonicSync(file);
}
return path;
}
Expand All @@ -83,7 +83,7 @@ export default class Factory {
try {
return fn(store);
} catch (err) {
if (err.code && err.code === 'MODULE_NOT_FOUND') {
if (err.cause() && err.cause().code === 'ENOENT') {
debug(`WARNING: ${err.message}`);
return store;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
│ See the License for the specific language governing permissions and │
│ limitations under the License. │
\*───────────────────────────────────────────────────────────────────────────*/
import shush from 'shush';
import loadJsonicSync from 'load-jsonic-sync';
import async from 'async';
import Shortstop from 'shortstop'
import { path as createPath } from 'shortstop-handlers';
Expand Down Expand Up @@ -79,7 +79,7 @@ export default class Handlers {
shorty.use('import', function (file, cb) {
try {
file = path(file);
return shorty.resolve(shush(file), cb);
return shorty.resolve(loadJsonicSync(file), cb);
} catch (err) {
cb(err);
}
Expand Down Expand Up @@ -113,4 +113,4 @@ export default class Handlers {
});

}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"caller": "^1.0.0",
"core-util-is": "^1.0.1",
"debuglog": "^1.0.1",
"load-jsonic-sync": "^1.0.0",
"minimist": "^1.1.0",
"shortstop": "^1.0.1",
"shortstop-handlers": "^1.0.0",
"shush": "^1.0.0"
"shortstop-handlers": "^1.0.0"
}
}
2 changes: 1 addition & 1 deletion test/confit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ test('confit', function (t) {
.create(function (err, config) {
t.ok(err);
t.notOk(config);
t.equal(err.code, 'MODULE_NOT_FOUND');
t.equal(err.cause().code, 'ENOENT');
t.end();
});
});
Expand Down

0 comments on commit adca7a6

Please sign in to comment.