astro 2.9.7 → 3.0.0-beta.0

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 (161) hide show
  1. package/astro.js +2 -2
  2. package/components/ViewTransitions.astro +65 -12
  3. package/dist/@types/astro.d.ts +68 -7
  4. package/dist/@types/astro.js +1 -0
  5. package/dist/assets/generate.js +7 -3
  6. package/dist/assets/image-endpoint.d.ts +1 -1
  7. package/dist/assets/image-endpoint.js +3 -3
  8. package/dist/assets/internal.js +1 -2
  9. package/dist/assets/services/noop.d.ts +3 -0
  10. package/dist/assets/services/noop.js +17 -0
  11. package/dist/assets/services/vendor/squoosh/image_data.js +3 -0
  12. package/dist/assets/services/vendor/squoosh/impl.js +2 -3
  13. package/dist/assets/services/vendor/squoosh/utils/workerPool.js +4 -0
  14. package/dist/assets/vendor/image-size/types/tiff.js +1 -1
  15. package/dist/assets/vendor/queue/queue.d.ts +3 -3
  16. package/dist/assets/vite-plugin-assets.d.ts +1 -1
  17. package/dist/assets/vite-plugin-assets.js +1 -23
  18. package/dist/cli/add/index.js +6 -9
  19. package/dist/cli/build/index.js +1 -1
  20. package/dist/cli/check/index.d.ts +2 -78
  21. package/dist/cli/check/index.js +23 -275
  22. package/dist/cli/dev/index.js +1 -1
  23. package/dist/cli/index.js +7 -13
  24. package/dist/cli/info/index.js +3 -4
  25. package/dist/cli/install-package.d.ts +7 -0
  26. package/dist/cli/install-package.js +102 -0
  27. package/dist/cli/preview/index.js +1 -1
  28. package/dist/cli/sync/index.js +1 -1
  29. package/dist/content/runtime-assets.js +1 -2
  30. package/dist/content/runtime.js +3 -5
  31. package/dist/content/server-listeners.js +1 -2
  32. package/dist/content/types-generator.js +8 -8
  33. package/dist/content/utils.js +3 -4
  34. package/dist/content/vite-plugin-content-assets.js +4 -6
  35. package/dist/content/vite-plugin-content-imports.js +1 -1
  36. package/dist/content/vite-plugin-content-virtual-mod.js +5 -6
  37. package/dist/core/app/index.js +5 -3
  38. package/dist/core/app/node.d.ts +1 -1
  39. package/dist/core/app/node.js +7 -2
  40. package/dist/core/build/css-asset-name.js +2 -4
  41. package/dist/core/build/generate.js +10 -17
  42. package/dist/core/build/graph.js +3 -4
  43. package/dist/core/build/index.js +8 -1
  44. package/dist/core/build/internal.js +2 -2
  45. package/dist/core/build/plugin.js +2 -4
  46. package/dist/core/build/plugins/plugin-analyzer.js +6 -9
  47. package/dist/core/build/plugins/plugin-component-entry.js +2 -4
  48. package/dist/core/build/plugins/plugin-css.js +6 -9
  49. package/dist/core/build/plugins/plugin-hoisted-scripts.js +2 -3
  50. package/dist/core/build/plugins/plugin-internals.js +1 -2
  51. package/dist/core/build/plugins/plugin-pages.js +5 -1
  52. package/dist/core/build/plugins/plugin-ssr.js +12 -8
  53. package/dist/core/build/static-build.js +8 -12
  54. package/dist/core/client-directive/build.js +1 -2
  55. package/dist/core/compile/compile.js +2 -1
  56. package/dist/core/compile/style.js +2 -3
  57. package/dist/core/config/schema.d.ts +8 -0
  58. package/dist/core/config/schema.js +11 -3
  59. package/dist/core/config/settings.js +3 -3
  60. package/dist/core/config/timer.js +5 -6
  61. package/dist/core/constants.js +1 -1
  62. package/dist/core/cookies/cookies.d.ts +5 -5
  63. package/dist/core/cookies/cookies.js +9 -9
  64. package/dist/core/create-vite.js +6 -28
  65. package/dist/core/dev/container.d.ts +0 -1
  66. package/dist/core/dev/container.js +0 -5
  67. package/dist/core/dev/dev.js +2 -3
  68. package/dist/core/dev/index.d.ts +1 -1
  69. package/dist/core/dev/index.js +1 -2
  70. package/dist/core/dev/restart.d.ts +1 -4
  71. package/dist/core/dev/restart.js +15 -19
  72. package/dist/core/endpoint/dev/index.js +1 -1
  73. package/dist/core/endpoint/index.js +3 -4
  74. package/dist/core/errors/dev/utils.js +12 -16
  75. package/dist/core/errors/dev/vite.js +11 -13
  76. package/dist/core/errors/errors-data.d.ts +21 -0
  77. package/dist/core/errors/errors-data.js +21 -0
  78. package/dist/core/errors/errors.js +12 -17
  79. package/dist/core/errors/overlay.js +7 -8
  80. package/dist/core/errors/utils.js +1 -1
  81. package/dist/core/fs/index.js +1 -1
  82. package/dist/core/logger/console.js +1 -1
  83. package/dist/core/logger/core.d.ts +26 -6
  84. package/dist/core/logger/core.js +54 -8
  85. package/dist/core/logger/node.d.ts +4 -4
  86. package/dist/core/logger/node.js +6 -6
  87. package/dist/core/messages.js +4 -5
  88. package/dist/core/module-loader/vite.js +2 -2
  89. package/dist/core/polyfill.js +12 -4
  90. package/dist/core/redirects/helpers.js +3 -3
  91. package/dist/core/render/core.js +1 -4
  92. package/dist/core/render/params-and-props.js +2 -3
  93. package/dist/core/render/result.js +1 -2
  94. package/dist/core/render/route-cache.d.ts +1 -2
  95. package/dist/core/render/route-cache.js +6 -11
  96. package/dist/core/routing/manifest/create.js +2 -6
  97. package/dist/core/routing/params.js +1 -1
  98. package/dist/core/routing/validation.js +7 -8
  99. package/dist/core/sync/index.js +1 -1
  100. package/dist/core/util.js +1 -1
  101. package/dist/events/error.js +1 -1
  102. package/dist/events/session.js +12 -13
  103. package/dist/integrations/astroFeaturesValidation.d.ts +14 -0
  104. package/dist/integrations/astroFeaturesValidation.js +109 -0
  105. package/dist/integrations/index.d.ts +3 -1
  106. package/dist/integrations/index.js +96 -31
  107. package/dist/jsx/babel.js +1 -2
  108. package/dist/prerender/metadata.js +1 -2
  109. package/dist/runtime/client/hmr.js +1 -2
  110. package/dist/runtime/server/astro-component.js +1 -2
  111. package/dist/runtime/server/astro-island.js +53 -55
  112. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  113. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  114. package/dist/runtime/server/endpoint.d.ts +2 -1
  115. package/dist/runtime/server/endpoint.js +21 -27
  116. package/dist/runtime/server/hydration.js +9 -0
  117. package/dist/runtime/server/jsx.js +3 -2
  118. package/dist/runtime/server/render/astro/instance.js +6 -3
  119. package/dist/runtime/server/render/astro/render-template.js +4 -3
  120. package/dist/runtime/server/render/astro/render.js +3 -3
  121. package/dist/runtime/server/render/common.js +1 -1
  122. package/dist/runtime/server/render/component.js +11 -13
  123. package/dist/runtime/server/render/dom.js +1 -1
  124. package/dist/runtime/server/render/page.js +2 -3
  125. package/dist/runtime/server/render/slot.js +2 -1
  126. package/dist/runtime/server/render/util.js +1 -2
  127. package/dist/runtime/server/transition.d.ts +1 -0
  128. package/dist/runtime/server/transition.js +1 -0
  129. package/dist/transitions/vite-plugin-transitions.js +1 -0
  130. package/dist/vite-plugin-astro/compile.js +2 -3
  131. package/dist/vite-plugin-astro/hmr.js +3 -5
  132. package/dist/vite-plugin-astro/index.js +1 -1
  133. package/dist/vite-plugin-astro/metadata.js +1 -2
  134. package/dist/vite-plugin-astro-postprocess/index.js +1 -1
  135. package/dist/vite-plugin-astro-server/base.js +1 -2
  136. package/dist/vite-plugin-astro-server/controller.js +2 -3
  137. package/dist/vite-plugin-astro-server/css.js +1 -1
  138. package/dist/vite-plugin-astro-server/request.js +1 -1
  139. package/dist/vite-plugin-astro-server/route.js +1 -2
  140. package/dist/vite-plugin-astro-server/scripts.js +2 -3
  141. package/dist/vite-plugin-astro-server/vite.js +1 -1
  142. package/dist/vite-plugin-config-alias/index.js +1 -1
  143. package/dist/vite-plugin-env/index.js +2 -2
  144. package/dist/vite-plugin-head/index.js +4 -6
  145. package/dist/vite-plugin-html/index.js +1 -2
  146. package/dist/vite-plugin-html/transform/index.js +1 -1
  147. package/dist/vite-plugin-html/transform/slots.js +5 -6
  148. package/dist/vite-plugin-html/transform/utils.js +1 -2
  149. package/dist/vite-plugin-jsx/import-source.js +1 -2
  150. package/dist/vite-plugin-jsx/index.js +1 -1
  151. package/dist/vite-plugin-jsx/tag.js +4 -6
  152. package/dist/vite-plugin-markdown/index.js +1 -2
  153. package/dist/vite-plugin-scanner/index.js +2 -1
  154. package/dist/vite-plugin-scanner/scan.js +1 -1
  155. package/dist/vite-plugin-scripts/index.js +1 -1
  156. package/dist/vite-plugin-scripts/page-ssr.js +2 -2
  157. package/package.json +13 -22
  158. package/tsconfigs/base.json +8 -6
  159. package/tsconfigs/strict.json +2 -3
  160. package/dist/cli/check/print.d.ts +0 -2
  161. package/dist/cli/check/print.js +0 -95
