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:
parent
1fba85681e
commit
80d87fb3ef
4 changed files with 45 additions and 0 deletions
|
@ -1535,6 +1535,9 @@ export interface AstroUserConfig {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** ⚠️ WARNING: SUBJECT TO CHANGE */
|
||||||
|
db?: Config.Database;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @docs
|
* @docs
|
||||||
* @kind heading
|
* @kind heading
|
||||||
|
@ -2743,3 +2746,10 @@ declare global {
|
||||||
'astro-dev-overlay-card': DevToolbarCard;
|
'astro-dev-overlay-card': DevToolbarCard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
namespace Config {
|
||||||
|
type Database = Record<string, any>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
27
packages/astro/src/cli/db/index.ts
Normal file
27
packages/astro/src/cli/db/index.ts
Normal 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);
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ type CLICommand =
|
||||||
| 'dev'
|
| 'dev'
|
||||||
| 'build'
|
| 'build'
|
||||||
| 'preview'
|
| 'preview'
|
||||||
|
| 'db'
|
||||||
| 'sync'
|
| 'sync'
|
||||||
| 'check'
|
| 'check'
|
||||||
| 'info'
|
| 'info'
|
||||||
|
@ -72,6 +73,7 @@ function resolveCommand(flags: yargs.Arguments): CLICommand {
|
||||||
'preview',
|
'preview',
|
||||||
'check',
|
'check',
|
||||||
'docs',
|
'docs',
|
||||||
|
'db',
|
||||||
'info',
|
'info',
|
||||||
]);
|
]);
|
||||||
if (supportedCommands.has(cmd)) {
|
if (supportedCommands.has(cmd)) {
|
||||||
|
@ -143,6 +145,11 @@ async function runCommand(cmd: string, flags: yargs.Arguments) {
|
||||||
await add(packages, { flags });
|
await add(packages, { flags });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case 'db': {
|
||||||
|
const { db } = await import('./db/index.js');
|
||||||
|
await db({ flags });
|
||||||
|
return;
|
||||||
|
}
|
||||||
case 'dev': {
|
case 'dev': {
|
||||||
const { dev } = await import('./dev/index.js');
|
const { dev } = await import('./dev/index.js');
|
||||||
const server = await dev({ flags });
|
const server = await dev({ flags });
|
||||||
|
|
|
@ -112,6 +112,7 @@ export const AstroConfigSchema = z.object({
|
||||||
.optional()
|
.optional()
|
||||||
.default('attribute'),
|
.default('attribute'),
|
||||||
adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
|
adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
|
||||||
|
db: z.object({}).passthrough().default({}).optional(),
|
||||||
integrations: z.preprocess(
|
integrations: z.preprocess(
|
||||||
// preprocess
|
// preprocess
|
||||||
(val) => (Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val),
|
(val) => (Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val),
|
||||||
|
|
Loading…
Add table
Reference in a new issue