astro 5.4.2 → 5.5.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/client.d.ts +2 -2
- package/dist/assets/build/generate.js +3 -0
- 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/compile/compile.js +1 -0
- package/dist/core/config/schema.d.ts +110 -16
- package/dist/core/config/schema.js +16 -4
- 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/events/session.js +3 -1
- package/dist/transitions/router.js +12 -1
- package/dist/types/public/config.d.ts +145 -51
- 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/dist/vite-plugin-astro-server/plugin.js +1 -1
- package/dist/vite-plugin-markdown/index.js +1 -0
- package/package.json +11 -12
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' {
|
|
@@ -170,6 +170,9 @@ async function generateImagesForPath(originalFilePath, transformsAndPath, env) {
|
|
|
170
170
|
env.imageConfig
|
|
171
171
|
)).data;
|
|
172
172
|
} catch (e) {
|
|
173
|
+
if (AstroError.is(e)) {
|
|
174
|
+
throw e;
|
|
175
|
+
}
|
|
173
176
|
const error = new AstroError(
|
|
174
177
|
{
|
|
175
178
|
...AstroErrorData.CouldNotTransformImage,
|
|
@@ -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.
|
|
156
|
+
if (previousAstroVersion && previousAstroVersion !== "5.5.0") {
|
|
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.
|
|
165
|
-
await this.#store.metaStore().set("astro-version", "5.
|
|
164
|
+
if ("5.5.0") {
|
|
165
|
+
await this.#store.metaStore().set("astro-version", "5.5.0");
|
|
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)) {
|