@mikro-orm/cli 7.2.9-dev.25 → 7.2.9-dev.26

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
@@ -31,6 +31,8 @@ export declare class CLIHelper {
31
31
  * @param [from] Location to start the node resolution
32
32
  */
33
33
  private static resolveModulePath;
34
+ /** Resolves `id` from the project via its `exports`. `import.meta.resolve()` ignores `parent` without a flag. */
35
+ private static resolveFromProject;
34
36
  static dumpTable(options: {
35
37
  columns: string[];
36
38
  rows: string[][];
package/CLIHelper.js CHANGED
@@ -244,6 +244,33 @@ export class CLIHelper {
244
244
  parts.splice(idx, parts.length - idx);
245
245
  return parts.join('/');
246
246
  }
247
+ /** Resolves `id` from the project via its `exports`. `import.meta.resolve()` ignores `parent` without a flag. */
248
+ static resolveFromProject(id) {
249
+ const slash = id.indexOf('/', id.startsWith('@') ? id.indexOf('/') + 1 : 0);
250
+ const name = slash === -1 ? id : id.slice(0, slash);
251
+ const subpath = slash === -1 ? '' : id.slice(slash);
252
+ const root = createRequire(join(process.cwd(), 'noop.js'))
253
+ .resolve.paths(name)
254
+ ?.map(dir => join(dir, name))
255
+ .find(dir => fs.pathExists(join(dir, 'package.json')));
256
+ if (!root) {
257
+ return undefined;
258
+ }
259
+ const pick = (target) => {
260
+ if (typeof target === 'string') {
261
+ return target;
262
+ }
263
+ for (const [condition, value] of Object.entries(target ?? {})) {
264
+ const path = ['node', 'import', 'default'].includes(condition) ? pick(value) : undefined;
265
+ if (path) {
266
+ return path;
267
+ }
268
+ }
269
+ return undefined;
270
+ };
271
+ const target = pick(fs.readJSONSync(join(root, 'package.json')).exports?.[`.${subpath}`]);
272
+ return target ? pathToFileURL(join(root, target)).href : undefined;
273
+ }
247
274
  static dumpTable(options) {
248
275
  if (options.rows.length === 0) {
249
276
  return CLIHelper.dump(options.empty);
@@ -316,7 +343,9 @@ export class CLIHelper {
316
343
  const module = isEsm && esm ? esm : cjs;
317
344
  let mod;
318
345
  try {
319
- mod = await Utils.tryImport({ module });
346
+ const projectModule = this.resolveFromProject(module);
347
+ mod = projectModule ? await Utils.tryImport({ module: projectModule }) : undefined;
348
+ mod ??= await Utils.tryImport({ module });
320
349
  }
321
350
  catch (e) {
322
351
  const error = new Error(`Failed to load TypeScript loader \`${loader}\` (${module}): ${e.message}`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/cli",
3
- "version": "7.2.9-dev.25",
3
+ "version": "7.2.9-dev.26",
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.9-dev.25",
54
- "mikro-orm": "7.2.9-dev.25",
53
+ "@mikro-orm/core": "7.2.9-dev.26",
54
+ "mikro-orm": "7.2.9-dev.26",
55
55
  "yargs": "18.2.0"
56
56
  },
57
57
  "engines": {