Skip to content

Commit 3d5237c

Browse files
authored
feat!: rename Dir to Fs.Builder and consolidate into fs module (#104)
* feat!: rename Dir to Fs.Builder and consolidate into fs module Move the Dir module into the Fs namespace as Fs.Builder, following the same pattern as Fs.Memory consolidation. This better reflects what the module does (builds filesystem layouts) and groups it with related Fs functionality. BREAKING CHANGE: Dir namespace renamed to Fs.Builder - import { Dir } from '@wollybeard/kit' → import { Fs } from '@wollybeard/kit' - Dir.spec() → Fs.Builder.spec() - Dir.Layout → Fs.Builder.Layout Closes #102 * fix: resolve circular dependency in builder module Replace `#fs` imports with relative imports to fix layered import architecture violations in the builder module files.
1 parent 4926194 commit 3d5237c

File tree

17 files changed

+271
-274
lines changed

17 files changed

+271
-274
lines changed

docs/api/paka/extractor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Pure extraction function that processes files without I/O. Takes all files as in
4040
import { Paka } from '@wollybeard/kit/paka'
4141
// ---cut---
4242
// [!code word:spec:1]
43-
const layout = Dir.spec('/')
43+
const layout = Fs.Builder.spec('/')
4444
.add('package.json', { name: 'x', exports: { './foo': './build/foo/$.js' } })
4545
.add('src/foo/$.ts', 'export const bar = () => {}')
4646
.toLayout()

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
"#codec/codec": "./build/utils/codec/__.js",
4141
"#url": "./build/domains/url/_.js",
4242
"#url/url": "./build/domains/url/__.js",
43-
"#dir": "./build/utils/dir/_.js",
44-
"#dir/dir": "./build/utils/dir/__.js",
4543
"#fn": "./build/domains/fn/_.js",
4644
"#fn/fn": "./build/domains/fn/__.js",
4745
"#fn/core": "./build/domains/fn/core/_.js",
@@ -167,7 +165,6 @@
167165
"./cli": "./build/utils/cli/__.js",
168166
"./codec": "./build/utils/codec/__.js",
169167
"./color": "./build/domains/color/__.js",
170-
"./dir": "./build/utils/dir/__.js",
171168
"./err": "./build/utils/err/__.js",
172169
"./fn": "./build/domains/fn/__.js",
173170
"./fs": "./build/utils/fs/__.js",

src/exports/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export * from '#cli'
2525
export * from '#codec'
2626
export * from '#config-manager'
2727
export * from '#configurator'
28-
export * from '#dir'
2928
export * from '#err'
3029
export * from '#fs'
3130
export * from '#html'

src/utils/dir/_.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/utils/dir/dir.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/utils/fs/__.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
* @module
1616
*/
17+
export * as Builder from './builder/__.js'
1718
export * from './filesystem.js'
1819
export * from './fs.js'
1920
export * from './glob.js'

src/utils/dir/_.test.ts renamed to src/utils/fs/builder/_.test.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Fs } from '#fs'
22
import { FileSystem } from '@effect/platform'
33
import { Effect, Schema as S } from 'effect'
44
import { describe, expect, it } from 'vitest'
5-
import { Dir } from './_.js'
5+
import { Builder } from './_.js'
66

77
// Local helper function for decoding
88
const decodeAbsDir = S.decodeSync(Fs.Path.AbsDir.Schema)
99

