Skip to content

Commit a8821b5

Browse files
committed
Add configuration option for the .store folder in pnpm mode called pnpmStoreFolder
1 parent 64d6a82 commit a8821b5

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed

.yarn/versions/81e42c15.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
releases:
2+
"@yarnpkg/cli": minor
3+
"@yarnpkg/plugin-pnpm": minor
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-init"
11+
- "@yarnpkg/plugin-interactive-tools"
12+
- "@yarnpkg/plugin-nm"
13+
- "@yarnpkg/plugin-npm-cli"
14+
- "@yarnpkg/plugin-pack"
15+
- "@yarnpkg/plugin-patch"
16+
- "@yarnpkg/plugin-pnp"
17+
- "@yarnpkg/plugin-stage"
18+
- "@yarnpkg/plugin-typescript"
19+
- "@yarnpkg/plugin-version"
20+
- "@yarnpkg/plugin-workspace-tools"
21+
- "@yarnpkg/builder"
22+
- "@yarnpkg/core"
23+
- "@yarnpkg/doctor"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {xfs, ppath} from '@yarnpkg/fslib';
2+
3+
const {
4+
fs: {FsLinkType, determineLinkType},
5+
} = require(`pkg-tests-core`);
6+
7+
const customStoreFolderName = `.customStore`;
8+
9+
describe(`Features`, () => {
10+
describe(`pnpmStoreLocation`, () => {
11+
test(
12+
`it should create the store at custom path and symlink all files to the custom store location`,
13+
makeTemporaryEnv(
14+
{
15+
dependencies: {[`no-deps`]: `1.0.0`},
16+
},
17+
{
18+
nodeLinker: `pnpm`,
19+
pnpmStoreFolder: customStoreFolderName,
20+
},
21+
async ({path, run, source}) => {
22+
await run(`install`);
23+
24+
// Ensure that the default node_modules/.store folder is not created
25+
expect(xfs.existsSync(ppath.join(path, `node_modules`, `.store`))).toEqual(false);
26+
27+
// Ensure that the customized folder is created
28+
const absolutePnpmStorePath = ppath.join(path, customStoreFolderName);
29+
expect(xfs.existsSync(absolutePnpmStorePath)).toEqual(true);
30+
31+
// Ensure that the installed package is a symbolic link
32+
const installedPackagePath = ppath.join(path, `node_modules`, `no-deps`);
33+
expect(await determineLinkType(installedPackagePath)).toEqual(FsLinkType.SYMBOLIC);
34+
35+
// Ensure that the link target is a relative path
36+
const installedPackageLinkTarget = await xfs.readlinkPromise(installedPackagePath);
37+
expect(ppath.isAbsolute(installedPackageLinkTarget)).toBeFalsy();
38+
39+
// Ensure that the resolved link target is within the customized pnpmStoreFolder.
40+
const resolvedPackageLinkTarget = ppath.join(ppath.dirname(installedPackagePath), installedPackageLinkTarget);
41+
expect(ppath.contains(absolutePnpmStorePath, resolvedPackageLinkTarget)).toBeTruthy();
42+
},
43+
),
44+
);
45+
});
46+
});

packages/docusaurus/static/configuration/yarnrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@
481481
"type": "string",
482482
"default": "pnp"
483483
},
484+
"pnpmStoreFolder": {
485+
"_package": "@yarnpkg/plugin-pnpm",
486+
"title": "Path where the pnpm store will be stored",
487+
"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.",
488+
"type": "string",
489+
"format": "uri-reference",
490+
"examples": [".cache/.store"]
491+
},
484492
"winLinkType": {
485493
"_package": "@yarnpkg/core",
486494
"title": "Define whether to use junctions or symlinks when creating links on Windows.",

packages/plugin-pnpm/sources/PnpmLinker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function getNodeModulesLocation(project: Project) {
309309
}
310310

311311
function getStoreLocation(project: Project) {
312-
return ppath.join(getNodeModulesLocation(project), `.store`);
312+
return project.configuration.get(`pnpmStoreFolder`);
313313
}
314314

315315
function getPackagePaths(locator: Locator, {project}: {project: Project}) {

packages/plugin-pnpm/sources/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
import {Plugin} from '@yarnpkg/core';
1+
import {Plugin, SettingsType} from '@yarnpkg/core';
2+
import {PortablePath} from '@yarnpkg/fslib';
23

3-
import {PnpmLinker} from './PnpmLinker';
4+
import {PnpmLinker} from './PnpmLinker';
45

56
export {PnpmLinker};
67

8+
declare module '@yarnpkg/core' {
9+
interface ConfigurationValueMap {
10+
pnpmStoreFolder: PortablePath;
11+
}
12+
}
13+
714
const plugin: Plugin = {
15+
configuration: {
16+
pnpmStoreFolder: {
17+
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.`,
18+
type: SettingsType.ABSOLUTE_PATH,
19+
default: `./node_modules/.store`,
20+
},
21+
},
822
linkers: [
923
PnpmLinker,
1024
],

0 commit comments

Comments
 (0)