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

amd-name-resolver

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amd-name-resolver - npm Package Compare versions

Comparing version 1.0.0 to 1.2.0

87

index.js

@@ -1,6 +0,15 @@

var throwOnRootAccess = true;
var ensurePosix = require('ensure-posix-path');
/**
* Configures the module resolver. Empty options will reset to default settings
* @typedef {Object} Options
* @property {Bool} throwOnRootAccess whether to throw on
* @property {String} moduleRoot to use for each of the resolved modules
* @param {Options} options
* @returns {Function} configured module resolver
*/
function resolveModules(options) {
options = options || {};
options || (options = {});
var throwOnRootAccess = true;
var moduleRoot;

@@ -11,40 +20,62 @@ if (options.throwOnRootAccess === false) {

return moduleResolve;
}
if (typeof options.moduleRoot === 'string') {
moduleRoot = options.moduleRoot;
}
function moduleResolve(_child, _name) {
var child = ensurePosix(_child);
var name = ensurePosix(_name);
if (child.charAt(0) !== '.') { return child; }
/**
* Module resolver for AMD transpiling (Babel)
* @param {String} _child child path of module to resolve
* @param {String} _name name path of module to resolve
* @returns {String} resolved module path
*/
function moduleResolve(_child, _name) {
var child = ensurePosix(_child);
var name = ensurePosix(_name);
if (child.charAt(0) !== '.') {
return child;
}
var parts = child.split('/');
var nameParts = name.split('/');
var parentBase = nameParts.slice(0, -1);
var parts = child.split('/');
var nameParts = name.split('/');
var parentBase = nameParts.slice(0, -1);
// Add moduleRoot if not already present
if (moduleRoot && nameParts[0] !== moduleRoot) {
parentBase = moduleRoot.split('/').concat(parentBase);
}
for (var i = 0, l = parts.length; i < l; i++) {
var part = parts[i];
for (var i = 0, l = parts.length; i < l; i++) {
var part = parts[i];
if (part === '..') {
if (parentBase.length === 0) {
if (throwOnRootAccess) {
throw new Error('Cannot access parent module of root');
} else {
continue;
if (part === '..') {
if (parentBase.length === 0) {
if (throwOnRootAccess) {
throw new Error('Cannot access parent module of root');
} else {
continue;
}
}
parentBase.pop();
} else if (part === '.') {
continue;
} else {
parentBase.push(part);
}
parentBase.pop();
} else if (part === '.') {
continue;
} else { parentBase.push(part); }
}
return parentBase.join('/');
}
return parentBase.join('/');
// parallel API - enable parallel babel transpilation for the moduleResolve function
moduleResolve._parallelBabel = {
requireFile: __filename,
buildUsing: 'resolveModules',
params: options
};
return moduleResolve;
}
// parallel API - enable parallel babel transpilation for the moduleResolve function
moduleResolve._parallelBabel = { requireFile: __dirname, useMethod: 'moduleResolve' };
module.exports = {
moduleResolve: moduleResolve,
moduleResolve: resolveModules(),
resolveModules: resolveModules
};
{
"name": "amd-name-resolver",
"version": "1.0.0",
"version": "1.2.0",
"description": "AMD module name resolver algorithm",

@@ -5,0 +5,0 @@ "main": "index.js",

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