@mikro-orm/cli 7.0.0-dev.91 → 7.0.0-dev.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLIHelper.d.ts +1 -0
- package/CLIHelper.js +21 -6
- package/package.json +4 -4
package/CLIHelper.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class CLIHelper {
|
|
|
11
11
|
* @param options Additional options to augment the final configuration with.
|
|
12
12
|
*/
|
|
13
13
|
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>>(contextName?: string, paths?: string[], options?: Partial<Options<D>>): Promise<Configuration<D, EM>>;
|
|
14
|
+
static commonJSCompat(options: Partial<Options>): void;
|
|
14
15
|
static getORM<D extends IDatabaseDriver = IDatabaseDriver>(contextName?: string, configPaths?: string[], opts?: Partial<Options<D>>): Promise<MikroORM<D>>;
|
|
15
16
|
static isDBConnected(config: Configuration, reason?: false): Promise<boolean>;
|
|
16
17
|
static isDBConnected(config: Configuration, reason: true): Promise<true | string>;
|
package/CLIHelper.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { extname, join } from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
4
|
import yargs from 'yargs';
|
|
4
5
|
import { colors, Configuration, loadEnvironmentVars, lookupExtensions, MikroORM, Utils, } from '@mikro-orm/core';
|
|
5
6
|
import { fs } from '@mikro-orm/core/fs-utils';
|
|
@@ -15,6 +16,7 @@ export class CLIHelper {
|
|
|
15
16
|
* @param options Additional options to augment the final configuration with.
|
|
16
17
|
*/
|
|
17
18
|
static async getConfiguration(contextName, paths, options = {}) {
|
|
19
|
+
this.commonJSCompat(options);
|
|
18
20
|
paths ??= await this.getConfigPaths();
|
|
19
21
|
const deps = fs.getORMPackages();
|
|
20
22
|
if (!deps.has('@mikro-orm/cli') && !process.env.MIKRO_ORM_ALLOW_GLOBAL_CLI) {
|
|
@@ -84,6 +86,16 @@ export class CLIHelper {
|
|
|
84
86
|
await lookupExtensions(tmp);
|
|
85
87
|
return new Configuration(Utils.mergeConfig({}, esmConfigOptions, tmp, options, env));
|
|
86
88
|
}
|
|
89
|
+
static commonJSCompat(options) {
|
|
90
|
+
if (this.isESM()) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
/* v8 ignore next */
|
|
94
|
+
options.dynamicImportProvider ??= id => {
|
|
95
|
+
id = fileURLToPath(id);
|
|
96
|
+
return createRequire(process.cwd())(id);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
87
99
|
static async getORM(contextName, configPaths, opts = {}) {
|
|
88
100
|
const options = await this.getConfiguration(contextName, configPaths, opts);
|
|
89
101
|
const settings = this.getSettings();
|
|
@@ -280,16 +292,19 @@ export class CLIHelper {
|
|
|
280
292
|
process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS ??= '1';
|
|
281
293
|
const explicitLoader = tsLoader ?? process.env.MIKRO_ORM_CLI_TS_LOADER ?? 'auto';
|
|
282
294
|
const loaders = {
|
|
283
|
-
swc: {
|
|
284
|
-
tsx: {
|
|
285
|
-
jiti: {
|
|
286
|
-
tsimp: {
|
|
295
|
+
swc: { esm: '@swc-node/register/esm-register', cjs: '@swc-node/register' },
|
|
296
|
+
tsx: { esm: 'tsx/esm/api', cjs: 'tsx/cjs/api', cb: (tsx) => tsx.register({ tsconfig: configPath }) },
|
|
297
|
+
jiti: { esm: 'jiti/register', cjs: 'jiti/register', cb: () => Utils.dynamicImportProvider = id => import(id).then(mod => mod?.default ?? mod) },
|
|
298
|
+
tsimp: { esm: 'tsimp/import', cjs: 'tsimp/import' },
|
|
287
299
|
};
|
|
288
300
|
for (const loader of Utils.keys(loaders)) {
|
|
289
301
|
if (explicitLoader !== 'auto' && loader !== explicitLoader) {
|
|
290
302
|
continue;
|
|
291
303
|
}
|
|
292
|
-
const {
|
|
304
|
+
const { esm, cjs, cb } = loaders[loader];
|
|
305
|
+
const isEsm = this.isESM();
|
|
306
|
+
/* v8 ignore next */
|
|
307
|
+
const module = isEsm ? esm : cjs;
|
|
293
308
|
const mod = await Utils.tryImport({ module });
|
|
294
309
|
if (mod) {
|
|
295
310
|
cb?.(mod);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.92",
|
|
5
5
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
57
|
-
"@mikro-orm/knex": "7.0.0-dev.
|
|
58
|
-
"mikro-orm": "7.0.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.0.0-dev.92",
|
|
57
|
+
"@mikro-orm/knex": "7.0.0-dev.92",
|
|
58
|
+
"mikro-orm": "7.0.0-dev.92",
|
|
59
59
|
"yargs": "17.7.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|