mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 04:28:28 +02:00
refactor: dont try all files if not defined
This commit is contained in:
parent
93c92af672
commit
1cea06d8fc
1 changed files with 26 additions and 33 deletions
17
src/utils.ts
17
src/utils.ts
|
@ -35,22 +35,16 @@ const FILE_VERSION_READERS = {
|
|||
".bumrc": (content: string) => content,
|
||||
};
|
||||
|
||||
export function readVersionFromFile(
|
||||
files: string | string[]
|
||||
): string | undefined {
|
||||
export function readVersionFromFile(file: string): string | undefined {
|
||||
const cwd = process.env.GITHUB_WORKSPACE;
|
||||
if (!cwd) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!files) {
|
||||
warning("No version file specified, trying all known files.");
|
||||
return readVersionFromFile(Object.keys(FILE_VERSION_READERS));
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.isArray(files)) files = [files];
|
||||
|
||||
for (const file of files) {
|
||||
debug(`Reading version from ${file}`);
|
||||
|
||||
const path = join(cwd, file);
|
||||
|
@ -58,7 +52,7 @@ export function readVersionFromFile(
|
|||
|
||||
if (!existsSync(path)) {
|
||||
warning(`File ${path} not found`);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = FILE_VERSION_READERS[base] ?? (() => undefined);
|
||||
|
@ -69,7 +63,7 @@ export function readVersionFromFile(
|
|||
|
||||
if (!output) {
|
||||
warning(`Failed to read version from ${file}`);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
const { message } = error as Error;
|
||||
|
@ -81,4 +75,3 @@ export function readVersionFromFile(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue