-
Notifications
You must be signed in to change notification settings - Fork 63
Use custom string types to better determine what a path is #1153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
e864320
be41c28
a41ae32
36121d6
30b57e0
3013116
a6056d2
01e1549
483aae3
718a6f7
d793679
add5596
b142a63
9159361
ef8269f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { readdir, stat as statAsync, readFile } from "fs/promises"; | ||
| import { join, resolve } from "path"; | ||
| import { compilerInfoPartialPath } from "./constants"; | ||
| import { NormalizedPath } from "./utils"; | ||
|
|
||
| // Efficient parallel folder traversal to find node_modules directories | ||
| async function findNodeModulesDirs( | ||
|
|
@@ -92,14 +93,16 @@ async function findRescriptRuntimeInAlternativeLayout( | |
| return results; | ||
| } | ||
|
|
||
| async function findRuntimePath(project: string): Promise<string[]> { | ||
| async function findRuntimePath( | ||
| project: NormalizedPath, | ||
| ): Promise<NormalizedPath[]> { | ||
| // Try a compiler-info.json file first | ||
| const compilerInfo = resolve(project, compilerInfoPartialPath); | ||
| try { | ||
| const contents = await readFile(compilerInfo, "utf8"); | ||
| const compileInfo: { runtime_path?: string } = JSON.parse(contents); | ||
| if (compileInfo && compileInfo.runtime_path) { | ||
| return [compileInfo.runtime_path]; | ||
| return [compileInfo.runtime_path as NormalizedPath]; | ||
| } | ||
| } catch { | ||
| // Ignore errors, fallback to node_modules search | ||
|
|
@@ -146,7 +149,9 @@ async function findRuntimePath(project: string): Promise<string[]> { | |
| }), | ||
| ).then((results) => results.flatMap((x) => x)); | ||
|
|
||
| return rescriptRuntimeDirs.map((runtime) => resolve(runtime)); | ||
| return rescriptRuntimeDirs.map( | ||
| (runtime) => resolve(runtime) as NormalizedPath, | ||
| ); | ||
|
Comment on lines
154
to
157
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -156,7 +161,7 @@ async function findRuntimePath(project: string): Promise<string[]> { | |
| * (see getRuntimePathFromWorkspaceRoot in utils.ts). | ||
| */ | ||
| export async function findRescriptRuntimesInProject( | ||
| project: string, | ||
| ): Promise<string[]> { | ||
| project: NormalizedPath, | ||
| ): Promise<NormalizedPath[]> { | ||
| return await findRuntimePath(project); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direct type assertion to
NormalizedPathassumesruntime_pathfrom JSON is already normalized. UsenormalizePath(compileInfo.runtime_path)to ensure it's actually normalized, and handle the null case appropriately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nojaf worth adding a comment here on why the
asis fine?