docs: add script to catch bad redirects (#12361)
* docs: add script to catch bad redirects * add missing dependency
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
crossProjectLinksPlugin,
|
||||
} from "remark-rehype-plugins"
|
||||
import path from "path"
|
||||
import { catchBadRedirects } from "build-scripts"
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
@@ -23,13 +24,13 @@ const nextConfig = {
|
||||
optimizePackageImports: ["docs-utils"],
|
||||
},
|
||||
async redirects() {
|
||||
return [
|
||||
return catchBadRedirects([
|
||||
{
|
||||
source: "/api/download/:path",
|
||||
destination: "/download/:path",
|
||||
permanent: true,
|
||||
},
|
||||
]
|
||||
])
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
"@types/pluralize": "^0.0.33",
|
||||
"@types/react": "npm:types-react@rc",
|
||||
"@types/react-dom": "npm:types-react@rc",
|
||||
"build-scripts": "*",
|
||||
"eslint": "^9.13.0",
|
||||
"eslint-plugin-prettier": "^5.2.1",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import path from "path"
|
||||
import redirects from "./utils/redirects.mjs"
|
||||
import { generatedSidebars } from "./generated/sidebar.mjs"
|
||||
import { catchBadRedirects } from "build-scripts"
|
||||
|
||||
const withMDX = mdx({
|
||||
extension: /\.mdx?$/,
|
||||
@@ -168,7 +169,11 @@ const nextConfig = {
|
||||
],
|
||||
}
|
||||
},
|
||||
redirects,
|
||||
redirects: async () => {
|
||||
const result = await redirects()
|
||||
|
||||
return catchBadRedirects(result)
|
||||
},
|
||||
outputFileTracingIncludes: {
|
||||
"/md\\-content/\\[\\.\\.\\.slug\\]": ["./app/**/*.mdx"],
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @returns {Promise<import("next").Redirect[]>}
|
||||
* @type {import("next").NextConfig["redirects"]}
|
||||
*/
|
||||
const redirects = async () => {
|
||||
return [
|
||||
|
||||
@@ -10,6 +10,7 @@ import bundleAnalyzer from "@next/bundle-analyzer"
|
||||
import mdx from "@next/mdx"
|
||||
import mdxPluginOptions from "./mdx-options.mjs"
|
||||
import path from "node:path"
|
||||
import { catchBadRedirects } from "build-scripts"
|
||||
|
||||
const withMDX = mdx({
|
||||
extension: /\.mdx?$/,
|
||||
@@ -62,7 +63,7 @@ const nextConfig = {
|
||||
|
||||
basePath: process.env.NEXT_PUBLIC_BASE_PATH || "/resources",
|
||||
async redirects() {
|
||||
return [
|
||||
return catchBadRedirects([
|
||||
{
|
||||
source: "/commerce-modules/order/relations-to-other-modules",
|
||||
destination: "/commerce-modules/order/links-to-other-modules",
|
||||
@@ -228,7 +229,7 @@ const nextConfig = {
|
||||
destination: "/references/user/events",
|
||||
permanent: true,
|
||||
},
|
||||
]
|
||||
])
|
||||
},
|
||||
outputFileTracingExcludes: {
|
||||
"*": ["node_modules/@medusajs/icons"],
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.11.20",
|
||||
"next": "15.3.1",
|
||||
"rimraf": "^5.0.5",
|
||||
"tsconfig": "*",
|
||||
"types": "*",
|
||||
|
||||
17
www/packages/build-scripts/src/catch-bad-redirects.ts
Normal file
17
www/packages/build-scripts/src/catch-bad-redirects.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { NextConfig } from "next"
|
||||
|
||||
type CatchBadRedirectsOptions = Awaited<
|
||||
ReturnType<NonNullable<NextConfig["redirects"]>>
|
||||
>
|
||||
|
||||
export const catchBadRedirects = (redirects: CatchBadRedirectsOptions) => {
|
||||
for (const redirect of redirects) {
|
||||
if (redirect.source === redirect.destination) {
|
||||
throw new Error(
|
||||
`Redirect source and destination are the same: ${JSON.stringify(redirect, null, 2)}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return redirects
|
||||
}
|
||||
@@ -3,6 +3,7 @@ export * from "./generate-llms-full.js"
|
||||
export * from "./generate-sidebar.js"
|
||||
export * from "./generate-split-sidebars.js"
|
||||
export * from "./retrieve-mdx-pages.js"
|
||||
export * from "./catch-bad-redirects.js"
|
||||
|
||||
export * from "./utils/get-core-flows-ref-sidebar-children.js"
|
||||
export * from "./utils/get-sidebar-item-link.js"
|
||||
|
||||
@@ -6252,6 +6252,7 @@ __metadata:
|
||||
"@types/react-dom": "npm:types-react@rc"
|
||||
algoliasearch: 4
|
||||
autoprefixer: 10.4.14
|
||||
build-scripts: "*"
|
||||
clsx: ^2.0.0
|
||||
docs-ui: "*"
|
||||
docs-utils: "*"
|
||||
@@ -6703,6 +6704,7 @@ __metadata:
|
||||
"@types/node": ^20.11.20
|
||||
docs-utils: "*"
|
||||
fdir: ^6.4.3
|
||||
next: 15.3.1
|
||||
pluralize: ^8.0.0
|
||||
rimraf: ^5.0.5
|
||||
slugify: ^1.6.6
|
||||
|
||||
Reference in New Issue
Block a user