astro 5.4.2 → 5.4.3
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/client.d.ts +2 -2
- package/dist/assets/utils/imageKind.d.ts +18 -0
- package/dist/assets/utils/imageKind.js +5 -1
- package/dist/assets/utils/index.d.ts +6 -1
- package/dist/assets/utils/index.js +0 -2
- package/dist/assets/utils/metadata.d.ts +8 -0
- package/dist/assets/utils/metadata.js +16 -15
- package/dist/assets/utils/node/emitAsset.d.ts +9 -0
- package/dist/assets/utils/node/emitAsset.js +1 -1
- package/dist/assets/utils/queryParams.d.ts +9 -0
- package/dist/assets/utils/remoteProbe.d.ts +7 -0
- package/dist/assets/utils/transformToPath.d.ts +30 -0
- package/dist/cli/add/index.js +44 -73
- package/dist/cli/install-package.d.ts +0 -6
- package/dist/cli/install-package.js +17 -54
- package/dist/content/content-layer.js +3 -3
- package/dist/core/build/plugins/plugin-css.js +1 -27
- package/dist/core/build/static-build.js +9 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +11 -11
- package/dist/core/errors/errors-data.js +5 -5
- package/dist/core/messages.js +6 -5
- package/dist/transitions/router.js +3 -1
- package/dist/vite-plugin-astro/index.d.ts +2 -2
- package/dist/vite-plugin-astro/index.js +3 -9
- package/dist/vite-plugin-astro/types.d.ts +0 -20
- package/package.json +4 -5
package/client.d.ts
CHANGED
|
@@ -193,14 +193,14 @@ declare module 'astro:config/server' {
|
|
|
193
193
|
// biome-ignore format: bug
|
|
194
194
|
type ServerConfigSerialized = import('./dist/types/public/manifest.js').ServerDeserializedManifest;
|
|
195
195
|
const manifest: ServerConfigSerialized;
|
|
196
|
-
export
|
|
196
|
+
export = manifest;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
declare module 'astro:config/client' {
|
|
200
200
|
// biome-ignore format: bug
|
|
201
201
|
type ClientConfigSerialized = import('./dist/types/public/manifest.js').ClientDeserializedManifest;
|
|
202
202
|
const manifest: ClientConfigSerialized;
|
|
203
|
-
export
|
|
203
|
+
export = manifest;
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
declare module 'astro:components' {
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import type { ImageMetadata, UnresolvedImageTransform } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Determines if the given source is an ECMAScript Module (ESM) imported image.
|
|
4
|
+
*
|
|
5
|
+
* @param {ImageMetadata | string} src - The source to check. It can be an `ImageMetadata` object or a string.
|
|
6
|
+
* @return {boolean} Returns `true` if the source is an `ImageMetadata` object, otherwise `false`.
|
|
7
|
+
*/
|
|
2
8
|
export declare function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata;
|
|
9
|
+
/**
|
|
10
|
+
* Determines if the provided source is a remote image URL in the form of a string.
|
|
11
|
+
*
|
|
12
|
+
* @param {ImageMetadata | string} src - The source to check, which can either be an `ImageMetadata` object or a string.
|
|
13
|
+
* @return {boolean} Returns `true` if the source is a string, otherwise `false`.
|
|
14
|
+
*/
|
|
3
15
|
export declare function isRemoteImage(src: ImageMetadata | string): src is string;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the source of an image transformation by handling asynchronous or synchronous inputs.
|
|
18
|
+
*
|
|
19
|
+
* @param {UnresolvedImageTransform['src']} src - The source of the image transformation.
|
|
20
|
+
* @return {Promise<string | ImageMetadata>} A promise that resolves to the image source. It returns either the default export of the resolved source or the resolved source itself if the default export doesn't exist.
|
|
21
|
+
*/
|
|
4
22
|
export declare function resolveSrc(src: UnresolvedImageTransform['src']): Promise<string | ImageMetadata>;
|
|
@@ -5,7 +5,11 @@ function isRemoteImage(src) {
|
|
|
5
5
|
return typeof src === "string";
|
|
6
6
|
}
|
|
7
7
|
async function resolveSrc(src) {
|
|
8
|
-
|
|
8
|
+
if (typeof src === "object" && "then" in src) {
|
|
9
|
+
const resource = await src;
|
|
10
|
+
return resource.default ?? resource;
|
|
11
|
+
}
|
|
12
|
+
return src;
|
|
9
13
|
}
|
|
10
14
|
export {
|
|
11
15
|
isESMImportedImage,
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NOTE: this is a public module exposed to the user, so all functions exposed
|
|
3
|
+
* here must be documented via JsDoc and in the docs website.
|
|
4
|
+
*
|
|
5
|
+
* If some functions don't need to be exposed, just import the file that contains the functions.
|
|
6
|
+
*/
|
|
1
7
|
export { emitESMImage } from './node/emitAsset.js';
|
|
2
8
|
export { isESMImportedImage, isRemoteImage } from './imageKind.js';
|
|
3
9
|
export { imageMetadata } from './metadata.js';
|
|
4
10
|
export { getOrigQueryParams } from './queryParams.js';
|
|
5
11
|
export { hashTransform, propsToFilename } from './transformToPath.js';
|
|
6
12
|
export { inferRemoteSize } from './remoteProbe.js';
|
|
7
|
-
export { makeSvgComponent } from './svg.js';
|
|
8
13
|
export { isRemoteAllowed, matchHostname, matchPathname, matchPattern, matchPort, matchProtocol, type RemotePattern, } from './remotePattern.js';
|
|
@@ -4,7 +4,6 @@ import { imageMetadata } from "./metadata.js";
|
|
|
4
4
|
import { getOrigQueryParams } from "./queryParams.js";
|
|
5
5
|
import { hashTransform, propsToFilename } from "./transformToPath.js";
|
|
6
6
|
import { inferRemoteSize } from "./remoteProbe.js";
|
|
7
|
-
import { makeSvgComponent } from "./svg.js";
|
|
8
7
|
import {
|
|
9
8
|
isRemoteAllowed,
|
|
10
9
|
matchHostname,
|
|
@@ -22,7 +21,6 @@ export {
|
|
|
22
21
|
isESMImportedImage,
|
|
23
22
|
isRemoteAllowed,
|
|
24
23
|
isRemoteImage,
|
|
25
|
-
makeSvgComponent,
|
|
26
24
|
matchHostname,
|
|
27
25
|
matchPathname,
|
|
28
26
|
matchPattern,
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import type { ImageMetadata } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts image metadata such as dimensions, format, and orientation from the provided image data.
|
|
4
|
+
*
|
|
5
|
+
* @param {Uint8Array} data - The binary data of the image.
|
|
6
|
+
* @param {string} [src] - The source path or URL of the image, used for error messages. Optional.
|
|
7
|
+
* @return {Promise<Omit<ImageMetadata, 'src' | 'fsPath'>>} A promise that resolves with the extracted metadata, excluding `src` and `fsPath`.
|
|
8
|
+
* @throws {AstroError} Throws an error if the image metadata cannot be extracted.
|
|
9
|
+
*/
|
|
2
10
|
export declare function imageMetadata(data: Uint8Array, src?: string): Promise<Omit<ImageMetadata, 'src' | 'fsPath'>>;
|
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
|
2
2
|
import { lookup as probe } from "../utils/vendor/image-size/lookup.js";
|
|
3
3
|
async function imageMetadata(data, src) {
|
|
4
|
+
let result;
|
|
4
5
|
try {
|
|
5
|
-
|
|
6
|
-
if (!result.height || !result.width || !result.type) {
|
|
7
|
-
throw new AstroError({
|
|
8
|
-
...AstroErrorData.NoImageMetadata,
|
|
9
|
-
message: AstroErrorData.NoImageMetadata.message(src)
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
const { width, height, type, orientation } = result;
|
|
13
|
-
const isPortrait = (orientation || 0) >= 5;
|
|
14
|
-
return {
|
|
15
|
-
width: isPortrait ? height : width,
|
|
16
|
-
height: isPortrait ? width : height,
|
|
17
|
-
format: type,
|
|
18
|
-
orientation
|
|
19
|
-
};
|
|
6
|
+
result = probe(data);
|
|
20
7
|
} catch {
|
|
21
8
|
throw new AstroError({
|
|
22
9
|
...AstroErrorData.NoImageMetadata,
|
|
23
10
|
message: AstroErrorData.NoImageMetadata.message(src)
|
|
24
11
|
});
|
|
25
12
|
}
|
|
13
|
+
if (!result.height || !result.width || !result.type) {
|
|
14
|
+
throw new AstroError({
|
|
15
|
+
...AstroErrorData.NoImageMetadata,
|
|
16
|
+
message: AstroErrorData.NoImageMetadata.message(src)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const { width, height, type, orientation } = result;
|
|
20
|
+
const isPortrait = (orientation || 0) >= 5;
|
|
21
|
+
return {
|
|
22
|
+
width: isPortrait ? height : width,
|
|
23
|
+
height: isPortrait ? width : height,
|
|
24
|
+
format: type,
|
|
25
|
+
orientation
|
|
26
|
+
};
|
|
26
27
|
}
|
|
27
28
|
export {
|
|
28
29
|
imageMetadata
|
|
@@ -4,6 +4,15 @@ type FileEmitter = vite.Rollup.EmitFile;
|
|
|
4
4
|
type ImageMetadataWithContents = ImageMetadata & {
|
|
5
5
|
contents?: Buffer;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Processes an image file and emits its metadata and optionally its contents. This function supports both build and development modes.
|
|
9
|
+
*
|
|
10
|
+
* @param {string | undefined} id - The identifier or path of the image file to process. If undefined, the function returns immediately.
|
|
11
|
+
* @param {boolean} _watchMode - **Deprecated**: Indicates if the method is operating in watch mode. This parameter will be removed or updated in the future.
|
|
12
|
+
* @param {boolean} experimentalSvgEnabled - A flag to enable experimental handling of SVG files. Embeds SVG file data if set to true.
|
|
13
|
+
* @param {FileEmitter | undefined} [fileEmitter] - Function for emitting files during the build process. May throw in certain scenarios.
|
|
14
|
+
* @return {Promise<ImageMetadataWithContents | undefined>} Resolves to metadata with optional image contents or `undefined` if processing fails.
|
|
15
|
+
*/
|
|
7
16
|
export declare function emitESMImage(id: string | undefined,
|
|
8
17
|
/** @deprecated */
|
|
9
18
|
_watchMode: boolean, experimentalSvgEnabled: boolean, fileEmitter?: FileEmitter): Promise<ImageMetadataWithContents | undefined>;
|
|
@@ -24,7 +24,7 @@ async function emitESMImage(id, _watchMode, experimentalSvgEnabled, fileEmitter)
|
|
|
24
24
|
writable: false,
|
|
25
25
|
value: id
|
|
26
26
|
});
|
|
27
|
-
if (fileMetadata.format === "svg" && experimentalSvgEnabled
|
|
27
|
+
if (fileMetadata.format === "svg" && experimentalSvgEnabled) {
|
|
28
28
|
emittedImage.contents = fileData;
|
|
29
29
|
}
|
|
30
30
|
let isBuild = typeof fileEmitter === "function";
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import type { ImageMetadata } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the original image query parameters (width, height, format) from the given `URLSearchParams` object
|
|
4
|
+
* and returns them as an object. If any of the required parameters are missing or invalid, the function returns undefined.
|
|
5
|
+
*
|
|
6
|
+
* The `width` and `height` are parsed to integer values.
|
|
7
|
+
*
|
|
8
|
+
* @param {URLSearchParams} params - The `URLSearchParams` object containing the query parameters.
|
|
9
|
+
* @return {Pick<ImageMetadata, 'width' | 'height' | 'format'> | undefined} An object with the original image parameters (width, height, format) or undefined if any parameter is missing.
|
|
10
|
+
*/
|
|
2
11
|
export declare function getOrigQueryParams(params: URLSearchParams): Pick<ImageMetadata, 'width' | 'height' | 'format'> | undefined;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import type { ImageMetadata } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Infers the dimensions of a remote image by streaming its data and analyzing it progressively until sufficient metadata is available.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} url - The URL of the remote image from which to infer size metadata.
|
|
6
|
+
* @return {Promise<Omit<ImageMetadata, 'src' | 'fsPath'>>} Returns a promise that resolves to an object containing the image dimensions metadata excluding `src` and `fsPath`.
|
|
7
|
+
* @throws {AstroError} Thrown when the fetching fails or metadata cannot be extracted.
|
|
8
|
+
*/
|
|
2
9
|
export declare function inferRemoteSize(url: string): Promise<Omit<ImageMetadata, 'src' | 'fsPath'>>;
|
|
@@ -1,3 +1,33 @@
|
|
|
1
1
|
import type { ImageTransform } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a file path and transformation properties of the transformation image service, into a formatted filename.
|
|
4
|
+
*
|
|
5
|
+
* The formatted filename follows this structure:
|
|
6
|
+
*
|
|
7
|
+
* `<prefixDirname>/<baseFilename>_<hash><outputExtension>`
|
|
8
|
+
*
|
|
9
|
+
* - `prefixDirname`: If the image is an ESM imported image, this is the directory name of the original file path; otherwise, it will be an empty string.
|
|
10
|
+
* - `baseFilename`: The base name of the file or a hashed short name if the file is a `data:` URI.
|
|
11
|
+
* - `hash`: A unique hash string generated to distinguish the transformed file.
|
|
12
|
+
* - `outputExtension`: The desired output file extension derived from the `transform.format` or the original file extension.
|
|
13
|
+
*
|
|
14
|
+
* ## Example
|
|
15
|
+
* - Input: `filePath = '/images/photo.jpg'`, `transform = { format: 'png', src: '/images/photo.jpg' }`, `hash = 'abcd1234'`.
|
|
16
|
+
* - Output: `/images/photo_abcd1234.png`
|
|
17
|
+
*
|
|
18
|
+
* @param {string} filePath - The original file path or data URI of the source image.
|
|
19
|
+
* @param {ImageTransform} transform - An object representing the transformation properties, including format and source.
|
|
20
|
+
* @param {string} hash - A unique hash used to differentiate the transformed file.
|
|
21
|
+
* @return {string} The generated filename based on the provided input, transformations, and hash.
|
|
22
|
+
*/
|
|
2
23
|
export declare function propsToFilename(filePath: string, transform: ImageTransform, hash: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Transforms the provided `transform` object into a hash string based on selected properties
|
|
26
|
+
* and the specified `imageService`.
|
|
27
|
+
*
|
|
28
|
+
* @param {ImageTransform} transform - The transform object containing various image transformation properties.
|
|
29
|
+
* @param {string} imageService - The name of the image service related to the transform.
|
|
30
|
+
* @param {string[]} propertiesToHash - An array of property names from the `transform` object that should be used to generate the hash.
|
|
31
|
+
* @return {string} A hashed string created from the specified properties of the `transform` object and the image service.
|
|
32
|
+
*/
|
|
3
33
|
export declare function hashTransform(transform: ImageTransform, imageService: string, propertiesToHash: string[]): string;
|
package/dist/cli/add/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { diffWords } from "diff";
|
|
|
6
6
|
import { bold, cyan, dim, green, magenta, red, yellow } from "kleur/colors";
|
|
7
7
|
import { builders, generateCode, loadFile } from "magicast";
|
|
8
8
|
import { getDefaultExportOptions } from "magicast/helpers";
|
|
9
|
-
import
|
|
9
|
+
import { detect, resolveCommand } from "package-manager-detector";
|
|
10
10
|
import prompts from "prompts";
|
|
11
11
|
import maxSatisfying from "semver/ranges/max-satisfying.js";
|
|
12
12
|
import yoctoSpinner from "yocto-spinner";
|
|
@@ -190,7 +190,7 @@ async function add(names, { flags }) {
|
|
|
190
190
|
logger.debug("add", `Using existing db configuration`);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
if (integrations.find((integration) => integration.id === "lit") && (await
|
|
193
|
+
if (integrations.find((integration) => integration.id === "lit") && (await detect({ cwd: fileURLToPath(root) }))?.name === "pnpm") {
|
|
194
194
|
await setupIntegrationConfig({
|
|
195
195
|
root,
|
|
196
196
|
logger,
|
|
@@ -494,28 +494,6 @@ ${message}`
|
|
|
494
494
|
return 2 /* cancelled */;
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
|
-
async function getInstallIntegrationsCommand({
|
|
498
|
-
integrations,
|
|
499
|
-
logger,
|
|
500
|
-
cwd = process.cwd()
|
|
501
|
-
}) {
|
|
502
|
-
const pm = await preferredPM(cwd);
|
|
503
|
-
logger.debug("add", `package manager: ${JSON.stringify(pm)}`);
|
|
504
|
-
if (!pm) return null;
|
|
505
|
-
const dependencies = await convertIntegrationsToInstallSpecifiers(integrations);
|
|
506
|
-
switch (pm.name) {
|
|
507
|
-
case "npm":
|
|
508
|
-
return { pm: "npm", command: "install", flags: [], dependencies };
|
|
509
|
-
case "yarn":
|
|
510
|
-
return { pm: "yarn", command: "add", flags: [], dependencies };
|
|
511
|
-
case "pnpm":
|
|
512
|
-
return { pm: "pnpm", command: "add", flags: [], dependencies };
|
|
513
|
-
case "bun":
|
|
514
|
-
return { pm: "bun", command: "add", flags: [], dependencies };
|
|
515
|
-
default:
|
|
516
|
-
return null;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
497
|
async function convertIntegrationsToInstallSpecifiers(integrations) {
|
|
520
498
|
const ranges = {};
|
|
521
499
|
for (let { dependencies } of integrations) {
|
|
@@ -550,7 +528,14 @@ async function tryToInstallIntegrations({
|
|
|
550
528
|
flags,
|
|
551
529
|
logger
|
|
552
530
|
}) {
|
|
553
|
-
const
|
|
531
|
+
const packageManager = await detect({
|
|
532
|
+
cwd,
|
|
533
|
+
// Include the `install-metadata` strategy to have the package manager that's
|
|
534
|
+
// used for installation take precedence
|
|
535
|
+
strategies: ["install-metadata", "lockfile", "packageManager-field"]
|
|
536
|
+
});
|
|
537
|
+
logger.debug("add", `package manager: "${packageManager?.name}"`);
|
|
538
|
+
if (!packageManager) return 0 /* none */;
|
|
554
539
|
const inheritedFlags = Object.entries(flags).map(([flag]) => {
|
|
555
540
|
if (flag == "_") return;
|
|
556
541
|
if (INHERITED_FLAGS.has(flag)) {
|
|
@@ -558,60 +543,46 @@ async function tryToInstallIntegrations({
|
|
|
558
543
|
return `--${flag}`;
|
|
559
544
|
}
|
|
560
545
|
}).filter(Boolean).flat();
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
...installCommand.flags,
|
|
567
|
-
...inheritedFlags
|
|
568
|
-
].join(" ")} ${cyan(installCommand.dependencies.join(" "))}`;
|
|
569
|
-
const message = `
|
|
546
|
+
const installCommand = resolveCommand(packageManager?.agent ?? "npm", "add", inheritedFlags);
|
|
547
|
+
if (!installCommand) return 0 /* none */;
|
|
548
|
+
const installSpecifiers = await convertIntegrationsToInstallSpecifiers(integrations);
|
|
549
|
+
const coloredOutput = `${bold(installCommand.command)} ${installCommand.args.join(" ")} ${cyan(installSpecifiers.join(" "))}`;
|
|
550
|
+
const message = `
|
|
570
551
|
${boxen(coloredOutput, {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
552
|
+
margin: 0.5,
|
|
553
|
+
padding: 0.5,
|
|
554
|
+
borderStyle: "round"
|
|
555
|
+
})}
|
|
575
556
|
`;
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
557
|
+
logger.info(
|
|
558
|
+
"SKIP_FORMAT",
|
|
559
|
+
`
|
|
579
560
|
${magenta("Astro will run the following command:")}
|
|
580
561
|
${dim(
|
|
581
|
-
|
|
582
|
-
|
|
562
|
+
"If you skip this step, you can always run it yourself later"
|
|
563
|
+
)}
|
|
583
564
|
${message}`
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
);
|
|
604
|
-
spinner.success();
|
|
605
|
-
return 1 /* updated */;
|
|
606
|
-
} catch (err) {
|
|
607
|
-
spinner.error();
|
|
608
|
-
logger.debug("add", "Error installing dependencies", err);
|
|
609
|
-
console.error("\n", err.stdout || err.message, "\n");
|
|
610
|
-
return 3 /* failure */;
|
|
611
|
-
}
|
|
612
|
-
} else {
|
|
613
|
-
return 2 /* cancelled */;
|
|
565
|
+
);
|
|
566
|
+
if (await askToContinue({ flags })) {
|
|
567
|
+
const spinner = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
|
568
|
+
try {
|
|
569
|
+
await exec(installCommand.command, [...installCommand.args, ...installSpecifiers], {
|
|
570
|
+
nodeOptions: {
|
|
571
|
+
cwd,
|
|
572
|
+
// reset NODE_ENV to ensure install command run in dev mode
|
|
573
|
+
env: { NODE_ENV: void 0 }
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
spinner.success();
|
|
577
|
+
return 1 /* updated */;
|
|
578
|
+
} catch (err) {
|
|
579
|
+
spinner.error();
|
|
580
|
+
logger.debug("add", "Error installing dependencies", err);
|
|
581
|
+
console.error("\n", err.stdout || err.message, "\n");
|
|
582
|
+
return 3 /* failure */;
|
|
614
583
|
}
|
|
584
|
+
} else {
|
|
585
|
+
return 2 /* cancelled */;
|
|
615
586
|
}
|
|
616
587
|
}
|
|
617
588
|
async function validateIntegrations(integrations) {
|
|
@@ -5,12 +5,6 @@ type GetPackageOptions = {
|
|
|
5
5
|
cwd?: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function getPackage<T>(packageName: string, logger: Logger, options: GetPackageOptions, otherDeps?: string[]): Promise<T | undefined>;
|
|
8
|
-
/**
|
|
9
|
-
* Get the command to execute and download a package (e.g. `npx`, `yarn dlx`, `pnpm dlx`, etc.)
|
|
10
|
-
* @param packageManager - Optional package manager to use. If not provided, Astro will attempt to detect the preferred package manager.
|
|
11
|
-
* @returns The command to execute and download a package
|
|
12
|
-
*/
|
|
13
|
-
export declare function getExecCommand(packageManager?: string): Promise<string>;
|
|
14
8
|
export declare function fetchPackageJson(scope: string | undefined, name: string, tag: string): Promise<Record<string, any> | Error>;
|
|
15
9
|
export declare function fetchPackageVersions(packageName: string): Promise<string[] | Error>;
|
|
16
10
|
export {};
|
|
@@ -2,9 +2,8 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import boxen from "boxen";
|
|
3
3
|
import ci from "ci-info";
|
|
4
4
|
import { bold, cyan, dim, magenta } from "kleur/colors";
|
|
5
|
-
import
|
|
5
|
+
import { detect, resolveCommand } from "package-manager-detector";
|
|
6
6
|
import prompts from "prompts";
|
|
7
|
-
import whichPm from "which-pm";
|
|
8
7
|
import yoctoSpinner from "yocto-spinner";
|
|
9
8
|
import { exec } from "./exec.js";
|
|
10
9
|
const require2 = createRequire(import.meta.url);
|
|
@@ -34,48 +33,17 @@ async function getPackage(packageName, logger, options, otherDeps = []) {
|
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
|
-
function getInstallCommand(packages, packageManager) {
|
|
38
|
-
switch (packageManager) {
|
|
39
|
-
case "npm":
|
|
40
|
-
return { pm: "npm", command: "install", flags: [], dependencies: packages };
|
|
41
|
-
case "yarn":
|
|
42
|
-
return { pm: "yarn", command: "add", flags: [], dependencies: packages };
|
|
43
|
-
case "pnpm":
|
|
44
|
-
return { pm: "pnpm", command: "add", flags: [], dependencies: packages };
|
|
45
|
-
case "bun":
|
|
46
|
-
return { pm: "bun", command: "add", flags: [], dependencies: packages };
|
|
47
|
-
default:
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
async function getExecCommand(packageManager) {
|
|
52
|
-
if (!packageManager) {
|
|
53
|
-
packageManager = (await preferredPM(process.cwd()))?.name ?? "npm";
|
|
54
|
-
}
|
|
55
|
-
switch (packageManager) {
|
|
56
|
-
case "npm":
|
|
57
|
-
return "npx";
|
|
58
|
-
case "yarn":
|
|
59
|
-
return "yarn dlx";
|
|
60
|
-
case "pnpm":
|
|
61
|
-
return "pnpm dlx";
|
|
62
|
-
case "bun":
|
|
63
|
-
return "bunx";
|
|
64
|
-
default:
|
|
65
|
-
return "npx";
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
36
|
async function installPackage(packageNames, options, logger) {
|
|
69
37
|
const cwd = options.cwd ?? process.cwd();
|
|
70
|
-
const packageManager =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
38
|
+
const packageManager = await detect({
|
|
39
|
+
cwd,
|
|
40
|
+
// Include the `install-metadata` strategy to have the package manager that's
|
|
41
|
+
// used for installation take precedence
|
|
42
|
+
strategies: ["install-metadata", "lockfile", "packageManager-field"]
|
|
43
|
+
});
|
|
44
|
+
const installCommand = resolveCommand(packageManager?.agent ?? "npm", "add", []);
|
|
45
|
+
if (!installCommand) return false;
|
|
46
|
+
const coloredOutput = `${bold(installCommand.command)} ${installCommand.args.join(" ")} ${cyan(packageNames.join(" "))}`;
|
|
79
47
|
const message = `
|
|
80
48
|
${boxen(coloredOutput, {
|
|
81
49
|
margin: 0.5,
|
|
@@ -106,17 +74,13 @@ ${message}`
|
|
|
106
74
|
if (Boolean(response)) {
|
|
107
75
|
const spinner = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
|
108
76
|
try {
|
|
109
|
-
await exec(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
cwd,
|
|
115
|
-
// reset NODE_ENV to ensure install command run in dev mode
|
|
116
|
-
env: { NODE_ENV: void 0 }
|
|
117
|
-
}
|
|
77
|
+
await exec(installCommand.command, [...installCommand.args, ...packageNames], {
|
|
78
|
+
nodeOptions: {
|
|
79
|
+
cwd,
|
|
80
|
+
// reset NODE_ENV to ensure install command run in dev mode
|
|
81
|
+
env: { NODE_ENV: void 0 }
|
|
118
82
|
}
|
|
119
|
-
);
|
|
83
|
+
});
|
|
120
84
|
spinner.success();
|
|
121
85
|
return true;
|
|
122
86
|
} catch (err) {
|
|
@@ -157,7 +121,7 @@ let _registry;
|
|
|
157
121
|
async function getRegistry() {
|
|
158
122
|
if (_registry) return _registry;
|
|
159
123
|
const fallback = "https://registry.npmjs.org";
|
|
160
|
-
const packageManager = (await
|
|
124
|
+
const packageManager = (await detect())?.name || "npm";
|
|
161
125
|
try {
|
|
162
126
|
const { stdout } = await exec(packageManager, ["config", "get", "registry"]);
|
|
163
127
|
_registry = stdout.trim()?.replace(/\/$/, "") || fallback;
|
|
@@ -170,6 +134,5 @@ async function getRegistry() {
|
|
|
170
134
|
export {
|
|
171
135
|
fetchPackageJson,
|
|
172
136
|
fetchPackageVersions,
|
|
173
|
-
getExecCommand,
|
|
174
137
|
getPackage
|
|
175
138
|
};
|
|
@@ -153,7 +153,7 @@ ${contentConfig.error.message}`);
|
|
|
153
153
|
logger.info("Content config changed");
|
|
154
154
|
shouldClear = true;
|
|
155
155
|
}
|
|
156
|
-
if (previousAstroVersion && previousAstroVersion !== "5.4.
|
|
156
|
+
if (previousAstroVersion && previousAstroVersion !== "5.4.3") {
|
|
157
157
|
logger.info("Astro version changed");
|
|
158
158
|
shouldClear = true;
|
|
159
159
|
}
|
|
@@ -161,8 +161,8 @@ ${contentConfig.error.message}`);
|
|
|
161
161
|
logger.info("Clearing content store");
|
|
162
162
|
this.#store.clearAll();
|
|
163
163
|
}
|
|
164
|
-
if ("5.4.
|
|
165
|
-
await this.#store.metaStore().set("astro-version", "5.4.
|
|
164
|
+
if ("5.4.3") {
|
|
165
|
+
await this.#store.metaStore().set("astro-version", "5.4.3");
|
|
166
166
|
}
|
|
167
167
|
if (currentConfigDigest) {
|
|
168
168
|
await this.#store.metaStore().set("content-config-digest", currentConfigDigest);
|
|
@@ -101,22 +101,6 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
|
-
const cssScopeToPlugin = {
|
|
105
|
-
name: "astro:rollup-plugin-css-scope-to",
|
|
106
|
-
renderChunk(_, chunk, __, meta) {
|
|
107
|
-
for (const id in chunk.modules) {
|
|
108
|
-
const modMeta = this.getModuleInfo(id)?.meta;
|
|
109
|
-
const cssScopeTo = modMeta?.astroCss?.cssScopeTo;
|
|
110
|
-
if (cssScopeTo && !isCssScopeToRendered(cssScopeTo, Object.values(meta.chunks))) {
|
|
111
|
-
delete chunk.modules[id];
|
|
112
|
-
const moduleIdsIndex = chunk.moduleIds.indexOf(id);
|
|
113
|
-
if (moduleIdsIndex > -1) {
|
|
114
|
-
chunk.moduleIds.splice(moduleIdsIndex, 1);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
104
|
const singleCssPlugin = {
|
|
121
105
|
name: "astro:rollup-plugin-single-css",
|
|
122
106
|
enforce: "post",
|
|
@@ -178,7 +162,7 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
178
162
|
});
|
|
179
163
|
}
|
|
180
164
|
};
|
|
181
|
-
return [cssBuildPlugin,
|
|
165
|
+
return [cssBuildPlugin, singleCssPlugin, inlineStylesheetsPlugin];
|
|
182
166
|
}
|
|
183
167
|
function* getParentClientOnlys(id, ctx, internals) {
|
|
184
168
|
for (const info of getParentModuleInfos(id, ctx)) {
|
|
@@ -203,16 +187,6 @@ function appendCSSToPage(pageData, meta, pagesToCss, depth, order) {
|
|
|
203
187
|
}
|
|
204
188
|
}
|
|
205
189
|
}
|
|
206
|
-
function isCssScopeToRendered(cssScopeTo, chunks) {
|
|
207
|
-
for (const moduleId in cssScopeTo) {
|
|
208
|
-
const exports = cssScopeTo[moduleId];
|
|
209
|
-
const renderedModule = chunks.find((c) => c.moduleIds.includes(moduleId))?.modules[moduleId];
|
|
210
|
-
if (renderedModule?.renderedExports.some((e) => exports.includes(e))) {
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
190
|
export {
|
|
217
191
|
pluginCSS
|
|
218
192
|
};
|
|
@@ -137,7 +137,15 @@ async function ssrBuild(opts, internals, input, container) {
|
|
|
137
137
|
const encoded = encodeName(name);
|
|
138
138
|
return [prefix, encoded, suffix].join("");
|
|
139
139
|
},
|
|
140
|
-
assetFileNames
|
|
140
|
+
assetFileNames(chunkInfo) {
|
|
141
|
+
const { names } = chunkInfo;
|
|
142
|
+
const name = names[0] ?? "";
|
|
143
|
+
if (name.includes(ASTRO_PAGE_EXTENSION_POST_PATTERN)) {
|
|
144
|
+
const [sanitizedName] = name.split(ASTRO_PAGE_EXTENSION_POST_PATTERN);
|
|
145
|
+
return `${settings.config.build.assets}/${sanitizedName}.[hash][extname]`;
|
|
146
|
+
}
|
|
147
|
+
return `${settings.config.build.assets}/[name].[hash][extname]`;
|
|
148
|
+
},
|
|
141
149
|
...viteConfig.build?.rollupOptions?.output,
|
|
142
150
|
entryFileNames(chunkInfo) {
|
|
143
151
|
if (chunkInfo.facadeModuleId?.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -22,7 +22,7 @@ async function dev(inlineConfig) {
|
|
|
22
22
|
await telemetry.record([]);
|
|
23
23
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
24
24
|
const logger = restart.container.logger;
|
|
25
|
-
const currentVersion = "5.4.
|
|
25
|
+
const currentVersion = "5.4.3";
|
|
26
26
|
const isPrerelease = currentVersion.includes("-");
|
|
27
27
|
if (!isPrerelease) {
|
|
28
28
|
try {
|
|
@@ -803,17 +803,6 @@ export declare const MiddlewareCantBeLoaded: {
|
|
|
803
803
|
title: string;
|
|
804
804
|
message: string;
|
|
805
805
|
};
|
|
806
|
-
/**
|
|
807
|
-
* @docs
|
|
808
|
-
* @description
|
|
809
|
-
* Thrown in development mode when the actions file can't be loaded.
|
|
810
|
-
*
|
|
811
|
-
*/
|
|
812
|
-
export declare const ActionsCantBeLoaded: {
|
|
813
|
-
name: string;
|
|
814
|
-
title: string;
|
|
815
|
-
message: string;
|
|
816
|
-
};
|
|
817
806
|
/**
|
|
818
807
|
* @docs
|
|
819
808
|
* @see
|
|
@@ -1604,6 +1593,17 @@ export declare const UnknownError: {
|
|
|
1604
1593
|
name: string;
|
|
1605
1594
|
title: string;
|
|
1606
1595
|
};
|
|
1596
|
+
/**
|
|
1597
|
+
* @docs
|
|
1598
|
+
* @description
|
|
1599
|
+
* Thrown in development mode when the actions file can't be loaded.
|
|
1600
|
+
*
|
|
1601
|
+
*/
|
|
1602
|
+
export declare const ActionsCantBeLoaded: {
|
|
1603
|
+
name: string;
|
|
1604
|
+
title: string;
|
|
1605
|
+
message: string;
|
|
1606
|
+
};
|
|
1607
1607
|
/**
|
|
1608
1608
|
* @docs
|
|
1609
1609
|
* @kind heading
|
|
@@ -285,11 +285,6 @@ const MiddlewareCantBeLoaded = {
|
|
|
285
285
|
title: "Can't load the middleware.",
|
|
286
286
|
message: "An unknown error was thrown while loading your middleware."
|
|
287
287
|
};
|
|
288
|
-
const ActionsCantBeLoaded = {
|
|
289
|
-
name: "ActionsCantBeLoaded",
|
|
290
|
-
title: "Can't load the Astro actions.",
|
|
291
|
-
message: "An unknown error was thrown while loading the Astro actions file."
|
|
292
|
-
};
|
|
293
288
|
const LocalImageUsedWrongly = {
|
|
294
289
|
name: "LocalImageUsedWrongly",
|
|
295
290
|
title: "Local images must be imported.",
|
|
@@ -638,6 +633,11 @@ const ActionCalledFromServerError = {
|
|
|
638
633
|
hint: "See the `Astro.callAction()` reference for usage examples: https://docs.astro.build/en/reference/api-reference/#callaction"
|
|
639
634
|
};
|
|
640
635
|
const UnknownError = { name: "UnknownError", title: "Unknown Error." };
|
|
636
|
+
const ActionsCantBeLoaded = {
|
|
637
|
+
name: "ActionsCantBeLoaded",
|
|
638
|
+
title: "Can't load the Astro actions.",
|
|
639
|
+
message: "An unknown error was thrown while loading the Astro actions file."
|
|
640
|
+
};
|
|
641
641
|
const SessionWithoutSupportedAdapterOutputError = {
|
|
642
642
|
name: "SessionWithoutSupportedAdapterOutputError",
|
|
643
643
|
title: "Sessions cannot be used with an adapter that doesn't support server output.",
|
package/dist/core/messages.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
underline,
|
|
15
15
|
yellow
|
|
16
16
|
} from "kleur/colors";
|
|
17
|
-
import {
|
|
17
|
+
import { detect, resolveCommand } from "package-manager-detector";
|
|
18
18
|
import { getDocsForError, renderErrorMarkdown } from "./errors/dev/utils.js";
|
|
19
19
|
import {
|
|
20
20
|
AstroError,
|
|
@@ -38,7 +38,7 @@ function serverStart({
|
|
|
38
38
|
host,
|
|
39
39
|
base
|
|
40
40
|
}) {
|
|
41
|
-
const version = "5.4.
|
|
41
|
+
const version = "5.4.3";
|
|
42
42
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
43
43
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
44
44
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -74,8 +74,9 @@ function serverShortcuts({ key, label }) {
|
|
|
74
74
|
async function newVersionAvailable({ latestVersion }) {
|
|
75
75
|
const badge = bgYellow(black(` update `));
|
|
76
76
|
const headline = yellow(`\u25B6 New version of Astro available: ${latestVersion}`);
|
|
77
|
-
const
|
|
78
|
-
const
|
|
77
|
+
const packageManager = (await detect())?.agent ?? "npm";
|
|
78
|
+
const execCommand = resolveCommand(packageManager, "execute", ["@astrojs/upgrade"]);
|
|
79
|
+
const details = !execCommand ? "" : ` Run ${cyan(`${execCommand.command} ${execCommand.args.join(" ")}`)} to update`;
|
|
79
80
|
return ["", `${badge} ${headline}`, details, ""].join("\n");
|
|
80
81
|
}
|
|
81
82
|
function telemetryNotice() {
|
|
@@ -281,7 +282,7 @@ function printHelp({
|
|
|
281
282
|
message.push(
|
|
282
283
|
linebreak(),
|
|
283
284
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
284
|
-
`v${"5.4.
|
|
285
|
+
`v${"5.4.3"}`
|
|
285
286
|
)} ${headline}`
|
|
286
287
|
);
|
|
287
288
|
}
|
|
@@ -327,7 +327,9 @@ async function transition(direction, from, to, options, historyState) {
|
|
|
327
327
|
skipTransition: () => {
|
|
328
328
|
currentTransition.transitionSkipped = true;
|
|
329
329
|
document.documentElement.removeAttribute(OLD_NEW_ATTR);
|
|
330
|
-
}
|
|
330
|
+
},
|
|
331
|
+
types: /* @__PURE__ */ new Set()
|
|
332
|
+
// empty by default
|
|
331
333
|
};
|
|
332
334
|
}
|
|
333
335
|
currentTransition.viewTransition?.updateCallbackDone.finally(async () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
2
|
import type { Logger } from '../core/logger/core.js';
|
|
3
3
|
import type { AstroSettings } from '../types/astro.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { PluginMetadata as AstroPluginMetadata } from './types.js';
|
|
5
5
|
export { getAstroMetadata } from './metadata.js';
|
|
6
|
-
export type { AstroPluginMetadata
|
|
6
|
+
export type { AstroPluginMetadata };
|
|
7
7
|
interface AstroPluginOptions {
|
|
8
8
|
settings: AstroSettings;
|
|
9
9
|
logger: Logger;
|
|
@@ -89,15 +89,9 @@ function astro({ settings, logger }) {
|
|
|
89
89
|
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
|
|
90
90
|
return {
|
|
91
91
|
code: result.code,
|
|
92
|
-
//
|
|
93
|
-
// if the
|
|
94
|
-
meta: result.isGlobal ? void 0 : {
|
|
95
|
-
astroCss: {
|
|
96
|
-
cssScopeTo: {
|
|
97
|
-
[filename]: ["default"]
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
92
|
+
// `vite.cssScopeTo` is a Vite feature that allows this CSS to be treeshaken
|
|
93
|
+
// if the Astro component's default export is not used
|
|
94
|
+
meta: result.isGlobal ? void 0 : { vite: { cssScopeTo: [filename, "default"] } }
|
|
101
95
|
};
|
|
102
96
|
}
|
|
103
97
|
case "script": {
|
|
@@ -15,26 +15,6 @@ export interface PluginMetadata {
|
|
|
15
15
|
pageOptions: PageOptions;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
export interface PluginCssMetadata {
|
|
19
|
-
astroCss: {
|
|
20
|
-
/**
|
|
21
|
-
* For Astro CSS virtual modules, it can scope to the main Astro module's default export
|
|
22
|
-
* so that if those exports are treeshaken away, the CSS module will also be treeshaken.
|
|
23
|
-
*
|
|
24
|
-
* Example config if the CSS id is `/src/Foo.astro?astro&type=style&lang.css`:
|
|
25
|
-
* ```js
|
|
26
|
-
* cssScopeTo: {
|
|
27
|
-
* '/src/Foo.astro': ['default']
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* The above is the only config we use today, but we're exposing as a `Record` to follow the
|
|
32
|
-
* upstream Vite implementation: https://github.com/vitejs/vite/pull/16058. When/If that lands,
|
|
33
|
-
* we can also remove our custom implementation.
|
|
34
|
-
*/
|
|
35
|
-
cssScopeTo: Record<string, string[]>;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
18
|
export interface CompileMetadata {
|
|
39
19
|
/** Used for HMR to compare code changes */
|
|
40
20
|
originalCode: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.3",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -137,8 +137,8 @@
|
|
|
137
137
|
"neotraverse": "^0.6.18",
|
|
138
138
|
"p-limit": "^6.2.0",
|
|
139
139
|
"p-queue": "^8.1.0",
|
|
140
|
+
"package-manager-detector": "^1.0.0",
|
|
140
141
|
"picomatch": "^4.0.2",
|
|
141
|
-
"preferred-pm": "^4.1.1",
|
|
142
142
|
"prompts": "^2.4.2",
|
|
143
143
|
"rehype": "^13.0.2",
|
|
144
144
|
"semver": "^7.7.1",
|
|
@@ -152,15 +152,14 @@
|
|
|
152
152
|
"vfile": "^6.0.3",
|
|
153
153
|
"vite": "^6.2.0",
|
|
154
154
|
"vitefu": "^1.0.6",
|
|
155
|
-
"which-pm": "^3.0.1",
|
|
156
155
|
"xxhash-wasm": "^1.1.0",
|
|
157
156
|
"yargs-parser": "^21.1.1",
|
|
158
157
|
"yocto-spinner": "^0.2.1",
|
|
159
158
|
"zod": "^3.24.2",
|
|
160
159
|
"zod-to-json-schema": "^3.24.3",
|
|
161
160
|
"zod-to-ts": "^1.2.0",
|
|
162
|
-
"@astrojs/internal-helpers": "0.6.
|
|
163
|
-
"@astrojs/markdown-remark": "6.2.
|
|
161
|
+
"@astrojs/internal-helpers": "0.6.1",
|
|
162
|
+
"@astrojs/markdown-remark": "6.2.1",
|
|
164
163
|
"@astrojs/telemetry": "3.2.0"
|
|
165
164
|
},
|
|
166
165
|
"optionalDependencies": {
|