astro 4.6.3 → 4.7.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/components/ViewTransitions.astro +9 -2
- package/dist/@types/astro.d.ts +48 -6
- package/dist/assets/endpoint/generic.js +2 -2
- package/dist/assets/endpoint/node.js +2 -2
- package/dist/assets/utils/emitAsset.d.ts +6 -1
- package/dist/assets/utils/emitAsset.js +15 -9
- package/dist/assets/vite-plugin-assets.js +6 -1
- package/dist/cli/add/index.js +1 -41
- package/dist/cli/install-package.d.ts +9 -0
- package/dist/cli/install-package.js +64 -1
- package/dist/config/index.js +2 -2
- package/dist/content/runtime-assets.d.ts +1 -1
- package/dist/content/runtime-assets.js +2 -2
- package/dist/content/runtime.d.ts +1 -1
- package/dist/content/utils.d.ts +1 -1
- package/dist/content/utils.js +2 -2
- package/dist/content/vite-plugin-content-imports.js +10 -2
- package/dist/core/app/createOutgoingHttpHeaders.d.ts +1 -0
- package/dist/core/build/static-build.js +4 -0
- package/dist/core/config/schema.d.ts +332 -289
- package/dist/core/config/settings.js +3 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +1 -1
- package/dist/core/dev/dev.js +34 -2
- package/dist/core/dev/restart.js +5 -1
- package/dist/core/dev/update-check.d.ts +4 -0
- package/dist/core/dev/update-check.js +36 -0
- package/dist/core/logger/core.d.ts +1 -1
- package/dist/core/messages.d.ts +3 -0
- package/dist/core/messages.js +11 -2
- package/dist/integrations/index.d.ts +28 -0
- package/dist/integrations/index.js +40 -1
- package/dist/preferences/defaults.d.ts +9 -0
- package/dist/preferences/defaults.js +9 -0
- package/dist/preferences/index.d.ts +12 -4
- package/dist/preferences/index.js +11 -4
- package/dist/runtime/client/dev-toolbar/apps/astro.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/astro.js +3 -0
- package/dist/runtime/client/dev-toolbar/apps/audit/index.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/settings.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/xray.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/entrypoint.js +3 -2
- package/dist/runtime/client/dev-toolbar/helpers.d.ts +61 -0
- package/dist/runtime/client/dev-toolbar/helpers.js +87 -0
- package/dist/runtime/client/dev-toolbar/toolbar.d.ts +3 -2
- package/dist/runtime/client/dev-toolbar/toolbar.js +2 -1
- package/dist/runtime/server/astro-island.js +132 -137
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/toolbar/index.d.ts +2 -0
- package/dist/toolbar/index.js +6 -0
- package/dist/{vite-plugin-dev-toolbar → toolbar}/vite-plugin-dev-toolbar.js +33 -12
- package/dist/transitions/router.js +0 -1
- package/dist/vite-plugin-astro-server/pipeline.js +1 -0
- package/dist/vite-plugin-markdown/images.d.ts +0 -1
- package/dist/vite-plugin-markdown/images.js +1 -4
- package/dist/vite-plugin-markdown/index.js +8 -2
- package/package.json +48 -50
- package/tsconfigs/strictest.json +1 -3
- /package/dist/{vite-plugin-dev-toolbar → toolbar}/vite-plugin-dev-toolbar.d.ts +0 -0
|
@@ -108,9 +108,16 @@ const { fallback = 'animate' } = Astro.props;
|
|
|
108
108
|
const form = el as HTMLFormElement;
|
|
109
109
|
const submitter = ev.submitter;
|
|
110
110
|
const formData = new FormData(form, submitter);
|
|
111
|
+
// form.action and form.method can point to an <input name="action"> or <input name="method">
|
|
112
|
+
// in which case should fallback to the form attribute
|
|
113
|
+
const formAction =
|
|
114
|
+
typeof form.action === 'string' ? form.action : form.getAttribute('action');
|
|
115
|
+
const formMethod =
|
|
116
|
+
typeof form.method === 'string' ? form.method : form.getAttribute('method');
|
|
111
117
|
// Use the form action, if defined, otherwise fallback to current path.
|
|
112
|
-
let action = submitter?.getAttribute('formaction') ??
|
|
113
|
-
|
|
118
|
+
let action = submitter?.getAttribute('formaction') ?? formAction ?? location.pathname;
|
|
119
|
+
// Use the form method, if defined, otherwise fallback to "get"
|
|
120
|
+
const method = submitter?.getAttribute('formmethod') ?? formMethod ?? 'get';
|
|
114
121
|
|
|
115
122
|
// the "dialog" method is a special keyword used within <dialog> elements
|
|
116
123
|
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -14,7 +14,9 @@ import type { AstroTimer } from '../core/config/timer.js';
|
|
|
14
14
|
import type { TSConfig } from '../core/config/tsconfig.js';
|
|
15
15
|
import type { AstroCookies } from '../core/cookies/index.js';
|
|
16
16
|
import type { AstroIntegrationLogger, Logger, LoggerLevel } from '../core/logger/core.js';
|
|
17
|
+
import type { getToolbarServerCommunicationHelpers } from '../integrations/index.js';
|
|
17
18
|
import type { AstroPreferences } from '../preferences/index.js';
|
|
19
|
+
import type { ToolbarAppEventTarget, ToolbarServerHelpers } from '../runtime/client/dev-toolbar/helpers.js';
|
|
18
20
|
import type { AstroDevToolbar, DevToolbarCanvas } from '../runtime/client/dev-toolbar/toolbar.js';
|
|
19
21
|
import type { Icon } from '../runtime/client/dev-toolbar/ui-library/icons.js';
|
|
20
22
|
import type { DevToolbarBadge, DevToolbarButton, DevToolbarCard, DevToolbarHighlight, DevToolbarIcon, DevToolbarSelect, DevToolbarToggle, DevToolbarTooltip, DevToolbarWindow } from '../runtime/client/dev-toolbar/ui-library/index.js';
|
|
@@ -22,7 +24,7 @@ import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/s
|
|
|
22
24
|
import type { TransitionBeforePreparationEvent, TransitionBeforeSwapEvent } from '../transitions/events.js';
|
|
23
25
|
import type { DeepPartial, OmitIndexSignature, Simplify } from '../type-utils.js';
|
|
24
26
|
import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
|
|
25
|
-
export {
|
|
27
|
+
export type { AstroIntegrationLogger, ToolbarServerHelpers };
|
|
26
28
|
export type { MarkdownHeading, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
|
|
27
29
|
export type { ExternalImageService, ImageService, LocalImageService, } from '../assets/services/service.js';
|
|
28
30
|
export type { GetImageResult, ImageInputFormat, ImageMetadata, ImageOutputFormat, ImageQuality, ImageQualityPreset, ImageTransform, UnresolvedImageTransform, } from '../assets/types.js';
|
|
@@ -1939,7 +1941,7 @@ export interface AstroSettings {
|
|
|
1939
1941
|
* Map of directive name (e.g. `load`) to the directive script code
|
|
1940
1942
|
*/
|
|
1941
1943
|
clientDirectives: Map<string, string>;
|
|
1942
|
-
devToolbarApps: string[];
|
|
1944
|
+
devToolbarApps: (DevToolbarAppEntry | string)[];
|
|
1943
1945
|
middlewares: {
|
|
1944
1946
|
pre: string[];
|
|
1945
1947
|
post: string[];
|
|
@@ -1948,6 +1950,14 @@ export interface AstroSettings {
|
|
|
1948
1950
|
tsConfigPath: string | undefined;
|
|
1949
1951
|
watchFiles: string[];
|
|
1950
1952
|
timer: AstroTimer;
|
|
1953
|
+
/**
|
|
1954
|
+
* Latest version of Astro, will be undefined if:
|
|
1955
|
+
* - unable to check
|
|
1956
|
+
* - the user has disabled the check
|
|
1957
|
+
* - the check has not completed yet
|
|
1958
|
+
* - the user is on the latest version already
|
|
1959
|
+
*/
|
|
1960
|
+
latestAstroVersion: string | undefined;
|
|
1951
1961
|
}
|
|
1952
1962
|
export type AsyncRendererComponentFn<U> = (Component: any, props: any, slots: Record<string, string>, metadata?: AstroComponentMetadata) => Promise<U>;
|
|
1953
1963
|
/** Generic interface for a component (Astro, Svelte, React, etc.) */
|
|
@@ -2470,7 +2480,7 @@ export interface AstroIntegration {
|
|
|
2470
2480
|
* TODO: Fully remove in Astro 5.0
|
|
2471
2481
|
*/
|
|
2472
2482
|
addDevOverlayPlugin: (entrypoint: string) => void;
|
|
2473
|
-
addDevToolbarApp: (entrypoint: string) => void;
|
|
2483
|
+
addDevToolbarApp: (entrypoint: DevToolbarAppEntry | string) => void;
|
|
2474
2484
|
addMiddleware: (mid: AstroIntegrationMiddleware) => void;
|
|
2475
2485
|
logger: AstroIntegrationLogger;
|
|
2476
2486
|
}) => void | Promise<void>;
|
|
@@ -2482,6 +2492,7 @@ export interface AstroIntegration {
|
|
|
2482
2492
|
'astro:server:setup'?: (options: {
|
|
2483
2493
|
server: vite.ViteDevServer;
|
|
2484
2494
|
logger: AstroIntegrationLogger;
|
|
2495
|
+
toolbar: ReturnType<typeof getToolbarServerCommunicationHelpers>;
|
|
2485
2496
|
}) => void | Promise<void>;
|
|
2486
2497
|
'astro:server:start'?: (options: {
|
|
2487
2498
|
address: AddressInfo;
|
|
@@ -2694,18 +2705,49 @@ export interface ClientDirectiveConfig {
|
|
|
2694
2705
|
name: string;
|
|
2695
2706
|
entrypoint: string;
|
|
2696
2707
|
}
|
|
2697
|
-
|
|
2708
|
+
type DevToolbarAppMeta = {
|
|
2698
2709
|
id: string;
|
|
2699
2710
|
name: string;
|
|
2700
2711
|
icon?: Icon;
|
|
2701
|
-
|
|
2712
|
+
};
|
|
2713
|
+
export type DevToolbarAppEntry = DevToolbarAppMeta & {
|
|
2714
|
+
entrypoint: string;
|
|
2715
|
+
};
|
|
2716
|
+
export type DevToolbarApp = {
|
|
2717
|
+
/**
|
|
2718
|
+
* @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`.
|
|
2719
|
+
*
|
|
2720
|
+
* Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })`
|
|
2721
|
+
*
|
|
2722
|
+
* In the future, putting these properties directly on the app object will be removed.
|
|
2723
|
+
*/
|
|
2724
|
+
id?: string;
|
|
2725
|
+
/**
|
|
2726
|
+
* @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`.
|
|
2727
|
+
*
|
|
2728
|
+
* Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })`
|
|
2729
|
+
*
|
|
2730
|
+
* In the future, putting these properties directly on the app object will be removed.
|
|
2731
|
+
*/
|
|
2732
|
+
name?: string;
|
|
2733
|
+
/**
|
|
2734
|
+
* @deprecated The `id`, `name`, and `icon` properties should now be defined when using `addDevToolbarApp`.
|
|
2735
|
+
*
|
|
2736
|
+
* Ex: `addDevToolbarApp({ id: 'my-app', name: 'My App', icon: '🚀', entrypoint: '/path/to/app' })`
|
|
2737
|
+
*
|
|
2738
|
+
* In the future, putting these properties directly on the app object will be removed.
|
|
2739
|
+
*/
|
|
2740
|
+
icon?: Icon;
|
|
2741
|
+
init?(canvas: ShadowRoot, app: ToolbarAppEventTarget, server: ToolbarServerHelpers): void | Promise<void>;
|
|
2702
2742
|
beforeTogglingOff?(canvas: ShadowRoot): boolean | Promise<boolean>;
|
|
2703
|
-
}
|
|
2743
|
+
};
|
|
2744
|
+
export type ResolvedDevToolbarApp = DevToolbarAppMeta & Omit<DevToolbarApp, 'id' | 'name' | 'icon'>;
|
|
2704
2745
|
export type DevOverlayPlugin = DevToolbarApp;
|
|
2705
2746
|
export type DevToolbarMetadata = Window & typeof globalThis & {
|
|
2706
2747
|
__astro_dev_toolbar__: {
|
|
2707
2748
|
root: string;
|
|
2708
2749
|
version: string;
|
|
2750
|
+
latestAstroVersion: AstroSettings['latestAstroVersion'];
|
|
2709
2751
|
debugInfo: string;
|
|
2710
2752
|
};
|
|
2711
2753
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { imageConfig } from "astro:assets";
|
|
2
2
|
import { isRemotePath } from "@astrojs/internal-helpers/path";
|
|
3
|
-
import mime from "
|
|
3
|
+
import * as mime from "mrmime";
|
|
4
4
|
import { getConfiguredImageService } from "../internal.js";
|
|
5
5
|
import { etag } from "../utils/etag.js";
|
|
6
6
|
import { isRemoteAllowed } from "../utils/remotePattern.js";
|
|
@@ -47,7 +47,7 @@ const GET = async ({ request }) => {
|
|
|
47
47
|
return new Response(data, {
|
|
48
48
|
status: 200,
|
|
49
49
|
headers: {
|
|
50
|
-
"Content-Type": mime.
|
|
50
|
+
"Content-Type": mime.lookup(format) ?? `image/${format}`,
|
|
51
51
|
"Cache-Control": "public, max-age=31536000",
|
|
52
52
|
ETag: etag(data.toString()),
|
|
53
53
|
Date: (/* @__PURE__ */ new Date()).toUTCString()
|
|
@@ -4,7 +4,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
4
4
|
import { assetsDir, imageConfig, outDir } from "astro:assets";
|
|
5
5
|
import { isRemotePath, removeQueryString } from "@astrojs/internal-helpers/path";
|
|
6
6
|
import { readFile } from "fs/promises";
|
|
7
|
-
import mime from "
|
|
7
|
+
import * as mime from "mrmime";
|
|
8
8
|
import { getConfiguredImageService } from "../internal.js";
|
|
9
9
|
import { etag } from "../utils/etag.js";
|
|
10
10
|
import { isRemoteAllowed } from "../utils/remotePattern.js";
|
|
@@ -83,7 +83,7 @@ const GET = async ({ request }) => {
|
|
|
83
83
|
return new Response(data, {
|
|
84
84
|
status: 200,
|
|
85
85
|
headers: {
|
|
86
|
-
"Content-Type": mime.
|
|
86
|
+
"Content-Type": mime.lookup(format) ?? `image/${format}`,
|
|
87
87
|
"Cache-Control": "public, max-age=31536000",
|
|
88
88
|
ETag: etag(data.toString()),
|
|
89
89
|
Date: (/* @__PURE__ */ new Date()).toUTCString()
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
import type * as vite from 'vite';
|
|
1
2
|
import type { ImageMetadata } from '../types.js';
|
|
2
|
-
|
|
3
|
+
type FileEmitter = vite.Rollup.EmitFile;
|
|
4
|
+
export declare function emitESMImage(id: string | undefined,
|
|
5
|
+
/** @deprecated */
|
|
6
|
+
_watchMode: boolean, fileEmitter?: FileEmitter): Promise<ImageMetadata | undefined>;
|
|
7
|
+
export {};
|
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import { prependForwardSlash, slash } from "../../core/path.js";
|
|
5
5
|
import { imageMetadata } from "./metadata.js";
|
|
6
|
-
async function emitESMImage(id,
|
|
6
|
+
async function emitESMImage(id, _watchMode, fileEmitter) {
|
|
7
7
|
if (!id) {
|
|
8
8
|
return void 0;
|
|
9
9
|
}
|
|
@@ -24,16 +24,22 @@ async function emitESMImage(id, watchMode, fileEmitter) {
|
|
|
24
24
|
writable: false,
|
|
25
25
|
value: id
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
let isBuild = typeof fileEmitter === "function";
|
|
28
|
+
if (isBuild) {
|
|
28
29
|
const pathname = decodeURI(url.pathname);
|
|
29
30
|
const filename = path.basename(pathname, path.extname(pathname) + `.${fileMetadata.format}`);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
try {
|
|
32
|
+
const handle = fileEmitter({
|
|
33
|
+
name: filename,
|
|
34
|
+
source: await fs.readFile(url),
|
|
35
|
+
type: "asset"
|
|
36
|
+
});
|
|
37
|
+
emittedImage.src = `__ASTRO_ASSET_IMAGE__${handle}__`;
|
|
38
|
+
} catch {
|
|
39
|
+
isBuild = false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!isBuild) {
|
|
37
43
|
url.searchParams.append("origWidth", fileMetadata.width.toString());
|
|
38
44
|
url.searchParams.append("origHeight", fileMetadata.height.toString());
|
|
39
45
|
url.searchParams.append("origFormat", fileMetadata.format);
|
|
@@ -69,6 +69,7 @@ function assets({
|
|
|
69
69
|
mode
|
|
70
70
|
}) {
|
|
71
71
|
let resolvedConfig;
|
|
72
|
+
let shouldEmitFile = false;
|
|
72
73
|
globalThis.astroAsset = {
|
|
73
74
|
referencedImages: /* @__PURE__ */ new Set()
|
|
74
75
|
};
|
|
@@ -155,6 +156,9 @@ function assets({
|
|
|
155
156
|
{
|
|
156
157
|
name: "astro:assets:esm",
|
|
157
158
|
enforce: "pre",
|
|
159
|
+
config(_, env) {
|
|
160
|
+
shouldEmitFile = env.command === "build";
|
|
161
|
+
},
|
|
158
162
|
configResolved(viteConfig) {
|
|
159
163
|
resolvedConfig = viteConfig;
|
|
160
164
|
},
|
|
@@ -169,7 +173,8 @@ function assets({
|
|
|
169
173
|
if (!assetRegexEnds.test(id)) {
|
|
170
174
|
return;
|
|
171
175
|
}
|
|
172
|
-
const
|
|
176
|
+
const emitFile = shouldEmitFile ? this.emitFile : void 0;
|
|
177
|
+
const imageMetadata = await emitESMImage(id, this.meta.watchMode, emitFile);
|
|
173
178
|
if (!imageMetadata) {
|
|
174
179
|
throw new AstroError({
|
|
175
180
|
...AstroErrorData.ImageNotFound,
|
package/dist/cli/add/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { apply as applyPolyfill } from "../../core/polyfill.js";
|
|
|
27
27
|
import { ensureProcessNodeEnv, parseNpmName } from "../../core/util.js";
|
|
28
28
|
import { eventCliSession, telemetry } from "../../events/index.js";
|
|
29
29
|
import { createLoggerFromFlags, flagsToAstroInlineConfig } from "../flags.js";
|
|
30
|
+
import { fetchPackageJson, fetchPackageVersions } from "../install-package.js";
|
|
30
31
|
import { generate, parse, t, visit } from "./babel.js";
|
|
31
32
|
import { ensureImport } from "./imports.js";
|
|
32
33
|
import { wrapDefaultExport } from "./wrapper.js";
|
|
@@ -77,22 +78,6 @@ const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
|
|
|
77
78
|
cloudflare: "@astrojs/cloudflare",
|
|
78
79
|
node: "@astrojs/node"
|
|
79
80
|
};
|
|
80
|
-
let _registry;
|
|
81
|
-
async function getRegistry() {
|
|
82
|
-
if (_registry)
|
|
83
|
-
return _registry;
|
|
84
|
-
const fallback = "https://registry.npmjs.org";
|
|
85
|
-
const packageManager = (await preferredPM(process.cwd()))?.name || "npm";
|
|
86
|
-
try {
|
|
87
|
-
const { stdout } = await execa(packageManager, ["config", "get", "registry"]);
|
|
88
|
-
_registry = stdout?.trim()?.replace(/\/$/, "") || fallback;
|
|
89
|
-
if (!new URL(_registry).host)
|
|
90
|
-
_registry = fallback;
|
|
91
|
-
} catch (e) {
|
|
92
|
-
_registry = fallback;
|
|
93
|
-
}
|
|
94
|
-
return _registry;
|
|
95
|
-
}
|
|
96
81
|
async function add(names, { flags }) {
|
|
97
82
|
ensureProcessNodeEnv("production");
|
|
98
83
|
applyPolyfill();
|
|
@@ -683,31 +668,6 @@ ${message}`
|
|
|
683
668
|
}
|
|
684
669
|
}
|
|
685
670
|
}
|
|
686
|
-
async function fetchPackageJson(scope, name, tag) {
|
|
687
|
-
const packageName = `${scope ? `${scope}/` : ""}${name}`;
|
|
688
|
-
const registry = await getRegistry();
|
|
689
|
-
const res = await fetch(`${registry}/${packageName}/${tag}`);
|
|
690
|
-
if (res.status >= 200 && res.status < 300) {
|
|
691
|
-
return await res.json();
|
|
692
|
-
} else if (res.status === 404) {
|
|
693
|
-
return new Error();
|
|
694
|
-
} else {
|
|
695
|
-
return new Error(`Failed to fetch ${registry}/${packageName}/${tag} - GET ${res.status}`);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
async function fetchPackageVersions(packageName) {
|
|
699
|
-
const registry = await getRegistry();
|
|
700
|
-
const res = await fetch(`${registry}/${packageName}`, {
|
|
701
|
-
headers: { accept: "application/vnd.npm.install-v1+json" }
|
|
702
|
-
});
|
|
703
|
-
if (res.status >= 200 && res.status < 300) {
|
|
704
|
-
return await res.json().then((data) => Object.keys(data.versions));
|
|
705
|
-
} else if (res.status === 404) {
|
|
706
|
-
return new Error();
|
|
707
|
-
} else {
|
|
708
|
-
return new Error(`Failed to fetch ${registry}/${packageName} - GET ${res.status}`);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
671
|
async function validateIntegrations(integrations) {
|
|
712
672
|
const spinner = ora("Resolving packages...").start();
|
|
713
673
|
try {
|
|
@@ -5,4 +5,13 @@ 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`, `pnpx`, 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
|
+
export declare function fetchPackageJson(scope: string | undefined, name: string, tag: string): Promise<Record<string, any> | Error>;
|
|
15
|
+
export declare function fetchPackageVersions(packageName: string): Promise<string[] | Error>;
|
|
16
|
+
export declare function getRegistry(): Promise<string>;
|
|
8
17
|
export {};
|
|
@@ -5,6 +5,7 @@ import ci from "ci-info";
|
|
|
5
5
|
import { execa } from "execa";
|
|
6
6
|
import { bold, cyan, dim, magenta } from "kleur/colors";
|
|
7
7
|
import ora from "ora";
|
|
8
|
+
import preferredPM from "preferred-pm";
|
|
8
9
|
import prompts from "prompts";
|
|
9
10
|
import resolvePackage from "resolve";
|
|
10
11
|
import whichPm from "which-pm";
|
|
@@ -76,6 +77,23 @@ function getInstallCommand(packages, packageManager) {
|
|
|
76
77
|
return null;
|
|
77
78
|
}
|
|
78
79
|
}
|
|
80
|
+
async function getExecCommand(packageManager) {
|
|
81
|
+
if (!packageManager) {
|
|
82
|
+
packageManager = (await preferredPM(process.cwd()))?.name ?? "npm";
|
|
83
|
+
}
|
|
84
|
+
switch (packageManager) {
|
|
85
|
+
case "npm":
|
|
86
|
+
return "npx";
|
|
87
|
+
case "yarn":
|
|
88
|
+
return "yarn dlx";
|
|
89
|
+
case "pnpm":
|
|
90
|
+
return "pnpx";
|
|
91
|
+
case "bun":
|
|
92
|
+
return "bunx";
|
|
93
|
+
default:
|
|
94
|
+
return "npx";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
79
97
|
async function installPackage(packageNames, options, logger) {
|
|
80
98
|
const cwd = options.cwd ?? process.cwd();
|
|
81
99
|
const packageManager = (await whichPm(cwd))?.name ?? "npm";
|
|
@@ -133,6 +151,51 @@ ${message}`
|
|
|
133
151
|
return false;
|
|
134
152
|
}
|
|
135
153
|
}
|
|
154
|
+
async function fetchPackageJson(scope, name, tag) {
|
|
155
|
+
const packageName = `${scope ? `${scope}/` : ""}${name}`;
|
|
156
|
+
const registry = await getRegistry();
|
|
157
|
+
const res = await fetch(`${registry}/${packageName}/${tag}`);
|
|
158
|
+
if (res.status >= 200 && res.status < 300) {
|
|
159
|
+
return await res.json();
|
|
160
|
+
} else if (res.status === 404) {
|
|
161
|
+
return new Error();
|
|
162
|
+
} else {
|
|
163
|
+
return new Error(`Failed to fetch ${registry}/${packageName}/${tag} - GET ${res.status}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function fetchPackageVersions(packageName) {
|
|
167
|
+
const registry = await getRegistry();
|
|
168
|
+
const res = await fetch(`${registry}/${packageName}`, {
|
|
169
|
+
headers: { accept: "application/vnd.npm.install-v1+json" }
|
|
170
|
+
});
|
|
171
|
+
if (res.status >= 200 && res.status < 300) {
|
|
172
|
+
return await res.json().then((data) => Object.keys(data.versions));
|
|
173
|
+
} else if (res.status === 404) {
|
|
174
|
+
return new Error();
|
|
175
|
+
} else {
|
|
176
|
+
return new Error(`Failed to fetch ${registry}/${packageName} - GET ${res.status}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
let _registry;
|
|
180
|
+
async function getRegistry() {
|
|
181
|
+
if (_registry)
|
|
182
|
+
return _registry;
|
|
183
|
+
const fallback = "https://registry.npmjs.org";
|
|
184
|
+
const packageManager = (await preferredPM(process.cwd()))?.name || "npm";
|
|
185
|
+
try {
|
|
186
|
+
const { stdout } = await execa(packageManager, ["config", "get", "registry"]);
|
|
187
|
+
_registry = stdout?.trim()?.replace(/\/$/, "") || fallback;
|
|
188
|
+
if (!new URL(_registry).host)
|
|
189
|
+
_registry = fallback;
|
|
190
|
+
} catch (e) {
|
|
191
|
+
_registry = fallback;
|
|
192
|
+
}
|
|
193
|
+
return _registry;
|
|
194
|
+
}
|
|
136
195
|
export {
|
|
137
|
-
|
|
196
|
+
fetchPackageJson,
|
|
197
|
+
fetchPackageVersions,
|
|
198
|
+
getExecCommand,
|
|
199
|
+
getPackage,
|
|
200
|
+
getRegistry
|
|
138
201
|
};
|
package/dist/config/index.js
CHANGED
|
@@ -27,8 +27,8 @@ function getViteConfig(inlineConfig) {
|
|
|
27
27
|
level: "info"
|
|
28
28
|
});
|
|
29
29
|
const { astroConfig: config } = await resolveConfig({}, cmd);
|
|
30
|
-
|
|
31
|
-
await runHookConfigSetup({ settings, command: cmd, logger });
|
|
30
|
+
let settings = await createSettings(config, inlineConfig.root);
|
|
31
|
+
settings = await runHookConfigSetup({ settings, command: cmd, logger });
|
|
32
32
|
const viteConfig = await createVite(
|
|
33
33
|
{
|
|
34
34
|
mode,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PluginContext } from 'rollup';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
export declare function createImage(pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, z.ZodNever | {
|
|
3
|
+
export declare function createImage(pluginContext: PluginContext, shouldEmitFile: boolean, entryFilePath: string): () => z.ZodEffects<z.ZodString, z.ZodNever | {
|
|
4
4
|
ASTRO_ASSET: string;
|
|
5
5
|
src: string;
|
|
6
6
|
width: number;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { emitESMImage } from "../assets/utils/emitAsset.js";
|
|
3
|
-
function createImage(pluginContext, entryFilePath) {
|
|
3
|
+
function createImage(pluginContext, shouldEmitFile, entryFilePath) {
|
|
4
4
|
return () => {
|
|
5
5
|
return z.string().transform(async (imagePath, ctx) => {
|
|
6
6
|
const resolvedFilePath = (await pluginContext.resolve(imagePath, entryFilePath))?.id;
|
|
7
7
|
const metadata = await emitESMImage(
|
|
8
8
|
resolvedFilePath,
|
|
9
9
|
pluginContext.meta.watchMode,
|
|
10
|
-
pluginContext.emitFile
|
|
10
|
+
shouldEmitFile ? pluginContext.emitFile : void 0
|
|
11
11
|
);
|
|
12
12
|
if (!metadata) {
|
|
13
13
|
ctx.addIssue({
|
|
@@ -14,7 +14,7 @@ export declare function createGetCollection({ contentCollectionToEntryMap, dataC
|
|
|
14
14
|
contentCollectionToEntryMap: CollectionToEntryMap;
|
|
15
15
|
dataCollectionToEntryMap: CollectionToEntryMap;
|
|
16
16
|
getRenderEntryImport: GetEntryImport;
|
|
17
|
-
}): (collection: string, filter?: (
|
|
17
|
+
}): (collection: string, filter?: (entry: any) => unknown) => Promise<any[]>;
|
|
18
18
|
export declare function createGetEntryBySlug({ getEntryImport, getRenderEntryImport, }: {
|
|
19
19
|
getEntryImport: GetEntryImport;
|
|
20
20
|
getRenderEntryImport: GetEntryImport;
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ export declare function getEntryData(entry: {
|
|
|
99
99
|
collection: string;
|
|
100
100
|
unvalidatedData: Record<string, unknown>;
|
|
101
101
|
_internal: EntryInternal;
|
|
102
|
-
}, collectionConfig: CollectionConfig, pluginContext: PluginContext): Promise<
|
|
102
|
+
}, collectionConfig: CollectionConfig, shouldEmitFile: boolean, pluginContext: PluginContext): Promise<Record<string, unknown>>;
|
|
103
103
|
export declare function getContentEntryExts(settings: Pick<AstroSettings, 'contentEntryTypes'>): string[];
|
|
104
104
|
export declare function getDataEntryExts(settings: Pick<AstroSettings, 'dataEntryTypes'>): string[];
|
|
105
105
|
export declare function getEntryConfigByExtMap<TEntryType extends ContentEntryType | DataEntryType>(entryTypes: TEntryType[]): Map<string, TEntryType>;
|
package/dist/content/utils.js
CHANGED
|
@@ -49,7 +49,7 @@ function parseEntrySlug({
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
async function getEntryData(entry, collectionConfig, pluginContext) {
|
|
52
|
+
async function getEntryData(entry, collectionConfig, shouldEmitFile, pluginContext) {
|
|
53
53
|
let data;
|
|
54
54
|
if (collectionConfig.type === "data") {
|
|
55
55
|
data = entry.unvalidatedData;
|
|
@@ -60,7 +60,7 @@ async function getEntryData(entry, collectionConfig, pluginContext) {
|
|
|
60
60
|
let schema = collectionConfig.schema;
|
|
61
61
|
if (typeof schema === "function") {
|
|
62
62
|
schema = schema({
|
|
63
|
-
image: createImage(pluginContext, entry._internal.filePath)
|
|
63
|
+
image: createImage(pluginContext, shouldEmitFile, entry._internal.filePath)
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
if (schema) {
|
|
@@ -44,9 +44,13 @@ function astroContentImportPlugin({
|
|
|
44
44
|
const contentEntryConfigByExt = getEntryConfigByExtMap(settings.contentEntryTypes);
|
|
45
45
|
const dataEntryConfigByExt = getEntryConfigByExtMap(settings.dataEntryTypes);
|
|
46
46
|
const { contentDir } = contentPaths;
|
|
47
|
+
let shouldEmitFile = false;
|
|
47
48
|
const plugins = [
|
|
48
49
|
{
|
|
49
50
|
name: "astro:content-imports",
|
|
51
|
+
config(_config, env) {
|
|
52
|
+
shouldEmitFile = env.command === "build";
|
|
53
|
+
},
|
|
50
54
|
async transform(_, viteId) {
|
|
51
55
|
if (hasContentFlag(viteId, DATA_FLAG)) {
|
|
52
56
|
const fileId = viteId.split("?")[0] ?? viteId;
|
|
@@ -56,7 +60,8 @@ function astroContentImportPlugin({
|
|
|
56
60
|
contentDir,
|
|
57
61
|
config: settings.config,
|
|
58
62
|
fs,
|
|
59
|
-
pluginContext: this
|
|
63
|
+
pluginContext: this,
|
|
64
|
+
shouldEmitFile
|
|
60
65
|
});
|
|
61
66
|
const code = `
|
|
62
67
|
export const id = ${JSON.stringify(id)};
|
|
@@ -77,7 +82,8 @@ export const _internal = {
|
|
|
77
82
|
contentDir,
|
|
78
83
|
config: settings.config,
|
|
79
84
|
fs,
|
|
80
|
-
pluginContext: this
|
|
85
|
+
pluginContext: this,
|
|
86
|
+
shouldEmitFile
|
|
81
87
|
});
|
|
82
88
|
const code = `
|
|
83
89
|
export const id = ${JSON.stringify(id)};
|
|
@@ -158,6 +164,7 @@ async function getContentEntryModule(params) {
|
|
|
158
164
|
const data = collectionConfig ? await getEntryData(
|
|
159
165
|
{ id, collection, _internal, unvalidatedData },
|
|
160
166
|
collectionConfig,
|
|
167
|
+
params.shouldEmitFile,
|
|
161
168
|
pluginContext
|
|
162
169
|
) : unvalidatedData;
|
|
163
170
|
const contentEntryModule = {
|
|
@@ -182,6 +189,7 @@ async function getDataEntryModule(params) {
|
|
|
182
189
|
const data = collectionConfig ? await getEntryData(
|
|
183
190
|
{ id, collection, _internal, unvalidatedData },
|
|
184
191
|
collectionConfig,
|
|
192
|
+
params.shouldEmitFile,
|
|
185
193
|
pluginContext
|
|
186
194
|
) : unvalidatedData;
|
|
187
195
|
const dataEntryModule = {
|
|
@@ -334,6 +334,10 @@ async function cleanServerOutput(opts, ssrOutputChunkNames, internals) {
|
|
|
334
334
|
removeEmptyDirs(out);
|
|
335
335
|
}
|
|
336
336
|
if (out.toString() !== opts.settings.config.outDir.toString()) {
|
|
337
|
+
const fileNames = await fs.promises.readdir(out);
|
|
338
|
+
await Promise.all(
|
|
339
|
+
fileNames.filter((fileName) => fileName.endsWith(".d.ts")).map((fileName) => fs.promises.rm(new URL(fileName, out)))
|
|
340
|
+
);
|
|
337
341
|
await copyFiles(out, opts.settings.config.outDir, true);
|
|
338
342
|
await fs.promises.rm(out, { recursive: true });
|
|
339
343
|
return;
|