
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
esbuild-dependency-graph
Advanced tools
Dependency graph helper based on esbuild's metafile
npm install esbuild-dependency-graph
# or yarn
yarn add esbuild-dependency-graph
import * as esbuild from 'esbuild';
import { DependencyGraph } from 'esbuild-dependency-graph';
const result = await esbuild.build({
metafile: true,
/* other build options */
});
const graph = new DependencyGraph(result.metafile, {
/**
* Root path for lookup modules.
*
* Defaults to `process.cwd()`.
*/
root: '/path/to/root-dir',
});
// Get dependencies of the specified module.
graph.dependenciesOf('path/to/code.ts'); // `ModulePath[]`
// Get dependents of the specified module.
graph.dependentsOf('path/to/code.ts'); // `ModulePath[]`
// Get inverse dependencies of the specified module.
graph.inverseDependenciesOf('path/to/code.ts'); // `ModulePath[]`
import {
DependencyGraph,
isExternal,
isInternal,
} from 'esbuild-dependency-graph';
// Get module.
graph.getModule('path/to/code.ts'); // `Module`
// Register new module to the graph.
graph.addModule(
'path/to/code.ts',
['path/to/dependency-a', 'path/to/dependency-b'],
['path/to/dependent'],
); // `void`
// Update registered module.
graph.updateModule(
'path/to/code.ts',
['path/to/dependency-a', 'path/to/dependency-b'],
['path/to/dependent'],
); // `void`
// Remove module from graph.
graph.removeModule('path/to/code.ts'); // `void`
// Check if this module is external.
isExternal('path/to/code.ts'); // `boolean`
type EsbuildModule = Metafile['inputs'][string];
interface InternalModule extends ModuleBase, EsbuildModule {
dependencies: Set<ModuleId>;
inverseDependencies: Set<ModuleId>;
}
interface ExternalModule extends ModuleBase {}
type ModuleId = number;
type ModulePath = string;
type Module = InternalModule | ExternalModule;
/**
* @type {import('esbuild').Metafile}
*/
interface Metafile {
inputs: {
[path: string]: {
// Can be used as module path!
imports: {
path: string; // Can be used as module path!
/* ... */
}[];
/* ... */
};
};
outputs: {
/* ... */
};
}
Demo code here.
// Module: src/components/Section.tsx
{
path: 'src/components/Section.tsx',
dependencies: Set(3) { 509, 73, 1043 },
inverseDependencies: Set(1) { 1123 }
}
// Dependencies
[
'node_modules/react/jsx-runtime.js',
'node_modules/react/index.js',
'node_modules/dripsy/src/index.ts'
]
// Dependents
[ 'src/components/index.ts' ]
// Inverse dependencies
[
'src/components/index.ts',
'src/screens/MainScreen.tsx',
'src/screens/IntroScreen.tsx',
'src/screens/index.ts',
'src/navigators/RootStack.tsx',
'src/navigators/index.ts',
'src/App.tsx',
'index.js'
]
FAQs
A library that generates a dependency graph using esbuild's metadata
The npm package esbuild-dependency-graph receives a total of 627 weekly downloads. As such, esbuild-dependency-graph popularity was classified as not popular.
We found that esbuild-dependency-graph demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.