Skip to content

Commit 63e6f4f

Browse files
committed
feat(devtools)!: rename debug to devtools, rename debug.devtools to devtools.ui
1 parent 480360f commit 63e6f4f

File tree

10 files changed

+59
-55
lines changed

10 files changed

+59
-55
lines changed

dts.snapshot.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"CopyOptions": "type CopyOptions = Arrayable<string | CopyEntry>",
2727
"CopyOptionsFn": "type CopyOptionsFn = (_: ResolvedConfig) => Awaitable<CopyOptions>",
2828
"CssOptions": "interface CssOptions {\n splitting?: boolean\n fileName?: string\n}",
29-
"DebugOptions": "interface DebugOptions extends NonNullable<InputOptions['debug']> {\n devtools?: boolean | Partial<StartOptions>\n clean?: boolean\n}",
29+
"DevtoolsOptions": "interface DevtoolsOptions extends NonNullable<InputOptions['devtools']> {\n ui?: boolean | Partial<StartOptions>\n clean?: boolean\n}",
3030
"ExportsOptions": "interface ExportsOptions {\n devExports?: boolean | string\n packageJson?: boolean\n all?: boolean\n exclude?: (RegExp | string)[]\n customExports?: (_: Record<string, any>, _: { pkg: PackageJson; chunks: ChunksByFormat; isPublish: boolean }) => Awaitable<Record<string, any>>\n}",
3131
"Format": "type Format = ModuleFormat",
3232
"globalLogger": "Logger",
@@ -58,14 +58,14 @@
5858
"PublintOptions": "interface PublintOptions extends Options {}",
5959
"ReportOptions": "interface ReportOptions {\n gzip?: boolean\n brotli?: boolean\n maxCompressSize?: number\n}",
6060
"ReportPlugin": "declare function ReportPlugin(_: ReportOptions, _: Logger, _: string, _: boolean, _: string, _: boolean): Plugin",
61-
"ResolvedConfig": "type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, 'workspace' | 'fromVite' | 'publicDir' | 'silent' | 'bundle' | 'removeNodeProtocol' | 'logLevel' | 'failOnWarn' | 'customLogger' | 'envFile' | 'envPrefix'>, 'globalName' | 'inputOptions' | 'outputOptions' | 'minify' | 'define' | 'alias' | 'external' | 'onSuccess' | 'outExtensions' | 'hooks' | 'copy' | 'loader' | 'name' | 'banner' | 'footer'>, { entry: Record<string, string>; nameLabel: string | undefined; format: NormalizedFormat; target?: string[]; clean: string[]; pkg?: PackageJsonWithPath; nodeProtocol: 'strip' | boolean; logger: Logger; ignoreWatch: Array<string | RegExp>; noExternal?: NoExternalFn; inlineOnly?: Array<string | RegExp>; css: Required<CssOptions>; dts: false | DtsOptions; report: false | ReportOptions; tsconfig: false | string; exports: false | ExportsOptions; debug: false | DebugOptions; publint: false | PublintOptions; attw: false | AttwOptions; unused: false | UnusedOptions }>",
61+
"ResolvedConfig": "type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, 'workspace' | 'fromVite' | 'publicDir' | 'silent' | 'bundle' | 'removeNodeProtocol' | 'logLevel' | 'failOnWarn' | 'customLogger' | 'envFile' | 'envPrefix'>, 'globalName' | 'inputOptions' | 'outputOptions' | 'minify' | 'define' | 'alias' | 'external' | 'onSuccess' | 'outExtensions' | 'hooks' | 'copy' | 'loader' | 'name' | 'banner' | 'footer'>, { entry: Record<string, string>; nameLabel: string | undefined; format: NormalizedFormat; target?: string[]; clean: string[]; pkg?: PackageJsonWithPath; nodeProtocol: 'strip' | boolean; logger: Logger; ignoreWatch: Array<string | RegExp>; noExternal?: NoExternalFn; inlineOnly?: Array<string | RegExp>; css: Required<CssOptions>; dts: false | DtsOptions; report: false | ReportOptions; tsconfig: false | string; exports: false | ExportsOptions; devtools: false | DevtoolsOptions; publint: false | PublintOptions; attw: false | AttwOptions; unused: false | UnusedOptions }>",
6262
"RolldownChunk": "type RolldownChunk = (OutputChunk | OutputAsset) & { outDir: string }",
6363
"RolldownContext": "interface RolldownContext {\n buildOptions: BuildOptions\n}",
6464
"Sourcemap": "type Sourcemap = boolean | 'inline' | 'hidden'",
6565
"TsdownBundle": "interface TsdownBundle extends AsyncDisposable {\n chunks: RolldownChunk[]\n config: ResolvedConfig\n}",
6666
"TsdownHooks": "interface TsdownHooks {\n 'build:prepare': (_: BuildContext) => void | Promise<void>\n 'build:before': (_: BuildContext & RolldownContext) => void | Promise<void>\n 'build:done': (_: BuildContext & { chunks: RolldownChunk[] }) => void | Promise<void>\n}",
6767
"TsdownInputOption": "type TsdownInputOption = string | string[] | Record<string, string | string[]>",
68-
"UserConfig": "interface UserConfig {\n entry?: TsdownInputOption\n external?: ExternalOption\n noExternal?: Arrayable<string | RegExp> | NoExternalFn\n inlineOnly?: Arrayable<string | RegExp>\n skipNodeModulesBundle?: boolean\n alias?: Record<string, string>\n tsconfig?: string | boolean\n platform?: 'node' | 'neutral' | 'browser'\n target?: string | string[] | false\n env?: Record<string, any>\n envFile?: string\n envPrefix?: string | string[]\n define?: Record<string, string>\n shims?: boolean\n treeshake?: boolean | TreeshakingOptions\n loader?: ModuleTypes\n removeNodeProtocol?: boolean\n nodeProtocol?: 'strip' | boolean\n plugins?: InputOptions['plugins']\n inputOptions?: InputOptions | ((_: InputOptions, _: NormalizedFormat, _: { cjsDts: boolean }) => Awaitable<InputOptions | void | null>)\n format?: Format | Format[] | Partial<Record<Format, Partial<ResolvedConfig>>>\n globalName?: string\n outDir?: string\n write?: boolean\n sourcemap?: Sourcemap\n clean?: boolean | string[]\n minify?: boolean | 'dce-only' | MinifyOptions\n footer?: ChunkAddon\n banner?: ChunkAddon\n unbundle?: boolean\n bundle?: boolean\n fixedExtension?: boolean\n outExtensions?: OutExtensionFactory\n hash?: boolean\n cjsDefault?: boolean\n outputOptions?: OutputOptions | ((_: OutputOptions, _: NormalizedFormat, _: { cjsDts: boolean }) => Awaitable<OutputOptions | void | null>)\n cwd?: string\n name?: string\n silent?: boolean\n logLevel?: LogLevel\n failOnWarn?: boolean | CIOption\n customLogger?: Logger\n fromVite?: boolean | 'vitest'\n watch?: boolean | Arrayable<string>\n ignoreWatch?: Arrayable<string | RegExp>\n debug?: WithEnabled<DebugOptions>\n onSuccess?: string | ((_: ResolvedConfig, _: AbortSignal) => void | Promise<void>)\n dts?: WithEnabled<DtsOptions>\n unused?: WithEnabled<UnusedOptions>\n publint?: WithEnabled<PublintOptions>\n attw?: WithEnabled<AttwOptions>\n report?: WithEnabled<ReportOptions>\n globImport?: boolean\n exports?: WithEnabled<ExportsOptions>\n css?: CssOptions\n publicDir?: CopyOptions | CopyOptionsFn\n copy?: CopyOptions | CopyOptionsFn\n hooks?: Partial<TsdownHooks> | ((_: Hookable<TsdownHooks>) => Awaitable<void>)\n workspace?: Workspace | Arrayable<string> | true\n}",
68+
"UserConfig": "interface UserConfig {\n entry?: TsdownInputOption\n external?: ExternalOption\n noExternal?: Arrayable<string | RegExp> | NoExternalFn\n inlineOnly?: Arrayable<string | RegExp>\n skipNodeModulesBundle?: boolean\n alias?: Record<string, string>\n tsconfig?: string | boolean\n platform?: 'node' | 'neutral' | 'browser'\n target?: string | string[] | false\n env?: Record<string, any>\n envFile?: string\n envPrefix?: string | string[]\n define?: Record<string, string>\n shims?: boolean\n treeshake?: boolean | TreeshakingOptions\n loader?: ModuleTypes\n removeNodeProtocol?: boolean\n nodeProtocol?: 'strip' | boolean\n plugins?: InputOptions['plugins']\n inputOptions?: InputOptions | ((_: InputOptions, _: NormalizedFormat, _: { cjsDts: boolean }) => Awaitable<InputOptions | void | null>)\n format?: Format | Format[] | Partial<Record<Format, Partial<ResolvedConfig>>>\n globalName?: string\n outDir?: string\n write?: boolean\n sourcemap?: Sourcemap\n clean?: boolean | string[]\n minify?: boolean | 'dce-only' | MinifyOptions\n footer?: ChunkAddon\n banner?: ChunkAddon\n unbundle?: boolean\n bundle?: boolean\n fixedExtension?: boolean\n outExtensions?: OutExtensionFactory\n hash?: boolean\n cjsDefault?: boolean\n outputOptions?: OutputOptions | ((_: OutputOptions, _: NormalizedFormat, _: { cjsDts: boolean }) => Awaitable<OutputOptions | void | null>)\n cwd?: string\n name?: string\n silent?: boolean\n logLevel?: LogLevel\n failOnWarn?: boolean | CIOption\n customLogger?: Logger\n fromVite?: boolean | 'vitest'\n watch?: boolean | Arrayable<string>\n ignoreWatch?: Arrayable<string | RegExp>\n devtools?: WithEnabled<DevtoolsOptions>\n onSuccess?: string | ((_: ResolvedConfig, _: AbortSignal) => void | Promise<void>)\n dts?: WithEnabled<DtsOptions>\n unused?: WithEnabled<UnusedOptions>\n publint?: WithEnabled<PublintOptions>\n attw?: WithEnabled<AttwOptions>\n report?: WithEnabled<ReportOptions>\n globImport?: boolean\n exports?: WithEnabled<ExportsOptions>\n css?: CssOptions\n publicDir?: CopyOptions | CopyOptionsFn\n copy?: CopyOptions | CopyOptionsFn\n hooks?: Partial<TsdownHooks> | ((_: Hookable<TsdownHooks>) => Awaitable<void>)\n workspace?: Workspace | Arrayable<string> | true\n}",
6969
"UserConfigExport": "type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>",
7070
"UserConfigFn": "type UserConfigFn = (_: InlineConfig, _: { ci: boolean }) => Awaitable<Arrayable<UserConfig>>",
7171
"WithEnabled": "type WithEnabled<T> = boolean | undefined | CIOption | (T & { enabled?: boolean | CIOption })",
@@ -84,7 +84,7 @@
8484
"CopyOptions",
8585
"CopyOptionsFn",
8686
"CssOptions",
87-
"DebugOptions",
87+
"DevtoolsOptions",
8888
"DtsOptions",
8989
"ExportsOptions",
9090
"Format",

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cli
2929
.option('--clean', 'Clean output directory, --no-clean to disable')
3030
.option('--external <module>', 'Mark dependencies as external')
3131
.option('--minify', 'Minify output')
32-
.option('--debug', 'Enable debug mode')
32+
.option('--devtools', 'Enable devtools integration')
3333
.option('--debug-logs [feat]', 'Show debug logs')
3434
.option('--target <target>', 'Bundle target, e.g "es2015", "esnext"')
3535
.option('-l, --logLevel <level>', 'Set log level: info, warn, error, silent')

