Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-experimentalize basePath config #14283

Merged
merged 3 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function createEntrypoints(
assetPrefix: config.assetPrefix,
generateEtags: config.generateEtags,
canonicalBase: config.canonicalBase,
basePath: config.experimental.basePath,
basePath: config.basePath,
runtimeConfig: hasRuntimeConfig
? JSON.stringify({
publicRuntimeConfig: config.publicRuntimeConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
const routesManifest: any = {
version: 3,
pages404: true,
basePath: config.experimental.basePath,
basePath: config.basePath,
redirects: redirects.map((r) => buildCustomRoute(r, 'redirect')),
rewrites: rewrites.map((r) => buildCustomRoute(r, 'rewrite')),
headers: headers.map((r) => buildCustomRoute(r, 'header')),
Expand Down
4 changes: 1 addition & 3 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,7 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_REACT_MODE': JSON.stringify(
config.experimental.reactMode
),
'process.env.__NEXT_ROUTER_BASEPATH': JSON.stringify(
config.experimental.basePath
),
'process.env.__NEXT_ROUTER_BASEPATH': JSON.stringify(config.basePath),
...(isServer
? {
// Fix bad-actors in the npm ecosystem (e.g. `node-formidable`)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default async function exportApp(
distDir,
dev: false,
hotReloader: null,
basePath: nextConfig.experimental.basePath,
basePath: nextConfig.basePath,
canonicalBase: nextConfig.amp?.canonicalBase || '',
isModern: nextConfig.experimental.modern,
ampValidatorPath: nextConfig.experimental.amp?.validator || undefined,
Expand Down
23 changes: 11 additions & 12 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const defaultConfig: { [key: string]: any } = {
amp: {
canonicalBase: '',
},
basePath: '',
exportTrailingSlash: false,
sassOptions: {},
experimental: {
Expand All @@ -49,7 +50,6 @@ const defaultConfig: { [key: string]: any } = {
sprFlushToDisk: true,
reactMode: 'legacy',
workerThreads: false,
basePath: '',
pageEnv: false,
productionBrowserSourceMaps: false,
optionalCatchAll: false,
Expand Down Expand Up @@ -158,35 +158,34 @@ function assignDefaults(userConfig: { [key: string]: any }) {
)
}
if (result.experimental) {
if (typeof result.experimental.basePath !== 'string') {
if (typeof result.basePath !== 'string') {
throw new Error(
`Specified basePath is not a string, found type "${typeof result
.experimental.basePath}"`
`Specified basePath is not a string, found type "${typeof result.basePath}"`
)
}

if (result.experimental.basePath !== '') {
if (result.experimental.basePath === '/') {
if (result.basePath !== '') {
if (result.basePath === '/') {
throw new Error(
`Specified basePath /. basePath has to be either an empty string or a path prefix"`
)
}

if (!result.experimental.basePath.startsWith('/')) {
if (!result.basePath.startsWith('/')) {
throw new Error(
`Specified basePath has to start with a /, found "${result.experimental.basePath}"`
`Specified basePath has to start with a /, found "${result.basePath}"`
)
}

if (result.experimental.basePath !== '/') {
if (result.experimental.basePath.endsWith('/')) {
if (result.basePath !== '/') {
if (result.basePath.endsWith('/')) {
throw new Error(
`Specified basePath should not end with /, found "${result.experimental.basePath}"`
`Specified basePath should not end with /, found "${result.basePath}"`
)
}

if (result.assetPrefix === '') {
result.assetPrefix = result.experimental.basePath
result.assetPrefix = result.basePath
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default class Server {
previewProps: this.getPreviewProps(),
customServer: customServer === true ? true : undefined,
ampOptimizerConfig: this.nextConfig.experimental.amp?.optimizer,
basePath: this.nextConfig.experimental.basePath,
basePath: this.nextConfig.basePath,
}

// Only the `publicRuntimeConfig` key is exposed to the client side
Expand Down Expand Up @@ -258,7 +258,7 @@ export default class Server {
parsedUrl.query = parseQs(parsedUrl.query)
}

const { basePath } = this.nextConfig.experimental
const { basePath } = this.nextConfig

// if basePath is set require it be present
if (basePath && !req.url!.startsWith(basePath)) {
Expand Down
4 changes: 1 addition & 3 deletions test/integration/basepath/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ module.exports = {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
experimental: {
basePath: '/docs',
},
basePath: '/docs',
}
2 changes: 1 addition & 1 deletion test/integration/basepath/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ describe('basePath serverless', () => {

beforeAll(async () => {
await nextConfig.write(
`module.exports = { target: 'serverless', experimental: { basePath: '/docs' } }`
`module.exports = { target: 'experimental-serverless-trace', basePath: '/docs' } `
)
await nextBuild(appDir)
context.appPort = await findPort()
Expand Down