Socket
Socket
Sign inDemoInstall

moog-require

Package Overview
Dependencies
Maintainers
12
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moog-require - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

test/project_modules/nestedModulesTest/nestedModule/index.js

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');
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc