MCPcopy
hub / github.com/yarnpkg/yarn / makeTemporaryEnv

Function makeTemporaryEnv

packages/pkg-tests/pkg-tests-core/sources/utils/tests.js:305–356  ·  view source on GitHub ↗
(packageJson, subDefinition, fn)

Source from the content-addressed store, hash-verified

303exports.generatePkgDriver = function generatePkgDriver({runDriver}: {|runDriver: PackageRunDriver|}): PackageDriver {
304 function withConfig(definition): PackageDriver {
305 const makeTemporaryEnv = (packageJson, subDefinition, fn) => {
306 if (typeof subDefinition === 'function') {
307 fn = subDefinition;
308 subDefinition = {};
309 }
310
311 if (typeof fn !== 'function') {
312 throw new Error(
313 // eslint-disable-next-line
314 `Invalid test function (got ${typeof fn}) - you probably put the closing parenthesis of the "makeTemporaryEnv" utility at the wrong place`,
315 );
316 }
317
318 return async function(): Promise<void> {
319 const path = await fsUtils.realpath(await fsUtils.createTemporaryFolder());
320
321 const registryUrl = await exports.startPackageServer();
322
323 // Writes a new package.json file into our temporary directory
324 await fsUtils.writeJson(`${path}/package.json`, await deepResolve(packageJson));
325
326 const run = (...args) => {
327 let callDefinition = {};
328
329 if (args.length > 0 && typeof args[args.length - 1] === 'object') {
330 callDefinition = args.pop();
331 }
332
333 return runDriver(path, args, {
334 registryUrl,
335 ...definition,
336 ...subDefinition,
337 ...callDefinition,
338 });
339 };
340
341 const source = async script => {
342 return JSON.parse((await run('node', '-p', `JSON.stringify((() => ${script})())`)).stdout.toString());
343 };
344
345 try {
346 await fn({
347 path,
348 run,
349 source,
350 });
351 } catch (error) {
352 error.message = `Temporary fixture folder: ${path}\n\n` + error.message;
353 throw error;
354 }
355 };
356 };
357
358 makeTemporaryEnv.withConfig = subDefinition => {
359 return withConfig({...definition, ...subDefinition});

Callers 7

script.jsFile · 0.85
pnp.jsFile · 0.85
workspace.jsFile · 0.85
lock.jsFile · 0.85
basic.jsFile · 0.85
pnpapi-v1.jsFile · 0.85
dragon.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…