|
14 | 14 | // |
15 | 15 | // ⛔ Nothing here changes which arguments the CLI accepts. `os dev --no-ui` is |
16 | 16 | // still rejected — it is only rejected legibly. |
17 | | -import { flush, handle, run } from '@oclif/core'; |
| 17 | +import { flush, handle, run, settings } from '@oclif/core'; |
| 18 | + |
| 19 | +/** |
| 20 | + * ⭐ THIS ENTRY POINT RUNS `dist/`. It says so here so that an ambient |
| 21 | + * environment variable cannot decide otherwise. |
| 22 | + * |
| 23 | + * `bin/run.js` is the BUILT entry — `bin.objectstack` / `bin.os`, the file an |
| 24 | + * `npm i -g @objectstack/cli` install executes — and `packages/cli/package.json` |
| 25 | + * declares its command table over the emitted tree |
| 26 | + * (`"target": "./dist/commands"`). `bin/run-dev.js` is the SOURCE entry, run |
| 27 | + * under tsx, and it is the one that is SUPPOSED to reach `src/`. That division |
| 28 | + * is not new prose: `scripts/check-cli-test-child-env.mjs` already enforces it |
| 29 | + * on every test that spawns this file, and its rule 3 states the property in |
| 30 | + * the same words — a child of the built entrypoint must be readably outside |
| 31 | + * `development`/`test`, with no baseline and only two declared exceptions. |
| 32 | + * |
| 33 | + * What was missing is that **this file never asserted it about itself.** |
| 34 | + * `@oclif/core@4.13.3`'s `lib/config/ts-path.js` skips its TypeScript path |
| 35 | + * lookup only when `isProd()`, which `lib/util/util.js` defines as |
| 36 | + * `['development', 'test'].includes(process.env.NODE_ENV ?? '')` negated. So an |
| 37 | + * ambient `NODE_ENV` — exported by a developer, or inherited by any child this |
| 38 | + * CLI spawns — rewrote the command target from `dist/commands` to |
| 39 | + * `src/commands` and registered tsx on the way. Measured against `Config.load()` |
| 40 | + * on this package with `dist` present (the table #11317 recorded, unchanged): |
| 41 | + * |
| 42 | + * child NODE_ENV resolved commandsDir |
| 43 | + * -------------- ------------------------- |
| 44 | + * unset packages/cli/dist/commands |
| 45 | + * production packages/cli/dist/commands |
| 46 | + * development packages/cli/src/commands ⛔ |
| 47 | + * test packages/cli/src/commands ⛔ |
| 48 | + * |
| 49 | + * ⚠️ The registration is the damaging half, not the redirect. `registerTsx()` |
| 50 | + * runs BEFORE `determinePath()` decides anything, and tsx honours the tsconfig |
| 51 | + * of the **current working directory**. An application whose tsconfig maps a |
| 52 | + * workspace package to its TypeScript source for TYPE resolution — |
| 53 | + * `"@objectstack/formula": ["../../packages/formula/src/index.ts"]`, which is |
| 54 | + * what `examples/app-crm`, `app-showcase` and `app-multi-package` all do — then |
| 55 | + * steers this CLI's own module graph into `.ts` files, after which Node's CJS |
| 56 | + * resolver walks their extensionless siblings and knows nothing about `.ts`: |
| 57 | + * |
| 58 | + * [MODULE_NOT_FOUND] import() failed to load …/packages/cli/src/commands/doctor.ts: |
| 59 | + * Cannot find module './registry' |
| 60 | + * Require stack: |
| 61 | + * - …/packages/formula/src/index.ts |
| 62 | + * |
| 63 | + * ⭐ Note WHICH file failed to load: `src/commands/doctor.ts`. The casualty is |
| 64 | + * this CLI's own command table, not the user's config — so the failure is not |
| 65 | + * specific to any one command, and no amount of scrubbing a CHILD's environment |
| 66 | + * reaches it. Measured at `examples/app-crm` and `examples/app-showcase` with |
| 67 | + * `NODE_ENV=development` exported, before this line existed: `os compile`, |
| 68 | + * `os dev --compile --fresh`, `os serve --dev` and `os start` each exit 1 on |
| 69 | + * that signature, against exit 0 / still-serving for every one of them with |
| 70 | + * `NODE_ENV=production`. `examples/app-todo`, the one example app whose |
| 71 | + * tsconfig carries no `paths` block, is the only one that survived — the |
| 72 | + * failures map 1:1 onto that population, and #8249 is actively growing it. |
| 73 | + * |
| 74 | + * ⛔ This is deliberately NOT a `TSX_TSCONFIG_PATH` pin like the one |
| 75 | + * `bin/run-dev.js` carries. That shim genuinely executes TypeScript, so all it |
| 76 | + * can do is aim the transpiler at the right tsconfig; and it cannot even do |
| 77 | + * that in-process (tsx parses its tsconfig in the loader's `initialize`, which |
| 78 | + * has already run by then), so it pays a whole re-exec. This file executes no |
| 79 | + * TypeScript at all, so the correct statement is not "transpile against a |
| 80 | + * different config" but "do not transpile" — and the published install has no |
| 81 | + * `packages/cli/tsconfig.json` to aim at in any case (`files` names `dist` |
| 82 | + * only). |
| 83 | + * |
| 84 | + * ⚠️ What it costs, measured rather than assumed. The one thing oclif keeps the |
| 85 | + * TypeScript lookup alive for even in production is a LINKED plugin |
| 86 | + * (`plugin?.type !== 'link'` guards the `isProduction` early return), and this |
| 87 | + * setting is checked ahead of that — so a `plugins link`ed TypeScript plugin |
| 88 | + * would no longer be auto-transpiled through this entry. ⭐ That path is not |
| 89 | + * reachable today: `@oclif/plugin-plugins` sits in `devDependencies`, and |
| 90 | + * oclif's core-plugin loader only matches names under `dependencies`, so |
| 91 | + * `os plugins` is not a registered command at all (measured on this entry — |
| 92 | + * `os --help` lists 34 topics and none of them is `plugins`; the count is the |
| 93 | + * control, so the zero is a reading). `content/docs/plugins/index.mdx` says the |
| 94 | + * same in its own words and tells an extension author to build an `os` |
| 95 | + * distribution listing the package in both places. ⛔ If that is ever fixed, |
| 96 | + * this line is what has to be revisited — the remedy is `bin/run-dev.js`, or |
| 97 | + * building the plugin. |
| 98 | + * |
| 99 | + * The other change in behaviour is a convergence, not a loss: on an UNBUILT |
| 100 | + * tree this file now answers oclif's "command not found" under |
| 101 | + * `development`/`test` exactly as it already did when `NODE_ENV` was unset — |
| 102 | + * the signature `scripts/cli-build-prerequisite.mjs` classifies for every gate |
| 103 | + * that shells out to this CLI, so the three legs stop disagreeing. |
| 104 | + */ |
| 105 | +settings.enableAutoTranspile = false; |
18 | 106 |
|
19 | 107 | /** |
20 | 108 | * Print the one-line invocation verdict, if this failure is one. |
|
0 commit comments