astro 2.0.18 → 2.1.1
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/README.md +3 -3
- package/client-base.d.ts +27 -0
- package/client-image.d.ts +48 -0
- package/components/Image.astro +28 -0
- package/dist/@types/astro.d.ts +123 -1
- package/dist/assets/consts.d.ts +4 -0
- package/dist/assets/consts.js +20 -0
- package/dist/assets/image-endpoint.d.ts +5 -0
- package/dist/assets/image-endpoint.js +50 -0
- package/dist/assets/index.d.ts +4 -0
- package/dist/assets/index.js +10 -0
- package/dist/assets/internal.d.ts +36 -0
- package/dist/assets/internal.js +70 -0
- package/dist/assets/services/service.d.ts +71 -0
- package/dist/assets/services/service.js +99 -0
- package/dist/assets/services/sharp.d.ts +3 -0
- package/dist/assets/services/sharp.js +57 -0
- package/dist/assets/services/squoosh.d.ts +3 -0
- package/dist/assets/services/squoosh.js +56 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_enc.d.js +11 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +1628 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +1850 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/codecs.d.ts +158 -0
- package/dist/assets/services/vendor/squoosh/codecs.js +284 -0
- package/dist/assets/services/vendor/squoosh/copy-wasm.d.ts +1 -0
- package/dist/assets/services/vendor/squoosh/copy-wasm.js +24 -0
- package/dist/assets/services/vendor/squoosh/emscripten-types.d.js +0 -0
- package/dist/assets/services/vendor/squoosh/emscripten-utils.d.ts +9 -0
- package/dist/assets/services/vendor/squoosh/emscripten-utils.js +33 -0
- package/dist/assets/services/vendor/squoosh/image-pool.d.ts +4 -0
- package/dist/assets/services/vendor/squoosh/image-pool.js +94 -0
- package/dist/assets/services/vendor/squoosh/image.d.ts +14 -0
- package/dist/assets/services/vendor/squoosh/image.js +27 -0
- package/dist/assets/services/vendor/squoosh/image_data.d.ts +9 -0
- package/dist/assets/services/vendor/squoosh/image_data.js +22 -0
- package/dist/assets/services/vendor/squoosh/impl.d.ts +22 -0
- package/dist/assets/services/vendor/squoosh/impl.js +110 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_enc.d.js +11 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +1631 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +1737 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.d.ts +10 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.js +89 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.d.ts +15 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +138 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.d.ts +15 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.js +95 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/rotate/rotate.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/utils/execOnce.d.ts +1 -0
- package/dist/assets/services/vendor/squoosh/utils/execOnce.js +14 -0
- package/dist/assets/services/vendor/squoosh/utils/workerPool.d.ts +22 -0
- package/dist/assets/services/vendor/squoosh/utils/workerPool.js +95 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_enc.d.js +4 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +1473 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +1640 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.wasm +0 -0
- package/dist/assets/types.d.ts +119 -0
- package/dist/assets/types.js +0 -0
- package/dist/assets/utils/etag.d.ts +12 -0
- package/dist/assets/utils/etag.js +28 -0
- package/dist/assets/utils/metadata.d.ts +6 -0
- package/dist/assets/utils/metadata.js +30 -0
- package/dist/assets/utils/queryParams.d.ts +2 -0
- package/dist/assets/utils/queryParams.js +16 -0
- package/dist/assets/utils/transformToPath.d.ts +2 -0
- package/dist/assets/utils/transformToPath.js +17 -0
- package/dist/assets/vite-plugin-assets.d.ts +5 -0
- package/dist/assets/vite-plugin-assets.js +188 -0
- package/dist/cli/check/index.d.ts +81 -2
- package/dist/cli/check/index.js +190 -44
- package/dist/cli/index.js +39 -16
- package/dist/cli/telemetry.js +1 -1
- package/dist/content/consts.d.ts +0 -1
- package/dist/content/consts.js +1 -3
- package/dist/content/internal.d.ts +7 -0
- package/dist/content/internal.js +27 -5
- package/dist/content/template/virtual-mod.d.mts +1 -0
- package/dist/content/types-generator.js +25 -10
- package/dist/content/utils.d.ts +16 -13
- package/dist/content/utils.js +29 -6
- package/dist/content/vite-plugin-content-assets.d.ts +3 -1
- package/dist/content/vite-plugin-content-assets.js +10 -6
- package/dist/content/vite-plugin-content-imports.js +54 -27
- package/dist/content/vite-plugin-content-virtual-mod.js +7 -4
- package/dist/core/app/index.js +104 -134
- package/dist/core/build/generate.js +30 -5
- package/dist/core/build/index.d.ts +2 -0
- package/dist/core/build/index.js +16 -0
- package/dist/core/build/plugins/plugin-ssr.js +3 -5
- package/dist/core/config/config.js +2 -1
- package/dist/core/config/schema.d.ts +64 -8
- package/dist/core/config/schema.js +17 -3
- package/dist/core/config/settings.js +3 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +36 -68
- package/dist/core/create-vite.js +5 -1
- package/dist/core/dev/dev.d.ts +2 -2
- package/dist/core/dev/dev.js +24 -4
- package/dist/core/errors/dev/vite.js +6 -1
- package/dist/core/errors/errors-data.d.ts +70 -1
- package/dist/core/errors/errors-data.js +25 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/path.d.ts +1 -0
- package/dist/core/path.js +4 -0
- package/dist/core/preview/index.d.ts +3 -1
- package/dist/core/preview/index.js +16 -1
- package/dist/core/render/dev/environment.js +1 -5
- package/dist/core/render/environment.js +1 -2
- package/dist/core/render/result.js +13 -35
- package/dist/core/sync/index.d.ts +18 -5
- package/dist/core/sync/index.js +13 -1
- package/dist/core/util.d.ts +1 -0
- package/dist/core/util.js +10 -0
- package/dist/integrations/index.js +12 -1
- package/dist/runtime/server/jsx.js +8 -1
- package/dist/runtime/server/render/component.js +1 -1
- package/dist/runtime/server/response.js +11 -30
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.js +1 -1
- package/dist/vite-plugin-env/index.js +4 -4
- package/dist/vite-plugin-inject-env-ts/index.js +17 -2
- package/dist/vite-plugin-markdown/content-entry-type.d.ts +7 -0
- package/dist/vite-plugin-markdown/content-entry-type.js +39 -0
- package/dist/vite-plugin-markdown/index.js +70 -4
- package/dist/vite-plugin-ssr-manifest/index.d.ts +2 -0
- package/dist/vite-plugin-ssr-manifest/index.js +25 -0
- package/package.json +26 -8
- package/src/content/template/types.d.ts +18 -9
- package/src/content/template/virtual-mod.mjs +6 -0
- package/tsconfigs/base.json +6 -1
|
@@ -64,7 +64,7 @@ export declare const AstroErrorData: {
|
|
|
64
64
|
* @description
|
|
65
65
|
* The `Astro.clientAddress` property is only available when [Server-side rendering](https://docs.astro.build/en/guides/server-side-rendering/) is enabled.
|
|
66
66
|
*
|
|
67
|
-
* To get the user's IP address in static mode, different APIs such as [Ipify](https://www.ipify.org/) can be used in a [Client-side script](https://docs.astro.build/en/
|
|
67
|
+
* To get the user's IP address in static mode, different APIs such as [Ipify](https://www.ipify.org/) can be used in a [Client-side script](https://docs.astro.build/en/guides/client-side-scripts/) or it may be possible to get the user's IP using a serverless function hosted on your hosting provider.
|
|
68
68
|
*/
|
|
69
69
|
readonly StaticClientAddressNotAvailable: {
|
|
70
70
|
readonly title: "`Astro.clientAddress` is not available in static mode.";
|
|
@@ -397,6 +397,75 @@ export declare const AstroErrorData: {
|
|
|
397
397
|
readonly message: (paramName: string) => string;
|
|
398
398
|
readonly hint: "Rename your file to `[page].astro` or `[...page].astro`.";
|
|
399
399
|
};
|
|
400
|
+
/**
|
|
401
|
+
* @docs
|
|
402
|
+
* @see
|
|
403
|
+
* - [Assets (Experimental)](https://docs.astro.build/en/guides/assets/)
|
|
404
|
+
* - [Image component](https://docs.astro.build/en/guides/assets/#image--astroassets)
|
|
405
|
+
* - [Image component#alt](https://docs.astro.build/en/guides/assets/#alt-required)
|
|
406
|
+
* @description
|
|
407
|
+
* The `alt` property allows you to provide descriptive alt text to users of screen readers and other assistive technologies. In order to ensure your images are accessible, the `Image` component requires that an `alt` be specified.
|
|
408
|
+
*
|
|
409
|
+
* If the image is merely decorative (i.e. doesn’t contribute to the understanding of the page), set `alt=""` so that screen readers know to ignore the image.
|
|
410
|
+
*/
|
|
411
|
+
readonly ImageMissingAlt: {
|
|
412
|
+
readonly title: "Missing alt property";
|
|
413
|
+
readonly code: 3022;
|
|
414
|
+
readonly message: "The alt property is required.";
|
|
415
|
+
readonly hint: "The `alt` property is important for the purpose of accessibility, without it users using screen readers or other assistive technologies won't be able to understand what your image is supposed to represent. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-alt for more information.";
|
|
416
|
+
};
|
|
417
|
+
/**
|
|
418
|
+
* @docs
|
|
419
|
+
* @see
|
|
420
|
+
* - [Image Service API](https://docs.astro.build/en/reference/image-service-reference/)
|
|
421
|
+
* @description
|
|
422
|
+
* There was an error while loading the configured image service. This can be caused by various factors, such as your image service not properly exporting a compatible object in its default export, or an incorrect path.
|
|
423
|
+
*
|
|
424
|
+
* If you believe that your service is properly configured and this error is wrong, please [open an issue](https://astro.build/issues/).
|
|
425
|
+
*/
|
|
426
|
+
readonly InvalidImageService: {
|
|
427
|
+
readonly title: "Error while loading image service";
|
|
428
|
+
readonly code: 3023;
|
|
429
|
+
readonly message: "There was an error loading the configured image service. Please see the stack trace for more information.";
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* @docs
|
|
433
|
+
* @message
|
|
434
|
+
* Missing width and height attributes for `IMAGE_URL`. When using remote images, both dimensions are always required in order to avoid cumulative layout shift (CLS).
|
|
435
|
+
* @see
|
|
436
|
+
* - [Assets (Experimental)](https://docs.astro.build/en/guides/assets/)
|
|
437
|
+
* - [Image component#width-and-height](https://docs.astro.build/en/guides/assets/#width-and-height)
|
|
438
|
+
* @description
|
|
439
|
+
* For remote images, `width` and `height` cannot be inferred from the original file. As such, in order to avoid CLS, those two properties are always required.
|
|
440
|
+
*
|
|
441
|
+
* If your image is inside your `src` folder, you probably meant to import it instead. See [the Imports guide for more information](https://docs.astro.build/en/guides/imports/#other-assets).
|
|
442
|
+
*/
|
|
443
|
+
readonly MissingImageDimension: {
|
|
444
|
+
readonly title: "Missing image dimensions";
|
|
445
|
+
readonly code: 3024;
|
|
446
|
+
readonly message: (missingDimension: 'width' | 'height' | 'both', imageURL: string) => string;
|
|
447
|
+
readonly hint: "If your image is inside your `src` folder, you probably meant to import it instead. See [the Imports guide for more information](https://docs.astro.build/en/guides/imports/#other-assets).";
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* @docs
|
|
451
|
+
* @description
|
|
452
|
+
* The built-in image services do not currently support optimizing all image formats.
|
|
453
|
+
*
|
|
454
|
+
* For unsupported formats such as SVGs and GIFs, you may be able to use an `img` tag directly:
|
|
455
|
+
* ```astro
|
|
456
|
+
* ---
|
|
457
|
+
* import rocket from '../assets/images/rocket.svg'
|
|
458
|
+
* ---
|
|
459
|
+
*
|
|
460
|
+
* <img src={rocket.src} width={rocket.width} height={rocket.height} alt="A rocketship in space." />
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
readonly UnsupportedImageFormat: {
|
|
464
|
+
readonly title: "Unsupported image format";
|
|
465
|
+
readonly code: 3025;
|
|
466
|
+
readonly message: (format: string, imagePath: string, supportedFormats: readonly string[]) => string;
|
|
467
|
+
readonly hint: "If you do not need optimization, using an `img` tag directly instead of the `Image` component might be what you're looking for.";
|
|
468
|
+
};
|
|
400
469
|
/**
|
|
401
470
|
* @docs
|
|
402
471
|
* @see
|
|
@@ -145,6 +145,31 @@ Expected \`true\` value but got \`${suffix}\`.`;
|
|
|
145
145
|
message: (paramName) => `[paginate()] page number param \`${paramName}\` not found in your filepath.`,
|
|
146
146
|
hint: "Rename your file to `[page].astro` or `[...page].astro`."
|
|
147
147
|
},
|
|
148
|
+
ImageMissingAlt: {
|
|
149
|
+
title: "Missing alt property",
|
|
150
|
+
code: 3022,
|
|
151
|
+
message: "The alt property is required.",
|
|
152
|
+
hint: "The `alt` property is important for the purpose of accessibility, without it users using screen readers or other assistive technologies won't be able to understand what your image is supposed to represent. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-alt for more information."
|
|
153
|
+
},
|
|
154
|
+
InvalidImageService: {
|
|
155
|
+
title: "Error while loading image service",
|
|
156
|
+
code: 3023,
|
|
157
|
+
message: "There was an error loading the configured image service. Please see the stack trace for more information."
|
|
158
|
+
},
|
|
159
|
+
MissingImageDimension: {
|
|
160
|
+
title: "Missing image dimensions",
|
|
161
|
+
code: 3024,
|
|
162
|
+
message: (missingDimension, imageURL) => `Missing ${missingDimension === "both" ? "width and height attributes" : `${missingDimension} attribute`} for ${imageURL}. When using remote images, both dimensions are always required in order to avoid CLS.`,
|
|
163
|
+
hint: "If your image is inside your `src` folder, you probably meant to import it instead. See [the Imports guide for more information](https://docs.astro.build/en/guides/imports/#other-assets)."
|
|
164
|
+
},
|
|
165
|
+
UnsupportedImageFormat: {
|
|
166
|
+
title: "Unsupported image format",
|
|
167
|
+
code: 3025,
|
|
168
|
+
message: (format, imagePath, supportedFormats) => `Received unsupported format \`${format}\` from \`${imagePath}\`. Currently only ${supportedFormats.join(
|
|
169
|
+
", "
|
|
170
|
+
)} are supported for optimization.`,
|
|
171
|
+
hint: "If you do not need optimization, using an `img` tag directly instead of the `Image` component might be what you're looking for."
|
|
172
|
+
},
|
|
148
173
|
UnknownViteError: {
|
|
149
174
|
title: "Unknown Vite Error.",
|
|
150
175
|
code: 4e3
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
base,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "2.
|
|
50
|
+
const version = "2.1.1";
|
|
51
51
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
52
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
53
53
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -233,7 +233,7 @@ function printHelp({
|
|
|
233
233
|
message.push(
|
|
234
234
|
linebreak(),
|
|
235
235
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
236
|
-
`v${"2.
|
|
236
|
+
`v${"2.1.1"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
package/dist/core/path.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export declare function isRelativePath(path: string): boolean;
|
|
|
12
12
|
export declare function joinPaths(...paths: (string | undefined)[]): string;
|
|
13
13
|
export declare function removeFileExtension(path: string): string;
|
|
14
14
|
export declare function removeQueryString(path: string): string;
|
|
15
|
+
export declare function isRemotePath(src: string): boolean;
|
package/dist/core/path.js
CHANGED
|
@@ -50,10 +50,14 @@ function removeQueryString(path) {
|
|
|
50
50
|
const index = path.lastIndexOf("?");
|
|
51
51
|
return index > 0 ? path.substring(0, index) : path;
|
|
52
52
|
}
|
|
53
|
+
function isRemotePath(src) {
|
|
54
|
+
return /^(http|ftp|https):?\/\//.test(src) || src.startsWith("data:");
|
|
55
|
+
}
|
|
53
56
|
export {
|
|
54
57
|
appendExtension,
|
|
55
58
|
appendForwardSlash,
|
|
56
59
|
isRelativePath,
|
|
60
|
+
isRemotePath,
|
|
57
61
|
joinPaths,
|
|
58
62
|
prependForwardSlash,
|
|
59
63
|
removeFileExtension,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { AstroTelemetry } from '@astrojs/telemetry';
|
|
2
|
+
import type { Arguments } from 'yargs-parser';
|
|
2
3
|
import type { AstroSettings, PreviewServer } from '../../@types/astro';
|
|
3
4
|
import type { LogOptions } from '../logger/core';
|
|
4
5
|
interface PreviewOptions {
|
|
5
6
|
logging: LogOptions;
|
|
6
7
|
telemetry: AstroTelemetry;
|
|
8
|
+
flags?: Arguments;
|
|
7
9
|
}
|
|
8
10
|
/** The primary dev action */
|
|
9
|
-
export default function preview(_settings: AstroSettings, { logging }: PreviewOptions): Promise<PreviewServer>;
|
|
11
|
+
export default function preview(_settings: AstroSettings, { logging, flags }: PreviewOptions): Promise<PreviewServer | undefined>;
|
|
10
12
|
export {};
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
import { cyan } from "kleur/colors";
|
|
1
2
|
import { createRequire } from "module";
|
|
2
3
|
import { pathToFileURL } from "url";
|
|
3
4
|
import { runHookConfigDone, runHookConfigSetup } from "../../integrations/index.js";
|
|
5
|
+
import { printHelp } from "../messages.js";
|
|
4
6
|
import createStaticPreviewServer from "./static-preview-server.js";
|
|
5
7
|
import { getResolvedHostForHttpServer } from "./util.js";
|
|
6
|
-
async function preview(_settings, { logging }) {
|
|
8
|
+
async function preview(_settings, { logging, flags }) {
|
|
9
|
+
if ((flags == null ? void 0 : flags.help) || (flags == null ? void 0 : flags.h)) {
|
|
10
|
+
printHelp({
|
|
11
|
+
commandName: "astro preview",
|
|
12
|
+
usage: "[...flags]",
|
|
13
|
+
tables: {
|
|
14
|
+
Flags: [["--help (-h)", "See all available flags."]]
|
|
15
|
+
},
|
|
16
|
+
description: `Starts a local server to serve your static dist/ directory. Check ${cyan(
|
|
17
|
+
"https://docs.astro.build/en/reference/cli-reference/#astro-preview"
|
|
18
|
+
)} for more information.`
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
7
22
|
const settings = await runHookConfigSetup({
|
|
8
23
|
settings: _settings,
|
|
9
24
|
command: "preview",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getContentPaths } from "../../../content/index.js";
|
|
2
1
|
import { createEnvironment } from "../index.js";
|
|
3
2
|
import { RouteCache } from "../route-cache.js";
|
|
4
3
|
import { createResolve } from "./resolve.js";
|
|
@@ -8,10 +7,7 @@ function createDevelopmentEnvironment(settings, logging, loader) {
|
|
|
8
7
|
let env = createEnvironment({
|
|
9
8
|
adapterName: (_a = settings.adapter) == null ? void 0 : _a.name,
|
|
10
9
|
logging,
|
|
11
|
-
markdown:
|
|
12
|
-
...settings.config.markdown,
|
|
13
|
-
contentDir: getContentPaths(settings.config).contentDir
|
|
14
|
-
},
|
|
10
|
+
markdown: settings.config.markdown,
|
|
15
11
|
mode,
|
|
16
12
|
renderers: [],
|
|
17
13
|
resolve: createResolve(loader, settings.config.root),
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
var __accessCheck = (obj, member, msg) => {
|
|
2
|
-
if (!member.has(obj))
|
|
3
|
-
throw TypeError("Cannot " + msg);
|
|
4
|
-
};
|
|
5
|
-
var __privateGet = (obj, member, getter) => {
|
|
6
|
-
__accessCheck(obj, member, "read from private field");
|
|
7
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
-
};
|
|
9
|
-
var __privateAdd = (obj, member, value) => {
|
|
10
|
-
if (member.has(obj))
|
|
11
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
-
};
|
|
14
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
-
__accessCheck(obj, member, "write to private field");
|
|
16
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
19
|
-
var _result, _slots, _loggingOpts;
|
|
20
1
|
import {
|
|
21
2
|
createScopedResult,
|
|
22
3
|
renderSlot,
|
|
@@ -45,13 +26,13 @@ function getFunctionExpression(slot) {
|
|
|
45
26
|
return slot.expressions[0];
|
|
46
27
|
}
|
|
47
28
|
class Slots {
|
|
29
|
+
#result;
|
|
30
|
+
#slots;
|
|
31
|
+
#loggingOpts;
|
|
48
32
|
constructor(result, slots, logging) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
__privateSet(this, _result, result);
|
|
53
|
-
__privateSet(this, _slots, slots);
|
|
54
|
-
__privateSet(this, _loggingOpts, logging);
|
|
33
|
+
this.#result = result;
|
|
34
|
+
this.#slots = slots;
|
|
35
|
+
this.#loggingOpts = logging;
|
|
55
36
|
if (slots) {
|
|
56
37
|
for (const key of Object.keys(slots)) {
|
|
57
38
|
if (this[key] !== void 0) {
|
|
@@ -70,22 +51,22 @@ class Slots {
|
|
|
70
51
|
}
|
|
71
52
|
}
|
|
72
53
|
has(name) {
|
|
73
|
-
if (!
|
|
54
|
+
if (!this.#slots)
|
|
74
55
|
return false;
|
|
75
|
-
return Boolean(
|
|
56
|
+
return Boolean(this.#slots[name]);
|
|
76
57
|
}
|
|
77
58
|
async render(name, args = []) {
|
|
78
|
-
if (!
|
|
59
|
+
if (!this.#slots || !this.has(name))
|
|
79
60
|
return;
|
|
80
|
-
const scoped = createScopedResult(
|
|
61
|
+
const scoped = createScopedResult(this.#result, ScopeFlags.RenderSlot);
|
|
81
62
|
if (!Array.isArray(args)) {
|
|
82
63
|
warn(
|
|
83
|
-
|
|
64
|
+
this.#loggingOpts,
|
|
84
65
|
"Astro.slots.render",
|
|
85
66
|
`Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`
|
|
86
67
|
);
|
|
87
68
|
} else if (args.length > 0) {
|
|
88
|
-
const slotValue =
|
|
69
|
+
const slotValue = this.#slots[name];
|
|
89
70
|
const component = typeof slotValue === "function" ? await slotValue(scoped) : await slotValue;
|
|
90
71
|
const expression = getFunctionExpression(component);
|
|
91
72
|
if (expression) {
|
|
@@ -98,14 +79,11 @@ class Slots {
|
|
|
98
79
|
);
|
|
99
80
|
}
|
|
100
81
|
}
|
|
101
|
-
const content = await renderSlot(scoped,
|
|
82
|
+
const content = await renderSlot(scoped, this.#slots[name]);
|
|
102
83
|
const outHTML = stringifyChunk(scoped, content);
|
|
103
84
|
return outHTML;
|
|
104
85
|
}
|
|
105
86
|
}
|
|
106
|
-
_result = new WeakMap();
|
|
107
|
-
_slots = new WeakMap();
|
|
108
|
-
_loggingOpts = new WeakMap();
|
|
109
87
|
let renderMarkdown = null;
|
|
110
88
|
function createResult(args) {
|
|
111
89
|
const { markdown, params, pathname, renderers, request, resolve } = args;
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type fsMod from 'node:fs';
|
|
3
|
+
import type { Arguments } from 'yargs-parser';
|
|
3
4
|
import type { AstroSettings } from '../../@types/astro';
|
|
4
5
|
import { LogOptions } from '../logger/core.js';
|
|
5
|
-
type ProcessExit = 0 | 1;
|
|
6
|
-
export
|
|
6
|
+
export type ProcessExit = 0 | 1;
|
|
7
|
+
export type SyncOptions = {
|
|
7
8
|
logging: LogOptions;
|
|
8
9
|
fs: typeof fsMod;
|
|
9
|
-
}
|
|
10
|
-
export declare function
|
|
10
|
+
};
|
|
11
|
+
export declare function syncCli(settings: AstroSettings, { logging, fs, flags }: {
|
|
11
12
|
logging: LogOptions;
|
|
12
13
|
fs: typeof fsMod;
|
|
14
|
+
flags?: Arguments;
|
|
13
15
|
}): Promise<ProcessExit>;
|
|
14
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Generate content collection types, and then returns the process exit signal.
|
|
18
|
+
*
|
|
19
|
+
* A non-zero process signal is emitted in case there's an error while generating content collection types.
|
|
20
|
+
*
|
|
21
|
+
* @param {SyncOptions} options
|
|
22
|
+
* @param {AstroSettings} settings Astro settings
|
|
23
|
+
* @param {typeof fsMod} options.fs The file system
|
|
24
|
+
* @param {LogOptions} options.logging Logging options
|
|
25
|
+
* @return {Promise<ProcessExit>}
|
|
26
|
+
*/
|
|
27
|
+
export declare function sync(settings: AstroSettings, { logging, fs }: SyncOptions): Promise<ProcessExit>;
|
package/dist/core/sync/index.js
CHANGED
|
@@ -9,7 +9,19 @@ import { getTimeStat } from "../build/util.js";
|
|
|
9
9
|
import { createVite } from "../create-vite.js";
|
|
10
10
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
11
11
|
import { info } from "../logger/core.js";
|
|
12
|
-
|
|
12
|
+
import { printHelp } from "../messages.js";
|
|
13
|
+
async function syncCli(settings, { logging, fs, flags }) {
|
|
14
|
+
if ((flags == null ? void 0 : flags.help) || (flags == null ? void 0 : flags.h)) {
|
|
15
|
+
printHelp({
|
|
16
|
+
commandName: "astro sync",
|
|
17
|
+
usage: "[...flags]",
|
|
18
|
+
tables: {
|
|
19
|
+
Flags: [["--help (-h)", "See all available flags."]]
|
|
20
|
+
},
|
|
21
|
+
description: `Generates TypeScript types for all Astro modules.`
|
|
22
|
+
});
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
13
25
|
const resolvedSettings = await runHookConfigSetup({
|
|
14
26
|
settings,
|
|
15
27
|
logging,
|
package/dist/core/util.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare function isPage(file: URL, settings: AstroSettings): boolean;
|
|
|
37
37
|
export declare function isEndpoint(file: URL, settings: AstroSettings): boolean;
|
|
38
38
|
export declare function isModeServerWithNoAdapter(settings: AstroSettings): boolean;
|
|
39
39
|
export declare function relativeToSrcDir(config: AstroConfig, idOrUrl: URL | string): string;
|
|
40
|
+
export declare function rootRelativePath(config: AstroConfig, idOrUrl: URL | string): string;
|
|
40
41
|
export declare function emoji(char: string, fallback: string): string;
|
|
41
42
|
/**
|
|
42
43
|
* Simulate Vite's resolve and import analysis so we can import the id as an URL
|
package/dist/core/util.js
CHANGED
|
@@ -114,6 +114,15 @@ function relativeToSrcDir(config, idOrUrl) {
|
|
|
114
114
|
}
|
|
115
115
|
return id.slice(slash(fileURLToPath(config.srcDir)).length);
|
|
116
116
|
}
|
|
117
|
+
function rootRelativePath(config, idOrUrl) {
|
|
118
|
+
let id;
|
|
119
|
+
if (typeof idOrUrl !== "string") {
|
|
120
|
+
id = unwrapId(viteID(idOrUrl));
|
|
121
|
+
} else {
|
|
122
|
+
id = idOrUrl;
|
|
123
|
+
}
|
|
124
|
+
return prependForwardSlash(id.slice(normalizePath(fileURLToPath(config.root)).length));
|
|
125
|
+
}
|
|
117
126
|
function emoji(char, fallback) {
|
|
118
127
|
return process.platform !== "win32" ? char : fallback;
|
|
119
128
|
}
|
|
@@ -170,6 +179,7 @@ export {
|
|
|
170
179
|
resolveJsToTs,
|
|
171
180
|
resolvePages,
|
|
172
181
|
resolvePath,
|
|
182
|
+
rootRelativePath,
|
|
173
183
|
unwrapId,
|
|
174
184
|
viteID
|
|
175
185
|
};
|
|
@@ -3,6 +3,7 @@ import fs from "node:fs";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { mergeConfig } from "../core/config/config.js";
|
|
5
5
|
import { info } from "../core/logger/core.js";
|
|
6
|
+
import { mdxContentEntryType } from "../vite-plugin-markdown/content-entry-type.js";
|
|
6
7
|
async function withTakingALongTimeMsg({
|
|
7
8
|
name,
|
|
8
9
|
hookResult,
|
|
@@ -33,8 +34,10 @@ async function runHookConfigSetup({
|
|
|
33
34
|
let addPageExtension2 = function(...input) {
|
|
34
35
|
const exts = input.flat(Infinity).map((ext) => `.${ext.replace(/^\./, "")}`);
|
|
35
36
|
updatedSettings.pageExtensions.push(...exts);
|
|
37
|
+
}, addContentEntryType2 = function(contentEntryType) {
|
|
38
|
+
updatedSettings.contentEntryTypes.push(contentEntryType);
|
|
36
39
|
};
|
|
37
|
-
var addPageExtension = addPageExtension2;
|
|
40
|
+
var addPageExtension = addPageExtension2, addContentEntryType = addContentEntryType2;
|
|
38
41
|
const hooks = {
|
|
39
42
|
config: updatedConfig,
|
|
40
43
|
command,
|
|
@@ -66,11 +69,19 @@ async function runHookConfigSetup({
|
|
|
66
69
|
writable: false,
|
|
67
70
|
enumerable: false
|
|
68
71
|
});
|
|
72
|
+
Object.defineProperty(hooks, "addContentEntryType", {
|
|
73
|
+
value: addContentEntryType2,
|
|
74
|
+
writable: false,
|
|
75
|
+
enumerable: false
|
|
76
|
+
});
|
|
69
77
|
await withTakingALongTimeMsg({
|
|
70
78
|
name: integration.name,
|
|
71
79
|
hookResult: integration.hooks["astro:config:setup"](hooks),
|
|
72
80
|
logging
|
|
73
81
|
});
|
|
82
|
+
if (integration.name === "@astrojs/mdx" && !updatedSettings.contentEntryTypes.find((c) => c.extensions.includes(".mdx"))) {
|
|
83
|
+
addContentEntryType2(mdxContentEntryType);
|
|
84
|
+
}
|
|
74
85
|
}
|
|
75
86
|
}
|
|
76
87
|
updatedSettings.config = updatedConfig;
|
|
@@ -194,10 +194,17 @@ Did you forget to import the component or is it possible there is a typo?`);
|
|
|
194
194
|
async function renderElement(result, tag, { children, ...props }) {
|
|
195
195
|
return markHTMLString(
|
|
196
196
|
`<${tag}${spreadAttributes(props)}${markHTMLString(
|
|
197
|
-
(children == null || children == "") && voidElementNames.test(tag) ? `/>` : `>${children == null ? "" : await renderJSX(result, children)}</${tag}>`
|
|
197
|
+
(children == null || children == "") && voidElementNames.test(tag) ? `/>` : `>${children == null ? "" : await renderJSX(result, prerenderElementChildren(tag, children))}</${tag}>`
|
|
198
198
|
)}`
|
|
199
199
|
);
|
|
200
200
|
}
|
|
201
|
+
function prerenderElementChildren(tag, children) {
|
|
202
|
+
if (typeof children === "string" && (tag === "style" || tag === "script")) {
|
|
203
|
+
return markHTMLString(children);
|
|
204
|
+
} else {
|
|
205
|
+
return children;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
201
208
|
function useConsoleFilter() {
|
|
202
209
|
consoleFilterRefs++;
|
|
203
210
|
if (!originalConsoleError) {
|
|
@@ -1,42 +1,23 @@
|
|
|
1
|
-
var __accessCheck = (obj, member, msg) => {
|
|
2
|
-
if (!member.has(obj))
|
|
3
|
-
throw TypeError("Cannot " + msg);
|
|
4
|
-
};
|
|
5
|
-
var __privateGet = (obj, member, getter) => {
|
|
6
|
-
__accessCheck(obj, member, "read from private field");
|
|
7
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
-
};
|
|
9
|
-
var __privateAdd = (obj, member, value) => {
|
|
10
|
-
if (member.has(obj))
|
|
11
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
-
};
|
|
14
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
-
__accessCheck(obj, member, "write to private field");
|
|
16
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
19
1
|
import { streamAsyncIterator } from "./util.js";
|
|
20
2
|
const isNodeJS = typeof process === "object" && Object.prototype.toString.call(process) === "[object process]";
|
|
21
3
|
let StreamingCompatibleResponse;
|
|
22
4
|
function createResponseClass() {
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
StreamingCompatibleResponse = class extends Response {
|
|
6
|
+
#isStream;
|
|
7
|
+
#body;
|
|
25
8
|
constructor(body, init) {
|
|
26
9
|
let isStream = body instanceof ReadableStream;
|
|
27
10
|
super(isStream ? null : body, init);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
__privateSet(this, _isStream, isStream);
|
|
31
|
-
__privateSet(this, _body, body);
|
|
11
|
+
this.#isStream = isStream;
|
|
12
|
+
this.#body = body;
|
|
32
13
|
}
|
|
33
14
|
get body() {
|
|
34
|
-
return
|
|
15
|
+
return this.#body;
|
|
35
16
|
}
|
|
36
17
|
async text() {
|
|
37
|
-
if (
|
|
18
|
+
if (this.#isStream && isNodeJS) {
|
|
38
19
|
let decoder = new TextDecoder();
|
|
39
|
-
let body =
|
|
20
|
+
let body = this.#body;
|
|
40
21
|
let out = "";
|
|
41
22
|
for await (let chunk of streamAsyncIterator(body)) {
|
|
42
23
|
out += decoder.decode(chunk);
|
|
@@ -46,8 +27,8 @@ function createResponseClass() {
|
|
|
46
27
|
return super.text();
|
|
47
28
|
}
|
|
48
29
|
async arrayBuffer() {
|
|
49
|
-
if (
|
|
50
|
-
let body =
|
|
30
|
+
if (this.#isStream && isNodeJS) {
|
|
31
|
+
let body = this.#body;
|
|
51
32
|
let chunks = [];
|
|
52
33
|
let len = 0;
|
|
53
34
|
for await (let chunk of streamAsyncIterator(body)) {
|
|
@@ -64,7 +45,7 @@ function createResponseClass() {
|
|
|
64
45
|
}
|
|
65
46
|
return super.arrayBuffer();
|
|
66
47
|
}
|
|
67
|
-
}
|
|
48
|
+
};
|
|
68
49
|
return StreamingCompatibleResponse;
|
|
69
50
|
}
|
|
70
51
|
const createResponse = isNodeJS ? (body, init) => {
|
|
@@ -25,7 +25,7 @@ function astro(_opts) {
|
|
|
25
25
|
const firstArgEnd = node.arguments[0].end;
|
|
26
26
|
const lastArgEnd = node.arguments[node.arguments.length - 1].end;
|
|
27
27
|
const firstArg = code.slice(firstArgStart, firstArgEnd);
|
|
28
|
-
s
|
|
28
|
+
s ??= new MagicString(code);
|
|
29
29
|
s.overwrite(
|
|
30
30
|
firstArgStart,
|
|
31
31
|
lastArgEnd,
|
|
@@ -33,7 +33,7 @@ function createVitePluginAstroServer({
|
|
|
33
33
|
handle: baseMiddleware(settings, logging)
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
viteServer.middlewares.use(async (req, res)
|
|
36
|
+
viteServer.middlewares.use(async function astroDevHandler(req, res) {
|
|
37
37
|
if (req.url === void 0 || !req.method) {
|
|
38
38
|
res.writeHead(500, "Incomplete request");
|
|
39
39
|
res.end();
|
|
@@ -59,21 +59,21 @@ function envVitePlugin({ settings }) {
|
|
|
59
59
|
while (match = pattern.exec(source)) {
|
|
60
60
|
let replacement;
|
|
61
61
|
if (match[0] === "import.meta.env") {
|
|
62
|
-
privateEnv
|
|
63
|
-
references
|
|
62
|
+
privateEnv ??= getPrivateEnv(viteConfig, astroConfig);
|
|
63
|
+
references ??= getReferencedPrivateKeys(source, privateEnv);
|
|
64
64
|
replacement = `(Object.assign(import.meta.env,{`;
|
|
65
65
|
for (const key of references.values()) {
|
|
66
66
|
replacement += `${key}:${privateEnv[key]},`;
|
|
67
67
|
}
|
|
68
68
|
replacement += "}))";
|
|
69
69
|
} else if (match[2]) {
|
|
70
|
-
privateEnv
|
|
70
|
+
privateEnv ??= getPrivateEnv(viteConfig, astroConfig);
|
|
71
71
|
replacement = privateEnv[match[2]];
|
|
72
72
|
}
|
|
73
73
|
if (replacement) {
|
|
74
74
|
const start = match.index;
|
|
75
75
|
const end = start + match[0].length;
|
|
76
|
-
s
|
|
76
|
+
s ??= new MagicString(source);
|
|
77
77
|
s.overwrite(start, end, replacement);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -32,9 +32,22 @@ async function setUpEnvTs({
|
|
|
32
32
|
path.relative(fileURLToPath(settings.config.root), fileURLToPath(envTsPath))
|
|
33
33
|
);
|
|
34
34
|
if (fs.existsSync(envTsPath)) {
|
|
35
|
+
let typesEnvContents = await fs.promises.readFile(envTsPath, "utf-8");
|
|
36
|
+
if (settings.config.experimental.assets && typesEnvContents.includes('types="astro/client"')) {
|
|
37
|
+
typesEnvContents = typesEnvContents.replace(
|
|
38
|
+
'types="astro/client"',
|
|
39
|
+
'types="astro/client-image"'
|
|
40
|
+
);
|
|
41
|
+
await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
|
|
42
|
+
} else if (typesEnvContents.includes('types="astro/client-image"')) {
|
|
43
|
+
typesEnvContents = typesEnvContents.replace(
|
|
44
|
+
'types="astro/client-image"',
|
|
45
|
+
'types="astro/client"'
|
|
46
|
+
);
|
|
47
|
+
await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
|
|
48
|
+
}
|
|
35
49
|
if (!fs.existsSync(dotAstroDir))
|
|
36
50
|
return;
|
|
37
|
-
let typesEnvContents = await fs.promises.readFile(envTsPath, "utf-8");
|
|
38
51
|
const expectedTypeReference = getDotAstroTypeReference(settings.config);
|
|
39
52
|
if (!typesEnvContents.includes(expectedTypeReference)) {
|
|
40
53
|
typesEnvContents = `${expectedTypeReference}
|
|
@@ -44,7 +57,9 @@ ${typesEnvContents}`;
|
|
|
44
57
|
}
|
|
45
58
|
} else {
|
|
46
59
|
let referenceDefs = [];
|
|
47
|
-
if (settings.config.
|
|
60
|
+
if (settings.config.experimental.assets) {
|
|
61
|
+
referenceDefs.push('/// <reference types="astro/client-image" />');
|
|
62
|
+
} else if (settings.config.integrations.find((i) => i.name === "@astrojs/image")) {
|
|
48
63
|
referenceDefs.push('/// <reference types="@astrojs/image/client" />');
|
|
49
64
|
} else {
|
|
50
65
|
referenceDefs.push('/// <reference types="astro/client" />');
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContentEntryType } from '../@types/astro.js';
|
|
2
|
+
export declare const markdownContentEntryType: ContentEntryType;
|
|
3
|
+
/**
|
|
4
|
+
* MDX content type for compatibility with older `@astrojs/mdx` versions
|
|
5
|
+
* TODO: remove in next Astro minor release
|
|
6
|
+
*/
|
|
7
|
+
export declare const mdxContentEntryType: ContentEntryType;
|