Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async attachInternalDependencies(locator: Locator, dependencies: Array<[Descriptor, Locator]>) {
const packageInformation = this.getPackageInformation(locator);
for (const [descriptor, locator] of dependencies) {
const target = !structUtils.areIdentsEqual(descriptor, locator)
? [structUtils.requirableIdent(locator), locator.reference] as [string, string]
: locator.reference;
packageInformation.packageDependencies.set(structUtils.requirableIdent(descriptor), target);
}
}
pkg.peerDependencies.size > 0 &&
!structUtils.isVirtualLocator(pkg) &&
!this.opts.project.tryWorkspaceByLocator(pkg);
const packageFs = !hasVirtualInstances && pkg.linkType !== LinkType.SOFT && (buildScripts.length > 0 || this.isUnplugged(pkg, dependencyMeta))
? await this.unplugPackage(pkg, fetchResult.packageFs)
: fetchResult.packageFs;
const packageRawLocation = ppath.resolve(packageFs.getRealPath(), ppath.relative(PortablePath.root, fetchResult.prefixPath));
const packageLocation = this.normalizeDirectoryPath(packageRawLocation);
const packageDependencies = new Map();
const packagePeers = new Set();
for (const descriptor of pkg.peerDependencies.values()) {
packageDependencies.set(structUtils.requirableIdent(descriptor), null);
packagePeers.add(descriptor.name);
}
const packageStore = this.getPackageStore(key1);
packageStore.set(key2, {packageLocation, packageDependencies, packagePeers, linkType: pkg.linkType});
if (hasVirtualInstances)
this.blacklistedPaths.add(packageLocation);
return {
packageLocation,
buildDirective: buildScripts.length > 0 ? buildScripts as BuildDirective[] : null,
};
}
private getPackageInformation(locator: Locator) {
const key1 = structUtils.requirableIdent(locator);
const key2 = locator.reference;
const packageInformationStore = this.packageRegistry.get(key1);
if (!packageInformationStore)
throw new Error(`Assertion failed: The package information store should have been available (for ${structUtils.prettyIdent(this.opts.project.configuration, locator)})`);
const packageInformation = packageInformationStore.get(key2);
if (!packageInformation)
throw new Error(`Assertion failed: The package information should have been available (for ${structUtils.prettyLocator(this.opts.project.configuration, locator)})`);
return packageInformation;
}
private getPackageInformation(locator: Locator) {
const key1 = structUtils.requirableIdent(locator);
const key2 = locator.reference;
const packageInformationStore = this.packageRegistry.get(key1);
if (!packageInformationStore)
throw new Error(`Assertion failed: The package information store should have been available (for ${structUtils.prettyIdent(this.opts.project.configuration, locator)})`);
const packageInformation = packageInformationStore.get(key2);
if (!packageInformation)
throw new Error(`Assertion failed: The package information should have been available (for ${structUtils.prettyLocator(this.opts.project.configuration, locator)})`);
return packageInformation;
}
async attachInternalDependencies(locator: Locator, dependencies: Array<[Descriptor, Locator]>) {
const packageInformation = this.getPackageInformation(locator);
for (const [descriptor, locator] of dependencies) {
const target = !structUtils.areIdentsEqual(descriptor, locator)
? [structUtils.requirableIdent(locator), locator.reference] as [string, string]
: locator.reference;
packageInformation.packageDependencies.set(structUtils.requirableIdent(descriptor), target);
}
}
async attachExternalDependents(locator: Locator, dependentPaths: Array) {
for (const dependentPath of dependentPaths) {
const packageInformation = this.getDiskInformation(dependentPath);
packageInformation.packageDependencies.set(structUtils.requirableIdent(locator), locator.reference);
}
}
async findPackageLocation(locator: Locator, 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 pnpFile = miscUtils.dynamicRequireNoCache(pnpPath);
const packageLocator = {name: structUtils.requirableIdent(locator), reference: locator.reference};
const packageInformation = pnpFile.getPackageInformation(packageLocator);
if (!packageInformation)
throw new UsageError(`Couldn't find ${structUtils.prettyLocator(opts.project.configuration, locator)} in the currently installed PnP map - running an install might help`);
return npath.toPortablePath(packageInformation.packageLocation);
}
async findPackageLocation(locator: Locator, 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 packageLocator = {name: structUtils.requirableIdent(locator), reference: locator.reference};
const packageInformation = pnpFile.getPackageInformation(packageLocator);
if (!packageInformation)
throw new UsageError(`Couldn't find ${structUtils.prettyLocator(opts.project.configuration, locator)} in the currently installed PnP map - running an install might help`);
return npath.toPortablePath(packageInformation.packageLocation);
}
const dependencyTreeRoots = this.opts.project.workspaces.map(({anchoredLocator}) => ({name: structUtils.requirableIdent(anchoredLocator), reference: anchoredLocator.reference}));
const enableTopLevelFallback = pnpFallbackMode !== `none`;