Skip to content

Commit 454f8de

Browse files
authored
Convert to ESM module (#93)
* Update dependencies * Update to ESM module * Update GH Actions * Migrate eslint config file * npm run lint-fix
1 parent 0e87f34 commit 454f8de

File tree

8 files changed

+3434
-4484
lines changed

8 files changed

+3434
-4484
lines changed

.eslintrc

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ name: Node.js CI
22

33
on: [push]
44

5+
permissions:
6+
contents: read
7+
58
jobs:
69
build:
710
runs-on: ubuntu-latest
811

912
strategy:
1013
matrix:
11-
node-version: [10.x, 12.x, 14.x]
14+
node-version: [18, 20, 22]
1215

1316
env:
1417
CI: true
1518
steps:
16-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v4
1720
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v1
21+
uses: actions/setup-node@v4
1922
with:
2023
node-version: ${{ matrix.node-version }}
2124
- run: npm ci

.github/workflows/release.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ name: NPM Publish
33
on:
44
release:
55
types: [published]
6+
7+
permissions:
8+
contents: write
9+
610
jobs:
711
build:
812
runs-on: ubuntu-latest
913
steps:
10-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1115
with:
1216
ref: ${{ github.event.release.target_commitish }}
1317
- name: Use Node.js 12
14-
uses: actions/setup-node@v1
18+
uses: actions/setup-node@v4
1519
with:
1620
node-version: 12
1721
registry-url: https://registry.npmjs.org/

eslint.config.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig } from "eslint/config";
2+
import prettier from "eslint-plugin-prettier";
3+
4+
export default defineConfig([{
5+
plugins: {
6+
prettier,
7+
},
8+
9+
languageOptions: {
10+
ecmaVersion: 2020,
11+
sourceType: "module",
12+
13+
parserOptions: {
14+
impliedStrict: true,
15+
16+
ecmaFeatures: {
17+
impliedStrict: true,
18+
experimentalObjectRestSpread: true,
19+
},
20+
},
21+
},
22+
23+
rules: {
24+
"prettier/prettier": "error",
25+
},
26+
}]);

fetch-repos.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function (octokit, opts) {
1+
export default function (octokit, opts) {
22
return new Promise(async (resolve, reject) => {
33
opts = {
44
visibility: "all",
@@ -108,7 +108,7 @@ module.exports = function (octokit, opts) {
108108

109109
if (!is_org && team) {
110110
throw new Error(
111-
"The provided 'owner' is not an organization, and so can not have teams"
111+
"The provided 'owner' is not an organization, and so can not have teams",
112112
);
113113
}
114114

@@ -120,4 +120,4 @@ module.exports = function (octokit, opts) {
120120
throw e;
121121
}
122122
}
123-
};
123+
}

fetch-repos.test.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
const plugin = require("./fetch-repos");
2-
const { Octokit } = require("@octokit/rest");
1+
import plugin from "./fetch-repos";
2+
import { Octokit } from "@octokit/rest";
3+
import nock from "nock";
34

4-
const nock = require("nock");
55
nock.disableNetConnect();
6-
const octokit = new Octokit();
6+
const octokit = new Octokit({
7+
log: {
8+
error: () => {},
9+
},
10+
});
711

812
function run(body) {
913
return plugin(octokit, body);
@@ -18,7 +22,7 @@ test(`owner does not exist`, async () => {
1822
mockGetUser(owner, null);
1923

2024
await expect(run({ owner })).rejects.toEqual(
21-
`The user/org '${owner}' could not be found`
25+
`The user/org '${owner}' could not be found`,
2226
);
2327
});
2428

@@ -27,7 +31,7 @@ test(`team requested, but user is not an org`, async () => {
2731
mockGetUser("valid-user", "User");
2832

2933
await expect(run({ owner })).rejects.toEqual(
30-
`The provided 'owner' is not an organization, and so can not have teams`
34+
`The provided 'owner' is not an organization, and so can not have teams`,
3135
);
3236
});
3337

@@ -76,7 +80,7 @@ test(`runs with defaults`, async () => {
7680
await expect(
7781
run({
7882
owner: "mheap",
79-
})
83+
}),
8084
).resolves.toEqual([
8185
publicRepo,
8286
privateRepo,
@@ -94,7 +98,7 @@ test(`can disable forks`, async () => {
9498
run({
9599
owner: "mheap",
96100
include_forks: false,
97-
})
101+
}),
98102
).resolves.toEqual([]);
99103
});
100104

@@ -105,7 +109,7 @@ test(`allows archived`, async () => {
105109
run({
106110
owner: "mheap",
107111
include_archived: true,
108-
})
112+
}),
109113
).resolves.toEqual([archivedRepo]);
110114
});
111115

