Socket
Socket
Sign inDemoInstall

module-alias

Package Overview
Dependencies
0
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.6 to 2.1.0

test/src/bar/baz/index.js

20

index.js

@@ -14,3 +14,3 @@ 'use strict'

var moduleAliases = {}
var moduleAliasNames = [];
var moduleAliasNames = []

@@ -31,10 +31,16 @@ var oldNodeModulePaths = Module._nodeModulePaths

var oldResolveFilename = Module._resolveFilename
Module._resolveFilename = function (request, parent, isMain) {
Module._resolveFilename = function (request, parentModule, isMain) {
for (var i = moduleAliasNames.length; i-- > 0;) {
var alias = moduleAliasNames[i]
if (isPathMatchesAlias(request, alias)) {
request = nodePath.join(
moduleAliases[alias],
request.substr(alias.length)
)
var aliasTarget = moduleAliases[alias]
// Custom function handler
if (typeof moduleAliases[alias] === 'function') {
var fromPath = parentModule.filename
aliasTarget = moduleAliases[alias](fromPath, request, alias)
if (!aliasTarget || typeof aliasTarget !== 'string') {
throw new Error('[module-alias] Expecting custom handler function to return path.')
}
}
request = nodePath.join(aliasTarget, request.substr(alias.length))
// Only use the first match

@@ -45,3 +51,3 @@ break

return oldResolveFilename.call(this, request, parent, isMain)
return oldResolveFilename.call(this, request, parentModule, isMain)
}

@@ -48,0 +54,0 @@

{
"name": "module-alias",
"description": "Create aliases of directories and register custom module paths in NodeJS like a boss!",
"version": "2.0.6",
"description": "Create aliases of directories and register custom module paths",
"version": "2.1.0",
"author": {

@@ -38,3 +38,2 @@ "name": "Nick Gavrilov",

},
"dependencies": {},
"devDependencies": {

@@ -41,0 +40,0 @@ "chai": "^3.5.0",

@@ -100,2 +100,13 @@ # module-alias

// Custom handler function (starting from v2.1)
moduleAlias.addAlias('@src', (fromPath, request, alias) => {
// fromPath - Full path of the file from which `require` was called
// request - The path (first argument) that was passed into `require`
// alias - The same alias that was passed as first argument to `addAlias` (`@src` in this case)
// Return any custom target path for the `@src` alias depending on arguments
if (fromPath.startsWith(__dirname + '/others')) return __dirname + '/others'
return __dirname + '/src'
})
//

@@ -102,0 +113,0 @@ // Register custom modules directory

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