package/astro.js CHANGED
@@ -13,8 +13,8 @@ const CI_INSTRUCTIONS = {
13
13
  };
14
14
 
15
15
  // Hardcode supported Node.js version so we don't have to read differently in CJS & ESM.
16
- const engines = '>=16.12.0';
17
- const skipSemverCheckIfAbove = 16;
16
+ const engines = '>=18.14.1';
17
+ const skipSemverCheckIfAbove = 19;
18
18
 
19
19
  /** `astro *` */
20
20
  async function main() {
@@ -34,6 +34,7 @@ const { fallback = 'animate' } = Astro.props as Props;
34
34
  !!document.querySelector('[name="astro-view-transitions-enabled"]');
35
35
  const triggerEvent = (name: Events) => document.dispatchEvent(new Event(name));
36
36
  const onload = () => triggerEvent('astro:load');
37
+ const PERSIST_ATTR = 'data-astro-transition-persist';
37
38
 
38
39
  const throttle = (cb: (...args: any[]) => any, delay: number) => {
39
40
  let wait = false;
@@ -86,8 +87,50 @@ const { fallback = 'animate' } = Astro.props as Props;
86
87
  async function updateDOM(dir: Direction, html: string, state?: State, fallback?: Fallback) {
87
88
  const doc = parser.parseFromString(html, 'text/html');
88
89
  doc.documentElement.dataset.astroTransition = dir;
90
+
91
+ // Check for a head element that should persist, either because it has the data
92
+ // attribute or is a link el.
93
+ const persistedHeadElement = (el: Element): Element | null => {
94
+ const id = el.getAttribute(PERSIST_ATTR);
95
+ const newEl = id && doc.head.querySelector(`[${PERSIST_ATTR}="${id}"]`);
96
+ if (newEl) {
97
+ return newEl;
98
+ }
99
+ if (el.matches('link[rel=stylesheet]')) {
100
+ const href = el.getAttribute('href');
101
+ return doc.head.querySelector(`link[rel=stylesheet][href="${href}"]`);
102
+ }
103
+ return null;
104
+ };
105
+
89
106
  const swap = () => {
90
- document.documentElement.replaceWith(doc.documentElement);
107
+ // Swap head
108
+ for (const el of Array.from(document.head.children)) {
109
+ const newEl = persistedHeadElement(el);
110
+ // If the element exists in the document already, remove it
111
+ // from the new document and leave the current node alone
112
+ if (newEl) {
113
+ newEl.remove();
114
+ } else {
115
+ // Otherwise remove the element in the head. It doesn't exist in the new page.
116
+ el.remove();
117
+ }
118
+ }
119
+ // Everything left in the new head is new, append it all.
120
+ document.head.append(...doc.head.children);
121
+
122
+ // Move over persist stuff in the body
123
+ const oldBody = document.body;
124
+ document.body.replaceWith(doc.body);
125
+ for (const el of oldBody.querySelectorAll(`[${PERSIST_ATTR}]`)) {
126
+ const id = el.getAttribute(PERSIST_ATTR);
127
+ const newEl = document.querySelector(`[${PERSIST_ATTR}="${id}"]`);
128
+ if (newEl) {
129
+ // The element exists in the new page, replace it with the element
130
+ // from the old page so that state is preserved.
131
+ newEl.replaceWith(el);
132
+ }
133
+ }
91
134
 
92
135
  if (state?.scrollY != null) {
93
136
  scrollTo(0, state.scrollY);
@@ -97,17 +140,27 @@ const { fallback = 'animate' } = Astro.props as Props;
97
140
  };
98
141
 
99
142
  // Wait on links to finish, to prevent FOUC
100
- const links = Array.from(doc.querySelectorAll('head link[rel=stylesheet]')).map(
101
- (link) =>
102
- new Promise((resolve) => {
103
- const c = link.cloneNode();
104
- ['load', 'error'].forEach((evName) => c.addEventListener(evName, resolve));
105
- document.head.append(c);
106
- })
107
- );
108
- if (links.length) {
109
- await Promise.all(links);
143
+ const links: Promise<any>[] = [];
144
+ for (const el of doc.querySelectorAll('head link[rel=stylesheet]')) {
145
+ // Do not preload links that are already on the page.
146
+ if (
147
+ !document.querySelector(
148
+ `[${PERSIST_ATTR}="${el.getAttribute(PERSIST_ATTR)}"], link[rel=stylesheet]`
149
+ )
150
+ ) {
151
+ const c = document.createElement('link');
152
+ c.setAttribute('rel', 'preload');
153
+ c.setAttribute('as', 'style');
154
+ c.setAttribute('href', el.getAttribute('href')!);
155
+ links.push(
156
+ new Promise<any>((resolve) => {
157
+ ['load', 'error'].forEach((evName) => c.addEventListener(evName, resolve));
158
+ document.head.append(c);
159
+ })
160
+ );
161
+ }
110
162
  }
163
+ links.length && (await Promise.all(links));
111
164
 
112
165
  if (fallback === 'animate') {
113
166
  let isAnimating = false;
@@ -187,7 +240,7 @@ const { fallback = 'animate' } = Astro.props as Props;
187
240
  transitionEnabledOnThisPage()
188
241
  ) {
189
242
  ev.preventDefault();
190
- navigate('forward', link.href);
243
+ navigate('forward', link.href, { index: currentHistoryIndex, scrollY: 0 });
191
244
  currentHistoryIndex++;
192
245
  const newState: State = { index: currentHistoryIndex, scrollY };
193
246
  persistState({ index: currentHistoryIndex - 1, scrollY });
@@ -15,6 +15,7 @@ import type { AstroConfigSchema } from '../core/config';
15
15
  import type { AstroTimer } from '../core/config/timer';
16
16
  import type { AstroCookies } from '../core/cookies';
17
17
  import type { LogOptions, LoggerLevel } from '../core/logger/core';
18
+ import { AstroIntegrationLogger } from '../core/logger/core';
18
19
  import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/server';
19
20
  import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
20
21
  export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
@@ -55,6 +56,7 @@ export interface AstroBuiltinAttributes {
55
56
  'is:raw'?: boolean;
56
57
  'transition:animate'?: 'morph' | 'slide' | 'fade' | TransitionDirectionalAnimations;
57
58
  'transition:name'?: string;
59
+ 'transition:persist'?: boolean | string;
58
60
  }
59
61
  export interface AstroDefineVarsAttribute {
60
62
  'define:vars'?: any;
@@ -277,7 +279,7 @@ type ServerConfig = {
277
279
  /**
278
280
  * @name server.port
279
281
  * @type {number}
280
- * @default `3000`
282
+ * @default `4321`
281
283
  * @description
282
284
  * Set which port the dev server should listen on.
283
285
  *
@@ -842,7 +844,7 @@ export interface AstroUserConfig {
842
844
  * ```js
843
845
  * {
844
846
  * // Example: Use the function syntax to customize based on command
845
- * server: ({ command }) => ({ port: command === 'dev' ? 3000 : 4000 })
847
+ * server: ({ command }) => ({ port: command === 'dev' ? 4321 : 4000 })
846
848
  * }
847
849
  * ```
848
850
  */
@@ -862,7 +864,7 @@ export interface AstroUserConfig {
862
864
  * @docs
863
865
  * @name server.port
864
866
  * @type {number}
865
- * @default `3000`
867
+ * @default `4321`
866
868
  * @description
867
869
  * Set which port the server should listen on.
868
870
  *
@@ -910,7 +912,7 @@ export interface AstroUserConfig {
910
912
  * @docs
911
913
  * @name image.service (Experimental)
912
914
  * @type {{entrypoint: 'astro/assets/services/sharp' | 'astro/assets/services/squoosh' | string, config: Record<string, any>}}
913
- * @default `{entrypoint: 'astro/assets/services/squoosh', config?: {}}`
915
+ * @default `{entrypoint: 'astro/assets/services/sharp', config?: {}}`
914
916
  * @version 2.1.0
915
917
  * @description
916
918
  * Set which image service is used for Astro’s experimental assets support.
@@ -1299,6 +1301,16 @@ export type GetDataEntryInfoReturnType = {
1299
1301
  data: Record<string, unknown>;
1300
1302
  rawData?: string;
1301
1303
  };
1304
+ export interface AstroAdapterFeatures {
1305
+ /**
1306
+ * Creates and edge function that will communiate with the Astro middleware
1307
+ */
1308
+ edgeMiddleware: boolean;
1309
+ /**
1310
+ * SSR only. Each route becomes its own function/file.
1311
+ */
1312
+ functionPerRoute: boolean;
1313
+ }
1302
1314
  export interface AstroSettings {
1303
1315
  config: AstroConfig;
1304
1316
  adapter: AstroAdapter | undefined;
@@ -1391,7 +1403,7 @@ export type GetStaticPathsResultKeyed = GetStaticPathsResult & {
1391
1403
  *
1392
1404
  * [Astro Reference](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
1393
1405
  */
1394
- export type GetStaticPaths = (options: GetStaticPathsOptions) => Promise<GetStaticPathsResult | GetStaticPathsResult[]> | GetStaticPathsResult | GetStaticPathsResult[];
1406
+ export type GetStaticPaths = (options: GetStaticPathsOptions) => Promise<GetStaticPathsResult> | GetStaticPathsResult;
1395
1407
  /**
1396
1408
  * Infers the shape of the `params` property returned by `getStaticPaths()`.
1397
1409
  *
@@ -1510,12 +1522,49 @@ export interface Page<T = any> {
1510
1522
  }
1511
1523
  export type PaginateFunction = (data: any[], args?: PaginateOptions) => GetStaticPathsResult;
1512
1524
  export type Params = Record<string, string | undefined>;
1525
+ export type SupportsKind = 'unsupported' | 'stable' | 'experimental' | 'deprecated';
1526
+ export type AstroFeatureMap = {
1527
+ /**
1528
+ * The adapter is able serve static pages
1529
+ */
1530
+ staticOutput?: SupportsKind;
1531
+ /**
1532
+ * The adapter is able to serve pages that are static or rendered via server
1533
+ */
1534
+ hybridOutput?: SupportsKind;
1535
+ /**
1536
+ * The adapter is able to serve SSR pages
1537
+ */
1538
+ serverOutput?: SupportsKind;
1539
+ /**
1540
+ * The adapter can emit static assets
1541
+ */
1542
+ assets?: AstroAssetsFeature;
1543
+ };
1544
+ export interface AstroAssetsFeature {
1545
+ supportKind?: SupportsKind;
1546
+ /**
1547
+ * Whether if this adapter deploys files in an enviroment that is compatible with the library `sharp`
1548
+ */
1549
+ isSharpCompatible?: boolean;
1550
+ /**
1551
+ * Whether if this adapter deploys files in an enviroment that is compatible with the library `squoosh`
1552
+ */
1553
+ isSquooshCompatible?: boolean;
1554
+ }
1513
1555
  export interface AstroAdapter {
1514
1556
  name: string;
1515
1557
  serverEntrypoint?: string;
1516
1558
  previewEntrypoint?: string;
1517
1559
  exports?: string[];
1518
1560
  args?: any;
1561
+ adapterFeatures?: AstroAdapterFeatures;
1562
+ /**
1563
+ * List of features supported by an adapter.
1564
+ *
1565
+ * If the adapter is not able to handle certain configurations, Astro will throw an error.
1566
+ */
1567
+ supportedAstroFeatures?: AstroFeatureMap;
1519
1568
  }
1520
1569
  type Body = string;
1521
1570
  export type ValidRedirectStatus = 300 | 301 | 302 | 303 | 304 | 307 | 308;
@@ -1695,18 +1744,24 @@ export interface AstroIntegration {
1695
1744
  injectScript: (stage: InjectedScriptStage, content: string) => void;
1696
1745
  injectRoute: (injectRoute: InjectedRoute) => void;
1697
1746
  addClientDirective: (directive: ClientDirectiveConfig) => void;
1747
+ logger: AstroIntegrationLogger;
1698
1748
  }) => void | Promise<void>;
1699
1749
  'astro:config:done'?: (options: {
1700
1750
  config: AstroConfig;
1701
1751
  setAdapter: (adapter: AstroAdapter) => void;
1752
+ logger: AstroIntegrationLogger;
1702
1753
  }) => void | Promise<void>;
1703
1754
  'astro:server:setup'?: (options: {
1704
1755
  server: vite.ViteDevServer;
1756
+ logger: AstroIntegrationLogger;
1705
1757
  }) => void | Promise<void>;
1706
1758
  'astro:server:start'?: (options: {
1707
1759
  address: AddressInfo;
1760
+ logger: AstroIntegrationLogger;
1761
+ }) => void | Promise<void>;
1762
+ 'astro:server:done'?: (options: {
1763
+ logger: AstroIntegrationLogger;
1708
1764
  }) => void | Promise<void>;
1709
- 'astro:server:done'?: () => void | Promise<void>;
1710
1765
  'astro:build:ssr'?: (options: {
1711
1766
  manifest: SerializedSSRManifest;
1712
1767
  /**
@@ -1718,16 +1773,21 @@ export interface AstroIntegration {
1718
1773
  * File path of the emitted middleware
1719
1774
  */
1720
1775
  middlewareEntryPoint: URL | undefined;
1776
+ logger: AstroIntegrationLogger;
1777
+ }) => void | Promise<void>;
1778
+ 'astro:build:start'?: (options: {
1779
+ logger: AstroIntegrationLogger;
1721
1780
  }) => void | Promise<void>;
1722
- 'astro:build:start'?: () => void | Promise<void>;
1723
1781
  'astro:build:setup'?: (options: {
1724
1782
  vite: vite.InlineConfig;
1725
1783
  pages: Map<string, PageBuildData>;
1726
1784
  target: 'client' | 'server';
1727
1785
  updateConfig: (newConfig: vite.InlineConfig) => void;
1786
+ logger: AstroIntegrationLogger;
1728
1787
  }) => void | Promise<void>;
1729
1788
  'astro:build:generated'?: (options: {
1730
1789
  dir: URL;
1790
+ logger: AstroIntegrationLogger;
1731
1791
  }) => void | Promise<void>;
1732
1792
  'astro:build:done'?: (options: {
1733
1793
  pages: {
@@ -1735,6 +1795,7 @@ export interface AstroIntegration {
1735
1795
  }[];
1736
1796
  dir: URL;
1737
1797
  routes: RouteData[];
1798
+ logger: AstroIntegrationLogger;
1738
1799
  }) => void | Promise<void>;
1739
1800
  };
1740
1801
  }
@@ -0,0 +1 @@
1
+ import { AstroIntegrationLogger } from "../core/logger/core";
@@ -5,6 +5,11 @@ import { prependForwardSlash } from "../core/path.js";
5
5
  import { isServerLikeOutput } from "../prerender/utils.js";
6
6
  import { getConfiguredImageService, isESMImportedImage } from "./internal.js";
7
7
  async function generateImage(buildOpts, options, filepath) {
8
+ if (typeof buildOpts.settings.config.image === "undefined") {
9
+ throw new Error(
10
+ "Astro hasn't set a default service for `astro:assets`. This is an internal error and you should report it."
11
+ );
12
+ }
8
13
  if (!isESMImportedImage(options.src)) {
9
14
  return void 0;
10
15
  }
@@ -78,11 +83,10 @@ async function generateImage(buildOpts, options, filepath) {
78
83
  };
79
84
  }
80
85
  function getStaticImageList() {
81
- var _a, _b;
82
- if (!((_a = globalThis == null ? void 0 : globalThis.astroAsset) == null ? void 0 : _a.staticImages)) {
86
+ if (!globalThis?.astroAsset?.staticImages) {
83
87
  return [];
84
88
  }
85
- return (_b = globalThis.astroAsset.staticImages) == null ? void 0 : _b.entries();
89
+ return globalThis.astroAsset.staticImages?.entries();
86
90
  }
87
91
  export {
88
92
  generateImage,
@@ -2,4 +2,4 @@ import type { APIRoute } from '../@types/astro.js';
2
2
  /**
3
3
  * Endpoint used in dev and SSR to serve optimized images by the base image services
4
4
  */
5
- export declare const get: APIRoute;
5
+ export declare const GET: APIRoute;
@@ -15,7 +15,7 @@ async function loadRemoteImage(src) {
15
15
  return void 0;
16
16
  }
17
17
  }
18
- const get = async ({ request }) => {
18
+ const GET = async ({ request }) => {
19
19
  try {
20
20
  const imageService = await getConfiguredImageService();
21
21
  if (!isLocalService(imageService)) {
@@ -23,7 +23,7 @@ const get = async ({ request }) => {
23
23
  }
24
24
  const url = new URL(request.url);
25
25
  const transform = await imageService.parseURL(url, imageServiceConfig);
26
- if (!(transform == null ? void 0 : transform.src)) {
26
+ if (!transform?.src) {
27
27
  throw new Error("Incorrect transform returned by `parseURL`");
28
28
  }
29
29
  let inputBuffer = void 0;
@@ -51,5 +51,5 @@ const get = async ({ request }) => {
51
51
  }
52
52
  };
53
53
  export {
54
- get
54
+ GET
55
55
  };
@@ -12,8 +12,7 @@ function isESMImportedImage(src) {
12
12
  return typeof src === "object";
13
13
  }
14
14
  async function getConfiguredImageService() {
15
- var _a;
16
- if (!((_a = globalThis == null ? void 0 : globalThis.astroAsset) == null ? void 0 : _a.imageService)) {
15
+ if (!globalThis?.astroAsset?.imageService) {
17
16
  const { default: service } = await import(
18
17
  // @ts-expect-error
19
18
  "virtual:image-service"
@@ -0,0 +1,3 @@
1
+ import { type LocalImageService } from './service.js';
2
+ declare const noopService: LocalImageService;
3
+ export default noopService;
@@ -0,0 +1,17 @@
1
+ import { baseService } from "./service.js";
2
+ const noopService = {
3
+ validateOptions: baseService.validateOptions,
4
+ getURL: baseService.getURL,
5
+ parseURL: baseService.parseURL,
6
+ getHTMLAttributes: baseService.getHTMLAttributes,
7
+ async transform(inputBuffer, transformOptions) {
8
+ return {
9
+ data: inputBuffer,
10
+ format: transformOptions.format
11
+ };
12
+ }
13
+ };
14
+ var noop_default = noopService;
15
+ export {
16
+ noop_default as default
17
+ };
@@ -2,6 +2,9 @@ class ImageData {
2
2
  static from(input) {
3
3
  return new ImageData(input.data || input._data, input.width, input.height);
4
4
  }
5
+ _data;
6
+ width;
7
+ height;
5
8
  get data() {
6
9
  if (Object.prototype.toString.call(this._data) === "[object Object]") {
7
10
  return Buffer.from(Object.values(this._data));
@@ -18,16 +18,15 @@ function maybeDelay() {
18
18
  return Promise.resolve();
19
19
  }
20
20
  async function decodeBuffer(_buffer) {
21
- var _a;
22
21
  const buffer = Buffer.from(_buffer);
23
22
  const firstChunk = buffer.slice(0, 16);
24
23
  const firstChunkString = Array.from(firstChunk).map((v) => String.fromCodePoint(v)).join("");
25
24
  if (firstChunkString.includes("GIF")) {
26
25
  throw Error(`GIF images are not supported, please install the @astrojs/image/sharp plugin`);
27
26
  }
28
- const key = (_a = Object.entries(supportedFormats).find(
27
+ const key = Object.entries(supportedFormats).find(
29
28
  ([, { detectors }]) => detectors.some((detector) => detector.exec(firstChunkString))
30
- )) == null ? void 0 : _a[0];
29
+ )?.[0];
31
30
  if (!key) {
32
31
  throw Error(`Buffer has an unsupported format`);
33
32
  }
@@ -3,6 +3,10 @@ function uuid() {
3
3
  return Array.from({ length: 16 }, () => Math.floor(Math.random() * 256).toString(16)).join("");
4
4
  }
5
5
  class WorkerPool {
6
+ numWorkers;
7
+ jobQueue;
8
+ workerQueue;
9
+ done;
6
10
  constructor(numWorkers, workerFile) {
7
11
  this.numWorkers = numWorkers;
8
12
  this.jobQueue = new TransformStream();
@@ -26,7 +26,7 @@ function nextTag(buffer) {
26
26
  function extractTags(buffer, isBigEndian) {
27
27
  const tags = {};
28
28
  let temp = buffer;
29
- while (temp == null ? void 0 : temp.length) {
29
+ while (temp?.length) {
30
30
  const code = readUInt(temp, 16, 0, isBigEndian);
31
31
  const type = readUInt(temp, 16, 2, isBigEndian);
32
32
  const length = readUInt(temp, 32, 4, isBigEndian);
@@ -23,11 +23,11 @@ export default class Queue extends EventTarget {
23
23
  shift(): any;
24
24
  indexOf(searchElement: any, fromIndex: any): number;
25
25
  lastIndexOf(searchElement: any, fromIndex: any): number;
26
- slice(start: any, end: any): Queue;
27
- reverse(): Queue;
26
+ slice(start: any, end: any): this;
27
+ reverse(): this;
28
28
  push(...workers: any[]): number;
29
29
  unshift(...workers: any[]): number;
30
- splice(start: any, deleteCount: any, ...workers: any[]): Queue;
30
+ splice(start: any, deleteCount: any, ...workers: any[]): this;
31
31
  get length(): number;
32
32
  start(callback: any): any;
33
33
  stop(): void;
@@ -1,5 +1,5 @@
1
1
  import type * as vite from 'vite';
2
2
  import type { AstroPluginOptions } from '../@types/astro';
3
- export default function assets({ settings, logging, mode, }: AstroPluginOptions & {
3
+ export default function assets({ settings, mode, }: AstroPluginOptions & {
4
4
  mode: string;
5
5
  }): vite.Plugin[];
@@ -1,8 +1,6 @@
1
- import { bold } from "kleur/colors";
2
1
  import MagicString from "magic-string";
3
2
  import { fileURLToPath } from "node:url";
4
3
  import { normalizePath } from "vite";
5
- import { error } from "../core/logger/core.js";
6
4
  import {
7
5
  appendForwardSlash,
8
6
  joinPaths,
@@ -18,30 +16,10 @@ const rawRE = /(?:\?|&)raw(?:&|$)/;
18
16
  const urlRE = /(\?|&)url(?:&|$)/;
19
17
  function assets({
20
18
  settings,
21
- logging,
22
19
  mode
23
20
  }) {
24
- var _a;
25
21
  let resolvedConfig;
26
22
  globalThis.astroAsset = {};
27
- const UNSUPPORTED_ADAPTERS = /* @__PURE__ */ new Set([
28
- "@astrojs/cloudflare",
29
- "@astrojs/deno",
30
- "@astrojs/netlify/edge-functions",
31
- "@astrojs/vercel/edge"
32
- ]);
33
- const adapterName = (_a = settings.config.adapter) == null ? void 0 : _a.name;
34
- if (["astro/assets/services/sharp", "astro/assets/services/squoosh"].includes(
35
- settings.config.image.service.entrypoint
36
- ) && adapterName && UNSUPPORTED_ADAPTERS.has(adapterName)) {
37
- error(
38
- logging,
39
- "assets",
40
- `The currently selected adapter \`${adapterName}\` does not run on Node, however the currently used image service depends on Node built-ins. ${bold(
41
- "Your project will NOT be able to build."
42
- )}`
43
- );
44
- }
45
23
  return [
46
24
  // Expose the components and different utilities from `astro:assets` and handle serving images from `/_image` in dev
47
25
  {
@@ -122,7 +100,7 @@ function assets({
122
100
  if (s) {
123
101
  return {
124
102
  code: s.toString(),
125
- map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: true }) : null
103
+ map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: "boundary" }) : null
126
104
  };
127
105
  } else {
128
106
  return null;
@@ -58,17 +58,15 @@ const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
58
58
  deno: "@astrojs/deno"
59
59
  };
60
60
  async function getRegistry() {
61
- var _a, _b;
62
- const packageManager = ((_a = await preferredPM(process.cwd())) == null ? void 0 : _a.name) || "npm";
61
+ const packageManager = (await preferredPM(process.cwd()))?.name || "npm";
63
62
  try {
64
63
  const { stdout } = await execa(packageManager, ["config", "get", "registry"]);
65
- return ((_b = stdout == null ? void 0 : stdout.trim()) == null ? void 0 : _b.replace(/\/$/, "")) || "https://registry.npmjs.org";
64
+ return stdout?.trim()?.replace(/\/$/, "") || "https://registry.npmjs.org";
66
65
  } catch (e) {
67
66
  return "https://registry.npmjs.org";
68
67
  }
69
68
  }
70
69
  async function add(names, { flags }) {
71
- var _a;
72
70
  telemetry.record(eventCliSession("add"));
73
71
  applyPolyfill();
74
72
  if (flags.help || names.length === 0) {
@@ -145,7 +143,7 @@ async function add(names, { flags }) {
145
143
  defaultConfigContent: SVELTE_CONFIG_STUB
146
144
  });
147
145
  }
148
- if (integrations.find((integration) => integration.id === "lit") && ((_a = await preferredPM(fileURLToPath(root))) == null ? void 0 : _a.name) === "pnpm") {
146
+ if (integrations.find((integration) => integration.id === "lit") && (await preferredPM(fileURLToPath(root)))?.name === "pnpm") {
149
147
  await setupIntegrationConfig({
150
148
  root,
151
149
  logging,
@@ -186,7 +184,7 @@ async function add(names, { flags }) {
186
184
  configURL = new URL("./astro.config.mjs", root);
187
185
  await fs.writeFile(fileURLToPath(configURL), ASTRO_CONFIG_STUB, { encoding: "utf-8" });
188
186
  }
189
- if (configURL == null ? void 0 : configURL.pathname.endsWith("package.json")) {
187
+ if (configURL?.pathname.endsWith("package.json")) {
190
188
  throw new Error(
191
189
  `Unable to use "astro add" with package.json configuration. Try migrating to \`astro.config.mjs\` and try again.`
192
190
  );
@@ -594,7 +592,6 @@ async function validateIntegrations(integrations) {
594
592
  try {
595
593
  const integrationEntries = await Promise.all(
596
594
  integrations.map(async (integration) => {
597
- var _a;
598
595
  const parsed = parseIntegrationName(integration);
599
596
  if (!parsed) {
600
597
  throw new Error(`${bold(integration)} does not appear to be a valid package name!`);
@@ -646,7 +643,7 @@ async function validateIntegrations(integrations) {
646
643
  if (pkgJson["peerDependencies"]) {
647
644
  const meta = pkgJson["peerDependenciesMeta"] || {};
648
645
  for (const peer in pkgJson["peerDependencies"]) {
649
- const optional = ((_a = meta[peer]) == null ? void 0 : _a.optional) || false;
646
+ const optional = meta[peer]?.optional || false;
650
647
  const isAstro = peer === "astro";
651
648
  if (!optional && !isAstro) {
652
649
  dependencies.push([peer, pkgJson["peerDependencies"][peer]]);
@@ -743,7 +740,7 @@ ${message}`
743
740
  );
744
741
  }
745
742
  if (await askToContinue({ flags })) {
746
- await fs.writeFile((inputConfig == null ? void 0 : inputConfig.path) ?? path.join(cwd, "tsconfig.json"), output, {
743
+ await fs.writeFile(inputConfig?.path ?? path.join(cwd, "tsconfig.json"), output, {
747
744
  encoding: "utf-8"
748
745
  });
749
746
  debug("add", `Updated ${configFileName} file`);
@@ -2,7 +2,7 @@ import _build from "../../core/build/index.js";
2
2
  import { printHelp } from "../../core/messages.js";
3
3
  import { flagsToAstroInlineConfig } from "../flags.js";
4
4
  async function build({ flags }) {
5
- if ((flags == null ? void 0 : flags.help) || (flags == null ? void 0 : flags.h)) {
5
+ if (flags?.help || flags?.h) {
6
6
  printHelp({
7
7
  commandName: "astro build",
8
8
  usage: "[...flags]",