2020-02-24 22:36:59 +01:00
|
|
|
import { buildStaticPaths } from '../build/utils'
|
|
|
|
import { loadComponents } from '../next-server/server/load-components'
|
2020-05-12 21:58:21 +02:00
|
|
|
import '../next-server/server/node-polyfill-fetch'
|
2020-03-05 19:48:09 +01:00
|
|
|
|
2020-08-04 18:47:37 +02:00
|
|
|
type RuntimeConfig = any
|
|
|
|
|
2020-03-25 19:57:14 +01:00
|
|
|
let workerWasUsed = false
|
2020-02-24 22:36:59 +01:00
|
|
|
|
|
|
|
// we call getStaticPaths in a separate process to ensure
|
|
|
|
// side-effects aren't relied on in dev that will break
|
|
|
|
// during a production build
|
|
|
|
export async function loadStaticPaths(
|
|
|
|
distDir: string,
|
|
|
|
pathname: string,
|
2020-08-04 18:47:37 +02:00
|
|
|
serverless: boolean,
|
2020-10-07 23:11:01 +02:00
|
|
|
config: RuntimeConfig,
|
|
|
|
locales?: string[],
|
|
|
|
defaultLocale?: string
|
2020-02-24 22:36:59 +01:00
|
|
|
) {
|
2020-03-25 19:57:14 +01:00
|
|
|
// we only want to use each worker once to prevent any invalid
|
|
|
|
// caches
|
|
|
|
if (workerWasUsed) {
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2020-02-24 22:36:59 +01:00
|
|
|
|
2020-08-04 18:47:37 +02:00
|
|
|
// update work memory runtime-config
|
|
|
|
require('./../next-server/lib/runtime-config').setConfig(config)
|
|
|
|
|
2020-06-15 16:41:17 +02:00
|
|
|
const components = await loadComponents(distDir, pathname, serverless)
|
2020-02-24 22:36:59 +01:00
|
|
|
|
2020-02-27 18:57:39 +01:00
|
|
|
if (!components.getStaticPaths) {
|
2020-02-24 22:36:59 +01:00
|
|
|
// we shouldn't get to this point since the worker should
|
|
|
|
// only be called for SSG pages with getStaticPaths
|
|
|
|
throw new Error(
|
2020-02-27 18:57:39 +01:00
|
|
|
`Invariant: failed to load page with getStaticPaths for ${pathname}`
|
2020-02-24 22:36:59 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-25 19:57:14 +01:00
|
|
|
workerWasUsed = true
|
2020-10-07 23:11:01 +02:00
|
|
|
return buildStaticPaths(
|
|
|
|
pathname,
|
|
|
|
components.getStaticPaths,
|
|
|
|
locales,
|
|
|
|
defaultLocale
|
|
|
|
)
|
2020-02-24 22:36:59 +01:00
|
|
|
}
|