Socket
Socket
Sign inDemoInstall

module-lookup-amd

Package Overview
Dependencies
Maintainers
3
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

module-lookup-amd - npm Package Compare versions

Comparing version 7.0.1 to 8.0.0

LICENSE

23

bin/cli.js

@@ -5,8 +5,8 @@ #!/usr/bin/env node

const lookup = require('../');
const program = require('commander');
const lookup = require('../index.js');
const { version } = require('../package.json');
program
.version(require('../package.json').version)
.version(version)
.usage('[options] <path>')

@@ -16,12 +16,13 @@ .option('-c, --config <path>', 'location of a RequireJS config file for AMD')

.option('-d, --directory <path>', 'directory containing all files')
.parse(process.argv);
.parse();
const config = program.config;
const filename = program.filename;
const partial = program.args[0];
const { filename, config } = program.opts();
console.log(lookup({
config: config,
filename: filename,
partial: partial
}));
const result = lookup({
config,
filename,
partial
});
console.log(result);
'use strict';
const {ConfigFile} = require('requirejs-config-file');
const fs = require('fs');
const path = require('path');
const debug = require('debug')('lookup');
const fs = require('node:fs');
const path = require('node:path');
const { debuglog } = require('node:util');
const requirejs = require('requirejs');
const { ConfigFile } = require('requirejs-config-file');
const glob = require('glob');
const debug = debuglog('lookup');
/**

@@ -20,12 +22,12 @@ * Determines the real path of a potentially aliased dependency path

* @param {String|Object} [options.configPath] - The location of the config file used to create the preparsed config object
* @param {Object} [options.fileSystem] An alternative filesystem / fs implementation to use for locating files.
* @param {Object} [options.fileSystem] An alternative filesystem / fs implementation to use for locating files.
*
* @return {String}
*/
module.exports = function(options) {
var configPath = options.configPath;
var config = options.config || {};
var depPath = options.partial;
var filename = options.filename;
var fileSystem = options.fileSystem || fs;
module.exports = function(options = {}) {
let { configPath } = options;
let config = options.config || {};
const depPath = options.partial;
const { filename } = options;
const fileSystem = options.fileSystem || fs;

@@ -39,3 +41,3 @@ debug('config: ', config);

config = module.exports._readConfig(config, fileSystem);
debug('converting given config file ' + configPath + ' to an object:\n', config);
debug(`converting given config file ${configPath} to an object:\n`, config);
}

@@ -51,7 +53,6 @@

config.baseUrl = './';
debug('set baseUrl to ' + config.baseUrl);
debug(`set baseUrl to ${config.baseUrl}`);
}
let normalizedModuleId = stripLoader(depPath);
let resolutionDirectory;

@@ -61,10 +62,10 @@

resolutionDirectory = path.dirname(options.filename);
debug('module resolution directory (relative): ' + resolutionDirectory);
debug(`module resolution directory (relative): ${resolutionDirectory}`);
} else {
if (configPath) {
resolutionDirectory = configPath;
debug('module resolution directory (based on configPath): ' + resolutionDirectory);
debug(`module resolution directory (based on configPath): ${resolutionDirectory}`);
} else if (options.directory) {
resolutionDirectory = options.directory;
debug('module resolution directory (based on directory): ' + resolutionDirectory);
debug(`module resolution directory (based on directory): ${resolutionDirectory}`);
}

@@ -75,3 +76,3 @@

resolutionDirectory = resolutionDirectory.replace(config.baseUrl, '');
debug('new resolution directory: ' + resolutionDirectory);
debug(`new resolution directory: ${resolutionDirectory}`);
}

@@ -87,3 +88,3 @@

debug('requirejs normalized module id: ' + normalizedModuleId);
debug(`requirejs normalized module id: ${normalizedModuleId}`);

@@ -93,3 +94,3 @@ if (normalizedModuleId.includes('...')) {

normalizedModuleId = normalizedModuleId.replace('.../', '../../');
debug('expanded module id: ' + normalizedModuleId);
debug(`expanded module id: ${normalizedModuleId}`);
}

@@ -99,3 +100,3 @@

debug('resolved url: ' + resolved);
debug(`resolved url: ${resolved}`);

@@ -106,3 +107,3 @@ // No need to search for a file that already has an extension

if (path.extname(resolved) && fileExists(resolved, fileSystem)) {
debug(resolved + ' already has an extension and is a real file');
debug(`${resolved} already has an extension and is a real file`);
return resolved;

@@ -114,5 +115,5 @@ }