10-
describe('Dir', () => {
10+
describe('Builder', () => {
1111
describe('chaining API', () => {
1212
it('creates files and directories', async () => {
1313
// Setup memory filesystem
@@ -17,9 +17,9 @@ describe('Dir', () => {
1717
const fs = yield* FileSystem.FileSystem
1818

1919
// Create a directory with chaining
20-
const dir = Dir.withChaining(Dir.create('/test'))
20+
const builder = Builder.withChaining(Builder.create('/test'))
2121

22-
yield* dir
22+
yield* builder
2323
.file('README.md', '# Test Project')
2424
.file('package.json', { name: 'test', version: '1.0.0' })
2525
.dir('src/', _ =>
@@ -64,9 +64,9 @@ describe('Dir', () => {
6464
const isDev = true
6565
const isProd = false
6666

67-
const dir = Dir.withChaining(Dir.create('/app'))
67+
const builder = Builder.withChaining(Builder.create('/app'))
6868

69-
yield* dir
69+
yield* builder
7070
.file('app.js', 'console.log("app")')
7171
.when(isDev, _ =>
7272
_
@@ -104,9 +104,9 @@ describe('Dir', () => {
104104
const program = Effect.gen(function*() {
105105
const fs = yield* FileSystem.FileSystem
106106

107-
const dir = Dir.withChaining(Dir.create('/workspace'))
107+
const builder = Builder.withChaining(Builder.create('/workspace'))
108108

109-
yield* dir
109+
yield* builder
110110
.remove('old.txt')
111111
.clear('cache/')
112112
.file('new.txt', 'new content')
@@ -149,9 +149,9 @@ describe('Dir', () => {
149149
const program = Effect.gen(function*() {
150150
const fs = yield* FileSystem.FileSystem
151151

152-
const dir = Dir.withChaining(Dir.create('/project'))
152+
const builder = Builder.withChaining(Builder.create('/project'))
153153

154-
yield* dir
154+
yield* builder
155155
.move('draft.md', 'README.md')
156156
.move('old-name.txt', 'new-name.txt')
157157
.commit()
@@ -181,12 +181,12 @@ describe('Dir', () => {
181181
const program = Effect.gen(function*() {
182182
const fs = yield* FileSystem.FileSystem
183183

184-
const dir = Dir.withChaining(Dir.create('/data'))
184+
const builder = Builder.withChaining(Builder.create('/data'))
185185

186186
const uint8Array = new Uint8Array([0, 1, 2, 3, 4])
187187
const buffer = Buffer.from([5, 6, 7, 8, 9])
188188

189-
yield* dir
189+
yield* builder
190190
.file('data1.bin', uint8Array)
191191
.file('data2.bin', buffer)
192192
.commit()
@@ -212,9 +212,9 @@ describe('Dir', () => {
212212
const program = Effect.gen(function*() {
213213
const fs = yield* FileSystem.FileSystem
214214

215-
const dir = Dir.withChaining(Dir.create('/app'))
215+
const builder = Builder.withChaining(Builder.create('/app'))
216216

217-
yield* dir
217+
yield* builder
218218
.dir('src/', _ =>
219219
_
220220
.file('index.ts', 'export {}')
@@ -244,21 +244,21 @@ describe('Dir', () => {
244244
})
245245

246246
describe('create functions', () => {
247-
it('creates a Dir with absolute path', () => {
248-
const dir = Dir.create('/absolute/path')
249-
expect(dir.base.segments).toEqual(['absolute', 'path'])
247+
it('creates a Builder with absolute path', () => {
248+
const builder = Builder.create('/absolute/path')
249+
expect(builder.base.segments).toEqual(['absolute', 'path'])
250250
})
251251

252-
it('creates a Dir with Fs.Path.AbsDir', () => {
252+
it('creates a Builder with Fs.Path.AbsDir', () => {
253253
const absDir = decodeAbsDir('/test/')
254-
const dir = Dir.create(absDir)
255-
expect(dir.base).toBe(absDir)
254+
const builder = Builder.create(absDir)
255+
expect(builder.base).toBe(absDir)
256256
})
257257
})
258258

259-
describe('DirSpec', () => {
259+
describe('SpecBuilder', () => {
260260
it('creates a spec with operations', () => {
261-
const spec = Dir.spec('/test')
261+
const spec = Builder.spec('/test')
262262
.file('README.md', '# Test')
263263
.dir('src/', _ => _.file('index.ts', 'export {}'))
264264

@@ -277,7 +277,7 @@ describe('Dir', () => {
277277
const isDev = true
278278
const isProd = false
279279

280-
const spec = Dir.spec('/app')
280+
const spec = Builder.spec('/app')
281281
.file('main.ts', 'console.log("main")')
282282
.when(isDev, _ => _.file('env.txt', 'DEBUG=true'))
283283
.unless(isProd, _ => _.file('dev.config.js', '{}'))
@@ -293,7 +293,7 @@ describe('Dir', () => {
293293
})
294294

295295
it('supports withBase to change base directory', () => {
296-
const spec1 = Dir.spec('/project1')
296+
const spec1 = Builder.spec('/project1')
297297
.file('test.txt', 'content')
298298

299299
const spec2 = spec1.withBase('/project2')
@@ -304,13 +304,13 @@ describe('Dir', () => {
304304
})
305305

306306
it('supports merge to combine specs', () => {
307-
const spec1 = Dir.spec('/test')
307+
const spec1 = Builder.spec('/test')
308308
.file('a.txt', 'A')
309309

310-
const spec2 = Dir.spec('/test')
310+
const spec2 = Builder.spec('/test')
311311
.file('b.txt', 'B')
312312

313-
const spec3 = Dir.spec('/test')
313+
const spec3 = Builder.spec('/test')
314314
.file('c.txt', 'C')
315315

316316
const merged = spec1.merge(spec2, spec3)
@@ -343,16 +343,16 @@ describe('Dir', () => {
343343
const memoryFs = Fs.Memory.layer({})
344344

345345
// Create a spec
346-
const spec = Dir.spec('/test')
346+
const spec = Builder.spec('/test')
347347
.file('spec.md', '# From Spec')
348348
.dir('nested/', _ => _.file('inner.txt', 'nested content'))
349349

350350
const program = Effect.gen(function*() {
351351
const fs = yield* FileSystem.FileSystem
352352

353-
// Create a chain from a dir and merge the spec
354-
const dir = Dir.create('/test')
355-
const chain = Dir.chain(dir)
353+
// Create a chain from a builder and merge the spec
354+
const builder = Builder.create('/test')
355+
const chain = Builder.chain(builder)
356356

357357
// Apply spec operations to chain
358358
yield* chain.merge(spec).commit()

src/utils/fs/builder/_.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as Builder from './__.js'

src/utils/dir/__.ts renamed to src/utils/fs/builder/__.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export type { Dir } from './dir.js'
2-
export { create, createTemp, createTempUnsafe } from './dir.js'
1+
export type { Builder } from './builder.js'
2+
export { create, createTemp, createTempUnsafe } from './builder.js'
33

44
export type { DirChain } from './chain.js'
55
export { chain, withChaining } from './chain.js'

0 commit comments

Comments
 (0)