astro 1.0.0-beta.6 → 1.0.0-beta.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +28 -88
  3. package/astro-jsx.d.ts +4 -1
  4. package/components/Code.astro +1 -1
  5. package/components/Markdown.astro +7 -0
  6. package/components/Shiki.js +24 -0
  7. package/dist/cli/check.js +2 -2
  8. package/dist/cli/index.js +81 -75
  9. package/dist/cli/telemetry.js +38 -0
  10. package/dist/core/add/babel.js +2 -2
  11. package/dist/core/add/index.js +62 -53
  12. package/dist/core/app/common.js +8 -23
  13. package/dist/core/app/index.js +27 -23
  14. package/dist/core/app/node.js +1 -1
  15. package/dist/core/build/add-rollup-input.js +14 -27
  16. package/dist/core/build/generate.js +24 -22
  17. package/dist/core/build/graph.js +27 -0
  18. package/dist/core/build/index.js +12 -29
  19. package/dist/core/build/internal.js +35 -4
  20. package/dist/core/build/page-data.js +23 -54
  21. package/dist/core/build/static-build.js +62 -67
  22. package/dist/{@types/serialize-javascript.d.js → core/build/types.js} +0 -0
  23. package/dist/core/build/vite-plugin-analyzer.js +93 -0
  24. package/dist/core/build/vite-plugin-hoisted-scripts.js +31 -7
  25. package/dist/core/build/vite-plugin-pages.js +7 -10
  26. package/dist/core/build/vite-plugin-ssr.js +52 -20
  27. package/dist/core/config.js +142 -65
  28. package/dist/core/create-vite.js +44 -14
  29. package/dist/core/dev/index.js +22 -5
  30. package/dist/core/endpoint/dev/index.js +3 -21
  31. package/dist/core/endpoint/index.js +1 -20
  32. package/dist/core/errors.js +38 -0
  33. package/dist/core/logger/console.js +2 -2
  34. package/dist/core/logger/core.js +2 -13
  35. package/dist/core/logger/node.js +4 -4
  36. package/dist/core/messages.js +94 -45
  37. package/dist/core/path.js +14 -10
  38. package/dist/core/preview/index.js +3 -3
  39. package/dist/core/render/core.js +11 -40
  40. package/dist/core/render/dev/css.js +22 -6
  41. package/dist/core/render/dev/index.js +40 -97
  42. package/dist/core/render/dev/resolve.js +11 -0
  43. package/dist/core/render/paginate.js +11 -27
  44. package/dist/core/render/result.js +41 -52
  45. package/dist/core/render/route-cache.js +5 -11
  46. package/dist/core/render/ssr-element.js +18 -1
  47. package/dist/core/render/util.js +39 -2
  48. package/dist/core/request.js +3 -21
  49. package/dist/core/routing/index.js +1 -1
  50. package/dist/core/routing/manifest/create.js +72 -27
  51. package/dist/core/routing/manifest/generator.js +15 -0
  52. package/dist/core/routing/manifest/serialization.js +16 -16
  53. package/dist/core/routing/params.js +12 -1
  54. package/dist/core/routing/validation.js +7 -0
  55. package/dist/core/util.js +32 -2
  56. package/dist/events/error.js +42 -0
  57. package/dist/events/index.js +21 -0
  58. package/dist/events/session.js +66 -0
  59. package/dist/integrations/index.js +55 -29
  60. package/dist/jsx/babel.js +122 -0
  61. package/dist/jsx/renderer.js +21 -0
  62. package/dist/jsx/server.js +40 -0
  63. package/dist/jsx-runtime/index.js +84 -0
  64. package/dist/runtime/client/events.js +21 -0
  65. package/dist/runtime/client/hmr.js +94 -6
  66. package/dist/{@types/shorthash.d.js → runtime/client/hydration-directives.d.js} +0 -0
  67. package/dist/runtime/client/idle.js +3 -23
  68. package/dist/runtime/client/idle.prebuilt.js +4 -0
  69. package/dist/runtime/client/load.js +5 -23
  70. package/dist/runtime/client/load.prebuilt.js +4 -0
  71. package/dist/runtime/client/media.js +3 -23
  72. package/dist/runtime/client/media.prebuilt.js +4 -0
  73. package/dist/runtime/client/only.js +5 -23
  74. package/dist/runtime/client/only.prebuilt.js +4 -0
  75. package/dist/runtime/client/visible.js +7 -29
  76. package/dist/runtime/client/visible.prebuilt.js +4 -0
  77. package/dist/runtime/server/astro-island.js +73 -0
  78. package/dist/runtime/server/astro-island.prebuilt.js +4 -0
  79. package/dist/runtime/server/hydration.js +29 -22
  80. package/dist/runtime/server/index.js +255 -125
  81. package/dist/runtime/server/jsx.js +86 -0
  82. package/dist/runtime/server/metadata.js +9 -38
  83. package/dist/runtime/server/response.js +69 -0
  84. package/dist/runtime/server/scripts.js +55 -0
  85. package/dist/runtime/server/serialize.js +57 -0
  86. package/dist/runtime/server/shorthash.js +62 -0
  87. package/dist/runtime/server/util.js +0 -4
  88. package/dist/template/5xx.js +2 -2
  89. package/dist/types/@types/astro.d.ts +129 -113
  90. package/dist/types/cli/index.d.ts +1 -1
  91. package/dist/types/cli/telemetry.d.ts +7 -0
  92. package/dist/types/core/add/babel.d.ts +1 -1
  93. package/dist/types/core/add/index.d.ts +3 -1
  94. package/dist/types/core/app/common.d.ts +1 -1
  95. package/dist/types/core/app/index.d.ts +2 -0
  96. package/dist/types/core/app/node.d.ts +1 -1
  97. package/dist/types/core/app/types.d.ts +14 -6
  98. package/dist/types/core/build/graph.d.ts +7 -0
  99. package/dist/types/core/build/index.d.ts +3 -1
  100. package/dist/types/core/build/internal.d.ts +22 -10
  101. package/dist/types/core/build/page-data.d.ts +2 -2
  102. package/dist/types/core/build/types.d.ts +34 -0
  103. package/dist/types/core/build/vite-plugin-analyzer.d.ts +4 -0
  104. package/dist/types/core/build/vite-plugin-hoisted-scripts.d.ts +1 -1
  105. package/dist/types/core/build/vite-plugin-pages.d.ts +0 -2
  106. package/dist/types/core/build/vite-plugin-ssr.d.ts +2 -1
  107. package/dist/types/core/config.d.ts +85 -44
  108. package/dist/types/core/dev/index.d.ts +5 -1
  109. package/dist/types/core/errors.d.ts +8 -0
  110. package/dist/types/core/messages.d.ts +11 -8
  111. package/dist/types/core/path.d.ts +4 -3
  112. package/dist/types/core/preview/index.d.ts +2 -0
  113. package/dist/types/core/render/core.d.ts +5 -10
  114. package/dist/types/core/render/dev/css.d.ts +5 -1
  115. package/dist/types/core/render/dev/index.d.ts +6 -13
  116. package/dist/types/core/render/dev/resolve.d.ts +1 -0
  117. package/dist/types/core/render/result.d.ts +5 -3
  118. package/dist/types/core/render/route-cache.d.ts +1 -2
  119. package/dist/types/core/render/ssr-element.d.ts +8 -0
  120. package/dist/types/core/render/util.d.ts +4 -1
  121. package/dist/types/core/routing/index.d.ts +1 -1
  122. package/dist/types/core/routing/manifest/generator.d.ts +2 -0
  123. package/dist/types/core/routing/manifest/serialization.d.ts +2 -2
  124. package/dist/types/core/routing/params.d.ts +6 -0
  125. package/dist/types/core/routing/validation.d.ts +2 -0
  126. package/dist/types/core/util.d.ts +2 -0
  127. package/dist/types/events/error.d.ts +30 -0
  128. package/dist/types/events/index.d.ts +4 -0
  129. package/dist/types/events/session.d.ts +26 -0
  130. package/dist/types/integrations/index.d.ts +8 -1
  131. package/dist/types/jsx/babel.d.ts +2 -0
  132. package/dist/types/jsx/renderer.d.ts +9 -0
  133. package/dist/types/jsx/server.d.ts +13 -0
  134. package/dist/types/jsx-runtime/index.d.ts +11 -0
  135. package/dist/types/runtime/client/events.d.ts +1 -0
  136. package/dist/types/runtime/client/idle.d.ts +0 -6
  137. package/dist/types/runtime/client/idle.prebuilt.d.ts +7 -0
  138. package/dist/types/runtime/client/load.d.ts +0 -5
  139. package/dist/types/runtime/client/load.prebuilt.d.ts +7 -0
  140. package/dist/types/runtime/client/media.d.ts +0 -5
  141. package/dist/types/runtime/client/media.prebuilt.d.ts +7 -0
  142. package/dist/types/runtime/client/only.d.ts +0 -5
  143. package/dist/types/runtime/client/only.prebuilt.d.ts +7 -0
  144. package/dist/types/runtime/client/visible.d.ts +0 -7
  145. package/dist/types/runtime/client/visible.prebuilt.d.ts +7 -0
  146. package/dist/types/runtime/server/astro-island.d.ts +4 -0
  147. package/dist/types/runtime/server/astro-island.prebuilt.d.ts +7 -0
  148. package/dist/types/runtime/server/hydration.d.ts +2 -3
  149. package/dist/types/runtime/server/index.d.ts +14 -14
  150. package/dist/types/runtime/server/jsx.d.ts +1 -0
  151. package/dist/types/runtime/server/metadata.d.ts +0 -10
  152. package/dist/types/runtime/server/response.d.ts +3 -0
  153. package/dist/types/runtime/server/scripts.d.ts +6 -0
  154. package/dist/types/runtime/server/serialize.d.ts +1 -0
  155. package/dist/types/runtime/server/shorthash.d.ts +31 -0
  156. package/dist/types/runtime/server/util.d.ts +0 -6
  157. package/dist/types/vite-plugin-astro/compile.d.ts +12 -4
  158. package/dist/types/vite-plugin-astro/hmr.d.ts +2 -2
  159. package/dist/types/vite-plugin-astro/query.d.ts +3 -2
  160. package/dist/types/vite-plugin-astro/styles.d.ts +3 -1
  161. package/dist/types/vite-plugin-astro/types.d.ts +8 -0
  162. package/dist/types/vite-plugin-build-css/index.d.ts +2 -5
  163. package/dist/types/vite-plugin-build-css/resolve.d.ts +2 -2
  164. package/dist/types/vite-plugin-utils/index.d.ts +5 -0
  165. package/dist/vite-plugin-astro/compile.js +29 -12
  166. package/dist/vite-plugin-astro/hmr.js +20 -15
  167. package/dist/vite-plugin-astro/index.js +95 -41
  168. package/dist/vite-plugin-astro/styles.js +4 -3
  169. package/dist/{core/build/types.d.js → vite-plugin-astro/types.js} +0 -0
  170. package/dist/vite-plugin-astro-server/index.js +69 -29
  171. package/dist/vite-plugin-build-css/index.js +100 -177
  172. package/dist/vite-plugin-config-alias/index.js +6 -21
  173. package/dist/vite-plugin-env/index.js +9 -3
  174. package/dist/vite-plugin-jsx/index.js +15 -8
  175. package/dist/vite-plugin-markdown/index.js +77 -65
  176. package/dist/vite-plugin-utils/index.js +13 -0
  177. package/env.d.ts +15 -0
  178. package/package.json +46 -44
  179. package/dist/core/add/consts.js +0 -36
  180. package/dist/core/render/dev/html.js +0 -90
  181. package/dist/core/render/pretty-feed.js +0 -103
  182. package/dist/core/render/rss.js +0 -119
  183. package/dist/types/core/add/consts.d.ts +0 -11
  184. package/dist/types/core/render/dev/html.d.ts +0 -7
  185. package/dist/types/core/render/pretty-feed.d.ts +0 -2
  186. package/dist/types/core/render/rss.d.ts +0 -14
  187. package/dist/types/vite-plugin-build-html/add-rollup-input.d.ts +0 -2
  188. package/dist/types/vite-plugin-build-html/extract-assets.d.ts +0 -20
  189. package/dist/types/vite-plugin-build-html/index.d.ts +0 -18
  190. package/dist/types/vite-plugin-build-html/util.d.ts +0 -7
  191. package/dist/vite-plugin-build-html/add-rollup-input.js +0 -50
  192. package/dist/vite-plugin-build-html/extract-assets.js +0 -202
  193. package/dist/vite-plugin-build-html/index.js +0 -427
  194. package/dist/vite-plugin-build-html/util.js +0 -44
