FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: reload when workspace config changed · rolldown/tsdown@68b3056 · GitHub

Commit 68b3056

Browse files
committed
fix: reload when workspace config changed
1 parent 91ed530 commit 68b3056

3 files changed

Lines changed: 42 additions & 28 deletions

File tree

‎src/features/watch.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { logger } from '../utils/logger'
44
import type { ResolvedOptions } from '../options'
55
import type { FSWatcher } from 'chokidar'
66

7-
const endsWithPackageJson = /[\\/]package\.json$/
7+
const endsWithConfig = /[\\/](?:package\.json|tsdown\.config.*)$/
88

99
export async function watchBuild(
1010
options: ResolvedOptions,
11-
configFile: string | undefined,
11+
configFiles: string[],
1212
rebuild: () => void,
1313
restart: () => void,
1414
): Promise<FSWatcher> {
@@ -24,7 +24,7 @@ export async function watchBuild(
2424
typeof options.watch === 'boolean' ? options.cwd : options.watch,
2525
)
2626
logger.info(`Watching for changes in ${files.join(', ')}`)
27-
if (configFile) files.push(configFile)
27+
files.push(...configFiles)
2828

2929
const { watch } = await import('chokidar')
3030
const debouncedRebuild = debounce(rebuild, 100)
@@ -36,7 +36,7 @@ export async function watchBuild(
3636
})
3737

3838
watcher.on('all', (type: string, file: string) => {
39-
if (endsWithPackageJson.test(file) || configFile === file) {
39+
if (configFiles.includes(file) || endsWithConfig.test(file)) {
4040
logger.info(`Reload config: ${file}`)
4141
restart()
4242
return

‎src/index.ts‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import { ShebangPlugin } from './plugins'
3434
import { logger, prettyName } from './utils/logger'
3535
import type { Options as DtsOptions } from 'rolldown-plugin-dts'
3636

37-
const debug = Debug('tsdown:main')
38-
3937
/**
4038
* Build with tsdown.
4139
*/
@@ -44,16 +42,7 @@ export async function build(userOptions: Options = {}): Promise<void> {
4442
logger.setSilent(userOptions.silent)
4543
}
4644

47-
debug('Loading config')
48-
const { configs, file: configFile } = await resolveOptions(userOptions)
49-
if (configFile) {
50-
debug('Loaded config:', configFile)
51-
configs.forEach((config) => {
52-
debug('using resolved config: %O', config)
53-
})
54-
} else {
55-
debug('No config file found')
56-
}
45+
const { configs, files: configFiles } = await resolveOptions(userOptions)
5746

5847
let cleanPromise: Promise<void> | undefined
5948
const clean = () => {
@@ -71,7 +60,7 @@ export async function build(userOptions: Options = {}): Promise<void> {
7160
const rebuild = rebuilds[i]
7261
if (!rebuild) continue
7362

74-
const watcher = await watchBuild(config, configFile, rebuild, restart)
63+
const watcher = await watchBuild(config, configFiles, rebuild, restart)
7564
cleanCbs.push(() => watcher.close())
7665
}
7766

‎src/options/index.ts‎

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,36 +365,47 @@ export type ResolvedOptions = Omit<
365365

366366
export async function resolveOptions(options: Options): Promise<{
367367
configs: ResolvedOptions[]
368-
file?: string
368+
files: string[]
369369
}> {
370+
const files: string[] = []
371+
372+
debug('options %O', options)
373+
debug('loading config file: %s', options.config)
370374
const { configs: rootConfigs, file } = await loadConfigFile(options)
371375
if (file) {
372-
debug('Loaded config file %s', file)
373-
debug('Root configs %o', rootConfigs)
376+
files.push(file)
377+
debug('loaded root config file %s', file)
378+
debug('root configs %o', rootConfigs)
379+
} else {
380+
debug('no root config file found')
374381
}
375382

376383
const configs = (
377384
await Promise.all(
378385
rootConfigs.map(async (rootConfig) => {
379-
const workspaceConfigs = await resolveWorkspace(rootConfig, options)
386+
const { configs: workspaceConfigs, files: workspaceFiles } =
387+
await resolveWorkspace(rootConfig, options)
388+
if (workspaceFiles) {
389+
files.push(...workspaceFiles)
390+
}
380391
return Promise.all(
381392
workspaceConfigs.map((config) => resolveConfig(config)),
382393
)
383394
}),
384395
)
385396
).flat()
386-
debug('Resolved configs %O', configs)
387-
return { configs, file }
397+
debug('resolved configs %O', configs)
398+
return { configs, files }
388399
}
389400

390401
async function resolveWorkspace(
391402
config: NormalizedUserConfig,
392403
options: Options,
393-
): Promise<NormalizedUserConfig[]> {
404+
): Promise<{ configs: NormalizedUserConfig[]; files?: string[] }> {
394405
const normalized = { ...config, ...options }
395406
const rootCwd = normalized.cwd || process.cwd()
396407
let { workspace } = normalized
397-
if (!workspace) return [normalized]
408+
if (!workspace) return { configs: [normalized], files: [] }
398409

399410
if (workspace === true) {
400411
workspace = {}
@@ -454,23 +465,37 @@ async function resolveWorkspace(
454465
}
455466
}
456467

468+
const files: string[] = []
457469
const configs = (
458470
await Promise.all(
459471
packages.map(async (cwd) => {
460-
const { configs } = await loadConfigFile(
472+
debug('loading workspace config %s', cwd)
473+
const { configs, file } = await loadConfigFile(
461474
{
462475
...options,
463476
config: workspaceConfig,
464477
cwd,
465478
},
466479
cwd,
467480
)
468-
return configs.map((config) => ({ ...normalized, cwd, ...config }))
481+
if (file) {
482+
debug('loaded workspace config file %s', file)
483+
files.push(file)
484+
} else {
485+
debug('no workspace config file found in %s', cwd)
486+
}
487+
return configs.map(
488+
(config): NormalizedUserConfig => ({
489+
...normalized,
490+
cwd,
491+
...config,
492+
}),
493+
)
469494
}),
470495
)
471496
).flat()
472497

473-
return configs
498+
return { configs, files }
474499
}
475500

476501
async function resolveConfig(

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL