Add a few extra types (#13363)

Added a few extra types here and there while I was digging through the code
This commit is contained in:
Jan Potoms 2020-05-25 23:15:56 +02:00 committed by GitHub
parent 268d3572bc
commit 2e1a322d6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 18 deletions

View file

@ -73,6 +73,8 @@ import {
} from './utils'
import getBaseWebpackConfig from './webpack-config'
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')
@ -461,10 +463,10 @@ export default async function build(dir: string, conf = null): Promise<void> {
const pageInfos = new Map<string, PageInfo>()
const pagesManifest = JSON.parse(
await promises.readFile(manifestPath, 'utf8')
)
) as PagesManifest
const buildManifest = JSON.parse(
await promises.readFile(buildManifestPath, 'utf8')
)
) as BuildManifest
let customAppGetInitialProps: boolean | undefined
let namedExports: Array<string> | undefined

View file

@ -6,6 +6,8 @@ import {
SERVERLESS_ROUTE_NAME_REGEX,
} from '../../../next-server/lib/constants'
export type PagesManifest = { [page: string]: string }
// 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
// It's also used by next export to provide defaultPathMap
@ -19,7 +21,7 @@ export default class PagesManifestPlugin implements Plugin {
apply(compiler: Compiler): void {
compiler.hooks.emit.tap('NextJsPagesManifest', (compilation) => {
const { chunks } = compilation
const pages: { [page: string]: string } = {}
const pages: PagesManifest = {}
for (const chunk of chunks) {
const result = (this.serverless

View file

@ -36,6 +36,7 @@ import { Telemetry } from '../telemetry/storage'
import { normalizePagePath } from '../next-server/server/normalize-page-path'
import { loadEnvConfig } from '../lib/load-env-config'
import { PrerenderManifest } from '../build'
import { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
const exists = promisify(existsOrig)
@ -85,9 +86,17 @@ type ExportPathMap = {
[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,
options: any,
options: ExportOptions,
configuration?: any
): Promise<void> {
function log(message: string): void {
@ -133,11 +142,11 @@ export default async function (
const buildId = readFileSync(join(distDir, BUILD_ID_FILE), 'utf8')
const pagesManifest =
!options.pages &&
require(join(
(require(join(
distDir,
isLikeServerless ? SERVERLESS_DIRECTORY : SERVER_DIRECTORY,
PAGES_MANIFEST
))
)) as PagesManifest)
let prerenderManifest: PrerenderManifest | undefined = undefined
try {
@ -347,15 +356,12 @@ export default async function (
})
}
const worker: Worker & { default: Function } = new Worker(
require.resolve('./worker'),
{
maxRetries: 0,
numWorkers: threads,
enableWorkerThreads: nextConfig.experimental.workerThreads,
exposedMethods: ['default'],
}
) as any
const worker = new Worker(require.resolve('./worker'), {
maxRetries: 0,
numWorkers: threads,
enableWorkerThreads: nextConfig.experimental.workerThreads,
exposedMethods: ['default'],
}) as Worker & { default: Function }
worker.getStdout().pipe(process.stdout)
worker.getStderr().pipe(process.stderr)

View file

@ -65,6 +65,7 @@ import { isBlockedPage } from './utils'
import { compile as compilePathToRegex } from 'next/dist/compiled/path-to-regexp'
import { loadEnvConfig } from '../../lib/load-env-config'
import './node-polyfill-fetch'
import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin'
const getCustomRouteMatcher = pathMatch(true)
@ -108,7 +109,7 @@ export default class Server {
publicDir: string
hasStaticDir: boolean
serverBuildDir: string
pagesManifest?: { [name: string]: string }
pagesManifest?: PagesManifest
buildId: string
renderOpts: {
poweredByHeader: boolean

View file

@ -6,6 +6,7 @@ import {
SERVERLESS_DIRECTORY,
} from '../lib/constants'
import { normalizePagePath } from './normalize-page-path'
import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin'
export function pageNotFoundError(page: string): Error {
const err: any = new Error(`Cannot find module for page: ${page}`)
@ -23,7 +24,10 @@ export function getPagePath(
distDir,
serverless && !dev ? SERVERLESS_DIRECTORY : SERVER_DIRECTORY
)
const pagesManifest = require(join(serverBuildPath, PAGES_MANIFEST))
const pagesManifest = require(join(
serverBuildPath,
PAGES_MANIFEST
)) as PagesManifest
try {
page = normalizePagePath(page)