package/LICENSE CHANGED
@@ -32,3 +32,30 @@ The above copyright notice and this permission notice shall be included in all c
32
32
 
33
33
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
34
  """
35
+
36
+
37
+ """
38
+ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
39
+
40
+ MIT License
41
+
42
+ Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining a copy
45
+ of this software and associated documentation files (the "Software"), to deal
46
+ in the Software without restriction, including without limitation the rights
47
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48
+ copies of the Software, and to permit persons to whom the Software is
49
+ furnished to do so, subject to the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be included in all
52
+ copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60
+ SOFTWARE.
61
+ """
package/README.md CHANGED
@@ -1,106 +1,46 @@
1
- <a href="https://astro.build">
2
- <img src="https://raw.githubusercontent.com/withastro/astro/main/assets/social/banner.svg" />
3
- </a>
1
+ <br/>
2
+ <p align="center">
3
+ <img src="../../assets/social/banner-minimal.png" alt="Astro logo">
4
+ <br/><br/>
5
+ <a href="https://astro.build">Astro</a> is a website build tool for the modern web &mdash;
6
+ <br/>
7
+ powerful developer experience meets lightweight output.
8
+ <br/><br/>
9
+ </p>
4
10
 
5
- <div center>
6
11
 
7
- **Astro** is a new kind of static site builder for the modern web&mdash;powerful developer experience meets lightweight output.
12
+ ## Install
8
13
 
9
- </div>
10
14
 
11
- ### [🚀 Read the launch post →](https://astro.build/blog/introducing-astro)
15
+ ```bash
16
+ # Recommended!
17
+ npm create astro@latest
12
18
 
13
- ### [📚 Learn Astro →](https://docs.astro.build/en/getting-started/)
19
+ # Manual:
20
+ npm install --save-dev astro
21
+ ```
14
22
 
15
- ## Project Status
23
+ Looking for help? Start with our [Getting Started](https://docs.astro.build/en/getting-started/) guide.
16
24
 
17
- ⚠️ **Astro is still beta software&mdash;missing features and bugs are to be expected!** We are quickly working our way towards a stable, production-ready v1.0 release, but we are still finalizing some of Astro's APIs.
25
+ Looking for quick examples? [Open a starter project](https://astro.new/) right in your browser.
18
26
 
19
- That being said, there are quite a few Astro sites in production already. We're incredibly grateful to everyone who has made an early bet on Astro!
27
+ ## Documentation
20
28
 
21
- ## Quick Start
29
+ Visit our [offical documentation](https://docs.astro.build/).
22
30
 
23
- <table>
24
- <tbody>
25
- <tr>
26
- <td>
27
- <img width="441" height="1px">
28
- <strong>👾 Online</strong>
29
- </td>
30
- <td>
31
- <img width="441" height="1px">
32
- <strong>📦 Local</strong>
33
- </td>
34
- </tr>
35
- <tr>
36
- <td>
31
+ ## Support
37
32
 
38
- Try Astro in your browser!
33
+ Having trouble? Get help in the official [Astro Discord](https://astro.build/chat).
34
+ ## Contributing
39
35
 
40
- [Launch astro.new →](https://astro.new)
36
+ **New contributors welcome!** Check out our [Contributors Guide](CONTRIBUTING.md) for help getting started.
41
37
 
42
- </td>
43
- <td>
38
+ Join us on [Discord](https://astro.build/chat) to meet other maintainers. We'll help you get your first contribution in no time!
44
39
 
45
- Get started with Astro using our interactive CLI!
40
+ ## Sponsors
46
41
 
47
- ```bash
48
- npm init astro my-astro-project
49
- ```
42
+ Astro is generously supported by [Netlify](https://www.netlify.com/), [Vercel](https://vercel.com/), and several other amazing organizations [listed here.](https://astro.build/)
50
43
 
51
- </td>
52
- </tr>
53
- </tbody>
54
- </table>
44
+ [❤️ Sponsor Astro! ❤️](https://github.com/withastro/astro/blob/main/FUNDING.md)
55
45
 
56
- ## Sponsors
57
46
 
58
- You can sponsor Astro's development on [Open Collective](https://opencollective.com/astrodotbuild). Astro is generously supported by the following companies and individuals:
59
-
60
- ### Platinum Sponsors
61
-
62
- <table>
63
- <tbody>
64
- <tr>
65
- <td align="center"><a href="https://www.netlify.com/#gh-light-mode-only" target="_blank"><img width="147" height="40" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/netlify.svg#gh-light-mode-only" alt="Netlify" /></a><a href="https://www.netlify.com/#gh-dark-mode-only" target="_blank"><img width="147" height="40" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/netlify-dark.svg#gh-dark-mode-only" alt="Netlify" />
66
- </a></td>
67
- <td align="center"><a href="https://www.vercel.com/#gh-light-mode-only" target="_blank"><img width="150" height="34" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/vercel.svg#gh-light-mode-only" alt="Vercel" /></a><a href="https://www.vercel.com/#gh-dark-mode-only"><img width="150" height="34" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/vercel-dark.svg#gh-dark-mode-only" alt="Vercel" />
68
- </a></td>
69
- </tr>
70
- </tbody>
71
- </table>
72
-
73
- ### Gold Sponsors
74
-
75
- <table>
76
- <tbody>
77
- <tr>
78
- <td align="center">
79
- <a href="https://divRIOTS.com#gh-light-mode-only" target="_blank">
80
- <img width="150" height="40" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/divriots.svg#gh-light-mode-only" alt="‹div›RIOTS" />
81
- </a>
82
- <a href="https://divRIOTS.com#gh-dark-mode-only" target="_blank">
83
- <img width="150" height="40" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/divriots-dark.svg#gh-dark-mode-only" alt="‹div›RIOTS" />
84
- </a>
85
- </td>
86
- <td align="center">
87
- <a href="https://stackupdigital.co.uk/#gh-light-mode-only" target="_blank">
88
- <img width="162" height="40" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/stackup.svg#gh-light-mode-only" alt="StackUp Digital" />
89
- </a>
90
- <a href="https://stackupdigital.co.uk/#gh-dark-mode-only" target="_blank">
91
- <img width="130" height="32" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/stackup-dark.svg#gh-dark-mode-only" alt="StackUp Digital" />
92
- </a>
93
- </td>
94
- </tr>
95
- </tbody>
96
- </table>
97
-
98
- ### Sponsors
99
-
100
- <table>
101
- <tbody>
102
- <tr>
103
- <td align="center"><a href="https://sentry.io" target="_blank"><img width="147" height="40" src="https://raw.githubusercontent.com/withastro/astro/main/.github/assets/sentry.svg" alt="Sentry" /></a></td><td align="center"><a href="https://qoddi.com" target="_blank"><img width="147" height="40" src="https://devcenter.qoddi.com/wp-content/uploads/2021/11/blog-transparent-logo-1.png" alt="Qoddi App Platform" /></a></td>
104
- </tr>
105
- </tbody>
106
- </table>
package/astro-jsx.d.ts CHANGED
@@ -621,7 +621,10 @@ declare namespace astroHTML.JSX {
621
621
  // - "number | string"
622
622
  // - "string"
623
623
  // - union of string literals
624
- interface SVGAttributes<T extends EventTarget> extends AriaAttributes, DOMAttributes<T> {
624
+ interface SVGAttributes<T extends EventTarget>
625
+ extends AriaAttributes,
626
+ DOMAttributes<T>,
627
+ AstroBuiltinAttributes {
625
628
  // Attributes which also defined in HTMLAttributes
626
629
  className?: string | undefined | null;
627
630
  class?: string | undefined | null;
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  import type * as shiki from 'shiki';
3
- import { getHighlighter } from 'shiki';
3
+ import { getHighlighter } from './Shiki.js';
4
4
 
5
5
  export interface Props {
6
6
  /** The code to highlight. Required. */
@@ -3,6 +3,13 @@ export interface Props {
3
3
  content?: string;
4
4
  }
5
5
 
6
+ // NOTE(fks): We are most likely moving this component out of Astro core
7
+ // in a few weeks. Checking the name like this is a bit of a hack, but we
8
+ // intentionally don't want to add an SSR flag for others to read from, just yet.
9
+ if (Astro.redirect.name !== '_onlyAvailableInSSR') {
10
+ console.error(`\x1B[31mThe <Markdown> component is not available in SSR. See https://github.com/withastro/rfcs/discussions/179 for more info.\x1B[39m`);
11
+ }
12
+
6
13
  const dedent = (str: string) => {
7
14
  const _str = str.split('\n').filter(s => s.trimStart().length > 0);
8
15
  if (_str.length === 0) {
@@ -0,0 +1,24 @@
1
+ import { getHighlighter as getShikiHighlighter } from 'shiki';
2
+
3
+ // Caches Promise<Highligher> for reuse when the same theme and langs are provided
4
+ const _resolvedHighlighters = new Map();
5
+
6
+ function stringify(opts) {
7
+ // Always sort keys before stringifying to make sure objects match regardless of parameter ordering
8
+ return JSON.stringify(opts, Object.keys(opts).sort());
9
+ }
10
+
11
+ export function getHighlighter(opts) {
12
+ const key = stringify(opts);
13
+
14
+ // Highlighter has already been requested, reuse the same instance
15
+ if (_resolvedHighlighters.has(key)) {
16
+ return _resolvedHighlighters.get(key);
17
+ }
18
+
19
+ // Start the async getHighlighter call and cache the Promise
20
+ const highlighter = getShikiHighlighter(opts);
21
+ _resolvedHighlighters.set(key, highlighter);
22
+
23
+ return highlighter;
24
+ }
package/dist/cli/check.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { AstroCheck, DiagnosticSeverity } from "@astrojs/language-server";
2
- import { bold, black, bgWhite, red, cyan, yellow } from "kleur/colors";
3
2
  import glob from "fast-glob";
3
+ import * as fs from "fs";
4
+ import { bgWhite, black, bold, cyan, red, yellow } from "kleur/colors";
4
5
  import * as path from "path";
5
6
  import { pathToFileURL } from "url";
6
- import * as fs from "fs";
7
7
  async function openAllDocuments(workspaceUri, filePathsToIgnore, checker) {
8
8
  const files = await glob("**/*.astro", {
9
9
  cwd: workspaceUri.pathname,
package/dist/cli/index.js CHANGED
@@ -1,51 +1,57 @@
1
1
  import * as colors from "kleur/colors";
2
2
  import yargs from "yargs-parser";
3
3
  import { z } from "zod";
4
- import { nodeLogDestination, enableVerboseLogging } from "../core/logger/node.js";
5
- import build from "../core/build/index.js";
6
4
  import add from "../core/add/index.js";
5
+ import build from "../core/build/index.js";
6
+ import { openConfig } from "../core/config.js";
7
7
  import devServer from "../core/dev/index.js";
8
+ import { collectErrorMetadata } from "../core/errors.js";
9
+ import { debug } from "../core/logger/core.js";
10
+ import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js";
11
+ import { formatConfigErrorMessage, formatErrorMessage, printHelp } from "../core/messages.js";
8
12
  import preview from "../core/preview/index.js";
13
+ import { ASTRO_VERSION, createSafeError } from "../core/util.js";
14
+ import * as event from "../events/index.js";
15
+ import { eventConfigError, eventError, telemetry } from "../events/index.js";
9
16
  import { check } from "./check.js";
10
17
  import { openInBrowser } from "./open.js";
11
- import { loadConfig } from "../core/config.js";
12
- import { printHelp, formatErrorMessage, formatConfigErrorMessage } from "../core/messages.js";
13
- import { createSafeError } from "../core/util.js";
18
+ import * as telemetryHandler from "./telemetry.js";
14
19
  function printAstroHelp() {
15
20
  printHelp({
16
21
  commandName: "astro",
22
+ usage: "[command] [...flags]",
17
23
  headline: "Futuristic web development tool.",
18
- commands: [
19
- ["add", "Add an integration to your configuration."],
20
- ["docs", "Launch Astro's Doc site directly from the terminal. "],
21
- ["dev", "Run Astro in development mode."],
22
- ["build", "Build a pre-compiled production-ready site."],
23
- ["preview", "Preview your build locally before deploying."],
24
- ["check", "Check your project for errors."],
25
- ["--version", "Show the version number and exit."],
26
- ["--help", "Show this help message."]
27
- ],
28
- flags: [
29
- ["--host [optional IP]", "Expose server on network"],
30
- ["--config <path>", "Specify the path to the Astro config file."],
31
- ["--root <path>", "Specify the path to the project root folder."],
32
- ["--legacy-build", "Use the build strategy prior to 0.24.0"],
33
- ["--experimental-ssr", "Enable SSR compilation fot 3rd-party adapters."],
34
- ["--drafts", "Include markdown draft pages in the build."],
35
- ["--verbose", "Enable verbose logging"],
36
- ["--silent", "Disable logging"]
37
- ]
24
+ tables: {
25
+ Commands: [
26
+ ["add", "Add an integration."],
27
+ ["build", "Build your project and write it to disk."],
28
+ ["check", "Check your project for errors."],
29
+ ["dev", "Start the development server."],
30
+ ["docs", "Open documentation in your web browser."],
31
+ ["preview", "Preview your build locally."],
32
+ ["telemetry", "Configure telemetry settings."]
33
+ ],
34
+ "Global Flags": [
35
+ ["--config <path>", "Specify your config file."],
36
+ ["--root <path>", "Specify your project root folder."],
37
+ ["--verbose", "Enable verbose logging."],
38
+ ["--silent", "Disable all logging."],
39
+ ["--version", "Show the version number and exit."],
40
+ ["--help", "Show this help message."]
41
+ ]
42
+ }
38
43
  });
39
44
  }
40
45
  async function printVersion() {
41
- const version = "1.0.0-beta.5";
42
46
  console.log();
43
- console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
47
+ console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${ASTRO_VERSION}`)}`);
44
48
  }
45
49
  function resolveCommand(flags) {
46
50
  const cmd = flags._[2];
47
51
  if (cmd === "add")
48
52
  return "add";
53
+ if (cmd === "telemetry")
54
+ return "telemetry";
49
55
  if (flags.version)
50
56
  return "version";
51
57
  else if (flags.help)
@@ -56,9 +62,8 @@ function resolveCommand(flags) {
56
62
  }
57
63
  return "help";
58
64
  }
59
- async function cli(args) {
60
- const flags = yargs(args);
61
- const cmd = resolveCommand(flags);
65
+ async function runCommand(cmd, flags) {
66
+ var _a;
62
67
  const root = flags.root;
63
68
  switch (cmd) {
64
69
  case "help":
@@ -78,68 +83,69 @@ async function cli(args) {
78
83
  } else if (flags.silent) {
79
84
  logging.level = "silent";
80
85
  }
81
- let config;
82
- try {
83
- config = await loadConfig({ cwd: root, flags, cmd });
84
- } catch (err) {
85
- return throwAndExit(err);
86
- }
87
86
  switch (cmd) {
88
87
  case "add": {
89
- try {
90
- const packages = flags._.slice(3);
91
- return await add(packages, { cwd: root, flags, logging });
92
- } catch (err) {
93
- return throwAndExit(err);
94
- }
88
+ telemetry.record(event.eventCliSession(cmd));
89
+ const packages = flags._.slice(3);
90
+ return await add(packages, { cwd: root, flags, logging, telemetry });
91
+ }
92
+ case "docs": {
93
+ telemetry.record(event.eventCliSession(cmd));
94
+ return await openInBrowser("https://docs.astro.build/");
95
+ }
96
+ case "telemetry": {
97
+ const subcommand = (_a = flags._[3]) == null ? void 0 : _a.toString();
98
+ return await telemetryHandler.update(subcommand, { flags, telemetry });
95
99
  }
100
+ }
101
+ const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
102
+ telemetry.record(event.eventCliSession(cmd, userConfig, flags));
103
+ switch (cmd) {
96
104
  case "dev": {
97
- try {
98
- await devServer(config, { logging });
99
- return await new Promise(() => {
100
- });
101
- } catch (err) {
102
- return throwAndExit(err);
103
- }
105
+ await devServer(astroConfig, { logging, telemetry });
106
+ return await new Promise(() => {
107
+ });
104
108
  }
105
109
  case "build": {
106
- try {
107
- return await build(config, { logging });
108
- } catch (err) {
109
- return throwAndExit(err);
110
- }
110
+ return await build(astroConfig, { logging, telemetry });
111
111
  }
112
112
  case "check": {
113
- const ret = await check(config);
113
+ const ret = await check(astroConfig);
114
114
  return process.exit(ret);
115
115
  }
116
116
  case "preview": {
117
- try {
118
- const server = await preview(config, { logging });
119
- return await server.closed();
120
- } catch (err) {
121
- return throwAndExit(err);
122
- }
123
- }
124
- case "docs": {
125
- try {
126
- return await openInBrowser("https://docs.astro.build/");
127
- } catch (err) {
128
- return throwAndExit(err);
129
- }
130
- }
131
- default: {
132
- throw new Error(`Error running ${cmd}`);
117
+ const server = await preview(astroConfig, { logging, telemetry });
118
+ return await server.closed();
133
119
  }
134
120
  }
121
+ throw new Error(`Error running ${cmd} -- no command found.`);
122
+ }
123
+ async function cli(args) {
124
+ const flags = yargs(args);
125
+ const cmd = resolveCommand(flags);
126
+ try {
127
+ await runCommand(cmd, flags);
128
+ } catch (err) {
129
+ await throwAndExit(cmd, err);
130
+ }
135
131
  }
136
- function throwAndExit(err) {
132
+ async function throwAndExit(cmd, err) {
133
+ let telemetryPromise;
134
+ let errorMessage;
135
+ function exitWithErrorMessage() {
136
+ console.error(errorMessage);
137
+ process.exit(1);
138
+ }
137
139
  if (err instanceof z.ZodError) {
138
- console.error(formatConfigErrorMessage(err));
140
+ telemetryPromise = telemetry.record(eventConfigError({ cmd, err, isFatal: true }));
141
+ errorMessage = formatConfigErrorMessage(err);
139
142
  } else {
140
- console.error(formatErrorMessage(createSafeError(err)));
143
+ const errorWithMetadata = collectErrorMetadata(createSafeError(err));
144
+ telemetryPromise = telemetry.record(eventError({ cmd, err: errorWithMetadata, isFatal: true }));
145
+ errorMessage = formatErrorMessage(errorWithMetadata);
141
146
  }
142
- process.exit(1);
147
+ setTimeout(exitWithErrorMessage, 400);
148
+ await telemetryPromise.catch((err2) => debug("telemetry", `record() error: ${err2.message}`)).then(exitWithErrorMessage);
143
149
  }
144
150
  export {
145
151
  cli
@@ -0,0 +1,38 @@
1
+ import * as msg from "../core/messages.js";
2
+ async function update(subcommand, { flags, telemetry }) {
3
+ const isValid = ["enable", "disable", "reset"].includes(subcommand);
4
+ if (flags.help || !isValid) {
5
+ msg.printHelp({
6
+ commandName: "astro telemetry",
7
+ usage: "[command]",
8
+ tables: {
9
+ Commands: [
10
+ ["enable", "Enable anonymous data collection."],
11
+ ["disable", "Disable anonymous data collection."],
12
+ ["reset", "Reset anonymous data collection settings."]
13
+ ]
14
+ }
15
+ });
16
+ return;
17
+ }
18
+ switch (subcommand) {
19
+ case "enable": {
20
+ telemetry.setEnabled(true);
21
+ console.log(msg.telemetryEnabled());
22
+ return;
23
+ }
24
+ case "disable": {
25
+ telemetry.setEnabled(false);
26
+ console.log(msg.telemetryDisabled());
27
+ return;
28
+ }
29
+ case "reset": {
30
+ telemetry.clear();
31
+ console.log(msg.telemetryReset());
32
+ return;
33
+ }
34
+ }
35
+ }
36
+ export {
37
+ update
38
+ };
@@ -1,7 +1,7 @@
1
- import traverse from "@babel/traverse";
2
1
  import generator from "@babel/generator";
3
- import * as t from "@babel/types";
4
2
  import parser from "@babel/parser";
3
+ import traverse from "@babel/traverse";
4
+ import * as t from "@babel/types";
5
5
  const visit = traverse.default;
6
6
  async function generate(ast) {
7
7
  const astToText = generator.default;
@@ -1,74 +1,83 @@
1
- import path from "path";
2
- import { existsSync, promises as fs } from "fs";
3
- import { execa } from "execa";
4
- import { fileURLToPath, pathToFileURL } from "url";
5
- import { diffWords } from "diff";
6
1
  import boxen from "boxen";
7
- import prompts from "prompts";
8
- import preferredPM from "preferred-pm";
2
+ import { diffWords } from "diff";
3
+ import { execa } from "execa";
4
+ import { existsSync, promises as fs } from "fs";
5
+ import { bold, cyan, dim, green, magenta } from "kleur/colors";
9
6
  import ora from "ora";
7
+ import path from "path";
8
+ import preferredPM from "preferred-pm";
9
+ import prompts from "prompts";
10
+ import { fileURLToPath, pathToFileURL } from "url";
10
11
  import { resolveConfigURL } from "../config.js";
11
- import { apply as applyPolyfill } from "../polyfill.js";
12
- import { error, info, debug } from "../logger/core.js";
13
- import { printHelp } from "../messages.js";
12
+ import { debug, info } from "../logger/core.js";
14
13
  import * as msg from "../messages.js";
15
- import * as CONSTS from "./consts.js";
16
- import { dim, cyan, green, magenta, bold } from "kleur/colors";
14
+ import { printHelp } from "../messages.js";
15
+ import { appendForwardSlash } from "../path.js";
16
+ import { apply as applyPolyfill } from "../polyfill.js";
17
17
  import { parseNpmName } from "../util.js";
18
- import { wrapDefaultExport } from "./wrapper.js";
18
+ import { generate, parse, t, visit } from "./babel.js";
19
19
  import { ensureImport } from "./imports.js";
20
- import { t, parse, visit, generate } from "./babel.js";
21
- async function add(names, { cwd, flags, logging }) {
22
- if (flags.help) {
20
+ import { wrapDefaultExport } from "./wrapper.js";
21
+ const ALIASES = /* @__PURE__ */ new Map([
22
+ ["solid", "solid-js"],
23
+ ["tailwindcss", "tailwind"]
24
+ ]);
25
+ const ASTRO_CONFIG_STUB = `import { defineConfig } from 'astro/config';
26
+
27
+ default defineConfig({});`;
28
+ const TAILWIND_CONFIG_STUB = `/** @type {import('tailwindcss').Config} */
29
+ module.exports = {
30
+ content: ['./src/**/*.{astro,html,js,jsx,md,svelte,ts,tsx,vue}'],
31
+ theme: {
32
+ extend: {},
33
+ },
34
+ plugins: [],
35
+ }
36
+ `;
37
+ async function add(names, { cwd, flags, logging, telemetry }) {
38
+ if (flags.help || names.length === 0) {
23
39
  printHelp({
24
40
  commandName: "astro add",
25
- usage: "[FLAGS] [INTEGRATIONS...]",
26
- flags: [
27
- ["--yes", "Add the integration without user interaction."],
28
- ["--help", "Show this help message."]
29
- ]
41
+ usage: "[...integrations]",
42
+ tables: {
43
+ Flags: [
44
+ ["--yes", "Accept all prompts."],
45
+ ["--help", "Show this help message."]
46
+ ],
47
+ "Example: Add a UI Framework": [
48
+ ["react", "astro add react"],
49
+ ["preact", "astro add preact"],
50
+ ["vue", "astro add vue"],
51
+ ["svelte", "astro add svelte"],
52
+ ["solid-js", "astro add solid-js"],
53
+ ["lit", "astro add lit"]
54
+ ],
55
+ "Example: Add an Integration": [
56
+ ["tailwind", "astro add tailwind"],
57
+ ["partytown", "astro add partytown"],
58
+ ["sitemap", "astro add sitemap"]
59
+ ]
60
+ },
61
+ description: `Check out the full integration catalog: ${cyan("https://astro.build/integrations")}`
30
62
  });
31
63
  return;
32
64
  }
33
65
  let configURL;
34
66
  const root = pathToFileURL(cwd ? path.resolve(cwd) : process.cwd());
35
67
  configURL = await resolveConfigURL({ cwd, flags });
36
- if (configURL == null ? void 0 : configURL.pathname.endsWith("package.json")) {
37
- throw new Error(`Unable to use astro add with package.json#astro configuration! Try migrating to \`astro.config.mjs\` and try again.`);
38
- }
39
68
  applyPolyfill();
40
- if (names.length === 0) {
41
- const response = await prompts([
42
- {
43
- type: "multiselect",
44
- name: "frameworks",
45
- message: "What frameworks would you like to enable?",
46
- instructions: "\n Space to select. Return to submit",
47
- choices: CONSTS.FIRST_PARTY_FRAMEWORKS
48
- },
49
- {
50
- type: "multiselect",
51
- name: "addons",
52
- message: "What additional integrations would you like to enable?",
53
- instructions: "\n Space to select. Return to submit",
54
- choices: CONSTS.FIRST_PARTY_ADDONS
55
- }
56
- ]);
57
- names = [...response.frameworks ?? [], ...response.addons ?? []];
58
- }
59
- if (names.length === 0) {
60
- error(logging, null, `No integrations specified.`);
61
- return;
62
- }
63
- names = names.map((name) => CONSTS.ALIASES.has(name) ? CONSTS.ALIASES.get(name) : name);
64
69
  if (configURL) {
65
70
  debug("add", `Found config at ${configURL}`);
66
71
  } else {
67
72
  info(logging, "add", `Unable to locate a config file, generating one for you.`);
68
- configURL = new URL("./astro.config.mjs", root);
69
- await fs.writeFile(fileURLToPath(configURL), CONSTS.CONFIG_STUB, { encoding: "utf-8" });
73
+ configURL = new URL("./astro.config.mjs", appendForwardSlash(root.href));
74
+ await fs.writeFile(fileURLToPath(configURL), ASTRO_CONFIG_STUB, { encoding: "utf-8" });
75
+ }
76
+ if (configURL == null ? void 0 : configURL.pathname.endsWith("package.json")) {
77
+ throw new Error(`Unable to use "astro add" with package.json configuration. Try migrating to \`astro.config.mjs\` and try again.`);
70
78
  }
71
- const integrations = await validateIntegrations(names);
79
+ const integrationNames = names.map((name) => ALIASES.has(name) ? ALIASES.get(name) : name);
80
+ const integrations = await validateIntegrations(integrationNames);
72
81
  let ast = null;
73
82
  try {
74
83
  ast = await parseAstroConfig(configURL);
@@ -137,7 +146,7 @@ async function add(names, { cwd, flags, logging }) {
137
146
  ${magenta(`Astro will generate a minimal ${bold("./tailwind.config.cjs")} file.`)}
138
147
  `);
139
148
  if (await askToContinue({ flags })) {
140
- await fs.writeFile(fileURLToPath(new URL("./tailwind.config.cjs", configURL)), CONSTS.TAILWIND_CONFIG_STUB, { encoding: "utf-8" });
149
+ await fs.writeFile(fileURLToPath(new URL("./tailwind.config.cjs", configURL)), TAILWIND_CONFIG_STUB, { encoding: "utf-8" });
141
150
  debug("add", `Generated default ./tailwind.config.cjs file`);
142
151
  }
143
152
  } else {
@@ -288,7 +297,7 @@ async function getInstallIntegrationsCommand({
288
297
  debug("add", `package manager: ${JSON.stringify(pm)}`);
289
298
  if (!pm)
290
299
  return null;
291
- let dependencies = integrations.map((i) => [[i.packageName, null], ...i.dependencies]).flat(1).filter((dep, i, arr) => arr.findIndex((d) => d[0] === dep[0]) === i).map(([name, version]) => version === null ? name : `${name}@${version}`).sort();
300
+ let dependencies = integrations.map((i) => [[i.packageName, null], ...i.dependencies]).flat(1).filter((dep, i, arr) => arr.findIndex((d) => d[0] === dep[0]) === i).map(([name, version]) => version === null ? name : `${name}@${version.split(/\s*\|\|\s*/).pop()}`).sort();
292
301
  switch (pm.name) {
293
302
  case "npm":
294
303
  return { pm: "npm", command: "install", flags: ["--save-dev"], dependencies };