未验证 提交 b87e4989 编写于 作者: J Jan Potoms 提交者: GitHub

Rename exportTrailingSlash to existing trailingSlash property (#15768)

In terms of url rewriting, `trailingSlash` supports everything `exportTrailingSlash` does. We can just share all other code paths and deprecate `exportTrailingSlash`.

This PR shows a deprecation warning when `exportTrailingSlash` is used.

Also fixes https://github.com/vercel/next.js/issues/15774

We can update the tests now or later. (I kept them the same to prove it's non-breaking)

To do:
- [x] Do we want to keep this? => nope https://github.com/vercel/next.js/blob/841d4efc517a379d8947f491e3c6a1c4784bbccf/packages/next/next-server/lib/router/router.ts#L329
- [x] I kept `exportTrailingSlash` here. Do we want to rename that as well? => nope https://github.com/vercel/next.js/blob/2d9d649d492b77adeddea0242ab6b7fe73d18079/packages/next/build/index.ts#L959
上级 e89bcf7e
......@@ -740,7 +740,7 @@ export default async function build(
return defaultMap
},
exportTrailingSlash: false,
trailingSlash: false,
}
await exportApp(dir, exportOptions, exportConfig)
......@@ -956,7 +956,7 @@ export default async function build(
JSON.stringify({
version: 1,
hasExportPathMap: typeof config.exportPathMap === 'function',
exportTrailingSlash: config.exportTrailingSlash === true,
exportTrailingSlash: config.trailingSlash === true,
}),
'utf8'
)
......
......@@ -861,9 +861,6 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_TRAILING_SLASH': JSON.stringify(
config.trailingSlash
),
'process.env.__NEXT_EXPORT_TRAILING_SLASH': JSON.stringify(
config.exportTrailingSlash
),
'process.env.__NEXT_MODERN_BUILD': JSON.stringify(
config.experimental.modern && !dev
),
......
......@@ -237,20 +237,6 @@ function Link(props: React.PropsWithChildren<LinkProps>) {
childProps.href = addBasePath(as)
}
// Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly.
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('../next-server/lib/router/rewrite-url-for-export')
.rewriteUrlForNextExport
if (
childProps.href &&
typeof __NEXT_DATA__ !== 'undefined' &&
__NEXT_DATA__.nextExport
) {
childProps.href = rewriteUrlForNextExport(childProps.href)
}
}
return React.cloneElement(child, childProps)
}
......
......@@ -133,7 +133,7 @@ export default async function exportApp(
)
}
const subFolders = nextConfig.exportTrailingSlash
const subFolders = nextConfig.trailingSlash
const isLikeServerless = nextConfig.target !== 'server'
log(`> using build directory: ${distDir}`)
......
export function rewriteUrlForNextExport(url: string): string {
const [pathname, hash] = url.split('#')
// tslint:disable-next-line
let [path, qs] = pathname.split('?')
if (path) {
path = path.replace(/\/$/, '')
// Append a trailing slash if this path does not have an extension
if (!/\.[^/]+\/?$/.test(path)) path += `/`
}
if (typeof qs === 'string') path += '?' + qs
if (typeof hash === 'string') path += '#' + hash
return path
}
......@@ -325,17 +325,6 @@ export default class Router implements BaseRouter {
}
}
// @deprecated backwards compatibility even though it's a private method.
static _rewriteUrlForNextExport(url: string): string {
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('./rewrite-url-for-export')
.rewriteUrlForNextExport
return rewriteUrlForNextExport(url)
} else {
return url
}
}
onPopState = (e: PopStateEvent): void => {
const state = e.state as HistoryState
......@@ -453,17 +442,6 @@ export default class Router implements BaseRouter {
performance.mark('routeChange')
}
// Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly for the SSR page.
if (process.env.__NEXT_EXPORT_TRAILING_SLASH) {
const rewriteUrlForNextExport = require('./rewrite-url-for-export')
.rewriteUrlForNextExport
// @ts-ignore this is temporarily global (attached to window)
if (__NEXT_DATA__.nextExport) {
as = rewriteUrlForNextExport(as)
}
}
if (this._inFlightRoute) {
this.abortComponentLoad(this._inFlightRoute)
}
......
......@@ -35,7 +35,6 @@ const defaultConfig: { [key: string]: any } = {
canonicalBase: '',
},
basePath: '',
exportTrailingSlash: false,
sassOptions: {},
trailingSlash: false,
experimental: {
......@@ -73,6 +72,17 @@ const experimentalWarning = execOnce(() => {
})
function assignDefaults(userConfig: { [key: string]: any }) {
if (typeof userConfig.exportTrailingSlash !== 'undefined') {
console.warn(
chalk.yellow.bold('Warning: ') +
'The "exportTrailingSlash" option has been renamed to "trailingSlash". Please update your next.config.js.'
)
if (typeof userConfig.trailingSlash === 'undefined') {
userConfig.trailingSlash = userConfig.exportTrailingSlash
}
delete userConfig.exportTrailingSlash
}
const config = Object.keys(userConfig).reduce<{ [key: string]: any }>(
(currentConfig, key) => {
const value = userConfig[key]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册