@zairakai/js-dev-tools 3.16.0 → 3.17.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 CHANGED
@@ -179,6 +179,7 @@ The pipeline template updates the dependencies of a project by itself, and this
179
179
  - `deps:release` brings `develop` into `main` after such an update, and `deps:tag` tags `main` when a published range (`dependencies`, `peerDependencies`) changed. A project that changed only its development dependencies is not tagged: its published archive is the same.
180
180
  - After the publication of a tag, `deps:cascade` waits for the version to be on the registry, then starts the update of the projects that have a `.dependency-update.json`.
181
181
  - The packages of the [dependency policy](https://gitlab.com/zairakai/dependency-policy) (`node.json`) are never updated. `node node_modules/@zairakai/js-dev-tools/scripts/update-dependencies.mjs policy-check <ref>` fails when the change since `<ref>` updates one of them in `package.json` or `package-lock.json`; it only reads, so it runs on GitHub as well.
182
+ - `dependabot-sync` rewrites the ignore rules of `.github/dependabot.yml`, between `# BEGIN dependency-policy (npm)` and `# END dependency-policy (npm)`, with one rule per package of the policy: the policy is the only place where a package is held back.
182
183
 
183
184
  The same script serves the PHP projects (`composer.json`): a job in the PHP image runs `composer update`, then this script commits, signs and opens the merge request, and `deps:tag` looks at `require` only. The jobs that sign (`deps:update`, `deps:tag`) run on an exact version of the node image (`NODE_UPDATE_IMAGE`, published on Docker Hub), because they need `gpg` and the image of the runner is not updated by itself.
184
185
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zairakai/js-dev-tools",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "The unified and centralized development toolkit for JavaScript/TypeScript projects - ESLint, Prettier, Stylelint, Knip, Vitest, Git Hooks, and GitLab CI pipeline templates",
5
5
  "keywords": [
6
6
  "dev-tools",
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Automatic updates of the dependencies of a package of the zairakai group.
4
4
  *
5
- * Usage: node update-dependencies.mjs update | release | tag | cascade | audit | policy | policy-validate | policy-check <ref>
5
+ * Usage: node update-dependencies.mjs update | release | tag | cascade | audit | policy | policy-validate | policy-check <ref> | dependabot-sync
6
6
  *
7
7
  * - update: prepare a branch with the minor and patch updates, open a merge request into develop and merge it when its
8
8
  * pipeline succeeds. The pipeline of the merge request is the gate: nothing is tested here.
@@ -14,6 +14,7 @@
14
14
  * - policy: in the repository dependency-policy, lift the entries whose condition is met (merge request).
15
15
  * - policy-validate: in the repository dependency-policy, check the shape of the files.
16
16
  * - policy-check: fail when the change since a ref updates a package of the policy (GitLab or GitHub, it only reads).
17
+ * - dependabot-sync: rewrite the ignore rules of .github/dependabot.yml (between the markers of the ecosystem) from the policy.
17
18
  *
18
19
  * The packages listed in the dependency policy (https://gitlab.com/zairakai/dependency-policy) are never updated, whatever
19
20
  * the project. DEPENDENCY_POLICY_URL replaces the address of the files.
@@ -45,6 +46,7 @@ const ISSUE_LABELS = ['Kind::Security', 'Area::Security', 'Automated']
45
46
  const POLICY_URL = 'https://gitlab.com/zairakai/dependency-policy/-/raw/main'
46
47
  const POLICY_FILES = { npm: 'node.json', composer: 'php.json' }
47
48
  const POLICY_BRANCH_PREFIX = 'chore/unblock'
49
+ const DEPENDABOT_FILE = '.github/dependabot.yml'
48
50
  const GROUP_SCOPE = '@zairakai/'
49
51
  const TRUSTED_SCOPES = [GROUP_SCOPE, '@stanislas-poisson/']
50
52
 
@@ -292,6 +294,28 @@ export function policyViolations({ blocked, beforeManifest, afterManifest, befor
292
294
  return problems
293
295
  }
294
296
 
297
+ /**
298
+ * The text of dependabot.yml with the block of the ecosystem rewritten: between `# BEGIN dependency-policy (npm)` and
299
+ * `# END dependency-policy (npm)`, one ignore rule per package of the policy (nothing when none). Null without markers.
300
+ */
301
+ export function syncDependabot(text, names, ecosystem) {
302
+ const begin = `# BEGIN dependency-policy (${ecosystem})`
303
+ const end = `# END dependency-policy (${ecosystem})`
304
+ const pattern = new RegExp(
305
+ `^([ \\t]*)${begin.replaceAll(/[()]/g, '\\$&')}\\n[\\s\\S]*?^[ \\t]*${end.replaceAll(/[()]/g, '\\$&')}$`,
306
+ 'm'
307
+ )
308
+ const match = pattern.exec(text)
309
+
310
+ if (null === match) return null
311
+
312
+ const indent = match[1]
313
+ const rules =
314
+ 0 === names.length ? [] : [`${indent}ignore:`, ...names.map((name) => `${indent} - dependency-name: "${name}"`)]
315
+
316
+ return text.replace(pattern, () => [`${indent}${begin}`, ...rules, `${indent}${end}`].join('\n'))
317
+ }
318
+
295
319
  /**
296
320
  * The packages of a lock file that the refresh may update: the ones of the group are left out, because they are trusted
297
321
  * and not made to wait, and the cooling date would refuse a version that was just published.
@@ -1120,6 +1144,29 @@ async function policyCheck(_config, base) {
1120
1144
  log('No package of the dependency policy is updated.')
1121
1145
  }
1122
1146
 
1147
+ /** Rewrite the ignore rules of .github/dependabot.yml from the policy. The workflow of the repository commits the result. */
1148
+ async function dependabotSync() {
1149
+ if (!existsSync(DEPENDABOT_FILE)) throw new Error(`${DEPENDABOT_FILE} does not exist.`)
1150
+
1151
+ const names = (await readPolicy('npm')).entries.map((entry) => entry.package)
1152
+ const text = readFileSync(DEPENDABOT_FILE, 'utf8')
1153
+ const synced = syncDependabot(text, names, 'npm')
1154
+
1155
+ if (null === synced) {
1156
+ throw new Error(
1157
+ `${DEPENDABOT_FILE} has no block "# BEGIN dependency-policy (npm)" ... "# END dependency-policy (npm)".`
1158
+ )
1159
+ }
1160
+
1161
+ if (synced === text) {
1162
+ log('The ignore rules of Dependabot are in sync with the policy.')
1163
+ return
1164
+ }
1165
+
1166
+ writeFileSync(DEPENDABOT_FILE, synced)
1167
+ log(`The ignore rules of Dependabot are updated: ${names.join(', ') || 'none'}.`)
1168
+ }
1169
+
1123
1170
  const modes = {
1124
1171
  update,
1125
1172
  release,
@@ -1129,6 +1176,7 @@ const modes = {
1129
1176
  policy: policyWatch,
1130
1177
  'policy-validate': policyValidate,
1131
1178
  'policy-check': policyCheck,
1179
+ 'dependabot-sync': dependabotSync,
1132
1180
  }
1133
1181
 
1134
1182
  async function main(mode, argument) {