Nundler (Not a Bundler)
Nundler (version 0.2.0) is an early-stage utility designed for JavaScript and TypeScript projects that explicitly aim to *avoid* traditional bundling paradigms, or for workflows where fine-grained control over module resolution and dependency analysis is preferred over monolithic output. Instead of merging and optimizing code into a single or few output files, Nundler focuses on assisting developers in understanding and managing module graphs in an unbundled context. Its release cadence is currently unpredictable given its alpha status. Key differentiators include its focus on unbundled environments, potentially offering tools for dynamic import analysis, dependency introspection, or optimized loading strategies without modifying source code for bundling purposes. This tool could be beneficial for scenarios like serverless functions with strict individual file size limits, or development environments emphasizing native ESM module loading directly in Node.js.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'someMethod')
cause Attempting to use an API method that has been renamed, removed, or is not correctly imported due to API instability in pre-1.0 versions.fixConsult the latest source code or documentation (if available) on the GitHub repository for recent API changes. Ensure named imports match current exports. -
Error: Cannot find module 'nundler' from '<your-project-path>'
cause The `nundler` package is not installed or not resolvable in the current project context.fixRun `npm install nundler` or `yarn add nundler` in your project directory. If using ESM, ensure your `package.json` has `"type": "module"` or use `.mjs` files.
Warnings
- breaking As a pre-1.0 release (v0.2.0), Nundler's API is highly unstable and subject to frequent, significant breaking changes without prior notice. Semantic Versioning is not strictly followed for minor/patch releases at this stage.
- gotcha Nundler is explicitly *not* a bundler. It will not optimize, transpile, or merge your code. Misinterpreting its purpose and expecting bundled output or performance optimizations from it will lead to incorrect assumptions and frustration.
- gotcha Performance may vary significantly with very large codebases. Since Nundler aims to analyze individual modules, processing projects with tens of thousands of files or complex module resolution schemes might be slow.
Install
-
npm install nundler -
yarn add nundler -
pnpm add nundler
Imports
- analyzeDependencies
const { analyzeDependencies } = require('nundler')import { analyzeDependencies } from 'nundler' - resolveModulePath
import resolveModulePath from 'nundler'
import { resolveModulePath } from 'nundler' - DependencyGraph
import type { DependencyGraph } from 'nundler'
Quickstart
import { analyzeDependencies } from 'nundler';
import * as path from 'node:path';
import * as fs from 'node:fs/promises';
async function main() {
const projectRoot = process.cwd(); // Or a specific path, e.g., './src'
console.log(`Analyzing dependencies in: ${projectRoot}`);
try {
const analysisResult = await analyzeDependencies(projectRoot, {
entryPoints: ['index.js', 'main.ts'], // Specify your main entry points
ignoreNodeModules: true,
// further options to control analysis depth or file types
});
console.log('--- Dependency Graph Summary ---');
if (analysisResult.graph) {
console.log(`Total modules found: ${analysisResult.graph.nodes.length}`);
console.log(`Total dependencies: ${analysisResult.graph.edges.length}`);
// Example: Log unique external dependencies
const externalDeps = new Set(analysisResult.graph.edges
.filter(edge => edge.type === 'external')
.map(edge => edge.target));
console.log('External dependencies:', Array.from(externalDeps).join(', '));
} else {
console.log('No dependency graph generated, check entry points and options.');
}
if (analysisResult.errors && analysisResult.errors.length > 0) {
console.warn('\n--- Warnings/Errors during analysis ---');
analysisResult.errors.forEach(err => console.warn(`- ${err.message} (File: ${err.file})`));
}
} catch (error) {
console.error('An error occurred during analysis:', error);
}
}
main().catch(console.error);