@mikro-orm/cli 7.2.0-dev.9 → 7.2.1-dev.0

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 CHANGED
@@ -37,18 +37,19 @@ export declare class CLIHelper {
37
37
  empty: string;
38
38
  }): void;
39
39
  /**
40
- * Tries to register TS support in the following order: oxc, swc, tsx, jiti, tsimp
40
+ * Tries to register TS support in the following order: oxc, swc, tsx, jiti, tsimp, nub
41
41
  * Use `MIKRO_ORM_CLI_TS_LOADER` env var to set the loader explicitly.
42
+ * `nub` is skipped when a custom tsconfig path is used, and it supports only the legacy decorators.
42
43
  * This method is used only in CLI context.
43
44
  */
44
- static registerTypeScriptSupport(configPath?: string, tsLoader?: 'oxc' | 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'auto'): Promise<boolean>;
45
+ static registerTypeScriptSupport(configPath?: string, tsLoader?: 'oxc' | 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'nub' | 'auto'): Promise<boolean>;
45
46
  static isESM(): boolean;
46
47
  static showHelp(): void;
47
48
  }
48
49
  export interface Settings {
49
50
  verbose?: boolean;
50
51
  preferTs?: boolean;
51
- tsLoader?: 'oxc' | 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'auto';
52
+ tsLoader?: 'oxc' | 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'nub' | 'auto';
52
53
  tsConfigPath?: string;
53
54
  configPaths?: string[];
54
55
  }
