MCPcopy Index your code
hub / github.com/code-pushup/cli / withLocalTmpDir

Function withLocalTmpDir

packages/plugin-lighthouse/src/lib/runner/utils.ts:207–232  ·  view source on GitHub ↗
(fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

205 * @returns Wrapped function which overrides `TEMP` environment variable, before cleaning up afterwards.
206 */
207export function withLocalTmpDir<T>(fn: () => Promise<T>): () => Promise<T> {
208 if (os.platform() !== 'win32') {
209 return fn;
210 }
211
212 return async () => {
213 const originalTmpDir = process.env['TEMP'];
214 const localPath = path.join(pluginWorkDir(LIGHTHOUSE_PLUGIN_SLUG), 'tmp');
215
216 // eslint-disable-next-line functional/immutable-data
217 process.env['TEMP'] = localPath;
218 logger.debug(
219 `Temporarily overwriting TEMP environment variable with ${localPath} to prevent permissions error on cleanup`,
220 );
221
222 try {
223 return await fn();
224 } finally {
225 // eslint-disable-next-line functional/immutable-data
226 process.env['TEMP'] = originalTmpDir;
227 logger.debug(
228 `Restored TEMP environment variable to original value ${originalTmpDir}`,
229 );
230 }
231 };
232}

Callers 2

createRunnerFunctionFunction · 0.85
utils.unit.test.tsFile · 0.85

Calls 3

pluginWorkDirFunction · 0.90
fnFunction · 0.50
debugMethod · 0.45

Tested by

no test coverage detected