New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

find-imports

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-imports - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

19

index.js

@@ -0,9 +1,12 @@

var _ = require('lodash');
var babel = require('babel-core');
var esprima = require('esprima');
var glob = require('glob');
var lodash = require('lodash');
// @params {string|array} patterns The glob pattern or a list of glob patterns
// @params {object} options The options object
// @params {boolean} [options.absoluteImports] True to return absolute imports, defaults to false
// @params {boolean} [options.relativeImports] True to return relative imports, defaults to false
// @params {string|array} patterns The glob pattern or a list of glob patterns.
// @params {object} options The options object.
// @params {boolean} [options.flatten] True to flatten the output, defaults to false.
// @params {boolean} [options.absoluteImports] True to return absolute imports, defaults to false.
// @params {boolean} [options.relativeImports] True to return relative imports, defaults to false.
var findImports = function(patterns, options) {

@@ -69,2 +72,10 @@ var requiredModules = {};

if (options.flatten) {
requiredModules = _(requiredModules)
.toArray()
.flatten()
.uniq()
.value();
}
return requiredModules;

@@ -71,0 +82,0 @@ };

{
"name": "find-imports",
"version": "0.2.0",
"version": "0.3.0",
"description": "Find all imported modules in JavaScript files.",

@@ -18,4 +18,3 @@ "homepage": "https://github.com/cheton/find-imports",

},
"keywords": [
],
"keywords": [],
"dependencies": {

@@ -26,3 +25,4 @@ "babel-core": "^6.9.0",

"esprima": "^2.7.2",
"glob": "^7.0.3"
"glob": "^7.0.3",
"lodash": "^4.12.0"
},

@@ -29,0 +29,0 @@ "devDependencies": {

@@ -11,9 +11,2 @@ # find-imports [![build status](https://travis-ci.org/cheton/find-imports.svg?branch=master)](https://travis-ci.org/cheton/find-imports) [![Coverage Status](https://coveralls.io/repos/cheton/find-imports/badge.svg)](https://coveralls.io/r/cheton/find-imports)

var deps = _(findImports('src/**/*.{js,jsx}'))
.toArray()
.flatten()
.uniq()
.sort()
.value();
// Webpack Configuration

@@ -25,3 +18,3 @@ module.exports = {

],
vendor: deps
vendor: findImports('src/**/*.{js,jsx}', { flatten: true })
},

@@ -54,3 +47,3 @@ output: {

findImports(files);
// → { 'src/web/index.jsx':
// → { 'src/index.jsx':
// [ 'lodash',

@@ -64,2 +57,14 @@ // 'async',

To flatten the output:
```js
findImports(files, { flatten: true });
// → [ 'lodash',
// 'async',
// 'jsuri',
// 'react',
// 'react-dom',
// 'react-router' ]
```
To return absolute and relative imports:

@@ -71,3 +76,3 @@ ```js

});
// → { 'src/web/index.jsx':
// → { 'src/index.jsx':
// [ 'lodash',

@@ -74,0 +79,0 @@ // 'async',

@@ -71,2 +71,32 @@ import { test } from 'tap';

test('Flatten output', (t) => {
const result = findImports('test/fixtures/app.js', { flatten: true });
const wanted = [
'lodash',
'fs',
'path',
'express',
'consolidate',
'errorhandler',
'serve-favicon',
'cookie-parser',
'body-parser',
'connect-multiparty',
'connect-restreamer',
'method-override',
'morgan',
'compression',
'serve-static',
'express-session',
'session-file-store',
'i18next',
'i18next-node-fs-backend',
'del',
'i18next-express-middleware',
'hogan.js'
];
t.same(result, wanted);
t.end();
});
test('Relative imports', (t) => {

@@ -73,0 +103,0 @@ const files = [

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