Skip to content

Commit 8937691

Browse files
authored
chore: update dependencies and reduce bundle size (#2012)
1 parent 8a2ea91 commit 8937691

File tree

13 files changed

+113
-103
lines changed

13 files changed

+113
-103
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"gen:config": "node src/scripts/config.js config.js",
1010
"start": "docusaurus start --no-minify",
1111
"build": "docusaurus build",
12+
"build:analyze": "docusaurus build --bundle-analyzer",
1213
"swizzle": "docusaurus swizzle",
1314
"serve": "docusaurus serve",
1415
"test": "playwright test",
@@ -50,14 +51,14 @@
5051
"file-loader": "6.2.0",
5152
"json-loader": "0.5.7",
5253
"json-schema-faker": "0.5.8",
54+
"lodash.get": "^4.4.2",
5355
"mermaid": "11.4.1",
5456
"net": "1.0.2",
5557
"node-fetch": "2.7.0",
5658
"node-polyfill-webpack-plugin": "3.0.0",
5759
"parser-front-matter": "1.6.4",
58-
"prism-react-renderer": "2.3.1",
60+
"prism-react-renderer": "2.4.1",
5961
"prismjs": "1.29.0",
60-
"ramda": "0.29.1",
6162
"react": "19.0.0",
6263
"react-dom": "19.0.0",
6364
"redocusaurus": "2.2.1",

src/components/ConfigEditor/index.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import RefParser from "@apidevtools/json-schema-ref-parser"
22
import { withTheme } from "@rjsf/core"
33
import { Theme as Bootstrap4Theme } from "@rjsf/bootstrap-4"
44
import validator from "@rjsf/validator-ajv8"
5-
import axios from "axios"
65
import { useEffect, useState } from "react"
76

87
const Form = withTheme(Bootstrap4Theme)
@@ -11,15 +10,17 @@ export default function ConfigEditor(props: { url: any }) {
1110
const [schema, setSchema] = useState<any>()
1211

1312
useEffect(() => {
14-
axios.get(props.url).then((res) => {
15-
RefParser.dereference(res.data, (err, api) => {
16-
if (err) {
17-
console.log(err)
18-
} else {
19-
setSchema(api)
20-
}
13+
fetch(props.url)
14+
.then((r) => r.json())
15+
.then((res) => {
16+
RefParser.dereference(res, (err, api) => {
17+
if (err) {
18+
console.log(err)
19+
} else {
20+
setSchema(api)
21+
}
22+
})
2123
})
22-
})
2324
}, [props.url])
2425

2526
if (!schema) {

src/components/ConfigMarkdown/index.tsx

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import axios from "axios"
44
import RefParser from "@apidevtools/json-schema-ref-parser"
55
import jsf from "json-schema-faker"
66
import YAML from "yaml"
7-
import { pathOr } from "ramda"
87
import Admonition from "@theme/Admonition"
98
import CodeBlock from "@theme/CodeBlock"
9+
import { pathOr } from "../../utils/pathOr"
1010

1111
const parser = new RefParser()
1212

@@ -128,83 +128,86 @@ export default function ConfigMarkdown(props: { src: string; binary: string }) {
128128
})
129129

130130
useEffect(() => {
131-
axios.get(props.src).then(({ data: schema }) => {
132-
new Promise((resolve, reject) => {
133-
parser.dereference(
134-
schema,
135-
{
136-
resolve: {
137-
ory: oryResolver,
131+
fetch(props.src)
132+
.then((r) => r.json())
133+
.then((schema) => {
134+
new Promise((resolve, reject) => {
135+
parser.dereference(
136+
schema,
137+
{
138+
resolve: {
139+
ory: oryResolver,
140+
},
138141
},
139-
},
140-
(err, result) => (err ? reject(err) : resolve(result)),
141-
)
142-
})
143-
.then((schema: any) => {
144-
const removeAdditionalProperties = (o) => {
145-
delete o["additionalProperties"]
146-
if (o.properties) {
147-
Object.keys(o.properties).forEach((key) =>
148-
removeAdditionalProperties(o.properties[key]),
149-
)
142+
(err, result) => (err ? reject(err) : resolve(result)),
143+
)
144+
})
145+
.then((schema: any) => {
146+
const removeAdditionalProperties = (o) => {
147+
delete o["additionalProperties"]
148+
if (o.properties) {
149+
Object.keys(o.properties).forEach((key) =>
150+
removeAdditionalProperties(o.properties[key]),
151+
)
152+
}
150153
}
151-
}
152-
153-
const enableAll = (o) => {
154-
if (o.properties) {
155-
Object.keys(o.properties).forEach((key) => {
156-
if (key === "enable") {
157-
o.properties[key] = true
158-
}
159-
enableAll(o.properties[key])
160-
})
154+
155+
const enableAll = (o) => {
156+
if (o.properties) {
157+
Object.keys(o.properties).forEach((key) => {
158+
if (key === "enable") {
159+
o.properties[key] = true
160+
}
161+
enableAll(o.properties[key])
162+
})
163+
}
161164
}
162-
}
163-
164-
removeAdditionalProperties(schema)
165-
enableAll(schema)
166-
if (schema.definitions) {
167-
Object.keys(schema.definitions).forEach((key) => {
168-
removeAdditionalProperties(schema.definitions[key])
169-
enableAll(schema.definitions[key])
170-
})
171-
}
172165

173-
jsf.option({
174-
useExamplesValue: true,
175-
useDefaultValue: false, // do not change this!!
176-
fixedProbabilities: true,
177-
alwaysFakeOptionals: true,
178-
})
166+
removeAdditionalProperties(schema)
167+
enableAll(schema)
168+
if (schema.definitions) {
169+
Object.keys(schema.definitions).forEach((key) => {
170+
removeAdditionalProperties(schema.definitions[key])
171+
enableAll(schema.definitions[key])
172+
})
173+
}
179174

180-
const values = jsf.generate(schema)
181-
const doc = YAML.parseDocument(YAML.stringify(values))
175+
jsf.option({
176+
useExamplesValue: true,
177+
useDefaultValue: false, // do not change this!!
178+
fixedProbabilities: true,
179+
alwaysFakeOptionals: true,
180+
})
182181

183-
const comments = [`# ${pathOr(props.binary, ["title"], schema)}`, ""]
182+
const values = jsf.generate(schema)
183+
const doc = YAML.parseDocument(YAML.stringify(values))
184184

185-
const description = pathOr("", ["description"], schema)
186-
if (description) {
187-
comments.push(" " + description)
188-
}
185+
const comments = [
186+
`# ${pathOr(props.binary, ["title"], schema)}`,
187+
"",
188+
]
189189

190-
console.log({ doc })
190+
const description = pathOr("", ["description"], schema)
191+
if (description) {
192+
comments.push(" " + description)
193+
}
191194

192-
doc.commentBefore = comments.join("\n")
193-
doc.spaceAfter = false
194-
doc.spaceBefore = false
195+
doc.commentBefore = comments.join("\n")
196+
doc.spaceAfter = false
197+
doc.spaceBefore = false
195198

196-
doc.contents.items.forEach(enhance(schema, []))
199+
doc.contents.items.forEach(enhance(schema, []))
197200

198-
return Promise.resolve({
199-
// schema,
200-
// values,
201-
yaml: doc.toString(),
201+
return Promise.resolve({
202+
// schema,
203+
// values,
204+
yaml: doc.toString(),
205+
})
202206
})
203-
})
204-
.then((out) => {
205-
setContent(out.yaml)
206-
})
207-
})
207+
.then((out) => {
208+
setContent(out.yaml)
209+
})
210+
})
208211
}, [props.src])
209212

210213
return (

src/scripts/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
const RefParser = require("json-schema-ref-parser")
55
const parser = new RefParser()
6-
const jsf = require("json-schema-faker").default
6+
const jsf = require("json-schema-faker")
77
const YAML = require("yaml")
8-
const { pathOr } = require("ramda")
98
const path = require("path")
109
const fs = require("fs")
1110
const prettier = require("prettier")
@@ -47,6 +46,7 @@ if (process.argv.length !== 3 || process.argv[1] === "help") {
4746
}
4847

4948
const config = require(path.resolve(process.argv[2]))
49+
const { pathOr } = require("../utils/pathOr")
5050

5151
const enhance =
5252
(schema, parents = []) =>

src/theme/API.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useEffect, useState } from "react"
22
import Redoc from "@theme/Redoc"
33
import "./API.module.css"
4-
import axios from "axios"
54
import { useLatestRelease } from "../hooks"
65

76
const canUseDOM: boolean = !!(
@@ -27,9 +26,11 @@ function API({
2726
return
2827
}
2928

30-
axios.get(url.replace(/master/, version)).then((res) => {
31-
setSpec(res.data)
32-
})
29+
fetch(url.replace(/master/, version))
30+
.then((r) => r.json())
31+
.then((res) => {
32+
setSpec(res)
33+
})
3334
}, [url, repo, version])
3435

3536
// For some reason this does not render server-side...

src/theme/prism-include-languages.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import siteConfig from "@generated/docusaurus.config"
66
import ketoRelationTuplesPrism from "./ketoRelationTuplesPrism"
77
import ketoRelationsPermissionsPrism from "./ketoRelationsPermissionsPrism"
88

9+
// Automatically overrides the docusaurus prism coonfig.
10+
911
export default function prismIncludeLanguages(PrismObject) {
1012
const {
1113
themeConfig: { prism },

src/utils/pathOr.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const pathOr = (defaultValue, path, obj) => {
2+
return path.reduce(
3+
(acc, key) => (acc && acc[key] !== undefined ? acc[key] : defaultValue),
4+
obj,
5+
)
6+
}

tests/jest/redirects/docs-redirects.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright © 2022 Ory Corp
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { readSitemapXML, Sitemap, getLoc, getNewURL, runTest } from "./utils"
4+
import { readSitemapXML, runTest } from "./utils"
55

66
const sitemap = readSitemapXML("sitemap_docs.xml")
77

tests/jest/redirects/hydra-redirects.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright © 2022 Ory Corp
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { readSitemapXML, Sitemap, getLoc, getNewURL, runTest } from "./utils"
4+
import { readSitemapXML, runTest } from "./utils"
55

66
const sitemap = readSitemapXML("sitemap_hydra.xml")
77

0 commit comments

Comments
 (0)