Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Close #1357 Load json files with require()
Browse files Browse the repository at this point in the history
Signed off by everybody.
  • Loading branch information
isaacs committed Jul 21, 2011
1 parent 1b0e054 commit 588d885
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,13 @@ Module._extensions['.node'] = function(module, filename) {
};


// Native extension for .json
Module._extensions['.json'] = function (module, filename) {
var content = NativeModule.require('fs').readFileSync(filename, 'utf8');
module.exports = JSON.parse(content);
};


// bootstrap main module.
Module.runMain = function() {
// Load the main module--the command line argument.
Expand Down
7 changes: 7 additions & 0 deletions test/simple/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ var child = require('../fixtures/module-require/child/');
assert.equal(child.loaded, parent.loaded);


// #1357 Loading JSON files with require()
var json = require('../fixtures/packages/main/package.json');
assert.deepEqual(json, { name: 'package-name',
version: '1.2.3',
main: 'package-main-module' });


process.addListener('exit', function() {
assert.ok(common.indirectInstanceOf(a.A, Function));
assert.equal('A done', a.A());
Expand Down

0 comments on commit 588d885

Please sign in to comment.