Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use the default store and cache locations for pnpm #7039

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions scopes/dependencies/pnpm/lynx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { createPkgGraph } from '@pnpm/workspace.pkgs-graph';
import { PackageManifest, ProjectManifest, ReadPackageHook } from '@pnpm/types';
import { Logger } from '@teambit/logger';
import toNerfDart from 'nerf-dart';
import userHome from 'user-home';
import { pnpmErrorToBitError } from './pnpm-error-to-bit-error';
import { readConfig } from './read-config';

Expand All @@ -46,12 +45,12 @@ const STORE_CACHE: Record<string, { ctrl: StoreController; dir: string }> = {};
async function createStoreController(
options: {
rootDir: string;
storeDir: string;
storeDir?: string;
cacheDir: string;
registries: Registries;
proxyConfig: PackageManagerProxyConfig;
networkConfig: PackageManagerNetworkConfig;
} & Pick<CreateStoreControllerOptions, 'packageImportMethod'>
} & Pick<CreateStoreControllerOptions, 'packageImportMethod' | 'pnpmHomeDir'>
): Promise<{ ctrl: StoreController; dir: string }> {
const authConfig = getAuthConfig(options.registries);
const opts: CreateStoreControllerOptions = {
Expand All @@ -71,8 +70,8 @@ async function createStoreController(
maxSockets: options.networkConfig.maxSockets,
networkConcurrency: options.networkConfig.networkConcurrency,
packageImportMethod: options.packageImportMethod,
pnpmHomeDir: path.join(userHome, '.pnpm'), // This is not actually used in our case
resolveSymlinksInInjectedDirs: true,
pnpmHomeDir: options.pnpmHomeDir,
};
// We should avoid the recreation of store.
// The store holds cache that makes subsequent resolutions faster.
Expand Down Expand Up @@ -120,14 +119,14 @@ async function generateResolverAndFetcher(
export async function getPeerDependencyIssues(
manifestsByPaths: Record<string, any>,
opts: {
storeDir: string;
storeDir?: string;
cacheDir: string;
registries: Registries;
rootDir: string;
proxyConfig: PackageManagerProxyConfig;
networkConfig: PackageManagerNetworkConfig;
overrides?: Record<string, string>;
} & Pick<CreateStoreControllerOptions, 'packageImportMethod'>
} & Pick<CreateStoreControllerOptions, 'packageImportMethod' | 'pnpmHomeDir'>
): Promise<PeerDependencyIssuesByProjects> {
const projects: ProjectOptions[] = [];
const workspacePackages = {};
Expand Down Expand Up @@ -157,7 +156,7 @@ export async function getPeerDependencyIssues(
export async function install(
rootDir: string,
manifestsByPaths: Record<string, ProjectManifest>,
storeDir: string,
storeDir: string | undefined,
cacheDir: string,
registries: Registries,
proxyConfig: PackageManagerProxyConfig = {},
Expand All @@ -172,7 +171,7 @@ export async function install(
InstallOptions,
'publicHoistPattern' | 'hoistPattern' | 'nodeVersion' | 'engineStrict' | 'peerDependencyRules'
> &
Pick<CreateStoreControllerOptions, 'packageImportMethod'>,
Pick<CreateStoreControllerOptions, 'packageImportMethod' | 'pnpmHomeDir'>,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
logger?: Logger
) {
Expand Down Expand Up @@ -224,6 +223,7 @@ export async function install(
proxyConfig,
networkConfig,
packageImportMethod: options?.packageImportMethod,
pnpmHomeDir: options?.pnpmHomeDir,
});
const opts: InstallOptions = {
allProjects,
Expand Down
33 changes: 8 additions & 25 deletions scopes/dependencies/pnpm/pnpm.package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,12 @@ import { PeerDependencyIssuesByProjects } from '@pnpm/core';
import { readModulesManifest } from '@pnpm/modules-yaml';
import { ProjectManifest } from '@pnpm/types';
import { join } from 'path';
import userHome from 'user-home';
import { readConfig } from './read-config';

const defaultStoreDir = join(userHome, '.pnpm-store');
const defaultCacheDir = join(userHome, '.pnpm-cache');

export class PnpmPackageManager implements PackageManager {
private readConfig = memoize(readConfig);
constructor(private depResolver: DependencyResolverMain, private logger: Logger) {}

async _getGlobalPnpmDirs(
opts: {
cacheRootDir?: string;
packageManagerConfigRootDir?: string;
} = {}
) {
const { config } = await this.readConfig(opts.packageManagerConfigRootDir);
const storeDir = opts.cacheRootDir ? join(opts.cacheRootDir, '.pnpm-store') : config.storeDir ?? defaultStoreDir;
const cacheDir = opts.cacheRootDir ? join(opts.cacheRootDir, '.pnpm-cache') : config.cacheDir ?? defaultCacheDir;
return { storeDir, cacheDir };
}

async install(
{ rootDir, manifests }: InstallationContext,
installOptions: PackageManagerInstallOptions = {}
Expand All @@ -56,16 +40,15 @@ export class PnpmPackageManager implements PackageManager {
const registries = await this.depResolver.getRegistries();
const proxyConfig = await this.depResolver.getProxyConfig();
const networkConfig = await this.depResolver.getNetworkConfig();
const { storeDir, cacheDir } = await this._getGlobalPnpmDirs(installOptions);
const { config } = await this.readConfig(installOptions.packageManagerConfigRootDir);
if (!installOptions.useNesting) {
manifests = await extendWithComponentsFromDir(rootDir, manifests);
}
await install(
rootDir,
manifests,
storeDir,
cacheDir,
config.storeDir,
config.cacheDir,
registries,
proxyConfig,
networkConfig,
Expand All @@ -83,6 +66,7 @@ export class PnpmPackageManager implements PackageManager {
peerDependencyRules: installOptions.peerDependencyRules,
sideEffectsCacheRead: installOptions.sideEffectsCache ?? true,
sideEffectsCacheWrite: installOptions.sideEffectsCache ?? true,
pnpmHomeDir: config.pnpmHomeDir,
},
this.logger
);
Expand All @@ -97,17 +81,16 @@ export class PnpmPackageManager implements PackageManager {
manifests: Record<string, ProjectManifest>,
installOptions: PackageManagerInstallOptions = {}
): Promise<PeerDependencyIssuesByProjects> {
const { storeDir, cacheDir } = await this._getGlobalPnpmDirs(installOptions);
const proxyConfig = await this.depResolver.getProxyConfig();
const networkConfig = await this.depResolver.getNetworkConfig();
const registries = await this.depResolver.getRegistries();
// require it dynamically for performance purpose. the pnpm package require many files - do not move to static import
// eslint-disable-next-line global-require, import/no-dynamic-require
const lynx = require('./lynx');
const { config } = await this.readConfig();
const { config } = await this.readConfig(installOptions.packageManagerConfigRootDir);
return lynx.getPeerDependencyIssues(manifests, {
storeDir,
cacheDir,
storeDir: config.storeDir,
cacheDir: config.cacheDir,
proxyConfig,
registries,
rootDir,
Expand All @@ -124,11 +107,11 @@ export class PnpmPackageManager implements PackageManager {
// require it dynamically for performance purpose. the pnpm package require many files - do not move to static import
// eslint-disable-next-line global-require, import/no-dynamic-require
const { resolveRemoteVersion } = require('./lynx');
const { cacheDir } = await this._getGlobalPnpmDirs(options);
const registries = await this.depResolver.getRegistries();
const proxyConfig = await this.depResolver.getProxyConfig();
const networkConfig = await this.depResolver.getNetworkConfig();
return resolveRemoteVersion(packageName, options.rootDir, cacheDir, registries, proxyConfig, networkConfig);
const { config } = await this.readConfig(options.packageManagerConfigRootDir);
return resolveRemoteVersion(packageName, options.rootDir, config.cacheDir, registries, proxyConfig, networkConfig);
}

async getProxyConfig?(): Promise<PackageManagerProxyConfig> {
Expand Down