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

Avoid importing vite in db utils #10946

Closed
wants to merge 2 commits into from
Closed

Avoid importing vite in db utils #10946

wants to merge 2 commits into from

Conversation

delucis
Copy link
Member

@delucis delucis commented May 3, 2024

Changes

  • Reorganises some Astro DB code to avoid Vite being imported by @astrojs/db/utils

Testing

  • Existing tests should pass
  • Is there a way we can enforce or check Vite is not imported?

Docs

n/a — bug fix

Copy link

changeset-bot bot commented May 3, 2024

🦋 Changeset detected

Latest commit: 477c330

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -1,8 +1,12 @@
export { defineDbIntegration } from './core/utils.js';
import type { AstroIntegration } from 'astro';
import { tableSchema } from './core/schemas.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still importing from core/schemas.js which imports core/utils.js which imports vite.

The rule is that runtime should not import inside in core. I don't know if this problem is solvable in this way.

Copy link
Member Author

@delucis delucis May 3, 2024

Choose a reason for hiding this comment

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

core/schemas no longer imports Vite — I removed/refactored that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I see that now, but this could easily be broken by a new PR that does need something else from utils. We try to stick with the rule that runtime code only imports runtime code and not core, to prevent mistakes.

@@ -4,7 +4,6 @@ import { type ZodTypeDef, z } from 'zod';
import { SERIALIZED_SQL_KEY, type SerializedSQL } from '../runtime/types.js';
import { errorMap } from './integration/error-map.js';
import type { NumberColumn, TextColumn } from './types.js';
import { mapObject } from './utils.js';
Copy link
Member Author

Choose a reason for hiding this comment

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

core/utils imports Vite so we want to avoid importing it — moved mapObject inline into this file as it is only used here

Comment on lines -31 to -33
export function defineDbIntegration(integration: AstroDbIntegration): AstroIntegration {
return integration;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this straight to the user-facing utils library to avoid importing it from here where Vite is also imported

@delucis delucis closed this May 3, 2024
@bluwy bluwy deleted the chris/fix-db-vite-ref branch October 8, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants