From 3d77be2beed2194b2797f983b8f79606698cdcea Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Fri, 1 Mar 2024 13:32:09 -0500 Subject: [PATCH] chore: remove useBundledDbUrl --- .../db/src/core/cli/commands/execute/index.ts | 1 - .../db/src/core/integration/vite-plugin-db.ts | 12 +---- packages/db/src/core/load-file.ts | 47 +++++++------------ 3 files changed, 18 insertions(+), 42 deletions(-) diff --git a/packages/db/src/core/cli/commands/execute/index.ts b/packages/db/src/core/cli/commands/execute/index.ts index fab14a4f85..875850b7ca 100644 --- a/packages/db/src/core/cli/commands/execute/index.ts +++ b/packages/db/src/core/cli/commands/execute/index.ts @@ -30,7 +30,6 @@ export async function cmd({ const appToken = await getManagedAppTokenOrExit(flags.token); await executeFile({ - connectToStudio: true, fileUrl, tables: dbConfig.tables ?? {}, root: astroConfig.root, diff --git a/packages/db/src/core/integration/vite-plugin-db.ts b/packages/db/src/core/integration/vite-plugin-db.ts index bce7cc4111..98d18d23a0 100644 --- a/packages/db/src/core/integration/vite-plugin-db.ts +++ b/packages/db/src/core/integration/vite-plugin-db.ts @@ -79,16 +79,10 @@ export function getLocalVirtualModContents({ tables, root, shouldSeed, - useBundledDbUrl = true, }: { tables: DBTables; root: URL; shouldSeed: boolean; - /** - * Allow `db execute` to use `dbUrl` directly without rollup bundling. - * `db execute` loads config with minimal esbuild config instead of vite. - */ - useBundledDbUrl?: boolean; }) { const dbUrl = new URL(DB_PATH, root); const seedFilePaths = SEED_DEV_FILE_NAMES_SORTED.map( @@ -99,11 +93,7 @@ export function getLocalVirtualModContents({ return ` import { asDrizzleTable, createLocalDatabaseClient } from ${RUNTIME_IMPORT}; -${ - useBundledDbUrl - ? `import dbUrl from ${JSON.stringify(`${dbUrl}?fileurl`)};` - : `const dbUrl = ${JSON.stringify(dbUrl)};` -} +import dbUrl from ${JSON.stringify(`${dbUrl}?fileurl`)}; export const db = await createLocalDatabaseClient({ dbUrl, diff --git a/packages/db/src/core/load-file.ts b/packages/db/src/core/load-file.ts index 9a4dacdab5..5d370f4d55 100644 --- a/packages/db/src/core/load-file.ts +++ b/packages/db/src/core/load-file.ts @@ -3,7 +3,6 @@ import { CONFIG_FILE_NAMES, VIRTUAL_MODULE_ID } from './consts.js'; import { fileURLToPath } from 'node:url'; import { getConfigVirtualModContents, - getLocalVirtualModContents, getStudioVirtualModContents, } from './integration/vite-plugin-db.js'; import type { DBTables } from './types.js'; @@ -11,36 +10,24 @@ import { writeFile, unlink } from 'node:fs/promises'; import { getDbDirUrl } from './utils.js'; import { existsSync } from 'node:fs'; -type ExecuteFileParams = - | { - connectToStudio: false; - fileUrl: URL; - tables: DBTables; - root: URL; - } - | { - connectToStudio: true; - fileUrl: URL; - tables: DBTables; - root: URL; - appToken: string; - }; - -export async function executeFile(params: ExecuteFileParams): Promise { - const virtualModContents = params.connectToStudio - ? getStudioVirtualModContents({ - tables: params.tables, - appToken: params.appToken, - }) - : getLocalVirtualModContents({ - tables: params.tables, - root: params.root, - shouldSeed: false, - useBundledDbUrl: false, - }); - const { code } = await bundleFile({ virtualModContents, ...params }); +export async function executeFile({ + tables, + appToken, + root, + fileUrl, +}: { + tables: DBTables; + appToken: string; + root: URL; + fileUrl: URL; +}): Promise { + const virtualModContents = getStudioVirtualModContents({ + tables, + appToken, + }); + const { code } = await bundleFile({ virtualModContents, root, fileUrl }); // Executable files use top-level await. Importing will run the file. - await importBundledFile({ code, root: params.root }); + await importBundledFile({ code, root }); } export async function loadConfigFile(