Skip to content

Commit d77bb9c

Browse files
chore(config): move stx.config.ts to config/stx.ts
Relocate to the conventional config/ directory; stx resolves config/stx.ts via bunfig (it searches ./config), so config loading is unchanged. Fix up imageoptim's relative imports for the deeper path. Also extend story findConfigFile() to search config/ and .config/ (matching bunfig's resolution order) so the dev/story config-change watcher keeps working after configs move out of the project root. getConfigModifiedTime() benefits via findConfigFile(). Adds a unit test covering root and config/ resolution.
1 parent 41b7110 commit d77bb9c

5 files changed

Lines changed: 76 additions & 2 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* repo root — no custom server bootstrap needed.
88
*/
99

10-
import type { StxConfig } from '../../packages/stx/src/types'
11-
import { optimize } from './optimize'
10+
import type { StxConfig } from '../../../packages/stx/src/types'
11+
import { optimize } from '../optimize'
1212

1313
/** Hard cap so a runaway upload can't OOM the dev server. */
1414
const MAX_UPLOAD_BYTES = 256 * 1024 * 1024 // 256 MB

packages/stx/src/story/config-watcher.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,19 @@ export function watchConfigFile(
9292
* Get the config file path if it exists
9393
*/
9494
export function findConfigFile(root: string): string | null {
95+
// Mirror bunfig's resolution order: root first (back-compat with the
96+
// historical `stx.config.*` location), then the `config/` and `.config/`
97+
// directories where `stx.ts` now conventionally lives.
9598
const configPaths = [
9699
path.join(root, 'stx.config.ts'),
97100
path.join(root, 'stx.config.js'),
98101
path.join(root, 'stx.config.mjs'),
102+
path.join(root, 'config', 'stx.ts'),
103+
path.join(root, 'config', 'stx.js'),
104+
path.join(root, 'config', 'stx.mjs'),
105+
path.join(root, '.config', 'stx.ts'),
106+
path.join(root, '.config', 'stx.js'),
107+
path.join(root, '.config', 'stx.mjs'),
99108
]
100109

101110
for (const configPath of configPaths) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Tests for story config-watcher config resolution
3+
*/
4+
5+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
6+
import fs from 'node:fs'
7+
import os from 'node:os'
8+
import path from 'node:path'
9+
import { findConfigFile, getConfigModifiedTime } from '../../src/story/config-watcher'
10+
11+
describe('findConfigFile', () => {
12+
let tmpRoot: string
13+
14+
beforeEach(() => {
15+
tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'stx-config-watcher-'))
16+
})
17+
18+
afterEach(() => {
19+
fs.rmSync(tmpRoot, { recursive: true, force: true })
20+
})
21+
22+
test('returns null when no config exists', () => {
23+
expect(findConfigFile(tmpRoot)).toBeNull()
24+
})
25+
26+
test('resolves a root stx.config.ts (back-compat)', () => {
27+
const configPath = path.join(tmpRoot, 'stx.config.ts')
28+
fs.writeFileSync(configPath, 'export default {}\n')
29+
30+
expect(findConfigFile(tmpRoot)).toBe(configPath)
31+
})
32+
33+
test('resolves a config/stx.ts after the config moved into config/', () => {
34+
fs.mkdirSync(path.join(tmpRoot, 'config'))
35+
const configPath = path.join(tmpRoot, 'config', 'stx.ts')
36+
fs.writeFileSync(configPath, 'export default {}\n')
37+
38+
expect(findConfigFile(tmpRoot)).toBe(configPath)
39+
})
40+
41+
test('resolves a .config/stx.ts', () => {
42+
fs.mkdirSync(path.join(tmpRoot, '.config'))
43+
const configPath = path.join(tmpRoot, '.config', 'stx.ts')
44+
fs.writeFileSync(configPath, 'export default {}\n')
45+
46+
expect(findConfigFile(tmpRoot)).toBe(configPath)
47+
})
48+
49+
test('prefers a root stx.config.ts over config/stx.ts when both exist', () => {
50+
const rootPath = path.join(tmpRoot, 'stx.config.ts')
51+
fs.writeFileSync(rootPath, 'export default {}\n')
52+
fs.mkdirSync(path.join(tmpRoot, 'config'))
53+
fs.writeFileSync(path.join(tmpRoot, 'config', 'stx.ts'), 'export default {}\n')
54+
55+
expect(findConfigFile(tmpRoot)).toBe(rootPath)
56+
})
57+
58+
test('getConfigModifiedTime resolves via config/stx.ts', async () => {
59+
fs.mkdirSync(path.join(tmpRoot, 'config'))
60+
fs.writeFileSync(path.join(tmpRoot, 'config', 'stx.ts'), 'export default {}\n')
61+
62+
const mtime = await getConfigModifiedTime(tmpRoot)
63+
expect(typeof mtime).toBe('number')
64+
})
65+
})

0 commit comments

Comments
 (0)