-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Modules providers loading mechanism to infer the source dir (#8015)
* fix: Modules providers loading mechanism to infer the source dir * finalize
- Loading branch information
Showing
5 changed files
with
44 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/core/utils/src/common/normalize-import-path-with-source.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { join } from "path" | ||
|
||
/** | ||
* Normalize the import path based on the project running on ts-node or not. | ||
* @param path | ||
*/ | ||
export function normalizeImportPathWithSource( | ||
path: string | undefined | ||
): string { | ||
let normalizePath = path | ||
|
||
/** | ||
* If the project is running on ts-node all relative module resolution | ||
* will target the src directory and otherwise the dist directory. | ||
* If the path is not relative, then we can safely import from it and let the resolution | ||
* happen under the hood. | ||
*/ | ||
if (normalizePath?.startsWith("./")) { | ||
const sourceDir = process[Symbol.for("ts-node.register.instance")] | ||
? "src" | ||
: "dist" | ||
normalizePath = join(process.cwd(), sourceDir, normalizePath) | ||
} | ||
|
||
return normalizePath ?? "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters