Skip to content

Commit bfc649e

Browse files
committed
fix: inline CI detection
1 parent 15ac682 commit bfc649e

11 files changed

Lines changed: 61 additions & 38 deletions

File tree

docs/advanced/ci.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tsdown automatically detects CI environments and allows you to enable or disable
44

55
## CI Detection
66

7-
tsdown uses the [`is-in-ci`](https://www.npmjs.com/package/is-in-ci) package to detect CI environments. This covers all major CI providers including GitHub Actions, GitLab CI, Jenkins, CircleCI, Travis CI, and more.
7+
tsdown detects CI from the `CI` environment variable. CI mode is enabled when `process.env.CI` is set to a value other than `0` or `false` (case-insensitive).
88

99
## CI-Aware Options
1010

docs/zh-CN/advanced/ci.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tsdown 能够自动检测 CI 环境,并允许你根据构建是在本地还是
44

55
## CI 检测
66

7-
tsdown 使用 [`is-in-ci`](https://www.npmjs.com/package/is-in-ci) 包来检测 CI 环境,支持所有主流 CI 服务商,包括 GitHub Actions、GitLab CI、Jenkins、CircleCI、Travis CI
7+
tsdown 通过 `CI` 环境变量检测 CI 环境。当 `process.env.CI` 被设置,且其值不是 `0``false`(不区分大小写)时,将启用 CI 模式
88

99
## CI 感知选项
1010

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@
146146
"unconfig-core": "catalog:prod"
147147
},
148148
"inlinedDependencies": {
149-
"is-in-ci": "2.0.0",
150149
"package-manager-detector": "1.6.0",
151150
"pkg-types": "2.3.1"
152151
},
@@ -171,7 +170,6 @@
171170
"bumpp": "catalog:dev",
172171
"dedent": "catalog:dev",
173172
"eslint": "catalog:dev",
174-
"is-in-ci": "catalog:prod",
175173
"memfs": "catalog:dev",
176174
"package-manager-detector": "catalog:prod",
177175
"pkg-types": "catalog:dev",

pnpm-lock.yaml

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ catalogs:
7474
empathic: ^2.0.1
7575
hookable: ^6.1.1
7676
import-without-cache: ^0.4.0
77-
is-in-ci: ^2.0.0
7877
lightningcss: ^1.32.0
7978
obug: ^2.1.1
8079
package-manager-detector: ^1.6.0

skills/tsdown/references/advanced-ci.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Automatically detect CI environments and toggle features based on local vs CI bu
44

55
## Overview
66

7-
tsdown uses the [`is-in-ci`](https://www.npmjs.com/package/is-in-ci) package to detect CI environments. This covers GitHub Actions, GitLab CI, Jenkins, CircleCI, Travis CI, and more.
7+
tsdown detects CI from the `CI` environment variable. CI mode is enabled when `process.env.CI` is set to a value other than `0` or `false` (case-insensitive).
88

99
## CI-Aware Values
1010

src/config/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import process from 'node:process'
44
import { pathToFileURL } from 'node:url'
55
import { underline } from 'ansis'
66
import { depsStore, init, isSupported } from 'import-without-cache'
7-
import isInCi from 'is-in-ci'
87
import { createDebug } from 'obug'
98
import { createConfigCoreLoader } from 'unconfig-core'
9+
import { isInCI } from '../utils/ci.ts'
1010
import { fsStat } from '../utils/fs.ts'
1111
import { importWithError, toArray } from '../utils/general.ts'
1212
import { globalLogger } from '../utils/logger.ts'
@@ -136,7 +136,7 @@ export async function loadConfigFile(
136136

137137
exported = await exported
138138
if (typeof exported === 'function') {
139-
exported = await exported(inlineConfig, { ci: isInCi, rootConfig })
139+
exported = await exported(inlineConfig, { ci: isInCI(), rootConfig })
140140
}
141141
}
142142

src/config/options.test.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import isInCi from 'is-in-ci'
2-
import { describe, expect, test } from 'vitest'
1+
import { afterEach, describe, expect, test, vi } from 'vitest'
2+
import { isInCI } from '../utils/ci.ts'
33
import {
44
resolveFeatureOption as _resolveFeatureOption,
55
mergeConfig,
@@ -11,18 +11,54 @@ interface DefaultOption {
1111
}
1212
const resolveFeatureOption = _resolveFeatureOption<DefaultOption>
1313

14+
afterEach(() => {
15+
vi.unstubAllEnvs()
16+
})
17+
18+
describe('isInCI', () => {
19+
test('detects CI from process.env.CI', () => {
20+
vi.stubEnv('CI', undefined)
21+
expect(isInCI()).toBe(false)
22+
23+
vi.stubEnv('CI', '')
24+
expect(isInCI()).toBe(true)
25+
26+
vi.stubEnv('CI', '0')
27+
expect(isInCI()).toBe(false)
28+
29+
vi.stubEnv('CI', 'false')
30+
expect(isInCI()).toBe(false)
31+
32+
vi.stubEnv('CI', 'FALSE')
33+
expect(isInCI()).toBe(false)
34+
35+
vi.stubEnv('CI', '1')
36+
expect(isInCI()).toBe(true)
37+
38+
vi.stubEnv('CI', 'true')
39+
expect(isInCI()).toBe(true)
40+
})
41+
})
42+
1443
describe('resolveFeatureOption', () => {
1544
test('literal boolean', () => {
1645
expect(resolveFeatureOption(true, defaultOption)).toBe(defaultOption)
1746
expect(resolveFeatureOption(false, defaultOption)).toBe(false)
1847
})
1948

20-
test('literal CI', () => {
21-
expect(resolveFeatureOption('ci-only', defaultOption)).toBe(
22-
isInCi ? defaultOption : false,
23-
)
49+
test('literal CI in CI', () => {
50+
vi.stubEnv('CI', 'true')
51+
52+
expect(resolveFeatureOption('ci-only', defaultOption)).toBe(defaultOption)
53+
expect(resolveFeatureOption('local-only', defaultOption)).toBe(false)
54+
})
55+
56+
test('literal CI locally', () => {
57+
vi.stubEnv('CI', undefined)
58+
59+
expect(resolveFeatureOption('ci-only', defaultOption)).toBe(false)
2460
expect(resolveFeatureOption('local-only', defaultOption)).toBe(
25-
isInCi ? false : defaultOption,
61+
defaultOption,
2662
)
2763
})
2864

@@ -43,18 +79,16 @@ describe('resolveFeatureOption', () => {
4379
})
4480

4581
test('object with CI enabled', () => {
82+
vi.stubEnv('CI', 'true')
83+
4684
{
4785
const value = { enabled: 'ci-only' as const, a: 42 }
48-
expect(resolveFeatureOption(value, defaultOption)).toBe(
49-
isInCi ? value : false,
50-
)
86+
expect(resolveFeatureOption(value, defaultOption)).toBe(value)
5187
}
5288

5389
{
5490
const value = { enabled: 'local-only' as const, a: 42 }
55-
expect(resolveFeatureOption(value, defaultOption)).toBe(
56-
isInCi ? false : value,
57-
)
91+
expect(resolveFeatureOption(value, defaultOption)).toBe(false)
5892
}
5993
})
6094
})

src/config/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from 'node:path'
33
import process from 'node:process'
44
import { blue } from 'ansis'
55
import { createDefu } from 'defu'
6-
import isInCi from 'is-in-ci'
76
import { createDebug } from 'obug'
87
import { readTsconfig } from 'rolldown-plugin-dts/internal'
98
import { resolveClean } from '../features/clean.ts'
@@ -14,6 +13,7 @@ import { hasExportsTypes } from '../features/pkg/exports.ts'
1413
import { flattenPlugins } from '../features/plugin.ts'
1514
import { resolveTarget } from '../features/target.ts'
1615
import { resolveTsconfig } from '../features/tsconfig.ts'
16+
import { isInCI } from '../utils/ci.ts'
1717
import {
1818
pkgExists,
1919
resolveComma,
@@ -461,8 +461,8 @@ export function resolveFeatureOption<T>(
461461
}
462462

463463
function resolveCIOption(value: boolean | CIOption): boolean {
464-
if (value === 'ci-only') return isInCi ? true : false
465-
if (value === 'local-only') return isInCi ? false : true
464+
if (value === 'ci-only') return isInCI()
465+
if (value === 'local-only') return !isInCI()
466466
return value
467467
}
468468

src/utils/ci.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import process from 'node:process'
2+
3+
export function isInCI(): boolean {
4+
const ci = process.env.CI
5+
return ci != null && ci !== '0' && ci.toLowerCase() !== 'false'
6+
}

0 commit comments

Comments
 (0)