if (foundFile) {
debug('found file like ' + resolved + ': ' + foundFile);
debug(`found file like ${resolved}: ${foundFile}`);
} else {
debug('could not find any file like ' + resolved);
debug(`could not find any file like ${resolved}`);
}

@@ -124,5 +125,5 @@

function findFileLike(resolved) {
const pattern = resolved + '.*';
const pattern = `${resolved}.*`;
debug('looking for file like ' + pattern);
debug(`looking for file like ${pattern}`);

@@ -132,3 +133,3 @@ try {

debug('found the following matches: ', results.join('\n'));
debug(`found the following matches: ${results.join('\n')}`);

@@ -138,5 +139,4 @@ // Not great if there are multiple matches, but the pattern should be

return results[0];
} catch (e) {
debug('error when looking for a match: ' + e.message);
} catch (error) {
debug(`error when looking for a match: ${error.message}`);
return '';

@@ -149,8 +149,7 @@ }

return fileSystem.statSync(filepath).isFile();
}
catch (e) {
} catch (error) {
// Check exception. If ENOENT - no such file or directory ok, file doesn't exist.
// Otherwise something else went wrong, we don't have rights to access the file, ...
if (e.code != 'ENOENT') {
throw e;
if (error.code !== 'ENOENT') {
throw error;
}

@@ -166,5 +165,5 @@

if (exclamationLocation !== -1) {
debug('stripping off the plugin loader from ' + partial);
debug(`stripping off the plugin loader from ${partial}`);
partial = partial.slice(exclamationLocation + 1);
debug('partial is now ' + partial);
debug(`partial is now ${partial}`);
}

@@ -171,0 +170,0 @@

{
"name": "module-lookup-amd",
"version": "7.0.1",
"version": "8.0.0",
"description": "Resolve aliased dependency paths using a RequireJS config",
"main": "index.js",
"scripts": {
"test": "jscs index.js test bin && mocha test/test.js"
},
"files": [
"bin/cli.js",
"index.js"
],
"bin": {
"lookup-amd": "bin/cli.js"
},
"scripts": {
"lint": "xo",
"fix": "xo --fix",
"mocha": "mocha",
"test": "npm run lint && npm run mocha",
"test:ci": "c8 npm run mocha"
},
"repository": {
"type": "git",
"url": "https://github.com/mrjoelkemp/node-module-lookup-amd.git"
"url": "git+https://github.com/dependents/node-module-lookup-amd.git"
},

@@ -25,21 +33,67 @@ "keywords": [

"bugs": {
"url": "https://github.com/mrjoelkemp/node-module-lookup-amd/issues"
"url": "https://github.com/dependents/node-module-lookup-amd/issues"
},
"homepage": "https://github.com/mrjoelkemp/node-module-lookup-amd",
"homepage": "https://github.com/dependents/node-module-lookup-amd",
"engines": {
"node": ">=10.13.0"
"node": ">=14"
},
"dependencies": {
"commander": "^2.8.1",
"debug": "^4.1.0",
"glob": "^7.1.6",
"requirejs": "^2.3.5",
"commander": "^9.5.0",
"glob": "^7.2.3",
"requirejs": "^2.3.6",
"requirejs-config-file": "^4.0.0"
},
"devDependencies": {
"jscs": "^3.0.7",
"jscs-preset-mrjoelkemp": "^2.0.0",
"mocha": "^8.2.1",
"sinon": "^9.2.1"
"c8": "^7.13.0",
"mocha": "^10.2.0",
"sinon": "^15.0.4",
"xo": "^0.54.1"
},
"xo": {
"space": true,
"ignores": [
"test/fixtures/*"
],
"rules": {
"arrow-body-style": "off",
"capitalized-comments": "off",
"comma-dangle": [
"error",
"never"
],
"curly": [
"error",
"multi-line"
],
"max-nested-callbacks": [
"error",
6
],
"operator-linebreak": [
"error",
"after"
],
"object-curly-spacing": [
"error",
"always"
],
"prefer-template": "error",
"space-before-function-paren": [
"error",
"never"
],
"unicorn/prefer-module": "off",
"unicorn/prefer-string-slice": "off",
"unicorn/prefer-top-level-await": "off",
"unicorn/prevent-abbreviations": "off"
},
"overrides": [
{
"files": "test/**",
"envs": [
"mocha"
]
}
]
}
}
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