-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update filename generation for client-side compilation (#14279)
Updates the way filenames are generated for browser compilation. Notably: - All entry bundles now have hashes in production, this includes pages (previously pages used a buildId in the path) - The AmpFiles no longer depends on hardcoded bundle names, it uses the buildManifest instead (internals) - All cases where we match the page name from the chunk/entrypoint name now use the same function `getRouteFromEntrypoint` (internals) - In development we no longer include the "faked" `buildId` set to `development` for page files, instead we just use the `/_next/static/pages` path (was `/_next/static/development/pages`). This was changed as it caused unneeded complexity and makes generating the bundles easier (internals) - Updated tons of tests to be more resilient to these changes by relying on the buildManifest instead of hardcoded paths (internals) Follow up of these PRs: #13759 #13870 #13937 #14130 #14176 #14268 Fixes #6303 Fixes #12087 Fixes #1948 Fixes #4368 Fixes #4255 Fixes #2548
- Loading branch information
1 parent
76673fd
commit bef9b56
Showing
25 changed files
with
218 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 22 additions & 14 deletions
36
packages/next/next-server/server/get-route-from-entrypoint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
import { denormalizePagePath } from './normalize-page-path' | ||
|
||
// matches static/<buildid>/pages/:page*.js | ||
const ROUTE_NAME_REGEX = /^static[/\\][^/\\]+[/\\]pages[/\\](.*)\.js$/ | ||
const SERVERLESS_ROUTE_NAME_REGEX = /^pages[/\\](.*)\.js$/ | ||
const ROUTE_NAME_REGEX = /^static[/\\][^/\\]+[/\\]pages[/\\](.*)$/ | ||
// matches pages/:page*.js | ||
const SERVERLESS_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/ | ||
// matches static/pages/:page*.js | ||
const BROWSER_ROUTE_NAME_REGEX = /^static[/\\]pages[/\\](.*)$/ | ||
|
||
export default function getRouteFromEntrypoint( | ||
entryFile: string, | ||
isServerlessLike: boolean = false | ||
): string | null { | ||
const result = (isServerlessLike | ||
? SERVERLESS_ROUTE_NAME_REGEX | ||
: ROUTE_NAME_REGEX | ||
).exec(entryFile) | ||
function matchBundle(regex: RegExp, input: string): string | null { | ||
const result = regex.exec(input) | ||
|
||
if (!result) { | ||
return null | ||
} | ||
|
||
const pagePath = result[1] | ||
return denormalizePagePath(`/${result[1]}`) | ||
} | ||
|
||
if (!pagePath) { | ||
return null | ||
export default function getRouteFromEntrypoint( | ||
entryFile: string, | ||
isServerlessLike: boolean = false | ||
): string | null { | ||
let pagePath = matchBundle( | ||
isServerlessLike ? SERVERLESS_ROUTE_NAME_REGEX : ROUTE_NAME_REGEX, | ||
entryFile | ||
) | ||
|
||
if (pagePath) { | ||
return pagePath | ||
} | ||
|
||
return denormalizePagePath(`/${pagePath}`) | ||
// Potentially the passed item is a browser bundle so we try to match that also | ||
return matchBundle(BROWSER_ROUTE_NAME_REGEX, entryFile) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.