mirror of
https://github.com/withastro/astro.git
synced 2025-02-24 22:46:02 -05:00
chore: remove useBundledDbUrl
This commit is contained in:
parent
483fbd13fc
commit
3d77be2bee
3 changed files with 18 additions and 42 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
export async function executeFile({
|
||||
tables,
|
||||
appToken,
|
||||
root,
|
||||
fileUrl,
|
||||
}: {
|
||||
tables: DBTables;
|
||||
root: URL;
|
||||
}
|
||||
| {
|
||||
connectToStudio: true;
|
||||
fileUrl: URL;
|
||||
tables: DBTables;
|
||||
root: URL;
|
||||
appToken: string;
|
||||
};
|
||||
|
||||
export async function executeFile(params: ExecuteFileParams): Promise<void> {
|
||||
const virtualModContents = params.connectToStudio
|
||||
? getStudioVirtualModContents({
|
||||
tables: params.tables,
|
||||
appToken: params.appToken,
|
||||
})
|
||||
: getLocalVirtualModContents({
|
||||
tables: params.tables,
|
||||
root: params.root,
|
||||
shouldSeed: false,
|
||||
useBundledDbUrl: false,
|
||||
root: URL;
|
||||
fileUrl: URL;
|
||||
}): Promise<void> {
|
||||
const virtualModContents = getStudioVirtualModContents({
|
||||
tables,
|
||||
appToken,
|
||||
});
|
||||
const { code } = await bundleFile({ virtualModContents, ...params });
|
||||
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(
|
||||
|
|
Loading…
Add table
Reference in a new issue