Skip to content

Commit 7616960

Browse files
committed
feat(config): pass root config to workspace config functions
Allow workspace config functions to access the root config via the `rootConfig` property in the UserConfigFn context parameter.
1 parent a4da6af commit 7616960

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

dts.snapshot.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"TsdownInputOption": "type TsdownInputOption = Arrayable<string | Record<string, Arrayable<string>>>",
165165
"UserConfig": "interface UserConfig {\n entry?: TsdownInputOption\n deps?: DepsConfig\n external?: ExternalOption\n noExternal?: Arrayable<string | RegExp> | NoExternalFn\n inlineOnly?: Arrayable<string | RegExp> | false\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 checks?: ChecksOptions & { legacyCjs?: 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 root?: string\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 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?: _tsdown_css0.CssOptions\n injectStyle?: boolean\n publicDir?: CopyOptions | CopyOptionsFn\n copy?: CopyOptions | CopyOptionsFn\n hooks?: Partial<TsdownHooks> | ((_: Hookable<TsdownHooks>) => Awaitable<void>)\n exe?: WithEnabled<ExeOptions>\n workspace?: Workspace | Arrayable<string> | true\n}",
166166
"UserConfigExport": "type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>",
167-
"UserConfigFn": "type UserConfigFn = (_: InlineConfig, _: { ci: boolean }) => Awaitable<Arrayable<UserConfig>>",
167+
"UserConfigFn": "type UserConfigFn = (_: InlineConfig, _: { ci: boolean; rootConfig?: UserConfig }) => Awaitable<Arrayable<UserConfig>>",
168168
"WithEnabled": "type WithEnabled<T> = boolean | undefined | CIOption | (T & { enabled?: boolean | CIOption })",
169169
"Workspace": "interface Workspace {\n include?: Arrayable<string> | 'auto'\n exclude?: Arrayable<string>\n config?: boolean | string\n}"
170170
}

src/config/file.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const configPrefix = 'tsdown.config'
5757
export async function loadConfigFile(
5858
inlineConfig: InlineConfig,
5959
workspace?: string,
60+
rootConfig?: UserConfig,
6061
): Promise<{
6162
configs: UserConfig[]
6263
file?: string
@@ -119,7 +120,7 @@ export async function loadConfigFile(
119120

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

src/config/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ export interface InlineConfig extends UserConfig {
619619

620620
export type UserConfigFn = (
621621
inlineConfig: InlineConfig,
622-
context: { ci: boolean },
622+
context: { ci: boolean; rootConfig?: UserConfig },
623623
) => Awaitable<Arrayable<UserConfig>>
624624

625625
export type UserConfigExport = Awaitable<Arrayable<UserConfig> | UserConfigFn>

src/config/workspace.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function resolveWorkspace(
1919
config: UserConfig,
2020
inlineConfig: InlineConfig,
2121
): Promise<{ configs: UserConfig[]; files?: string[] }> {
22-
const normalized = { ...config, ...inlineConfig }
22+
const normalized: UserConfig = { ...config, ...inlineConfig }
2323
const rootCwd = normalized.cwd || process.cwd()
2424

2525
let { workspace } = normalized
@@ -74,6 +74,7 @@ export async function resolveWorkspace(
7474
cwd,
7575
},
7676
cwd,
77+
normalized,
7778
)
7879
if (file) {
7980
debug('loaded workspace config file %s', file)

0 commit comments

Comments
 (0)