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,
|
crossProjectLinksPlugin,
|
||||||
} from "remark-rehype-plugins"
|
} from "remark-rehype-plugins"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
import { catchBadRedirects } from "build-scripts"
|
||||||
|
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
@@ -23,13 +24,13 @@ const nextConfig = {
|
|||||||
optimizePackageImports: ["docs-utils"],
|
optimizePackageImports: ["docs-utils"],
|
||||||
},
|
},
|
||||||
async redirects() {
|
async redirects() {
|
||||||
return [
|
return catchBadRedirects([
|
||||||
{
|
{
|
||||||
source: "/api/download/:path",
|
source: "/api/download/:path",
|
||||||
destination: "/download/:path",
|
destination: "/download/:path",
|
||||||
permanent: true,
|
permanent: true,
|
||||||
},
|
},
|
||||||
]
|
])
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
"@types/pluralize": "^0.0.33",
|
"@types/pluralize": "^0.0.33",
|
||||||
"@types/react": "npm:types-react@rc",
|
"@types/react": "npm:types-react@rc",
|
||||||
"@types/react-dom": "npm:types-react@rc",
|
"@types/react-dom": "npm:types-react@rc",
|
||||||
|
"build-scripts": "*",
|
||||||
"eslint": "^9.13.0",
|
"eslint": "^9.13.0",
|
||||||
"eslint-plugin-prettier": "^5.2.1",
|
"eslint-plugin-prettier": "^5.2.1",
|
||||||
"eslint-plugin-react-hooks": "^5.0.0",
|
"eslint-plugin-react-hooks": "^5.0.0",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import redirects from "./utils/redirects.mjs"
|
import redirects from "./utils/redirects.mjs"
|
||||||
import { generatedSidebars } from "./generated/sidebar.mjs"
|
import { generatedSidebars } from "./generated/sidebar.mjs"
|
||||||
|
import { catchBadRedirects } from "build-scripts"
|
||||||
|
|
||||||
const withMDX = mdx({
|
const withMDX = mdx({
|
||||||
extension: /\.mdx?$/,
|
extension: /\.mdx?$/,
|
||||||
@@ -168,7 +169,11 @@ const nextConfig = {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
redirects,
|
redirects: async () => {
|
||||||
|
const result = await redirects()
|
||||||
|
|
||||||
|
return catchBadRedirects(result)
|
||||||
|
},
|
||||||
outputFileTracingIncludes: {
|
outputFileTracingIncludes: {
|
||||||
"/md\\-content/\\[\\.\\.\\.slug\\]": ["./app/**/*.mdx"],
|
"/md\\-content/\\[\\.\\.\\.slug\\]": ["./app/**/*.mdx"],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @returns {Promise<import("next").Redirect[]>}
|
* @type {import("next").NextConfig["redirects"]}
|
||||||
*/
|
*/
|
||||||
const redirects = async () => {
|
const redirects = async () => {
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import bundleAnalyzer from "@next/bundle-analyzer"
|
|||||||
import mdx from "@next/mdx"
|
import mdx from "@next/mdx"
|
||||||
import mdxPluginOptions from "./mdx-options.mjs"
|
import mdxPluginOptions from "./mdx-options.mjs"
|
||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
|
import { catchBadRedirects } from "build-scripts"
|
||||||
|
|
||||||
const withMDX = mdx({
|
const withMDX = mdx({
|
||||||
extension: /\.mdx?$/,
|
extension: /\.mdx?$/,
|
||||||
@@ -62,7 +63,7 @@ const nextConfig = {
|
|||||||
|
|
||||||
basePath: process.env.NEXT_PUBLIC_BASE_PATH || "/resources",
|
basePath: process.env.NEXT_PUBLIC_BASE_PATH || "/resources",
|
||||||
async redirects() {
|
async redirects() {
|
||||||
return [
|
return catchBadRedirects([
|
||||||
{
|
{
|
||||||
source: "/commerce-modules/order/relations-to-other-modules",
|
source: "/commerce-modules/order/relations-to-other-modules",
|
||||||
destination: "/commerce-modules/order/links-to-other-modules",
|
destination: "/commerce-modules/order/links-to-other-modules",
|
||||||
@@ -228,7 +229,7 @@ const nextConfig = {
|
|||||||
destination: "/references/user/events",
|
destination: "/references/user/events",
|
||||||
permanent: true,
|
permanent: true,
|
||||||
},
|
},
|
||||||
]
|
])
|
||||||
},
|
},
|
||||||
outputFileTracingExcludes: {
|
outputFileTracingExcludes: {
|
||||||
"*": ["node_modules/@medusajs/icons"],
|
"*": ["node_modules/@medusajs/icons"],
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.11.20",
|
"@types/node": "^20.11.20",
|
||||||
|
"next": "15.3.1",
|
||||||
"rimraf": "^5.0.5",
|
"rimraf": "^5.0.5",
|
||||||
"tsconfig": "*",
|
"tsconfig": "*",
|
||||||
"types": "*",
|
"types": "*",
|
||||||
|
|||||||
@@ -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-sidebar.js"
|
||||||
export * from "./generate-split-sidebars.js"
|
export * from "./generate-split-sidebars.js"
|
||||||
export * from "./retrieve-mdx-pages.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-core-flows-ref-sidebar-children.js"
|
||||||
export * from "./utils/get-sidebar-item-link.js"
|
export * from "./utils/get-sidebar-item-link.js"
|
||||||
|
|||||||
@@ -6252,6 +6252,7 @@ __metadata:
|
|||||||
"@types/react-dom": "npm:types-react@rc"
|
"@types/react-dom": "npm:types-react@rc"
|
||||||
algoliasearch: 4
|
algoliasearch: 4
|
||||||
autoprefixer: 10.4.14
|
autoprefixer: 10.4.14
|
||||||
|
build-scripts: "*"
|
||||||
clsx: ^2.0.0
|
clsx: ^2.0.0
|
||||||
docs-ui: "*"
|
docs-ui: "*"
|
||||||
docs-utils: "*"
|
docs-utils: "*"
|
||||||
@@ -6703,6 +6704,7 @@ __metadata:
|
|||||||
"@types/node": ^20.11.20
|
"@types/node": ^20.11.20
|
||||||
docs-utils: "*"
|
docs-utils: "*"
|
||||||
fdir: ^6.4.3
|
fdir: ^6.4.3
|
||||||
|
next: 15.3.1
|
||||||
pluralize: ^8.0.0
|
pluralize: ^8.0.0
|
||||||
rimraf: ^5.0.5
|
rimraf: ^5.0.5
|
||||||
slugify: ^1.6.6
|
slugify: ^1.6.6
|
||||||
|
|||||||
Reference in New Issue
Block a user