vite-plugin-zephyr
Version:
Vite plugin for Zephyr
42 lines (41 loc) • 1.63 kB
JavaScript
import { ZeErrors, ZephyrError } from "zephyr-agent";
function firstDefined(parts) {
return parts.every((part)=>!!part) ? parts.join(':') : void 0;
}
function resolveCiInvocationId(env) {
return firstDefined([
env['GITHUB_RUN_ID'],
env['GITHUB_RUN_ATTEMPT'] ?? '1',
env['GITHUB_JOB']
]) ?? firstDefined([
env['CI_PIPELINE_ID'],
env['CI_JOB_ID']
]) ?? firstDefined([
env['BUILDKITE_BUILD_ID'],
env['BUILDKITE_JOB_ID']
]) ?? firstDefined([
env['CIRCLE_WORKFLOW_ID'],
env['CIRCLE_BUILD_NUM']
]);
}
function resolveVitePartialBuildScope(options, env = process.env) {
const invocationId = options?.invocationId?.trim() || env['ZE_BUILD_INVOCATION_ID']?.trim() || resolveCiInvocationId(env);
if (!invocationId) return;
const generation = options?.generation ?? 0;
if (!Number.isSafeInteger(generation) || generation < 0) throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
message: 'Vite partial build generation must be a non-negative safe integer.'
});
return {
invocationId,
generation
};
}
function requireVitePartialBuildScope(options) {
const scope = resolveVitePartialBuildScope(options);
if (scope) return scope;
throw new ZephyrError(ZeErrors.ERR_DEPLOY_LOCAL_BUILD, {
message: "withZephyrPartial() requires a shared invocationId (or ZE_BUILD_INVOCATION_ID) so concurrent builds of the same application cannot mix outputs."
});
}
export { requireVitePartialBuildScope, resolveVitePartialBuildScope };
//# sourceMappingURL=partial-build-scope.mjs.map