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

feat: set node version for astro #5269

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions packages/build-info/src/frameworks/astro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test('should return 3000 for less than 3.0.0', async () => {
expect(detected?.[0].build.directory).toBe('dist')
expect(detected?.[0].dev?.command).toBe('astro dev')
expect(detected?.[0].dev?.port).toBe(3000)
expect(detected?.[0].env?.NODE_VERSION).toBe('16')
})

test('should detect Astro 3.0.0+ via the dependency', async () => {
Expand All @@ -49,4 +50,5 @@ test('should detect Astro 3.0.0+ via the dependency', async () => {
expect(detected?.[0].build.directory).toBe('dist')
expect(detected?.[0].dev?.command).toBe('astro dev')
expect(detected?.[0].dev?.port).toBe(4321)
expect(detected?.[0].env?.NODE_VERSION).toBe('18')
})
5 changes: 5 additions & 0 deletions packages/build-info/src/frameworks/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ export class Astro extends BaseFramework implements Framework {
dark: '/logos/astro/dark.svg',
}

env = {
NODE_VERSION: '18',
Copy link
Contributor

Choose a reason for hiding this comment

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

Mhm I think we should check if a node version is already set in the environment variables. What if a user wants to use node 20?

So we should first check if a node version is set that is larger than 18 and if an environment variable is set.

There are basically 2 ways to set a node version through the UI (should be available through the this.project.getCurrentNodeVersion and this.project.getEnv('NODE_VERSION') if the user set's the env variable we should not set it regardless of if it is greater or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah thats a great point, just looked at how the other frameworks did it and went with that. I vaguely remember being told the user's will always be respected, but hey

}

async detect(): Promise<DetectedFramework | undefined> {
await super.detect()

if (this.detected) {
// Less than 3.x.x. uses port 3000
if (this.version && lt(this.version, '3.0.0')) {
this.dev.port = 3000
this.env.NODE_VERSION = '16'
}

return this as DetectedFramework
Expand Down
Loading