@mikro-orm/cli 7.0.0-dev.75 → 7.0.0-dev.77
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/CLIConfigurator.js
CHANGED
|
@@ -36,12 +36,12 @@ function createBasicConfig() {
|
|
|
36
36
|
.strict();
|
|
37
37
|
}
|
|
38
38
|
export async function configure() {
|
|
39
|
-
ConfigurationLoader.checkPackageVersion();
|
|
40
|
-
const settings = CLIHelper.getSettings();
|
|
39
|
+
await ConfigurationLoader.checkPackageVersion();
|
|
40
|
+
const settings = await CLIHelper.getSettings();
|
|
41
41
|
const version = Utils.getORMVersion();
|
|
42
42
|
if (settings.preferTs !== false) {
|
|
43
43
|
const preferTs = await CLIHelper.registerTypeScriptSupport(settings.tsConfigPath, settings.tsLoader);
|
|
44
|
-
/* v8 ignore next
|
|
44
|
+
/* v8 ignore next */
|
|
45
45
|
if (!preferTs) {
|
|
46
46
|
process.env.MIKRO_ORM_CLI_PREFER_TS ??= '0';
|
|
47
47
|
}
|
package/CLIHelper.d.ts
CHANGED
|
@@ -14,11 +14,10 @@ export declare class CLIHelper {
|
|
|
14
14
|
static getORM<D extends IDatabaseDriver = IDatabaseDriver>(contextName?: string, configPaths?: string[], opts?: Partial<Options<D>>): Promise<MikroORM<D>>;
|
|
15
15
|
static isDBConnected(config: Configuration, reason?: false): Promise<boolean>;
|
|
16
16
|
static isDBConnected(config: Configuration, reason: true): Promise<true | string>;
|
|
17
|
-
static getNodeVersion(): string;
|
|
18
17
|
static getDriverDependencies(config: Configuration): string[];
|
|
19
18
|
static dump(text: string, config?: Configuration): void;
|
|
20
|
-
static getSettings(): Settings
|
|
21
|
-
static getConfigPaths(): string[]
|
|
19
|
+
static getSettings(): Promise<Settings>;
|
|
20
|
+
static getConfigPaths(): Promise<string[]>;
|
|
22
21
|
private static getConfigFile;
|
|
23
22
|
private static loadEnvironmentVars;
|
|
24
23
|
static dumpDependencies(): Promise<void>;
|
|
@@ -40,7 +39,7 @@ export declare class CLIHelper {
|
|
|
40
39
|
* This method is used only in CLI context.
|
|
41
40
|
*/
|
|
42
41
|
static registerTypeScriptSupport(configPath?: string, tsLoader?: 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'auto'): Promise<boolean>;
|
|
43
|
-
static isESM(): boolean
|
|
42
|
+
static isESM(): Promise<boolean>;
|
|
44
43
|
static showHelp(): void;
|
|
45
44
|
}
|
|
46
45
|
export interface Settings {
|
package/CLIHelper.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { extname, join, resolve } from 'node:path';
|
|
1
|
+
import { extname, join } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
4
3
|
import yargs from 'yargs';
|
|
5
|
-
import { colors, ConfigurationLoader, MikroORM, Utils, Configuration, } from '@mikro-orm/core';
|
|
4
|
+
import { colors, ConfigurationLoader, MikroORM, Utils, Configuration, lookupExtensions, } from '@mikro-orm/core';
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
*/
|
|
@@ -14,13 +13,15 @@ export class CLIHelper {
|
|
|
14
13
|
* @param paths Array of possible paths for a configuration file. Files will be checked in order, and the first existing one will be used. Defaults to the output of {@link ConfigurationLoader.getConfigPaths}.
|
|
15
14
|
* @param options Additional options to augment the final configuration with.
|
|
16
15
|
*/
|
|
17
|
-
static async getConfiguration(contextName, paths
|
|
18
|
-
|
|
16
|
+
static async getConfiguration(contextName, paths, options = {}) {
|
|
17
|
+
paths ??= await this.getConfigPaths();
|
|
18
|
+
const deps = await ConfigurationLoader.getORMPackages();
|
|
19
19
|
if (!deps.has('@mikro-orm/cli') && !process.env.MIKRO_ORM_ALLOW_GLOBAL_CLI) {
|
|
20
20
|
throw new Error('@mikro-orm/cli needs to be installed as a local dependency!');
|
|
21
21
|
}
|
|
22
22
|
contextName ??= process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default';
|
|
23
23
|
const env = await this.loadEnvironmentVars();
|
|
24
|
+
await lookupExtensions(options);
|
|
24
25
|
const configFinder = (cfg) => {
|
|
25
26
|
return typeof cfg === 'object' && cfg !== null && ('contextName' in cfg ? cfg.contextName === contextName : (contextName === 'default'));
|
|
26
27
|
};
|
|
@@ -78,12 +79,12 @@ export class CLIHelper {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
|
-
const esmConfigOptions = this.isESM() ? { entityGenerator: { esmImport: true } } : {};
|
|
82
|
+
const esmConfigOptions = await this.isESM() ? { entityGenerator: { esmImport: true } } : {};
|
|
82
83
|
return new Configuration(Utils.mergeConfig({}, esmConfigOptions, tmp, options, env));
|
|
83
84
|
}
|
|
84
85
|
static async getORM(contextName, configPaths, opts = {}) {
|
|
85
86
|
const options = await this.getConfiguration(contextName, configPaths, opts);
|
|
86
|
-
const settings = this.getSettings();
|
|
87
|
+
const settings = await this.getSettings();
|
|
87
88
|
options.set('allowGlobalContext', true);
|
|
88
89
|
options.set('debug', !!settings.verbose);
|
|
89
90
|
options.getLogger().setDebugMode(!!settings.verbose);
|
|
@@ -108,9 +109,6 @@ export class CLIHelper {
|
|
|
108
109
|
return false;
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
|
-
static getNodeVersion() {
|
|
112
|
-
return process.versions.node;
|
|
113
|
-
}
|
|
114
112
|
static getDriverDependencies(config) {
|
|
115
113
|
try {
|
|
116
114
|
return config.getDriver().getDependencies();
|
|
@@ -126,8 +124,8 @@ export class CLIHelper {
|
|
|
126
124
|
// eslint-disable-next-line no-console
|
|
127
125
|
console.log(text);
|
|
128
126
|
}
|
|
129
|
-
static getSettings() {
|
|
130
|
-
const config = ConfigurationLoader.getPackageConfig();
|
|
127
|
+
static async getSettings() {
|
|
128
|
+
const config = await ConfigurationLoader.getPackageConfig();
|
|
131
129
|
const settings = { ...config['mikro-orm'] };
|
|
132
130
|
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
133
131
|
settings.preferTs = process.env.MIKRO_ORM_CLI_PREFER_TS != null ? bool(process.env.MIKRO_ORM_CLI_PREFER_TS) : settings.preferTs;
|
|
@@ -139,8 +137,8 @@ export class CLIHelper {
|
|
|
139
137
|
}
|
|
140
138
|
return settings;
|
|
141
139
|
}
|
|
142
|
-
static getConfigPaths() {
|
|
143
|
-
const settings = this.getSettings();
|
|
140
|
+
static async getConfigPaths() {
|
|
141
|
+
const settings = await this.getSettings();
|
|
144
142
|
const typeScriptSupport = settings.preferTs ?? Utils.detectTypeScriptSupport();
|
|
145
143
|
const paths = [];
|
|
146
144
|
if (process.env.MIKRO_ORM_CLI_CONFIG) {
|
|
@@ -174,20 +172,29 @@ export class CLIHelper {
|
|
|
174
172
|
}
|
|
175
173
|
static async loadEnvironmentVars() {
|
|
176
174
|
const ret = ConfigurationLoader.loadEnvironmentVars();
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
175
|
+
/* v8 ignore next */
|
|
176
|
+
switch (process.env.MIKRO_ORM_TYPE) {
|
|
177
|
+
case 'mongo':
|
|
178
|
+
ret.driver ??= await import('@mikro-orm/sqlite').then(m => m.SqliteDriver);
|
|
179
|
+
break;
|
|
180
|
+
case 'mysql':
|
|
181
|
+
ret.driver ??= await import('@mikro-orm/mysql').then(m => m.MySqlDriver);
|
|
182
|
+
break;
|
|
183
|
+
case 'mssql':
|
|
184
|
+
ret.driver ??= await import('@mikro-orm/mssql').then(m => m.MsSqlDriver);
|
|
185
|
+
break;
|
|
186
|
+
case 'mariadb':
|
|
187
|
+
ret.driver ??= await import('@mikro-orm/mariadb').then(m => m.MariaDbDriver);
|
|
188
|
+
break;
|
|
189
|
+
case 'postgresql':
|
|
190
|
+
ret.driver ??= await import('@mikro-orm/postgresql').then(m => m.PostgreSqlDriver);
|
|
191
|
+
break;
|
|
192
|
+
case 'sqlite':
|
|
193
|
+
ret.driver ??= await import('@mikro-orm/sqlite').then(m => m.SqliteDriver);
|
|
194
|
+
break;
|
|
195
|
+
case 'libsql':
|
|
196
|
+
ret.driver ??= await import('@mikro-orm/libsql').then(m => m.LibSqlDriver);
|
|
197
|
+
break;
|
|
191
198
|
}
|
|
192
199
|
return ret;
|
|
193
200
|
}
|
|
@@ -195,9 +202,9 @@ export class CLIHelper {
|
|
|
195
202
|
const version = Utils.getORMVersion();
|
|
196
203
|
CLIHelper.dump(' - dependencies:');
|
|
197
204
|
CLIHelper.dump(` - mikro-orm ${colors.green(version)}`);
|
|
198
|
-
CLIHelper.dump(` - node ${colors.green(
|
|
205
|
+
CLIHelper.dump(` - node ${colors.green(process.versions.node)}`);
|
|
199
206
|
if (Utils.pathExists(process.cwd() + '/package.json')) {
|
|
200
|
-
/* v8 ignore
|
|
207
|
+
/* v8 ignore if */
|
|
201
208
|
if (process.versions.bun) {
|
|
202
209
|
CLIHelper.dump(` - typescript via bun`);
|
|
203
210
|
}
|
|
@@ -212,18 +219,12 @@ export class CLIHelper {
|
|
|
212
219
|
}
|
|
213
220
|
static async getModuleVersion(name) {
|
|
214
221
|
try {
|
|
215
|
-
const
|
|
222
|
+
const path = `${this.resolveModulePath(name)}/package.json`;
|
|
223
|
+
const pkg = Utils.readJSONSync(path);
|
|
216
224
|
return colors.green(pkg.version);
|
|
217
225
|
}
|
|
218
226
|
catch {
|
|
219
|
-
|
|
220
|
-
const path = `${this.resolveModulePath(name)}/package.json`;
|
|
221
|
-
const pkg = await readFile(path, { encoding: 'utf8' });
|
|
222
|
-
return colors.green(JSON.parse(pkg).version);
|
|
223
|
-
}
|
|
224
|
-
catch {
|
|
225
|
-
return '';
|
|
226
|
-
}
|
|
227
|
+
return '';
|
|
227
228
|
}
|
|
228
229
|
}
|
|
229
230
|
/**
|
|
@@ -235,7 +236,7 @@ export class CLIHelper {
|
|
|
235
236
|
if (!extname(from)) {
|
|
236
237
|
from = join(from, '__fake.js');
|
|
237
238
|
}
|
|
238
|
-
const path = Utils.normalizePath(
|
|
239
|
+
const path = Utils.normalizePath(import.meta.resolve(id, pathToFileURL(from)));
|
|
239
240
|
const parts = path.split('/');
|
|
240
241
|
const idx = parts.lastIndexOf(id) + 1;
|
|
241
242
|
parts.splice(idx, parts.length - idx);
|
|
@@ -268,16 +269,13 @@ export class CLIHelper {
|
|
|
268
269
|
* This method is used only in CLI context.
|
|
269
270
|
*/
|
|
270
271
|
static async registerTypeScriptSupport(configPath = 'tsconfig.json', tsLoader) {
|
|
271
|
-
/* v8 ignore
|
|
272
|
+
/* v8 ignore if */
|
|
272
273
|
if (process.versions.bun) {
|
|
273
274
|
return true;
|
|
274
275
|
}
|
|
275
276
|
process.env.SWC_NODE_PROJECT ??= configPath;
|
|
276
277
|
process.env.TSIMP_PROJECT ??= configPath;
|
|
277
278
|
process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS ??= '1';
|
|
278
|
-
const isEsm = this.isESM();
|
|
279
|
-
/* v8 ignore next */
|
|
280
|
-
const importMethod = isEsm ? 'tryImport' : 'tryRequire';
|
|
281
279
|
const explicitLoader = tsLoader ?? process.env.MIKRO_ORM_CLI_TS_LOADER ?? 'auto';
|
|
282
280
|
const loaders = {
|
|
283
281
|
swc: { esm: '@swc-node/register/esm-register', cjs: '@swc-node/register' },
|
|
@@ -290,9 +288,10 @@ export class CLIHelper {
|
|
|
290
288
|
continue;
|
|
291
289
|
}
|
|
292
290
|
const { esm, cjs, cb } = loaders[loader];
|
|
291
|
+
const isEsm = await this.isESM();
|
|
293
292
|
/* v8 ignore next */
|
|
294
293
|
const module = isEsm ? esm : cjs;
|
|
295
|
-
const mod = await Utils
|
|
294
|
+
const mod = await Utils.tryImport({ module });
|
|
296
295
|
if (mod) {
|
|
297
296
|
cb?.(mod);
|
|
298
297
|
process.env.MIKRO_ORM_CLI_TS_LOADER = loader;
|
|
@@ -303,12 +302,12 @@ export class CLIHelper {
|
|
|
303
302
|
console.warn('Neither `swc`, `tsx`, `jiti` nor `tsimp` found in the project dependencies, support for working with TypeScript files might not work. To use `swc`, you need to install both `@swc-node/register` and `@swc/core`.');
|
|
304
303
|
return false;
|
|
305
304
|
}
|
|
306
|
-
static isESM() {
|
|
307
|
-
const config = ConfigurationLoader.getPackageConfig();
|
|
305
|
+
static async isESM() {
|
|
306
|
+
const config = await ConfigurationLoader.getPackageConfig();
|
|
308
307
|
const type = config?.type ?? '';
|
|
309
308
|
return type === 'module';
|
|
310
309
|
}
|
|
311
|
-
/* v8 ignore next
|
|
310
|
+
/* v8 ignore next */
|
|
312
311
|
static showHelp() {
|
|
313
312
|
yargs(process.argv.slice(2)).showHelp();
|
|
314
313
|
}
|
package/commands/DebugCommand.js
CHANGED
|
@@ -9,12 +9,12 @@ export class DebugCommand {
|
|
|
9
9
|
async handler(args) {
|
|
10
10
|
CLIHelper.dump(`Current ${colors.cyan('MikroORM')} CLI configuration`);
|
|
11
11
|
await CLIHelper.dumpDependencies();
|
|
12
|
-
const settings = CLIHelper.getSettings();
|
|
12
|
+
const settings = await CLIHelper.getSettings();
|
|
13
13
|
if (!process.versions.bun && settings.preferTs !== false) {
|
|
14
14
|
const loader = process.env.MIKRO_ORM_CLI_TS_LOADER ?? 'auto';
|
|
15
15
|
CLIHelper.dump(' - TypeScript support ' + colors.green(`enabled (${loader})`));
|
|
16
16
|
}
|
|
17
|
-
const configPaths = args.config ?? CLIHelper.getConfigPaths();
|
|
17
|
+
const configPaths = args.config ?? await CLIHelper.getConfigPaths();
|
|
18
18
|
CLIHelper.dump(' - searched config paths:');
|
|
19
19
|
await DebugCommand.checkPaths(configPaths, 'yellow');
|
|
20
20
|
CLIHelper.dump(` - searched for config name: ${colors.green(args.contextName)}`);
|
|
@@ -148,7 +148,7 @@ export class MigrationCommandFactory {
|
|
|
148
148
|
CLIHelper.dump(colors.green('Creating migration with following queries:'));
|
|
149
149
|
CLIHelper.dump(colors.green('up:'));
|
|
150
150
|
CLIHelper.dump(ret.diff.up.map(sql => ' ' + sql).join('\n'), config);
|
|
151
|
-
/* v8 ignore
|
|
151
|
+
/* v8 ignore if */
|
|
152
152
|
if (config.getDriver().getPlatform().supportsDownMigrations()) {
|
|
153
153
|
CLIHelper.dump(colors.green('down:'));
|
|
154
154
|
CLIHelper.dump(ret.diff.down.map(sql => ' ' + sql).join('\n'), config);
|
|
@@ -84,7 +84,7 @@ export class SchemaCommandFactory {
|
|
|
84
84
|
if (args.dump) {
|
|
85
85
|
const m = `get${method.substr(0, 1).toUpperCase()}${method.substr(1)}SchemaSQL`;
|
|
86
86
|
const dump = await orm.schema[m](params);
|
|
87
|
-
/* v8 ignore
|
|
87
|
+
/* v8 ignore if */
|
|
88
88
|
if (dump) {
|
|
89
89
|
CLIHelper.dump(dump, orm.config);
|
|
90
90
|
successMessage = '';
|
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.77",
|
|
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.77",
|
|
57
|
+
"@mikro-orm/knex": "7.0.0-dev.77",
|
|
58
|
+
"mikro-orm": "7.0.0-dev.77",
|
|
59
59
|
"yargs": "17.7.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|