@rtorcato/js-tooling 2.6.0 → 2.8.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 +4 -0
- package/dist/cli/commands/doctor.js +31 -0
- package/dist/cli/commands/fix-targets.js +1 -0
- package/dist/cli/commands/fix.js +12 -1
- package/dist/cli/generators/misc.js +10 -0
- package/package.json +34 -19
- package/tooling/vitest/jsdom-shims.d.mts +1 -0
- package/tooling/vitest/jsdom-shims.mjs +58 -0
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# js-tooling
|
|
2
4
|
|
|
5
|
+

|
|
6
|
+
|
|
3
7
|
JavaScript and TypeScript tooling for Node.js, React, Next.js, and Vitest.
|
|
4
8
|
|
|
5
9
|
[](https://github.com/rtorcato/js-tooling/actions/workflows/ci.yml)
|
|
@@ -297,6 +297,36 @@ async function checkKnip(dir, pkg) {
|
|
|
297
297
|
hint: 'Add `knip` to detect unused files, deps, and exports',
|
|
298
298
|
};
|
|
299
299
|
}
|
|
300
|
+
const SIZE_LIMIT_FILES = [
|
|
301
|
+
'.size-limit.json',
|
|
302
|
+
'.size-limit.js',
|
|
303
|
+
'.size-limit.cjs',
|
|
304
|
+
'.size-limit.mjs',
|
|
305
|
+
'.size-limit.ts',
|
|
306
|
+
];
|
|
307
|
+
async function checkSizeLimit(dir, pkg) {
|
|
308
|
+
const inPkg = pkg ? 'size-limit' in pkg : false;
|
|
309
|
+
let inFile = null;
|
|
310
|
+
for (const candidate of SIZE_LIMIT_FILES) {
|
|
311
|
+
if (await fs.pathExists(path.join(dir, candidate))) {
|
|
312
|
+
inFile = candidate;
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (inPkg || inFile) {
|
|
317
|
+
return {
|
|
318
|
+
check: 'size-limit',
|
|
319
|
+
status: 'ok',
|
|
320
|
+
detail: inPkg ? '`size-limit` field in package.json' : `${inFile} found`,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
check: 'size-limit',
|
|
325
|
+
status: 'optional-missing',
|
|
326
|
+
detail: 'size-limit not configured',
|
|
327
|
+
hint: 'Add `size-limit` to enforce bundle-size budgets in CI for library projects',
|
|
328
|
+
};
|
|
329
|
+
}
|
|
300
330
|
const SEMANTIC_RELEASE_FILES = [
|
|
301
331
|
'.releaserc',
|
|
302
332
|
'.releaserc.json',
|
|
@@ -488,6 +518,7 @@ export async function runDoctor(dir) {
|
|
|
488
518
|
results.push(await checkLintStaged(targetDir, pkg));
|
|
489
519
|
results.push(await checkSemanticRelease(targetDir, pkg));
|
|
490
520
|
results.push(await checkKnip(targetDir, pkg));
|
|
521
|
+
results.push(await checkSizeLimit(targetDir, pkg));
|
|
491
522
|
results.push(await checkGitHubActions(targetDir));
|
|
492
523
|
results.push(await checkDependabot(targetDir));
|
|
493
524
|
results.push(await checkCodeQL(targetDir));
|
package/dist/cli/commands/fix.js
CHANGED
|
@@ -6,7 +6,7 @@ import { generateSemanticReleaseConfig } from '../generators/build.js';
|
|
|
6
6
|
import { generateCommitlintConfig, generateHuskyConfig } from '../generators/git.js';
|
|
7
7
|
import { generateGitHubActions } from '../generators/github-actions.js';
|
|
8
8
|
import { generateESLintConfig, generatePrettierConfig } from '../generators/linting.js';
|
|
9
|
-
import { ensureEnginesNode, generateEditorConfig, generateKnipConfig, generateNvmrc, } from '../generators/misc.js';
|
|
9
|
+
import { ensureEnginesNode, generateEditorConfig, generateKnipConfig, generateNvmrc, generateSizeLimitConfig, } from '../generators/misc.js';
|
|
10
10
|
import { generateCodeQLWorkflow, generateDependabotConfig } from '../generators/security.js';
|
|
11
11
|
import { generateVitestConfig } from '../generators/testing.js';
|
|
12
12
|
import { copyPreset } from '../utils/copy-preset.js';
|
|
@@ -231,6 +231,17 @@ const FIXERS = [
|
|
|
231
231
|
return { filesWritten: ['knip.json'] };
|
|
232
232
|
},
|
|
233
233
|
},
|
|
234
|
+
{
|
|
235
|
+
target: 'size-limit',
|
|
236
|
+
description: 'Scaffold .size-limit.json with a default 10 kB budget (customize per-subpath for libraries)',
|
|
237
|
+
appliesTo: ['size-limit'],
|
|
238
|
+
outputs: ['.size-limit.json'],
|
|
239
|
+
canFixDrift: true,
|
|
240
|
+
async run({ targetDir }) {
|
|
241
|
+
await generateSizeLimitConfig(targetDir);
|
|
242
|
+
return { filesWritten: ['.size-limit.json'] };
|
|
243
|
+
},
|
|
244
|
+
},
|
|
234
245
|
{
|
|
235
246
|
target: 'package-json',
|
|
236
247
|
description: 'Add @rtorcato/js-tooling to devDependencies',
|
|
@@ -23,6 +23,13 @@ const KNIP_CONFIG = {
|
|
|
23
23
|
entry: ['src/index.ts'],
|
|
24
24
|
project: ['src/**/*.ts'],
|
|
25
25
|
};
|
|
26
|
+
const SIZE_LIMIT_CONFIG = [
|
|
27
|
+
{
|
|
28
|
+
name: 'package (default entry)',
|
|
29
|
+
path: 'dist/index.js',
|
|
30
|
+
limit: '10 kB',
|
|
31
|
+
},
|
|
32
|
+
];
|
|
26
33
|
export async function generateEditorConfig(targetDir) {
|
|
27
34
|
await fs.writeFile(path.join(targetDir, '.editorconfig'), EDITORCONFIG_CONTENT);
|
|
28
35
|
}
|
|
@@ -44,6 +51,9 @@ export async function ensureEnginesNode(targetDir, version = '>=22') {
|
|
|
44
51
|
export async function generateKnipConfig(targetDir) {
|
|
45
52
|
await fs.writeJson(path.join(targetDir, 'knip.json'), KNIP_CONFIG, { spaces: 2 });
|
|
46
53
|
}
|
|
54
|
+
export async function generateSizeLimitConfig(targetDir) {
|
|
55
|
+
await fs.writeJson(path.join(targetDir, '.size-limit.json'), SIZE_LIMIT_CONFIG, { spaces: 2 });
|
|
56
|
+
}
|
|
47
57
|
export async function generateMiscBaseline(targetDir) {
|
|
48
58
|
await generateEditorConfig(targetDir);
|
|
49
59
|
await generateNvmrc(targetDir);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rtorcato/js-tooling",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "JavaScript and TypeScript tooling for Node.js, React, Next.js, and Vitest.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -61,6 +61,8 @@
|
|
|
61
61
|
"tooling/vitest/vitest.config.react.d.mts",
|
|
62
62
|
"tooling/vitest/vitest.setup.mjs",
|
|
63
63
|
"tooling/vitest/vitest.setup.d.mts",
|
|
64
|
+
"tooling/vitest/jsdom-shims.mjs",
|
|
65
|
+
"tooling/vitest/jsdom-shims.d.mts",
|
|
64
66
|
"tooling/tsup/index.ts",
|
|
65
67
|
"tooling/biome/biome.json",
|
|
66
68
|
"tooling/semantic-release/*.mjs",
|
|
@@ -123,6 +125,10 @@
|
|
|
123
125
|
"types": "./tooling/vitest/vitest.setup.d.mts",
|
|
124
126
|
"import": "./tooling/vitest/vitest.setup.mjs"
|
|
125
127
|
},
|
|
128
|
+
"./vitest/jsdom-shims": {
|
|
129
|
+
"types": "./tooling/vitest/jsdom-shims.d.mts",
|
|
130
|
+
"import": "./tooling/vitest/jsdom-shims.mjs"
|
|
131
|
+
},
|
|
126
132
|
"./tsup": "./tooling/tsup/index.ts",
|
|
127
133
|
"./biome": "./tooling/biome/biome.json",
|
|
128
134
|
"./semantic-release": {
|
|
@@ -142,24 +148,24 @@
|
|
|
142
148
|
"chalk": "^5.6.2",
|
|
143
149
|
"commander": "^14.0.3",
|
|
144
150
|
"fs-extra": "^11.3.2",
|
|
145
|
-
"inquirer": "^14.0.
|
|
151
|
+
"inquirer": "^14.0.2"
|
|
146
152
|
},
|
|
147
153
|
"devDependencies": {
|
|
148
|
-
"@biomejs/biome": "^2.
|
|
154
|
+
"@biomejs/biome": "^2.4.16",
|
|
155
|
+
"@commitlint/cli": "^20.1.0",
|
|
156
|
+
"@commitlint/config-conventional": "^21.0.2",
|
|
149
157
|
"@commitlint/types": "^20.0.0",
|
|
150
158
|
"@eslint/js": "^9.38.0",
|
|
151
159
|
"@ianvs/prettier-plugin-sort-imports": "^4.4.2",
|
|
152
|
-
"@
|
|
153
|
-
"@commitlint/config-conventional": "^21.0.1",
|
|
154
|
-
"@next/eslint-plugin-next": "^16.0.0",
|
|
160
|
+
"@next/eslint-plugin-next": "^16.2.7",
|
|
155
161
|
"@playwright/test": "^1.56.1",
|
|
156
162
|
"@semantic-release/changelog": "^6.0.3",
|
|
157
163
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
158
164
|
"@semantic-release/exec": "^7.1.0",
|
|
159
165
|
"@semantic-release/git": "^10.0.1",
|
|
160
|
-
"@semantic-release/github": "^12.0.
|
|
161
|
-
"@semantic-release/npm": "^13.1.
|
|
162
|
-
"@semantic-release/release-notes-generator": "^14.1.
|
|
166
|
+
"@semantic-release/github": "^12.0.8",
|
|
167
|
+
"@semantic-release/npm": "^13.1.5",
|
|
168
|
+
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
163
169
|
"@total-typescript/ts-reset": "0.6.1",
|
|
164
170
|
"@types/fs-extra": "^11.0.4",
|
|
165
171
|
"@types/node": "^25.9.1",
|
|
@@ -175,33 +181,34 @@
|
|
|
175
181
|
"eslint": "9.38.0",
|
|
176
182
|
"eslint-plugin-import": "^2.32.0",
|
|
177
183
|
"eslint-plugin-jest": "29.0.1",
|
|
178
|
-
"jest": "^29.7.0",
|
|
179
184
|
"husky": "^9.1.7",
|
|
180
185
|
"is-ci": "^4.1.0",
|
|
186
|
+
"jest": "^29.7.0",
|
|
187
|
+
"jsdom": "^26.1.0",
|
|
188
|
+
"knip": "^5.61.3",
|
|
181
189
|
"lint-staged": "^16.2.6",
|
|
182
|
-
"prettier": "^3.
|
|
183
|
-
"rimraf": "6.
|
|
184
|
-
"semantic-release": "^25.0.
|
|
185
|
-
"ts-jest": "^29.4.
|
|
190
|
+
"prettier": "^3.8.3",
|
|
191
|
+
"rimraf": "6.1.3",
|
|
192
|
+
"semantic-release": "^25.0.3",
|
|
193
|
+
"ts-jest": "^29.4.11",
|
|
186
194
|
"tsup": "8.5.1",
|
|
187
195
|
"typescript": "^5.9.3",
|
|
188
196
|
"typescript-eslint": "^8.60.0",
|
|
189
|
-
"vitest": "4.0.3"
|
|
190
|
-
"knip": "^5.61.3"
|
|
197
|
+
"vitest": "4.0.3"
|
|
191
198
|
},
|
|
192
199
|
"peerDependencies": {
|
|
193
200
|
"@biomejs/biome": "^2.0.0",
|
|
194
201
|
"@commitlint/cli": "^20.0.0",
|
|
195
|
-
"@commitlint/config-conventional": "^21.0.
|
|
202
|
+
"@commitlint/config-conventional": "^21.0.2",
|
|
196
203
|
"@commitlint/types": "^20.0.0",
|
|
197
204
|
"@eslint/js": "^9.0.0",
|
|
198
205
|
"@ianvs/prettier-plugin-sort-imports": "^4.0.0",
|
|
199
|
-
"@next/eslint-plugin-next": "^16.
|
|
206
|
+
"@next/eslint-plugin-next": "^16.2.7",
|
|
200
207
|
"@semantic-release/changelog": "^6.0.0",
|
|
201
208
|
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
202
209
|
"@semantic-release/exec": "^7.0.0",
|
|
203
210
|
"@semantic-release/git": "^10.0.0",
|
|
204
|
-
"@semantic-release/github": "^12.0.
|
|
211
|
+
"@semantic-release/github": "^12.0.8",
|
|
205
212
|
"@semantic-release/npm": "^13.0.0",
|
|
206
213
|
"@semantic-release/release-notes-generator": "^14.0.0",
|
|
207
214
|
"@total-typescript/ts-reset": "^0.6.0",
|
|
@@ -216,6 +223,8 @@
|
|
|
216
223
|
"jest": "^29.0.0",
|
|
217
224
|
"prettier": "^3.0.0",
|
|
218
225
|
"semantic-release": "^25.0.0",
|
|
226
|
+
"size-limit": "^12.0.0",
|
|
227
|
+
"@size-limit/preset-small-lib": "^12.0.0",
|
|
219
228
|
"ts-jest": "^29.0.0",
|
|
220
229
|
"tsup": "^8.0.0",
|
|
221
230
|
"typescript": ">=5.0.0",
|
|
@@ -301,6 +310,12 @@
|
|
|
301
310
|
"semantic-release": {
|
|
302
311
|
"optional": true
|
|
303
312
|
},
|
|
313
|
+
"size-limit": {
|
|
314
|
+
"optional": true
|
|
315
|
+
},
|
|
316
|
+
"@size-limit/preset-small-lib": {
|
|
317
|
+
"optional": true
|
|
318
|
+
},
|
|
304
319
|
"ts-jest": {
|
|
305
320
|
"optional": true
|
|
306
321
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// jsdom doesn't ship the browser APIs that Radix UI, cmdk, embla-carousel,
|
|
2
|
+
// react-day-picker and friends call at mount time. Import this file from your
|
|
3
|
+
// vitest setupFiles to install no-op polyfills for all of them:
|
|
4
|
+
//
|
|
5
|
+
// // vitest.config.ts -> test.setupFiles
|
|
6
|
+
// import '@rtorcato/js-tooling/vitest/jsdom-shims'
|
|
7
|
+
//
|
|
8
|
+
// Side-effect only; nothing is exported.
|
|
9
|
+
|
|
10
|
+
if (typeof Element !== 'undefined') {
|
|
11
|
+
if (!Element.prototype.hasPointerCapture) {
|
|
12
|
+
Element.prototype.hasPointerCapture = () => false
|
|
13
|
+
}
|
|
14
|
+
if (!Element.prototype.setPointerCapture) {
|
|
15
|
+
Element.prototype.setPointerCapture = () => {}
|
|
16
|
+
}
|
|
17
|
+
if (!Element.prototype.releasePointerCapture) {
|
|
18
|
+
Element.prototype.releasePointerCapture = () => {}
|
|
19
|
+
}
|
|
20
|
+
if (!Element.prototype.scrollIntoView) {
|
|
21
|
+
Element.prototype.scrollIntoView = () => {}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (typeof globalThis.ResizeObserver === 'undefined') {
|
|
26
|
+
globalThis.ResizeObserver = class ResizeObserver {
|
|
27
|
+
observe() {}
|
|
28
|
+
unobserve() {}
|
|
29
|
+
disconnect() {}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof globalThis.IntersectionObserver === 'undefined') {
|
|
34
|
+
globalThis.IntersectionObserver = class IntersectionObserver {
|
|
35
|
+
observe() {}
|
|
36
|
+
unobserve() {}
|
|
37
|
+
disconnect() {}
|
|
38
|
+
takeRecords() {
|
|
39
|
+
return []
|
|
40
|
+
}
|
|
41
|
+
root = null
|
|
42
|
+
rootMargin = ''
|
|
43
|
+
thresholds = []
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (typeof window !== 'undefined' && typeof window.matchMedia === 'undefined') {
|
|
48
|
+
window.matchMedia = (query) => ({
|
|
49
|
+
matches: false,
|
|
50
|
+
media: query,
|
|
51
|
+
onchange: null,
|
|
52
|
+
addListener: () => {},
|
|
53
|
+
removeListener: () => {},
|
|
54
|
+
addEventListener: () => {},
|
|
55
|
+
removeEventListener: () => {},
|
|
56
|
+
dispatchEvent: () => false,
|
|
57
|
+
})
|
|
58
|
+
}
|