module-lookup-amd
Advanced tools
Comparing version 7.0.0 to 7.0.1
61
index.js
@@ -7,4 +7,4 @@ 'use strict'; | ||
const debug = require('debug')('lookup'); | ||
const find = require('find'); | ||
const requirejs = require('requirejs'); | ||
const glob = require('glob'); | ||
@@ -53,28 +53,32 @@ /** | ||
let normalizedModuleId = stripLoader(depPath); | ||
let resolutionDirectory; | ||
if (configPath) { | ||
resolutionDirectory = configPath; | ||
debug('module resolution directory (based on configPath): ' + resolutionDirectory); | ||
if (normalizedModuleId[0] === '.' || (!configPath && !options.directory)) { | ||
resolutionDirectory = path.dirname(options.filename); | ||
debug('module resolution directory (relative): ' + resolutionDirectory); | ||
} else { | ||
if (configPath) { | ||
resolutionDirectory = configPath; | ||
debug('module resolution directory (based on configPath): ' + resolutionDirectory); | ||
} else if (options.directory) { | ||
resolutionDirectory = options.directory; | ||
debug('module resolution directory (based on directory): ' + resolutionDirectory); | ||
} | ||
} else if (options.directory && depPath[0] !== '.') { | ||
resolutionDirectory = options.directory; | ||
debug('module resolution directory (based on directory): ' + resolutionDirectory); | ||
if (config.baseUrl[0] === '/') { | ||
debug('baseUrl with a leading slash detected'); | ||
resolutionDirectory = resolutionDirectory.replace(config.baseUrl, ''); | ||
debug('new resolution directory: ' + resolutionDirectory); | ||
} | ||
} else { | ||
resolutionDirectory = path.dirname(options.filename); | ||
debug('module resolution directory (based on filename): ' + resolutionDirectory); | ||
} | ||
if (normalizedModuleId[0] === '/') { | ||
normalizedModuleId = normalizedModuleId.replace(/^\/+/g, ''); | ||
} | ||
if (config.baseUrl[0] === '/') { | ||
debug('baseUrl with a leading slash detected'); | ||
resolutionDirectory = resolutionDirectory.replace(config.baseUrl, ''); | ||
debug('new resolution directory: ' + resolutionDirectory); | ||
requirejs.config(config); | ||
normalizedModuleId = requirejs.toUrl(normalizedModuleId); | ||
} | ||
requirejs.config(config); | ||
depPath = stripLoader(depPath); | ||
let normalizedModuleId = requirejs.toUrl(depPath); | ||
debug('requirejs normalized module id: ' + normalizedModuleId); | ||
@@ -100,3 +104,3 @@ | ||
const foundFile = findFileLike(fileSystem, normalizedModuleId, resolved) || ''; | ||
const foundFile = findFileLike(resolved) || ''; | ||
@@ -112,13 +116,10 @@ if (foundFile) { | ||
function findFileLike(fileSystem, partial, resolved) { | ||
const fileDir = path.dirname(resolved); | ||
function findFileLike(resolved) { | ||
const pattern = resolved + '.*'; | ||
const pattern = escapeRegExp(resolved + '.'); | ||
debug('looking for file like ' + pattern); | ||
debug('within ' + fileDir); | ||
try { | ||
const results = find.use({fs: fileSystem}) | ||
.fileSync(new RegExp(pattern), fileDir); | ||
const results = glob.sync(pattern); | ||
debug('found the following matches: ', results.join('\n')); | ||
@@ -163,6 +164,2 @@ | ||
function escapeRegExp(str) { | ||
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); | ||
} | ||
/** | ||
@@ -169,0 +166,0 @@ * Exposed for testing |
{ | ||
"name": "module-lookup-amd", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "Resolve aliased dependency paths using a RequireJS config", | ||
@@ -34,3 +34,3 @@ "main": "index.js", | ||
"debug": "^4.1.0", | ||
"find": "^0.3.0", | ||
"glob": "^7.1.6", | ||
"requirejs": "^2.3.5", | ||
@@ -37,0 +37,0 @@ "requirejs-config-file": "^4.0.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8860
155
+ Addedglob@^7.1.6
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedfind@^0.3.0
- Removedfind@0.3.0(transitive)
- Removedtraverse-chain@0.1.0(transitive)