rman 2.38.0 → 2.39.0

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.
package/README.md CHANGED
@@ -41,8 +41,9 @@ npx rman list
41
41
  ## Quick start
42
42
 
43
43
  `rman` auto-detects your repository layout - point it at a directory containing a `package.json`
44
- with a `workspaces` array (npm/yarn/pnpm-style) and every matched package becomes available to
45
- every command:
44
+ with a `workspaces` array (npm/yarn), or a `pnpm-workspace.yaml` with a `packages` list beside it
45
+ (pnpm, which wins when both are there), and every matched package becomes available to every
46
+ command:
46
47
 
47
48
  ```json
48
49
  // package.json (repository root)
@@ -11,15 +11,12 @@ export declare class NodePlatform implements Platform {
11
11
  manifestProvider: NodeManifestProvider;
12
12
  versionPlanner: NodeVersionPlanService;
13
13
  dependencyUpdater: NodeDependencyUpdater;
14
+ /** The file pnpm keeps a workspace's member list in - see `getWorkspace`. */
15
+ protected readonly pnpmWorkspaceFile: string;
14
16
  /**
15
- * npm's `workspaces` globs, resolved against `dir` - the directories directly below it that hold
16
- * a `package.json`.
17
- *
18
- * **Asked of every directory the walk reaches, not only of the repository root**, which is what
19
- * the seam changing from a layout to a per-directory question bought: a `package.json` naming
20
- * `workspaces` is a workspace root wherever it sits, so a Node sub-workspace inside a larger
21
- * repository is now found by the same code that finds the top one. `deep: 0` already made the
22
- * globs one level, so nothing here had to change to make that true.
17
+ * The workspace members of `dir`: the directories its `pnpm-workspace.yaml` `packages` globs
18
+ * match when it has that list, else its `package.json` `workspaces` globs - each one holding a
19
+ * `package.json`. Throws for a `pnpm-workspace.yaml` that is not valid YAML.
23
20
  */
24
21
  getWorkspace(dir: string): string[] | undefined;
25
22
  /**
@@ -52,4 +49,9 @@ export declare class NodePlatform implements Platform {
52
49
  * `<root>/node_modules/.bin` when that has to be overridden - the walk above reaches there first.
53
50
  */
54
51
  getBinPaths(cwd: string): string[];
52
+ /** The `packages` globs of `dir`'s `pnpm-workspace.yaml`, or `undefined` when there is no such
53
+ * file or it lists none. Throws when the file is not valid YAML. */
54
+ protected pnpmWorkspacePackages(dir: string): string[] | undefined;
55
+ /** The directories of `dirs` that hold a `package.json`, each once. */
56
+ protected packageDirs(dirs: readonly string[]): string[];
55
57
  }
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import parseNpmScript from '@netlify/parse-npm-script';
4
4
  import glob from 'fast-glob';
5
+ import * as yaml from 'js-yaml';
5
6
  import { NodeDependencyUpdater } from './node-dependency-updater.js';
6
7
  import { NodeManifestProvider } from './node-manifest.provider.js';
7
8
  import { NodeVersionPlanService } from './services/version-plan.service.js';
@@ -15,20 +16,40 @@ export class NodePlatform {
15
16
  manifestProvider = new NodeManifestProvider();
16
17
  versionPlanner = new NodeVersionPlanService();
17
18
  dependencyUpdater = new NodeDependencyUpdater();
19
+ /** The file pnpm keeps a workspace's member list in - see `getWorkspace`. */
20
+ pnpmWorkspaceFile = 'pnpm-workspace.yaml';
18
21
  /**
19
- * npm's `workspaces` globs, resolved against `dir` - the directories directly below it that hold
20
- * a `package.json`.
22
+ * The workspace members of `dir`: the directories its `pnpm-workspace.yaml` `packages` globs
23
+ * match when it has that list, else its `package.json` `workspaces` globs - each one holding a
24
+ * `package.json`. Throws for a `pnpm-workspace.yaml` that is not valid YAML.
25
+ */
26
+ /* **pnpm's list first, when there is one** - pnpm reads `pnpm-workspace.yaml` and ignores
27
+ * `package.json#workspaces`, so in a pnpm repository that file is the one the installed tree
28
+ * follows. Reported from `syncbridge-io/public-modules`: with only `pnpm-workspace.yaml`, rman
29
+ * found no packages at all, and the repository had to keep both lists in step.
30
+ *
31
+ * **A `pnpm-workspace.yaml` with no `packages` falls back to `workspaces`**, which is not what pnpm
32
+ * does: measured on pnpm 12.10.1, a settings-only file (`publicHoistPattern` alone) leaves pnpm
33
+ * with the root and no members. pnpm 9 moved its settings into this file, so a settings-only one
34
+ * is ordinary, and a file that says nothing about packages is read as saying nothing.
35
+ *
36
+ * **pnpm's globbing, as measured on the same pnpm**: `packages/**` takes members at any depth and
37
+ * none under `node_modules`; `!packages/test-*` leaves those out. npm's `workspaces` keep the
38
+ * one-level reading (`deep: 0`), which nothing has asked to change.
21
39
  *
