@compilr-dev/tooling 0.0.0-stage → 0.1.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/CHANGELOG.md +20 -0
- package/LICENSE +108 -0
- package/README.md +64 -2
- package/dist/audit.d.ts +17 -0
- package/dist/audit.js +128 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +11 -0
- package/dist/eslint.d.ts +113 -0
- package/dist/eslint.js +33 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/package.json +65 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-12-06
|
|
4
|
+
|
|
5
|
+
First release. Two entry points, no runtime dependencies.
|
|
6
|
+
|
|
7
|
+
**`./eslint`** — `runtimeBlock(runtime, { files, globals })` and `RUNTIMES`: the six runtimes these
|
|
8
|
+
app repos ship code into, as data. It states `files` and `languageOptions` and nothing else; the
|
|
9
|
+
repo keeps its own eslint, plugins and rules and passes its own `globals` object in. That division
|
|
10
|
+
is why there are no dependencies: across the four repos this came from, eslint spanned two majors,
|
|
11
|
+
`globals` two, TypeScript two and the test runner three.
|
|
12
|
+
|
|
13
|
+
**`./audit`** and the `compilr-audit-gates` bin — `auditGates({ root })` reports the files no gate
|
|
14
|
+
covers and the gates that cannot fail: lint coverage per file class, a tsconfig a gate is aimed at
|
|
15
|
+
that resolves to none of your files, a claimed gate with no script, and a gate no workflow runs.
|
|
16
|
+
Returns findings rather than asserting.
|
|
17
|
+
|
|
18
|
+
Written after an audit of four app repos found **143 files linted by nothing** — including 72
|
|
19
|
+
production serverless functions, the modules a database access layer lived in, and a service worker
|
|
20
|
+
that ships to every browser — with `npm run lint` exiting 0 throughout.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
Abbreviation: FSL-1.1-MIT
|
|
4
|
+
|
|
5
|
+
Notice
|
|
6
|
+
|
|
7
|
+
Copyright 2026 Carmelo Scozzola
|
|
8
|
+
|
|
9
|
+
Terms and Conditions
|
|
10
|
+
|
|
11
|
+
Licensor ("We")
|
|
12
|
+
|
|
13
|
+
The party offering the Software under these Terms and Conditions.
|
|
14
|
+
|
|
15
|
+
The Software
|
|
16
|
+
|
|
17
|
+
The "Software" is each version of the software that we make available under
|
|
18
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
19
|
+
Conditions with the Software.
|
|
20
|
+
|
|
21
|
+
License Grant
|
|
22
|
+
|
|
23
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
24
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
25
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
26
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
27
|
+
|
|
28
|
+
Permitted Purpose
|
|
29
|
+
|
|
30
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
31
|
+
means making the Software available to others in a commercial product or
|
|
32
|
+
service that:
|
|
33
|
+
|
|
34
|
+
1. substitutes for the Software;
|
|
35
|
+
|
|
36
|
+
2. substitutes for any other product or service we offer using the Software
|
|
37
|
+
that exists as of the date we make the Software available; or
|
|
38
|
+
|
|
39
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
40
|
+
|
|
41
|
+
Permitted Purposes specifically include using the Software:
|
|
42
|
+
|
|
43
|
+
1. for your internal use and access;
|
|
44
|
+
|
|
45
|
+
2. for non-commercial education;
|
|
46
|
+
|
|
47
|
+
3. for non-commercial research; and
|
|
48
|
+
|
|
49
|
+
4. in connection with professional services that you provide to a licensee
|
|
50
|
+
using the Software in accordance with these Terms and Conditions.
|
|
51
|
+
|
|
52
|
+
Patents
|
|
53
|
+
|
|
54
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
55
|
+
patents, the license grant above includes a license under our patents. If you
|
|
56
|
+
make a claim against any party that the Software infringes or contributes to
|
|
57
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
58
|
+
immediately.
|
|
59
|
+
|
|
60
|
+
Redistribution
|
|
61
|
+
|
|
62
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
63
|
+
the Software.
|
|
64
|
+
|
|
65
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
66
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
67
|
+
remove any copyright notices provided in or with the Software.
|
|
68
|
+
|
|
69
|
+
Disclaimer
|
|
70
|
+
|
|
71
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
72
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
73
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
74
|
+
|
|
75
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
76
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
77
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
78
|
+
|
|
79
|
+
Trademarks
|
|
80
|
+
|
|
81
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
82
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
83
|
+
trademarks, trade names, service marks or product names.
|
|
84
|
+
|
|
85
|
+
Grant of Future License
|
|
86
|
+
|
|
87
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
88
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
89
|
+
the Software available. On or after that date, you may use the Software under
|
|
90
|
+
the MIT license, in which case the following will apply:
|
|
91
|
+
|
|
92
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
93
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
94
|
+
the Software without restriction, including without limitation the rights to
|
|
95
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
96
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
97
|
+
so, subject to the following conditions:
|
|
98
|
+
|
|
99
|
+
The above copyright notice and this permission notice shall be included in all
|
|
100
|
+
copies or substantial portions of the Software.
|
|
101
|
+
|
|
102
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
103
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
104
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
105
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
106
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
107
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
108
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @compilr-dev/tooling
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared quality gates for app repos: **which runtime each class of source file belongs to**, and **an audit that reports the files no gate covers**.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i -D @compilr-dev/tooling
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
Four app repos were audited and **143 files across them were linted by nothing**. Their eslint configs matched `*.{ts,tsx}` globs only, so every `.js`, `.mjs` and `.cjs` file sat outside the linter — 72 production serverless functions, the modules a database access layer lived in, a service worker that ships to every browser — while `npm run lint` exited 0 the whole time.
|
|
12
|
+
|
|
13
|
+
**A file no config block matched is indistinguishable, in an exit code, from a clean one.**
|
|
14
|
+
|
|
15
|
+
Fixing it four times produced the same discovery four times, which is what this package carries.
|
|
16
|
+
|
|
17
|
+
## `./eslint` — the runtime facts
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import globals from 'globals'
|
|
21
|
+
import js from '@eslint/js'
|
|
22
|
+
import { runtimeBlock } from '@compilr-dev/tooling/eslint'
|
|
23
|
+
|
|
24
|
+
export default [
|
|
25
|
+
{ ...runtimeBlock('node-cjs', { files: ['netlify/functions/*.js'], globals }), ...js.configs.recommended },
|
|
26
|
+
{ ...runtimeBlock('service-worker', { files: ['public/sw.js'], globals }), ...js.configs.recommended },
|
|
27
|
+
]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Six runtimes, because **one set of globals does not fit**:
|
|
31
|
+
|
|
32
|
+
| runtime | for | note |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `node-esm` | build scripts, `.mjs` handlers, shared modules | |
|
|
35
|
+
| `node-cjs` | a CommonJS functions directory | a repo with `type: module` can still hold one; parsing it as ESM is a parse error |
|
|
36
|
+
| `edge-deno` | edge functions | Deno, not Node — no `process`, and a host-specific global |
|
|
37
|
+
| `service-worker` | `public/sw.js` | its own runtime: `self`, `caches`, `clients` — **not** `window` |
|
|
38
|
+
| `node-and-browser` | a driver script's `evaluate()` callbacks; a page module with a Node-tested pure half | both sets, because judging by either half is wrong |
|
|
39
|
+
| `browser` | a browser module | |
|
|
40
|
+
|
|
41
|
+
**It sets no rules.** The package owns the runtime facts; your repo owns which eslint, which plugins and which rules. That division is deliberate: across the four repos this came from, **eslint spanned two majors, `globals` two, TypeScript two and the test runner three** — so a package that imported any of them would break a lint run on skew. This one has **no runtime dependencies**; you pass your own `globals` in.
|
|
42
|
+
|
|
43
|
+
⚠️ A flat-config block with `languageOptions` and no rules **lints nothing while looking configured**. Spread `js.configs.recommended` alongside, and let the audit confirm the class ends up with a non-empty rule set.
|
|
44
|
+
|
|
45
|
+
## `./audit` and `compilr-audit-gates` — the holes a config cannot show you
|
|
46
|
+
|
|
47
|
+
```jsonc
|
|
48
|
+
// package.json
|
|
49
|
+
"scripts": { "audit:gates": "compilr-audit-gates" }
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Four checks, each from a defect that shipped:
|
|
53
|
+
|
|
54
|
+
1. **lint coverage** — every class of source file in the tree gets `eslint --print-config`; a class with zero rules is reported. ⚠️ A file the config *deliberately* ignores prints the literal `undefined` and is not a hole — two different silences.
|
|
55
|
+
2. **a tsconfig a gate is aimed at must resolve to files of yours** — one repo aimed `tsc --noEmit` at a solution-style config holding only `references`, so it exited 0 having compiled an empty program. A config that resolves to nothing and that *nothing points at* is fine; that shape is the point of it.
|
|
56
|
+
3. **claimed gates exist** — one repo had no `typecheck` script at all, so `npm run typecheck` printed "Missing script", which through a `| grep "error TS"` pipeline reads as a clean run.
|
|
57
|
+
4. **something runs them** — a gate nothing runs looks exactly like one that passes. ⚠️ `npm test` without `run` counts.
|
|
58
|
+
|
|
59
|
+
It returns findings rather than asserting, so a test, a CI step or a script can use it. The CLI exits 1 on any finding.
|
|
60
|
+
|
|
61
|
+
**This package runs it on itself in CI**, and that found three of its own holes — including a relative-root bug that every fixture test missed, because they all passed absolute paths.
|
|
62
|
+
|
|
63
|
+
## Licence
|
|
64
|
+
|
|
65
|
+
FSL-1.1-MIT.
|
package/dist/audit.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface AuditOptions {
|
|
2
|
+
/** The repo root. */
|
|
3
|
+
root: string;
|
|
4
|
+
/** Directories never to walk. Defaults cover build output and dependencies. */
|
|
5
|
+
skipDirs?: readonly string[];
|
|
6
|
+
/** Extensions eslint is expected to cover. */
|
|
7
|
+
lintableExtensions?: readonly string[];
|
|
8
|
+
/** Gates that must exist as npm scripts AND be invoked by a workflow. */
|
|
9
|
+
requiredGates?: readonly string[];
|
|
10
|
+
}
|
|
11
|
+
export interface AuditFinding {
|
|
12
|
+
kind: 'unlinted' | 'empty-tsconfig' | 'missing-script' | 'gate-not-in-ci' | 'no-workflow' | 'probe-failed';
|
|
13
|
+
message: string;
|
|
14
|
+
/** Files or paths the finding is about, for a caller that wants to print them. */
|
|
15
|
+
subjects?: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare function auditGates(options: AuditOptions): AuditFinding[];
|
package/dist/audit.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
2
|
+
import { join, extname, relative, resolve } from 'node:path';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
const DEFAULT_SKIP = ['node_modules', 'dist', 'coverage', '.git', '.netlify', '.stryker-tmp', 'build', '__pycache__'];
|
|
5
|
+
const DEFAULT_EXTS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
6
|
+
const DEFAULT_GATES = ['lint', 'typecheck', 'test', 'build'];
|
|
7
|
+
const capture = (cwd, cmd, args) => {
|
|
8
|
+
try {
|
|
9
|
+
return execFileSync(cmd, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
const err = e;
|
|
13
|
+
return `${err.stdout ?? ''}${err.stderr ?? ''}`;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function walk(root, skip, exts, rel = '', out = []) {
|
|
17
|
+
for (const entry of readdirSync(join(root, rel), { withFileTypes: true })) {
|
|
18
|
+
if (skip.has(entry.name))
|
|
19
|
+
continue;
|
|
20
|
+
const next = rel ? `${rel}/${entry.name}` : entry.name;
|
|
21
|
+
if (entry.isDirectory())
|
|
22
|
+
walk(root, skip, exts, next, out);
|
|
23
|
+
else if (exts.has(extname(entry.name)))
|
|
24
|
+
out.push(next);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
function fileClasses(files) {
|
|
29
|
+
const by = new Map();
|
|
30
|
+
for (const f of files) {
|
|
31
|
+
const parts = f.split('/');
|
|
32
|
+
const head = parts.slice(0, Math.min(2, parts.length - 1)).join('/') || '.';
|
|
33
|
+
const key = `${head}/*${extname(f)}`;
|
|
34
|
+
const found = by.get(key);
|
|
35
|
+
if (found)
|
|
36
|
+
found.count += 1;
|
|
37
|
+
else
|
|
38
|
+
by.set(key, { sample: f, count: 1 });
|
|
39
|
+
}
|
|
40
|
+
return by;
|
|
41
|
+
}
|
|
42
|
+
export function auditGates(options) {
|
|
43
|
+
const root = resolve(options.root);
|
|
44
|
+
const skip = new Set(options.skipDirs ?? DEFAULT_SKIP);
|
|
45
|
+
const exts = new Set(options.lintableExtensions ?? DEFAULT_EXTS);
|
|
46
|
+
const gates = options.requiredGates ?? DEFAULT_GATES;
|
|
47
|
+
const findings = [];
|
|
48
|
+
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
49
|
+
const scripts = pkg.scripts ?? {};
|
|
50
|
+
const unlinted = [];
|
|
51
|
+
for (const [key, { sample, count }] of fileClasses(walk(root, skip, exts))) {
|
|
52
|
+
const text = capture(root, 'npx', ['eslint', '--print-config', sample]).trim();
|
|
53
|
+
if (text === 'undefined')
|
|
54
|
+
continue;
|
|
55
|
+
let rules;
|
|
56
|
+
try {
|
|
57
|
+
rules = Object.keys(JSON.parse(text).rules ?? {}).length;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
findings.push({
|
|
61
|
+
kind: 'probe-failed',
|
|
62
|
+
message: `eslint printed no usable config for ${sample}: ${text.split('\n')[0] || '(no output)'}`,
|
|
63
|
+
subjects: [sample],
|
|
64
|
+
});
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (rules === 0)
|
|
68
|
+
unlinted.push({ key, count, sample });
|
|
69
|
+
}
|
|
70
|
+
if (unlinted.length) {
|
|
71
|
+
findings.push({
|
|
72
|
+
kind: 'unlinted',
|
|
73
|
+
message: `${unlinted.reduce((n, u) => n + u.count, 0)} file(s) in ${unlinted.length} class(es) are linted by ` +
|
|
74
|
+
`NOTHING: ${unlinted.map((u) => `${u.key} (${u.count})`).join(', ')}`,
|
|
75
|
+
subjects: unlinted.map((u) => u.sample),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const allScripts = Object.values(scripts).join(' ; ');
|
|
79
|
+
for (const file of readdirSync(root).filter((f) => /^tsconfig.*\.json$/.test(f))) {
|
|
80
|
+
const aimed = new RegExp(`(-p|--project)\\s+${file.replace('.', '\\.')}`).test(allScripts) ||
|
|
81
|
+
(file === 'tsconfig.json' && /\btsc\b(?![^;]*(-p|--project))/.test(allScripts));
|
|
82
|
+
if (!aimed)
|
|
83
|
+
continue;
|
|
84
|
+
const listed = capture(root, 'npx', ['tsc', '-p', file, '--listFilesOnly'])
|
|
85
|
+
.split('\n')
|
|
86
|
+
.map((l) => l.trim())
|
|
87
|
+
.filter((l) => l && !l.includes('node_modules') && l.startsWith(root));
|
|
88
|
+
if (listed.length === 0) {
|
|
89
|
+
findings.push({
|
|
90
|
+
kind: 'empty-tsconfig',
|
|
91
|
+
message: `a gate is aimed at ${file}, which resolves to ZERO of our files — that run exits 0 having checked nothing`,
|
|
92
|
+
subjects: [file],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const gate of gates) {
|
|
97
|
+
if (!scripts[gate]) {
|
|
98
|
+
findings.push({
|
|
99
|
+
kind: 'missing-script',
|
|
100
|
+
message: `no \`${gate}\` script — \`npm run ${gate}\` says "Missing script", which reads as silence in a pipeline`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const wf = join(root, '.github', 'workflows');
|
|
105
|
+
const ci = existsSync(wf)
|
|
106
|
+
? readdirSync(wf)
|
|
107
|
+
.filter((f) => /\.ya?ml$/.test(f))
|
|
108
|
+
.map((f) => readFileSync(join(wf, f), 'utf8'))
|
|
109
|
+
.join('\n')
|
|
110
|
+
: '';
|
|
111
|
+
if (!ci) {
|
|
112
|
+
findings.push({ kind: 'no-workflow', message: 'no GitHub workflow found — nothing runs any gate on push' });
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
for (const gate of gates.filter((g) => scripts[g])) {
|
|
116
|
+
const invoked = new RegExp(`npm (run )?${gate}\\b`).test(ci) ||
|
|
117
|
+
new RegExp(`(yarn|pnpm) (run )?${gate}\\b`).test(ci) ||
|
|
118
|
+
new RegExp(`\\b${scripts[gate].split(' ')[0]}\\b`).test(ci);
|
|
119
|
+
if (!invoked) {
|
|
120
|
+
findings.push({
|
|
121
|
+
kind: 'gate-not-in-ci',
|
|
122
|
+
message: `\`${gate}\` exists but no workflow runs it — a gate nothing runs looks exactly like one that passes`,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return findings.map((f) => ({ ...f, subjects: f.subjects?.map((s) => relative(root, join(root, s))) }));
|
|
128
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { auditGates } from './audit.js';
|
|
3
|
+
const root = process.argv[2] ?? process.cwd();
|
|
4
|
+
const findings = auditGates({ root });
|
|
5
|
+
for (const f of findings)
|
|
6
|
+
console.error(` ✗ [${f.kind}] ${f.message}`);
|
|
7
|
+
if (findings.length) {
|
|
8
|
+
console.error(`\n${findings.length} gate hole(s). A file no gate covers is not a file that passed.`);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
console.log('ok — every class of source file is covered, and every gate exists and runs');
|
package/dist/eslint.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which runtime does each class of source file actually belong to?
|
|
3
|
+
*
|
|
4
|
+
* ⚠️ **WHY THIS IS DATA AND NOT A CONFIG.** Four app repos were audited in December 2026 and 143
|
|
5
|
+
* files across them were linted by NOTHING: their eslint configs matched `*.{ts,tsx}` globs only,
|
|
6
|
+
* so every `.js`, `.mjs` and `.cjs` file — including 72 production serverless functions, the
|
|
7
|
+
* modules a database access layer lived in, and a service worker that ships to every browser — sat
|
|
8
|
+
* outside the linter while `npm run lint` exited 0. A file no config block matched is
|
|
9
|
+
* indistinguishable, in an exit code, from a clean one.
|
|
10
|
+
*
|
|
11
|
+
* Fixing that four times produced the same discovery four times: **one set of globals does not
|
|
12
|
+
* fit.** Those files ran in six different runtimes, and two of them were two runtimes AT ONCE.
|
|
13
|
+
* Judging a file by its outer runtime reports real globals as undefined, which teaches people to
|
|
14
|
+
* ignore the linter.
|
|
15
|
+
*
|
|
16
|
+
* ⚠️ **AND WHY THIS PACKAGE HAS NO DEPENDENCIES AT ALL.** Across those four repos, eslint spanned
|
|
17
|
+
* two majors, `globals` two, TypeScript two and the test runner three. A preset package that
|
|
18
|
+
* imported eslint, its plugins or `globals` would need peer ranges across two majors each and
|
|
19
|
+
* would break a lint run on skew. So the division is:
|
|
20
|
+
*
|
|
21
|
+
* - **this package owns the FACTS** — what runtime a class of file is, which `globals` groups it
|
|
22
|
+
* needs, and the `ecmaVersion` that class requires;
|
|
23
|
+
* - **the repo owns the CHOICES** — which eslint, which plugins, which rules, and it passes its
|
|
24
|
+
* OWN `globals` object in.
|
|
25
|
+
*
|
|
26
|
+
* Usage in a flat config:
|
|
27
|
+
*
|
|
28
|
+
* import globals from 'globals';
|
|
29
|
+
* import js from '@eslint/js';
|
|
30
|
+
* import { runtimeBlock } from '@compilr-dev/tooling/eslint';
|
|
31
|
+
*
|
|
32
|
+
* export default [
|
|
33
|
+
* { ...runtimeBlock('node-cjs', { files: ['netlify/functions/*.js'], globals }),
|
|
34
|
+
* ...js.configs.recommended },
|
|
35
|
+
* ];
|
|
36
|
+
*
|
|
37
|
+
* (A recursive glob is written here without its leading star-star: that sequence ENDS a block
|
|
38
|
+
* comment, and the zero-width space one reaches for to prevent it is itself a lint error. I made
|
|
39
|
+
* that mistake three times in one day before writing it down.)
|
|
40
|
+
*/
|
|
41
|
+
/** The runtimes these app repos actually ship code into. */
|
|
42
|
+
export type RuntimeName =
|
|
43
|
+
/** Node, ES modules: build scripts, `.mjs` serverless handlers, shared library modules. */
|
|
44
|
+
'node-esm'
|
|
45
|
+
/**
|
|
46
|
+
* Node, CommonJS. ⚠️ A repo whose root `package.json` says `type: module` can still hold a
|
|
47
|
+
* directory of CommonJS functions, pinned by its own `package.json`. Parsing those as ESM is a
|
|
48
|
+
* parse error, not a style complaint.
|
|
49
|
+
*/
|
|
50
|
+
| 'node-cjs'
|
|
51
|
+
/**
|
|
52
|
+
* An edge runtime: Deno, not Node. No `process`; a `Deno` global, and on one host a `Netlify`
|
|
53
|
+
* global that exists nowhere else in the repo.
|
|
54
|
+
*/
|
|
55
|
+
| 'edge-deno'
|
|
56
|
+
/**
|
|
57
|
+
* A service worker. ⚠️ Its own runtime: `self`, `caches`, `clients`, `skipWaiting` — NOT
|
|
58
|
+
* `window`, not Node. It is also classic-script scoped, not a module.
|
|
59
|
+
*/
|
|
60
|
+
| 'service-worker'
|
|
61
|
+
/**
|
|
62
|
+
* Node AND browser in one file, which is not a mistake and not rare. Two real cases: a script
|
|
63
|
+
* whose callbacks are serialised and run in a page by a browser driver, and a page module with a
|
|
64
|
+
* pure half imported by a Node test and a bridge half that runs inside a host's iframe. Both
|
|
65
|
+
* global sets, because judging it by whichever half you read first is wrong either way.
|
|
66
|
+
*/
|
|
67
|
+
| 'node-and-browser'
|
|
68
|
+
/** A browser module (not a worker, not a page bridge). */
|
|
69
|
+
| 'browser';
|
|
70
|
+
export interface RuntimeFacts {
|
|
71
|
+
/** `globals` package groups to spread, in order. The REPO supplies the package. */
|
|
72
|
+
globalsGroups: readonly string[];
|
|
73
|
+
/** Globals the `globals` package does not carry, as name → access. */
|
|
74
|
+
extraGlobals?: Readonly<Record<string, 'readonly' | 'writable'>>;
|
|
75
|
+
sourceType: 'module' | 'commonjs' | 'script';
|
|
76
|
+
/**
|
|
77
|
+
* ⚠️ 2025 rather than something older because of IMPORT ATTRIBUTES — `import x from './f.json'
|
|
78
|
+
* with { type: 'json' }`, which is how a module bundles an asset for a runtime that has no
|
|
79
|
+
* filesystem. An older setting stops the parser at `with` and reports a lint ERROR on a file
|
|
80
|
+
* that runs correctly on both Node and Deno.
|
|
81
|
+
*/
|
|
82
|
+
ecmaVersion: number;
|
|
83
|
+
}
|
|
84
|
+
export declare const RUNTIMES: Readonly<Record<RuntimeName, RuntimeFacts>>;
|
|
85
|
+
/** The shape of the `globals` package: group name → globals map. Structural, so no import is needed. */
|
|
86
|
+
export type GlobalsPackage = Record<string, Record<string, boolean | 'readonly' | 'writable' | 'off'>>;
|
|
87
|
+
export interface RuntimeBlockOptions {
|
|
88
|
+
/** The glob(s) this block applies to. */
|
|
89
|
+
files: readonly string[];
|
|
90
|
+
/** YOUR `globals` package — `import globals from 'globals'`. Keeps this package dependency-free. */
|
|
91
|
+
globals: GlobalsPackage;
|
|
92
|
+
/** Extra globals for this block, merged last. */
|
|
93
|
+
extraGlobals?: Readonly<Record<string, 'readonly' | 'writable'>>;
|
|
94
|
+
/** Rules for this block. This package states no rule preferences; that is the repo's choice. */
|
|
95
|
+
rules?: Record<string, unknown>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* An eslint flat-config block for one runtime: `files` plus `languageOptions`, and nothing else.
|
|
99
|
+
*
|
|
100
|
+
* ⚠️ **It sets NO RULES, and a block with no rules LINTS NOTHING while looking configured.** That
|
|
101
|
+
* is a real failure mode — one was shipped during the audit above and only a coverage check found
|
|
102
|
+
* it. Spread `js.configs.recommended` (or your own) alongside, and let the audit confirm the file
|
|
103
|
+
* class ends up with a non-empty rule set.
|
|
104
|
+
*/
|
|
105
|
+
export declare function runtimeBlock(runtime: RuntimeName, { files, globals, extraGlobals, rules }: RuntimeBlockOptions): {
|
|
106
|
+
files: string[];
|
|
107
|
+
languageOptions: {
|
|
108
|
+
ecmaVersion: number;
|
|
109
|
+
sourceType: 'module' | 'commonjs' | 'script';
|
|
110
|
+
globals: Record<string, unknown>;
|
|
111
|
+
};
|
|
112
|
+
rules?: Record<string, unknown>;
|
|
113
|
+
};
|
package/dist/eslint.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const RUNTIMES = {
|
|
2
|
+
'node-esm': { globalsGroups: ['node'], sourceType: 'module', ecmaVersion: 2025 },
|
|
3
|
+
'node-cjs': { globalsGroups: ['node'], sourceType: 'commonjs', ecmaVersion: 2025 },
|
|
4
|
+
'edge-deno': {
|
|
5
|
+
globalsGroups: ['browser'],
|
|
6
|
+
extraGlobals: { Deno: 'readonly', Netlify: 'readonly' },
|
|
7
|
+
sourceType: 'module',
|
|
8
|
+
ecmaVersion: 2025,
|
|
9
|
+
},
|
|
10
|
+
'service-worker': { globalsGroups: ['serviceworker'], sourceType: 'script', ecmaVersion: 2025 },
|
|
11
|
+
'node-and-browser': { globalsGroups: ['node', 'browser'], sourceType: 'module', ecmaVersion: 2025 },
|
|
12
|
+
browser: { globalsGroups: ['browser'], sourceType: 'module', ecmaVersion: 2025 },
|
|
13
|
+
};
|
|
14
|
+
export function runtimeBlock(runtime, { files, globals, extraGlobals, rules }) {
|
|
15
|
+
const facts = RUNTIMES[runtime];
|
|
16
|
+
if (!facts)
|
|
17
|
+
throw new Error(`runtimeBlock: unknown runtime "${runtime}". Known: ${Object.keys(RUNTIMES).join(', ')}`);
|
|
18
|
+
const merged = {};
|
|
19
|
+
for (const group of facts.globalsGroups) {
|
|
20
|
+
const set = globals[group];
|
|
21
|
+
if (!set) {
|
|
22
|
+
throw new Error(`runtimeBlock("${runtime}"): the globals package has no "${group}" group. ` +
|
|
23
|
+
`Available: ${Object.keys(globals).slice(0, 12).join(', ')}…`);
|
|
24
|
+
}
|
|
25
|
+
Object.assign(merged, set);
|
|
26
|
+
}
|
|
27
|
+
Object.assign(merged, facts.extraGlobals ?? {}, extraGlobals ?? {});
|
|
28
|
+
return {
|
|
29
|
+
files: [...files],
|
|
30
|
+
languageOptions: { ecmaVersion: facts.ecmaVersion, sourceType: facts.sourceType, globals: merged },
|
|
31
|
+
...(rules ? { rules } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilr-dev/tooling",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared quality gates for app repos: which runtime each class of source file belongs to, and an audit that reports the files no gate covers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./eslint": {
|
|
15
|
+
"types": "./dist/eslint.d.ts",
|
|
16
|
+
"import": "./dist/eslint.js",
|
|
17
|
+
"default": "./dist/eslint.js"
|
|
18
|
+
},
|
|
19
|
+
"./audit": {
|
|
20
|
+
"types": "./dist/audit.d.ts",
|
|
21
|
+
"import": "./dist/audit.js",
|
|
22
|
+
"default": "./dist/audit.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"bin": {
|
|
26
|
+
"compilr-audit-gates": "dist/cli.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"CHANGELOG.md"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.build.json && tsc --emitDeclarationOnly",
|
|
35
|
+
"lint": "eslint src/ *.js",
|
|
36
|
+
"format": "prettier --write src/",
|
|
37
|
+
"format:check": "prettier --check src/",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"test:package": "node scripts/no-internal-refs.mjs",
|
|
40
|
+
"prepublishOnly": "npm run build",
|
|
41
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json",
|
|
42
|
+
"audit:self": "node dist/cli.js ."
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@eslint/js": "^9.39.4",
|
|
46
|
+
"@types/node": "^22.0.0",
|
|
47
|
+
"eslint": "^9.0.0",
|
|
48
|
+
"prettier": "^3.4.0",
|
|
49
|
+
"typescript": "^5.7.0",
|
|
50
|
+
"typescript-eslint": "^8.59.0",
|
|
51
|
+
"vitest": "^4.1.12",
|
|
52
|
+
"globals": "^15.15.0"
|
|
53
|
+
},
|
|
54
|
+
"sideEffects": false,
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=20.0.0"
|
|
57
|
+
},
|
|
58
|
+
"license": "FSL-1.1-MIT",
|
|
59
|
+
"author": "Carmelo Scozzola",
|
|
60
|
+
"keywords": [
|
|
61
|
+
"eslint",
|
|
62
|
+
"eslint-config",
|
|
63
|
+
"tooling",
|
|
64
|
+
"gates",
|
|
65
|
+
"lint-coverage"
|
|
66
|
+
]
|
|
67
|
+
}
|