mikro-orm
mikro-orm copied to clipboard
feat(core): improved configuration loaders
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, andnative; - [x] Add new type-safe ESM utilities:
- [x]
tryModule- it resolves a promise, returned byimport()and catches the errors with theERR_MODULE_NOT_FOUNDcode, then wraps it into aTryModuleError, so it can be handled later. Unlike existent utilities (Utils.dynamicImport and Utils.tryRequire), the resulting value has correct types (though it only supports theimport()- it can be easily modified to supportrequire()function as well); - [x]
requireDefault- resolves thedefaultmember from a module's exports while also providing correct types;
- [x]
- [x] Add in-code documentation for CLI Settings interface;
- [x] Deprecate
useTsNode,preferTs, andalwaysAllowTsin favor ofloaders; - [x] Integrate loaders into
ConfigurationLoaderclass; - [ ] Add tests for loaders and
ConfigurationLoaderintegration:- [x] Add tests for loader option and environment variable;
- [ ] Add tests for
ConfigurationLoader.getConfigurationmethod;
- [ ] 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.