src/config/options.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function resolveUserConfig(
8585
inlineOnly,
8686
css,
8787
fixedExtension = platform === 'node',
88-
debug = false,
88+
devtools = false,
8989
write = true,
9090
} = userConfig
9191

@@ -236,15 +236,15 @@ export async function resolveUserConfig(
236236
inlineOnly = toArray(inlineOnly)
237237
}
238238

239-
debug = resolveFeatureOption(debug, {})
240-
if (debug) {
239+
devtools = resolveFeatureOption(devtools, {})
240+
if (devtools) {
241241
if (watch) {
242-
if (debug.devtools) {
243-
logger.warn('Devtools is not supported in watch mode, disabling it.')
242+
if (devtools.ui) {
243+
logger.warn('Devtools UI is not supported in watch mode, disabling it.')
244244
}
245-
debug.devtools = false
245+
devtools.ui = false
246246
} else {
247-
debug.devtools ??= !!pkgExists('@vitejs/devtools/cli')
247+
devtools.ui ??= !!pkgExists('@vitejs/devtools/cli')
248248
}
249249
}
250250

@@ -258,7 +258,7 @@ export async function resolveUserConfig(
258258
copy: publicDir || copy,
259259
css: resolveCssOptions(css),
260260
cwd,
261-
debug,
261+
devtools,
262262
dts,
263263
entry: resolvedEntry,
264264
env,

src/config/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CopyEntry, CopyOptions, CopyOptionsFn } from '../features/copy.ts'
22
import type { CssOptions } from '../features/css.ts'
3-
import type { DebugOptions } from '../features/debug.ts'
3+
import type { DevtoolsOptions } from '../features/devtools.ts'
44
import type {
55
BuildContext,
66
RolldownContext,
@@ -77,7 +77,7 @@ export type {
7777
CopyOptions,
7878
CopyOptionsFn,
7979
CssOptions,
80-
DebugOptions,
80+
DevtoolsOptions,
8181
DtsOptions,
8282
ExportsOptions,
8383
OutExtensionContext,
@@ -437,15 +437,15 @@ export interface UserConfig {
437437
ignoreWatch?: Arrayable<string | RegExp>
438438

439439
/**
440-
* **[experimental]** Enable debug mode.
440+
* **[experimental]** Enable devtools.
441441
*
442-
* Both debug mode and Vite DevTools are still under development, and this is for early testers only.
442+
*DevTools is still under development, and this is for early testers only.
443443
*
444444
* This may slow down the build process significantly.
445445
*
446446
* @default false
447447
*/
448-
debug?: WithEnabled<DebugOptions>
448+
devtools?: WithEnabled<DevtoolsOptions>
449449

450450
//#region Addons
451451

@@ -621,7 +621,7 @@ export type ResolvedConfig = Overwrite<
621621
report: false | ReportOptions
622622
tsconfig: false | string
623623
exports: false | ExportsOptions
624-
debug: false | DebugOptions
624+
devtools: false | DevtoolsOptions
625625
publint: false | PublintOptions
626626
attw: false | AttwOptions
627627
unused: false | UnusedOptions

src/features/clean.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export async function cleanOutDir(configs: ResolvedConfig[]): Promise<void> {
1515
const removes = new Set<string>()
1616

1717
for (const config of configs) {
18-
if (config.debug && (config.debug.clean ?? true)) {
19-
config.clean.push('.rolldown')
18+
if (config.devtools && (config.devtools.clean ?? true)) {
19+
config.clean.push('node_modules/.rolldown')
2020
}
2121

2222
if (!config.clean.length) continue

src/features/debug.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
import { createDebug, enable, namespaces } from 'obug'
22
import { resolveComma, toArray } from '../utils/general.ts'
3-
import type { StartOptions } from '@vitejs/devtools/cli-commands'
4-
import type { InputOptions } from 'rolldown'
53

64
const debug = createDebug('tsdown:debug')
75

8-
export interface DebugOptions extends NonNullable<InputOptions['debug']> {
9-
/**
10-
* **[experimental]** Enable devtools integration. `@vitejs/devtools` must be installed as a dependency.
11-
*
12-
* Defaults to true, if `@vitejs/devtools` is installed.
13-
*/
14-
devtools?: boolean | Partial<StartOptions>
15-
16-
/**
17-
* Clean devtools stale sessions.
18-
*
19-
* @default true
20-
*/
21-
clean?: boolean
22-
}
23-
246
export function enableDebugLog(cliOptions: Record<string, any>): void {
257
const { debugLogs } = cliOptions
268
if (!debugLogs) return

src/features/devtools.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { importWithError } from '../utils/general.ts'
2+
import type { StartOptions } from '@vitejs/devtools/cli-commands'
3+
import type { InputOptions } from 'rolldown'
4+
5+
export interface DevtoolsOptions extends NonNullable<InputOptions['devtools']> {
6+
/**
7+
* **[experimental]** Enable devtools integration. `@vitejs/devtools` must be installed as a dependency.
8+
*
9+
* Defaults to true, if `@vitejs/devtools` is installed.
10+
*/
11+
ui?: boolean | Partial<StartOptions>
12+
13+
/**
14+
* Clean devtools stale sessions.
15+
*
16+
* @default true
17+
*/
18+
clean?: boolean
19+
}
20+
21+
export async function startDevtoolsUI(config: DevtoolsOptions): Promise<void> {
22+
const { start } = await importWithError<
23+
typeof import('@vitejs/devtools/cli-commands')
24+
>('@vitejs/devtools/cli-commands')
25+
await start({
26+
host: '127.0.0.1',
27+
open: true,
28+
...(typeof config.ui === 'object' ? config.ui : {}),
29+
})
30+
}

src/features/rolldown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function resolveInputOptions(
8585
alias,
8686
cjsDefault,
8787
cwd,
88-
debug,
88+
devtools,
8989
dts,
9090
entry,
9191
env,
@@ -217,7 +217,7 @@ async function resolveInputOptions(
217217
defaultHandler(level, log)
218218
}
219219
: undefined,
220-
debug: debug || undefined,
220+
devtools: devtools || undefined,
221221
checks: {
222222
pluginTimings: false,
223223
},

src/index.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {
1010
} from 'rolldown'
1111
import {
1212
resolveConfig,
13-
type DebugOptions,
1413
type InlineConfig,
1514
type ResolvedConfig,
1615
} from './config/index.ts'
1716
import { warnLegacyCJS } from './features/cjs.ts'
1817
import { cleanChunks, cleanOutDir } from './features/clean.ts'
1918
import { copy } from './features/copy.ts'
19+
import { startDevtoolsUI } from './features/devtools.ts'
2020
import { createHooks, executeOnSuccess } from './features/hooks.ts'
2121
import { bundleDone, initBundleByPkg } from './features/pkg/index.ts'
2222
import {
@@ -31,7 +31,7 @@ import {
3131
type RolldownChunk,
3232
type TsdownBundle,
3333
} from './utils/chunks.ts'
34-
import { importWithError } from './utils/general.ts'
34+
import { typeAssert } from './utils/general.ts'
3535
import { globalLogger } from './utils/logger.ts'
3636

3737
const asyncDispose: typeof Symbol.asyncDispose =
@@ -88,7 +88,7 @@ export async function build(
8888
)
8989

9090
const firstDevtoolsConfig = configs.find(
91-
(config) => config.debug && config.debug.devtools,
91+
(config) => config.devtools && config.devtools.ui,
9292
)
9393

9494
const hasWatchConfig = configs.some((config) => config.watch)
@@ -99,17 +99,9 @@ export async function build(
9999
disposeCbs.push(bundle[asyncDispose])
100100
}
101101
} else if (firstDevtoolsConfig) {
102+
typeAssert(firstDevtoolsConfig.devtools)
102103
// build done, start devtools
103-
const { start } = await importWithError<
104-
typeof import('@vitejs/devtools/cli-commands')
105-
>('@vitejs/devtools/cli-commands')
106-
107-
const devtoolsOptions = (firstDevtoolsConfig.debug as DebugOptions).devtools
108-
await start({
109-
host: '127.0.0.1',
110-
open: true,
111-
...(typeof devtoolsOptions === 'object' ? devtoolsOptions : {}),
112-
})
104+
startDevtoolsUI(firstDevtoolsConfig.devtools)
113105
}
114106

115107
return bundles

src/utils/general.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import picomatch from 'picomatch'
21
import { pathToFileURL } from 'node:url'
2+
import picomatch from 'picomatch'
33

44
export function toArray<T>(
55
val: T | T[] | null | undefined,

0 commit comments

Comments
 (0)