MCPcopy Create free account
hub / github.com/facebook/memlab / logScript

Method logScript

packages/e2e/src/ScriptManager.ts:126–156  ·  view source on GitHub ↗
(
    url: string,
    code: string,
    resourceType: string,
  )

Source from the content-addressed store, hash-verified

124 }
125
126 public async logScript(
127 url: string,
128 code: string,
129 resourceType: string,
130 ): Promise<void> {
131 if (this.urlToScriptMap.has(url)) {
132 return;
133 }
134 const metaFile = fileManager.getWebSourceMetaFile();
135 const file = path.join(
136 fileManager.getWebSourceDir(),
137 `${++this.fileId}${this.resourceTypeToSuffix(resourceType)}`,
138 );
139 const scriptInfo: ScriptInfo = {
140 url,
141 fileId: this.fileId,
142 codePath: file,
143 resourceType,
144 };
145 this.urlToScriptMap.set(url, scriptInfo);
146 this.scriptInfos.push(scriptInfo);
147 fs.writeFile(file, code, {encoding: 'utf8'}, () => {
148 // async write, do nothing here
149 });
150 // only write the latest version of the meta file state
151 this.debounce(() => {
152 fs.writeFileSync(metaFile, JSON.stringify(this.scriptInfos, void 0, 2), {
153 encoding: 'utf8',
154 });
155 }, 1000);
156 }
157
158 private debounce(callback: AnyFunction, timeout: number): void {
159 if (this.metaFileWriteTimeout) {

Callers 1

interceptScriptMethod · 0.80

Calls 6

resourceTypeToSuffixMethod · 0.95
debounceMethod · 0.95
getWebSourceMetaFileMethod · 0.80
getWebSourceDirMethod · 0.80
hasMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected