@syntopica/quality-config 0.11.0 → 0.11.1

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.
@@ -26,6 +26,7 @@ import { spawnSync } from 'node:child_process'
26
26
  import { readFile } from 'node:fs/promises'
27
27
  import { resolve } from 'node:path'
28
28
  import { argv, cwd, exit } from 'node:process'
29
+ import { pnpmCommand } from './pnpmCommand.mjs'
29
30
 
30
31
  const LEVELS = ['info', 'low', 'moderate', 'high', 'critical']
31
32
  const DEFAULT_FILE = '.baseline-advisories.json'
@@ -48,7 +49,8 @@ const allowlist = await readAllowlist(resolve(root, flag('file', DEFAULT_FILE)))
48
49
 
49
50
  // `pnpm audit` exits non-zero when it finds anything, which is the whole
50
51
  // point, so its status is not an error condition here - the JSON is.
51
- const result = spawnSync('pnpm', ['audit', '--json'], {
52
+ const [pnpm, ...pnpmArgs] = pnpmCommand()
53
+ const result = spawnSync(pnpm, [...pnpmArgs, 'audit', '--json'], {
52
54
  encoding: 'utf8',
53
55
  maxBuffer: 64 * 1024 * 1024,
54
56
  })
@@ -15,6 +15,7 @@ import { spawnSync } from 'node:child_process'
15
15
  import { existsSync, readdirSync } from 'node:fs'
16
16
  import { relative, resolve } from 'node:path'
17
17
  import { argv, cwd, exit } from 'node:process'
18
+ import { pnpmCommand } from './pnpmCommand.mjs'
18
19
 
19
20
  const DEFAULT_SOURCES = ['src', 'app', 'server', 'lib']
20
21
  const SKIPPED_DIRECTORIES = new Set([
@@ -69,6 +70,8 @@ function findWorkspaces(root, depth = 0) {
69
70
  return found
70
71
  }
71
72
 
73
+ const [pnpm, ...pnpmArgs] = pnpmCommand()
74
+
72
75
  const failed = []
73
76
  for (const workspace of findWorkspaces(cwd())) {
74
77
  const present = sourceDirectories.filter((directory) =>
@@ -79,8 +82,9 @@ for (const workspace of findWorkspaces(cwd())) {
79
82
  const label = relative(cwd(), workspace) || '.'
80
83
  console.log(`deps-graph: cruising ${label} (${present.join(', ')})`)
81
84
  const result = spawnSync(
82
- 'pnpm',
85
+ pnpm,
83
86
  [
87
+ ...pnpmArgs,
84
88
  'exec',
85
89
  'depcruise',
86
90
  ...present,
@@ -38,6 +38,7 @@ import { tmpdir } from 'node:os'
38
38
  import { join } from 'node:path'
39
39
  import { argv, exit } from 'node:process'
40
40
  import { fileURLToPath } from 'node:url'
41
+ import { pnpmCommand } from './pnpmCommand.mjs'
41
42
 
42
43
  const PACKAGED_CONFIG = fileURLToPath(new URL('../jscpd.json', import.meta.url))
43
44
 
@@ -108,7 +109,8 @@ if (found.value !== -1) args[found.value] = config
108
109
  else if (found.inline !== -1) args[found.inline] = `--config=${config}`
109
110
  else args.push('--config', config)
110
111
 
111
- const result = spawnSync('pnpm', ['exec', 'jscpd', ...args], {
112
+ const [pnpm, ...pnpmArgs] = pnpmCommand()
113
+ const result = spawnSync(pnpm, [...pnpmArgs, 'exec', 'jscpd', ...args], {
112
114
  stdio: 'inherit',
113
115
  })
114
116
 
@@ -33,6 +33,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs'
33
33
  import { dirname, relative, resolve } from 'node:path'
34
34
  import { argv, cwd, exit } from 'node:process'
35
35
  import { fileURLToPath } from 'node:url'
36
+ import { pnpmCommand } from './pnpmCommand.mjs'
36
37
 
37
38
  const IGNORED_FILES = ['.next/**', '.nuxt/**', 'tests/**', '**/*.test.*']
38
39
  const SKIPPED_DIRECTORIES = new Set([
@@ -207,12 +208,15 @@ if (!workspaces.length) {
207
208
  exit(1)
208
209
  }
209
210
 
211
+ const [pnpm, ...pnpmArgs] = pnpmCommand()
212
+
210
213
  let failed = false
211
214
  for (const workspace of workspaces) {
212
215
  const label = relative(cwd(), workspace.project ?? workspace.directory) || '.'
213
216
  const result = spawnSync(
214
- 'pnpm',
217
+ pnpm,
215
218
  [
219
+ ...pnpmArgs,
216
220
  'exec',
217
221
  'type-coverage',
218
222
  '--strict',
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The argv prefix that runs pnpm: `[command, ...leadingArguments]`.
3
+ *
4
+ * Spread it ahead of pnpm's own arguments, so a machine whose `pnpm` on PATH
5
+ * is the shebang-less pnpm placeholder is still reachable from Node.
6
+ */
7
+ export declare function pnpmCommand(): [string, ...string[]]
@@ -0,0 +1,75 @@
1
+ // How to spawn pnpm from a Node program, on a machine where `pnpm` on PATH is
2
+ // not executable by the kernel.
3
+ //
4
+ // pnpm 11 puts a shebang-less `sh` script at its bin path and replaces it with
5
+ // the native binary during installation. The file says so itself: a bin shim
6
+ // and a shell both retry it under `sh`, "Apple's libc does not, so on macOS a
7
+ // program that spawns this path itself gets ENOEXEC". A Homebrew install that
8
+ // never ran that replacement leaves the placeholder in place, and then every
9
+ // `spawnSync('pnpm', ...)` here fails with `spawnSync pnpm ENOEXEC` - measured
10
+ // on 2026-09-21, where it surfaced as `type-coverage: FAIL .` with no output
11
+ // on a repository at 99.82% coverage, and as `baseline-dupes: could not run
12
+ // jscpd`. The gate reported the subject as broken when the subject was fine.
13
+ //
14
+ // So the runner resolves an entry point Node can always execute:
15
+ // 1. `npm_execpath`, which pnpm sets for its own scripts and which points at
16
+ // a JavaScript file, run under this Node.
17
+ // 2. otherwise the `pnpm` on PATH, if the kernel can exec it - a shebang or
18
+ // a real binary.
19
+ // 3. otherwise the `bin/pnpm.mjs` the placeholder itself hands over to.
20
+ import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs'
21
+ import { delimiter, dirname, join } from 'node:path'
22
+ import { env, execPath, platform } from 'node:process'
23
+
24
+ const JS_ENTRY = /\.[cm]?js$/
25
+
26
+ /**
27
+ * The argv prefix that runs pnpm: `[command, ...leadingArguments]`.
28
+ * @returns {[string, ...string[]]} Spread it ahead of pnpm's own arguments.
29
+ */
30
+ export function pnpmCommand() {
31
+ const fromNpm = env.npm_execpath
32
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
33
+ if (fromNpm && JS_ENTRY.test(fromNpm) && existsSync(fromNpm)) {
34
+ return [execPath, fromNpm]
35
+ }
36
+ const onPath = resolveOnPath('pnpm')
37
+ if (!onPath) return ['pnpm']
38
+ if (isKernelExecutable(onPath)) return ['pnpm']
39
+ /* eslint-disable security/detect-non-literal-fs-filename */
40
+ const handover = join(dirname(realpathSync(onPath)), 'bin', 'pnpm.mjs')
41
+ return existsSync(handover) ? [execPath, handover] : ['pnpm']
42
+ /* eslint-enable security/detect-non-literal-fs-filename */
43
+ }
44
+
45
+ /** The first `name` on PATH, or undefined. Windows keeps its own extensions. */
46
+ function resolveOnPath(name) {
47
+ const suffixes = platform === 'win32' ? ['.cmd', '.exe', '.bat', ''] : ['']
48
+ for (const directory of (env.PATH ?? '').split(delimiter).filter(Boolean)) {
49
+ for (const suffix of suffixes) {
50
+ const candidate = join(directory, `${name}${suffix}`)
51
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
52
+ if (existsSync(candidate) && statSync(candidate).isFile()) {
53
+ return candidate
54
+ }
55
+ }
56
+ }
57
+ return undefined
58
+ }
59
+
60
+ /** Whether `execve` can run this file: a shebang, or anything not plain text. */
61
+ function isKernelExecutable(path) {
62
+ if (platform === 'win32') return true
63
+ let head
64
+ try {
65
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
66
+ head = readFileSync(path).subarray(0, 2)
67
+ } catch {
68
+ return true
69
+ }
70
+ if (head[0] === 0x23 && head[1] === 0x21) return true
71
+ // Mach-O, ELF and the fat binaries macOS ships all start outside printable
72
+ // ASCII: not text, so not the placeholder. Only a text file without a
73
+ // shebang is the case this exists for.
74
+ return head[0] >= 0x7f
75
+ }
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@syntopica/quality-config",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "private": false,
5
- "packageManager": "pnpm@11.25.0",
6
5
  "license": "MIT",
7
6
  "description": "Shared configuration for cross-file quality gates: knip, dependency-cruiser, type-coverage, jscpd, lefthook",
8
7
  "repository": {
9
8
  "type": "git",
10
- "url": "git+https://github.com/BusiRocket/baseline.git",
9
+ "url": "git+https://github.com/syntopica/codeality.git",
11
10
  "directory": "packages/quality-config"
12
11
  },
13
- "homepage": "https://github.com/BusiRocket/baseline/tree/main/packages/quality-config#readme",
12
+ "homepage": "https://github.com/syntopica/codeality/tree/main/packages/quality-config#readme",
14
13
  "bugs": {
15
- "url": "https://github.com/BusiRocket/baseline/issues"
14
+ "url": "https://github.com/syntopica/codeality/issues"
16
15
  },
17
16
  "publishConfig": {
18
17
  "access": "public"
@@ -47,16 +46,8 @@
47
46
  "./lefthook": "./src/lefthook.ts",
48
47
  "./jscpd": "./jscpd.json",
49
48
  "./commitlint": "./src/commitlint.ts",
50
- "./oxlint": "./oxlintrc.json"
51
- },
52
- "scripts": {
53
- "fix": "pnpm run lint:fix",
54
- "lint": "eslint src bin --max-warnings 0",
55
- "lint:fix": "eslint src bin --fix",
56
- "lint:suppress": "eslint src bin --suppress-all",
57
- "lint:prune": "eslint src bin --prune-suppressions",
58
- "type-check": "tsc --noEmit -p tsconfig.json",
59
- "publish:check": "baseline-licenses && publint --strict && attw --pack . --profile node16 --ignore-rules cjs-resolves-to-esm internal-resolution-error"
49
+ "./oxlint": "./oxlintrc.json",
50
+ "./pnpm-command": "./bin/pnpmCommand.mjs"
60
51
  },
61
52
  "peerDependencies": {
62
53
  "@commitlint/config-conventional": ">=21.0.0",
@@ -81,13 +72,22 @@
81
72
  },
82
73
  "devDependencies": {
83
74
  "@arethetypeswrong/cli": "^0.18.5",
84
- "@syntopica/eslint-config": "workspace:*",
85
- "@types/node": "^26.4.0",
86
- "dependency-cruiser": "^18.2.0",
87
- "eslint": "^10.9.1",
88
- "eslint-plugin-regexp": "^3.2.0",
89
- "knip": "^6.33.0",
75
+ "@syntopica/eslint-config": "0.8.0",
76
+ "@types/node": "^26.6.2",
77
+ "dependency-cruiser": "^18.4.0",
78
+ "eslint": "^10.11.0",
79
+ "eslint-plugin-regexp": "^3.3.1",
80
+ "knip": "^6.37.0",
90
81
  "publint": "^0.3.24",
91
82
  "typescript": "npm:@typescript/typescript6@^6.0.2"
83
+ },
84
+ "scripts": {
85
+ "fix": "pnpm run lint:fix",
86
+ "lint": "eslint src bin --max-warnings 0",
87
+ "lint:fix": "eslint src bin --fix",
88
+ "lint:suppress": "eslint src bin --suppress-all",
89
+ "lint:prune": "eslint src bin --prune-suppressions",
90
+ "type-check": "tsc --noEmit -p tsconfig.json",
91
+ "publish:check": "baseline-licenses && publint --strict && attw --pack . --profile node16 --ignore-rules cjs-resolves-to-esm internal-resolution-error"
92
92
  }
93
- }
93
+ }
@@ -21,7 +21,10 @@ const NEXT_FILE_CONVENTIONS =
21
21
  // optional-directory group.
22
22
  const ORPHAN_EXEMPTIONS = [
23
23
  '(^|/)\\.[^/]+\\.(js|cjs|mjs|ts|json)$',
24
- '\\.d\\.ts$',
24
+ // Declaration files of every extension: `.d.ts`, and the `.d.mts`/`.d.cts`
25
+ // a package ships beside an `.mjs`/`.cjs` entry point. They carry types, not
26
+ // modules, so nothing imports them.
27
+ '\\.d\\.[cm]?ts$',
25
28
  '(^|/)tsconfig\\.json$',
26
29
  // Framework/tooling config files: loaded directly by that tool's own
27
30
  // runtime, never imported by application code. Being an orphan in the module
@@ -131,7 +134,11 @@ export const createDepCruiserConfig = (
131
134
  options: {
132
135
  doNotFollow: { path: 'node_modules' },
133
136
  exclude: {
134
- path: '(^|/)(dist|coverage|\\.next|\\.nuxt|\\.output|\\.astro|target)/',
137
+ // `.venv` is here because a Python workspace vendors JavaScript: urllib3
138
+ // ships an Emscripten fetch worker, and cruising a repository that holds
139
+ // a uv project reported four of those as orphan modules - errors about
140
+ // files the repository does not own and cannot remove.
141
+ path: '(^|/)(dist|coverage|\\.next|\\.nuxt|\\.output|\\.astro|\\.venv|target)/',
135
142
  },
136
143
  tsPreCompilationDeps: true,
137
144
  tsConfig: options.tsConfigPath
@@ -1,4 +1,16 @@
1
- /** Entry and project globs per template framework, consumed by createKnipConfig. */
1
+ /**
2
+ * Entry and project globs per template framework, consumed by createKnipConfig.
3
+ *
4
+ * `includeEntryExports` says whether an entry file's own exports are checked.
5
+ * It is true only where the entries are hand-written (`src/main.ts`,
6
+ * `src/index.ts`), which is where a dead export is a real finding. Where the
7
+ * framework owns the entry - a config file's `export default defineConfig(...)`,
8
+ * a Next.js route's `export default function Page()`, its `metadata` - the
9
+ * export exists because the framework reads it, and nothing in the project
10
+ * imports it by design. knip 6.35 started applying `includeEntryExports` to
11
+ * the files its own plugins register, so a blanket `true` failed the gate in
12
+ * six of the eight templates with exports no project can remove.
13
+ */
2
14
  export type KnipFramework =
3
15
  | 'astro'
4
16
  | 'nestjs'
@@ -12,15 +24,17 @@ export type KnipFramework =
12
24
 
13
25
  export const FRAMEWORK_ENTRIES: Record<
14
26
  KnipFramework,
15
- { entry: string[]; project: string[] }
27
+ { entry: string[]; project: string[]; includeEntryExports: boolean }
16
28
  > = {
17
29
  astro: {
18
30
  entry: ['src/pages/**/*.{astro,ts,tsx}', 'astro.config.*'],
19
31
  project: ['src/**/*.{astro,ts,tsx}'],
32
+ includeEntryExports: false,
20
33
  },
21
34
  nestjs: {
22
35
  entry: ['src/main.ts', 'src/**/*.module.ts'],
23
36
  project: ['src/**/*.ts'],
37
+ includeEntryExports: true,
24
38
  },
25
39
  // The App Router lives at either `app/` or `src/app/`, and the proxy follows
26
40
  // it. `{,src/}` matches both in one pattern, so neither layout produces a
@@ -42,10 +56,12 @@ export const FRAMEWORK_ENTRIES: Record<
42
56
  '{,src/}{middleware,proxy}.ts',
43
57
  ],
44
58
  project: ['{,src/}app/**/*.{ts,tsx}', 'src/**/*.{ts,tsx}'],
59
+ includeEntryExports: false,
45
60
  },
46
61
  nuxt: {
47
62
  entry: ['app/**/*.vue', 'server/**/*.ts', 'nuxt.config.*'],
48
63
  project: ['app/**/*.{ts,vue}', 'server/**/*.ts'],
64
+ includeEntryExports: false,
49
65
  },
50
66
  // TanStack Start has no index.html and no src/main.tsx: the router is the
51
67
  // root of the graph and the framework generates routeTree.gen.ts from the
@@ -61,6 +77,7 @@ export const FRAMEWORK_ENTRIES: Record<
61
77
  'vite.config.*',
62
78
  ],
63
79
  project: ['src/**/*.{ts,tsx}'],
80
+ includeEntryExports: false,
64
81
  },
65
82
  tauri: {
66
83
  // The scaffolded tauri-app frontend is React, so its entry is
@@ -68,17 +85,21 @@ export const FRAMEWORK_ENTRIES: Record<
68
85
  // Tauri frontend also matches.
69
86
  entry: ['src/main.{ts,tsx}', 'vite.config.*'],
70
87
  project: ['src/**/*.{ts,tsx}'],
88
+ includeEntryExports: false,
71
89
  },
72
90
  'ts-package': {
73
91
  entry: ['src/index.ts'],
74
92
  project: ['src/**/*.ts'],
93
+ includeEntryExports: true,
75
94
  },
76
95
  'vite-react': {
77
96
  entry: ['src/main.tsx', 'index.html', 'vite.config.*'],
78
97
  project: ['src/**/*.{ts,tsx}'],
98
+ includeEntryExports: false,
79
99
  },
80
100
  'vite-vue': {
81
101
  entry: ['src/main.ts', 'index.html', 'vite.config.*'],
82
102
  project: ['src/**/*.{ts,vue}'],
103
+ includeEntryExports: false,
83
104
  },
84
105
  }
package/src/knip.ts CHANGED
@@ -103,9 +103,11 @@ export const createKnipConfig = (options: {
103
103
  */
104
104
  entry?: string[]
105
105
  /**
106
- * Set `false` for a package that is finished but not wired up yet. With the
107
- * default `true` its entire public API reports as unused exports, and the
108
- * obvious reading of that report is "delete this package".
106
+ * Whether an entry file's own exports are checked. Defaults per framework
107
+ * (see FRAMEWORK_ENTRIES): true where the entries are hand-written, false
108
+ * where the framework owns them. Set `false` for a package that is finished
109
+ * but not wired up yet - with `true` its entire public API reports as unused
110
+ * exports, and the obvious reading of that report is "delete this package".
109
111
  */
110
112
  includeEntryExports?: boolean
111
113
  /**
@@ -116,7 +118,8 @@ export const createKnipConfig = (options: {
116
118
  */
117
119
  drizzle?: false
118
120
  }): KnipConfiguration => {
119
- const { entry, project } = FRAMEWORK_ENTRIES[options.framework]
121
+ const { entry, project, includeEntryExports } =
122
+ FRAMEWORK_ENTRIES[options.framework]
120
123
 
121
124
  return {
122
125
  entry: [...entry, ...(options.entry ?? [])],
@@ -130,7 +133,7 @@ export const createKnipConfig = (options: {
130
133
  // fail `nextjs-app` (app/page.tsx), `vite-react-app` (src/main.tsx) or
131
134
  // `vue-app` (src/main.ts) - files a knip framework plugin registers as an
132
135
  // entry of its own, which the option does not reach.
133
- includeEntryExports: options.includeEntryExports ?? true,
136
+ includeEntryExports: options.includeEntryExports ?? includeEntryExports,
134
137
  // The Primary Unit Rule (code-policy/no-hidden-top-level-declarations)
135
138
  // forbids a hidden top-level declaration, so a helper an entry file uses
136
139
  // only itself still has to be exported - NestJS's `bootstrap`, called by