astro 6.0.0-beta.10 → 6.0.0-beta.12
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 +5 -0
- package/components/ResponsiveImage.astro +0 -2
- package/components/ResponsivePicture.astro +0 -1
- package/dist/assets/consts.d.ts +2 -0
- package/dist/assets/consts.js +4 -0
- package/dist/assets/internal.d.ts +1 -0
- package/dist/assets/internal.js +8 -8
- package/dist/assets/services/service.js +6 -5
- package/dist/assets/utils/generateImageStylesCSS.d.ts +1 -0
- package/dist/assets/utils/generateImageStylesCSS.js +38 -0
- package/dist/assets/vite-plugin-assets.js +60 -30
- package/dist/cli/add/index.js +45 -64
- package/dist/cli/index.js +3 -3
- package/dist/cli/info/infra/{prompts-prompt.d.ts → clack-prompt.d.ts} +1 -1
- package/dist/cli/info/infra/{prompts-prompt.js → clack-prompt.js} +7 -8
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/cli/install-package.js +16 -21
- package/dist/container/index.js +1 -0
- package/dist/content/content-layer.js +3 -3
- package/dist/content/mutable-data-store.js +14 -1
- package/dist/content/vite-plugin-content-imports.js +2 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +2 -1
- package/dist/core/app/entrypoints/index.d.ts +7 -0
- package/dist/core/app/{index.js → entrypoints/index.js} +6 -6
- package/dist/core/app/entrypoints/manifest.d.ts +1 -0
- package/dist/core/app/entrypoints/manifest.js +14 -0
- package/dist/core/app/entrypoints/node.d.ts +1 -0
- package/dist/core/app/entrypoints/node.js +8 -0
- package/dist/core/app/{entrypoint → entrypoints/virtual}/dev.d.ts +1 -1
- package/dist/core/app/{entrypoint → entrypoints/virtual}/dev.js +2 -2
- package/dist/core/app/entrypoints/virtual/index.d.ts +2 -0
- package/dist/core/app/entrypoints/virtual/index.js +5 -0
- package/dist/core/app/{entrypoint → entrypoints/virtual}/prod.d.ts +1 -1
- package/dist/core/app/{entrypoint → entrypoints/virtual}/prod.js +1 -1
- package/dist/core/app/node.d.ts +48 -7
- package/dist/core/app/node.js +139 -133
- package/dist/core/app/types.d.ts +6 -0
- package/dist/core/app/{validate-forwarded-headers.d.ts → validate-headers.d.ts} +4 -3
- package/dist/core/app/{validate-forwarded-headers.js → validate-headers.js} +33 -13
- package/dist/core/build/app.d.ts +1 -1
- package/dist/core/build/app.js +1 -1
- package/dist/core/build/pipeline.js +1 -1
- package/dist/core/build/plugins/plugin-manifest.js +6 -1
- package/dist/core/build/plugins/plugin-ssr.d.ts +6 -0
- package/dist/core/build/plugins/plugin-ssr.js +2 -1
- package/dist/core/build/static-build.js +21 -11
- package/dist/core/config/merge.js +2 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/adapter-validation.js +10 -0
- package/dist/core/dev/dev.js +2 -1
- package/dist/core/dev/restart.d.ts +1 -0
- package/dist/core/dev/restart.js +18 -16
- package/dist/core/messages.js +2 -2
- package/dist/core/routing/manifest/create.js +1 -1
- package/dist/manifest/serialized.js +6 -1
- package/dist/manifest/virtual-module.js +20 -1
- package/dist/types/public/integrations.d.ts +15 -11
- package/dist/types/public/manifest.d.ts +2 -0
- package/dist/virtual-modules/i18n.js +1 -1
- package/dist/vite-plugin-adapter-config/index.js +15 -0
- package/dist/vite-plugin-app/app.d.ts +1 -1
- package/dist/vite-plugin-app/app.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.js +6 -1
- package/dist/vite-plugin-routes/index.js +1 -1
- package/package.json +13 -16
- package/components/image.css +0 -11
- package/dist/assets/utils/imageAttributes.d.ts +0 -2
- package/dist/assets/utils/imageAttributes.js +0 -14
- package/dist/core/app/entrypoint.d.ts +0 -1
- package/dist/core/app/entrypoint.js +0 -4
- package/dist/core/app/index.d.ts +0 -7
package/client.d.ts
CHANGED
|
@@ -84,6 +84,11 @@ declare module 'astro:assets' {
|
|
|
84
84
|
}: AstroAssets;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
declare module 'virtual:astro:image-styles.css' {
|
|
88
|
+
const styles: string;
|
|
89
|
+
export default styles;
|
|
90
|
+
}
|
|
91
|
+
|
|
87
92
|
type ImageMetadata = import('./dist/assets/types.js').ImageMetadata;
|
|
88
93
|
|
|
89
94
|
declare module '*.gif' {
|
|
@@ -5,8 +5,6 @@ import Image from './Image.astro';
|
|
|
5
5
|
type Props = LocalImageProps | RemoteImageProps;
|
|
6
6
|
|
|
7
7
|
const { class: className, ...props } = Astro.props;
|
|
8
|
-
|
|
9
|
-
import './image.css';
|
|
10
8
|
---
|
|
11
9
|
|
|
12
10
|
{/* Applying class outside of the spread prevents it from applying unnecessary astro-* classes */}
|
|
@@ -4,7 +4,6 @@ import { default as Picture, type Props as PictureProps } from './Picture.astro'
|
|
|
4
4
|
type Props = PictureProps;
|
|
5
5
|
|
|
6
6
|
const { class: className, ...props } = Astro.props;
|
|
7
|
-
import './image.css';
|
|
8
7
|
---
|
|
9
8
|
|
|
10
9
|
{/* Applying class outside of the spread prevents it from applying unnecessary astro-* classes */}
|
package/dist/assets/consts.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const VIRTUAL_MODULE_ID = "astro:assets";
|
|
2
2
|
export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
|
|
3
3
|
export declare const VIRTUAL_SERVICE_ID = "virtual:image-service";
|
|
4
|
+
export declare const VIRTUAL_IMAGE_STYLES_ID = "virtual:astro:image-styles.css";
|
|
5
|
+
export declare const RESOLVED_VIRTUAL_IMAGE_STYLES_ID: string;
|
|
4
6
|
export declare const VALID_INPUT_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif", "svg", "avif"];
|
|
5
7
|
/**
|
|
6
8
|
* Valid formats that our base services support.
|
package/dist/assets/consts.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const VIRTUAL_MODULE_ID = "astro:assets";
|
|
2
2
|
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
3
3
|
const VIRTUAL_SERVICE_ID = "virtual:image-service";
|
|
4
|
+
const VIRTUAL_IMAGE_STYLES_ID = "virtual:astro:image-styles.css";
|
|
5
|
+
const RESOLVED_VIRTUAL_IMAGE_STYLES_ID = "\0" + VIRTUAL_IMAGE_STYLES_ID;
|
|
4
6
|
const VALID_INPUT_FORMATS = [
|
|
5
7
|
"jpeg",
|
|
6
8
|
"jpg",
|
|
@@ -36,10 +38,12 @@ const DEFAULT_HASH_PROPS = [
|
|
|
36
38
|
export {
|
|
37
39
|
DEFAULT_HASH_PROPS,
|
|
38
40
|
DEFAULT_OUTPUT_FORMAT,
|
|
41
|
+
RESOLVED_VIRTUAL_IMAGE_STYLES_ID,
|
|
39
42
|
RESOLVED_VIRTUAL_MODULE_ID,
|
|
40
43
|
VALID_INPUT_FORMATS,
|
|
41
44
|
VALID_OUTPUT_FORMATS,
|
|
42
45
|
VALID_SUPPORTED_FORMATS,
|
|
46
|
+
VIRTUAL_IMAGE_STYLES_ID,
|
|
43
47
|
VIRTUAL_MODULE_ID,
|
|
44
48
|
VIRTUAL_SERVICE_ID
|
|
45
49
|
};
|
|
@@ -2,5 +2,6 @@ import type { AstroConfig } from '../types/public/config.js';
|
|
|
2
2
|
import type { AstroAdapterClientConfig } from '../types/public/integrations.js';
|
|
3
3
|
import { type ImageService } from './services/service.js';
|
|
4
4
|
import { type GetImageResult, type UnresolvedImageTransform } from './types.js';
|
|
5
|
+
export declare const cssFitValues: string[];
|
|
5
6
|
export declare function getConfiguredImageService(): Promise<ImageService>;
|
|
6
7
|
export declare function getImage(options: UnresolvedImageTransform, imageConfig: AstroConfig['image'] & AstroAdapterClientConfig): Promise<GetImageResult>;
|
package/dist/assets/internal.js
CHANGED
|
@@ -11,10 +11,10 @@ import { isLocalService } from "./services/service.js";
|
|
|
11
11
|
import {
|
|
12
12
|
isImageMetadata
|
|
13
13
|
} from "./types.js";
|
|
14
|
-
import { addCSSVarsToStyle, cssFitValues } from "./utils/imageAttributes.js";
|
|
15
14
|
import { isESMImportedImage, isRemoteImage, resolveSrc } from "./utils/imageKind.js";
|
|
16
15
|
import { inferRemoteSize } from "./utils/remoteProbe.js";
|
|
17
16
|
import { createPlaceholderURL, stringifyPlaceholderURL } from "./utils/url.js";
|
|
17
|
+
const cssFitValues = ["fill", "contain", "cover", "scale-down"];
|
|
18
18
|
async function getConfiguredImageService() {
|
|
19
19
|
if (!globalThis?.astroAsset?.imageService) {
|
|
20
20
|
const { default: service } = await import(
|
|
@@ -110,14 +110,13 @@ async function getImage(options, imageConfig) {
|
|
|
110
110
|
});
|
|
111
111
|
resolvedOptions.sizes ||= getSizesAttribute({ width: resolvedOptions.width, layout });
|
|
112
112
|
delete resolvedOptions.densities;
|
|
113
|
-
resolvedOptions.style = addCSSVarsToStyle(
|
|
114
|
-
{
|
|
115
|
-
fit: cssFitValues.includes(resolvedOptions.fit ?? "") && resolvedOptions.fit,
|
|
116
|
-
pos: resolvedOptions.position
|
|
117
|
-
},
|
|
118
|
-
resolvedOptions.style
|
|
119
|
-
);
|
|
120
113
|
resolvedOptions["data-astro-image"] = layout;
|
|
114
|
+
if (resolvedOptions.fit && cssFitValues.includes(resolvedOptions.fit)) {
|
|
115
|
+
resolvedOptions["data-astro-image-fit"] = resolvedOptions.fit;
|
|
116
|
+
}
|
|
117
|
+
if (resolvedOptions.position) {
|
|
118
|
+
resolvedOptions["data-astro-image-pos"] = resolvedOptions.position.replace(/\s+/g, "-");
|
|
119
|
+
}
|
|
121
120
|
}
|
|
122
121
|
const validatedOptions = service.validateOptions ? await service.validateOptions(resolvedOptions, imageConfig) : resolvedOptions;
|
|
123
122
|
const srcSetTransforms = service.getSrcSet ? await service.getSrcSet(validatedOptions, imageConfig) : [];
|
|
@@ -182,6 +181,7 @@ async function getImage(options, imageConfig) {
|
|
|
182
181
|
};
|
|
183
182
|
}
|
|
184
183
|
export {
|
|
184
|
+
cssFitValues,
|
|
185
185
|
getConfiguredImageService,
|
|
186
186
|
getImage
|
|
187
187
|
};
|
|
@@ -64,7 +64,7 @@ function verifyOptions(options) {
|
|
|
64
64
|
if (options.widths && options.densities) {
|
|
65
65
|
throw new AstroError(AstroErrorData.IncompatibleDescriptorOptions);
|
|
66
66
|
}
|
|
67
|
-
if (options.src.format
|
|
67
|
+
if (options.src.format !== "svg" && options.format === "svg") {
|
|
68
68
|
throw new AstroError(AstroErrorData.UnsupportedImageConversion);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -72,12 +72,13 @@ function verifyOptions(options) {
|
|
|
72
72
|
const baseService = {
|
|
73
73
|
propertiesToHash: DEFAULT_HASH_PROPS,
|
|
74
74
|
validateOptions(options) {
|
|
75
|
-
if (isESMImportedImage(options.src) && options.src.format === "svg") {
|
|
76
|
-
options.format = "svg";
|
|
77
|
-
}
|
|
78
75
|
verifyOptions(options);
|
|
79
76
|
if (!options.format) {
|
|
80
|
-
options.format
|
|
77
|
+
if (isESMImportedImage(options.src) && options.src.format === "svg") {
|
|
78
|
+
options.format = "svg";
|
|
79
|
+
} else {
|
|
80
|
+
options.format = DEFAULT_OUTPUT_FORMAT;
|
|
81
|
+
}
|
|
81
82
|
}
|
|
82
83
|
if (options.width) options.width = Math.round(options.width);
|
|
83
84
|
if (options.height) options.height = Math.round(options.height);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateImageStylesCSS(defaultObjectFit?: string, defaultObjectPosition?: string): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { cssFitValues } from "../internal.js";
|
|
2
|
+
function generateImageStylesCSS(defaultObjectFit, defaultObjectPosition) {
|
|
3
|
+
const fitStyles = cssFitValues.map(
|
|
4
|
+
(fit) => `
|
|
5
|
+
[data-astro-image-fit="${fit}"] {
|
|
6
|
+
object-fit: ${fit};
|
|
7
|
+
}`
|
|
8
|
+
).join("\n");
|
|
9
|
+
const defaultFitStyle = defaultObjectFit && cssFitValues.includes(defaultObjectFit) ? `
|
|
10
|
+
:where([data-astro-image]:not([data-astro-image-fit])) {
|
|
11
|
+
object-fit: ${defaultObjectFit};
|
|
12
|
+
}` : "";
|
|
13
|
+
const positionStyle = defaultObjectPosition ? `
|
|
14
|
+
[data-astro-image-pos="${defaultObjectPosition.replace(/\s+/g, "-")}"] {
|
|
15
|
+
object-position: ${defaultObjectPosition};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:where([data-astro-image]:not([data-astro-image-pos])) {
|
|
19
|
+
object-position: ${defaultObjectPosition};
|
|
20
|
+
}` : "";
|
|
21
|
+
return `
|
|
22
|
+
:where([data-astro-image]) {
|
|
23
|
+
height: auto;
|
|
24
|
+
}
|
|
25
|
+
:where([data-astro-image="full-width"]) {
|
|
26
|
+
width: 100%;
|
|
27
|
+
}
|
|
28
|
+
:where([data-astro-image="constrained"]) {
|
|
29
|
+
max-width: 100%;
|
|
30
|
+
}
|
|
31
|
+
${fitStyles}
|
|
32
|
+
${defaultFitStyle}
|
|
33
|
+
${positionStyle}
|
|
34
|
+
`.trim();
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
generateImageStylesCSS
|
|
38
|
+
};
|
|
@@ -11,8 +11,10 @@ import {
|
|
|
11
11
|
import { normalizePath } from "../core/viteUtils.js";
|
|
12
12
|
import { isAstroServerEnvironment } from "../environments.js";
|
|
13
13
|
import {
|
|
14
|
+
RESOLVED_VIRTUAL_IMAGE_STYLES_ID,
|
|
14
15
|
RESOLVED_VIRTUAL_MODULE_ID,
|
|
15
16
|
VALID_INPUT_FORMATS,
|
|
17
|
+
VIRTUAL_IMAGE_STYLES_ID,
|
|
16
18
|
VIRTUAL_MODULE_ID,
|
|
17
19
|
VIRTUAL_SERVICE_ID
|
|
18
20
|
} from "./consts.js";
|
|
@@ -114,46 +116,46 @@ function assets({ fs, settings, sync, logger }) {
|
|
|
114
116
|
handler() {
|
|
115
117
|
return {
|
|
116
118
|
code: `
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
import { getConfiguredImageService as _getConfiguredImageService } from "astro/assets";
|
|
120
|
+
export { isLocalService } from "astro/assets";
|
|
121
|
+
import { getImage as getImageInternal } from "astro/assets";
|
|
122
|
+
${settings.config.image.responsiveStyles ? `import "${VIRTUAL_IMAGE_STYLES_ID}";` : ""}
|
|
123
|
+
export { default as Image } from "astro/components/${imageComponentPrefix}Image.astro";
|
|
124
|
+
export { default as Picture } from "astro/components/${imageComponentPrefix}Picture.astro";
|
|
125
|
+
import { inferRemoteSize as inferRemoteSizeInternal } from "astro/assets/utils/inferRemoteSize.js";
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
export { default as Font } from "astro/components/Font.astro";
|
|
128
|
+
export * from "${RUNTIME_VIRTUAL_MODULE_ID}";
|
|
129
|
+
|
|
130
|
+
export const getConfiguredImageService = _getConfiguredImageService;
|
|
128
131
|
|
|
129
132
|
export const viteFSConfig = ${JSON.stringify(resolvedConfig.server.fs ?? {})};
|
|
130
133
|
|
|
131
|
-
|
|
134
|
+
export const safeModulePaths = new Set(${JSON.stringify(
|
|
132
135
|
// @ts-expect-error safeModulePaths is internal to Vite
|
|
133
136
|
Array.from(resolvedConfig.safeModulePaths ?? [])
|
|
134
137
|
)});
|
|
135
138
|
|
|
136
|
-
|
|
139
|
+
const assetQueryParams = ${settings.adapter?.client?.assetQueryParams ? `new URLSearchParams(${JSON.stringify(
|
|
137
140
|
Array.from(settings.adapter.client.assetQueryParams.entries())
|
|
138
141
|
)})` : "undefined"};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
export const imageConfig = ${JSON.stringify(settings.config.image)};
|
|
143
|
+
Object.defineProperty(imageConfig, 'assetQueryParams', {
|
|
144
|
+
value: assetQueryParams,
|
|
145
|
+
enumerable: false,
|
|
146
|
+
configurable: true,
|
|
147
|
+
});
|
|
148
|
+
export const inferRemoteSize = async (url) => {
|
|
146
149
|
const service = await _getConfiguredImageService()
|
|
147
150
|
|
|
148
151
|
return service.getRemoteSize?.(url, imageConfig) ?? inferRemoteSizeInternal(url)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
export const outDir = /* #__PURE__ */ new URL(${JSON.stringify(
|
|
152
|
+
} // This is used by the @astrojs/node integration to locate images.
|
|
153
|
+
// It's unused on other platforms, but on some platforms like Netlify (and presumably also Vercel)
|
|
154
|
+
// new URL("dist/...") is interpreted by the bundler as a signal to include that directory
|
|
155
|
+
// in the Lambda bundle, which would bloat the bundle with images.
|
|
156
|
+
// To prevent this, we mark the URL construction as pure,
|
|
157
|
+
// so that it's tree-shaken away for all platforms that don't need it.
|
|
158
|
+
export const outDir = /* #__PURE__ */ new URL(${JSON.stringify(
|
|
157
159
|
new URL(
|
|
158
160
|
settings.buildOutput === "server" ? settings.config.build.client : settings.config.outDir
|
|
159
161
|
)
|
|
@@ -161,8 +163,8 @@ function assets({ fs, settings, sync, logger }) {
|
|
|
161
163
|
export const serverDir = /* #__PURE__ */ new URL(${JSON.stringify(
|
|
162
164
|
new URL(settings.config.build.server)
|
|
163
165
|
)});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
export const getImage = async (options) => await getImageInternal(options, imageConfig);
|
|
167
|
+
`
|
|
166
168
|
};
|
|
167
169
|
}
|
|
168
170
|
},
|
|
@@ -251,7 +253,35 @@ function assets({ fs, settings, sync, logger }) {
|
|
|
251
253
|
}
|
|
252
254
|
}
|
|
253
255
|
},
|
|
254
|
-
fontsPlugin({ settings, sync, logger })
|
|
256
|
+
fontsPlugin({ settings, sync, logger }),
|
|
257
|
+
{
|
|
258
|
+
name: "astro:image-styles",
|
|
259
|
+
resolveId: {
|
|
260
|
+
filter: {
|
|
261
|
+
id: new RegExp(`^${VIRTUAL_IMAGE_STYLES_ID}$`)
|
|
262
|
+
},
|
|
263
|
+
handler(id) {
|
|
264
|
+
if (id === VIRTUAL_IMAGE_STYLES_ID) {
|
|
265
|
+
return RESOLVED_VIRTUAL_IMAGE_STYLES_ID;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
load: {
|
|
270
|
+
filter: {
|
|
271
|
+
id: new RegExp(`^${RESOLVED_VIRTUAL_IMAGE_STYLES_ID}$`)
|
|
272
|
+
},
|
|
273
|
+
async handler(id) {
|
|
274
|
+
if (id === RESOLVED_VIRTUAL_IMAGE_STYLES_ID) {
|
|
275
|
+
const { generateImageStylesCSS } = await import("./utils/generateImageStylesCSS.js");
|
|
276
|
+
const css = generateImageStylesCSS(
|
|
277
|
+
settings.config.image.objectFit,
|
|
278
|
+
settings.config.image.objectPosition
|
|
279
|
+
);
|
|
280
|
+
return { code: css };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
255
285
|
];
|
|
256
286
|
}
|
|
257
287
|
export {
|
package/dist/cli/add/index.js
CHANGED
|
@@ -2,16 +2,14 @@ import fsMod, { existsSync, promises as fs } from "node:fs";
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
+
import * as clack from "@clack/prompts";
|
|
5
6
|
import { assertValidPackageName } from "@astrojs/internal-helpers/cli";
|
|
6
|
-
import boxen from "boxen";
|
|
7
7
|
import { diffWords } from "diff";
|
|
8
8
|
import { builders, generateCode, loadFile } from "magicast";
|
|
9
9
|
import { getDefaultExportOptions } from "magicast/helpers";
|
|
10
10
|
import { detect, resolveCommand } from "package-manager-detector";
|
|
11
11
|
import colors from "piccolore";
|
|
12
|
-
import prompts from "prompts";
|
|
13
12
|
import maxSatisfying from "semver/ranges/max-satisfying.js";
|
|
14
|
-
import yoctoSpinner from "yocto-spinner";
|
|
15
13
|
import {
|
|
16
14
|
loadTSConfig,
|
|
17
15
|
resolveConfig,
|
|
@@ -435,19 +433,21 @@ ${list}`
|
|
|
435
433
|
)
|
|
436
434
|
);
|
|
437
435
|
if (integrations.find((integration) => integration.integrationName === "tailwind")) {
|
|
438
|
-
const code = boxen(getDiffContent("---\n---", "---\nimport '../styles/global.css'\n---"), {
|
|
439
|
-
margin: 0.5,
|
|
440
|
-
padding: 0.5,
|
|
441
|
-
borderStyle: "round",
|
|
442
|
-
title: "src/layouts/Layout.astro"
|
|
443
|
-
});
|
|
444
436
|
logger.warn(
|
|
445
437
|
"SKIP_FORMAT",
|
|
446
438
|
msg.actionRequired(
|
|
447
439
|
"You must import your Tailwind stylesheet, e.g. in a shared layout:\n"
|
|
448
440
|
)
|
|
449
441
|
);
|
|
450
|
-
|
|
442
|
+
clack.box(
|
|
443
|
+
getDiffContent("---\n---", "---\nimport '../styles/global.css'\n---"),
|
|
444
|
+
"src/layouts/Layout.astro",
|
|
445
|
+
{
|
|
446
|
+
rounded: true,
|
|
447
|
+
withGuide: false,
|
|
448
|
+
width: "auto"
|
|
449
|
+
}
|
|
450
|
+
);
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
453
|
}
|
|
@@ -571,20 +571,16 @@ async function updateAstroConfig({
|
|
|
571
571
|
if (!diff) {
|
|
572
572
|
return 0 /* none */;
|
|
573
573
|
}
|
|
574
|
-
const message = `
|
|
575
|
-
${boxen(diff, {
|
|
576
|
-
margin: 0.5,
|
|
577
|
-
padding: 0.5,
|
|
578
|
-
borderStyle: "round",
|
|
579
|
-
title: configURL.pathname.split("/").pop()
|
|
580
|
-
})}
|
|
581
|
-
`;
|
|
582
574
|
logger.info(
|
|
583
575
|
"SKIP_FORMAT",
|
|
584
576
|
`
|
|
585
|
-
${magenta("Astro will make the following changes to your config file:")}
|
|
586
|
-
${message}`
|
|
577
|
+
${magenta("Astro will make the following changes to your config file:")}`
|
|
587
578
|
);
|
|
579
|
+
clack.box(diff, configURL.pathname.split("/").pop(), {
|
|
580
|
+
rounded: true,
|
|
581
|
+
withGuide: false,
|
|
582
|
+
width: "auto"
|
|
583
|
+
});
|
|
588
584
|
if (logAdapterInstructions) {
|
|
589
585
|
logger.info(
|
|
590
586
|
"SKIP_FORMAT",
|
|
@@ -635,20 +631,16 @@ async function updatePackageJsonScripts({
|
|
|
635
631
|
if (!diff) {
|
|
636
632
|
return 0 /* none */;
|
|
637
633
|
}
|
|
638
|
-
const message = `
|
|
639
|
-
${boxen(diff, {
|
|
640
|
-
margin: 0.5,
|
|
641
|
-
padding: 0.5,
|
|
642
|
-
borderStyle: "round",
|
|
643
|
-
title: "package.json"
|
|
644
|
-
})}
|
|
645
|
-
`;
|
|
646
634
|
logger.info(
|
|
647
635
|
"SKIP_FORMAT",
|
|
648
636
|
`
|
|
649
|
-
${magenta("Astro will add the following scripts to your package.json:")}
|
|
650
|
-
${message}`
|
|
637
|
+
${magenta("Astro will add the following scripts to your package.json:")}`
|
|
651
638
|
);
|
|
639
|
+
clack.box(diff, "package.json", {
|
|
640
|
+
rounded: true,
|
|
641
|
+
withGuide: false,
|
|
642
|
+
width: "auto"
|
|
643
|
+
});
|
|
652
644
|
if (await askToContinue({ flags, logger })) {
|
|
653
645
|
await fs.writeFile(pkgPath, output, { encoding: "utf-8" });
|
|
654
646
|
logger.debug("add", "Updated package.json scripts");
|
|
@@ -712,24 +704,22 @@ async function tryToInstallIntegrations({
|
|
|
712
704
|
(specifiers) => installCommand.command === "deno" ? specifiers.map((specifier) => `npm:${specifier}`) : specifiers
|
|
713
705
|
);
|
|
714
706
|
const coloredOutput = `${bold(installCommand.command)} ${installCommand.args.join(" ")} ${cyan(installSpecifiers.join(" "))}`;
|
|
715
|
-
const message = `
|
|
716
|
-
${boxen(coloredOutput, {
|
|
717
|
-
margin: 0.5,
|
|
718
|
-
padding: 0.5,
|
|
719
|
-
borderStyle: "round"
|
|
720
|
-
})}
|
|
721
|
-
`;
|
|
722
707
|
logger.info(
|
|
723
708
|
"SKIP_FORMAT",
|
|
724
709
|
`
|
|
725
710
|
${magenta("Astro will run the following command:")}
|
|
726
711
|
${dim(
|
|
727
712
|
"If you skip this step, you can always run it yourself later"
|
|
728
|
-
)}
|
|
729
|
-
${message}`
|
|
713
|
+
)}`
|
|
730
714
|
);
|
|
715
|
+
clack.box(coloredOutput, void 0, {
|
|
716
|
+
rounded: true,
|
|
717
|
+
withGuide: false,
|
|
718
|
+
width: "auto"
|
|
719
|
+
});
|
|
731
720
|
if (await askToContinue({ flags, logger })) {
|
|
732
|
-
const spinner =
|
|
721
|
+
const spinner = clack.spinner({ withGuide: false });
|
|
722
|
+
spinner.start("Installing dependencies...");
|
|
733
723
|
try {
|
|
734
724
|
await exec(installCommand.command, [...installCommand.args, ...installSpecifiers], {
|
|
735
725
|
nodeOptions: {
|
|
@@ -738,10 +728,10 @@ ${message}`
|
|
|
738
728
|
env: { NODE_ENV: void 0 }
|
|
739
729
|
}
|
|
740
730
|
});
|
|
741
|
-
spinner.
|
|
731
|
+
spinner.stop("Dependencies installed.");
|
|
742
732
|
return 1 /* updated */;
|
|
743
733
|
} catch (err) {
|
|
744
|
-
spinner.error();
|
|
734
|
+
spinner.error("Error installing dependencies.");
|
|
745
735
|
logger.debug("add", "Error installing dependencies", err);
|
|
746
736
|
console.error("\n", err.stdout || err.message, "\n");
|
|
747
737
|
return 3 /* failure */;
|
|
@@ -754,7 +744,8 @@ async function validateIntegrations(integrations, flags, logger) {
|
|
|
754
744
|
for (const integration of integrations) {
|
|
755
745
|
assertValidPackageName(integration);
|
|
756
746
|
}
|
|
757
|
-
const spinner =
|
|
747
|
+
const spinner = clack.spinner({ withGuide: false });
|
|
748
|
+
spinner.start("Resolving packages...");
|
|
758
749
|
try {
|
|
759
750
|
const integrationEntries = await Promise.all(
|
|
760
751
|
integrations.map(async (integration) => {
|
|
@@ -771,9 +762,9 @@ async function validateIntegrations(integrations, flags, logger) {
|
|
|
771
762
|
const firstPartyPkgCheck = await fetchPackageJson("@astrojs", name, tag);
|
|
772
763
|
if (firstPartyPkgCheck instanceof Error) {
|
|
773
764
|
if (firstPartyPkgCheck.message) {
|
|
774
|
-
spinner.
|
|
765
|
+
spinner.message(yellow(firstPartyPkgCheck.message));
|
|
775
766
|
}
|
|
776
|
-
spinner.
|
|
767
|
+
spinner.message(yellow(`${bold(integration)} is not an official Astro package.`));
|
|
777
768
|
if (!await askToContinue({ flags, logger })) {
|
|
778
769
|
throw new Error(
|
|
779
770
|
`No problem! Find our official integrations at ${cyan(
|
|
@@ -781,7 +772,7 @@ async function validateIntegrations(integrations, flags, logger) {
|
|
|
781
772
|
)}`
|
|
782
773
|
);
|
|
783
774
|
}
|
|
784
|
-
spinner.
|
|
775
|
+
spinner.message("Resolving with third party packages...");
|
|
785
776
|
pkgType = "third-party";
|
|
786
777
|
} else {
|
|
787
778
|
pkgType = "first-party";
|
|
@@ -792,7 +783,7 @@ async function validateIntegrations(integrations, flags, logger) {
|
|
|
792
783
|
const thirdPartyPkgCheck = await fetchPackageJson(scope, name, tag);
|
|
793
784
|
if (thirdPartyPkgCheck instanceof Error) {
|
|
794
785
|
if (thirdPartyPkgCheck.message) {
|
|
795
|
-
spinner.
|
|
786
|
+
spinner.message(yellow(thirdPartyPkgCheck.message));
|
|
796
787
|
}
|
|
797
788
|
throw new Error(`Unable to fetch ${bold(integration)}. Does the package exist?`);
|
|
798
789
|
} else {
|
|
@@ -846,7 +837,7 @@ async function validateIntegrations(integrations, flags, logger) {
|
|
|
846
837
|
};
|
|
847
838
|
})
|
|
848
839
|
);
|
|
849
|
-
spinner.
|
|
840
|
+
spinner.stop("Resolved packages.");
|
|
850
841
|
return integrationEntries;
|
|
851
842
|
} catch (e) {
|
|
852
843
|
if (e instanceof Error) {
|
|
@@ -895,19 +886,10 @@ async function updateTSConfig(cwd = process.cwd(), logger, integrationsInfo, fla
|
|
|
895
886
|
if (!diff) {
|
|
896
887
|
return 0 /* none */;
|
|
897
888
|
}
|
|
898
|
-
const message = `
|
|
899
|
-
${boxen(diff, {
|
|
900
|
-
margin: 0.5,
|
|
901
|
-
padding: 0.5,
|
|
902
|
-
borderStyle: "round",
|
|
903
|
-
title: configFileName
|
|
904
|
-
})}
|
|
905
|
-
`;
|
|
906
889
|
logger.info(
|
|
907
890
|
"SKIP_FORMAT",
|
|
908
891
|
`
|
|
909
|
-
${magenta(`Astro will make the following changes to your ${configFileName}:`)}
|
|
910
|
-
${message}`
|
|
892
|
+
${magenta(`Astro will make the following changes to your ${configFileName}:`)}`
|
|
911
893
|
);
|
|
912
894
|
if (firstIntegrationWithTSSettings) {
|
|
913
895
|
const conflictingIntegrations = Array.from(presets.keys()).filter(
|
|
@@ -964,13 +946,12 @@ async function askToContinue({
|
|
|
964
946
|
hasHintedAboutYesFlag = true;
|
|
965
947
|
logger.info("SKIP_FORMAT", dim(" To run this command without prompts, pass the --yes flag\n"));
|
|
966
948
|
}
|
|
967
|
-
const response = await
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
initial: true
|
|
949
|
+
const response = await clack.confirm({
|
|
950
|
+
message: colors.bold("Continue?"),
|
|
951
|
+
initialValue: true,
|
|
952
|
+
withGuide: false
|
|
972
953
|
});
|
|
973
|
-
return
|
|
954
|
+
return response === true;
|
|
974
955
|
}
|
|
975
956
|
function getDiffContent(input, output) {
|
|
976
957
|
let changes = [];
|
package/dist/cli/index.js
CHANGED
|
@@ -74,7 +74,7 @@ async function runCommand(cmd, flags) {
|
|
|
74
74
|
{ TinyexecCommandExecutor },
|
|
75
75
|
{ getPackageManager },
|
|
76
76
|
{ StyledDebugInfoFormatter },
|
|
77
|
-
{
|
|
77
|
+
{ ClackPrompt },
|
|
78
78
|
{ CliClipboard },
|
|
79
79
|
{ PassthroughTextStyler },
|
|
80
80
|
{ infoCommand }
|
|
@@ -87,7 +87,7 @@ async function runCommand(cmd, flags) {
|
|
|
87
87
|
import("./infra/tinyexec-command-executor.js"),
|
|
88
88
|
import("./info/core/get-package-manager.js"),
|
|
89
89
|
import("./info/infra/styled-debug-info-formatter.js"),
|
|
90
|
-
import("./info/infra/
|
|
90
|
+
import("./info/infra/clack-prompt.js"),
|
|
91
91
|
import("./info/infra/cli-clipboard.js"),
|
|
92
92
|
import("./infra/passthrough-text-styler.js"),
|
|
93
93
|
import("./info/core/info.js")
|
|
@@ -107,7 +107,7 @@ async function runCommand(cmd, flags) {
|
|
|
107
107
|
}),
|
|
108
108
|
nodeVersionProvider
|
|
109
109
|
});
|
|
110
|
-
const prompt = new
|
|
110
|
+
const prompt = new ClackPrompt({ force: flags.copy });
|
|
111
111
|
const clipboard = new CliClipboard({
|
|
112
112
|
commandExecutor,
|
|
113
113
|
logger,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
class
|
|
1
|
+
import { confirm } from "@clack/prompts";
|
|
2
|
+
class ClackPrompt {
|
|
3
3
|
#force;
|
|
4
4
|
constructor({ force }) {
|
|
5
5
|
this.#force = force;
|
|
@@ -11,15 +11,14 @@ class PromptsPrompt {
|
|
|
11
11
|
if (this.#force) {
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
type: "confirm",
|
|
16
|
-
name: "value",
|
|
14
|
+
const response = await confirm({
|
|
17
15
|
message,
|
|
18
|
-
|
|
16
|
+
initialValue: defaultValue,
|
|
17
|
+
withGuide: false
|
|
19
18
|
});
|
|
20
|
-
return
|
|
19
|
+
return response === true;
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
export {
|
|
24
|
-
|
|
23
|
+
ClackPrompt
|
|
25
24
|
};
|