Skip to content

Commit e1acfb9

Browse files
authored
Update Node.js + dependencies (#36)
* Update to Node.js 22 * Replace import assert w/ import with * Remove node-fetch usage * Fix missing confirm import * Update chalk to latest * Update diff to latest * Update @octokit/rest to latest
1 parent a6afe71 commit e1acfb9

File tree

8 files changed

+303
-738
lines changed

8 files changed

+303
-738
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16.20.2
1+
v22.16.0

package-lock.json

Lines changed: 278 additions & 713 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
},
1717
"homepage": "https://github.com/js-org/js.org-cleanup#readme",
1818
"dependencies": {
19-
"@octokit/rest": "^16.28.2",
20-
"chalk": "^2.4.2",
21-
"diff": "^5.0.0",
22-
"node-fetch": "^2.6.7",
23-
"octokit-create-pull-request": "^1.2.0"
19+
"@octokit/rest": "^22.0.0",
20+
"chalk": "^5.4.1",
21+
"diff": "^8.0.2",
22+
"octokit-plugin-create-pull-request": "^6.0.1"
2423
}
2524
}

src/robot/cnames.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { URL } from 'node:url';
22

33
import chalk from 'chalk';
4-
import fetch from 'node-fetch';
5-
import Octokit from '@octokit/rest';
4+
import { Octokit } from '@octokit/rest';
65

76
import { log } from '../util/log.js';
87
import { getCache, setCache } from './cache.js';
9-
import config from '../../config.json' assert { type: 'json' };
8+
import config from '../../config.json' with { type: 'json' };
109

1110
const octokit = new Octokit();
1211

@@ -19,7 +18,7 @@ export const getCNAMEsFile = async () => {
1918
log('\nStarting getCNAMEsFile process', chalk.cyanBright.bold);
2019

2120
// Get the raw GitHub API data
22-
const req = await octokit.repos.getContents({
21+
const req = await octokit.rest.repos.getContent({
2322
owner: config.repository_owner,
2423
repo: config.repository_name,
2524
path: 'cnames_active.js'
@@ -45,7 +44,7 @@ const testUrl = async url => {
4544

4645
try {
4746
resp = await fetch(url, {
48-
headers: { 'User-Agent': 'js.org-cleanup/1.0 node-fetch' },
47+
headers: { 'User-Agent': 'js.org-cleanup/1.0' },
4948
signal: controller.signal,
5049
});
5150
} catch (err) {

src/robot/issues.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import fs from 'node:fs';
22

33
import chalk from 'chalk';
4-
import Octokit from '@octokit/rest';
4+
import { Octokit } from '@octokit/rest';
55

66
import { logDown, logUp, log } from '../util/log.js';
77
import { getCache, setCache, removeCache } from './cache.js';
88
import { getCNAMEsFile, validateCNAMEs } from './cnames.js';
99
import { parseCNAMEsFile } from '../util/cnames.js';
1010
import { repoContactIssue } from './templates.js';
11-
import config from '../../config.json' assert { type: 'json' };
11+
import confirm from './confirm.js';
12+
import config from '../../config.json' with { type: 'json' };
1213

1314
const octokit = new Octokit({ auth: config.github_token });
1415

@@ -76,7 +77,7 @@ const attemptTargetIssues = async (failed, issueUrl) => {
7677
// Attempt to create issue
7778
let issue;
7879
try {
79-
issue = await octokit.issues.create({
80+
issue = await octokit.rest.issues.create({
8081
owner,
8182
repo,
8283
title: 'JS.ORG CLEANUP',
@@ -210,7 +211,7 @@ export const createMainIssue = async () => {
210211
// Create new empty issue (change this for DEV)
211212
let issue = getCache('createMainIssueProgress');
212213
if (!issue) {
213-
issue = await octokit.issues.create({
214+
issue = await octokit.rest.issues.create({
214215
owner: config.repository_owner,
215216
repo: config.repository_name,
216217
title: 'JS.ORG CLEANUP',
@@ -252,7 +253,7 @@ export const createMainIssue = async () => {
252253
.replace(/{{CONTACT_ISSUE}}/g, contactIssue);
253254

254255
// Edit the issue
255-
await octokit.issues.update({
256+
await octokit.rest.issues.update({
256257
owner: config.repository_owner,
257258
repo: config.repository_name,
258259
issue_number: issue.data.number,
@@ -291,7 +292,7 @@ export const parseIssueEntries = async issueNumber => {
291292
}
292293

293294
// Get the issue body
294-
const issue = await octokit.issues.get({
295+
const issue = await octokit.rest.issues.get({
295296
owner: config.repository_owner,
296297
repo: config.repository_name,
297298
issue_number: issueNumber

src/robot/prs.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import chalk from 'chalk';
2-
import Octokit from '@octokit/rest';
3-
import createPullRequestPlugin from 'octokit-create-pull-request';
2+
import { Octokit } from '@octokit/rest';
3+
import { createPullRequest } from 'octokit-plugin-create-pull-request';
44

55
import { logDown, logUp, log } from '../util/log.js';
66
import { getCache, setCache, removeCache } from './cache.js';
77
import { getCNAMEsFile, validateCNAMEs } from './cnames.js';
88
import { parseCNAMEsFile, generateCNAMEsFile } from '../util/cnames.js';
99
import { robotDisclaimer, mainPullRequest } from './templates.js';
1010
import { parseIssueEntries } from './issues.js';
11-
import config from '../../config.json' assert { type: 'json' };
11+
import config from '../../config.json' with { type: 'json' };
1212

13-
const octokit = new Octokit.plugin(createPullRequestPlugin)({ auth: config.github_token });
13+
const octokit = new (Octokit.plugin(createPullRequest))({ auth: config.github_token });
1414

1515
/**
1616
* Generates a perfect cnames_active.js file w/ pull request
@@ -62,7 +62,8 @@ export const perfectCNAMEsFile = async () => {
6262
'cnames_active.js': newFile
6363
},
6464
commit: 'Cleanup: Perfect Format & Sorting'
65-
}
65+
},
66+
update: true
6667
});
6768

6869
// Done
@@ -90,7 +91,7 @@ export const mainCleanupPull = async issueNumber => {
9091
// Lock issue
9192
log(' Locking cleanup issue...', chalk.blue);
9293
try {
93-
await octokit.issues.lock({
94+
await octokit.rest.issues.lock({
9495
owner: config.repository_owner,
9596
repo: config.repository_name,
9697
issue_number: issueNumber

src/robot/templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs';
22

3-
import config from '../../config.json' assert { type: 'json' };
3+
import config from '../../config.json' with { type: 'json' };
44

55
/**
66
* Generates the robot disclaimer

src/util/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const logUp = () => {
2323
* This logs a message at the current depth using the given color
2424
* Empty lines will be logged without indentation
2525
* @param {string} message - The message to be logged
26-
* @param {(line: string) => string} [chalkColor=chalk.default] - The chalk color that will be used
26+
* @param {(...text: unknown[]) => string} [chalkColor=chalk.default] - The chalk color that will be used
2727
*/
2828
export const log = (message, chalkColor) => {
2929
if (typeof message !== 'string') return;

0 commit comments

Comments
 (0)