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.
- package/astro.js +2 -2
- package/components/ViewTransitions.astro +65 -12
- package/dist/@types/astro.d.ts +68 -7
- package/dist/@types/astro.js +1 -0
- package/dist/assets/generate.js +7 -3
- package/dist/assets/image-endpoint.d.ts +1 -1
- package/dist/assets/image-endpoint.js +3 -3
- package/dist/assets/internal.js +1 -2
- package/dist/assets/services/noop.d.ts +3 -0
- package/dist/assets/services/noop.js +17 -0
- package/dist/assets/services/vendor/squoosh/image_data.js +3 -0
- package/dist/assets/services/vendor/squoosh/impl.js +2 -3
- package/dist/assets/services/vendor/squoosh/utils/workerPool.js +4 -0
- package/dist/assets/vendor/image-size/types/tiff.js +1 -1
- package/dist/assets/vendor/queue/queue.d.ts +3 -3
- package/dist/assets/vite-plugin-assets.d.ts +1 -1
- package/dist/assets/vite-plugin-assets.js +1 -23
- package/dist/cli/add/index.js +6 -9
- package/dist/cli/build/index.js +1 -1
- package/dist/cli/check/index.d.ts +2 -78
- package/dist/cli/check/index.js +23 -275
- package/dist/cli/dev/index.js +1 -1
- package/dist/cli/index.js +7 -13
- package/dist/cli/info/index.js +3 -4
- package/dist/cli/install-package.d.ts +7 -0
- package/dist/cli/install-package.js +102 -0
- package/dist/cli/preview/index.js +1 -1
- package/dist/cli/sync/index.js +1 -1
- package/dist/content/runtime-assets.js +1 -2
- package/dist/content/runtime.js +3 -5
- package/dist/content/server-listeners.js +1 -2
- package/dist/content/types-generator.js +8 -8
- package/dist/content/utils.js +3 -4
- package/dist/content/vite-plugin-content-assets.js +4 -6
- package/dist/content/vite-plugin-content-imports.js +1 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +5 -6
- package/dist/core/app/index.js +5 -3
- package/dist/core/app/node.d.ts +1 -1
- package/dist/core/app/node.js +7 -2
- package/dist/core/build/css-asset-name.js +2 -4
- package/dist/core/build/generate.js +10 -17
- package/dist/core/build/graph.js +3 -4
- package/dist/core/build/index.js +8 -1
- package/dist/core/build/internal.js +2 -2
- package/dist/core/build/plugin.js +2 -4
- package/dist/core/build/plugins/plugin-analyzer.js +6 -9
- package/dist/core/build/plugins/plugin-component-entry.js +2 -4
- package/dist/core/build/plugins/plugin-css.js +6 -9
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +2 -3
- package/dist/core/build/plugins/plugin-internals.js +1 -2
- package/dist/core/build/plugins/plugin-pages.js +5 -1
- package/dist/core/build/plugins/plugin-ssr.js +12 -8
- package/dist/core/build/static-build.js +8 -12
- package/dist/core/client-directive/build.js +1 -2
- package/dist/core/compile/compile.js +2 -1
- package/dist/core/compile/style.js +2 -3
- package/dist/core/config/schema.d.ts +8 -0
- package/dist/core/config/schema.js +11 -3
- package/dist/core/config/settings.js +3 -3
- package/dist/core/config/timer.js +5 -6
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.d.ts +5 -5
- package/dist/core/cookies/cookies.js +9 -9
- package/dist/core/create-vite.js +6 -28
- package/dist/core/dev/container.d.ts +0 -1
- package/dist/core/dev/container.js +0 -5
- package/dist/core/dev/dev.js +2 -3
- package/dist/core/dev/index.d.ts +1 -1
- package/dist/core/dev/index.js +1 -2
- package/dist/core/dev/restart.d.ts +1 -4
- package/dist/core/dev/restart.js +15 -19
- package/dist/core/endpoint/dev/index.js +1 -1
- package/dist/core/endpoint/index.js +3 -4
- package/dist/core/errors/dev/utils.js +12 -16
- package/dist/core/errors/dev/vite.js +11 -13
- package/dist/core/errors/errors-data.d.ts +21 -0
- package/dist/core/errors/errors-data.js +21 -0
- package/dist/core/errors/errors.js +12 -17
- package/dist/core/errors/overlay.js +7 -8
- package/dist/core/errors/utils.js +1 -1
- package/dist/core/fs/index.js +1 -1
- package/dist/core/logger/console.js +1 -1
- package/dist/core/logger/core.d.ts +26 -6
- package/dist/core/logger/core.js +54 -8
- package/dist/core/logger/node.d.ts +4 -4
- package/dist/core/logger/node.js +6 -6
- package/dist/core/messages.js +4 -5
- package/dist/core/module-loader/vite.js +2 -2
- package/dist/core/polyfill.js +12 -4
- package/dist/core/redirects/helpers.js +3 -3
- package/dist/core/render/core.js +1 -4
- package/dist/core/render/params-and-props.js +2 -3
- package/dist/core/render/result.js +1 -2
- package/dist/core/render/route-cache.d.ts +1 -2
- package/dist/core/render/route-cache.js +6 -11
- package/dist/core/routing/manifest/create.js +2 -6
- package/dist/core/routing/params.js +1 -1
- package/dist/core/routing/validation.js +7 -8
- package/dist/core/sync/index.js +1 -1
- package/dist/core/util.js +1 -1
- package/dist/events/error.js +1 -1
- package/dist/events/session.js +12 -13
- package/dist/integrations/astroFeaturesValidation.d.ts +14 -0
- package/dist/integrations/astroFeaturesValidation.js +109 -0
- package/dist/integrations/index.d.ts +3 -1
- package/dist/integrations/index.js +96 -31
- package/dist/jsx/babel.js +1 -2
- package/dist/prerender/metadata.js +1 -2
- package/dist/runtime/client/hmr.js +1 -2
- package/dist/runtime/server/astro-component.js +1 -2
- package/dist/runtime/server/astro-island.js +53 -55
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/endpoint.d.ts +2 -1
- package/dist/runtime/server/endpoint.js +21 -27
- package/dist/runtime/server/hydration.js +9 -0
- package/dist/runtime/server/jsx.js +3 -2
- package/dist/runtime/server/render/astro/instance.js +6 -3
- package/dist/runtime/server/render/astro/render-template.js +4 -3
- package/dist/runtime/server/render/astro/render.js +3 -3
- package/dist/runtime/server/render/common.js +1 -1
- package/dist/runtime/server/render/component.js +11 -13
- package/dist/runtime/server/render/dom.js +1 -1
- package/dist/runtime/server/render/page.js +2 -3
- package/dist/runtime/server/render/slot.js +2 -1
- package/dist/runtime/server/render/util.js +1 -2
- package/dist/runtime/server/transition.d.ts +1 -0
- package/dist/runtime/server/transition.js +1 -0
- package/dist/transitions/vite-plugin-transitions.js +1 -0
- package/dist/vite-plugin-astro/compile.js +2 -3
- package/dist/vite-plugin-astro/hmr.js +3 -5
- package/dist/vite-plugin-astro/index.js +1 -1
- package/dist/vite-plugin-astro/metadata.js +1 -2
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/base.js +1 -2
- package/dist/vite-plugin-astro-server/controller.js +2 -3
- package/dist/vite-plugin-astro-server/css.js +1 -1
- package/dist/vite-plugin-astro-server/request.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +1 -2
- package/dist/vite-plugin-astro-server/scripts.js +2 -3
- package/dist/vite-plugin-astro-server/vite.js +1 -1
- package/dist/vite-plugin-config-alias/index.js +1 -1
- package/dist/vite-plugin-env/index.js +2 -2
- package/dist/vite-plugin-head/index.js +4 -6
- package/dist/vite-plugin-html/index.js +1 -2
- package/dist/vite-plugin-html/transform/index.js +1 -1
- package/dist/vite-plugin-html/transform/slots.js +5 -6
- package/dist/vite-plugin-html/transform/utils.js +1 -2
- package/dist/vite-plugin-jsx/import-source.js +1 -2
- package/dist/vite-plugin-jsx/index.js +1 -1
- package/dist/vite-plugin-jsx/tag.js +4 -6
- package/dist/vite-plugin-markdown/index.js +1 -2
- package/dist/vite-plugin-scanner/index.js +2 -1
- package/dist/vite-plugin-scanner/scan.js +1 -1
- package/dist/vite-plugin-scripts/index.js +1 -1
- package/dist/vite-plugin-scripts/page-ssr.js +2 -2
- package/package.json +13 -22
- package/tsconfigs/base.json +8 -6
- package/tsconfigs/strict.json +2 -3
- package/dist/cli/check/print.d.ts +0 -2
- 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 = '>=
|
|
17
|
-
const skipSemverCheckIfAbove =
|
|
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
|
-
|
|
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 =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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 });
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -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 `
|
|
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' ?
|
|
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 `
|
|
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/
|
|
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
|
|
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
|
}
|
package/dist/@types/astro.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { AstroIntegrationLogger } from "../core/logger/core";
|
package/dist/assets/generate.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
89
|
+
return globalThis.astroAsset.staticImages?.entries();
|
|
86
90
|
}
|
|
87
91
|
export {
|
|
88
92
|
generateImage,
|
|
@@ -15,7 +15,7 @@ async function loadRemoteImage(src) {
|
|
|
15
15
|
return void 0;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
const
|
|
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 (!
|
|
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
|
-
|
|
54
|
+
GET
|
|
55
55
|
};
|
package/dist/assets/internal.js
CHANGED
|
@@ -12,8 +12,7 @@ function isESMImportedImage(src) {
|
|
|
12
12
|
return typeof src === "object";
|
|
13
13
|
}
|
|
14
14
|
async function getConfiguredImageService() {
|
|
15
|
-
|
|
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,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 =
|
|
27
|
+
const key = Object.entries(supportedFormats).find(
|
|
29
28
|
([, { detectors }]) => detectors.some((detector) => detector.exec(firstChunkString))
|
|
30
|
-
)
|
|
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
|
|
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):
|
|
27
|
-
reverse():
|
|
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[]):
|
|
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,
|
|
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:
|
|
103
|
+
map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: "boundary" }) : null
|
|
126
104
|
};
|
|
127
105
|
} else {
|
|
128
106
|
return null;
|
package/dist/cli/add/index.js
CHANGED
|
@@ -58,17 +58,15 @@ const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
|
|
|
58
58
|
deno: "@astrojs/deno"
|
|
59
59
|
};
|
|
60
60
|
async function getRegistry() {
|
|
61
|
-
|
|
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
|
|
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") && (
|
|
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
|
|
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 =
|
|
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(
|
|
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`);
|
package/dist/cli/build/index.js
CHANGED
|
@@ -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 (
|
|
5
|
+
if (flags?.help || flags?.h) {
|
|
6
6
|
printHelp({
|
|
7
7
|
commandName: "astro build",
|
|
8
8
|
usage: "[...flags]",
|