Skip to content
ES

Reference

newt add deps

Lets a module use another module of its context.

newt add deps lets one module call another module of the same context, such as a task reading its project. The other module is passed in when the context starts.

Terminal window
newt add deps <context>/<module> <module-it-uses> [options]
Argument Meaning
context/module The module that uses the other, as in tasks/task
module-it-uses Another module of the same context, as in project
Option Default Meaning
--backend <folder> the one you are in The backend, in a monorepo with several

It also takes the global flags.

Terminal window
newt add deps tasks/task project
created src/contexts/tasks/modules/task/task.deps.ts
updated src/contexts/tasks/modules/task/task.module.ts
updated src/contexts/tasks/tasks-modules.ts
Next steps:
call it in a use case of task: this.deps.project
bun test src/contexts/tasks/modules/task
src/contexts/tasks/modules/task/task.deps.ts
import type { Project_Module } from '../project/project.module'
export type Task_Deps = {
project: Project_Module
}
src/contexts/tasks/tasks-modules.ts
export function tasksModules(base: ContextBase, router: HttpRouter) {
const project = Project_Module.initialize(base, router)
const task = Task_Module.initialize(base, router, { project })
return {
task,
project,
}
}
  • <module>.deps.ts is created if missing, and gets the module it uses.
  • <module>.module.ts takes Task_Deps in initialize and its constructor, and keeps it as this.deps.
  • <context>-modules.ts passes the module in, and orders the modules so each starts after the ones it uses.
  • Call it in a use case: this.deps.project.
  • bun test src/contexts/<context>/modules/<module>
  • Missing arguments: newt add deps takes the module and the module of its context it uses.
  • A module of another context (tasks/project): refused; newt does not write that yet.
  • The module itself: refused.
  • A module the context does not have: refused; add it with newt add module.
  • A cycle: project → task → project would be a cycle: modules never use each other, even through others. If it is to check who may go on at a path, the context gives its router a guard (router.guard), and no module uses the other.

See Services and dependencies.