47 lines
1.9 KiB
JavaScript
47 lines
1.9 KiB
JavaScript
import { createRequestResponseMocks } from "./mock-request";
|
|
/**
|
|
* The DevBundlerService provides an interface to perform tasks with the
|
|
* bundler while in development.
|
|
*/ export class DevBundlerService {
|
|
constructor(bundler, handler){
|
|
this.bundler = bundler;
|
|
this.handler = handler;
|
|
this.ensurePage = async (definition)=>{
|
|
// TODO: remove after ensure is pulled out of server
|
|
return await this.bundler.hotReloader.ensurePage(definition);
|
|
};
|
|
this.logErrorWithOriginalStack = async (...args)=>{
|
|
return await this.bundler.logErrorWithOriginalStack(...args);
|
|
};
|
|
}
|
|
async getFallbackErrorComponents() {
|
|
await this.bundler.hotReloader.buildFallbackError();
|
|
// Build the error page to ensure the fallback is built too.
|
|
// TODO: See if this can be moved into hotReloader or removed.
|
|
await this.bundler.hotReloader.ensurePage({
|
|
page: "/_error",
|
|
clientOnly: false,
|
|
definition: undefined
|
|
});
|
|
}
|
|
async getCompilationError(page) {
|
|
const errors = await this.bundler.hotReloader.getCompilationErrors(page);
|
|
if (!errors) return;
|
|
// Return the very first error we found.
|
|
return errors[0];
|
|
}
|
|
async revalidate({ urlPath, revalidateHeaders, opts: revalidateOpts }) {
|
|
const mocked = createRequestResponseMocks({
|
|
url: urlPath,
|
|
headers: revalidateHeaders
|
|
});
|
|
await this.handler(mocked.req, mocked.res);
|
|
await mocked.res.hasStreamed;
|
|
if (mocked.res.getHeader("x-nextjs-cache") !== "REVALIDATED" && !(mocked.res.statusCode === 404 && revalidateOpts.unstable_onlyGenerated)) {
|
|
throw new Error(`Invalid response ${mocked.res.statusCode}`);
|
|
}
|
|
return {};
|
|
}
|
|
}
|
|
|
|
//# sourceMappingURL=dev-bundler-service.js.map
|