Skip to content

fix(cli): run the installer from a checkout without installed dependencies - #219

Open
cdotta wants to merge 1 commit into
theam:mainfrom
cdotta:fix/cli-runs-from-a-checkout
Open

fix(cli): run the installer from a checkout without installed dependencies#219
cdotta wants to merge 1 commit into
theam:mainfrom
cdotta:fix/cli-runs-from-a-checkout

Conversation

@cdotta

@cdotta cdotta commented Aug 30, 2026

Copy link
Copy Markdown

The README documents cloning Facility and running the installer directly, and describes the installer as not requiring Facility to be deployed at all:

git clone https://github.com/theam/facility.git /absolute/path/to/facility
cd your-repository
node /absolute/path/to/facility/packages/cli/bin/facility.mjs init

There is no install step in that recipe, and from a fresh clone every command fails:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'postgres'
    imported from packages/cli/src/instance.mjs

Not only initdoctor, --help and --version fail identically, with an unhandled stack trace rather than a diagnostic.

cli.mjs statically imports bootstrapInstance from instance.mjs, which statically imports the postgres driver at module scope, so every command eagerly loads a database driver that only instance bootstrap uses.

postgres is a correctly declared dependency and this is fine once the CLI is published to npm (#1). The problem is only the documented run-from-a-checkout path.

Change

Defer the import to its call site. The module already supports driver injection (options.postgres ?? …), so the bootstrap tests are unaffected.

Test

packages/cli/test/plain-checkout.test.mjs copies the published files (bin, src, templates, modules, package.json) into a temp directory with no node_modules — a faithful plain checkout, since the CLI has exactly one external dependency — and asserts --version, --help and init all succeed. Fails on main, passes with this change.

Verification

  • node --test test/*.test.mjs in packages/cli — all pass
  • node guards/run.mjs — clean

Related to #45, which frames this as documentation alignment. This makes the documented flow work as written instead, which seemed the better outcome — happy to close it as docs-only if you disagree.

…ncies

README documents cloning Facility and running the installer directly, and
describes it as not requiring Facility to be deployed at all. Every command
died instead, including --version and --help:

  Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'postgres'
  imported from packages/cli/src/instance.mjs

cli.mjs statically imports instance.mjs, which statically imports the
postgres driver, so every command eagerly loaded a database driver that only
'instance bootstrap' uses. Deferred to the call site; the existing
options.postgres injection keeps tests unaffected.

Refs theam#45.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant