Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2e1a322d
Unverified
Commit
2e1a322d
authored
May 25, 2020
by
Jan Potoms
Committed by
GitHub
May 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a few extra types (#13363)
Added a few extra types here and there while I was digging through the code
parent
268d3572
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
18 deletions
+33
-18
index.ts
packages/next/build/index.ts
+4
-2
pages-manifest-plugin.ts
packages/next/build/webpack/plugins/pages-manifest-plugin.ts
+3
-1
index.ts
packages/next/export/index.ts
+19
-13
next-server.ts
packages/next/next-server/server/next-server.ts
+2
-1
require.ts
packages/next/next-server/server/require.ts
+5
-1
No files found.
packages/next/build/index.ts
View file @
2e1a322d
...
@@ -73,6 +73,8 @@ import {
...
@@ -73,6 +73,8 @@ import {
}
from
'./utils'
}
from
'./utils'
import
getBaseWebpackConfig
from
'./webpack-config'
import
getBaseWebpackConfig
from
'./webpack-config'
import
{
writeBuildId
}
from
'./write-build-id'
import
{
writeBuildId
}
from
'./write-build-id'
import
{
PagesManifest
}
from
'./webpack/plugins/pages-manifest-plugin'
import
{
BuildManifest
}
from
'../next-server/server/get-page-files'
const
staticCheckWorker
=
require
.
resolve
(
'./utils'
)
const
staticCheckWorker
=
require
.
resolve
(
'./utils'
)
...
@@ -461,10 +463,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -461,10 +463,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
const
pageInfos
=
new
Map
<
string
,
PageInfo
>
()
const
pageInfos
=
new
Map
<
string
,
PageInfo
>
()
const
pagesManifest
=
JSON
.
parse
(
const
pagesManifest
=
JSON
.
parse
(
await
promises
.
readFile
(
manifestPath
,
'utf8'
)
await
promises
.
readFile
(
manifestPath
,
'utf8'
)
)
)
as
PagesManifest
const
buildManifest
=
JSON
.
parse
(
const
buildManifest
=
JSON
.
parse
(
await
promises
.
readFile
(
buildManifestPath
,
'utf8'
)
await
promises
.
readFile
(
buildManifestPath
,
'utf8'
)
)
)
as
BuildManifest
let
customAppGetInitialProps
:
boolean
|
undefined
let
customAppGetInitialProps
:
boolean
|
undefined
let
namedExports
:
Array
<
string
>
|
undefined
let
namedExports
:
Array
<
string
>
|
undefined
...
...
packages/next/build/webpack/plugins/pages-manifest-plugin.ts
View file @
2e1a322d
...
@@ -6,6 +6,8 @@ import {
...
@@ -6,6 +6,8 @@ import {
SERVERLESS_ROUTE_NAME_REGEX
,
SERVERLESS_ROUTE_NAME_REGEX
,
}
from
'../../../next-server/lib/constants'
}
from
'../../../next-server/lib/constants'
export
type
PagesManifest
=
{
[
page
:
string
]:
string
}
// This plugin creates a pages-manifest.json from page entrypoints.
// This plugin creates a pages-manifest.json from page entrypoints.
// This is used for mapping paths like `/` to `.next/server/static/<buildid>/pages/index.js` when doing SSR
// This is used for mapping paths like `/` to `.next/server/static/<buildid>/pages/index.js` when doing SSR
// It's also used by next export to provide defaultPathMap
// It's also used by next export to provide defaultPathMap
...
@@ -19,7 +21,7 @@ export default class PagesManifestPlugin implements Plugin {
...
@@ -19,7 +21,7 @@ export default class PagesManifestPlugin implements Plugin {
apply
(
compiler
:
Compiler
):
void
{
apply
(
compiler
:
Compiler
):
void
{
compiler
.
hooks
.
emit
.
tap
(
'NextJsPagesManifest'
,
(
compilation
)
=>
{
compiler
.
hooks
.
emit
.
tap
(
'NextJsPagesManifest'
,
(
compilation
)
=>
{
const
{
chunks
}
=
compilation
const
{
chunks
}
=
compilation
const
pages
:
{
[
page
:
string
]:
string
}
=
{}
const
pages
:
PagesManifest
=
{}
for
(
const
chunk
of
chunks
)
{
for
(
const
chunk
of
chunks
)
{
const
result
=
(
this
.
serverless
const
result
=
(
this
.
serverless
...
...
packages/next/export/index.ts
View file @
2e1a322d
...
@@ -36,6 +36,7 @@ import { Telemetry } from '../telemetry/storage'
...
@@ -36,6 +36,7 @@ import { Telemetry } from '../telemetry/storage'
import
{
normalizePagePath
}
from
'../next-server/server/normalize-page-path'
import
{
normalizePagePath
}
from
'../next-server/server/normalize-page-path'
import
{
loadEnvConfig
}
from
'../lib/load-env-config'
import
{
loadEnvConfig
}
from
'../lib/load-env-config'
import
{
PrerenderManifest
}
from
'../build'
import
{
PrerenderManifest
}
from
'../build'
import
{
PagesManifest
}
from
'../build/webpack/plugins/pages-manifest-plugin'
const
exists
=
promisify
(
existsOrig
)
const
exists
=
promisify
(
existsOrig
)
...
@@ -85,9 +86,17 @@ type ExportPathMap = {
...
@@ -85,9 +86,17 @@ type ExportPathMap = {
[
page
:
string
]:
{
page
:
string
;
query
?:
{
[
key
:
string
]:
string
}
}
[
page
:
string
]:
{
page
:
string
;
query
?:
{
[
key
:
string
]:
string
}
}
}
}
export
default
async
function
(
interface
ExportOptions
{
outdir
:
string
silent
?:
boolean
threads
?:
number
pages
?:
string
[]
buildExport
?:
boolean
}
export
default
async
function
exportApp
(
dir
:
string
,
dir
:
string
,
options
:
any
,
options
:
ExportOptions
,
configuration
?:
any
configuration
?:
any
):
Promise
<
void
>
{
):
Promise
<
void
>
{
function
log
(
message
:
string
):
void
{
function
log
(
message
:
string
):
void
{
...
@@ -133,11 +142,11 @@ export default async function (
...
@@ -133,11 +142,11 @@ export default async function (
const
buildId
=
readFileSync
(
join
(
distDir
,
BUILD_ID_FILE
),
'utf8'
)
const
buildId
=
readFileSync
(
join
(
distDir
,
BUILD_ID_FILE
),
'utf8'
)
const
pagesManifest
=
const
pagesManifest
=
!
options
.
pages
&&
!
options
.
pages
&&
require
(
join
(
(
require
(
join
(
distDir
,
distDir
,
isLikeServerless
?
SERVERLESS_DIRECTORY
:
SERVER_DIRECTORY
,
isLikeServerless
?
SERVERLESS_DIRECTORY
:
SERVER_DIRECTORY
,
PAGES_MANIFEST
PAGES_MANIFEST
))
))
as
PagesManifest
)
let
prerenderManifest
:
PrerenderManifest
|
undefined
=
undefined
let
prerenderManifest
:
PrerenderManifest
|
undefined
=
undefined
try
{
try
{
...
@@ -347,15 +356,12 @@ export default async function (
...
@@ -347,15 +356,12 @@ export default async function (
})
})
}
}
const
worker
:
Worker
&
{
default
:
Function
}
=
new
Worker
(
const
worker
=
new
Worker
(
require
.
resolve
(
'./worker'
),
{
require
.
resolve
(
'./worker'
),
maxRetries
:
0
,
{
numWorkers
:
threads
,
maxRetries
:
0
,
enableWorkerThreads
:
nextConfig
.
experimental
.
workerThreads
,
numWorkers
:
threads
,
exposedMethods
:
[
'default'
],
enableWorkerThreads
:
nextConfig
.
experimental
.
workerThreads
,
})
as
Worker
&
{
default
:
Function
}
exposedMethods
:
[
'default'
],
}
)
as
any
worker
.
getStdout
().
pipe
(
process
.
stdout
)
worker
.
getStdout
().
pipe
(
process
.
stdout
)
worker
.
getStderr
().
pipe
(
process
.
stderr
)
worker
.
getStderr
().
pipe
(
process
.
stderr
)
...
...
packages/next/next-server/server/next-server.ts
View file @
2e1a322d
...
@@ -65,6 +65,7 @@ import { isBlockedPage } from './utils'
...
@@ -65,6 +65,7 @@ import { isBlockedPage } from './utils'
import
{
compile
as
compilePathToRegex
}
from
'next/dist/compiled/path-to-regexp'
import
{
compile
as
compilePathToRegex
}
from
'next/dist/compiled/path-to-regexp'
import
{
loadEnvConfig
}
from
'../../lib/load-env-config'
import
{
loadEnvConfig
}
from
'../../lib/load-env-config'
import
'./node-polyfill-fetch'
import
'./node-polyfill-fetch'
import
{
PagesManifest
}
from
'../../build/webpack/plugins/pages-manifest-plugin'
const
getCustomRouteMatcher
=
pathMatch
(
true
)
const
getCustomRouteMatcher
=
pathMatch
(
true
)
...
@@ -108,7 +109,7 @@ export default class Server {
...
@@ -108,7 +109,7 @@ export default class Server {
publicDir
:
string
publicDir
:
string
hasStaticDir
:
boolean
hasStaticDir
:
boolean
serverBuildDir
:
string
serverBuildDir
:
string
pagesManifest
?:
{
[
name
:
string
]:
string
}
pagesManifest
?:
PagesManifest
buildId
:
string
buildId
:
string
renderOpts
:
{
renderOpts
:
{
poweredByHeader
:
boolean
poweredByHeader
:
boolean
...
...
packages/next/next-server/server/require.ts
View file @
2e1a322d
...
@@ -6,6 +6,7 @@ import {
...
@@ -6,6 +6,7 @@ import {
SERVERLESS_DIRECTORY
,
SERVERLESS_DIRECTORY
,
}
from
'../lib/constants'
}
from
'../lib/constants'
import
{
normalizePagePath
}
from
'./normalize-page-path'
import
{
normalizePagePath
}
from
'./normalize-page-path'
import
{
PagesManifest
}
from
'../../build/webpack/plugins/pages-manifest-plugin'
export
function
pageNotFoundError
(
page
:
string
):
Error
{
export
function
pageNotFoundError
(
page
:
string
):
Error
{
const
err
:
any
=
new
Error
(
`Cannot find module for page:
${
page
}
`
)
const
err
:
any
=
new
Error
(
`Cannot find module for page:
${
page
}
`
)
...
@@ -23,7 +24,10 @@ export function getPagePath(
...
@@ -23,7 +24,10 @@ export function getPagePath(
distDir
,
distDir
,
serverless
&&
!
dev
?
SERVERLESS_DIRECTORY
:
SERVER_DIRECTORY
serverless
&&
!
dev
?
SERVERLESS_DIRECTORY
:
SERVER_DIRECTORY
)
)
const
pagesManifest
=
require
(
join
(
serverBuildPath
,
PAGES_MANIFEST
))
const
pagesManifest
=
require
(
join
(
serverBuildPath
,
PAGES_MANIFEST
))
as
PagesManifest
try
{
try
{
page
=
normalizePagePath
(
page
)
page
=
normalizePagePath
(
page
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment