Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

filing-cabinet

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filing-cabinet - npm Package Compare versions

Comparing version 1.0.6 to 1.1.0

webpack.config.js

61

index.js

@@ -14,13 +14,6 @@ var path = require('path');

var appModulePath = require('app-module-path');
var assign = require('object-assign');
var assign = function(obj1, obj2) {
for (var prop in obj2) {
if (obj2.hasOwnProperty(prop)) {
obj1[prop] = obj2[prop];
}
}
var webpackResolve = require('enhanced-resolve');
return obj1;
};
var defaultLookups = {};

@@ -41,2 +34,3 @@

var config = options.config;
var webpackConfig = options.webpackConfig;

@@ -54,3 +48,3 @@ var ext = path.extname(filename);

var result = resolver(partial, filename, directory, config);
var result = resolver(partial, filename, directory, config, webpackConfig);
debug('resolved path for ' + partial + ': ' + result);

@@ -78,10 +72,17 @@ return result;

*/
function jsLookup(partial, filename, directory, config) {
var type = getModuleType.sync(filename);
function jsLookup(partial, filename, directory, config, webpackConfig) {
var type;
// Handle es6 exported to amd via babel
if (type === 'es6' && config) {
if (config) {
type = 'amd';
}
if (webpackConfig) {
type = 'webpack';
}
if (!type) {
type = getModuleType.sync(filename);
}
switch (type) {

@@ -91,5 +92,11 @@ case 'amd':

return amdLookup(config, partial, filename, directory);
case 'commonjs':
debug('using commonjs resolver');
return commonJSLookup(partial, filename, directory);
case 'webpack':
debug('using webpack resolver for es6');
return resolveWebpackPath(partial, filename, directory, webpackConfig);
case 'es6':

@@ -103,2 +110,4 @@ default:

/**
* TODO: Export to a separate module
*
* @private

@@ -135,1 +144,25 @@ * @param {String} partial

}
function resolveWebpackPath(partial, filename, directory, webpackConfig) {
webpackConfig = path.resolve(webpackConfig);
try {
var loadedConfig = require(webpackConfig);
var aliases = loadedConfig.resolve ? loadedConfig.resolve.alias : [];
var resolver = webpackResolve.create.sync({
alias: aliases
});
var resolvedPath = resolver(directory, partial);
return resolvedPath;
} catch (e) {
debug('error loading the webpack config at ' + webpackConfig);
debug(e.message);
debug(e.stack);
}
return '';
}
{
"name": "filing-cabinet",
"version": "1.0.6",
"version": "1.1.0",
"description": "Find files based on partial paths",

@@ -9,7 +9,4 @@ "main": "index.js",

},
"directories": {
"test": "test"
},
"scripts": {
"test": "jscs index.js test/test.js && mocha"
"test": "jscs index.js test/test.js && ./node_modules/.bin/mocha --compilers js:babel/register test/test.js"
},

@@ -38,5 +35,7 @@ "repository": {

"devDependencies": {
"jscs": "~2.0.0",
"babel": "~5.8.38",
"jscs": "~2.11.0",
"jscs-preset-mrjoelkemp": "~1.0.0",
"mocha": "~2.2.5",
"mock-fs": "~3.0.0",
"mock-fs": "~3.7.0",
"rewire": "~2.3.4",

@@ -49,5 +48,7 @@ "sinon": "~1.15.4"

"debug": "~2.2.0",
"enhanced-resolve": "~2.2.2",
"is-relative-path": "~1.0.0",
"module-definition": "~2.2.2",
"module-lookup-amd": "~2.0.4",
"object-assign": "~4.0.1",
"resolve": "~1.1.7",

@@ -54,0 +55,0 @@ "resolve-dependency-path": "~1.0.2",

@@ -17,6 +17,7 @@ ### filing-cabinet [![npm](http://img.shields.io/npm/v/filing-cabinet.svg)](https://npmjs.org/package/filing-cabinet) [![npm](http://img.shields.io/npm/dm/filing-cabinet.svg)](https://npmjs.org/package/filing-cabinet)

filename: 'path/to/parent/file',
config: 'path/to/requirejs/config'
config: 'path/to/requirejs/config',
webpackConfig: 'path/to/webpack/config'
});
console.log(result);
console.log(result); // absolute/path/to/somePartialPath
```

@@ -26,4 +27,5 @@

* This could be in any of the registered languages
* `config`: (optional) requirejs config for resolving aliased modules
* `webpackConfig`: (optional) webpack config for resolving aliased modules
### Registered languages

@@ -30,0 +32,0 @@

@@ -25,2 +25,15 @@ var assert = require('assert');

'bar.js': 'module.exports = function() {};'
},
'node_modules': {
'lodash.assign': {
'index.js': 'module.exports = function() {};'
},
'nested': {
'index.js': 'require("lodash.assign")',
'node_modules': {
'lodash.assign': {
'index.js': 'module.exports = function() {};'
}
}
}
}

@@ -31,2 +44,6 @@ }

afterEach(function() {
mock.restore();
});
describe('es6', function() {

@@ -135,2 +152,23 @@ it('uses a generic resolver', function() {

});
it('resolves a nested module', function() {
var directory = 'js/node_modules/nested/';
var filename = directory + 'index.js';
var result = cabinet({
partial: 'lodash.assign',
filename: filename,
directory: directory
});
assert.equal(
result,
path.join(
path.resolve(directory),
'node_modules',
'lodash.assign',
'index.js'
)
);
});
});

@@ -254,2 +292,25 @@ });

});
describe('webpack', function() {
function testResolution(partial) {
const directory = path.resolve(__dirname, '../');
const resolved = cabinet({
partial,
filename: `${directory}/index.js`,
directory,
webpackConfig: `${directory}/webpack.config.js`
});
assert.equal(resolved, `${directory}/node_modules/resolve/index.js`);
}
it('resolves an aliased path', function() {
testResolution('R');
});
it('resolves a non-aliased path', function() {
testResolution('resolve');
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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