Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/danger-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: --dangerfile scripts/dangerfile.ts
args: --dangerfile scripts/dangerfile.js
3 changes: 3 additions & 0 deletions scripts/check-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

/**
* This file needs to be run before any other script to ensure dependencies are installed Therefore,
* we cannot transform this file to Typescript, because it would require esbuild to be installed
Expand Down
50 changes: 39 additions & 11 deletions scripts/dangerfile.ts → scripts/dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
/**
* IMPORTANT: This file has unique constraints due to how Danger.js executes it.
*
* Restrictions:
* - NO TypeScript: This file runs without any transpilation/transformation
* - NO external dependencies: Scripts dependencies are not installed in CI
* - NO Node.js built-ins: Even `fs` and other core modules don't work in Danger's runtime
* - MUST use `import` for Danger API: The Danger runtime only processes `import` statements,
* not `require()`. These imports get compiled to global references by Danger.js
* - CAN use `require()` for local files: Works for things like package.json
*
* Why: We want Danger to run as fast as possible in CI without installing dependencies
* or running build processes.
*/
Comment on lines +1 to +14
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to highlight this for future reference, this comment is important.

There are restrictions on what you can do in this file.
Unfortunately those restriction are such that this is a FAUX ESM file!


import { danger, fail } from 'danger';

const pkg = JSON.parse(await readFile(join(import.meta.dirname, '../package.json'), 'utf-8'));

const intersection = (a: readonly string[], b: readonly string[]) => a.filter((v) => b.includes(v));
/**
* Returns the intersection of two arrays
* @template T
* @param {ReadonlyArray<T>} a - First array
* @param {ReadonlyArray<T>} b - Second array
* @returns {T[]} Array containing elements present in both arrays
*/
function intersection(a, b) {
return a.filter((v) => b.includes(v));
}

const prLogConfig = pkg['pr-log'];
const pkg = require('../code/package.json');

const Versions = {
PATCH: 'PATCH',
Expand All @@ -17,9 +36,16 @@ const Versions = {

const ciLabels = ['ci:normal', 'ci:merged', 'ci:daily', 'ci:docs'];

const { labels } = danger.github.issue;

const prLogConfig = pkg['pr-log'];

const branchVersion = Versions.MINOR;

const checkRequiredLabels = (labels: string[]) => {
/**
* @param {string[]} labels
*/
const checkRequiredLabels = (labels) => {
const forbiddenLabels = [
'ci: do not merge',
'in progress',
Expand All @@ -29,13 +55,13 @@ const checkRequiredLabels = (labels: string[]) => {

const requiredLabels = [
...(prLogConfig?.skipLabels ?? []),
...(prLogConfig?.validLabels ?? []).map(([label]: [string]) => label),
...(prLogConfig?.validLabels ?? []).map(([label]) => label),
];

const blockingLabels = intersection(forbiddenLabels, labels);
if (blockingLabels.length > 0) {
fail(
`PR is marked with ${blockingLabels.map((label: string) => `"${label}"`).join(', ')} label${
`PR is marked with ${blockingLabels.map((label) => `"${label}"`).join(', ')} label${
blockingLabels.length > 1 ? 's' : ''
}.`
);
Expand All @@ -56,7 +82,10 @@ const checkRequiredLabels = (labels: string[]) => {
}
};

const checkPrTitle = (title: string) => {
/**
* @param {string} title
*/
const checkPrTitle = (title) => {
const match = title.match(/^[A-Z].+:\s[A-Z].+$/);
if (!match) {
fail(
Expand All @@ -73,7 +102,6 @@ Bad examples:
};

if (prLogConfig) {
const { labels } = danger.github.issue;
checkRequiredLabels(labels.map((l) => l.name));
checkPrTitle(danger.github.pr.title);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

module.exports = {
meta: {
type: 'problem',
Expand Down
3 changes: 3 additions & 0 deletions scripts/eslint-plugin-local-rules/no-uncategorized-errors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

module.exports = {
meta: {
type: 'problem',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

const path = require('path');
const cache = {};

Expand Down
6 changes: 3 additions & 3 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"esbuild": "^0.27.0",
"serialize-javascript": "^3.1.0",
"type-fest": "~2.19",
"typescript": "^5.8.3"
"typescript": "^5.9.3"
},
"dependencies": {
"@actions/core": "^1.11.1",
Expand Down Expand Up @@ -149,7 +149,7 @@
"playwright": "1.52.0",
"playwright-core": "1.52.0",
"polka": "^1.0.0-next.28",
"prettier": "^3.5.3",
"prettier": "^3.6.2",
"prettier-plugin-brace-style": "^0.7.2",
"prettier-plugin-css-order": "^2.1.2",
"prettier-plugin-curly": "^0.3.2",
Expand All @@ -175,7 +175,7 @@
"trash": "^7.2.0",
"ts-dedent": "^2.2.0",
"type-fest": "~2.19",
"typescript": "^5.8.3",
"typescript": "^5.9.3",
"uuid": "^9.0.1",
"vitest": "^3.2.4",
"wait-on": "^8.0.3",
Expand Down
2 changes: 2 additions & 0 deletions scripts/reset.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { spawn } from 'node:child_process';
import { appendFile, writeFileSync } from 'node:fs';
import { rm } from 'node:fs/promises';
Expand Down
2 changes: 2 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"baseUrl": ".",
"incremental": false,
"noImplicitAny": true,
"allowJs": true,
"checkJs": true,
"jsx": "react",
"moduleResolution": "bundler",
"target": "ESNext",
Expand Down
Loading
Loading