feat: use packageManager from package.json as default bun version (#152)
* Initial plan * feat: make packageManager from package.json the default bun version Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * test: improve cross-platform compatibility and cleanup in utils tests Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * docs: update README to document automatic package.json version detection Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> * conflicts * ci: setup-bun-from-package-json-without-specified-field * ci: setup-bun-from-package-json-without-specified-field * ci: no cache --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com> Co-authored-by: Jozef Steinhübl <contact@xhyrom.dev>
This commit is contained in:
17
src/utils.ts
17
src/utils.ts
@@ -80,7 +80,10 @@ const FILE_VERSION_READERS = {
|
||||
".bun-version": (content: string) => content,
|
||||
};
|
||||
|
||||
export function readVersionFromFile(file: string): string | undefined {
|
||||
export function readVersionFromFile(
|
||||
file: string,
|
||||
silent = false,
|
||||
): string | undefined {
|
||||
const cwd = process.env.GITHUB_WORKSPACE;
|
||||
if (!cwd) {
|
||||
return;
|
||||
@@ -96,7 +99,9 @@ export function readVersionFromFile(file: string): string | undefined {
|
||||
const base = basename(file);
|
||||
|
||||
if (!existsSync(path)) {
|
||||
warning(`File ${path} not found`);
|
||||
if (!silent) {
|
||||
warning(`File ${path} not found`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,12 +112,16 @@ export function readVersionFromFile(file: string): string | undefined {
|
||||
output = reader(readFileSync(path, "utf8"))?.trim();
|
||||
|
||||
if (!output) {
|
||||
warning(`Failed to read version from ${file}`);
|
||||
if (!silent) {
|
||||
warning(`Failed to read version from ${file}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
const { message } = error as Error;
|
||||
warning(`Failed to read ${file}: ${message}`);
|
||||
if (!silent) {
|
||||
warning(`Failed to read ${file}: ${message}`);
|
||||
}
|
||||
} finally {
|
||||
if (output) {
|
||||
info(`Obtained version ${output} from ${file}`);
|
||||
|
||||
Reference in New Issue
Block a user