0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

Add new top-level passthrough config option (#9767)

* feat: add db as top-level config value

* merge

* add passthrough db command

* refactor: remove extra changes

* docs: update type info

* chore: remove changeset
This commit is contained in:
Nate Moore 2024-01-22 13:37:16 -06:00 committed by GitHub
parent 1fba85681e
commit 80d87fb3ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 0 deletions

View file

@ -1535,6 +1535,9 @@ export interface AstroUserConfig {
};
};
/** ⚠️ WARNING: SUBJECT TO CHANGE */
db?: Config.Database;
/**
* @docs
* @kind heading
@ -2743,3 +2746,10 @@ declare global {
'astro-dev-overlay-card': DevToolbarCard;
}
}
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Config {
type Database = Record<string, any>;
}
}

View file

@ -0,0 +1,27 @@
import type { Arguments } from 'yargs-parser';
import { createLoggerFromFlags } from '../flags.js';
import { getPackage } from '../install-package.js';
export async function db({ flags }: { flags: Arguments }) {
const logger = createLoggerFromFlags(flags);
const getPackageOpts = { skipAsk: flags.yes || flags.y, cwd: flags.root };
const dbPackage = await getPackage<any>(
'@astrojs/db',
logger,
getPackageOpts,
[]
);
if (!dbPackage) {
logger.error(
'check',
'The `@astrojs/db` package is required for this command to work. Please manually install it in your project and try again.'
);
return;
}
const { cli } = dbPackage;
const [command, ...args] = flags._.slice(3).map(v => v.toString());
await cli(command, args);
}

View file

@ -11,6 +11,7 @@ type CLICommand =
| 'dev'
| 'build'
| 'preview'
| 'db'
| 'sync'
| 'check'
| 'info'
@ -72,6 +73,7 @@ function resolveCommand(flags: yargs.Arguments): CLICommand {
'preview',
'check',
'docs',
'db',
'info',
]);
if (supportedCommands.has(cmd)) {
@ -143,6 +145,11 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
await add(packages, { flags });
return;
}
case 'db': {
const { db } = await import('./db/index.js');
await db({ flags });
return;
}
case 'dev': {
const { dev } = await import('./dev/index.js');
const server = await dev({ flags });

View file

@ -112,6 +112,7 @@ export const AstroConfigSchema = z.object({
.optional()
.default('attribute'),
adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
db: z.object({}).passthrough().default({}).optional(),
integrations: z.preprocess(
// preprocess
(val) => (Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val),