Lines 26-66typescript
26 * executes the user's model definitions, so `define*` throwing lands in the same
27 * catch as an unresolvable path — and wrapping it in ConfigLoadError attaches
28 * advice about `--config` and the default export to a config whose path and
29 * export are both fine. Matched by `_tag` rather than `instanceof`: a project
30 * may resolve a different copy of the package than the CLI is running from.
32const definitionError = (cause: unknown): ModelDefinitionError | undefined => {
33 const tag = (cause as { _tag?: unknown } | null)?._tag
34 return tag === "ModelDefinitionError" ? (cause as ModelDefinitionError) : undefined
37export const loadConfig = (
41 ConfigLoadError | ModelDefinitionError | DiscoveryError | DiscoveryConflictError
43 Effect.gen(function* () {
44 const absolute = NodePath.resolve(process.cwd(), configPath)
45 const config = yield* Effect.tryPromise({
47 const module = (await import(absolute)) as { default?: EfmeshConfig }
48 if (
MediumDynamic Require
Package source references dynamic require/import behavior.
src/cli/config.tsView on unpkg · L46 49 module.default === undefined ||
50 (!Array.isArray(module.default.models) && module.default.discovery === undefined)
52 throw new Error("config must export a default with models and/or discovery")
57 definitionError(cause) ?? new ConfigLoadError({ path: configPath, reason: String(cause) }),
59 const explicit = config.models ?? []
60 if (config.discovery === undefined) return { ...config, models: explicit }
61 // globs are relative to the config: the project is portable regardless of cwd
62 const discovered = yield* discoverModels(config.discovery, NodePath.dirname(absolute))
63 const seen = new Set(explicit)
64 const names = new Map(explicit.map((model) => [model.name.full, "config models"]))
65 const merged = [...explicit]
66 for (const model of discovered) {