@@ -116,7 +120,7 @@ test(`allows templates`, async () => {
116120
run({
117121
owner: "mheap",
118122
include_templates: true,
119-
})
123+
}),
120124
).resolves.toEqual([templateRepo]);
121125
});
122126

@@ -127,7 +131,7 @@ test(`filters to only public`, async () => {
127131
run({
128132
owner: "mheap",
129133
visibility: "public",
130-
})
134+
}),
131135
).resolves.toEqual([publicRepo]);
132136
});
133137

@@ -138,7 +142,7 @@ test(`filters to only private`, async () => {
138142
run({
139143
owner: "mheap",
140144
visibility: "private",
141-
})
145+
}),
142146
).resolves.toEqual([privateRepo]);
143147
});
144148

@@ -149,7 +153,7 @@ test(`permissions: pull (success)`, async () => {
149153
run({
150154
owner: "mheap",
151155
minimum_access: "pull",
152-
})
156+
}),
153157
).resolves.toEqual([repoWithPull]);
154158
});
155159

@@ -160,7 +164,7 @@ test(`permissions: push (success)`, async () => {
160164
run({
161165
owner: "mheap",
162166
minimum_access: "push",
163-
})
167+
}),
164168
).resolves.toEqual([repoWithPush]);
165169
});
166170

@@ -171,7 +175,7 @@ test(`permissions: pull (success)`, async () => {
171175
run({
172176
owner: "mheap",
173177
minimum_access: "admin",
174-
})
178+
}),
175179
).resolves.toEqual([repoWithAdmin]);
176180
});
177181

@@ -182,7 +186,7 @@ test(`permissions: pull (no auth, implicitly allowed)`, async () => {
182186
run({
183187
owner: "mheap",
184188
minimum_access: "pull",
185-
})
189+
}),
186190
).resolves.toEqual([publicRepo]);
187191
});
188192

@@ -193,7 +197,7 @@ test(`permissions: pull (no auth, implicitly disallowed)`, async () => {
193197
run({
194198
owner: "mheap",
195199
minimum_access: "push",
196-
})
200+
}),
197201
).resolves.toEqual([]);
198202
});
199203

@@ -204,7 +208,7 @@ test(`permissions: push (failure)`, async () => {
204208
run({
205209
owner: "mheap",
206210
minimum_access: "push",
207-
})
211+
}),
208212
).resolves.toEqual([]);
209213
});
210214

@@ -215,7 +219,7 @@ test(`permissions: admin (failure)`, async () => {
215219
run({
216220
owner: "mheap",
217221
minimum_access: "admin",
218-
})
222+
}),
219223
).resolves.toEqual([]);
220224
});
221225

@@ -226,7 +230,7 @@ test(`permissions: minimum_access is case insensitive`, async () => {
226230
run({
227231
owner: "mheap",
228232
minimum_access: "ADMIN",
229-
})
233+
}),
230234
).resolves.toEqual([repoWithAdmin]);
231235
});
232236

@@ -254,7 +258,7 @@ function mockGetOrgRepos(owner, repos) {
254258

255259
function mockGetTeamRepos(owner, team_slug, repos) {
256260
const m = nock("https://api.github.com").get(
257-
`/orgs/${owner}/teams/${team_slug}/repos`
261+
`/orgs/${owner}/teams/${team_slug}/repos`,
258262
);
259263
return m.reply(200, repos);
260264
}

0 commit comments

Comments
 (0)