Skip to content

Add configuration option to configure .store folder in pnpm mode #6710

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

Merged
merged 2 commits into from
Mar 5, 2025
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
23 changes: 23 additions & 0 deletions .yarn/versions/81e42c15.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": minor
"@yarnpkg/plugin-pnpm": minor

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {xfs, ppath} from '@yarnpkg/fslib';

const {
fs: {FsLinkType, determineLinkType},
} = require(`pkg-tests-core`);

const customStoreFolderName = `.customStore`;

describe(`Features`, () => {
describe(`pnpmStoreLocation`, () => {
test(
`it should create the store at custom path and symlink all files to the custom store location`,
makeTemporaryEnv(
{
dependencies: {[`no-deps`]: `1.0.0`},
},
{
nodeLinker: `pnpm`,
pnpmStoreFolder: customStoreFolderName,
winLinkType: `symlinks`,
},
async ({path, run, source}) => {
await run(`install`);

// Ensure that the customized folder is created
const absolutePnpmStorePath = ppath.join(path, customStoreFolderName);
expect(xfs.existsSync(absolutePnpmStorePath)).toEqual(true);

// Ensure that the default node_modules/.store folder is not created
expect(xfs.existsSync(ppath.join(path, `node_modules`, `.store`))).toEqual(false);

// Ensure that the installed package is a symbolic link
const installedPackagePath = ppath.join(path, `node_modules`, `no-deps`);
expect(await determineLinkType(installedPackagePath)).toEqual(FsLinkType.SYMBOLIC);

// Ensure that the link target is a relative path
const installedPackageLinkTarget = await xfs.readlinkPromise(installedPackagePath);
expect(ppath.isAbsolute(installedPackageLinkTarget)).toBeFalsy();

// Ensure that the resolved link target is within the customized pnpmStoreFolder.
const resolvedPackageLinkTarget = ppath.join(ppath.dirname(installedPackagePath), installedPackageLinkTarget);
expect(ppath.contains(absolutePnpmStorePath, resolvedPackageLinkTarget)).toBeTruthy();
},
),
);
});
});
8 changes: 8 additions & 0 deletions packages/docusaurus/static/configuration/yarnrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,14 @@
"type": "string",
"default": "pnp"
},
"pnpmStoreFolder": {
"_package": "@yarnpkg/plugin-pnpm",
"title": "Path where the pnpm store will be stored",
"description": "By default, the store is stored in the `node_modules/.store` of the project. Sometimes in CI scenario's it is convenient to store this in a different location so it can be cached and reused.",
"type": "string",
"format": "uri-reference",
"examples": [".cache/.store"]
},
"winLinkType": {
"_package": "@yarnpkg/core",
"title": "Define whether to use junctions or symlinks when creating links on Windows.",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pnpm/sources/PnpmLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function getNodeModulesLocation(project: Project) {
}

function getStoreLocation(project: Project) {
return ppath.join(getNodeModulesLocation(project), `.store`);
return project.configuration.get(`pnpmStoreFolder`);
}

function getPackagePaths(locator: Locator, {project}: {project: Project}) {
Expand Down
18 changes: 16 additions & 2 deletions packages/plugin-pnpm/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import {Plugin} from '@yarnpkg/core';
import {Plugin, SettingsType} from '@yarnpkg/core';
import {PortablePath} from '@yarnpkg/fslib';

import {PnpmLinker} from './PnpmLinker';
import {PnpmLinker} from './PnpmLinker';

export {PnpmLinker};

declare module '@yarnpkg/core' {
interface ConfigurationValueMap {
pnpmStoreFolder: PortablePath;
}
}

const plugin: Plugin = {
configuration: {
pnpmStoreFolder: {
description: `By default, the store is stored in the 'node_modules/.store' of the project. Sometimes in CI scenario's it is convenient to store this in a different location so it can be cached and reused.`,
type: SettingsType.ABSOLUTE_PATH,
default: `./node_modules/.store`,
},
},
linkers: [
PnpmLinker,
],
Expand Down
Loading