Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.2 to 1.0.3

5

package.json
{
"name": "module-alias",
"description": "Simple module for registering aliases of directories and custom module paths",
"version": "1.0.2",
"version": "1.0.3",
"author": {
"name": "Nikita Gavrilov"
"name": "Nikita Gavrilov",
"email": "artnikpro@gmail.com"
},

@@ -8,0 +9,0 @@ "scripts": {

19

README.md

@@ -7,3 +7,3 @@ # module-alias

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 you to create aliases of directories for further usage with `require`/`import`
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`

@@ -39,5 +39,5 @@ ## Install

import 'something'
import foo from '@foo'
import deepModule from '@bar/my-module'
import module from 'some-module' // module from `node_modules_custom` directory
import module from '@root/some-module'
import veryDeepModule from '@bar/my-module'
import myModule from '@my_module' // module from `node_modules_custom` directory
```

@@ -53,3 +53,3 @@

//
moduleAlias.addAlias('@server', __dirname + '/src/server')
moduleAlias.addAlias('@client', __dirname + '/src/client')

@@ -59,3 +59,3 @@ // Or multiple aliases

'@root' : __dirname,
'@server': __dirname + '/src/server',
'@client': __dirname + '/src/client',
...

@@ -99,2 +99,9 @@ })

## How it works?
In order to register a custom modules path (`addPath`) it modifies the internal `Module._nodeModulePaths` method so that the 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
### Tags

@@ -101,0 +108,0 @@ Require alias, node import alias, node custom module directory, node local require paths, register module directory in nodejs

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