Skip to content

Commit

Permalink
chore: fix CI for Windows (3)
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Jul 16, 2024
1 parent 5242444 commit f68d758
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions handlebars/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function renderTree(object, options) {
* @memberOf helpers
*/
function withPackageOf(filePath, options) {
return resolvePackageRoot(path.resolve(filePath)).then(function (resolvedPackageRoot) {
return resolvePackageRoot(path.resolve(filePath), { posix: true }).then(function (resolvedPackageRoot) {
const data = Handlebars.createFrame(options.data)
data.url = _githubUrl(resolvedPackageRoot)
data.package = resolvedPackageRoot.packageJson
Expand Down Expand Up @@ -426,7 +426,7 @@ function transformTree(object, fn) {
*/
function github(filePath) {
// Build url to correct version and file in githubs
return resolvePackageRoot(path.resolve(filePath)).then(_githubUrl)
return resolvePackageRoot(path.resolve(filePath), { posix: true }).then(_githubUrl)
}

/**
Expand Down
16 changes: 9 additions & 7 deletions lib/utils/resolve-package-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ module.exports = { resolvePackageRoot }
* * **relativeFile**: The path of "file" relative to the packageRoot
* * **packageJson**: The required package.json
*
* @param file
* @param
* @param {boolean} posix if set to true, use POSIX separator (i.e. "/") instead of OS dependent one.
* @return {{packageRoot: string, packageJson: object, relativeFile: string}} the path to the package.json
*/
function resolvePackageRoot(file) {
function resolvePackageRoot(file, { posix = false } = {}) {
try {
const fullPath = path.resolve(file)
for (let lead = fullPath; path.dirname(lead) !== lead; lead = path.dirname(lead)) {
const chosenPath = posix ? path.posix : path
const fullPath = chosenPath.resolve(file)
for (let lead = fullPath; chosenPath.dirname(lead) !== lead; lead = chosenPath.dirname(lead)) {
debug('Looking for package.json in ' + lead)
const packagePath = path.join(lead, 'package.json')
const packagePath = chosenPath.join(lead, 'package.json')
try {
if (fs.statSync(packagePath).isFile()) {
return fs
.readFile(packagePath, 'utf-8')
.then(JSON.parse)
.then(packageJson => {
return {
packageRoot: path.relative(process.cwd(), lead) || '.',
relativeFile: path.relative(lead, fullPath),
packageRoot: chosenPath.relative(process.cwd(), lead) || '.',
relativeFile: chosenPath.relative(lead, fullPath),
packageJson
}
})
Expand Down

0 comments on commit f68d758

Please sign in to comment.