diff --git a/src/index.ts b/src/index.ts index 973c5a7..5809520 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { detectProvider } from './providers' +import { detectProvider, ProviderName } from './providers' export type { ProviderName, ProviderInfo } from './providers' @@ -11,7 +11,7 @@ const nodeENV = envShim.NODE_ENV || '' export const platform = processShim.platform /** Current current provider name */ -export const provider = providerInfo.name +export const provider: ProviderName = providerInfo.name /** Detect if `CI` environment variable is set or a provider CI detected */ export const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false diff --git a/src/providers.ts b/src/providers.ts index 8c3cc03..723c8ef 100644 --- a/src/providers.ts +++ b/src/providers.ts @@ -1,51 +1,60 @@ // Reference: https://github.com/watson/ci-info/blob/v3.2.0/vendors.json -type InternalProvider = [vendorName: string, envName?: string, meta?: Record] + +export type ProviderName = + 'appveyor' | 'azure_pipelines' | 'azure_static' | 'appcircle' | 'bamboo' | + 'bitbucket' | 'bitrise' | 'buddy' | 'buildkite' | 'circle' | 'cirrus' | + 'codebuild' | 'codefresh' | 'drone' | 'drone' | 'dsari' | 'github_actions' | + 'gitlab' | 'gitlab' | 'gocd' | 'layerci' | 'hudson' | 'jenkins' | 'magnum' | + 'netlify' | 'netlify' | 'nevercode' | 'render' | 'sail' | 'semaphore' | + 'screwdriver' | 'shippable' | 'solano' | 'strider' | 'teamcity' | 'travis' | + 'vercel' | 'appcenter' | 'codesandbox' | 'stackblitz' + +type InternalProvider = [providerName: Uppercase, envName?: string, meta?: Record] const providers: InternalProvider[] = [ - ["APPVEYOR"], - ["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"], - ["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"], - ["APPCIRCLE", "AC_APPCIRCLE"], - ["BAMBOO", "bamboo_planKey"], - ["BITBUCKET", "BITBUCKET_COMMIT"], - ["BITRISE", "BITRISE_IO"], - ["BUDDY", "BUDDY_WORKSPACE_ID"], - ["BUILDKITE"], - ["CIRCLE", "CIRCLECI"], - ["CIRRUS", "CIRRUS_CI"], - ["CODEBUILD", "CODEBUILD_BUILD_ARN"], - ["CODEFRESH", "CF_BUILD_ID"], - ["DRONE"], - ["DRONE", "DRONE_BUILD_EVENT"], - ["DSARI"], - ["GITHUB_ACTIONS"], - ["GITLAB", "GITLAB_CI"], - ["GITLAB", "CI_MERGE_REQUEST_ID"], - ["GOCD", "GO_PIPELINE_LABEL"], - ["LAYERCI"], - ["HUDSON", "HUDSON_URL"], - ["JENKINS", "JENKINS_URL"], - ["MAGNUM"], - ["NETLIFY"], - ["NETLIFY", "NETLIFY_LOCAL", { ci: false }], - ["NEVERCODE"], - ["RENDER"], - ["SAIL", "SAILCI"], - ["SEMAPHORE"], - ["SCREWDRIVER"], - ["SHIPPABLE"], - ["SOLANO", "TDDIUM"], - ["STRIDER"], - ["TEAMCITY", "TEAMCITY_VERSION"], - ["TRAVIS"], - ["VERCEL", "NOW_BUILDER"], - ["APPCENTER", "APPCENTER_BUILD_ID"], - ["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }], - ["STACKBLITZ"], + ['APPVEYOR'], + ['AZURE_PIPELINES', 'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'], + ['AZURE_STATIC', 'INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN'], + ['APPCIRCLE', 'AC_APPCIRCLE'], + ['BAMBOO', 'bamboo_planKey'], + ['BITBUCKET', 'BITBUCKET_COMMIT'], + ['BITRISE', 'BITRISE_IO'], + ['BUDDY', 'BUDDY_WORKSPACE_ID'], + ['BUILDKITE'], + ['CIRCLE', 'CIRCLECI'], + ['CIRRUS', 'CIRRUS_CI'], + ['CODEBUILD', 'CODEBUILD_BUILD_ARN'], + ['CODEFRESH', 'CF_BUILD_ID'], + ['DRONE'], + ['DRONE', 'DRONE_BUILD_EVENT'], + ['DSARI'], + ['GITHUB_ACTIONS'], + ['GITLAB', 'GITLAB_CI'], + ['GITLAB', 'CI_MERGE_REQUEST_ID'], + ['GOCD', 'GO_PIPELINE_LABEL'], + ['LAYERCI'], + ['HUDSON', 'HUDSON_URL'], + ['JENKINS', 'JENKINS_URL'], + ['MAGNUM'], + ['NETLIFY'], + ['NETLIFY', 'NETLIFY_LOCAL', { ci: false }], + ['NEVERCODE'], + ['RENDER'], + ['SAIL', 'SAILCI'], + ['SEMAPHORE'], + ['SCREWDRIVER'], + ['SHIPPABLE'], + ['SOLANO', 'TDDIUM'], + ['STRIDER'], + ['TEAMCITY', 'TEAMCITY_VERSION'], + ['TRAVIS'], + ['VERCEL', 'NOW_BUILDER'], + ['APPCENTER', 'APPCENTER_BUILD_ID'], + ['CODESANDBOX', 'CODESANDBOX_SSE', { ci: false }], + ['STACKBLITZ'], ] -export type ProviderName = Lowercase<(typeof providers)[number][0]> export type ProviderInfo = { name: ProviderName, [meta: string]: any } export function detectProvider(env: Record): ProviderInfo | null {