54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "DevBundlerService", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return DevBundlerService;
|
|
}
|
|
});
|
|
const _mockrequest = require("./mock-request");
|
|
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 = (0, _mockrequest.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
|