Add optional experimentalStreamingLambda field for prerender (#10476)

This adds a new `experimentalStreamingLambda` field to Prerender
outputs, allowing references to an optional streaming lambda path.
This commit is contained in:
Nabeel Sulieman
2023-09-08 11:42:06 -07:00
committed by GitHub
parent 82231058da
commit 50e04dd858
3 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
'@vercel/build-utils': minor
---
Add new optional prerender field: experimentalStreamingLambdaPath

View File

@@ -12,6 +12,7 @@ interface PrerenderOptions {
initialStatus?: number;
passQuery?: boolean;
sourcePath?: string;
experimentalStreamingLambdaPath?: string;
}
export class Prerender {
@@ -26,6 +27,7 @@ export class Prerender {
public initialStatus?: number;
public passQuery?: boolean;
public sourcePath?: string;
public experimentalStreamingLambdaPath?: string;
constructor({
expiration,
@@ -38,6 +40,7 @@ export class Prerender {
initialStatus,
passQuery,
sourcePath,
experimentalStreamingLambdaPath,
}: PrerenderOptions) {
this.type = 'Prerender';
this.expiration = expiration;
@@ -130,5 +133,14 @@ export class Prerender {
}
this.allowQuery = allowQuery;
}
if (experimentalStreamingLambdaPath !== undefined) {
if (typeof experimentalStreamingLambdaPath !== 'string') {
throw new Error(
'The `experimentalStreamingLambdaPath` argument for `Prerender` must be a string.'
);
}
this.experimentalStreamingLambdaPath = experimentalStreamingLambdaPath;
}
}
}

View File

@@ -387,6 +387,42 @@ it('should support passQuery correctly', async () => {
);
});
it('should support experimentalStreamingLambdaPath correctly', async () => {
new Prerender({
expiration: 1,
fallback: null,
group: 1,
bypassToken: 'some-long-bypass-token-to-make-it-work',
experimentalStreamingLambdaPath: undefined,
});
new Prerender({
expiration: 1,
fallback: null,
group: 1,
bypassToken: 'some-long-bypass-token-to-make-it-work',
experimentalStreamingLambdaPath: '/some/path/to/lambda',
});
new Prerender({
expiration: 1,
fallback: null,
group: 1,
bypassToken: 'some-long-bypass-token-to-make-it-work',
});
expect(() => {
new Prerender({
expiration: 1,
fallback: null,
group: 1,
bypassToken: 'some-long-bypass-token-to-make-it-work',
// @ts-expect-error testing invalid field
experimentalStreamingLambdaPath: 1,
});
}).toThrowError(
`The \`experimentalStreamingLambdaPath\` argument for \`Prerender\` must be a string.`
);
});
it('should support require by path for legacy builders', () => {
const index = require('../');