Turn Env into a class, and add ReadOnlyEnv

This commit is contained in:
Michael B. Gale
2026-07-09 12:38:40 +01:00
parent 1d0e1b20e5
commit 732911a2fa
4 changed files with 93 additions and 53 deletions

43
lib/entry-points.js generated
View File

@@ -141483,15 +141483,32 @@ function getOptionalEnvVarFrom(env, paramName) {
function getOptionalEnvVar(paramName) {
return getOptionalEnvVarFrom(process.env, paramName);
}
var ReadOnlyEnv = class {
constructor(vars) {
this.vars = vars;
}
vars;
/** Tries to get the value for `name` and throws if there isn't one. */
getRequired(name) {
return getRequiredEnvVar(this.vars, name);
}
/** Gets the value for `name`, or `undefined` if it isn't set or empty. */
getOptional(name) {
return getOptionalEnvVarFrom(this.vars, name);
}
/** Gets the entries of the underlying `ProcessEnv`. */
entries() {
return Object.entries(this.vars);
}
};
var Env = class extends ReadOnlyEnv {
/** Sets an environment variable. */
set(name, value) {
this.vars[name] = value;
}
};
function getEnv(env = process.env) {
return {
getRequired: (name) => getRequiredEnvVar(env, name),
getOptional: (name) => getOptionalEnvVarFrom(env, name),
entries: () => Object.entries(env),
set: (name, value) => {
env[name] = value;
}
};
return new Env(env);
}
// src/util.ts
@@ -145613,15 +145630,15 @@ function createApiClientWithDetails(apiDetails, { allowExternal = false } = {})
})
);
}
function getApiDetails() {
function getApiDetails(env = getEnv()) {
return {
auth: getRequiredInput("token"),
url: getRequiredEnvParam("GITHUB_SERVER_URL" /* GITHUB_SERVER_URL */),
apiURL: getRequiredEnvParam("GITHUB_API_URL" /* GITHUB_API_URL */)
url: env.getRequired("GITHUB_SERVER_URL" /* GITHUB_SERVER_URL */),
apiURL: env.getRequired("GITHUB_API_URL" /* GITHUB_API_URL */)
};
}
function getApiClient() {
return createApiClientWithDetails(getApiDetails());
function getApiClient(env = getEnv()) {
return createApiClientWithDetails(getApiDetails(env));
}
function getApiClientWithExternalAuth(apiDetails) {
return createApiClientWithDetails(apiDetails, { allowExternal: true });