| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,11 +4,11 @@ import { logger } from '../utils/logger' | |||
| 4 | 4 | import type { ResolvedOptions } from '../options' | |
| 5 | 5 | import type { FSWatcher } from 'chokidar' | |
| 6 | 6 | ||
| 7 | - const endsWithPackageJson = /[\\/]package\.json$/ | ||
| 7 | + const endsWithConfig = /[\\/](?:package\.json|tsdown\.config.*)$/ | ||
| 8 | 8 | ||
| 9 | 9 | export async function watchBuild( | |
| 10 | 10 | options: ResolvedOptions, | |
| 11 | - configFile: string | undefined, | ||
| 11 | + configFiles: string[], | ||
| 12 | 12 | rebuild: () => void, | |
| 13 | 13 | restart: () => void, | |
| 14 | 14 | ): Promise<FSWatcher> { | |
@@ -24,7 +24,7 @@ export async function watchBuild( | |||
| 24 | 24 | typeof options.watch === 'boolean' ? options.cwd : options.watch, | |
| 25 | 25 | ) | |
| 26 | 26 | logger.info(`Watching for changes in ${files.join(', ')}`) | |
| 27 | - if (configFile) files.push(configFile) | ||
| 27 | + files.push(...configFiles) | ||
| 28 | 28 | ||
| 29 | 29 | const { watch } = await import('chokidar') | |
| 30 | 30 | const debouncedRebuild = debounce(rebuild, 100) | |
@@ -36,7 +36,7 @@ export async function watchBuild( | |||
| 36 | 36 | }) | |
| 37 | 37 | ||
| 38 | 38 | watcher.on('all', (type: string, file: string) => { | |
| 39 | - if (endsWithPackageJson.test(file) || configFile === file) { | ||
| 39 | + if (configFiles.includes(file) || endsWithConfig.test(file)) { | ||
| 40 | 40 | logger.info(`Reload config: ${file}`) | |
| 41 | 41 | restart() | |
| 42 | 42 | return | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,8 +34,6 @@ import { ShebangPlugin } from './plugins' | |||
| 34 | 34 | import { logger, prettyName } from './utils/logger' | |
| 35 | 35 | import type { Options as DtsOptions } from 'rolldown-plugin-dts' | |
| 36 | 36 | ||
| 37 | - const debug = Debug('tsdown:main') | ||
| 38 | - | ||
| 39 | 37 | /** | |
| 40 | 38 | * Build with tsdown. | |
| 41 | 39 | */ | |
@@ -44,16 +42,7 @@ export async function build(userOptions: Options = {}): Promise<void> { | |||
| 44 | 42 | logger.setSilent(userOptions.silent) | |
| 45 | 43 | } | |
| 46 | 44 | ||
| 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) | ||
| 57 | 46 | ||
| 58 | 47 | let cleanPromise: Promise<void> | undefined | |
| 59 | 48 | const clean = () => { | |
@@ -71,7 +60,7 @@ export async function build(userOptions: Options = {}): Promise<void> { | |||
| 71 | 60 | const rebuild = rebuilds[i] | |
| 72 | 61 | if (!rebuild) continue | |
| 73 | 62 | ||
| 74 | - const watcher = await watchBuild(config, configFile, rebuild, restart) | ||
| 63 | + const watcher = await watchBuild(config, configFiles, rebuild, restart) | ||
| 75 | 64 | cleanCbs.push(() => watcher.close()) | |
| 76 | 65 | } | |
| 77 | 66 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -365,36 +365,47 @@ export type ResolvedOptions = Omit< | |||
| 365 | 365 | ||
| 366 | 366 | export async function resolveOptions(options: Options): Promise<{ | |
| 367 | 367 | configs: ResolvedOptions[] | |
| 368 | - file?: string | ||
| 368 | + files: string[] | ||
| 369 | 369 | }> { | |
| 370 | + const files: string[] = [] | ||
| 371 | + | ||
| 372 | + debug('options %O', options) | ||
| 373 | + debug('loading config file: %s', options.config) | ||
| 370 | 374 | const { configs: rootConfigs, file } = await loadConfigFile(options) | |
| 371 | 375 | 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') | ||
| 374 | 381 | } | |
| 375 | 382 | ||
| 376 | 383 | const configs = ( | |
| 377 | 384 | await Promise.all( | |
| 378 | 385 | 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 | + } | ||
| 380 | 391 | return Promise.all( | |
| 381 | 392 | workspaceConfigs.map((config) => resolveConfig(config)), | |
| 382 | 393 | ) | |
| 383 | 394 | }), | |
| 384 | 395 | ) | |
| 385 | 396 | ).flat() | |
| 386 | - debug('Resolved configs %O', configs) | ||
| 387 | - return { configs, file } | ||
| 397 | + debug('resolved configs %O', configs) | ||
| 398 | + return { configs, files } | ||
| 388 | 399 | } | |
| 389 | 400 | ||
| 390 | 401 | async function resolveWorkspace( | |
| 391 | 402 | config: NormalizedUserConfig, | |
| 392 | 403 | options: Options, | |
| 393 | - ): Promise<NormalizedUserConfig[]> { | ||
| 404 | + ): Promise<{ configs: NormalizedUserConfig[]; files?: string[] }> { | ||
| 394 | 405 | const normalized = { ...config, ...options } | |
| 395 | 406 | const rootCwd = normalized.cwd || process.cwd() | |
| 396 | 407 | let { workspace } = normalized | |
| 397 | - if (!workspace) return [normalized] | ||
| 408 | + if (!workspace) return { configs: [normalized], files: [] } | ||
| 398 | 409 | ||
| 399 | 410 | if (workspace === true) { | |
| 400 | 411 | workspace = {} | |
@@ -454,23 +465,37 @@ async function resolveWorkspace( | |||
| 454 | 465 | } | |
| 455 | 466 | } | |
| 456 | 467 | ||
| 468 | + const files: string[] = [] | ||
| 457 | 469 | const configs = ( | |
| 458 | 470 | await Promise.all( | |
| 459 | 471 | packages.map(async (cwd) => { | |
| 460 | - const { configs } = await loadConfigFile( | ||
| 472 | + debug('loading workspace config %s', cwd) | ||
| 473 | + const { configs, file } = await loadConfigFile( | ||
| 461 | 474 | { | |
| 462 | 475 | ...options, | |
| 463 | 476 | config: workspaceConfig, | |
| 464 | 477 | cwd, | |
| 465 | 478 | }, | |
| 466 | 479 | cwd, | |
| 467 | 480 | ) | |
| 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 | + ) | ||
| 469 | 494 | }), | |
| 470 | 495 | ) | |
| 471 | 496 | ).flat() | |
| 472 | 497 | ||
| 473 | - return configs | ||
| 498 | + return { configs, files } | ||
| 474 | 499 | } | |
| 475 | 500 | ||
| 476 | 501 | async function resolveConfig( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments