@rtorcato/js-tooling 2.19.1 → 2.20.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.
@@ -807,6 +807,23 @@ async function checkCodeowners(dir) {
807
807
  hint: 'Run `npx @rtorcato/js-tooling fix codeowners` to scaffold .github/CODEOWNERS',
808
808
  };
809
809
  }
810
+ async function checkCommunityHealth(dir) {
811
+ const anchors = ['CONTRIBUTING.md', 'SECURITY.md'];
812
+ const present = await Promise.all(anchors.map((f) => fs.pathExists(path.join(dir, f))));
813
+ if (present.every(Boolean)) {
814
+ return {
815
+ check: 'Community health',
816
+ status: 'ok',
817
+ detail: 'CONTRIBUTING.md and SECURITY.md found',
818
+ };
819
+ }
820
+ return {
821
+ check: 'Community health',
822
+ status: 'optional-missing',
823
+ detail: 'missing community-health files (CONTRIBUTING/SECURITY/templates)',
824
+ hint: 'Run `npx @rtorcato/js-tooling fix community-health` to scaffold them',
825
+ };
826
+ }
810
827
  async function checkGitLabCI(dir) {
811
828
  for (const candidate of ['.gitlab-ci.yml', '.gitlab-ci.yaml']) {
812
829
  if (await fs.pathExists(path.join(dir, candidate))) {
@@ -850,6 +867,7 @@ export async function runDoctor(dir) {
850
867
  results.push(await checkCodeQL(targetDir));
851
868
  results.push(await checkGitLabCI(targetDir));
852
869
  results.push(await checkCodeowners(targetDir));
870
+ results.push(await checkCommunityHealth(targetDir));
853
871
  results.push(await checkTypedoc(targetDir, pkg));
854
872
  results.push(await checkAreTheTypesWrong(targetDir, pkg));
855
873
  results.push(await checkTreeshakeSetup(targetDir, pkg));
@@ -6,6 +6,7 @@ import fs from 'fs-extra';
6
6
  import inquirer from 'inquirer';
7
7
  import { installAgentRules } from '../generators/agent-rules.js';
8
8
  import { generateSemanticReleaseConfig } from '../generators/build.js';
9
+ import { generateCommunityHealth } from '../generators/community-health.js';
9
10
  import { generateCommitlintConfig, generateHuskyConfig, generatePrePushHook, } from '../generators/git.js';
10
11
  import { generateGitHubActions } from '../generators/github-actions.js';
11
12
  import { generateGitLabCI } from '../generators/gitlab-ci.js';
@@ -210,17 +211,17 @@ const FIXERS = [
210
211
  },
211
212
  {
212
213
  target: 'semantic-release',
213
- description: 'Scaffold release.config.mjs (skipped on private packages)',
214
+ description: 'Scaffold release.config.mjs + install preset plugins (skipped on private packages)',
214
215
  appliesTo: ['semantic-release'],
215
- outputs: ['release.config.mjs'],
216
+ outputs: ['release.config.mjs', 'package.json'],
216
217
  canFixDrift: true,
217
218
  async run({ targetDir, pkg }) {
218
219
  if (pkg?.private === true) {
219
220
  console.log(chalk.gray(' skipping — package is private'));
220
221
  return { filesWritten: [] };
221
222
  }
222
- await generateSemanticReleaseConfig(targetDir);
223
- return { filesWritten: ['release.config.mjs'] };
223
+ const filesWritten = await generateSemanticReleaseConfig(targetDir);
224
+ return { filesWritten };
224
225
  },
225
226
  },
226
227
  {
@@ -299,6 +300,24 @@ const FIXERS = [
299
300
  return { filesWritten: [written] };
300
301
  },
301
302
  },
303
+ {
304
+ target: 'community-health',
305
+ description: 'Scaffold CONTRIBUTING.md, SECURITY.md, PR + issue templates',
306
+ appliesTo: ['Community health'],
307
+ outputs: [
308
+ 'CONTRIBUTING.md',
309
+ 'SECURITY.md',
310
+ '.github/PULL_REQUEST_TEMPLATE.md',
311
+ '.github/ISSUE_TEMPLATE/bug_report.md',
312
+ '.github/ISSUE_TEMPLATE/feature_request.md',
313
+ ],
314
+ riskLevel: 'safe-add',
315
+ canFixDrift: false,
316
+ async run({ targetDir }) {
317
+ const filesWritten = await generateCommunityHealth(targetDir);
318
+ return { filesWritten };
319
+ },
320
+ },
302
321
  {
303
322
  target: 'gitlab-ci',
304
323
  description: 'Scaffold .gitlab-ci.yml (lint/typecheck/test/build mirrored from GitHub Actions)',
@@ -71,11 +71,41 @@ export default mergeConfig(preset, defineConfig({ plugins: [react()] }))
71
71
  `;
72
72
  await fs.writeFile(viteConfigPath, viteConfig);
73
73
  }
74
+ // Plugins the github/gitlab preset activates that semantic-release core does
75
+ // NOT bundle (core bundles only commit-analyzer, release-notes-generator, npm,
76
+ // github). Without these in the consumer's deps, `semantic-release` crashes
77
+ // with "Cannot find module '@semantic-release/changelog'" on first run.
78
+ const RELEASE_PLUGIN_DEPS = {
79
+ '@semantic-release/changelog': '^6.0.0',
80
+ '@semantic-release/git': '^10.0.0',
81
+ };
74
82
  export async function generateSemanticReleaseConfig(targetDir) {
75
83
  const releaseConfigPath = path.join(targetDir, 'release.config.mjs');
76
84
  const releaseConfig = `export { default } from '@rtorcato/js-tooling/semantic-release/github'
77
85
  `;
78
86
  await fs.writeFile(releaseConfigPath, releaseConfig);
87
+ const written = ['release.config.mjs'];
88
+ // Ensure the preset's non-bundled plugins are installed; otherwise the
89
+ // scaffolded release.config.mjs references modules the consumer lacks.
90
+ const pkgPath = path.join(targetDir, 'package.json');
91
+ if (await fs.pathExists(pkgPath)) {
92
+ const pkg = (await fs.readJson(pkgPath));
93
+ const devDeps = (pkg.devDependencies ?? {});
94
+ const deps = (pkg.dependencies ?? {});
95
+ let changed = false;
96
+ for (const [name, version] of Object.entries(RELEASE_PLUGIN_DEPS)) {
97
+ if (!devDeps[name] && !deps[name]) {
98
+ devDeps[name] = version;
99
+ changed = true;
100
+ }
101
+ }
102
+ if (changed) {
103
+ pkg.devDependencies = devDeps;
104
+ await fs.writeJson(pkgPath, pkg, { spaces: 2 });
105
+ written.push('package.json');
106
+ }
107
+ }
108
+ return written;
79
109
  }
80
110
  export async function generateChangesetsConfig(targetDir) {
81
111
  // Drop the canonical Changesets config into .changeset/config.json. The user
@@ -0,0 +1,145 @@
1
+ import path from 'node:path';
2
+ import fs from 'fs-extra';
3
+ const CONTRIBUTING = `# Contributing
4
+
5
+ Thanks for your interest in contributing!
6
+
7
+ ## Local setup
8
+
9
+ \`\`\`bash
10
+ pnpm install
11
+ pnpm build
12
+ pnpm test
13
+ \`\`\`
14
+
15
+ ## Commit messages
16
+
17
+ This project uses [Conventional Commits](https://www.conventionalcommits.org/).
18
+ Format: \`type(scope): summary\` — e.g. \`fix(api): handle empty payload\`.
19
+ Common types: \`feat\`, \`fix\`, \`docs\`, \`refactor\`, \`test\`, \`chore\`.
20
+ If commitizen is set up, run \`pnpm commit\` to be guided through it.
21
+
22
+ ## Pull requests
23
+
24
+ - Keep PRs focused and small where possible.
25
+ - Make sure \`pnpm test\` and \`pnpm check\` (lint) pass.
26
+ - Add tests for new behaviour.
27
+ - Describe what changed and why in the PR description.
28
+ `;
29
+ // Relative advisory link works from a repo-root SECURITY.md on GitHub, so the
30
+ // template stays repo-agnostic (no hardcoded owner/name). Fill in the contact.
31
+ const SECURITY = `# Security Policy
32
+
33
+ ## Supported versions
34
+
35
+ Only the latest major version receives security fixes.
36
+
37
+ ## Reporting a vulnerability
38
+
39
+ Do **not** open a public GitHub issue for security vulnerabilities.
40
+
41
+ Instead, use [GitHub's private vulnerability reporting](../../security/advisories/new)
42
+ or email **<security-contact@example.com>** with:
43
+
44
+ - A description of the vulnerability
45
+ - Steps to reproduce
46
+ - Potential impact
47
+
48
+ You'll receive a response within 5 business days.
49
+ `;
50
+ const PULL_REQUEST_TEMPLATE = `## Summary
51
+
52
+ <!-- 1-3 bullet points describing what changed and why -->
53
+ -
54
+
55
+ ## Type of change
56
+
57
+ - [ ] Bug fix
58
+ - [ ] New feature
59
+ - [ ] Refactor / cleanup
60
+ - [ ] Documentation
61
+ - [ ] CI / tooling
62
+
63
+ ## Test plan
64
+
65
+ - [ ] Existing tests pass (\`pnpm test\`)
66
+ - [ ] New tests added for new behaviour
67
+
68
+ ## Checklist
69
+
70
+ - [ ] No debug logging left in production code
71
+ - [ ] No breaking changes (or BREAKING CHANGE footer added to commit)
72
+ - [ ] Lint passes (\`pnpm check\` / \`pnpm lint\`)
73
+ `;
74
+ const BUG_REPORT = `---
75
+ name: Bug report
76
+ about: Something isn't working as expected
77
+ labels: bug
78
+ ---
79
+
80
+ ## Describe the bug
81
+
82
+ <!-- A clear and concise description of what the bug is -->
83
+
84
+ ## Steps to reproduce
85
+
86
+ 1.
87
+ 2.
88
+ 3.
89
+
90
+ ## Expected behaviour
91
+
92
+ ## Actual behaviour
93
+
94
+ <!-- Paste any error output here -->
95
+
96
+ \`\`\`
97
+ \`\`\`
98
+
99
+ ## Environment
100
+
101
+ - Package version:
102
+ - Node version (\`node -v\`):
103
+ - Package manager + version:
104
+ - OS:
105
+ `;
106
+ const FEATURE_REQUEST = `---
107
+ name: Feature request
108
+ about: Suggest an idea or improvement
109
+ labels: enhancement
110
+ ---
111
+
112
+ ## Problem
113
+
114
+ <!-- What are you trying to do that you can't do today? -->
115
+
116
+ ## Proposed solution
117
+
118
+ ## Alternatives considered
119
+
120
+ ## Additional context
121
+ `;
122
+ const FILES = [
123
+ { rel: 'CONTRIBUTING.md', content: CONTRIBUTING },
124
+ { rel: 'SECURITY.md', content: SECURITY },
125
+ { rel: '.github/PULL_REQUEST_TEMPLATE.md', content: PULL_REQUEST_TEMPLATE },
126
+ { rel: '.github/ISSUE_TEMPLATE/bug_report.md', content: BUG_REPORT },
127
+ { rel: '.github/ISSUE_TEMPLATE/feature_request.md', content: FEATURE_REQUEST },
128
+ ];
129
+ /**
130
+ * Scaffold GitHub community-health files. Safe-add: existing files are left
131
+ * untouched (the user owns them once written). Returns the list of files
132
+ * actually created.
133
+ */
134
+ export async function generateCommunityHealth(targetDir) {
135
+ const written = [];
136
+ for (const { rel, content } of FILES) {
137
+ const filepath = path.join(targetDir, rel);
138
+ if (await fs.pathExists(filepath))
139
+ continue;
140
+ await fs.ensureDir(path.dirname(filepath));
141
+ await fs.writeFile(filepath, content);
142
+ written.push(rel);
143
+ }
144
+ return written;
145
+ }
@@ -48,15 +48,15 @@ jobs:
48
48
  cache-key: \${{ steps.cache-key.outputs.key }}
49
49
  steps:
50
50
  - name: 📦 Checkout repository
51
- uses: actions/checkout@v4
51
+ uses: actions/checkout@v7
52
52
 
53
53
  - name: 📦 Setup Node.js
54
- uses: actions/setup-node@v4
54
+ uses: actions/setup-node@v6
55
55
  with:
56
56
  node-version-file: .nvmrc
57
57
 
58
58
  - name: 📦 Setup pnpm
59
- uses: pnpm/action-setup@v4
59
+ uses: pnpm/action-setup@v6
60
60
  with:
61
61
  version: latest
62
62
 
@@ -65,7 +65,7 @@ jobs:
65
65
  run: echo "key=\${{ runner.os }}-pnpm-\${{ hashFiles('**/pnpm-lock.yaml') }}" >> $GITHUB_OUTPUT
66
66
 
67
67
  - name: 📦 Cache dependencies
68
- uses: actions/cache@v4
68
+ uses: actions/cache@v5
69
69
  with:
70
70
  path: |
71
71
  ~/.pnpm-store
@@ -83,20 +83,20 @@ jobs:
83
83
  if: needs.check-skip.outputs.should-skip != 'true'
84
84
  steps:
85
85
  - name: 📦 Checkout repository
86
- uses: actions/checkout@v4
86
+ uses: actions/checkout@v7
87
87
 
88
88
  - name: 📦 Setup Node.js
89
- uses: actions/setup-node@v4
89
+ uses: actions/setup-node@v6
90
90
  with:
91
91
  node-version-file: .nvmrc
92
92
 
93
93
  - name: 📦 Setup pnpm
94
- uses: pnpm/action-setup@v4
94
+ uses: pnpm/action-setup@v6
95
95
  with:
96
96
  version: latest
97
97
 
98
98
  - name: 📦 Restore dependencies cache
99
- uses: actions/cache@v4
99
+ uses: actions/cache@v5
100
100
  with:
101
101
  path: |
102
102
  ~/.pnpm-store
@@ -113,20 +113,20 @@ ${hasTypeScript
113
113
  if: needs.check-skip.outputs.should-skip != 'true'
114
114
  steps:
115
115
  - name: 📦 Checkout repository
116
- uses: actions/checkout@v4
116
+ uses: actions/checkout@v7
117
117
 
118
118
  - name: 📦 Setup Node.js
119
- uses: actions/setup-node@v4
119
+ uses: actions/setup-node@v6
120
120
  with:
121
121
  node-version-file: .nvmrc
122
122
 
123
123
  - name: 📦 Setup pnpm
124
- uses: pnpm/action-setup@v4
124
+ uses: pnpm/action-setup@v6
125
125
  with:
126
126
  version: latest
127
127
 
128
128
  - name: 📦 Restore dependencies cache
129
- uses: actions/cache@v4
129
+ uses: actions/cache@v5
130
130
  with:
131
131
  path: |
132
132
  ~/.pnpm-store
@@ -144,20 +144,20 @@ ${hasTests
144
144
  if: needs.check-skip.outputs.should-skip != 'true'
145
145
  steps:
146
146
  - name: 📦 Checkout repository
147
- uses: actions/checkout@v4
147
+ uses: actions/checkout@v7
148
148
 
149
149
  - name: 📦 Setup Node.js
150
- uses: actions/setup-node@v4
150
+ uses: actions/setup-node@v6
151
151
  with:
152
152
  node-version-file: .nvmrc
153
153
 
154
154
  - name: 📦 Setup pnpm
155
- uses: pnpm/action-setup@v4
155
+ uses: pnpm/action-setup@v6
156
156
  with:
157
157
  version: latest
158
158
 
159
159
  - name: 📦 Restore dependencies cache
160
- uses: actions/cache@v4
160
+ uses: actions/cache@v5
161
161
  with:
162
162
  path: |
163
163
  ~/.pnpm-store
@@ -175,20 +175,20 @@ ${hasBuild
175
175
  if: needs.check-skip.outputs.should-skip != 'true'
176
176
  steps:
177
177
  - name: 📦 Checkout repository
178
- uses: actions/checkout@v4
178
+ uses: actions/checkout@v7
179
179
 
180
180
  - name: 📦 Setup Node.js
181
- uses: actions/setup-node@v4
181
+ uses: actions/setup-node@v6
182
182
  with:
183
183
  node-version-file: .nvmrc
184
184
 
185
185
  - name: 📦 Setup pnpm
186
- uses: pnpm/action-setup@v4
186
+ uses: pnpm/action-setup@v6
187
187
  with:
188
188
  version: latest
189
189
 
190
190
  - name: 📦 Restore dependencies cache
191
- uses: actions/cache@v4
191
+ uses: actions/cache@v5
192
192
  with:
193
193
  path: |
194
194
  ~/.pnpm-store
@@ -199,7 +199,7 @@ ${hasBuild
199
199
  run: pnpm build
200
200
 
201
201
  - name: 📦 Upload build artifacts
202
- uses: actions/upload-artifact@v4
202
+ uses: actions/upload-artifact@v7
203
203
  with:
204
204
  name: build-artifacts
205
205
  path: |
@@ -221,24 +221,24 @@ ${isLibrary && config.semanticRelease
221
221
  id-token: write
222
222
  steps:
223
223
  - name: 📦 Checkout repository
224
- uses: actions/checkout@v4
224
+ uses: actions/checkout@v7
225
225
  with:
226
226
  fetch-depth: 0
227
227
  token: \${{ secrets.GITHUB_TOKEN }}
228
228
 
229
229
  - name: 📦 Setup Node.js
230
- uses: actions/setup-node@v4
230
+ uses: actions/setup-node@v6
231
231
  with:
232
232
  node-version-file: .nvmrc
233
233
  registry-url: 'https://registry.npmjs.org'
234
234
 
235
235
  - name: 📦 Setup pnpm
236
- uses: pnpm/action-setup@v4
236
+ uses: pnpm/action-setup@v6
237
237
  with:
238
238
  version: latest
239
239
 
240
240
  - name: 📦 Restore dependencies cache
241
- uses: actions/cache@v4
241
+ uses: actions/cache@v5
242
242
  with:
243
243
  path: |
244
244
  ~/.pnpm-store
@@ -59,7 +59,7 @@ function renderGitLabCI(config) {
59
59
  return `# .gitlab-ci.yml — generated by @rtorcato/js-tooling
60
60
  # Customize stages and jobs to fit your pipeline.
61
61
 
62
- image: node:20
62
+ image: node:22
63
63
 
64
64
  stages:
65
65
  ${stages.map((s) => ` - ${s}`).join('\n')}
@@ -32,7 +32,7 @@ export async function generateBiomeConfig(targetDir) {
32
32
  // keys here forced consumers to run `biome migrate` before `biome check`
33
33
  // would run at all.
34
34
  const biomeConfig = {
35
- $schema: 'https://biomejs.dev/schemas/2.3.0/schema.json',
35
+ $schema: 'https://biomejs.dev/schemas/2.5.0/schema.json',
36
36
  extends: ['@rtorcato/js-tooling/biome'],
37
37
  };
38
38
  await fs.writeJson(biomeConfigPath, biomeConfig, { spaces: 2 });
@@ -75,7 +75,7 @@ jobs:
75
75
 
76
76
  steps:
77
77
  - name: Checkout
78
- uses: actions/checkout@v4
78
+ uses: actions/checkout@v7
79
79
 
80
80
  - name: Initialize CodeQL
81
81
  uses: github/codeql-action/init@v3
@@ -10,9 +10,9 @@ jobs:
10
10
  permissions:
11
11
  contents: write
12
12
  steps:
13
- - uses: actions/checkout@v4
14
- - uses: pnpm/action-setup@v4
15
- - uses: actions/setup-node@v4
13
+ - uses: actions/checkout@v7
14
+ - uses: pnpm/action-setup@v6
15
+ - uses: actions/setup-node@v6
16
16
  with:
17
17
  node-version: 22
18
18
  cache: pnpm
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtorcato/js-tooling",
3
- "version": "2.19.1",
3
+ "version": "2.20.0",
4
4
  "description": "JavaScript and TypeScript tooling for Node.js, React, Next.js, and Vitest.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -175,7 +175,8 @@
175
175
  "./tests/ssr-safety": {
176
176
  "types": "./tooling/tests/ssr-safety.d.mts",
177
177
  "import": "./tooling/tests/ssr-safety.mjs"
178
- }
178
+ },
179
+ "./package.json": "./package.json"
179
180
  },
180
181
  "dependencies": {
181
182
  "chalk": "^5.6.2",
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/2.3.0/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/2.5.0/schema.json",
3
3
  "vcs": {
4
4
  "enabled": false,
5
5
  "clientKind": "git",
@@ -27,7 +27,7 @@
27
27
  "linter": {
28
28
  "enabled": true,
29
29
  "rules": {
30
- "recommended": true,
30
+ "preset": "recommended",
31
31
  "style": {
32
32
  "noInferrableTypes": "off"
33
33
  },
@@ -51,8 +51,11 @@ export default {
51
51
  changelogFile: 'CHANGELOG.md',
52
52
  },
53
53
  ],
54
- ['@semantic-release/npm', { npmPublish: true, pkgRoot: '.' }],
55
- // NPM plugin to publish the package
54
+ // npm publishing is opt-in via NPM_TOKEN: a repo that provides the token
55
+ // (e.g. js-tooling's own CI) publishes; one that doesn't (GitHub-releases
56
+ // only) gets a green release instead of an EINVALIDNPMTOKEN failure. The
57
+ // version in package.json is still bumped either way.
58
+ ['@semantic-release/npm', { npmPublish: Boolean(process.env.NPM_TOKEN), pkgRoot: '.' }],
56
59
  [
57
60
  '@semantic-release/git',
58
61
  {
@@ -52,8 +52,11 @@ export default {
52
52
  changelogFile: 'CHANGELOG.md',
53
53
  },
54
54
  ],
55
- ['@semantic-release/npm', { npmPublish: true, pkgRoot: '.' }],
56
- // NPM plugin to publish the package
55
+ // npm publishing is opt-in via NPM_TOKEN: a repo that provides the token
56
+ // publishes; one that doesn't (GitLab releases only) gets a green release
57
+ // instead of an EINVALIDNPMTOKEN failure. The version in package.json is
58
+ // still bumped either way.
59
+ ['@semantic-release/npm', { npmPublish: Boolean(process.env.NPM_TOKEN), pkgRoot: '.' }],
57
60
  [
58
61
  '@semantic-release/git',
59
62
  {