Skip to content

feat(cli): add discovery:export command#7335

Merged
B4nan merged 6 commits intonextfrom
feat/discovery-export-command
Apr 18, 2026
Merged

feat(cli): add discovery:export command#7335
B4nan merged 6 commits intonextfrom
feat/discovery-export-command

Conversation

@B4nan
Copy link
Copy Markdown
Member

@B4nan B4nan commented Mar 17, 2026

Summary

Adds a discovery:export CLI command that scans entity source files and generates a TypeScript barrel file (#7323). The generated file provides:

  • export const entities = [...] as const — for use in ORM config
  • export type Database = ... — for typed getKysely<Database>() in DI contexts (NestJS, etc.)

Command usage

mikro-orm discovery:export [--path './src/entities/*.ts'] [--out ./entities.generated.ts] [--dump]

Files changed

  • New: packages/cli/src/commands/DiscoveryExportCommand.ts — the command implementation
  • Modified: packages/cli/src/CLIConfigurator.ts — register the command
  • New: tests/features/cli/DiscoveryExportCommand.test.ts — 14 tests
  • Modified: tests/features/cli/CLIHelper.test.ts — updated command list assertion
  • Modified: docs/docs/kysely.md and docs/versioned_docs/version-7.0/kysely.md — documentation

Test plan

  • 14 unit tests covering: dump mode, file write, ESM/CJS imports, EntitySchema dedup, decorator entities, multiple entities, driver package resolution, config path fallback, error cases
  • yarn build passes (CLI package)
  • yarn tsc-check-tests passes
  • Full test suite passes (5314/5314)

Closes #7323

🤖 Generated with Claude Code

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.64%. Comparing base (8808779) to head (848a889).
⚠️ Report is 19 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff            @@
##             next    #7335    +/-   ##
========================================
  Coverage   99.64%   99.64%            
========================================
  Files         262      263     +1     
  Lines       26080    26210   +130     
  Branches     7207     7236    +29     
========================================
+ Hits        25987    26117   +130     
  Misses         88       88            
  Partials        5        5            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@B4nan B4nan force-pushed the feat/discovery-export-command branch from 674b629 to fe50c40 Compare March 18, 2026 17:04
@B4nan B4nan force-pushed the feat/discovery-export-command branch 2 times, most recently from 4b5cf6d to ad98793 Compare April 1, 2026 14:53
B4nan and others added 6 commits April 14, 2026 09:23
Generate a TypeScript barrel file with entity exports for typed Kysely
and ORM config. Scans entity source files and produces an `entities`
array and a `Database` type for use with `getKysely<Database>()`.

Closes #7323

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rt --dump

The dump codepath passed `process.cwd()` (a directory) as `outPath` to
`generateFile()`, so `dirname()` resolved to the parent of cwd, making
import paths include the last cwd segment and vary across machines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Node 24 enables --experimental-strip-types by default. When vitest's
OXC transform races under multi-worker `isolate: false`, some .ts
imports fall through to Node's native strip-only mode which cannot
handle TypeScript parameter properties (`constructor(public x: T)`).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
After vi.resetModules() clears the module cache, the
globalThis.dynamicImportProvider still held a reference to an import()
function from a previous module evaluation. Under isolate: false with
multiple workers, this stale reference could resolve through Node's
native loader instead of vitest's OXC transform, causing SyntaxErrors
on decorator and parameter property syntax.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add tests for builder options, .d.ts skipping, __esModule filtering,
default exports, duplicate avoidance, output path resolution from
config, CJS file output, driver fallbacks, and non-entity exports.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Skip Kysely type imports/exports for MongoDB driver
- Create parent directories with mkdirSync when writing output file
- Revert BigIntType, DecimalType, FullTextType to use parameter properties

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@B4nan B4nan force-pushed the feat/discovery-export-command branch from ad98793 to 848a889 Compare April 14, 2026 07:23
@B4nan B4nan changed the base branch from master to next April 18, 2026 14:04
@B4nan B4nan merged commit bdf55ee into next Apr 18, 2026
22 checks passed
@B4nan B4nan deleted the feat/discovery-export-command branch April 18, 2026 14:11
B4nan added a commit that referenced this pull request Apr 19, 2026
## Summary

Adds a `discovery:export` CLI command that scans entity source files and
generates a TypeScript barrel file (#7323). The generated file provides:

- `export const entities = [...] as const` — for use in ORM config
- `export type Database = ...` — for typed `getKysely<Database>()` in DI
contexts (NestJS, etc.)

### Command usage

```bash
mikro-orm discovery:export [--path './src/entities/*.ts'] [--out ./entities.generated.ts] [--dump]
```

### Files changed

- **New:** `packages/cli/src/commands/DiscoveryExportCommand.ts` — the
command implementation
- **Modified:** `packages/cli/src/CLIConfigurator.ts` — register the
command
- **New:** `tests/features/cli/DiscoveryExportCommand.test.ts` — 14
tests
- **Modified:** `tests/features/cli/CLIHelper.test.ts` — updated command
list assertion
- **Modified:** `docs/docs/kysely.md` and
`docs/versioned_docs/version-7.0/kysely.md` — documentation

## Test plan

- [x] 14 unit tests covering: dump mode, file write, ESM/CJS imports,
EntitySchema dedup, decorator entities, multiple entities, driver
package resolution, config path fallback, error cases
- [x] `yarn build` passes (CLI package)
- [x] `yarn tsc-check-tests` passes
- [x] Full test suite passes (5314/5314)

Closes #7323

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
B4nan added a commit that referenced this pull request Apr 20, 2026
## Summary

Adds a `discovery:export` CLI command that scans entity source files and
generates a TypeScript barrel file (#7323). The generated file provides:

- `export const entities = [...] as const` — for use in ORM config
- `export type Database = ...` — for typed `getKysely<Database>()` in DI
contexts (NestJS, etc.)

### Command usage

```bash
mikro-orm discovery:export [--path './src/entities/*.ts'] [--out ./entities.generated.ts] [--dump]
```

### Files changed

- **New:** `packages/cli/src/commands/DiscoveryExportCommand.ts` — the
command implementation
- **Modified:** `packages/cli/src/CLIConfigurator.ts` — register the
command
- **New:** `tests/features/cli/DiscoveryExportCommand.test.ts` — 14
tests
- **Modified:** `tests/features/cli/CLIHelper.test.ts` — updated command
list assertion
- **Modified:** `docs/docs/kysely.md` and
`docs/versioned_docs/version-7.0/kysely.md` — documentation

## Test plan

- [x] 14 unit tests covering: dump mode, file write, ESM/CJS imports,
EntitySchema dedup, decorator entities, multiple entities, driver
package resolution, config path fallback, error cases
- [x] `yarn build` passes (CLI package)
- [x] `yarn tsc-check-tests` passes
- [x] Full test suite passes (5314/5314)

Closes #7323

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (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.

Add a command to the cli to generate entites field

1 participant