Socket
Socket
Sign inDemoInstall

module-alias

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

module-alias - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

4

package.json
{
"name": "module-alias",
"description": "Simple module for registering aliases of directories and custom module paths",
"version": "1.0.4",
"description": "Create aliases of directories and register custom module paths in NodeJS like a boss!",
"version": "1.0.5",
"author": {

@@ -6,0 +6,0 @@ "name": "Nikita Gavrilov",

@@ -5,6 +5,17 @@ # module-alias

Allows to register aliases of directories and custom module paths in NodeJS.
Create aliases of directories and register custom module paths in NodeJS like a boss!
This package is highly inspired by [app-module-path](https://www.npmjs.com/package/app-module-path) package and it's totally backwards compatible with it. The main difference is that this package also allows creating aliases of directories for further usage with `require`/`import`
No more shit-coding paths in Node like so:
```js
require('../../../../some/very/deep/module')
```
Enough of this madness!
Just create an alias and do it the right way:
```js
require('@deep/module')
```
## Install

@@ -52,2 +63,9 @@

If you don't want to modify your `package.json` or you just prefer to set it all up programmatically, then the following methods are available for you:
* `addAlias('alias', 'target_path')` - register a single alias
* `addAliases({ 'alias': 'target_path', ... }) ` - register multiple aliases
* `addPath(path)` - Register custom modules directory (like node_modules, but with your own modules)
_Examples:_
```js

@@ -69,4 +87,3 @@ import moduleAlias from 'module-alias'

//
// Register custom modules directory (like node_modules, but
// with your own modules)
// Register custom modules directory
//

@@ -77,3 +94,3 @@ moduleAlias.addPath(__dirname + '/node_modules_custom')

//
// Import settings from package.json
// Import settings from a specific package.json
//

@@ -90,2 +107,4 @@ moduleAlias(__dirname + '/package.json')

Luckily, WebPack has a built in support for aliases and custom modules directories so it's easy to make it work on the client side as well!
```js

@@ -108,6 +127,6 @@ // webpack.config.js

In order to register an alias it modifies the internal `Module._resolveFilename` method so that when you use `require` or `import` it first checks whether the given string starts with one of the registered aliases, if so, it replaces the alias in the string with the target path of the alias.
In order to register a custom modules path (`addPath`) it modifies the internal `Module._nodeModulePaths` method so that the given directory then acts like it's the `node_modules` directory.
In order to register an alias it modifies the internal `Module._resolveFilename` method so that when you fire `require` or `import` it first checks whether the given string starts with one of the registered aliases, if so, it then replaces the alias in the string with the target path of the alias
[npm-image]: https://img.shields.io/npm/v/module-alias.svg

@@ -114,0 +133,0 @@ [npm-url]: https://npmjs.org/package/module-alias

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc