@commitlint/resolve-extends
Advanced tools
Comparing version 19.0.0 to 19.0.1
@@ -1,2 +0,1 @@ | ||
import 'resolve-global'; | ||
import type { ParserPreset, UserConfig } from '@commitlint/types'; | ||
@@ -6,3 +5,3 @@ /** | ||
*/ | ||
export declare const resolveFrom: (specifier: string, parent?: string) => string; | ||
export declare const resolveFrom: (lookup: string, parent?: string) => string; | ||
/** | ||
@@ -26,2 +25,7 @@ * | ||
export default function resolveExtends(config?: UserConfig, context?: ResolveExtendsContext): Promise<UserConfig>; | ||
export declare function resolveFromSilent(specifier: string, parent: string): string | void; | ||
/** | ||
* @see https://github.com/sindresorhus/resolve-global/blob/682a6bb0bd8192b74a6294219bb4c536b3708b65/index.js#L7 | ||
*/ | ||
export declare function resolveGlobalSilent(specifier: string): string | void; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -12,9 +12,9 @@ var __rest = (this && this.__rest) || function (s, e) { | ||
}; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { pathToFileURL, fileURLToPath } from 'url'; | ||
import 'resolve-global'; | ||
import globalDirectory from 'global-directory'; | ||
import { moduleResolve } from 'import-meta-resolve'; | ||
import mergeWith from 'lodash.mergewith'; | ||
import { validateConfig } from '@commitlint/config-validator'; | ||
import importFresh from 'import-fresh'; | ||
const dynamicImport = async (id) => { | ||
@@ -24,12 +24,31 @@ const imported = await import(path.isAbsolute(id) ? pathToFileURL(id).toString() : id); | ||
}; | ||
const pathSuffixes = [ | ||
'', | ||
'.js', | ||
'.json', | ||
`${path.sep}index.js`, | ||
`${path.sep}index.json`, | ||
]; | ||
const specifierSuffixes = ['', '.js', '.json', '/index.js', '/index.json']; | ||
/** | ||
* @see moduleResolve | ||
*/ | ||
export const resolveFrom = (specifier, parent) => { | ||
let resolved; | ||
export const resolveFrom = (lookup, parent) => { | ||
if (path.isAbsolute(lookup)) { | ||
for (const suffix of pathSuffixes) { | ||
const filename = lookup + suffix; | ||
if (fs.existsSync(filename)) { | ||
return filename; | ||
} | ||
} | ||
} | ||
let resolveError; | ||
for (const suffix of ['', '.js', '.json', '/index.js', '/index.json']) { | ||
const base = pathToFileURL(parent | ||
? fs.statSync(parent).isDirectory() | ||
? path.join(parent, 'noop.js') | ||
: parent | ||
: import.meta.url); | ||
for (const suffix of specifierSuffixes) { | ||
try { | ||
resolved = moduleResolve(specifier + suffix, pathToFileURL(parent ? parent : import.meta.url)); | ||
return fileURLToPath(resolved); | ||
return fileURLToPath(moduleResolve(lookup + suffix, base)); | ||
} | ||
@@ -75,6 +94,2 @@ catch (err) { | ||
} | ||
/** | ||
* Fake file name to provide {@link moduleResolve} a filename to resolve from the configuration cwd | ||
*/ | ||
const FAKE_FILE_NAME_FOR_RESOLVER = '__'; | ||
async function loadExtends(config = {}, context = {}) { | ||
@@ -92,3 +107,3 @@ const { extends: e } = config; | ||
typeof c.parserPreset === 'string') { | ||
const resolvedParserPreset = resolveFrom(c.parserPreset, path.join(cwd, FAKE_FILE_NAME_FOR_RESOLVER)); | ||
const resolvedParserPreset = resolveFrom(c.parserPreset, cwd); | ||
const parserPreset = Object.assign({ name: c.parserPreset }, (await loadParserPreset(resolvedParserPreset))); | ||
@@ -150,15 +165,22 @@ ctx.parserPreset = parserPreset; | ||
} | ||
function resolveFromSilent(specifier, parent) { | ||
export function resolveFromSilent(specifier, parent) { | ||
try { | ||
return resolveFrom(specifier, path.join(parent, FAKE_FILE_NAME_FOR_RESOLVER)); | ||
return resolveFrom(specifier, parent); | ||
} | ||
catch (err) { } | ||
catch (_a) { } | ||
} | ||
function resolveGlobalSilent(specifier) { | ||
try { | ||
const resolveGlobal = importFresh('resolve-global'); | ||
return resolveGlobal(specifier); | ||
/** | ||
* @see https://github.com/sindresorhus/resolve-global/blob/682a6bb0bd8192b74a6294219bb4c536b3708b65/index.js#L7 | ||
*/ | ||
export function resolveGlobalSilent(specifier) { | ||
for (const globalPackages of [ | ||
globalDirectory.npm.packages, | ||
globalDirectory.yarn.packages, | ||
]) { | ||
try { | ||
return resolveFrom(specifier, globalPackages); | ||
} | ||
catch (_a) { } | ||
} | ||
catch (err) { } | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@commitlint/resolve-extends", | ||
"type": "module", | ||
"version": "19.0.0", | ||
"version": "19.0.1", | ||
"description": "Lint your commit messages", | ||
@@ -45,8 +45,7 @@ "main": "lib/index.js", | ||
"@commitlint/types": "^19.0.0", | ||
"import-fresh": "^3.0.0", | ||
"global-directory": "^4.0.1", | ||
"import-meta-resolve": "^4.0.0", | ||
"lodash.mergewith": "^4.6.2", | ||
"resolve-global": "^2.0.0" | ||
"lodash.mergewith": "^4.6.2" | ||
}, | ||
"gitHead": "f1ff12159d627ee63bf8982ab02e6cca8f10b09f" | ||
"gitHead": "9351b8e1f4e9fc1ff45e55dabcd2d887ac2a8070" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
17650
5
208
1
+ Addedglobal-directory@^4.0.1
- Removedimport-fresh@^3.0.0
- Removedresolve-global@^2.0.0
- Removedcallsites@3.1.0(transitive)
- Removedimport-fresh@3.3.0(transitive)
- Removedparent-module@1.0.1(transitive)
- Removedresolve-from@4.0.0(transitive)
- Removedresolve-global@2.0.0(transitive)