Skip to content

Commit

Permalink
do not use path.join
Browse files Browse the repository at this point in the history
Git uses forward slashes, even on windows
  • Loading branch information
tevanoff committed May 14, 2024
1 parent e368c0f commit 9f3bdc4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions node-src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Context } from '../types';
import gitNoCommits from '../ui/messages/errors/gitNoCommits';
import gitNotInitialized from '../ui/messages/errors/gitNotInitialized';
import gitNotInstalled from '../ui/messages/errors/gitNotInstalled';
import path from 'node:path';

const newline = /\r\n|\r|\n/; // Git may return \n even on Windows, so we can't use EOL
export const NULL_BYTE = '\0'; // Separator used when running `git ls-files` with `-z`
Expand Down Expand Up @@ -289,8 +288,10 @@ export async function findFilesFromRepositoryRoot(...patterns: string[]) {

// Ensure patterns are referenced from the repository root so that running
// from within a subdirectory does not skip the directories above
// e.g. /root/package.json and /root/**/package.json
const patternsFromRoot = patterns.map((pattern) => path.join(repoRoot, pattern));
// e.g. /root/package.json, /root/**/package.json
// Note that this does not use `path.join` to concatenate the file paths because
// git uses forward slashes, even on windows
const patternsFromRoot = patterns.map((pattern) => `${repoRoot}/${pattern}`);

// Uses `--full-name` to ensure that all files found are relative to the repository root,
// not the directory in which this is executed from
Expand Down
8 changes: 5 additions & 3 deletions node-src/lib/findChangedDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ export const findChangedDependencies = async (ctx: Context) => {
ctx.log.debug({ rootPath, rootManifestPath, rootLockfilePath }, `Found manifest and lockfile`);

// Handle monorepos with (multiple) nested package.json files.
const nestedManifestPaths = await findFilesFromRepositoryRoot(path.join('**', PACKAGE_JSON));
// Note that this does not use `path.join` to concatenate the file paths because
// git uses forward slashes, even on windows
const nestedManifestPaths = await findFilesFromRepositoryRoot(`**/${PACKAGE_JSON}`);
const metadataPathPairs = await Promise.all(
nestedManifestPaths.map(async (manifestPath) => {
const dirname = path.dirname(manifestPath);
const [lockfilePath] = await findFilesFromRepositoryRoot(
path.join(dirname, YARN_LOCK),
path.join(dirname, PACKAGE_LOCK)
`${dirname}/${YARN_LOCK}`,
`${dirname}/${PACKAGE_LOCK}`
);
// Fall back to the root lockfile if we can't find one in the same directory.
return [manifestPath, lockfilePath || rootLockfilePath];
Expand Down

0 comments on commit 9f3bdc4

Please sign in to comment.