Skip to content

Commit

Permalink
fix: fallback to resolve-from for Yarn P'n'P (#3941)
Browse files Browse the repository at this point in the history
* fix: fallback to `require.resolve` for Yarn P'n'P

close #3936

* refactor: use `resolve-from` package
  • Loading branch information
JounQin committed Feb 28, 2024
1 parent 9351b8e commit 1eb9b5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion @commitlint/resolve-extends/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"@commitlint/types": "^19.0.0",
"global-directory": "^4.0.1",
"import-meta-resolve": "^4.0.0",
"lodash.mergewith": "^4.6.2"
"lodash.mergewith": "^4.6.2",
"resolve-from": "^5.0.0"
},
"gitHead": "d829bf6260304ca8d6811f329fcdd1b6c50e9749"
}
11 changes: 10 additions & 1 deletion @commitlint/resolve-extends/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {pathToFileURL, fileURLToPath} from 'url';
import globalDirectory from 'global-directory';
import {moduleResolve} from 'import-meta-resolve';
import mergeWith from 'lodash.mergewith';
import resolveFrom_ from 'resolve-from';
import {validateConfig} from '@commitlint/config-validator';
import type {ParserPreset, UserConfig} from '@commitlint/types';

Expand Down Expand Up @@ -58,7 +59,15 @@ export const resolveFrom = (lookup: string, parent?: string): string => {
}
}

throw resolveError;
try {
/**
* Yarn P'n'P does not support pure ESM well, this is only a workaround for
* @see https://github.com/conventional-changelog/commitlint/issues/3936
*/
return resolveFrom_(path.dirname(fileURLToPath(base)), lookup);
} catch {
throw resolveError;
}
};

/**
Expand Down

0 comments on commit 1eb9b5f

Please sign in to comment.