-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow custom const x = boolean
exports to be read from plugins
#8260
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9c1c79a
Allow const boolean exports to be read from plugins
ottomated 5db9b9b
changeset
ottomated bf82d18
make it 7 times faster
ottomated 1f2058f
test
ottomated 57f10a9
install test
ottomated 063d61e
comment on test
ottomated 8846dac
add test cases
ottomated 07b6b4e
add comment to constant
ottomated 2391b63
fix regression
ottomated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Plugins can now access a page's boolean exports on RouteData['customOptions'] | ||
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
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
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,40 @@ | ||
import { expect } from 'chai'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Public', () => { | ||
let fixture; | ||
let routes; | ||
|
||
const integration = { | ||
name: 'test-custom-page-options', | ||
hooks: { | ||
['astro:build:done']: (options) => { | ||
routes = options.routes; | ||
}, | ||
}, | ||
} | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/custom-page-options/', | ||
integrations: [integration], | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('sets custom options', async () => { | ||
const page = routes.find(r => r.pathname === '/'); | ||
expect(page.customOptions).to.deep.equal({ | ||
customTrue: true, | ||
customFalse: false, | ||
whitespace: true, | ||
// customString: 'string', | ||
// customString2: 'string2', | ||
// customNumber: 123, | ||
// customNumber2: -123.456, | ||
// customHexNumber: 0xa, | ||
// customOctalNumber: 0o10, | ||
// customBinaryNumber: 0b1010, | ||
}); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/astro/test/fixtures/custom-page-options/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,4 @@ | ||
import { defineConfig } from 'astro/config'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({}); |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/custom-page-options/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/custom-page-options", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/astro/test/fixtures/custom-page-options/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,17 @@ | ||
--- | ||
export const prerender = true; | ||
|
||
export const customTrue = true; | ||
export const customFalse = false; | ||
ottomated marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export const whitespace = true | ||
export let invalid = true; | ||
|
||
// For later? | ||
export const customString = 'string'; | ||
export const customString2 = "string2"; | ||
export const customNumber = 123; | ||
export const customNumber2 = -123.456; | ||
export const customHexNumber = 0xa; | ||
export const customOctalNumber = 0o10; | ||
export const customBinaryNumber = 0b1010; | ||
--- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
I would call it
externalOptions
. It's more sound and communicates that these options don't come from Astro. OrpluginOptions
.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.
I don't think we should differentiate. If we accept this feature I think it should include all boolean options, including
prerender
.The reason is, if this field is just for non-Astro defined booleans, that would mean that if Astro adds any new booleans itself, that becomes a breaking change. However if they are all under
customOptions
then there is no breaking change.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.
@matthewp The only con to that approach is that we get a huge breaking change now that has a large impact on not only the astro codebase, but also breaks any plugins that rely on
prerender
. With the other approach, we might introduce breaking changes in the future, but any astro update that introduces a new page option will likely already be a major change.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.
Another option here is that custom options must have some prefix we define. Similar to how HTML has the
data-
attributes. If they were required to becustomFoo
, for example, we could ensure that Astro never accidentally breaks an integration defined option.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.
I like that idea but
custom
as a prefix feels a bit bulky to me