
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
js-dependency-extractor
Advanced tools
A JavaScript and TypeScript files dependency extractor.
The purpose of this project is to extract JavaScript and TypeScript dependencies from a project directory or a single file.
To use as a library:
npm i -S js-dependency-extractor
To use as a CLI tool:
npm i -g js-dependency-extractor
Code style follows Airbnb JavaScript Best Practices using ESLint.
Mocha and Chai.
Uses bugbug for debugging.
npm audit
.const jsDependencyExtractor = require('js-dependency-extractor');
js-dependency-extractor module exports a function named jsDependencyExtractor
.
jsDependencyExtractor
<AsyncFunction>.Extract JavaScript and TypeScript dependencies from a directory or a file.
Note:
options
<Object>
path
<String> Path to directory or file. Could be absolute or relative. Default: none
Required: true
ignorePaths
<Array> Paths to ignore. Could be absolute, relative or a pattern. Default: none
Required: false
mergePartial
<Boolean> Whether to merge partial requires/imports into one same dependency. Default: false
Required: false
onlyExtensions
<Array> File extensions to watch for. Empty list or null values mean to look up into all file extensions. Default: none
Required: false
Example:
// my-project/app/index.ts
import path from 'path';
import memwatch from '@airbnb/node-memwatch';
import partial from '@scope/example-lib/partial';
import uuidv1 from 'uuid/v1';
import uuidv4 from 'uuid/v4';
import helpers from './helpers';
// ...
// my-project/app/helpers/index.js
const path = require('path');
const partial = require('@scope/example-lib/partial');
const sharp = require('sharp');
// ...
// my-project/test/helpers/index.js
const chai = require('chai');
const helpers = require('../app/helpers');
// ...
// example 1
try {
const dependencies = await jsDependencyExtractor({
ignorePaths: ['node_modules'],
mergePartial: false,
onlyExtensions: ['.ts'],
path: '../../my-project',
});
console.log(dependencies);
// [
// '@airbnb/node-memwatch',
// '@scope/example-lib/partial',
// 'path',
// 'uuid/v1',
// 'uuid/v4'
// ]
} catch (e) {
console.error(e);
}
// example 2
try {
const dependencies = await jsDependencyExtractor({
ignorePaths: ['my-project/test', 'node_modules'],
mergePartial: true,
onlyExtensions: ['.js', '.ts'],
path: '../../my-project',
});
console.log(dependencies);
// [
// '@airbnb/node-memwatch',
// '@scope/example-lib',
// 'path',
// 'sharp',
// 'uuid'
// ]
} catch (e) {
console.error(e);
}
Extract JavaScript and TypeScript dependencies from a directory or a file using the command line interface.
See jsDependencyExtractor(options) for more details.
jsde
-p, --path <path>
Path to directory or file. Could be absolute or relative. Default: none
Required: true
-d, --debug
Output extra debugging. Default: false
Required: false
-e, --only-extensions [onlyExtensions...]
File extensions to watch for separated by a white space. Empty list or null values mean to look up into all file extensions. Default: none
Required: false
-i, --ignore-paths [ignorePaths...]
Paths to ignore separated by a white space. Could be absolute, relative or a pattern. Default: none
Required: false
-m, --merge-partial
Whether to merge partial requires/imports into one same dependency. Default: false
Required: false
-v, --version
Output the current version. Default: none
Required: false
Alphabetically ordered list of dependencies on stdout.
Based on jsDependencyExtractor(options) example.
jsde -p ../../my-project -e .js .ts -i my-project/test .node_modules -m
# print
@airbnb/node-memwatch
@scope/example-lib
path
sharp
uuid
name | type | description | default | example |
---|---|---|---|---|
DEBUG | Debug | Debug mode. See bugbug. | none | js-dependency-extractor:* |
*required
Errors emitted by js-dependency-extractor extend native Error:
{
name,
code,
message,
stack,
}
name | code | description | module |
---|---|---|---|
DependencyExtractionError | dependency-extraction-error | Dependency extraction encountered an error | src/index |
npm run lint
npm run test
This project has a Code of Conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
Please have a look at our TODO for any work in progress.
Please take also a moment to read our Contributing Guidelines if you haven't yet done so.
Please see our Support page if you have any questions or for any help needed.
For any security concerns or issues, please visit our Security Policy page.
MIT.
1.0.3 - delivery @07/06/2023
FAQs
A JavaScript and TypeScript files dependency extractor
We found that js-dependency-extractor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.