package/CLIHelper.js CHANGED
@@ -185,6 +185,9 @@ export class CLIHelper {
185
185
  case 'libsql':
186
186
  ret.driver ??= await import('@mikro-orm/libsql').then(m => m.LibSqlDriver);
187
187
  break;
188
+ case 'sql-js':
189
+ ret.driver ??= await import('@mikro-orm/sql-js').then(m => m.SqlJsDriver);
190
+ break;
188
191
  case 'oracledb':
189
192
  ret.driver ??= await import('@mikro-orm/oracledb').then(m => m.OracleDriver);
190
193
  break;
@@ -265,8 +268,9 @@ export class CLIHelper {
265
268
  CLIHelper.dump(ret);
266
269
  }
267
270
  /**
268
- * Tries to register TS support in the following order: oxc, swc, tsx, jiti, tsimp
271
+ * Tries to register TS support in the following order: oxc, swc, tsx, jiti, tsimp, nub
269
272
  * Use `MIKRO_ORM_CLI_TS_LOADER` env var to set the loader explicitly.
273
+ * `nub` is skipped when a custom tsconfig path is used, and it supports only the legacy decorators.
270
274
  * This method is used only in CLI context.
271
275
  */
272
276
  static async registerTypeScriptSupport(configPath = 'tsconfig.json', tsLoader) {
@@ -278,32 +282,62 @@ export class CLIHelper {
278
282
  process.env.TSIMP_PROJECT ??= configPath;
279
283
  process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS ??= '1';
280
284
  const explicitLoader = tsLoader ?? process.env.MIKRO_ORM_CLI_TS_LOADER ?? 'auto';
285
+ const usesDefaultTsConfig = fs.absolutePath(configPath) === fs.absolutePath('tsconfig.json');
281
286
  const setEsmImportProvider = () => {
282
287
  return (globalThis.dynamicImportProvider = (id) => import(id).then(mod => mod?.default ?? mod));
283
288
  };
289
+ if (explicitLoader === 'nub' && !usesDefaultTsConfig) {
290
+ throw new Error('The `nub` loader does not support a custom tsconfig path. Use the project tsconfig.json or select another loader.');
291
+ }
284
292
  const loaders = {
285
293
  oxc: { esm: '@oxc-node/core/register', cjs: '@oxc-node/core/register' },
286
294
  swc: { esm: '@swc-node/register/esm-register', cjs: '@swc-node/register' },
287
295
  tsx: { esm: 'tsx/esm/api', cjs: 'tsx/cjs/api', cb: (tsx) => tsx.register({ tsconfig: configPath }) },
288
296
  jiti: { cjs: 'jiti/register', cb: setEsmImportProvider },
289
297
  tsimp: { cjs: 'tsimp/import', cb: setEsmImportProvider },
298
+ nub: { esm: '@nubjs/loader', cjs: '@nubjs/loader' },
290
299
  };
300
+ const errors = [];
291
301
  for (const loader of Utils.keys(loaders)) {
302
+ if (loader === 'nub' && !usesDefaultTsConfig) {
303
+ continue;
304
+ }
292
305
  if (explicitLoader !== 'auto' && loader !== explicitLoader) {
293
306
  continue;
294
307
  }
295
308
  const { esm, cjs, cb } = loaders[loader];
296
309
  const isEsm = this.isESM();
297
310
  const module = isEsm && esm ? esm : cjs;
298
- const mod = await Utils.tryImport({ module });
311
+ let mod;
312
+ try {
313
+ mod = await Utils.tryImport({ module });
314
+ }
315
+ catch (e) {
316
+ const error = new Error(`Failed to load TypeScript loader \`${loader}\` (${module}): ${e.message}`, {
317
+ cause: e,
318
+ });
319
+ if (explicitLoader !== 'auto') {
320
+ throw error;
321
+ }
322
+ errors.push(error);
323
+ continue;
324
+ }
299
325
  if (mod) {
300
326
  cb?.(mod);
301
327
  process.env.MIKRO_ORM_CLI_TS_LOADER = loader;
302
328
  return true;
303
329
  }
304
330
  }
331
+ // a loader that is installed but broken is a real problem, not a missing dependency
332
+ if (errors.length > 0) {
333
+ throw new Error(errors.map(e => e.message).join('\n'), { cause: errors[0] });
334
+ }
335
+ const loadersMessage = usesDefaultTsConfig
336
+ ? '`oxc`, `swc`, `tsx`, `jiti`, `tsimp` nor `nub`'
337
+ : '`oxc`, `swc`, `tsx`, `jiti` nor `tsimp`';
338
+ const nubHint = usesDefaultTsConfig ? '' : ' The `nub` loader was skipped as a custom tsconfig path is configured.';
305
339
  // eslint-disable-next-line no-console
306
- console.warn('Neither `oxc`, `swc`, `tsx`, `jiti` nor `tsimp` found in the project dependencies, support for working with TypeScript files might not work. To use `oxc`, install `@oxc-node/core`. To use `swc`, install both `@swc-node/register` and `@swc/core`.');
340
+ console.warn(`Neither ${loadersMessage} found in the project dependencies, support for working with TypeScript files might not work.${nubHint} To use \`oxc\`, install \`@oxc-node/core\`. To use \`swc\`, install both \`@swc-node/register\` and \`@swc/core\`.`);
307
341
  return false;
308
342
  }
309
343
  static isESM() {
package/README.md CHANGED
@@ -24,6 +24,7 @@ npm install @mikro-orm/mysql # MySQL
24
24
  npm install @mikro-orm/mariadb # MariaDB
25
25
  npm install @mikro-orm/sqlite # SQLite
26
26
  npm install @mikro-orm/libsql # libSQL / Turso
27
+ npm install @mikro-orm/sql-js # sql.js (in-memory SQLite in WASM)
27
28
  npm install @mikro-orm/mongodb # MongoDB
28
29
  npm install @mikro-orm/mssql # MS SQL Server
29
30
  npm install @mikro-orm/oracledb # Oracle
@@ -10,6 +10,7 @@ const driverPackageMap = {
10
10
  MariaDbDriver: '@mikro-orm/mariadb',
11
11
  SqliteDriver: '@mikro-orm/sqlite',
12
12
  LibSqlDriver: '@mikro-orm/libsql',
13
+ SqlJsDriver: '@mikro-orm/sql-js',
13
14
  MsSqlDriver: '@mikro-orm/mssql',
14
15
  OracleDriver: '@mikro-orm/oracledb',
15
16
  MongoDriver: '@mikro-orm/mongodb',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/cli",
3
- "version": "7.2.0-dev.9",
3
+ "version": "7.2.1-dev.0",
4
4
  "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.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -50,8 +50,8 @@
50
50
  "copy": "node ../../scripts/copy.mjs"
51
51
  },
52
52
  "dependencies": {
53
- "@mikro-orm/core": "7.2.0-dev.9",
54
- "mikro-orm": "7.2.0-dev.9",
53
+ "@mikro-orm/core": "7.2.1-dev.0",
54
+ "mikro-orm": "7.2.1-dev.0",
55
55
  "yargs": "17.7.2"
56
56
  },
57
57
  "engines": {