@yarnpkg/plugin-pnpm 2.0.0-rc.5 → 2.0.0-rc.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,14 @@
1
1
  import { Descriptor, FetchResult, Installer, InstallPackageExtraApi, Linker, LinkOptions, Locator, LocatorHash, MinimalLinkOptions, Package } from '@yarnpkg/core';
2
2
  import { PortablePath } from '@yarnpkg/fslib';
3
- export declare type PnpmCustomData = {
4
- pathByLocator: Map<LocatorHash, PortablePath>;
3
+ export type PnpmCustomData = {
5
4
  locatorByPath: Map<PortablePath, string>;
5
+ pathsByLocator: Map<LocatorHash, {
6
+ packageLocation: PortablePath;
7
+ dependenciesLocation: PortablePath | null;
8
+ }>;
6
9
  };
7
10
  export declare class PnpmLinker implements Linker {
11
+ getCustomDataKey(): string;
8
12
  supportsPackage(pkg: Package, opts: MinimalLinkOptions): boolean;
9
13
  findPackageLocation(locator: Locator, opts: LinkOptions): Promise<PortablePath>;
10
14
  findPackageLocator(location: PortablePath, opts: LinkOptions): Promise<Locator | null>;
@@ -14,24 +18,21 @@ export declare class PnpmLinker implements Linker {
14
18
  declare class PnpmInstaller implements Installer {
15
19
  private opts;
16
20
  private readonly asyncActions;
21
+ private readonly indexFolderPromise;
17
22
  constructor(opts: LinkOptions);
18
- getCustomDataKey(): string;
19
23
  private customData;
20
24
  attachCustomData(customData: any): void;
21
25
  installPackage(pkg: Package, fetchResult: FetchResult, api: InstallPackageExtraApi): Promise<{
22
26
  packageLocation: PortablePath;
23
- buildDirective: null;
24
- } | {
25
- packageLocation: PortablePath;
26
- buildDirective: import("@yarnpkg/core").BuildDirective[];
27
+ buildRequest: import("@yarnpkg/core").BuildRequest | null;
27
28
  }>;
28
29
  installPackageSoft(pkg: Package, fetchResult: FetchResult, api: InstallPackageExtraApi): Promise<{
29
30
  packageLocation: PortablePath;
30
- buildDirective: null;
31
+ buildRequest: null;
31
32
  }>;
32
33
  installPackageHard(pkg: Package, fetchResult: FetchResult, api: InstallPackageExtraApi): Promise<{
33
34
  packageLocation: PortablePath;
34
- buildDirective: import("@yarnpkg/core").BuildDirective[];
35
+ buildRequest: import("@yarnpkg/core").BuildRequest | null;
35
36
  }>;
36
37
  attachInternalDependencies(locator: Locator, dependencies: Array<[Descriptor, Locator]>): Promise<void>;
37
38
  attachExternalDependents(locator: Locator, dependentPaths: Array<PortablePath>): Promise<void>;
package/lib/PnpmLinker.js CHANGED
@@ -6,26 +6,32 @@ const fslib_1 = require("@yarnpkg/fslib");
6
6
  const plugin_pnp_1 = require("@yarnpkg/plugin-pnp");
7
7
  const clipanion_1 = require("clipanion");
8
8
  class PnpmLinker {
9
+ getCustomDataKey() {
10
+ return JSON.stringify({
11
+ name: `PnpmLinker`,
12
+ version: 3,
13
+ });
14
+ }
9
15
  supportsPackage(pkg, opts) {
10
16
  return this.isEnabled(opts);
11
17
  }
12
18
  async findPackageLocation(locator, opts) {
13
19
  if (!this.isEnabled(opts))
14
20
  throw new Error(`Assertion failed: Expected the pnpm linker to be enabled`);
15
- const customDataKey = getCustomDataKey();
16
- const customData = opts.project.installersCustomData.get(customDataKey);
21
+ const customDataKey = this.getCustomDataKey();
22
+ const customData = opts.project.linkersCustomData.get(customDataKey);
17
23
  if (!customData)
18
24
  throw new clipanion_1.UsageError(`The project in ${core_1.formatUtils.pretty(opts.project.configuration, `${opts.project.cwd}/package.json`, core_1.formatUtils.Type.PATH)} doesn't seem to have been installed - running an install there might help`);
19
- const packageLocation = customData.pathByLocator.get(locator.locatorHash);
20
- if (typeof packageLocation === `undefined`)
25
+ const packagePaths = customData.pathsByLocator.get(locator.locatorHash);
26
+ if (typeof packagePaths === `undefined`)
21
27
  throw new clipanion_1.UsageError(`Couldn't find ${core_1.structUtils.prettyLocator(opts.project.configuration, locator)} in the currently installed pnpm map - running an install might help`);
22
- return packageLocation;
28
+ return packagePaths.packageLocation;
23
29
  }
24
30
  async findPackageLocator(location, opts) {
25
31
  if (!this.isEnabled(opts))
26
32
  return null;
27
- const customDataKey = getCustomDataKey();
28
- const customData = opts.project.installersCustomData.get(customDataKey);
33
+ const customDataKey = this.getCustomDataKey();
34
+ const customData = opts.project.linkersCustomData.get(customDataKey);
29
35
  if (!customData)
30
36
  throw new clipanion_1.UsageError(`The project in ${core_1.formatUtils.pretty(opts.project.configuration, `${opts.project.cwd}/package.json`, core_1.formatUtils.Type.PATH)} doesn't seem to have been installed - running an install there might help`);
31
37
  const nmRootLocation = location.match(/(^.*\/node_modules\/(@[^/]*\/)?[^/]+)(\/.*$)/);
@@ -60,13 +66,12 @@ class PnpmInstaller {
60
66
  this.opts = opts;
61
67
  this.asyncActions = new core_1.miscUtils.AsyncActions(10);
62
68
  this.customData = {
63
- pathByLocator: new Map(),
69
+ pathsByLocator: new Map(),
64
70
  locatorByPath: new Map(),
65
71
  };
66
- // Nothing to do
67
- }
68
- getCustomDataKey() {
69
- return getCustomDataKey();
72
+ this.indexFolderPromise = (0, fslib_1.setupCopyIndex)(fslib_1.xfs, {
73
+ indexPath: fslib_1.ppath.join(opts.project.configuration.get(`globalFolder`), `index`),
74
+ });
70
75
  }
71
76
  attachCustomData(customData) {
72
77
  // We don't want to attach the data because it's only used in the Linker and we'll recompute it anyways in the Installer,
@@ -80,40 +85,51 @@ class PnpmInstaller {
80
85
  throw new Error(`Assertion failed: Unsupported package link type`);
81
86
  }
82
87
  async installPackageSoft(pkg, fetchResult, api) {
83
- const pkgPath = fslib_1.ppath.resolve(fetchResult.packageFs.getRealPath(), fetchResult.prefixPath);
84
- this.customData.pathByLocator.set(pkg.locatorHash, pkgPath);
88
+ const packageLocation = fslib_1.ppath.resolve(fetchResult.packageFs.getRealPath(), fetchResult.prefixPath);
89
+ const dependenciesLocation = this.opts.project.tryWorkspaceByLocator(pkg)
90
+ ? fslib_1.ppath.join(packageLocation, fslib_1.Filename.nodeModules)
91
+ : null;
92
+ this.customData.pathsByLocator.set(pkg.locatorHash, {
93
+ packageLocation,
94
+ dependenciesLocation,
95
+ });
85
96
  return {
86
- packageLocation: pkgPath,
87
- buildDirective: null,
97
+ packageLocation,
98
+ buildRequest: null,
88
99
  };
89
100
  }
90
101
  async installPackageHard(pkg, fetchResult, api) {
91
- var _a;
92
- const pkgPath = getPackageLocation(pkg, { project: this.opts.project });
93
- this.customData.locatorByPath.set(pkgPath, core_1.structUtils.stringifyLocator(pkg));
94
- this.customData.pathByLocator.set(pkg.locatorHash, pkgPath);
102
+ const packagePaths = getPackagePaths(pkg, { project: this.opts.project });
103
+ const packageLocation = packagePaths.packageLocation;
104
+ this.customData.locatorByPath.set(packageLocation, core_1.structUtils.stringifyLocator(pkg));
105
+ this.customData.pathsByLocator.set(pkg.locatorHash, packagePaths);
95
106
  api.holdFetchResult(this.asyncActions.set(pkg.locatorHash, async () => {
96
- await fslib_1.xfs.mkdirPromise(pkgPath, { recursive: true });
107
+ await fslib_1.xfs.mkdirPromise(packageLocation, { recursive: true });
97
108
  // Copy the package source into the <root>/n_m/.store/<hash> directory, so
98
109
  // that we can then create symbolic links to it later.
99
- await fslib_1.xfs.copyPromise(pkgPath, fetchResult.prefixPath, {
110
+ await fslib_1.xfs.copyPromise(packageLocation, fetchResult.prefixPath, {
100
111
  baseFs: fetchResult.packageFs,
101
112
  overwrite: false,
113
+ linkStrategy: {
114
+ type: `HardlinkFromIndex`,
115
+ indexPath: await this.indexFolderPromise,
116
+ autoRepair: true,
117
+ },
102
118
  });
103
119
  }));
104
120
  const isVirtual = core_1.structUtils.isVirtualLocator(pkg);
105
121
  const devirtualizedLocator = isVirtual ? core_1.structUtils.devirtualizeLocator(pkg) : pkg;
106
122
  const buildConfig = {
107
- manifest: (_a = await core_1.Manifest.tryFind(fetchResult.prefixPath, { baseFs: fetchResult.packageFs })) !== null && _a !== void 0 ? _a : new core_1.Manifest(),
123
+ manifest: await core_1.Manifest.tryFind(fetchResult.prefixPath, { baseFs: fetchResult.packageFs }) ?? new core_1.Manifest(),
108
124
  misc: {
109
125
  hasBindingGyp: plugin_pnp_1.jsInstallUtils.hasBindingGyp(fetchResult),
110
126
  },
111
127
  };
112
128
  const dependencyMeta = this.opts.project.getDependencyMeta(devirtualizedLocator, pkg.version);
113
- const buildScripts = plugin_pnp_1.jsInstallUtils.extractBuildScripts(pkg, buildConfig, dependencyMeta, { configuration: this.opts.project.configuration, report: this.opts.report });
129
+ const buildRequest = plugin_pnp_1.jsInstallUtils.extractBuildRequest(pkg, buildConfig, dependencyMeta, { configuration: this.opts.project.configuration });
114
130
  return {
115
- packageLocation: pkgPath,
116
- buildDirective: buildScripts,
131
+ packageLocation,
132
+ buildRequest,
117
133
  };
118
134
  }
119
135
  async attachInternalDependencies(locator, dependencies) {
@@ -122,31 +138,33 @@ class PnpmInstaller {
122
138
  // We don't install those packages at all, because they can't be used anyway
123
139
  if (!isPnpmVirtualCompatible(locator, { project: this.opts.project }))
124
140
  return;
141
+ const packagePaths = this.customData.pathsByLocator.get(locator.locatorHash);
142
+ if (typeof packagePaths === `undefined`)
143
+ throw new Error(`Assertion failed: Expected the package to have been registered (${core_1.structUtils.stringifyLocator(locator)})`);
144
+ const { dependenciesLocation, } = packagePaths;
145
+ if (!dependenciesLocation)
146
+ return;
125
147
  this.asyncActions.reduce(locator.locatorHash, async (action) => {
126
- // Wait that the package is properly installed before starting to copy things into it
127
- await action;
128
- const pkgPath = this.customData.pathByLocator.get(locator.locatorHash);
129
- if (typeof pkgPath === `undefined`)
130
- throw new Error(`Assertion failed: Expected the package to have been registered (${core_1.structUtils.stringifyLocator(locator)})`);
131
- const nmPath = fslib_1.ppath.join(pkgPath, fslib_1.Filename.nodeModules);
132
- const concurrentPromises = [];
148
+ await fslib_1.xfs.mkdirPromise(dependenciesLocation, { recursive: true });
133
149
  // Retrieve what's currently inside the package's true nm folder. We
134
150
  // will use that to figure out what are the extraneous entries we'll
135
151
  // need to remove.
136
- const extraneous = await getNodeModulesListing(nmPath);
137
- for (const [descriptor, dependency] of dependencies) {
152
+ const initialEntries = await getNodeModulesListing(dependenciesLocation);
153
+ const extraneous = new Map(initialEntries);
154
+ const concurrentPromises = [action];
155
+ const installDependency = (descriptor, dependency) => {
138
156
  // Downgrade virtual workspaces (cf isPnpmVirtualCompatible's documentation)
139
157
  let targetDependency = dependency;
140
158
  if (!isPnpmVirtualCompatible(dependency, { project: this.opts.project })) {
141
- this.opts.report.reportWarning(core_1.MessageName.UNNAMED, `The pnpm linker doesn't support providing different versions to workspaces' peer dependencies`);
159
+ this.opts.report.reportWarningOnce(core_1.MessageName.UNNAMED, `The pnpm linker doesn't support providing different versions to workspaces' peer dependencies`);
142
160
  targetDependency = core_1.structUtils.devirtualizeLocator(dependency);
143
161
  }
144
- const depSrcPath = this.customData.pathByLocator.get(targetDependency.locatorHash);
145
- if (typeof depSrcPath === `undefined`)
162
+ const depSrcPaths = this.customData.pathsByLocator.get(targetDependency.locatorHash);
163
+ if (typeof depSrcPaths === `undefined`)
146
164
  throw new Error(`Assertion failed: Expected the package to have been registered (${core_1.structUtils.stringifyLocator(dependency)})`);
147
165
  const name = core_1.structUtils.stringifyIdent(descriptor);
148
- const depDstPath = fslib_1.ppath.join(nmPath, name);
149
- const depLinkPath = fslib_1.ppath.relative(fslib_1.ppath.dirname(depDstPath), depSrcPath);
166
+ const depDstPath = fslib_1.ppath.join(dependenciesLocation, name);
167
+ const depLinkPath = fslib_1.ppath.relative(fslib_1.ppath.dirname(depDstPath), depSrcPaths.packageLocation);
150
168
  const existing = extraneous.get(name);
151
169
  extraneous.delete(name);
152
170
  concurrentPromises.push(Promise.resolve().then(async () => {
@@ -160,15 +178,23 @@ class PnpmInstaller {
160
178
  }
161
179
  }
162
180
  await fslib_1.xfs.mkdirpPromise(fslib_1.ppath.dirname(depDstPath));
163
- if (process.platform == `win32`) {
164
- await fslib_1.xfs.symlinkPromise(depSrcPath, depDstPath, `junction`);
181
+ if (process.platform == `win32` && this.opts.project.configuration.get(`winLinkType`) === core_1.WindowsLinkType.JUNCTIONS) {
182
+ await fslib_1.xfs.symlinkPromise(depSrcPaths.packageLocation, depDstPath, `junction`);
165
183
  }
166
184
  else {
167
185
  await fslib_1.xfs.symlinkPromise(depLinkPath, depDstPath);
168
186
  }
169
187
  }));
188
+ };
189
+ let hasExplicitSelfDependency = false;
190
+ for (const [descriptor, dependency] of dependencies) {
191
+ if (descriptor.identHash === locator.identHash)
192
+ hasExplicitSelfDependency = true;
193
+ installDependency(descriptor, dependency);
170
194
  }
171
- concurrentPromises.push(cleanNodeModules(nmPath, extraneous));
195
+ if (!hasExplicitSelfDependency && !this.opts.project.tryWorkspaceByLocator(locator))
196
+ installDependency(core_1.structUtils.convertLocatorToDescriptor(locator), locator);
197
+ concurrentPromises.push(cleanNodeModules(dependenciesLocation, extraneous));
172
198
  await Promise.all(concurrentPromises);
173
199
  });
174
200
  }
@@ -181,46 +207,25 @@ class PnpmInstaller {
181
207
  await fslib_1.xfs.removePromise(storeLocation);
182
208
  }
183
209
  else {
184
- const removals = [];
185
- const expectedEntries = new Set();
186
- for (const packageLocation of this.customData.pathByLocator.values()) {
187
- const subpath = fslib_1.ppath.contains(storeLocation, packageLocation);
188
- if (subpath !== null) {
189
- const [storeEntry, /* Filename.nodeModules */ , ...identComponents] = subpath.split(fslib_1.ppath.sep);
190
- expectedEntries.add(storeEntry);
191
- const storeEntryPath = fslib_1.ppath.join(storeLocation, storeEntry);
192
- removals.push(fslib_1.xfs.readdirPromise(storeEntryPath)
193
- .then(entries => {
194
- return Promise.all(entries.map(async (entry) => {
195
- const p = fslib_1.ppath.join(storeEntryPath, entry);
196
- if (entry === fslib_1.Filename.nodeModules) {
197
- const extraneous = await getNodeModulesListing(p);
198
- extraneous.delete(identComponents.join(fslib_1.ppath.sep));
199
- return cleanNodeModules(p, extraneous);
200
- }
201
- else {
202
- return fslib_1.xfs.removePromise(p);
203
- }
204
- }));
205
- })
206
- .catch(error => {
207
- if (error.code !== `ENOENT`) {
208
- throw error;
209
- }
210
- }));
211
- }
212
- }
213
- let storeRecords;
210
+ let extraneous;
214
211
  try {
215
- storeRecords = await fslib_1.xfs.readdirPromise(storeLocation);
212
+ extraneous = new Set(await fslib_1.xfs.readdirPromise(storeLocation));
216
213
  }
217
214
  catch {
218
- storeRecords = [];
215
+ extraneous = new Set();
216
+ }
217
+ for (const { dependenciesLocation } of this.customData.pathsByLocator.values()) {
218
+ if (!dependenciesLocation)
219
+ continue;
220
+ const subpath = fslib_1.ppath.contains(storeLocation, dependenciesLocation);
221
+ if (subpath === null)
222
+ continue;
223
+ const [storeEntry] = subpath.split(fslib_1.ppath.sep);
224
+ extraneous.delete(storeEntry);
219
225
  }
220
- for (const record of storeRecords)
221
- if (!expectedEntries.has(record))
222
- removals.push(fslib_1.xfs.removePromise(fslib_1.ppath.join(storeLocation, record)));
223
- await Promise.all(removals);
226
+ await Promise.all([...extraneous].map(async (extraneousEntry) => {
227
+ await fslib_1.xfs.removePromise(fslib_1.ppath.join(storeLocation, extraneousEntry));
228
+ }));
224
229
  }
225
230
  // Wait for the package installs to catch up
226
231
  await this.asyncActions.wait();
@@ -232,23 +237,18 @@ class PnpmInstaller {
232
237
  };
233
238
  }
234
239
  }
235
- function getCustomDataKey() {
236
- return JSON.stringify({
237
- name: `PnpmInstaller`,
238
- version: 2,
239
- });
240
- }
241
240
  function getNodeModulesLocation(project) {
242
241
  return fslib_1.ppath.join(project.cwd, fslib_1.Filename.nodeModules);
243
242
  }
244
243
  function getStoreLocation(project) {
245
244
  return fslib_1.ppath.join(getNodeModulesLocation(project), `.store`);
246
245
  }
247
- function getPackageLocation(locator, { project }) {
246
+ function getPackagePaths(locator, { project }) {
248
247
  const pkgKey = core_1.structUtils.slugifyLocator(locator);
249
- const prefixPath = core_1.structUtils.getIdentVendorPath(locator);
250
- const pkgPath = fslib_1.ppath.join(getStoreLocation(project), pkgKey, prefixPath);
251
- return pkgPath;
248
+ const storeLocation = getStoreLocation(project);
249
+ const packageLocation = fslib_1.ppath.join(storeLocation, pkgKey, `package`);
250
+ const dependenciesLocation = fslib_1.ppath.join(storeLocation, pkgKey, fslib_1.Filename.nodeModules);
251
+ return { packageLocation, dependenciesLocation };
252
252
  }
253
253
  function isPnpmVirtualCompatible(locator, { project }) {
254
254
  // The pnpm install strategy has a limitation: because Node would always
@@ -303,12 +303,11 @@ async function getNodeModulesListing(nmPath) {
303
303
  return listing;
304
304
  }
305
305
  async function cleanNodeModules(nmPath, extraneous) {
306
- var _a;
307
306
  const removeNamePromises = [];
308
307
  const scopesToRemove = new Set();
309
308
  for (const name of extraneous.keys()) {
310
309
  removeNamePromises.push(fslib_1.xfs.removePromise(fslib_1.ppath.join(nmPath, name)));
311
- const scope = (_a = core_1.structUtils.tryParseIdent(name)) === null || _a === void 0 ? void 0 : _a.scope;
310
+ const scope = core_1.structUtils.tryParseIdent(name)?.scope;
312
311
  if (scope) {
313
312
  scopesToRemove.add(`@${scope}`);
314
313
  }
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import { Plugin } from '@yarnpkg/core';
2
+ import { PnpmLinker } from './PnpmLinker';
3
+ export { PnpmLinker };
2
4
  declare const plugin: Plugin;
3
5
  export default plugin;
package/lib/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PnpmLinker = void 0;
3
4
  const PnpmLinker_1 = require("./PnpmLinker");
5
+ Object.defineProperty(exports, "PnpmLinker", { enumerable: true, get: function () { return PnpmLinker_1.PnpmLinker; } });
4
6
  const plugin = {
5
7
  linkers: [
6
8
  PnpmLinker_1.PnpmLinker,
package/package.json CHANGED
@@ -1,23 +1,27 @@
1
1
  {
2
2
  "name": "@yarnpkg/plugin-pnpm",
3
- "version": "2.0.0-rc.5",
3
+ "version": "2.0.0-rc.51",
4
4
  "license": "BSD-2-Clause",
5
5
  "main": "./lib/index.js",
6
+ "exports": {
7
+ ".": "./lib/index.js",
8
+ "./package.json": "./package.json"
9
+ },
6
10
  "dependencies": {
7
- "@yarnpkg/fslib": "^3.0.0-rc.5",
8
- "@yarnpkg/plugin-pnp": "^4.0.0-rc.5",
9
- "@yarnpkg/plugin-stage": "^4.0.0-rc.5",
10
- "clipanion": "^3.2.0-rc.10",
11
+ "@yarnpkg/fslib": "^3.0.0-rc.51",
12
+ "@yarnpkg/plugin-pnp": "^4.0.0-rc.51",
13
+ "@yarnpkg/plugin-stage": "^4.0.0-rc.51",
14
+ "clipanion": "^4.0.0-rc.2",
11
15
  "p-limit": "^2.2.0",
12
- "tslib": "^1.13.0"
16
+ "tslib": "^2.4.0"
13
17
  },
14
18
  "peerDependencies": {
15
- "@yarnpkg/cli": "^4.0.0-rc.5",
16
- "@yarnpkg/core": "^4.0.0-rc.5"
19
+ "@yarnpkg/cli": "^4.0.0-rc.51",
20
+ "@yarnpkg/core": "^4.0.0-rc.51"
17
21
  },
18
22
  "devDependencies": {
19
- "@yarnpkg/cli": "^4.0.0-rc.5",
20
- "@yarnpkg/core": "^4.0.0-rc.5"
23
+ "@yarnpkg/cli": "^4.0.0-rc.51",
24
+ "@yarnpkg/core": "^4.0.0-rc.51"
21
25
  },
22
26
  "repository": {
23
27
  "type": "git",
@@ -30,14 +34,16 @@
30
34
  },
31
35
  "publishConfig": {
32
36
  "main": "./lib/index.js",
33
- "typings": "./lib/index.d.ts"
37
+ "exports": {
38
+ ".": "./lib/index.js",
39
+ "./package.json": "./package.json"
40
+ }
34
41
  },
35
42
  "files": [
36
43
  "/lib/**/*"
37
44
  ],
38
45
  "engines": {
39
- "node": ">=14.15.0"
46
+ "node": ">=18.12.0"
40
47
  },
41
- "stableVersion": "1.1.0",
42
- "typings": "./lib/index.d.ts"
48
+ "stableVersion": "1.1.3"
43
49
  }