22
40
  * **Asked of every directory the walk reaches, not only of the repository root**, which is what
23
41
  * the seam changing from a layout to a per-directory question bought: a `package.json` naming
24
42
  * `workspaces` is a workspace root wherever it sits, so a Node sub-workspace inside a larger
25
- * repository is now found by the same code that finds the top one. `deep: 0` already made the
26
- * globs one level, so nothing here had to change to make that true.
27
- */
43
+ * repository is found by the same code that finds the top one. */
28
44
  getWorkspace(dir) {
29
45
  const manifest = path.join(dir, 'package.json');
30
46
  if (!fs.existsSync(manifest))
31
47
  return undefined;
48
+ const pnpm = this.pnpmWorkspacePackages(dir);
49
+ if (pnpm) {
50
+ const dirs = glob.sync([...pnpm, '!**/node_modules/**'], { cwd: dir, absolute: true, onlyDirectories: true });
51
+ return this.packageDirs(dirs);
52
+ }
32
53
  let patterns;
33
54
  try {
34
55
  patterns = JSON.parse(fs.readFileSync(manifest, 'utf-8'))?.workspaces;
@@ -40,17 +61,13 @@ export class NodePlatform {
40
61
  }
41
62
  if (!Array.isArray(patterns))
42
63
  return undefined;
43
- const packageDirs = [];
64
+ const dirs = [];
44
65
  for (const pattern of patterns) {
45
66
  if (typeof pattern !== 'string')
46
67
  continue;
47
- const dirs = glob.sync(pattern, { cwd: dir, absolute: true, deep: 0, onlyDirectories: true });
48
- for (const d of dirs) {
49
- if (fs.existsSync(path.join(d, 'package.json')))
50
- packageDirs.push(d);
51
- }
68
+ dirs.push(...glob.sync(pattern, { cwd: dir, absolute: true, deep: 0, onlyDirectories: true }));
52
69
  }
53
- return packageDirs;
70
+ return this.packageDirs(dirs);
54
71
  }
55
72
  /**
56
73
  * Teaches `run` about `package.json#scripts`.
@@ -123,6 +140,30 @@ export class NodePlatform {
123
140
  result.push(path.resolve(cwd, process.execPath, '..'));
124
141
  return result;
125
142
  }
143
+ /** The `packages` globs of `dir`'s `pnpm-workspace.yaml`, or `undefined` when there is no such
144
+ * file or it lists none. Throws when the file is not valid YAML. */
145
+ /* Thrown rather than swallowed, unlike a malformed `package.json` above: nothing else in rman
146
+ * reads this file, so a parse error left here would surface as a repository with no packages. */
147
+ pnpmWorkspacePackages(dir) {
148
+ const file = path.join(dir, this.pnpmWorkspaceFile);
149
+ if (!fs.existsSync(file))
150
+ return undefined;
151
+ let parsed;
152
+ try {
153
+ parsed = yaml.load(fs.readFileSync(file, 'utf-8'));
154
+ }
155
+ catch (e) {
156
+ throw new Error(`Cannot read ${file}: ${e.message}`, { cause: e });
157
+ }
158
+ const packages = parsed?.packages;
159
+ if (!Array.isArray(packages))
160
+ return undefined;
161
+ return packages.filter((p) => typeof p === 'string');
162
+ }
163
+ /** The directories of `dirs` that hold a `package.json`, each once. */
164
+ packageDirs(dirs) {
165
+ return [...new Set(dirs)].filter(d => fs.existsSync(path.join(d, 'package.json')));
166
+ }
126
167
  }
127
168
  /** npm's lifecycle names, mapped onto rman's three slots. */
128
169
  function slotOf(stepName, script) {
package/constants.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.38.0';
1
+ export const version = '2.39.0';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rman",
3
3
  "description": "Repository manager",
4
- "version": "2.38.0",
4
+ "version": "2.39.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {