Skip to content

Commit

Permalink
Make ./scripts a package, make scripts typecheck, remove old stuff, w…
Browse files Browse the repository at this point in the history
…orkflow updates (DefinitelyTyped#67128)
  • Loading branch information
jakebailey authored Oct 30, 2023
1 parent 6db928c commit fe7aab5
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 211 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,22 @@ jobs:
TOKEN='ghp_i5wtj1l2AbpFv3OU96w6R'
TOKEN+='On3bHOkcV2AmVY6'
DANGER_GITHUB_API_TOKEN=$TOKEN pnpm danger ci || $( exit 0 )
scripts:
runs-on: ubuntu-latest
if: github.repository == 'DefinitelyTyped/DefinitelyTyped'

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16'

- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: latest
run_install: |
- args: [--filter, ., --filter, '{./scripts}...']
- run: pnpm tsc -p ./scripts
11 changes: 8 additions & 3 deletions .github/workflows/UpdateCodeowners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ jobs:
with:
version: latest
run_install: |
- args: [--filter, .]
- args: [--filter, ., --filter, '{./scripts}...']
- run: git config --global user.email "[email protected]"
- run: git config --global user.name "TypeScript Bot"

- run: pnpm run update-codeowners
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

- uses: stefanzweifel/[email protected]
with:
commit_author: 'TypeScript Bot <[email protected]>'
commit_message: '🤖 Update CODEOWNERS'
commit_user_email: '[email protected]'
commit_user_name: 'TypeScript Bot'
2 changes: 1 addition & 1 deletion .github/workflows/format-and-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
version: latest
run_install: |
- args: [--filter, .]
- args: [--filter, ., --filter, '{./scripts}...']
- name: Get date
id: date
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ghostbuster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v4

Expand All @@ -34,7 +32,7 @@ jobs:
with:
version: latest
run_install: |
- args: [--filter, .]
- args: [--filter, ., --filter, '{./scripts}...']
- run: node ./scripts/ghostbuster.js
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-md.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ jobs:
with:
version: latest
run_install: |
- args: [--filter, .]
- args: [--filter, ., --filter, '{./scripts}...']
- run: pnpm remark --frail . .github
2 changes: 1 addition & 1 deletion .github/workflows/support-window.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
with:
version: latest
run_install: |
- args: [--filter, .]
- args: [--filter, ., --filter, '{./scripts}...']
- name: Fetch TypeScript versions and release dates from npm
run: |
npm view --json typescript time |
Expand Down
24 changes: 6 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,30 @@
"preinstall": "npx only-allow pnpm",
"not-needed": "node scripts/not-needed.js",
"update-codeowners": "node scripts/update-codeowners.js",
"test-all": "node --require source-map-support/register node_modules/@definitelytyped/dtslint-runner/ --path .",
"test-all": "node --enable-source-maps node_modules/@definitelytyped/dtslint-runner/ --path .",
"clean": "node scripts/remove-empty.js",
"clean-node-modules": "node scripts/clean-node-modules.js",
"test": "node --require source-map-support/register node_modules/@definitelytyped/dtslint/ types",
"lint": "node --require source-map-support/register node_modules/@definitelytyped/dtslint/ types",
"test": "node --enable-source-maps node_modules/@definitelytyped/dtslint/ types",
"lint": "node --enable-source-maps node_modules/@definitelytyped/dtslint/ types",
"prettier": "prettier"
},
"devDependencies": {
"@definitelytyped/definitions-parser": "latest",
"@definitelytyped/dts-critic": "latest",
"@definitelytyped/dtslint": "latest",
"@definitelytyped/dtslint-runner": "latest",
"@definitelytyped/eslint-plugin": "latest",
"@definitelytyped/header-parser": "latest",
"@definitelytyped/typescript-versions": "latest",
"@definitelytyped/utils": "latest",
"@octokit/core": "^3.5.1",
"@octokit/rest": "^16.0.0",
"comment-json": "^4.2.3",
"d3-array": "^3.0.2",
"d3-axis": "^3.0.0",
"d3-scale": "^4.0.0",
"d3-selection": "^3.0.0",
"d3-time": "^3.0.0",
"d3-time-format": "^4.0.0",
"danger": "^11.2.3",
"dprint": "^0.42.3",
"eslint-plugin-jsdoc": "^44.2.7",
"jsdom": "^17.0.0",
"remark-cli": "^11.0.0",
"remark-gfm": "^3.0.0",
"remark-validate-links": "^12.0.0",
"shelljs": "^0.8.5",
"source-map-support": "^0.5.21",
"typescript": "next",
"w3c-xmlserializer": "^2.0.0",
"yargs": "^17.1.1"
"tslint": "latest",
"typescript": "next"
},
"type": "module",
"husky": {
Expand Down
1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages:
- 'scripts'
- 'types/**'
7 changes: 7 additions & 0 deletions scripts/clean-node-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const __filename = url.fileURLToPath(new URL(import.meta.url));
const __dirname = path.dirname(__filename);
const repoRoot = path.resolve(__dirname, "..");

/**
* @param {string} p
* @returns {Iterable<string>}
*/
function* iterateNodeModules(p) {
const dirents = fs.readdirSync(p, { withFileTypes: true });
for (const dirent of dirents) {
Expand All @@ -20,6 +24,9 @@ function* iterateNodeModules(p) {
}
}

/**
* @param {string} p
*/
function rimraf(p) {
// The rimraf package uses maxRetries=10 on Windows, but Node's fs.rm does not have that special case.
return fs.rmSync(p, { recursive: true, force: true, maxRetries: process.platform === "win32" ? 10 : 0 });
Expand Down
65 changes: 0 additions & 65 deletions scripts/close-old-issues.js

This file was deleted.

1 change: 1 addition & 0 deletions scripts/fix-tslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ for (const dirName of fs.readdirSync(home)) {
function fixTslint(dir) {
const target = new URL("tslint.json", dir);
if (!fs.existsSync(target)) return;
/** @type {any} */
const json = JSON.parse(fs.readFileSync(target, "utf-8"));
json.rules = fixRules(json.rules);
const text = Object.keys(json).length === 1
Expand Down
41 changes: 0 additions & 41 deletions scripts/generate-tsconfigs.js

This file was deleted.

25 changes: 23 additions & 2 deletions scripts/ghostbuster.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
// @ts-check
import { flatMap, mapDefined } from "@definitelytyped/utils";
import { Octokit } from "@octokit/core";
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";

/** @type {<T, U>(array: readonly T[] | undefined, mapfn: (x: T, i: number) => readonly U[]) => readonly U[]} */
function flatMap(array, mapfn) {
const result = [];
if (array) {
for (let i = 0; i < array.length; i++) {
result.push(...mapfn(array[i], i));
}
}
return result;
}

/** @type {<T, U>(arr: Iterable<T>, mapper: (t: T) => U | undefined) => U[]} */
function mapDefined(arr, mapper) {
const out = [];
for (const a of arr) {
const res = mapper(a);
if (res !== undefined) {
out.push(res);
}
}
return out;
}

/**
* @typedef {{ githubUsername?: string }} Owner
* @typedef {{ owners: Owner[]; raw: string; }} PackageInfo
Expand Down
17 changes: 0 additions & 17 deletions scripts/jsconfig.json

This file was deleted.

32 changes: 32 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"private": true,
"type": "module",
"devDependencies": {
"@octokit/core": "^3.5.1",
"@types/d3-array": "^3.0.0",
"@types/d3-axis": "^3.0.0",
"@types/d3-scale": "^4.0.0",
"@types/d3-selection": "^3.0.0",
"@types/d3-time": "^3.0.0",
"@types/d3-time-format": "^4.0.0",
"@types/jsdom": "^21.1.0",
"@types/json-stable-stringify": "^1.0.0",
"@types/node": "*",
"@types/shelljs": "^0.8.0",
"@types/w3c-xmlserializer": "^2.0.0",
"@types/yargs": "^17.0.0",
"comment-json": "^4.2.3",
"d3-array": "^3.0.2",
"d3-axis": "^3.0.0",
"d3-scale": "^4.0.0",
"d3-selection": "^3.0.0",
"d3-time": "^3.0.0",
"d3-time-format": "^4.0.0",
"jsdom": "^17.0.0",
"json-stable-stringify": "^1.0.2",
"shelljs": "^0.8.5",
"typescript": "next",
"w3c-xmlserializer": "^2.0.0",
"yargs": "^17.1.1"
}
}
1 change: 1 addition & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "nodenext",
"strict": true,
"allowJs": true,
"checkJs": true,
"noEmit": true
},
"include": ["**/*.js"]
Expand Down
Loading

0 comments on commit fe7aab5

Please sign in to comment.