Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function callNativeResolution(request: PortablePath, issuer: PortablePath): NativePath | false {
if (issuer.endsWith(`/`))
issuer = ppath.join(issuer, toFilename(`internal.js`));
// Since we would need to create a fake module anyway (to call _resolveLookupPath that
// would give us the paths to give to _resolveFilename), we can as well not use
// the {paths} option at all, since it internally makes _resolveFilename create another
// fake module anyway.
return Module._resolveFilename(request, makeFakeModule(npath.fromPortablePath(issuer)), false, {plugnplay: false});
}
for (const locatorHash of visibleLocators) {
const dependency = project.storedPackages.get(locatorHash);
if (!dependency)
throw new Error(`Assertion failed: The package (${locatorHash}) should have been registered`);
if (dependency.bin.size === 0)
continue;
const linker = linkers.find(linker => linker.supportsPackage(dependency, linkerOptions));
if (!linker)
continue;
const packageLocation = await linker.findPackageLocation(dependency, linkerOptions);
for (const [name, target] of dependency.bin) {
binaries.set(name, [dependency, npath.fromPortablePath(ppath.resolve(packageLocation, target))]);
}
}
return binaries;
}
public resolveUnqualified(unqualified: PortablePath, opts?: {extensions?: Array}): PortablePath {
return npath.toPortablePath(this.pnp.resolveUnqualified(npath.fromPortablePath(unqualified), opts));
}
async findPackageLocator(location: PortablePath, opts: LinkOptions) {
const pnpPath = getPnpPath(opts.project);
if (!xfs.existsSync(pnpPath))
throw new UsageError(`The project in ${opts.project.cwd}/package.json doesn't seem to have been installed - running an install there might help`);
const physicalPath = npath.fromPortablePath(pnpPath);
const pnpFile = miscUtils.dynamicRequire(physicalPath);
delete require.cache[physicalPath];
const locator = pnpFile.findPackageLocator(npath.fromPortablePath(location));
if (!locator)
return null;
return structUtils.makeLocator(structUtils.parseIdent(locator.name), locator.reference);
}
function runBinary(path: PortablePath) {
const physicalPath = npath.fromPortablePath(path);
if (physicalPath) {
execFileSync(process.execPath, [physicalPath, ...process.argv.slice(2)], {
stdio: `inherit`,
env: {
...process.env,
YARN_IGNORE_PATH: `1`,
},
});
} else {
execFileSync(physicalPath, process.argv.slice(2), {
stdio: `inherit`,
env: {
...process.env,
YARN_IGNORE_PATH: `1`,
},
async findPackageLocator(location: PortablePath, opts: LinkOptions) {
const pnpPath = getPnpPath(opts.project);
if (!xfs.existsSync(pnpPath))
throw new UsageError(`The project in ${opts.project.cwd}/package.json doesn't seem to have been installed - running an install there might help`);
const physicalPath = npath.fromPortablePath(pnpPath);
const pnpFile = miscUtils.dynamicRequire(physicalPath);
delete require.cache[physicalPath];
const locator = pnpFile.findPackageLocator(npath.fromPortablePath(location));
if (!locator)
return null;
return structUtils.makeLocator(structUtils.parseIdent(locator.name), locator.reference);
}
async function fetchPreviousNonce(workspace: Workspace, {root, base}: {root: PortablePath, base: string}) {
const {code, stdout} = await execUtils.execvp(`git`, [`show`, `${base}:${npath.fromPortablePath(ppath.relative(root, ppath.join(workspace.cwd, `package.json` as Filename)))}`], {cwd: workspace.cwd});
if (code === 0) {
return getNonce(Manifest.fromText(stdout));
} else {
return null;
}
}
resolveRequest: maybeLog(`resolveRequest`, (request: NativePath, issuer: NativePath | null, opts?: ResolveRequestOptions) => {
const portableIssuer = issuer !== null ? npath.toPortablePath(issuer) : null;
const resolution = resolveRequest(npath.toPortablePath(request), portableIssuer, opts);
if (resolution === null)
return null;
return npath.fromPortablePath(resolution);
}),
public findPackageLocator(location: PortablePath): PackageLocator | null {
return this.pnp.findPackageLocator(npath.fromPortablePath(location));
}