Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) {
// If the patch is statically defined (ie absolute or a builtin), then we
// don't need to bind the descriptor to its parent
const {patchPaths} = patchUtils.parseDescriptor(descriptor);
if (patchPaths.every(patchPath => !patchUtils.isParentRequired(patchPath)))
return descriptor;
return structUtils.bindDescriptor(descriptor, {
locator: structUtils.stringifyLocator(fromLocator),
});
}
bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) {
if (FILE_REGEXP.test(descriptor.range))
descriptor = structUtils.makeDescriptor(descriptor, `${PROTOCOL}${descriptor.range}`);
return structUtils.bindDescriptor(descriptor, {
locator: structUtils.stringifyLocator(fromLocator),
});
}
export async function extractPackageToDisk(locator: Locator, {cache, project}: {cache: Cache, project: Project}) {
const checksums = project.storedChecksums;
const report = new ThrowReport();
const fetcher = project.configuration.makeFetcher();
const fetchResult = await fetcher.fetch(locator, {cache, project, fetcher, checksums, report});
const temp = await xfs.mktempPromise();
await xfs.copyPromise(temp, fetchResult.prefixPath, {
baseFs: fetchResult.packageFs,
});
await xfs.writeJsonPromise(ppath.join(temp, `.yarn-patch.json` as Filename), {
locator: structUtils.stringifyLocator(locator),
});
return temp;
}
const sortedWorkspaces = miscUtils.sortMap(project.workspaces, workspace => {
return structUtils.stringifyLocator(workspace.anchoredLocator);
});
private async generatePackage(locator: Locator, generatorPath: PortablePath, opts: FetchOptions) {
const cwd = npath.toPortablePath(dirSync().name);
const env = await scriptUtils.makeScriptEnv({project: opts.project});
const logFile = npath.toPortablePath(tmpNameSync({
prefix: `buildfile-`,
postfix: `.log`,
}));
const stdin = null;
const stdout = xfs.createWriteStream(logFile);
const stderr = stdout;
stdout.write(`# This file contains the result of Yarn generating a package (${structUtils.stringifyLocator(locator)})\n`);
stdout.write(`\n`);
const {code} = await execUtils.pipevp(process.execPath, [npath.fromPortablePath(generatorPath), structUtils.stringifyIdent(locator)], {cwd, env, stdin, stdout, stderr});
if (code !== 0)
throw new Error(`Package generation failed (exit code ${code}, logs can be found here: ${logFile})`);
return cwd;
}
}
function makeSpec({parentLocator, sourceItem, patchPaths, patchHash}: {parentLocator: Locator | null, sourceItem: T, patchPaths: Array, patchHash?: string}, sourceStringifier: (source: T) => string) {
const parentLocatorSpread = parentLocator !== null
? {parentLocator: structUtils.stringifyLocator(parentLocator)}
: {} as {};
const patchHashSpread = typeof patchHash !== `undefined`
? {hash: patchHash}
: {} as {};
return structUtils.makeRange({
protocol: `patch:`,
source: sourceStringifier(sourceItem),
selector: patchPaths.join(`&`),
params: {
...parentLocatorSpread,
...patchHashSpread,
},
});
}
bindDescriptor(descriptor: Descriptor, fromLocator: Locator, opts: MinimalResolveOptions) {
return structUtils.bindDescriptor(descriptor, {
locator: structUtils.stringifyLocator(fromLocator),
});
}