moog-require
Advanced tools
Comparing version 1.0.1 to 1.1.0
13
index.js
@@ -6,2 +6,3 @@ var async = require('async'); | ||
var path = require('path'); | ||
var glob = require('glob'); | ||
@@ -54,7 +55,11 @@ module.exports = function(options) { | ||
var originalType; | ||
var projectLevelPath = self.options.localModules + '/' + type + '/index.js'; | ||
var projectLevelFolder = self.options.localModules + '/' + type; | ||
var projectLevelPath = projectLevelFolder + '/index.js'; | ||
projectLevelPath = path.normalize(projectLevelPath); | ||
if (options.nestedModuleSubdirs) { | ||
var matches = glob.sync(self.options.localModules + '/**/' + type + '/index.js'); | ||
if (matches.length > 1) { | ||
throw new Error('The module ' + type + ' appears in multiple locations:\n' + matches.join('\n')); | ||
} | ||
projectLevelPath = matches[0] ? path.normalize(matches[0]) : projectLevelPath; | ||
} | ||
if (fs.existsSync(projectLevelPath)) { | ||
@@ -61,0 +66,0 @@ projectLevelDefinition = self.root.require(projectLevelPath); |
{ | ||
"name": "moog-require", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "moog-require extends moog with support for type definitions in local files and npm modules.", | ||
@@ -8,2 +8,3 @@ "main": "index.js", | ||
"async": "^1.0.0", | ||
"glob": "^7.1.3", | ||
"lodash": "^4.0.0", | ||
@@ -10,0 +11,0 @@ "moog": "^1.0.0", |
@@ -338,4 +338,17 @@ [![Build Status](https://travis-ci.org/punkave/moog-require.svg?branch=master)](https://travis-ci.org/punkave/moog-require) | ||
## Nesting modules in subdirectories | ||
For your convenience, `moog-require` has optional support for loading modules from nested subdirectories. The rules of the game are very simple: | ||
* You must set the `nestedModuleSubdirs` option to `true`. | ||
* Modules can now be found nested beneath your `localModules` folder, at any depth. | ||
* The names of the parent directories **do not matter**. They are purely for your organizational convenience. | ||
* The name of the actual module directory must still be the full name of the module. | ||
If the same module exists in two places, an exception is thrown. | ||
## Changelog | ||
1.1.0: support for the `nestedModuleSubdirs` option. | ||
1.0.1: shallowly clone the result of `require` rather than attaching `.__meta` to a potentially shared object. This allows multiple instances of `moog-require` in multiple instances of `apostrophe` to independently track where modules were loaded from. | ||
@@ -342,0 +355,0 @@ |
@@ -782,2 +782,30 @@ var assert = require('assert'); | ||
describe('nestedModuleSubdirs option', function() { | ||
it('should load a module from a regular folder without the nesting feature enabled', function() { | ||
var synth = require('../index.js')({ | ||
localModules: __dirname + '/project_modules', | ||
root: module | ||
}); | ||
synth.define('testModuleSimple'); | ||
var instance = synth.create('testModuleSimple', {}); | ||
assert(instance._options); | ||
assert(instance._options.color === 'red'); | ||
}); | ||
it('should load a module from a nested or non-nested folder with the nesting option enabled', function() { | ||
var synth = require('../index.js')({ | ||
localModules: __dirname + '/project_modules', | ||
nestedModuleSubdirs: true, | ||
root: module | ||
}); | ||
synth.define('testModuleSimple'); | ||
var instance = synth.create('testModuleSimple', {}); | ||
assert(instance._options); | ||
assert(instance._options.color === 'red'); | ||
synth.define('nestedModule'); | ||
var instance = synth.create('nestedModule', {}); | ||
assert(instance._options); | ||
assert(instance._options.color === 'green'); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48280
31
1015
367
5
+ Addedglob@^7.1.3
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)