0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

refactor: rename "config" file to "virtual" (#10638)

* refactor: rename "config" file to "virtual"

* chore: changeset

* fix(test): config import
This commit is contained in:
Ben Holmes 2024-04-02 18:13:18 -04:00 committed by GitHub
parent 4f5dc14f31
commit f395ebcc08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 23 additions and 18 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/db": minor
---
Rename internal import from `runtime/config` to `runtime/virtual`

View file

@ -20,8 +20,8 @@
"types": "./dist/runtime/index.d.ts",
"import": "./dist/runtime/index.js"
},
"./dist/runtime/config.js": {
"import": "./dist/runtime/config.js"
"./dist/runtime/virtual.js": {
"import": "./dist/runtime/virtual.js"
},
"./types": {
"types": "./dist/core/types.d.ts",
@ -55,8 +55,8 @@
"astro-integration"
],
"scripts": {
"types:config": "tsc -p ./tsconfig.config-types.json",
"build": "astro-scripts build \"src/**/*.ts\" && tsc && pnpm types:config",
"types:virtual": "tsc -p ./tsconfig.virtual.json",
"build": "astro-scripts build \"src/**/*.ts\" && tsc && pnpm types:virtual",
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "mocha --exit --timeout 20000 \"test/*.js\" \"test/unit/**/*.js\"",

View file

@ -6,7 +6,7 @@ export const PACKAGE_NAME = JSON.parse(
export const RUNTIME_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime`);
export const RUNTIME_CONFIG_IMPORT = JSON.stringify(`${PACKAGE_NAME}/dist/runtime/config.js`);
export const RUNTIME_VIRTUAL_IMPORT = JSON.stringify(`${PACKAGE_NAME}/dist/runtime/virtual.js`);
export const DB_TYPES_FILE = 'db-types.d.ts';

View file

@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
import type { AstroConfig } from 'astro';
import { normalizePath } from 'vite';
import { SEED_DEV_FILE_NAME } from '../../runtime/queries.js';
import { DB_PATH, RUNTIME_CONFIG_IMPORT, RUNTIME_IMPORT, VIRTUAL_MODULE_ID } from '../consts.js';
import { DB_PATH, RUNTIME_VIRTUAL_IMPORT, RUNTIME_IMPORT, VIRTUAL_MODULE_ID } from '../consts.js';
import type { DBTables } from '../types.js';
import { type VitePlugin, getDbDirectoryUrl, getRemoteDatabaseUrl } from '../utils.js';
@ -83,7 +83,7 @@ export function vitePluginDb(params: VitePluginDBParams): VitePlugin {
}
export function getConfigVirtualModContents() {
return `export * from ${RUNTIME_CONFIG_IMPORT}`;
return `export * from ${RUNTIME_VIRTUAL_IMPORT}`;
}
export function getLocalVirtualModContents({
@ -136,7 +136,7 @@ ${
: ''
}
export * from ${RUNTIME_CONFIG_IMPORT};
export * from ${RUNTIME_VIRTUAL_IMPORT};
${getStringifiedTableExports(tables)}`;
}
@ -177,7 +177,7 @@ import {asDrizzleTable, createRemoteDatabaseClient} from ${RUNTIME_IMPORT};
export const db = await createRemoteDatabaseClient(${appTokenArg()}, ${dbUrlArg()});
export * from ${RUNTIME_CONFIG_IMPORT};
export * from ${RUNTIME_VIRTUAL_IMPORT};
${getStringifiedTableExports(tables)}
`;

View file

@ -6,7 +6,7 @@ import {
} from '../../dist/core/cli/migration-queries.js';
import { MIGRATION_VERSION } from '../../dist/core/consts.js';
import { tableSchema } from '../../dist/core/schemas.js';
import { NOW, column, defineTable } from '../../dist/runtime/config.js';
import { NOW, column, defineTable } from '../../dist/runtime/virtual.js';
const TABLE_NAME = 'Users';

View file

@ -2,7 +2,7 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { getTableChangeQueries } from '../../dist/core/cli/migration-queries.js';
import { dbConfigSchema, tableSchema } from '../../dist/core/schemas.js';
import { column } from '../../dist/runtime/config.js';
import { column } from '../../dist/runtime/virtual.js';
const userInitial = tableSchema.parse({
columns: {

View file

@ -2,7 +2,7 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';
import { getTableChangeQueries } from '../../dist/core/cli/migration-queries.js';
import { tablesSchema } from '../../dist/core/schemas.js';
import { column, defineTable } from '../../dist/runtime/config.js';
import { column, defineTable } from '../../dist/runtime/virtual.js';
const BaseUser = defineTable({
columns: {

View file

@ -3,7 +3,7 @@ import { describe, it } from 'mocha';
import { getMigrationQueries } from '../../dist/core/cli/migration-queries.js';
import { MIGRATION_VERSION } from '../../dist/core/consts.js';
import { tableSchema } from '../../dist/core/schemas.js';
import { column, defineTable } from '../../dist/runtime/config.js';
import { column, defineTable } from '../../dist/runtime/virtual.js';
const TABLE_NAME = 'Users';

View file

@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["src/runtime/config.ts"],
"exclude": ["src/runtime/virtual.ts"],
"compilerOptions": {
"outDir": "./dist"
}

View file

@ -1,11 +1,11 @@
{
// We want to avoid defineTable() and defineDb() import hints
// from the runtime config export instead of astro:db.
// We exclude runtime/config from the base types,
// We exclude runtime/virtual from the base types,
// and generate to a separate _internal/ directory
// for our virtual module (virtual.d.ts) to reference.
"extends": "../../tsconfig.base.json",
"files": ["./src/runtime/config.ts"],
"files": ["./src/runtime/virtual.ts"],
"compilerOptions": {
"outDir": "./dist/_internal"
}

View file

@ -1,7 +1,7 @@
declare module 'astro:db' {
type RuntimeConfig = typeof import('./dist/_internal/runtime/config.js');
type RuntimeConfig = typeof import('./dist/_internal/runtime/virtual.js');
export const db: import('./dist/_internal/runtime/config.js').Database;
export const db: import('./dist/_internal/runtime/virtual.js').Database;
export const dbUrl: string;
export const sql: RuntimeConfig['sql'];