-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Export experimental JS API #7979
Merged
+139
−29
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
435a454
Export JS API
bluwy b9836e1
Merge branch 'next' into export-js-api
bluwy 8f6fbdd
Fix check
bluwy b302430
Mark experimental
bluwy 57f130d
Merge branch 'next' into export-js-api
bluwy 3cde589
Improve changeset
bluwy 0035e62
Apply suggestions from code review
bluwy 6f72e24
Merge branch 'next' into export-js-api
bluwy f7c3280
Update logging jsdoc
bluwy 969f3ba
Apply suggestions from code review
bluwy 72d4c65
Merge branch 'next' into export-js-api
bluwy a78df6a
Merge branch 'next' into export-js-api
bluwy 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,35 @@ | ||
--- | ||
'astro': major | ||
--- | ||
|
||
Export experimental `dev`, `build`, `preview`, and `sync` APIs from `astro`. These APIs allow you to run Astro's commands programmatically, and replaces the previous entrypoint that runs the Astro CLI. | ||
bluwy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
While these APIs are experimental, the inline config parameter is relatively stable without foreseeable changes. However, the returned results of these APIs are more likely to change in the future. | ||
|
||
```ts | ||
import { dev, build, preview, sync, type AstroInlineConfig } from 'astro'; | ||
|
||
// Inline Astro config object. | ||
// Provide a path to a configuration file to load or set options directly inline. | ||
const inlineConfig: AstroInlineConfig = { | ||
// Inline-specific options... | ||
configFile: './astro.config.mjs', | ||
logLevel: 'info', | ||
// Standard Astro config options... | ||
site: 'https://example.com', | ||
}; | ||
|
||
// Start the Astro dev server | ||
const devServer = await dev(inlineConfig); | ||
await devServer.stop(); | ||
|
||
// Build your Astro project | ||
await build(inlineConfig); | ||
|
||
// Preview your built project | ||
const previewServer = await preview(inlineConfig); | ||
await previewServer.stop(); | ||
|
||
// Generate types for your Astro project | ||
await sync(inlineConfig); | ||
``` |
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,2 @@ | ||
export type * from './dist/@types/astro.js'; | ||
export * from './dist/core/index.js'; |
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
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,26 @@ | ||
// This is the main entrypoint when importing the `astro` package. | ||
|
||
import type { AstroInlineConfig } from '../@types/astro.js'; | ||
import { default as _build } from './build/index.js'; | ||
import { default as _sync } from './sync/index.js'; | ||
|
||
export { default as dev } from './dev/index.js'; | ||
export { default as preview } from './preview/index.js'; | ||
|
||
/** | ||
* Builds your site for deployment. By default, this will generate static files and place them in a dist/ directory. | ||
* If SSR is enabled, this will generate the necessary server files to serve your site. | ||
* | ||
* @experimental The JavaScript API is experimental | ||
*/ | ||
// Wrap `_build` to prevent exposing the second internal options parameter | ||
export const build = (inlineConfig: AstroInlineConfig) => _build(inlineConfig); | ||
|
||
/** | ||
* Generates TypeScript types for all Astro modules. This sets up a `src/env.d.ts` file for type inferencing, | ||
* and defines the `astro:content` module for the Content Collections API. | ||
* | ||
* @experimental The JavaScript API is experimental | ||
*/ | ||
// Wrap `_sync` to prevent exposing the second internal options parameter | ||
export const sync = (inlineConfig: AstroInlineConfig) => _sync(inlineConfig); |
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
2 changes: 1 addition & 1 deletion
2
packages/astro/test/units/dev/collections-mixed-content-errors.test.js
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
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.
Just pointing out that I see the word "experimental" here and that typically means "behind an experimental flag" for us. If that's the case, then we should show the flag to enable and should include them in config-reference as an experimental entry.
If it's closer to something like "new" or "use at your own risk" or "good luck!", we might want to consider a different word or phrase that is closer to that meaning.
When it comes time for docs, we do have a CLI page in reference, and we could consider including this on that page. The page starts out pretty user-friendly, but then could progress into something like this.
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.
The APIs are directly imported so I don't think we can have a flag for it. It's closer to "use at your own risk" though, and I'm not exactly sure what's the alternative to "experimental", maybe "work-in-progress" or "unstable"? 🤔
That sounds great. Since these APIs are experimental, and it's signature will likely change, do you think it's worth introducing a full section for these APIs as a start? Or I was thinking we can lightly touch on the JS API names for each CLI commands:
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.
Our usual approach with experimental things is to give them an isolated page or section — makes it easier to avoid lots of repetition saying each time something is mentioned is experimental, makes it easier to update the docs as experimental features change, plus avoids drawing too much attention to a feature we’re still stabilising.
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've made a first draft of the API under the CLI commands page as a section at withastro/docs#4234
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 think that's a good place to start this, and keep it self-contained on that page as an Advanced section! Let's run with that idea for now.