-
Notifications
You must be signed in to change notification settings - Fork 26.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flow, pages-manifest.json, defaultPathMap for export (minor) #4066
Merged
timneutkens
merged 12 commits into
vercel:canary
from
timneutkens:add/default-export-pathmap
Mar 30, 2018
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fc09580
Initial implementation of next export without exportPathMap
timneutkens af12570
Shorter message
timneutkens f60a4fa
Set up flow
timneutkens d232646
Create pages manifest
timneutkens c4d2af6
Use pagesManifest for next export
timneutkens 917d29c
Fix tests
timneutkens 6b61954
Document defaultPathMap
timneutkens 9ad271c
Replacing the path is no longer needed
timneutkens ca5d934
Use posix normalize for consistent behaviour
timneutkens 370de74
Remove second instance of examples
timneutkens 13f08d3
Add comment about what pages-manifest does
timneutkens 0a3c0d9
Make windows path a route
timneutkens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"presets": [ | ||
"env", | ||
"react" | ||
"react", | ||
"flow" | ||
], | ||
"plugins": [ | ||
"transform-object-rest-spread", | ||
|
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[ignore] | ||
<PROJECT_ROOT>/examples/.* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// @flow | ||
import { RawSource } from 'webpack-sources' | ||
import { MATCH_ROUTE_NAME } from '../../utils' | ||
import {PAGES_MANIFEST} from '../../../lib/constants' | ||
|
||
// This plugin creates a pages-manifest.json from page entrypoints. | ||
// This is used for mapping paths like `/` to `.next/dist/bundles/pages/index.js` when doing SSR | ||
// It's also used by next export to provide defaultPathMap | ||
export default class PagesManifestPlugin { | ||
apply (compiler: any) { | ||
compiler.plugin('emit', (compilation, callback) => { | ||
const {entries} = compilation | ||
const pages = {} | ||
|
||
for (const entry of entries) { | ||
const pagePath = MATCH_ROUTE_NAME.exec(entry.name)[1] | ||
|
||
if (!pagePath) { | ||
continue | ||
} | ||
|
||
const {name} = entry | ||
pages[`/${pagePath.replace(/\\/g, '/')}`] = name | ||
} | ||
|
||
compilation.assets[PAGES_MANIFEST] = new RawSource(JSON.stringify(pages)) | ||
callback() | ||
}) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {join, parse, normalize, sep} from 'path' | ||
import fs from 'mz/fs' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's still used, but there's another PR to remove it. |
||
import {join, posix} from 'path' | ||
import {PAGES_MANIFEST} from '../lib/constants' | ||
|
||
export function pageNotFoundError (page) { | ||
const err = new Error(`Cannot find module for page: ${page}`) | ||
|
@@ -18,13 +18,8 @@ export function normalizePagePath (page) { | |
page = `/${page}` | ||
} | ||
|
||
// Windows compatibility | ||
if (sep !== '/') { | ||
page = page.replace(/\//g, sep) | ||
} | ||
|
||
// Throw when using ../ etc in the pathname | ||
const resolvedPage = normalize(page) | ||
const resolvedPage = posix.normalize(page) | ||
if (page !== resolvedPage) { | ||
throw new Error('Requested and resolved page mismatch') | ||
} | ||
|
@@ -33,7 +28,8 @@ export function normalizePagePath (page) { | |
} | ||
|
||
export function getPagePath (page, {dir, dist}) { | ||
const pageBundlesPath = join(dir, dist, 'dist', 'bundles', 'pages') | ||
const serverBuildPath = join(dir, dist, 'dist') | ||
const pagesManifest = require(join(serverBuildPath, PAGES_MANIFEST)) | ||
|
||
try { | ||
page = normalizePagePath(page) | ||
|
@@ -42,24 +38,14 @@ export function getPagePath (page, {dir, dist}) { | |
throw pageNotFoundError(page) | ||
} | ||
|
||
const pagePath = join(pageBundlesPath, page) // Path to the page that is to be loaded | ||
|
||
// Don't allow wandering outside of the bundles directory | ||
const pathDir = parse(pagePath).dir | ||
if (pathDir.indexOf(pageBundlesPath) !== 0) { | ||
console.error('Resolved page path goes outside of bundles path') | ||
if (!pagesManifest[page]) { | ||
throw pageNotFoundError(page) | ||
} | ||
|
||
return pagePath | ||
return join(serverBuildPath, pagesManifest[page]) | ||
} | ||
|
||
export default async function requirePage (page, {dir, dist}) { | ||
const pagePath = getPagePath(page, {dir, dist}) + '.js' | ||
const fileExists = await fs.exists(pagePath) | ||
if (!fileExists) { | ||
throw pageNotFoundError(page) | ||
} | ||
|
||
const pagePath = getPagePath(page, {dir, dist}) | ||
return require(pagePath) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
test: 'error' | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"/index": "bundles/pages/index.js", | ||
"/world": "bundles/pages/world.js", | ||
"/_error": "bundles/pages/_error.js", | ||
"/non-existent-child": "bundles/pages/non-existent-child.js" | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log a message on this is exporting all the pages or something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generating map from "./pages"
seems clear to me 馃 @rauchg wrote the specific text update.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the
Generating map from "./pages".
It's bit of unclear what's map is. If the user created the
exportPathMap
before it's clear.Otherwise, he/she might be looking at what's this
map
is.