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(env): server/public variables #10881
Merged
florian-lefebvre
merged 48 commits into
feat/astro-env
from
feat/astro-env-server-public
May 6, 2024
+125
−9
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
c7fffe0
feat: add schema, types and envField
florian-lefebvre 0e90c5d
feat: move things around
florian-lefebvre 94d6ffc
feat: add validators
florian-lefebvre d717361
feat: rework everything
florian-lefebvre d9ce895
feat: default
florian-lefebvre f136b1b
chore: space
florian-lefebvre 0260bbb
Merge branch 'feat/astro-env-config' into feat/astro-env-validators
florian-lefebvre b84cea9
feat: reuse types
florian-lefebvre 3f32ea6
feat: work on test
florian-lefebvre ff99f0d
feat: write test
florian-lefebvre 8896fa7
feat: add test
florian-lefebvre 9d8d425
Merge branch 'feat/astro-env-config' into feat/astro-env-validators
florian-lefebvre 07f586e
feat: add vite plugin
florian-lefebvre 5063b1f
feat: update zod custom validation
florian-lefebvre b23233c
feat: validation logic
florian-lefebvre e02b722
feat: work on types injection
florian-lefebvre e9d99a1
Merge branch 'feat/astro-env' into feat/astro-env-vite-plugin
florian-lefebvre bff9024
fix: test
florian-lefebvre fc983d1
Merge branch 'feat/astro-env-vite-plugin' into feat/astro-env-client-…
florian-lefebvre 518fd15
fix: test
florian-lefebvre eeda833
fix: test
florian-lefebvre 9516c2c
fix: cli tests
florian-lefebvre f23296d
feat: make things work
florian-lefebvre 37ec524
feat: address todos
florian-lefebvre ae92463
Discard changes to examples/basics/astro.config.mjs
florian-lefebvre dc92fb6
Discard changes to examples/basics/src/env.d.ts
florian-lefebvre 4496bc9
Merge branch 'feat/astro-env' into feat/astro-env-client-public
florian-lefebvre f6a993a
fix: test
florian-lefebvre 1384136
feat: refactor astro sync test
florian-lefebvre 26e2b82
feat: update test to check env types
florian-lefebvre f4b09b8
fix: fixture
florian-lefebvre c1539ed
feat: simplify injected types
florian-lefebvre 4b5c28c
feat: move plugin
florian-lefebvre 0c99784
fix: imports
florian-lefebvre 20875e7
feat: add tests for getType
florian-lefebvre 82db951
feat: add test
florian-lefebvre e093397
Update index.ts
florian-lefebvre 770b806
fix: variable name conflict
florian-lefebvre e29e48d
Apply suggestions from code review
florian-lefebvre aa0312d
feat: harcode constants
florian-lefebvre 353446e
feat: rename condition to meetsCondition
florian-lefebvre 82a3142
feat: rename function
florian-lefebvre 4e37b39
feat: simplify content/dts computation
florian-lefebvre 5cb7e59
feat: throw one error with all invalid variables
florian-lefebvre 5f12f8d
feat: refactor for clarity and prepare server/public
florian-lefebvre e519f82
feat: use more vite hooks
florian-lefebvre 0c1f180
feat: add support for server/public variables
florian-lefebvre fccfc35
Merge branch 'feat/astro-env' into feat/astro-env-server-public
florian-lefebvre File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/astro-env-server-fail/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineConfig, envField } from 'astro/config'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
experimental: { | ||
env: { | ||
schema: { | ||
PUBLIC_FOO: envField.string({ context: "server", access: "public", optional: true, default: "ABC" }), | ||
} | ||
} | ||
} | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/astro-env-server-fail/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/astro-env-server-fail", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/astro-env-server-fail/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<script> | ||
import { PUBLIC_FOO } from "astro:env/server" | ||
</script> |
3 changes: 3 additions & 0 deletions
3
packages/astro/test/fixtures/astro-env-server-fail/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "astro/tsconfigs/base" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import assert from 'node:assert/strict'; | ||
import { before, describe, it } from 'node:test'; | ||
import { loadFixture } from '../../test-utils.js'; | ||
import { EnvServerOnlyModule } from '../../../dist/core/errors/errors-data.js'; | ||
import { AstroError } from '../../../dist/core/errors/errors.js'; | ||
|
||
describe('astro:env public variables', () => { | ||
/** @type {Awaited<ReturnType<typeof loadFixture>>} */ | ||
let fixture; | ||
|
||
describe('Client variables', () => { | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/astro-env/', | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('builds without throwing', async () => { | ||
assert.equal(true, true); | ||
}); | ||
|
||
it('includes client/public env in build', async () => { | ||
let indexHtml = await fixture.readFile('/index.html'); | ||
|
||
assert.equal(indexHtml.includes('ABC'), true); | ||
assert.equal(indexHtml.includes('DEF'), true); | ||
}); | ||
|
||
it('does not include server/public env in build', async () => { | ||
let indexHtml = await fixture.readFile('/index.html'); | ||
|
||
assert.equal(indexHtml.includes('GHI'), false); | ||
}); | ||
}); | ||
|
||
describe('Server variables', () => { | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/astro-env-server-fail/', | ||
}); | ||
}); | ||
|
||
it('throws if server module is called on the client', async () => { | ||
const error = await fixture.build().catch(err => err); | ||
assert.equal(error instanceof AstroError, true) | ||
assert.equal(error.name, EnvServerOnlyModule.name); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thoughts for myself: I know we have a few virtual modules that currently only meant to work in the server-side only. Maybe we can consider making this more generic later. We don't have to change this now.