Skip to content

Commit 0b1af18

Browse files
add assertions for making sure that the required setupDevBindings options are provided (#640)
1 parent 1350eea commit 0b1af18

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

.changeset/neat-rockets-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudflare/next-on-pages': patch
3+
---
4+
5+
add assertions for making sure that the required `setupDevBindings` options are provided

internal-packages/next-dev/src/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export async function setupDevBindings(
1818
const continueSetup = shouldSetupContinue();
1919
if (!continueSetup) return;
2020

21+
if (!options) {
22+
throwError('No options provided to setupDevBindings');
23+
}
24+
25+
if (!options.bindings) {
26+
throwError("The provided options object doesn't include a bindings field");
27+
}
28+
2129
const mf = await instantiateMiniflare(options);
2230

2331
const bindings = await mf.getBindings();
@@ -69,10 +77,6 @@ export interface ServiceDesignator {
6977
async function instantiateMiniflare(
7078
options: DevBindingsOptions,
7179
): Promise<Miniflare> {
72-
options ??= {
73-
bindings: {},
74-
};
75-
7680
const devBindingsDurableObjectOptions = Object.fromEntries(
7781
Object.entries(options.bindings).filter(
7882
([, binding]) => binding.type === 'durable-object',
@@ -84,7 +88,7 @@ async function instantiateMiniflare(
8488
devBindingsDurableObjectOptions as DevBindingsDurableObjectOptions,
8589
)) ?? {};
8690

87-
const bindings = await getMiniflareBindingOptions(options.bindings ?? {});
91+
const bindings = await getMiniflareBindingOptions(options.bindings);
8892

8993
const workers: WorkerOptions[] = [
9094
{
@@ -331,3 +335,7 @@ export function warnAboutD1Names(d1DatabaseNamesUsed: string[]): void {
331335
.join('\n')}\x1b[0m\n\n`,
332336
);
333337
}
338+
339+
function throwError(message: string): never {
340+
throw new Error(`⚠️ [setupDevBindings Error]: ${message}`);
341+
}

0 commit comments

Comments
 (0)