Creating Modules
A module is a PascalCase namespace inside a package. Two common cases:
- Extend
@kitz/effect ā add a new namespace (a concept) alongside
Path and Schema. The lightweight alternative to a whole new package
(vp create package).
- Add a module to any
@kitz/* package ā the same mechanics anywhere.
Read packages/effect/src/_.ts (the root namespace bundle) and
packages/effect/src/path/ (a submodule namespace) as the canonical examples.
Structure
# Single source file (__.ts elided):
src/<module>/
āāā _.ts # root assembly: export * as <Name> from './<module>.js'
āāā _.test.ts
āāā <module>.ts # implementation
# Multiple source files:
src/<module>/
āāā _.ts # root assembly: export * as <Name> from './__.js'
āāā _.test.ts
āāā __.ts # barrel: export * from './impl.js'
āāā *.ts
- Directory: kebab-case. Namespace export: PascalCase. Functions: camelCase, no
namespace prefix (
by, not groupBy).
- Prefer
export * from in barrels; use named re-exports only to rename or exclude.
- Elision: when
__.ts would re-export a single file, skip it and have _.ts
export the implementation directly.
_.ts exists only to assemble the namespace exported by the package root.
Explicit package subpaths target the module itself: __.ts, or the implementation
file when __.ts is elided.
Wire the namespace into the package
Re-export from the package root src/_.ts:
export { <Name> } from './<module>/_.js'
Add the package.json exports entry ā live-types, mirroring the existing
entries (dev ā src, publish ā build):
// exports
"./<Name>": "./src/<module>/__.ts",
// publishConfig.exports
"./<Name>": "./build/<module>/__.js"
Verify: pnpm exec vp run check and (if exported) pnpm exec vp run check:package.
Imports
- No
# imports. That convention was removed; packages no longer declare an
imports map. Within a package, use relative imports (./other/_.js).
- Package root: import assembled namespaces by name ā
import { FileSystem, Path } from '@kitz/effect'.
- Explicit subpath: import the direct module namespace ā
import * as Path from '@kitz/effect/Path'.