Skip to content

Commit d65eab4

Browse files
fix: replace glob with tinyglobby, replace lodash with native JS (#384)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: wolfy1339 <webmaster@wolfy1339.com>
1 parent 378df8b commit d65eab4

File tree

6 files changed

+79
-379
lines changed

6 files changed

+79
-379
lines changed

index.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export default fixtureServerMiddleware;
22

3-
import _ from "lodash";
43
import bodyParser from "body-parser";
54
import cachimo from "cachimo";
65
import { Router } from "express";
@@ -15,7 +14,7 @@ import DEFAULTS from "./lib/defaults.js";
1514
function fixtureServerMiddleware(options) {
1615
const middleware = Router();
1716

18-
const state = _.defaults(_.clone(options), DEFAULTS);
17+
const state = Object.assign({}, DEFAULTS, options);
1918

2019
if (!state.fixturesUrl) {
2120
state.fixturesUrl = `http://localhost:${state.port}`;
@@ -58,15 +57,13 @@ function fixtureServerMiddleware(options) {
5857
});
5958

6059
// load proxies for all unique scope URLs in fixtures
61-
_.chain(state.fixtures)
62-
.values()
63-
.flatten()
64-
.map("scope")
65-
.uniq()
66-
// remove default ports for http / https, they cause problems for the proxy
67-
.map((url) => url.replace(/:(80|443)$/, ""))
68-
.forEach((target) => middleware.use(proxy(state, { target })))
69-
.value();
60+
Object.values(state.fixtures)
61+
.flat()
62+
.map((fixture) => fixture.scope.replace(/:(80|443)$/, ""))
63+
.filter((url, i, arr) => arr.indexOf(url) === i)
64+
.forEach((target) => {
65+
middleware.use(proxy(state, { target }));
66+
});
7067

7168
return middleware;
7269
}

lib/defaults.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { dirname, resolve } from "path";
1+
import { dirname, resolve } from "node:path";
22
import globToFixtures from "./glob-to-fixtures.js";
33

4-
import { createRequire } from "module";
5-
const require = createRequire(import.meta.url);
6-
7-
const octokitFixturesPath = dirname(require.resolve("@octokit/fixtures"));
4+
const octokitFixturesPath = new URL(
5+
import.meta.resolve("@octokit/fixtures"),
6+
).pathname.replace("index.js", "");
87
const DEFAULT_FIXTURES_GLOB = resolve(
98
octokitFixturesPath,
109
"scenarios/**/normalized-fixture.json",

lib/glob-to-fixtures.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { dirname, basename, resolve } from "path";
1+
import { dirname, basename, resolve } from "node:path";
22

3-
import { globSync as glob } from "glob";
4-
import { readFileSync } from "fs";
3+
import { globSync as glob } from "tinyglobby";
4+
import { readFileSync } from "node:fs";
55

66
export default function globToFixtures(path) {
77
return glob(path).reduce((map, path) => {

lib/map-values-deep.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
export default mapValuesDeep;
2-
3-
import _ from "lodash";
4-
5-
function mapValuesDeep(v, callback) {
6-
if (_.isArray(v)) {
7-
return _.map(v, (v) => mapValuesDeep(v, callback));
1+
export default function mapValuesDeep(v, callback) {
2+
if (Array.isArray(v)) {
3+
return v.map((val) => mapValuesDeep(val, callback));
84
}
95

10-
if (_.isObject(v)) {
11-
return _.mapValues(v, (v) => mapValuesDeep(v, callback));
6+
if (v !== null && !Array.isArray(v) && typeof v === "object") {
7+
return Object.fromEntries(
8+
Object.entries(v).map(([key, val]) => [
9+
key,
10+
mapValuesDeep(val, callback),
11+
]),
12+
);
1213
}
1314

1415
return callback(v);

0 commit comments

Comments
 (0)