@savvy-web/silk-effects 9.1.2 → 9.1.3

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.
@@ -6,8 +6,9 @@ import { readFile } from "node:fs/promises";
6
6
  /**
7
7
  * Package manager detection for the commit-time hooks.
8
8
  *
9
- * Mirrors the husky hook detection: prefer `package.json#packageManager`,
10
- * fall back to lockfile presence in priority order pnpm \> yarn \> bun \> npm.
9
+ * Mirrors the husky hook detection: prefer `package.json#devEngines.packageManager`
10
+ * (the first entry when it is an array), then the legacy `packageManager` field,
11
+ * then lockfile presence in priority order pnpm \> yarn \> bun \> npm.
11
12
  *
12
13
  * @internal
13
14
  */
@@ -17,6 +18,14 @@ const VALID_PMS = /* @__PURE__ */ new Set([
17
18
  "bun",
18
19
  "npm"
19
20
  ]);
21
+ const toPackageManager = (name) => typeof name === "string" && VALID_PMS.has(name) ? name : null;
22
+ const devEnginesName = (manifest) => {
23
+ const devEngines = manifest.devEngines;
24
+ if (typeof devEngines !== "object" || devEngines === null) return void 0;
25
+ const declared = devEngines.packageManager;
26
+ const first = Array.isArray(declared) ? declared[0] : declared;
27
+ return typeof first === "object" && first !== null ? first.name : void 0;
28
+ };
20
29
  function parsePackageManagerField(packageJsonContent) {
21
30
  let parsed;
22
31
  try {
@@ -24,10 +33,13 @@ function parsePackageManagerField(packageJsonContent) {
24
33
  } catch {
25
34
  return null;
26
35
  }
27
- const field = typeof parsed === "object" && parsed !== null && "packageManager" in parsed ? parsed.packageManager : void 0;
36
+ if (typeof parsed !== "object" || parsed === null) return null;
37
+ const manifest = parsed;
38
+ const fromDevEngines = toPackageManager(devEnginesName(manifest));
39
+ if (fromDevEngines !== null) return fromDevEngines;
40
+ const field = manifest.packageManager;
28
41
  if (typeof field !== "string" || field.length === 0) return null;
29
- const name = field.split("@")[0];
30
- return VALID_PMS.has(name) ? name : null;
42
+ return toPackageManager(field.split("@")[0]);
31
43
  }
32
44
  function detectFromLockfiles(presence) {
33
45
  if (presence.pnpm) return "pnpm";
package/index.d.ts CHANGED
@@ -7909,10 +7909,11 @@ declare class Command {
7909
7909
  */
7910
7910
  static findRoot(cwd?: string): string;
7911
7911
  /**
7912
- * Detect the package manager from the root package.json's `packageManager` field.
7912
+ * Detect the package manager declared by the root package.json.
7913
7913
  *
7914
- * Parses the `packageManager` field (e.g., `pnpm\@9.0.0`) and extracts the manager name.
7915
- * Falls back to "npm" if no packageManager field is found.
7914
+ * Reads `devEngines.packageManager.name` (the first entry when it is an array), then the
7915
+ * legacy `packageManager` field (e.g., `pnpm\@9.0.0`), then lockfile presence in priority
7916
+ * order pnpm, yarn, bun. Falls back to "npm" when none of them names a manager.
7916
7917
  *
7917
7918
  * @param cwd - Directory to search for package.json (defaults to `Command.findRoot()`)
7918
7919
  * @returns The detected package manager
@@ -7963,7 +7964,7 @@ declare class Command {
7963
7964
  *
7964
7965
  * Search order:
7965
7966
  * 1. Global command (in PATH)
7966
- * 2. Project's package manager (detected from package.json `packageManager` field)
7967
+ * 2. Project's package manager (detected from package.json `devEngines.packageManager`, `packageManager`, or a lockfile)
7967
7968
  *
7968
7969
  * @param tool - The tool name to find
7969
7970
  * @returns Search result with command string if found
@@ -1,3 +1,4 @@
1
+ import { detectFromLockfiles, parsePackageManagerField } from "../../commitlint/hook/diagnostics/package-manager.js";
1
2
  import { existsSync, readFileSync } from "node:fs";
2
3
  import { dirname, join, resolve } from "node:path";
3
4
  import { execSync } from "node:child_process";
@@ -81,10 +82,11 @@ var Command = class Command {
81
82
  return cwd;
82
83
  }
83
84
  /**
84
- * Detect the package manager from the root package.json's `packageManager` field.
85
+ * Detect the package manager declared by the root package.json.
85
86
  *
86
- * Parses the `packageManager` field (e.g., `pnpm\@9.0.0`) and extracts the manager name.
87
- * Falls back to "npm" if no packageManager field is found.
87
+ * Reads `devEngines.packageManager.name` (the first entry when it is an array), then the
88
+ * legacy `packageManager` field (e.g., `pnpm\@9.0.0`), then lockfile presence in priority
89
+ * order pnpm, yarn, bun. Falls back to "npm" when none of them names a manager.
88
90
  *
89
91
  * @param cwd - Directory to search for package.json (defaults to `Command.findRoot()`)
90
92
  * @returns The detected package manager
@@ -98,23 +100,16 @@ var Command = class Command {
98
100
  static detectPackageManager(cwd = Command.findRoot()) {
99
101
  if (Command.cachedPackageManager !== null) return Command.cachedPackageManager;
100
102
  const packageJsonPath = join(cwd, "package.json");
101
- if (!existsSync(packageJsonPath)) {
102
- Command.cachedPackageManager = "npm";
103
- return "npm";
104
- }
103
+ let declared = null;
105
104
  try {
106
- const content = readFileSync(packageJsonPath, "utf-8");
107
- const pkg = JSON.parse(content);
108
- if (pkg.packageManager) {
109
- const match = pkg.packageManager.match(/^(npm|pnpm|yarn|bun)@/);
110
- if (match) {
111
- Command.cachedPackageManager = match[1];
112
- return Command.cachedPackageManager;
113
- }
114
- }
105
+ declared = parsePackageManagerField(readFileSync(packageJsonPath, "utf-8"));
115
106
  } catch {}
116
- Command.cachedPackageManager = "npm";
117
- return "npm";
107
+ Command.cachedPackageManager = declared ?? detectFromLockfiles({
108
+ pnpm: existsSync(join(cwd, "pnpm-lock.yaml")),
109
+ yarn: existsSync(join(cwd, "yarn.lock")),
110
+ bun: existsSync(join(cwd, "bun.lock"))
111
+ });
112
+ return Command.cachedPackageManager;
118
113
  }
119
114
  /**
120
115
  * Get the exec command prefix for a package manager.
@@ -177,7 +172,7 @@ var Command = class Command {
177
172
  *
178
173
  * Search order:
179
174
  * 1. Global command (in PATH)
180
- * 2. Project's package manager (detected from package.json `packageManager` field)
175
+ * 2. Project's package manager (detected from package.json `devEngines.packageManager`, `packageManager`, or a lockfile)
181
176
  *
182
177
  * @param tool - The tool name to find
183
178
  * @returns Search result with command string if found
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@savvy-web/silk-effects",
3
- "version": "9.1.2",
3
+ "version": "9.1.3",
4
4
  "private": false,
5
5
  "description": "Shared Effect library for Silk Suite conventions",
6
6
  "homepage": "https://github.com/savvy-web/systems/tree/main/packages/silk-effects",
@@ -37,13 +37,13 @@
37
37
  "@effected/github-references": "^0.5.0",
38
38
  "@effected/glob": "^0.8.0",
39
39
  "@effected/jsonc": "^0.13.0",
40
- "@effected/markdown": "^0.12.0",
40
+ "@effected/markdown": "^0.12.1",
41
41
  "@effected/package-json": "^0.17.0",
42
42
  "@effected/toml": "^0.9.0",
43
43
  "@effected/walker": "^0.12.0",
44
44
  "@effected/yaml": "^0.17.0",
45
45
  "@manypkg/get-packages": "^3.1.0",
46
- "@savvy-web/silk-core": "0.4.4",
46
+ "@savvy-web/silk-core": "0.4.5",
47
47
  "mdast-util-heading-range": "^4.0.0",
48
48
  "mdast-util-to-string": "^4.0.0",
49
49
  "remark-gfm": "^4.0.1",
@@ -58,7 +58,7 @@
58
58
  "@effected/commands": "^0.9.0",
59
59
  "@effected/git": "^0.17.0",
60
60
  "@effected/templates": "^0.8.0",
61
- "@effected/workspaces": "^0.25.0",
61
+ "@effected/workspaces": "^0.26.0",
62
62
  "effect": "4.0.0-rc.117"
63
63
  }
64
64
  }
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.1"
8
+ "packageVersion": "7.59.2"
9
9
  }
10
10
  ]
11
11
  }