mikro-orm icon indicating copy to clipboard operation
mikro-orm copied to clipboard

feat(core): improved configuration loaders

Open octet-stream opened this issue 9 months ago • 27 comments

Details

This PR implements improves configuration loading with support for new transpilers, like jiti and tsx. It also includes documentation updates, reflecting these changes. This PR also deprecates some of the old CLI settings: useTsNode, preferTs, and alwaysAllowTs in favor of a single new option called loader, and this new option allows to opt-in to a specific transpiler, or use auto-detection (the default), or opt-out to runtime's native import() (when set to either false or native).

Notable changes

  • [x] Implement new loaders: ts-node, jiti, tsx, and native;
  • [x] Add new type-safe ESM utilities:
    • [x] tryModule - it resolves a promise, returned by import() and catches the errors with the ERR_MODULE_NOT_FOUND code, then wraps it into a TryModuleError, so it can be handled later. Unlike existent utilities (Utils.dynamicImport and Utils.tryRequire), the resulting value has correct types (though it only supports the import() - it can be easily modified to support require() function as well);
    • [x] requireDefault - resolves the default member from a module's exports while also providing correct types;
  • [x] Add in-code documentation for CLI Settings interface;
  • [x] Deprecate useTsNode, preferTs, and alwaysAllowTs in favor of loaders;
  • [x] Integrate loaders into ConfigurationLoader class;
  • [ ] Add tests for loaders and ConfigurationLoader integration:
    • [x] Add tests for loader option and environment variable;
    • [ ] Add tests for ConfigurationLoader.getConfiguration method;
  • [ ] Update documentation to reflect the changes;

I also updated git hooks to use local binaries of lint-staged and commitlint, because there's no point to have those installed globally (yarn can pick up both local and global installations), nor to assume everyone has these by default.

octet-stream avatar Jan 12 '25 12:01 octet-stream