Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb0ec8de

Browse files
committed
Cache runtime results
1 parentc50424d commitb0ec8de

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

‎scripts/find-runtime.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Examples:
1919

2020
constproject=args[args.length-1];
2121

22-
import{findRuntime}from"../server/src/find-runtime.ts";
22+
import{findRescriptRuntimesInProject}from"../server/src/find-runtime.ts";
2323

24-
construntimes=awaitfindRuntime(project);
24+
construntimes=awaitfindRescriptRuntimesInProject(project);
2525

2626
console.log("Found @rescript/runtime directories:",runtimes);
2727

‎server/src/bsc-args/rewatch.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
IncrementallyCompiledFileInfo,
88
}from"../incrementalCompilation";
99
importtype{projectFiles}from"../projectFiles";
10-
import{findRuntime}from"../find-runtime";
10+
import{findRescriptRuntimesInProject}from"../find-runtime";
1111

1212
exporttypeRewatchCompilerArgs={
1313
compiler_args:Array<string>;
@@ -93,8 +93,9 @@ export async function getRewatchBscArgs(
9393
// TODO: We should check a potential configured value
9494
// Users should be able to provide this themselves if they like.
9595

96-
// TODO: We should also cache this value if we found it.
97-
constrescriptRuntimes=awaitfindRuntime(entry.project.workspaceRootPath);
96+
constrescriptRuntimes=awaitfindRescriptRuntimesInProject(
97+
entry.project.workspaceRootPath,
98+
);
9899

99100
if(debug()){
100101
if(rescriptRuntimes.length===0){

‎server/src/find-runtime.ts‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{readdir,statasstatAsync}from"fs/promises";
2-
import{join}from"path";
2+
import{join,resolve}from"path";
33

44
// Efficient parallel folder traversal to find node_modules directories
55
asyncfunctionfindNodeModulesDirs(
@@ -88,7 +88,7 @@ async function findDenoRescriptRuntime(nodeModulesPath: string) {
8888
returnresults;
8989
}
9090

91-
exportasyncfunctionfindRuntime(project:string){
91+
asyncfunctionfindRuntimePath(project:string){
9292
// Find all node_modules directories using efficient traversal
9393
constnode_modules=awaitfindNodeModulesDirs(project);
9494

@@ -117,5 +117,24 @@ export async function findRuntime(project: string) {
117117
}),
118118
).then((results)=>results.flatMap((x)=>x));
119119

120-
returnrescriptRuntimeDirs;
120+
returnrescriptRuntimeDirs.map((runtime)=>resolve(runtime));
121121
}
122+
123+
functionfindRuntimeCached(){
124+
constcache=newMap<string,string[]>();
125+
returnasync(project:string)=>{
126+
if(cache.has(project)){
127+
returncache.get(project)!;
128+
}
129+
construntimes=awaitfindRuntimePath(project);
130+
cache.set(project,runtimes);
131+
returnruntimes;
132+
};
133+
}
134+
135+
/**
136+
* Find all installed @rescript/runtime directories in the given project path.
137+
* In a perfect world, there should be exactly one.
138+
* This function is cached per project path.
139+
*/
140+
exportconstfindRescriptRuntimesInProject=findRuntimeCached();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp