2019-06-26 04:54:28 +02:00
|
|
|
import { isPageStatic } from './utils'
|
|
|
|
|
|
|
|
export default function worker(
|
|
|
|
options: any,
|
|
|
|
callback: (err: Error | null, data?: any) => void
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
const { serverBundle, runtimeEnvConfig } = options || ({} as any)
|
2019-07-01 23:13:52 +02:00
|
|
|
const result = isPageStatic(serverBundle, runtimeEnvConfig)
|
2019-06-26 21:16:54 +02:00
|
|
|
|
|
|
|
// clear require.cache to prevent running out of memory
|
|
|
|
// since the cache is persisted by default
|
|
|
|
Object.keys(require.cache).map(modId => {
|
|
|
|
const mod = require.cache[modId]
|
|
|
|
delete require.cache[modId]
|
|
|
|
if (mod.parent) {
|
|
|
|
const idx = mod.parent.children.indexOf(mod)
|
|
|
|
mod.parent.children.splice(idx, 1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-07-01 23:13:52 +02:00
|
|
|
callback(null, result)
|
2019-06-26 04:54:28 +02:00
|
|
|
} catch (error) {
|
|
|
|
callback(error)
|
|
|
|
}
|
|
|
|
}
|