Skip to content

Commit

Permalink
fix: don't match folders when globbing symbols (#131)
Browse files Browse the repository at this point in the history
* fix: don't match folders when globbing symbols

* refactor: simplify glob
  • Loading branch information
bobbyg603 authored Aug 8, 2024
1 parent 1b51a4f commit c71bf10
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
9 changes: 1 addition & 8 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import { CommandLineDefinition, argDefinitions, usageDefinitions } from './comma

const globPattern = `${directory}/${files}`;

let symbolFilePaths = await glob(globPattern);
let symbolFilePaths = await globFiles(globPattern);

if (!symbolFilePaths.length) {
throw new Error(`Could not find any files to upload using glob ${globPattern}!`);
Expand Down Expand Up @@ -147,13 +147,6 @@ async function createBugSplatClient({
return OAuthClientCredentialsClient.createAuthenticatedClient(clientId, clientSecret, host);
}

async function fileExists(path: string): Promise<boolean> {
try {
return !!(await stat(path));
} catch {
return false;
}
}

async function getCommandLineOptions(argDefinitions: Array<CommandLineDefinition>): Promise<CommandLineOptions> {
const options = commandLineArgs(argDefinitions);
Expand Down
15 changes: 15 additions & 0 deletions spec/fs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fileExists } from "../src/fs";

describe('fs', () => {
describe('fileExists', () => {
it('should return true if the file exists', async () => {
const exists = await fileExists(__filename);
expect(exists).toBe(true);
});

it('should return false if the file does not exist', async () => {
const exists = await fileExists('does-not-exist.txt');
expect(exists).toBe(false);
});
});
})
18 changes: 18 additions & 0 deletions spec/glob.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { join } from "node:path";
import { globFiles } from "../src/glob";

describe('glob', () => {
describe('globFiles', () => {
it('should return result with directories filtered out', async () => {
const supportDir = join(__dirname, 'support');
const pattern = join(supportDir, '**', '*.dll');
const files = await globFiles(pattern);
expect(files).toEqual(
jasmine.arrayContaining([
join(supportDir, 'bugsplat.dll'),
join(supportDir, 'symsrv', 'bugsplat.dll', '64FB82ED7A000', 'bugsplat.dll'),
])
);
});
});
});
Binary file not shown.
9 changes: 9 additions & 0 deletions src/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { stat } from "node:fs/promises";

export async function fileExists(path: string): Promise<boolean> {
try {
return !!(await stat(path));
} catch {
return false;
}
}
5 changes: 5 additions & 0 deletions src/glob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { glob } from "glob";

export async function globFiles(pattern: string): Promise<string[]> {
return glob(pattern, { nodir: true });
}

0 comments on commit c71bf10

Please sign in to comment.