Socket
Socket
Sign inDemoInstall

enhanced-resolve

Package Overview
Dependencies
0
Maintainers
1
Versions
128
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    enhanced-resolve

Offers a async require.resolve function. It's highly configurable.


Version published
Maintainers
1
Install size
23.1 kB
Created

Package description

What is enhanced-resolve?

The enhanced-resolve package is a highly configurable module resolution library for Node.js, which is used by webpack under the hood. It resolves a path to a file or directory in a file system. It can handle complex resolution patterns like module aliases, extensions, and directories with package.json files.

What are enhanced-resolve's main functionalities?

File Resolution

Resolves the path to a file, taking into account file extensions and processing according to the configuration provided.

const { ResolverFactory } = require('enhanced-resolve');

const resolver = ResolverFactory.createResolver({
  fileSystem: require('fs'),
  extensions: ['.js', '.json']
});

resolver.resolve({}, __dirname, './path/to/file', (err, result) => {
  if (err) console.error(err);
  else console.log(result);
});

Directory Resolution

Resolves the path to a directory, looking for the 'main' field in the package.json or index.js within that directory.

const { ResolverFactory } = require('enhanced-resolve');

const resolver = ResolverFactory.createResolver({
  fileSystem: require('fs'),
  mainFields: ['main']
});

resolver.resolve({}, __dirname, './path/to/directory', (err, result) => {
  if (err) console.error(err);
  else console.log(result);
});

Plugin System

Allows the use of plugins to extend or modify the resolution behavior, providing a high degree of customization.

const { ResolverFactory } = require('enhanced-resolve');
const MyPlugin = require('./MyPlugin');

const resolver = ResolverFactory.createResolver({
  fileSystem: require('fs'),
  plugins: [new MyPlugin()] // Custom plugin to modify resolution behavior
});

// Use the resolver as before

Other packages similar to enhanced-resolve

Readme

Source

enhanced-resolve

Offers a async require.resolve function. It's highly configurable.

Build Status

More documentation coming soon...

var resolve = require("enhanced-resolve");

resolve(string context, string identifier, object options, function callback(err, result))
resolve.sync(string context, string identifier, object options)
resolve.context(string context, string identifier, object options, function callback(err, result))
resolve.context.sync(string context, string identifier, object options)

It is used in webpack

FAQs

Last updated on 24 Sep 2012

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc