@teambit/pnpm 1.0.1123 → 1.0.1125

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.
Files changed (38) hide show
  1. package/.npmignore +18 -0
  2. package/dist/get-proxy-config.d.ts +2 -7
  3. package/dist/get-proxy-config.js +4 -7
  4. package/dist/get-proxy-config.js.map +1 -1
  5. package/dist/get-registries.d.ts +2 -2
  6. package/dist/get-registries.js +23 -93
  7. package/dist/get-registries.js.map +1 -1
  8. package/dist/load-pnpm-esm.cjs +19 -0
  9. package/dist/lockfile-deps-graph-converter.d.ts +17 -1
  10. package/dist/lockfile-deps-graph-converter.js +101 -32
  11. package/dist/lockfile-deps-graph-converter.js.map +1 -1
  12. package/dist/lockfile-deps-graph-converter.spec.js +200 -5
  13. package/dist/lockfile-deps-graph-converter.spec.js.map +1 -1
  14. package/dist/lynx.d.ts +53 -5
  15. package/dist/lynx.js +378 -322
  16. package/dist/lynx.js.map +1 -1
  17. package/dist/lynx.spec.d.ts +1 -0
  18. package/dist/lynx.spec.js +55 -0
  19. package/dist/lynx.spec.js.map +1 -0
  20. package/dist/pnpm-error-to-bit-error.d.ts +17 -2
  21. package/dist/pnpm-error-to-bit-error.js +7 -0
  22. package/dist/pnpm-error-to-bit-error.js.map +1 -1
  23. package/dist/pnpm-error-to-bit-error.spec.js +10 -11
  24. package/dist/pnpm-error-to-bit-error.spec.js.map +1 -1
  25. package/dist/pnpm-prune-modules.js +18 -8
  26. package/dist/pnpm-prune-modules.js.map +1 -1
  27. package/dist/pnpm.package-manager.d.ts +3 -4
  28. package/dist/pnpm.package-manager.js +168 -60
  29. package/dist/pnpm.package-manager.js.map +1 -1
  30. package/dist/pnpm.package-manager.spec.d.ts +1 -0
  31. package/dist/pnpm.package-manager.spec.js +48 -0
  32. package/dist/pnpm.package-manager.spec.js.map +1 -0
  33. package/dist/{preview-1785446962235.js → preview-1785493814568.js} +2 -2
  34. package/dist/read-config.d.ts +7 -1
  35. package/dist/read-config.js +22 -14
  36. package/dist/read-config.js.map +1 -1
  37. package/load-pnpm-esm.cjs +19 -0
  38. package/package.json +21 -33
@@ -46,30 +46,16 @@ function _lockfile() {
46
46
  };
47
47
  return data;
48
48
  }
49
- function _modulesYaml() {
50
- const data = require("@pnpm/modules-yaml");
51
- _modulesYaml = function () {
49
+ function _depsInspection() {
50
+ const data = require("@pnpm/deps.inspection.tree-builder");
51
+ _depsInspection = function () {
52
52
  return data;
53
53
  };
54
54
  return data;
55
55
  }
56
- function _reviewing() {
57
- const data = require("@pnpm/reviewing.dependencies-hierarchy");
58
- _reviewing = function () {
59
- return data;
60
- };
61
- return data;
62
- }
63
- function _list() {
64
- const data = require("@pnpm/list");
65
- _list = function () {
66
- return data;
67
- };
68
- return data;
69
- }
70
- function _lockfile2() {
71
- const data = require("@pnpm/lockfile.fs");
72
- _lockfile2 = function () {
56
+ function _depsInspection2() {
57
+ const data = require("@pnpm/deps.inspection.list");
58
+ _depsInspection2 = function () {
73
59
  return data;
74
60
  };
75
61
  return data;
@@ -116,19 +102,29 @@ function _pnpmPruneModules() {
116
102
  };
117
103
  return data;
118
104
  }
119
- function _lynx() {
120
- const data = require("./lynx");
121
- _lynx = function () {
122
- return data;
123
- };
124
- return data;
125
- }
126
105
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
127
106
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
128
107
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
129
108
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
130
109
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
131
110
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
111
+ let pnpmEsmPromise;
112
+ function loadPnpmEsm() {
113
+ pnpmEsmPromise ??= (async () => {
114
+ const {
115
+ loadEsm
116
+ } = require('./load-pnpm-esm.cjs');
117
+ const {
118
+ lockfileFs,
119
+ modulesYaml
120
+ } = await loadEsm();
121
+ return {
122
+ lockfileFs,
123
+ modulesYaml
124
+ };
125
+ })();
126
+ return pnpmEsmPromise;
127
+ }
132
128
  class PnpmPackageManager {
133
129
  constructor(depResolver, logger, cloud) {
134
130
  this.depResolver = depResolver;
@@ -157,31 +153,43 @@ class PnpmPackageManager {
157
153
  _defineProperty(this, "readConfig", (0, _lodash().memoize)(this._readConfig));
158
154
  }
159
155
  async dependenciesGraphToLockfile(dependenciesGraph, opts) {
156
+ await (0, _lockfileDepsGraphConverter().init)();
160
157
  const registries = opts.registries ?? new (_pkgEntities().Registries)(new (_pkgEntities().Registry)('https://node-registry.bit.cloud', false), {});
158
+ // eslint-disable-next-line global-require, import/no-dynamic-require
159
+ const {
160
+ generateResolverAndFetcher
161
+ } = require('./lynx');
161
162
  const {
162
163
  resolve
163
- } = await (0, _lynx().generateResolverAndFetcher)(_objectSpread(_objectSpread({}, opts), {}, {
164
+ } = await generateResolverAndFetcher(_objectSpread(_objectSpread({}, opts), {}, {
164
165
  registries
165
166
  }));
166
167
  const graphLockfile = await (0, _lockfileDepsGraphConverter().convertGraphToLockfile)(dependenciesGraph, _objectSpread(_objectSpread({}, opts), {}, {
167
168
  resolve
168
169
  }));
170
+ const {
171
+ lockfileFs: {
172
+ readWantedLockfile,
173
+ writeLockfileFile,
174
+ convertToLockfileFile: convertLockfileObjectToLockfileFile
175
+ }
176
+ } = await loadPnpmEsm();
169
177
  // Merge the graph-derived subset into any existing wanted lockfile rather than
170
178
  // overwriting. Only the importers, packages, and snapshots referenced by the
171
179
  // imported components' subgraph are re-stated here; every other workspace dep's
172
180
  // locked version must be preserved so pnpm doesn't re-resolve it to a newer
173
181
  // registry version.
174
- const existingLockfile = await (0, _lockfile2().readWantedLockfile)(opts.rootDir, {
182
+ const existingLockfile = await readWantedLockfile(opts.rootDir, {
175
183
  ignoreIncompatible: true
176
184
  });
177
- const mergedLockfile = existingLockfile ? mergeGraphLockfileIntoExisting((0, _lockfile2().convertToLockfileFile)(existingLockfile), graphLockfile) : graphLockfile;
185
+ const mergedLockfile = existingLockfile ? mergeGraphLockfileIntoExisting(convertLockfileObjectToLockfileFile(existingLockfile), graphLockfile) : graphLockfile;
178
186
  Object.assign(mergedLockfile, {
179
187
  bit: _objectSpread(_objectSpread({}, mergedLockfile.bit), {}, {
180
188
  restoredFromModel: true
181
189
  })
182
190
  });
183
191
  const lockfilePath = (0, _path().join)(opts.rootDir, 'pnpm-lock.yaml');
184
- await (0, _lockfile2().writeLockfileFile)(lockfilePath, mergedLockfile);
192
+ await writeLockfileFile(lockfilePath, mergedLockfile);
185
193
  this.logger.debug(`generated a lockfile from dependencies graph at ${lockfilePath}`);
186
194
  if (process.env.DEPS_GRAPH_LOG) {
187
195
  // eslint-disable-next-line no-console
@@ -239,6 +247,7 @@ class PnpmPackageManager {
239
247
  });
240
248
  }
241
249
  this.modulesManifestCache.delete(rootDir);
250
+ const hoistPattern = resolveHoistPattern(installOptions.hoistPatterns, config.hoistPattern);
242
251
  const {
243
252
  dependenciesChanged,
244
253
  rebuild,
@@ -263,7 +272,7 @@ class PnpmPackageManager {
263
272
  dedupeInjectedDeps: installOptions.dedupeInjectedDeps ?? false,
264
273
  dryRun: installOptions.dependenciesGraph == null && installOptions.dryRun,
265
274
  overrides: installOptions.overrides,
266
- hoistPattern: installOptions.hoistPatterns ?? config.hoistPattern,
275
+ hoistPattern,
267
276
  publicHoistPattern: config.shamefullyHoist ? ['*'] : ['@eslint/plugin-*', '*eslint-plugin*', '@prettier/plugin-*', '*prettier-plugin-*'],
268
277
  hoistWorkspacePackages: installOptions.hoistWorkspacePackages ?? false,
269
278
  hoistInjectedDependencies: installOptions.hoistInjectedDependencies,
@@ -358,35 +367,44 @@ class PnpmPackageManager {
358
367
  const {
359
368
  config
360
369
  } = await this.readConfig();
361
- const configuredUserAgent = config.rawConfig['user-agent'];
370
+ const configuredUserAgent = config.userAgent;
362
371
  if (!configuredUserAgent && !this.username) {
363
372
  this.username = (await this.cloud.getCurrentUser())?.username ?? 'anonymous';
364
373
  }
365
- // We need to use config.rawConfig as it will only contain the settings defined by the user.
366
- // config contains default values of the settings when they are not defined by the user.
367
374
  const result = {
368
375
  userAgent: configuredUserAgent ?? `bit user/${this.username}`
369
376
  };
370
- if (config.rawConfig['max-sockets'] != null) {
371
- result.maxSockets = config.rawConfig['max-sockets'];
377
+ // The resolved config carries the engine's defaults for the numeric
378
+ // network settings, and anything returned here overrides Bit's global
379
+ // network config in the dependency resolver's merge — so only settings
380
+ // the user explicitly configured may pass through. `explicitSettings`
381
+ // ships in @pnpm/napi > 12.0.0-beta.2; on older engines nothing is
382
+ // forwarded and the engine still honors `.npmrc` itself.
383
+ const explicitSettings = new Set(config.explicitSettings ?? []);
384
+ if (config.maxSockets != null && explicitSettings.has('maxSockets')) {
385
+ result.maxSockets = config.maxSockets;
372
386
  }
373
- if (config.rawConfig['network-concurrency'] != null) {
374
- result.networkConcurrency = config.rawConfig['network-concurrency'];
387
+ if (config.networkConcurrency != null && explicitSettings.has('networkConcurrency')) {
388
+ result.networkConcurrency = config.networkConcurrency;
375
389
  }
376
- if (config.rawConfig['fetch-retries'] != null) {
377
- result.fetchRetries = config.rawConfig['fetch-retries'];
390
+ if (config.fetchRetries != null && explicitSettings.has('fetchRetries')) {
391
+ result.fetchRetries = config.fetchRetries;
378
392
  }
379
- if (config.rawConfig['fetch-timeout'] != null) {
380
- result.fetchTimeout = config.rawConfig['fetch-timeout'];
393
+ if (config.fetchTimeout != null && explicitSettings.has('fetchTimeout')) {
394
+ result.fetchTimeout = config.fetchTimeout;
381
395
  }
382
- if (config.rawConfig['fetch-retry-maxtimeout'] != null) {
383
- result.fetchRetryMaxtimeout = config.rawConfig['fetch-retry-maxtimeout'];
396
+ if (config.fetchRetryMaxtimeout != null && explicitSettings.has('fetchRetryMaxtimeout')) {
397
+ result.fetchRetryMaxtimeout = config.fetchRetryMaxtimeout;
384
398
  }
385
- if (config.rawConfig['fetch-retry-mintimeout'] != null) {
386
- result.fetchRetryMintimeout = config.rawConfig['fetch-retry-mintimeout'];
399
+ if (config.fetchRetryMintimeout != null && explicitSettings.has('fetchRetryMintimeout')) {
400
+ result.fetchRetryMintimeout = config.fetchRetryMintimeout;
387
401
  }
388
- if (config.rawConfig['strict-ssl'] != null) {
389
- result.strictSSL = config.rawConfig['strict-ssl'];
402
+ // Unlike the numeric settings above, strictSsl/ca/cert/key are optional
403
+ // in the engine's projection and populated only when explicitly
404
+ // configured (the engine applies its own defaults at client-build
405
+ // time), so presence is already the explicit gate.
406
+ if (config.strictSsl != null) {
407
+ result.strictSSL = config.strictSsl;
390
408
  }
391
409
  if (config.ca != null) {
392
410
  result.ca = config.ca;
@@ -432,7 +450,12 @@ class PnpmPackageManager {
432
450
  if (this.modulesManifestCache.has(lockfileDir)) {
433
451
  return this.modulesManifestCache.get(lockfileDir);
434
452
  }
435
- const modulesManifest = await (0, _modulesYaml().readModulesManifest)((0, _path().join)(lockfileDir, 'node_modules'));
453
+ const {
454
+ modulesYaml: {
455
+ readModulesManifest
456
+ }
457
+ } = await loadPnpmEsm();
458
+ const modulesManifest = await readModulesManifest((0, _path().join)(lockfileDir, 'node_modules'));
436
459
  if (modulesManifest) {
437
460
  this.modulesManifestCache.set(lockfileDir, modulesManifest);
438
461
  }
@@ -445,7 +468,12 @@ class PnpmPackageManager {
445
468
  return (0, _pnpmPruneModules().pnpmPruneModules)(rootDir);
446
469
  }
447
470
  async findUsages(depName, opts) {
448
- const lockfile = await (0, _lockfile2().readWantedLockfile)(opts.lockfileDir, {
471
+ const {
472
+ lockfileFs: {
473
+ readWantedLockfile
474
+ }
475
+ } = await loadPnpmEsm();
476
+ const lockfile = await readWantedLockfile(opts.lockfileDir, {
449
477
  ignoreIncompatible: false
450
478
  });
451
479
  if (!lockfile) return '';
@@ -459,7 +487,7 @@ class PnpmPackageManager {
459
487
  version: pkgJson?.version ?? ''
460
488
  });
461
489
  }
462
- const trees = await (0, _reviewing().buildDependentsTree)([depName], projectPaths, {
490
+ const trees = await (0, _depsInspection().buildDependentsTree)([depName], projectPaths, {
463
491
  include: {
464
492
  dependencies: true,
465
493
  devDependencies: true,
@@ -484,7 +512,7 @@ class PnpmPackageManager {
484
512
  return manifest.name;
485
513
  }
486
514
  });
487
- return (0, _list().renderDependentsTree)(trees, {
515
+ return (0, _depsInspection2().renderDependentsTree)(trees, {
488
516
  depth: opts.depth ?? Infinity,
489
517
  long: false
490
518
  });
@@ -494,7 +522,14 @@ class PnpmPackageManager {
494
522
  * Calculating the dependencies graph of a given component using the lockfile.
495
523
  */
496
524
  async calcDependenciesGraph(opts) {
497
- const originalLockfile = await (0, _lockfile2().readWantedLockfile)(opts.rootDir, {
525
+ await (0, _lockfileDepsGraphConverter().init)();
526
+ const {
527
+ lockfileFs: {
528
+ readWantedLockfile,
529
+ convertToLockfileFile: convertLockfileObjectToLockfileFile
530
+ }
531
+ } = await loadPnpmEsm();
532
+ const originalLockfile = await readWantedLockfile(opts.rootDir, {
498
533
  ignoreIncompatible: false
499
534
  });
500
535
  if (!originalLockfile) {
@@ -532,16 +567,27 @@ class PnpmPackageManager {
532
567
  importers: _objectSpread(_objectSpread({}, originalLockfile.importers), clonedImporters)
533
568
  });
534
569
  for (const importerId of filterByImporterIds) {
535
- for (const depType of ['dependencies', 'devDependencies', 'optionalDependencies', 'specifiers', 'dependenciesMeta']) {
536
- for (const workspacePkgName of opts.componentIdByPkgName.keys()) {
537
- if (workspacePkgName !== pkgName) {
538
- delete lockfile.importers[importerId]?.[depType]?.[workspacePkgName];
539
- }
570
+ const importer = lockfile.importers[importerId];
571
+ if (importer == null) continue;
572
+ for (const workspacePkgName of opts.componentIdByPkgName.keys()) {
573
+ if (workspacePkgName === pkgName) continue;
574
+ // In the component's own importer, an injected sibling (a "file:"
575
+ // ref) is a real direct dependency of this component — the graph
576
+ // converter rewrites it to the component's semver id. Entries in
577
+ // any other importer (e.g. the capsule/workspace root) merely
578
+ // wire the workspace together and must not leak into this
579
+ // component's graph.
580
+ if (importerId === componentImporterId) {
581
+ const ref = importer.dependencies?.[workspacePkgName] ?? importer.devDependencies?.[workspacePkgName] ?? importer.optionalDependencies?.[workspacePkgName];
582
+ if (typeof ref === 'string' && ref.startsWith('file:')) continue;
583
+ }
584
+ for (const depType of ['dependencies', 'devDependencies', 'optionalDependencies', 'specifiers', 'dependenciesMeta']) {
585
+ delete importer[depType]?.[workspacePkgName];
540
586
  }
541
587
  }
542
588
  }
543
589
  // Filters the lockfile so that it only includes packages related to the given component.
544
- const partialLockfile = (0, _lockfile2().convertToLockfileFile)((0, _lockfile().filterLockfileByImporters)(lockfile, filterByImporterIds, {
590
+ const partialLockfile = convertLockfileObjectToLockfileFile((0, _lockfile().filterLockfileByImporters)(lockfile, filterByImporterIds, {
545
591
  include: {
546
592
  dependencies: true,
547
593
  devDependencies: true,
@@ -560,6 +606,16 @@ class PnpmPackageManager {
560
606
  }
561
607
  }
562
608
  exports.PnpmPackageManager = PnpmPackageManager;
609
+ function resolveHoistPattern(hoistPatternsFromBitConfig, hoistPatternFromPnpmConfig) {
610
+ if (hoistPatternsFromBitConfig == null) return hoistPatternFromPnpmConfig ?? ['*'];
611
+ if (isDefaultHoistPattern(hoistPatternsFromBitConfig) && hoistPatternFromPnpmConfig && !isDefaultHoistPattern(hoistPatternFromPnpmConfig)) {
612
+ return hoistPatternFromPnpmConfig;
613
+ }
614
+ return hoistPatternsFromBitConfig;
615
+ }
616
+ function isDefaultHoistPattern(hoistPattern) {
617
+ return hoistPattern.length === 1 && hoistPattern[0] === '*';
618
+ }
563
619
  function tryReadPackageJson(pkgDir) {
564
620
  try {
565
621
  return JSON.parse(_fs().default.readFileSync((0, _path().join)(pkgDir, 'package.json'), 'utf8'));
@@ -611,6 +667,7 @@ function mergeGraphLockfileIntoExisting(existing, graph) {
611
667
  depsRequiringBuild: mergedDepsRequiringBuild
612
668
  });
613
669
  }
670
+ pruneUnreachableLockfileEntries(merged);
614
671
  return merged;
615
672
  }
616
673
  function mergeEntryRecords(existing, graph) {
@@ -623,5 +680,56 @@ function mergeEntryRecords(existing, graph) {
623
680
  }
624
681
  return merged;
625
682
  }
683
+ function pruneUnreachableLockfileEntries(lockfile) {
684
+ const reachablePackages = new Set();
685
+ const reachableSnapshots = new Set();
686
+ // An explicit stack: deep dependency chains would overflow the call
687
+ // stack with a recursive walk.
688
+ const stack = [];
689
+ const visit = depPath => {
690
+ stack.push(depPath);
691
+ while (stack.length > 0) {
692
+ const current = stack.pop();
693
+ if (reachableSnapshots.has(current)) continue;
694
+ reachableSnapshots.add(current);
695
+ reachablePackages.add(removePeerSuffix(current));
696
+ const snapshot = lockfile.snapshots?.[current];
697
+ if (!snapshot) continue;
698
+ for (const depType of ['dependencies', 'optionalDependencies']) {
699
+ for (const [name, ref] of Object.entries(snapshot[depType] ?? {})) {
700
+ if (ref.startsWith('link:') || ref.startsWith('file:')) continue;
701
+ stack.push(`${name}@${ref}`);
702
+ }
703
+ }
704
+ }
705
+ };
706
+ for (const importer of Object.values(lockfile.importers ?? {})) {
707
+ for (const depType of ['dependencies', 'devDependencies', 'optionalDependencies']) {
708
+ for (const [name, dep] of Object.entries(importer[depType] ?? {})) {
709
+ const version = typeof dep === 'string' ? dep : dep.version;
710
+ if (!version || version.startsWith('link:') || version.startsWith('file:')) continue;
711
+ visit(`${name}@${version}`);
712
+ }
713
+ }
714
+ }
715
+ for (const pkgId of Object.keys(lockfile.packages ?? {})) {
716
+ if (!reachablePackages.has(pkgId)) {
717
+ delete lockfile.packages[pkgId];
718
+ }
719
+ }
720
+ for (const depPath of Object.keys(lockfile.snapshots ?? {})) {
721
+ if (!reachableSnapshots.has(depPath)) {
722
+ delete lockfile.snapshots[depPath];
723
+ }
724
+ }
725
+ const bitAttrs = lockfile.bit;
726
+ if (bitAttrs?.depsRequiringBuild) {
727
+ bitAttrs.depsRequiringBuild = bitAttrs.depsRequiringBuild.filter(depPath => reachablePackages.has(removePeerSuffix(depPath)));
728
+ }
729
+ }
730
+ function removePeerSuffix(depPath) {
731
+ const suffixStart = depPath.indexOf('(');
732
+ return suffixStart === -1 ? depPath : depPath.slice(0, suffixStart);
733
+ }
626
734
 
627
735
  //# sourceMappingURL=pnpm.package-manager.js.map