Skip to content

Commit

Permalink
add assertions for making sure that the required setupDevBindings o…
Browse files Browse the repository at this point in the history
…ptions are provided (#640)
  • Loading branch information
dario-piotrowicz authored Jan 30, 2024
1 parent 1350eea commit 0b1af18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-rockets-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

add assertions for making sure that the required `setupDevBindings` options are provided
18 changes: 13 additions & 5 deletions internal-packages/next-dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export async function setupDevBindings(
const continueSetup = shouldSetupContinue();
if (!continueSetup) return;

if (!options) {
throwError('No options provided to setupDevBindings');
}

if (!options.bindings) {
throwError("The provided options object doesn't include a bindings field");
}

const mf = await instantiateMiniflare(options);

const bindings = await mf.getBindings();
Expand Down Expand Up @@ -69,10 +77,6 @@ export interface ServiceDesignator {
async function instantiateMiniflare(
options: DevBindingsOptions,
): Promise<Miniflare> {
options ??= {
bindings: {},
};

const devBindingsDurableObjectOptions = Object.fromEntries(
Object.entries(options.bindings).filter(
([, binding]) => binding.type === 'durable-object',
Expand All @@ -84,7 +88,7 @@ async function instantiateMiniflare(
devBindingsDurableObjectOptions as DevBindingsDurableObjectOptions,
)) ?? {};

const bindings = await getMiniflareBindingOptions(options.bindings ?? {});
const bindings = await getMiniflareBindingOptions(options.bindings);

const workers: WorkerOptions[] = [
{
Expand Down Expand Up @@ -331,3 +335,7 @@ export function warnAboutD1Names(d1DatabaseNamesUsed: string[]): void {
.join('\n')}\x1b[0m\n\n`,
);
}

function throwError(message: string): never {
throw new Error(`⚠️ [setupDevBindings Error]: ${message}`);
}

0 comments on commit 0b1af18

Please sign in to comment.