Node Exports Info

1.6.0 · active · verified Tue Apr 21

node-exports-info is a utility library providing programmatic access to detailed information about Node.js's `exports` field support across different Node.js versions. It helps developers understand which `exports` features, such as conditions, patterns, and pattern trailers, are available in specific Node.js environments. The library categorizes Node.js versions into distinct groups based on their `exports` implementation, including 'pre-exports', 'broken', 'experimental', 'conditions', and various pattern-related categories. This is crucial for authors of libraries and applications needing to ensure correct module resolution and interoperability across a wide range of Node.js versions, particularly given the evolving landscape of ESM and CJS module systems. Currently at version 1.6.0, it is actively maintained with updates likely correlating to significant changes in Node.js's module resolution behavior. Its primary differentiator is providing a comprehensive and version-specific mapping of `exports` capabilities, simplifying compatibility concerns for complex `package.json` `exports` configurations.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to identify the current Node.js exports category, retrieve detailed feature flags for specific categories or module systems, and list all known categories with their corresponding Node.js version ranges.

import getCategory from 'node-exports-info/getCategory';
import getCategoryInfo from 'node-exports-info/getCategoryInfo';
import getRangePairs from 'node-exports-info/getRangePairs';

// Get the exports category for the current Node.js version
const currentCategory = getCategory();
console.log(`Current Node.js exports category: ${currentCategory}`);

// Get detailed info for a specific category, e.g., 'patterns'
const patternInfo = getCategoryInfo('patterns');
console.log('\nInfo for 'patterns' category:');
console.log(JSON.stringify(patternInfo, null, 2));

// Get info for the current category, specifically for 'require' module system
const currentCategoryRequireInfo = getCategoryInfo(currentCategory, 'require');
console.log(`\nCurrent category ('${currentCategory}') flags for 'require':`);
console.log(JSON.stringify(currentCategoryRequireInfo.flags, null, 2));

// List all categories with their associated semver ranges
console.log('\nAll exports categories and their Node.js version ranges:');
getRangePairs().forEach(([range, category]) => {
  console.log(`- ${category}: ${range}`);
});

view raw JSON →