Skip to content

Commit 8bbf088

Browse files
committed
feat: support ci-only / local-only on addon features
1 parent 3aee34b commit 8bbf088

File tree

11 files changed

+79
-36
lines changed

11 files changed

+79
-36
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"typesVersions": {
3535
"*": {
3636
"*": [
37-
"./dist/*",
37+
"./dist/*.d.mts",
3838
"./*"
3939
]
4040
}
@@ -117,6 +117,7 @@
117117
"@vueuse/core": "catalog:docs",
118118
"bumpp": "catalog:dev",
119119
"eslint": "catalog:dev",
120+
"is-in-ci": "catalog:prod",
120121
"lightningcss": "catalog:dev",
121122
"pkg-types": "catalog:dev",
122123
"prettier": "catalog:dev",

packages/create-tsdown/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"typesVersions": {
3030
"*": {
3131
"*": [
32-
"./dist/*",
32+
"./dist/*.d.mts",
3333
"./*"
3434
]
3535
}

pnpm-lock.yaml

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

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ catalogs:
5454
empathic: ^2.0.0
5555
giget: ^2.0.0
5656
hookable: ^5.5.3
57+
is-in-ci: ^2.0.0
5758
obug: ^2.1.1
5859
package-manager-detector: ^1.5.0
5960
rolldown: 1.0.0-beta.51

src/config/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path'
33
import process from 'node:process'
44
import { pathToFileURL } from 'node:url'
55
import { underline } from 'ansis'
6+
import isInCi from 'is-in-ci'
67
import { createDebug } from 'obug'
78
import { createConfigCoreLoader } from 'unconfig-core'
89
import { fsStat } from '../utils/fs.ts'
@@ -119,7 +120,7 @@ export async function loadConfigFile(
119120

120121
exported = await exported
121122
if (typeof exported === 'function') {
122-
exported = await exported(inlineConfig)
123+
exported = await exported(inlineConfig, { ci: isInCi })
123124
}
124125
}
125126

src/config/index.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path'
22
import process from 'node:process'
33
import { blue } from 'ansis'
4+
import isInCi from 'is-in-ci'
45
import { createDebug } from 'obug'
56
import { glob } from 'tinyglobby'
67
import { resolveClean } from '../features/clean.ts'
@@ -19,7 +20,12 @@ import { createLogger } from '../utils/logger.ts'
1920
import { normalizeFormat, readPackageJson } from '../utils/package.ts'
2021
import type { Awaitable } from '../utils/types.ts'
2122
import { loadConfigFile, loadViteConfig } from './config.ts'
22-
import type { InlineConfig, ResolvedConfig, UserConfig } from './types.ts'
23+
import type {
24+
CIOption,
25+
InlineConfig,
26+
ResolvedConfig,
27+
UserConfig,
28+
} from './types.ts'
2329

2430
export * from './types.ts'
2531

@@ -203,7 +209,7 @@ async function resolveUserConfig(
203209
env = {},
204210
copy,
205211
publicDir,
206-
hash,
212+
hash = true,
207213
cwd = process.cwd(),
208214
name,
209215
workspace,
@@ -221,7 +227,10 @@ async function resolveUserConfig(
221227
debug = false,
222228
} = userConfig
223229

224-
const logger = createLogger(logLevel, { customLogger, failOnWarn })
230+
const logger = createLogger(logLevel, {
231+
customLogger,
232+
failOnWarn: resolveFeatureOption(failOnWarn, true),
233+
})
225234

226235
if (typeof bundle === 'boolean') {
227236
logger.warn('`bundle` option is deprecated. Use `unbundle` instead.')
@@ -260,9 +269,12 @@ async function resolveUserConfig(
260269
noExternal = resolveRegex(noExternal)
261270
}
262271

263-
if (publint === true) publint = {}
264-
if (attw === true) attw = {}
265-
if (exports === true) exports = {}
272+
publint = resolveFeatureOption(publint, {})
273+
attw = resolveFeatureOption(attw, {})
274+
exports = resolveFeatureOption(exports, {})
275+
unused = resolveFeatureOption(unused, {})
276+
report = resolveFeatureOption(report, {})
277+
dts = resolveFeatureOption(dts, {})
266278

267279
if (publicDir) {
268280
if (copy) {
@@ -316,8 +328,8 @@ async function resolveUserConfig(
316328
inlineOnly = toArray(inlineOnly)
317329
}
318330

331+
debug = resolveFeatureOption(debug, {})
319332
if (debug) {
320-
if (debug === true) debug = {}
321333
debug.devtools ??= !!pkgExists('@vitejs/devtools/cli')
322334
}
323335

@@ -333,8 +345,8 @@ async function resolveUserConfig(
333345
treeshake,
334346
platform,
335347
sourcemap,
336-
dts: dts === true ? {} : dts,
337-
report: report === true ? {} : report,
348+
dts,
349+
report,
338350
unused,
339351
watch,
340352
ignoreWatch,
@@ -348,7 +360,7 @@ async function resolveUserConfig(
348360
env,
349361
pkg,
350362
copy: publicDir || copy,
351-
hash: hash ?? true,
363+
hash,
352364
name,
353365
external,
354366
noExternal,
@@ -378,3 +390,13 @@ export async function mergeUserOptions<T extends object, A extends unknown[]>(
378390
typeof user === 'function' ? await user(defaults, ...args) : user
379391
return { ...defaults, ...userOutputOptions }
380392
}
393+
394+
function resolveFeatureOption<T>(
395+
value: boolean | CIOption | T,
396+
defaults: T,
397+
): T | false {
398+
if (value === true) return defaults
399+
if (value === 'ci-only') return isInCi ? defaults : false
400+
if (value === 'local-only') return isInCi ? false : defaults
401+
return value
402+
}

src/config/types.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export type NoExternalFn = (
9393
importer: string | undefined,
9494
) => boolean | null | undefined | void
9595

96+
export type CIOption = 'ci-only' | 'local-only'
97+
9698
/**
9799
* Options for tsdown.
98100
*/
@@ -243,7 +245,7 @@ export interface UserConfig {
243245

244246
//#region Output Options
245247

246-
/** @default ['es'] */
248+
/** @default 'es' */
247249
format?: Format | Format[]
248250
globalName?: string
249251
/** @default 'dist' */
@@ -353,7 +355,7 @@ export interface UserConfig {
353355
* If true, fails the build on warnings.
354356
* @default false
355357
*/
356-
failOnWarn?: boolean
358+
failOnWarn?: boolean | CIOption
357359
/**
358360
* Custom logger.
359361
*/
@@ -387,7 +389,7 @@ export interface UserConfig {
387389
*
388390
* @default false
389391
*/
390-
debug?: boolean | DebugOptions
392+
debug?: boolean | CIOption | DebugOptions
391393

392394
//#region Addons
393395

@@ -398,21 +400,21 @@ export interface UserConfig {
398400
* - If the `types` field is present, or if the main `exports` contains a `types` entry, declaration file generation is enabled by default.
399401
* - Otherwise, declaration file generation is disabled by default.
400402
*/
401-
dts?: boolean | DtsOptions
403+
dts?: boolean | CIOption | DtsOptions
402404

403405
/**
404406
* Enable unused dependencies check with `unplugin-unused`
405407
* Requires `unplugin-unused` to be installed.
406408
* @default false
407409
*/
408-
unused?: boolean | UnusedOptions
410+
unused?: boolean | CIOption | UnusedOptions
409411

410412
/**
411413
* Run publint after bundling.
412414
* Requires `publint` to be installed.
413415
* @default false
414416
*/
415-
publint?: boolean | PublintOptions
417+
publint?: boolean | CIOption | PublintOptions
416418

417419
/**
418420
* Run `arethetypeswrong` after bundling.
@@ -421,13 +423,13 @@ export interface UserConfig {
421423
* @default false
422424
* @see https://github.com/arethetypeswrong/arethetypeswrong.github.io
423425
*/
424-
attw?: boolean | AttwOptions
426+
attw?: boolean | CIOption | AttwOptions
425427

426428
/**
427429
* Enable size reporting after bundling.
428430
* @default true
429431
*/
430-
report?: boolean | ReportOptions
432+
report?: boolean | CIOption | ReportOptions
431433

432434
/**
433435
* `import.meta.glob` support.
@@ -442,7 +444,7 @@ export interface UserConfig {
442444
* This will set the `main`, `module`, `types`, `exports` fields in `package.json`
443445
* to point to the generated files.
444446
*/
445-
exports?: boolean | ExportsOptions
447+
exports?: boolean | CIOption | ExportsOptions
446448

447449
/**
448450
* @deprecated Alias for `copy`, will be removed in the future.
@@ -492,6 +494,7 @@ export interface InlineConfig extends UserConfig {
492494

493495
export type UserConfigFn = (
494496
inlineConfig: InlineConfig,
497+
context: { ci: boolean },
495498
) => Awaitable<Arrayable<UserConfig>>
496499

497500
export type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>
@@ -530,16 +533,20 @@ export type ResolvedConfig = Overwrite<
530533
format: NormalizedFormat[]
531534
target?: string[]
532535
clean: string[]
533-
dts: false | DtsOptions
534-
report: false | ReportOptions
535-
tsconfig: false | string
536536
pkg?: PackageJson
537-
exports: false | ExportsOptions
538537
nodeProtocol: 'strip' | boolean
539538
logger: Logger
540539
ignoreWatch: Array<string | RegExp>
541540
noExternal?: NoExternalFn
542541
inlineOnly?: Array<string | RegExp>
542+
543+
dts: false | DtsOptions
544+
report: false | ReportOptions
545+
tsconfig: false | string
546+
exports: false | ExportsOptions
543547
debug: false | DebugOptions
548+
publint: false | PublintOptions
549+
attw: false | AttwOptions
550+
unused: false | UnusedOptions
544551
}
545552
>

src/features/attw.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ export async function attw(options: ResolvedConfig): Promise<void> {
114114
options.logger.warn('attw is enabled but package.json is not found')
115115
return
116116
}
117-
const {
118-
profile = 'strict',
119-
level = 'warn',
120-
...attwOptions
121-
} = options.attw === true ? {} : options.attw
117+
const { profile = 'strict', level = 'warn', ...attwOptions } = options.attw
122118

123119
const t = performance.now()
124120
debug('Running attw check')

src/features/publint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function publint(options: ResolvedConfig): Promise<void> {
2323
const { publint } = await importWithError<typeof import('publint')>('publint')
2424
const { formatMessage } = await import('publint/utils')
2525
const { messages } = await publint({
26-
...(options.publint === true ? {} : options.publint),
26+
...options.publint,
2727
pkgDir: path.dirname(options.pkg.packageJsonPath),
2828
})
2929
debug('Found %d issues', messages.length)

src/features/rolldown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async function resolveInputOptions(
136136
plugins.push(
137137
Unused.rolldown({
138138
root: cwd,
139-
...(unused === true ? {} : unused),
139+
...unused,
140140
}),
141141
)
142142
}

0 commit comments

Comments
 (0)