Unverified Commit 2e1a322d authored by Jan Potoms's avatar Jan Potoms Committed by GitHub

Add a few extra types (#13363)

Added a few extra types here and there while I was digging through the code
parent 268d3572
...@@ -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
......
...@@ -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
......
...@@ -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)
......
...@@ -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
......
...@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment