@lyrolab/nest-shared 0.0.1 → 0.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyrolab/nest-shared",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "UNLICENSED",
@@ -0,0 +1,22 @@
1
+ import { existsSync } from "fs"
2
+ import { dirname, join } from "path"
3
+
4
+ export function findMainPath() {
5
+ const rootPath = findUp("package.json", process.cwd())
6
+ if (!rootPath) throw new Error("package.json not found")
7
+ return rootPath
8
+ }
9
+
10
+ function findUp(path: string, cwd: string) {
11
+ const currentPath = cwd
12
+ const parentPath = dirname(currentPath)
13
+ if (parentPath === currentPath) {
14
+ return null
15
+ }
16
+
17
+ if (existsSync(join(currentPath, path))) {
18
+ return currentPath
19
+ }
20
+
21
+ return findUp(path, parentPath)
22
+ }
@@ -2,6 +2,7 @@ import { DynamicModule, Module, OnModuleDestroy } from "@nestjs/common"
2
2
  import { ConfigModule, ConfigService } from "@nestjs/config"
3
3
  import { TypeOrmModule, TypeOrmModuleOptions } from "@nestjs/typeorm"
4
4
  import { join } from "path"
5
+ import { findMainPath } from "./helpers/find-main-path"
5
6
  import { GenericContainer, StartedTestContainer, Wait } from "testcontainers"
6
7
  import { DataSource } from "typeorm"
7
8
 
@@ -63,11 +64,11 @@ export class SharedDatabaseModule implements OnModuleDestroy {
63
64
  )}/test`
64
65
 
65
66
  const entities = options.entities || [
66
- join(__dirname, "../../../**/*.entity{.ts,.js}"),
67
+ join(findMainPath(), "**/*.entity{.ts,.js}"),
67
68
  ]
68
69
 
69
70
  const migrations = options.migrations || [
70
- join(__dirname, "../../../migrations/**/*.{ts,js}"),
71
+ join(findMainPath(), "src/migrations/**/*.{ts,js}"),
71
72
  ]
72
73
 
73
74
  if (!this.testDataSource) {