module-lens
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -9,6 +9,6 @@ "use strict"; | ||
function searchUpperDir(from, searchName, filter) { | ||
let nextDir = from; | ||
let nextDirName = from; | ||
while (true) { | ||
let currentDir = nextDir; | ||
let searchPath = Path.join(currentDir, searchName); | ||
let currentDirName = nextDirName; | ||
let searchPath = Path.join(currentDirName, searchName); | ||
let stats; | ||
@@ -20,6 +20,6 @@ try { | ||
if (stats && (!filter || filter(searchPath, stats))) { | ||
return currentDir; | ||
return currentDirName; | ||
} | ||
nextDir = Path.dirname(currentDir); | ||
if (nextDir === currentDir) { | ||
nextDirName = Path.dirname(currentDirName); | ||
if (nextDirName === currentDirName) { | ||
return undefined; | ||
@@ -26,0 +26,0 @@ } |
export interface BuildOptions { | ||
sourceFileName: string; | ||
baseUrlDir?: string; | ||
baseUrlDirName?: string; | ||
} | ||
export declare function build(path: string, { sourceFileName, baseUrlDir }: BuildOptions): string; | ||
export declare function build(path: string, { sourceFileName, baseUrlDirName }: BuildOptions): string; | ||
export declare function format(path: string, dotSlashPrefix: boolean): string; |
@@ -5,7 +5,7 @@ "use strict"; | ||
const Path = tslib_1.__importStar(require("path")); | ||
function build(path, { sourceFileName, baseUrlDir }) { | ||
let sourceDir = Path.dirname(sourceFileName); | ||
function build(path, { sourceFileName, baseUrlDirName }) { | ||
let sourceDirName = Path.dirname(sourceFileName); | ||
let relativePath; | ||
if (typeof baseUrlDir === 'string') { | ||
relativePath = Path.relative(baseUrlDir, path); | ||
if (typeof baseUrlDirName === 'string') { | ||
relativePath = Path.relative(baseUrlDirName, path); | ||
if (!/^\.\.[\\/]/.test(relativePath)) { | ||
@@ -15,3 +15,3 @@ return format(relativePath, false); | ||
} | ||
relativePath = Path.relative(sourceDir, path); | ||
relativePath = Path.relative(sourceDirName, path); | ||
return format(relativePath, true); | ||
@@ -18,0 +18,0 @@ } |
export interface ResolveOptions { | ||
sourceFileName: string; | ||
baseUrlDir?: string; | ||
baseUrlDirName?: string; | ||
extensions?: string[]; | ||
@@ -11,4 +11,4 @@ } | ||
} | ||
export declare function resolveWithCategory(specifier: string, { sourceFileName, baseUrlDir, extensions, }: ResolveOptions): ResolveWithCategoryResult; | ||
export declare function resolveWithCategory(specifier: string, { sourceFileName, baseUrlDirName, extensions, }: ResolveOptions): ResolveWithCategoryResult; | ||
export declare function resolve(specifier: string, options: ResolveOptions): string | undefined; | ||
export declare function isNodeBuiltIn(specifier: string): boolean; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const BUILT_IN_MODULE_NAME_SET = new Set(module_1.default.builtinModules || Object.keys(process.binding('natives'))); | ||
function resolveWithCategory(specifier, { sourceFileName, baseUrlDir, extensions = ['.js', '.jsx', '.ts', '.tsx'], }) { | ||
function resolveWithCategory(specifier, { sourceFileName, baseUrlDirName, extensions = ['.js', '.jsx', '.ts', '.tsx'], }) { | ||
if (isNodeBuiltIn(specifier)) { | ||
@@ -36,3 +36,3 @@ return { | ||
} | ||
if (baseUrlDir) { | ||
if (baseUrlDirName) { | ||
let usingBaseUrl = false; | ||
@@ -42,3 +42,3 @@ // First segment is exactly the whole specifier, possibly a file name. | ||
usingBaseUrl = ['', ...extensions].some(extension => { | ||
let possiblePathUsingBaseUrl = Path.join(baseUrlDir, `${specifier}${extension}`); | ||
let possiblePathUsingBaseUrl = Path.join(baseUrlDirName, `${specifier}${extension}`); | ||
let possiblePathStats = _utils_1.gentleStat(possiblePathUsingBaseUrl); | ||
@@ -49,3 +49,3 @@ return !!possiblePathStats && possiblePathStats.isFile(); | ||
if (!usingBaseUrl) { | ||
let possibleDirUsingBaseUrl = Path.join(baseUrlDir, specifierFirstFragment); | ||
let possibleDirUsingBaseUrl = Path.join(baseUrlDirName, specifierFirstFragment); | ||
let possibleDirStats = _utils_1.gentleStat(possibleDirUsingBaseUrl); | ||
@@ -57,11 +57,11 @@ usingBaseUrl = !!possibleDirStats && possibleDirStats.isDirectory(); | ||
category: 'base-url', | ||
path: Path.join(baseUrlDir, specifier), | ||
path: Path.join(baseUrlDirName, specifier), | ||
}; | ||
} | ||
} | ||
let nodeModulesParentDir = _utils_1.searchUpperDir(Path.dirname(sourceFileName), `node_modules/${specifierFirstFragment}`, _utils_1.isDirectorySearchFilter); | ||
if (nodeModulesParentDir) { | ||
let nodeModulesParentDirName = _utils_1.searchUpperDir(Path.dirname(sourceFileName), `node_modules/${specifierFirstFragment}`, _utils_1.isDirectorySearchFilter); | ||
if (nodeModulesParentDirName) { | ||
return { | ||
category: 'node-modules', | ||
path: Path.join(nodeModulesParentDir, 'node_modules', specifier), | ||
path: Path.join(nodeModulesParentDirName, 'node_modules', specifier), | ||
}; | ||
@@ -68,0 +68,0 @@ } |
{ | ||
"name": "module-lens", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Simple module specifier utilities.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -20,3 +20,3 @@ [![NPM Package](https://badge.fury.io/js/module-lens.svg)](https://www.npmjs.com/package/module-lens) | ||
sourceFileName: __filename, | ||
baseUrlDir: __dirname, | ||
baseUrlDirName: __dirname, | ||
}); | ||
@@ -28,3 +28,3 @@ | ||
sourceFileName: __filename, | ||
baseUrlDir: __dirname, | ||
baseUrlDirName: __dirname, | ||
}); | ||
@@ -31,0 +31,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
10464