From adca7a6aea699f06c9c4fc32c6f3430e28313b01 Mon Sep 17 00:00:00 2001 From: Aria Stewart Date: Wed, 29 Jul 2015 11:54:54 -0400 Subject: [PATCH] Use load-jsonic-sync to load json with comments and report position and filename in error messages --- lib/factory.js | 12 ++++++------ lib/handlers.js | 6 +++--- package.json | 4 ++-- test/confit-test.js | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 012e91e..1ce61d1 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -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'; @@ -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)); @@ -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; } @@ -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; } diff --git a/lib/handlers.js b/lib/handlers.js index 61e5319..1301f32 100644 --- a/lib/handlers.js +++ b/lib/handlers.js @@ -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'; @@ -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); } @@ -113,4 +113,4 @@ export default class Handlers { }); } -} \ No newline at end of file +} diff --git a/package.json b/package.json index be5fe9e..eb27ea0 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/confit-test.js b/test/confit-test.js index caddff3..58084e7 100644 --- a/test/confit-test.js +++ b/test/confit-test.js @@ -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(); }); });