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; initialStatus?: number;
passQuery?: boolean; passQuery?: boolean;
sourcePath?: string; sourcePath?: string;
experimentalStreamingLambdaPath?: string;
} }
export class Prerender { export class Prerender {
@@ -26,6 +27,7 @@ export class Prerender {
public initialStatus?: number; public initialStatus?: number;
public passQuery?: boolean; public passQuery?: boolean;
public sourcePath?: string; public sourcePath?: string;
public experimentalStreamingLambdaPath?: string;
constructor({ constructor({
expiration, expiration,
@@ -38,6 +40,7 @@ export class Prerender {
initialStatus, initialStatus,
passQuery, passQuery,
sourcePath, sourcePath,
experimentalStreamingLambdaPath,
}: PrerenderOptions) { }: PrerenderOptions) {
this.type = 'Prerender'; this.type = 'Prerender';
this.expiration = expiration; this.expiration = expiration;
@@ -130,5 +133,14 @@ export class Prerender {
} }
this.allowQuery = allowQuery; 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', () => { it('should support require by path for legacy builders', () => {
const index = require('../'); const index = require('../');