Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-owls-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": minor
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made minor since this renames an exports entry to runtime/virtual.js. This export is undocumented and is only used by Astro DB internally (not Astro core). Just being extra cautious with versioning.

---

Rename internal import from `runtime/config` to `runtime/virtual`
8 changes: 4 additions & 4 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/core/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
8 changes: 4 additions & 4 deletions packages/db/src/core/integration/vite-plugin-db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'node:url';
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';

Expand Down Expand Up @@ -79,7 +79,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({
Expand Down Expand Up @@ -132,7 +132,7 @@ ${
: ''
}

export * from ${RUNTIME_CONFIG_IMPORT};
export * from ${RUNTIME_VIRTUAL_IMPORT};

${getStringifiedTableExports(tables)}`;
}
Expand Down Expand Up @@ -166,7 +166,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)}
`;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/db/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["src/runtime/config.ts"],
"exclude": ["src/runtime/virtual.ts"],
"compilerOptions": {
"outDir": "./dist"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/db/virtual.d.ts
Original file line number Diff line number Diff line change
@@ -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'];
Expand Down
Loading