astro 4.7.1 → 4.8.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 +1 -0
- package/content-module.template.mjs +2 -0
- package/dist/@types/astro.d.ts +219 -3
- package/dist/actions/consts.d.ts +3 -0
- package/dist/actions/consts.js +8 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +72 -0
- package/dist/actions/runtime/middleware.d.ts +7 -0
- package/dist/actions/runtime/middleware.js +38 -0
- package/dist/actions/runtime/route.d.ts +2 -0
- package/dist/actions/runtime/route.js +37 -0
- package/dist/actions/runtime/store.d.ts +6 -0
- package/dist/actions/runtime/store.js +18 -0
- package/dist/actions/runtime/utils.d.ts +4 -0
- package/dist/actions/runtime/utils.js +23 -0
- package/dist/actions/runtime/virtual/client.d.ts +4 -0
- package/dist/actions/runtime/virtual/client.js +20 -0
- package/dist/actions/runtime/virtual/server.d.ts +21 -0
- package/dist/actions/runtime/virtual/server.js +98 -0
- package/dist/actions/runtime/virtual/shared.d.ts +37 -0
- package/dist/actions/runtime/virtual/shared.js +104 -0
- package/dist/actions/utils.d.ts +2 -0
- package/dist/actions/utils.js +18 -0
- package/dist/assets/build/generate.js +1 -1
- package/dist/assets/internal.js +1 -2
- package/dist/assets/services/service.js +2 -4
- package/dist/assets/services/sharp.js +2 -4
- package/dist/assets/services/squoosh.js +2 -4
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +34 -68
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +39 -78
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +32 -64
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +32 -64
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +2 -4
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +29 -58
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +29 -58
- package/dist/assets/utils/getAssetsPrefix.js +2 -4
- package/dist/assets/utils/remotePattern.js +1 -2
- package/dist/assets/utils/remoteProbe.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/cur.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/icns.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/ico.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/utils.js +4 -8
- package/dist/assets/vite-plugin-assets.js +1 -1
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/imports.js +4 -8
- package/dist/cli/add/index.js +23 -46
- package/dist/cli/add/wrapper.js +1 -2
- package/dist/cli/index.js +1 -2
- package/dist/cli/info/index.js +1 -2
- package/dist/cli/install-package.js +3 -6
- package/dist/cli/throw-and-exit.js +1 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +2 -2
- package/dist/content/index.d.ts +1 -1
- package/dist/content/index.js +1 -7
- package/dist/content/runtime.d.ts +2 -1
- package/dist/content/runtime.js +11 -20
- package/dist/content/server-listeners.js +5 -10
- package/dist/content/types-generator.js +5 -10
- package/dist/content/utils.d.ts +0 -4
- package/dist/content/utils.js +4 -15
- package/dist/content/vite-plugin-content-assets.d.ts +1 -1
- package/dist/content/vite-plugin-content-assets.js +14 -47
- package/dist/content/vite-plugin-content-imports.js +6 -11
- package/dist/content/vite-plugin-content-virtual-mod.js +7 -14
- package/dist/core/app/index.js +11 -46
- package/dist/core/app/node.js +4 -3
- package/dist/core/app/pipeline.d.ts +7 -2
- package/dist/core/app/pipeline.js +70 -2
- package/dist/core/app/types.d.ts +1 -0
- package/dist/core/base-pipeline.d.ts +16 -1
- package/dist/core/build/generate.js +15 -61
- package/dist/core/build/index.js +2 -4
- package/dist/core/build/internal.d.ts +39 -9
- package/dist/core/build/internal.js +43 -54
- package/dist/core/build/page-data.js +6 -6
- package/dist/core/build/pipeline.d.ts +7 -3
- package/dist/core/build/pipeline.js +134 -23
- package/dist/core/build/plugins/plugin-analyzer.js +11 -32
- package/dist/core/build/plugins/plugin-content.d.ts +1 -0
- package/dist/core/build/plugins/plugin-content.js +34 -32
- package/dist/core/build/plugins/plugin-css.js +23 -51
- package/dist/core/build/plugins/plugin-manifest.js +7 -8
- package/dist/core/build/plugins/plugin-pages.d.ts +0 -1
- package/dist/core/build/plugins/plugin-pages.js +10 -12
- package/dist/core/build/plugins/plugin-ssr.js +15 -13
- package/dist/core/build/plugins/util.d.ts +26 -11
- package/dist/core/build/plugins/util.js +22 -6
- package/dist/core/build/static-build.js +30 -25
- package/dist/core/build/types.d.ts +6 -6
- package/dist/core/client-directive/build.js +1 -2
- package/dist/core/config/config.js +2 -7
- package/dist/core/config/logging.js +1 -2
- package/dist/core/config/schema.d.ts +92 -60
- package/dist/core/config/schema.js +6 -2
- package/dist/core/config/settings.js +1 -2
- package/dist/core/config/timer.js +4 -8
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +3 -6
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -2
- package/dist/core/errors/errors-data.d.ts +24 -0
- package/dist/core/errors/errors-data.js +13 -2
- package/dist/core/errors/errors.js +1 -2
- package/dist/core/errors/overlay.js +1 -2
- package/dist/core/errors/printer.js +2 -4
- package/dist/core/errors/zod-error-map.js +2 -4
- package/dist/core/fs/index.js +2 -4
- package/dist/core/logger/vite.js +9 -18
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +3 -2
- package/dist/core/middleware/callMiddleware.js +13 -3
- package/dist/core/middleware/index.js +12 -8
- package/dist/core/middleware/sequence.js +22 -4
- package/dist/core/module-loader/vite.js +1 -2
- package/dist/core/render/params-and-props.js +2 -4
- package/dist/core/render/slots.js +4 -8
- package/dist/core/render-context.d.ts +15 -5
- package/dist/core/render-context.js +134 -28
- package/dist/core/request.js +1 -2
- package/dist/core/routing/manifest/create.js +3 -6
- package/dist/core/sync/index.js +10 -3
- package/dist/core/util.d.ts +2 -0
- package/dist/core/util.js +18 -19
- package/dist/i18n/index.js +2 -4
- package/dist/i18n/middleware.js +1 -2
- package/dist/i18n/utils.js +1 -2
- package/dist/i18n/vite-plugin-i18n.js +1 -2
- package/dist/integrations/hooks.js +5 -1
- package/dist/jsx/babel.d.ts +3 -0
- package/dist/jsx/babel.js +9 -18
- package/dist/jsx/rehype.d.ts +11 -0
- package/dist/jsx/rehype.js +197 -0
- package/dist/jsx/server.js +20 -14
- package/dist/jsx/transform-options.d.ts +3 -0
- package/dist/jsx-runtime/index.js +8 -16
- package/dist/preferences/index.js +3 -6
- package/dist/preferences/store.js +3 -6
- package/dist/prefetch/index.js +8 -16
- package/dist/prefetch/vite-plugin-prefetch.js +2 -4
- package/dist/prerender/metadata.js +1 -2
- package/dist/prerender/routing.js +1 -1
- package/dist/prerender/utils.d.ts +0 -1
- package/dist/prerender/utils.js +2 -5
- package/dist/runtime/client/dev-toolbar/apps/astro.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +45 -90
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +16 -32
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +2 -4
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +3 -6
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/utils/window.js +4 -8
- package/dist/runtime/client/dev-toolbar/entrypoint.js +8 -11
- package/dist/runtime/client/dev-toolbar/helpers.js +2 -4
- package/dist/runtime/client/dev-toolbar/toolbar.js +11 -22
- package/dist/runtime/client/dev-toolbar/ui-library/badge.js +1 -2
- package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +5 -0
- package/dist/runtime/client/dev-toolbar/ui-library/button.js +26 -5
- package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
- package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.d.ts +13 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.js +109 -0
- package/dist/runtime/client/visible.js +1 -2
- package/dist/runtime/server/astro-component.js +2 -4
- package/dist/runtime/server/astro-island.js +7 -14
- 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/runtime/server/index.js +3 -6
- package/dist/runtime/server/jsx.js +1 -2
- package/dist/runtime/server/render/any.js +1 -2
- package/dist/runtime/server/render/astro/instance.js +1 -2
- package/dist/runtime/server/render/astro/render.js +5 -10
- package/dist/runtime/server/render/component.js +6 -11
- package/dist/runtime/server/render/dom.js +1 -2
- package/dist/runtime/server/render/page.js +1 -2
- package/dist/runtime/server/render/script.js +1 -2
- package/dist/runtime/server/render/slot.js +1 -2
- package/dist/runtime/server/render/tags.js +2 -4
- package/dist/runtime/server/render/util.js +2 -4
- package/dist/runtime/server/shorthash.js +1 -2
- package/dist/runtime/server/transition.js +4 -8
- package/dist/runtime/server/util.js +1 -2
- package/dist/transitions/events.d.ts +3 -3
- package/dist/transitions/events.js +5 -4
- package/dist/transitions/router.js +22 -113
- package/dist/transitions/swap-functions.d.ts +12 -0
- package/dist/transitions/swap-functions.js +105 -0
- package/dist/vite-plugin-astro/compile.js +1 -2
- package/dist/vite-plugin-astro/hmr.js +5 -10
- package/dist/vite-plugin-astro/index.js +2 -4
- package/dist/vite-plugin-astro-server/pipeline.d.ts +8 -3
- package/dist/vite-plugin-astro-server/pipeline.js +59 -11
- package/dist/vite-plugin-astro-server/plugin.js +6 -6
- package/dist/vite-plugin-astro-server/response.js +1 -2
- package/dist/vite-plugin-astro-server/route.js +36 -42
- package/dist/vite-plugin-astro-server/vite.js +1 -2
- package/dist/vite-plugin-config-alias/index.js +7 -14
- package/dist/vite-plugin-head/index.js +3 -6
- package/dist/vite-plugin-html/index.js +1 -2
- package/dist/vite-plugin-html/transform/escape.js +2 -4
- package/dist/vite-plugin-html/transform/slots.js +1 -2
- package/dist/vite-plugin-html/transform/utils.js +1 -2
- package/dist/vite-plugin-inject-env-ts/index.js +37 -11
- package/dist/vite-plugin-integrations-container/index.js +3 -6
- package/dist/vite-plugin-load-fallback/index.js +1 -2
- package/dist/vite-plugin-markdown/index.js +1 -2
- package/dist/vite-plugin-mdx/index.d.ts +3 -0
- package/dist/vite-plugin-mdx/tag.d.ts +2 -0
- package/dist/vite-plugin-mdx/tag.js +3 -6
- package/dist/vite-plugin-mdx/transform-jsx.d.ts +3 -0
- package/dist/vite-plugin-mdx/transform-jsx.js +1 -2
- package/dist/vite-plugin-scanner/index.js +4 -6
- package/dist/vite-plugin-scanner/scan.js +2 -4
- package/dist/vite-plugin-scripts/page-ssr.js +3 -6
- package/package.json +18 -14
- package/templates/actions.mjs +61 -0
- package/types/actions.d.ts +3 -0
- package/types/content.d.ts +2 -2
|
@@ -23,16 +23,17 @@ function createVitePluginAstroServer({
|
|
|
23
23
|
configureServer(viteServer) {
|
|
24
24
|
const loader = createViteLoader(viteServer);
|
|
25
25
|
const manifest = createDevelopmentManifest(settings);
|
|
26
|
-
const pipeline = DevPipeline.create({ loader, logger, manifest, settings });
|
|
27
26
|
let manifestData = ensure404Route(
|
|
28
27
|
createRouteManifest({ settings, fsMod }, logger)
|
|
29
28
|
);
|
|
29
|
+
const pipeline = DevPipeline.create(manifestData, { loader, logger, manifest, settings });
|
|
30
30
|
const controller = createController({ loader });
|
|
31
31
|
const localStorage = new AsyncLocalStorage();
|
|
32
32
|
function rebuildManifest(needsManifestRebuild) {
|
|
33
33
|
pipeline.clearRouteCache();
|
|
34
34
|
if (needsManifestRebuild) {
|
|
35
35
|
manifestData = ensure404Route(createRouteManifest({ settings }, logger));
|
|
36
|
+
pipeline.setManifestData(manifestData);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
viteServer.watcher.on("add", rebuildManifest.bind(null, true));
|
|
@@ -79,10 +80,8 @@ function createVitePluginAstroServer({
|
|
|
79
80
|
};
|
|
80
81
|
},
|
|
81
82
|
transform(code, id, opts = {}) {
|
|
82
|
-
if (opts.ssr)
|
|
83
|
-
|
|
84
|
-
if (!id.includes("vite/dist/client/client.mjs"))
|
|
85
|
-
return;
|
|
83
|
+
if (opts.ssr) return;
|
|
84
|
+
if (!id.includes("vite/dist/client/client.mjs")) return;
|
|
86
85
|
return patchOverlay(code);
|
|
87
86
|
}
|
|
88
87
|
};
|
|
@@ -105,7 +104,7 @@ function createDevelopmentManifest(settings) {
|
|
|
105
104
|
assets: /* @__PURE__ */ new Set(),
|
|
106
105
|
entryModules: {},
|
|
107
106
|
routes: [],
|
|
108
|
-
adapterName: "",
|
|
107
|
+
adapterName: settings?.adapter?.name || "",
|
|
109
108
|
clientDirectives: settings.clientDirectives,
|
|
110
109
|
renderers: [],
|
|
111
110
|
base: settings.config.base,
|
|
@@ -115,6 +114,7 @@ function createDevelopmentManifest(settings) {
|
|
|
115
114
|
inlinedScripts: /* @__PURE__ */ new Map(),
|
|
116
115
|
i18n: i18nManifest,
|
|
117
116
|
checkOrigin: settings.config.experimental.security?.csrfProtection?.origin ?? false,
|
|
117
|
+
rewritingEnabled: settings.config.experimental.rewriting,
|
|
118
118
|
middleware(_, next) {
|
|
119
119
|
return next();
|
|
120
120
|
}
|
|
@@ -78,7 +78,7 @@ ${AstroErrorData.NoMatchingStaticPathFound.hint(possibleRoutes)}`
|
|
|
78
78
|
}
|
|
79
79
|
if (custom404) {
|
|
80
80
|
const filePath = new URL(`./${custom404.component}`, config.root);
|
|
81
|
-
const preloadedComponent = await pipeline.preload(filePath);
|
|
81
|
+
const preloadedComponent = await pipeline.preload(custom404, filePath);
|
|
82
82
|
return {
|
|
83
83
|
route: custom404,
|
|
84
84
|
filePath,
|
|
@@ -139,40 +139,38 @@ async function handleRoute({
|
|
|
139
139
|
if (!pathNameHasLocale && pathname !== "/") {
|
|
140
140
|
return handle404Response(origin, incomingRequest, incomingResponse);
|
|
141
141
|
}
|
|
142
|
-
request = createRequest({
|
|
143
|
-
base: config.base,
|
|
144
|
-
url,
|
|
145
|
-
headers: incomingRequest.headers,
|
|
146
|
-
logger,
|
|
147
|
-
// no route found, so we assume the default for rendering the 404 page
|
|
148
|
-
staticLike: config.output === "static" || config.output === "hybrid"
|
|
149
|
-
});
|
|
150
|
-
route = {
|
|
151
|
-
component: "",
|
|
152
|
-
generate(_data) {
|
|
153
|
-
return "";
|
|
154
|
-
},
|
|
155
|
-
params: [],
|
|
156
|
-
// Disable eslint as we only want to generate an empty RegExp
|
|
157
|
-
// eslint-disable-next-line prefer-regex-literals
|
|
158
|
-
pattern: new RegExp(""),
|
|
159
|
-
prerender: false,
|
|
160
|
-
segments: [],
|
|
161
|
-
type: "fallback",
|
|
162
|
-
route: "",
|
|
163
|
-
fallbackRoutes: [],
|
|
164
|
-
isIndex: false
|
|
165
|
-
};
|
|
166
|
-
renderContext = RenderContext.create({
|
|
167
|
-
pipeline,
|
|
168
|
-
pathname,
|
|
169
|
-
middleware,
|
|
170
|
-
request,
|
|
171
|
-
routeData: route
|
|
172
|
-
});
|
|
173
|
-
} else {
|
|
174
|
-
return handle404Response(origin, incomingRequest, incomingResponse);
|
|
175
142
|
}
|
|
143
|
+
request = createRequest({
|
|
144
|
+
base: config.base,
|
|
145
|
+
url,
|
|
146
|
+
headers: incomingRequest.headers,
|
|
147
|
+
logger,
|
|
148
|
+
// no route found, so we assume the default for rendering the 404 page
|
|
149
|
+
staticLike: config.output === "static" || config.output === "hybrid"
|
|
150
|
+
});
|
|
151
|
+
route = {
|
|
152
|
+
component: "",
|
|
153
|
+
generate(_data) {
|
|
154
|
+
return "";
|
|
155
|
+
},
|
|
156
|
+
params: [],
|
|
157
|
+
// Disable eslint as we only want to generate an empty RegExp
|
|
158
|
+
// eslint-disable-next-line prefer-regex-literals
|
|
159
|
+
pattern: new RegExp(""),
|
|
160
|
+
prerender: false,
|
|
161
|
+
segments: [],
|
|
162
|
+
type: "fallback",
|
|
163
|
+
route: "",
|
|
164
|
+
fallbackRoutes: [],
|
|
165
|
+
isIndex: false
|
|
166
|
+
};
|
|
167
|
+
renderContext = RenderContext.create({
|
|
168
|
+
pipeline,
|
|
169
|
+
pathname,
|
|
170
|
+
middleware,
|
|
171
|
+
request,
|
|
172
|
+
routeData: route
|
|
173
|
+
});
|
|
176
174
|
} else {
|
|
177
175
|
const filePath = matchedRoute.filePath;
|
|
178
176
|
const { preloadedComponent } = matchedRoute;
|
|
@@ -188,8 +186,7 @@ async function handleRoute({
|
|
|
188
186
|
staticLike: config.output === "static" || route.prerender
|
|
189
187
|
});
|
|
190
188
|
for (const [name, value] of Object.entries(config.server.headers ?? {})) {
|
|
191
|
-
if (value)
|
|
192
|
-
incomingResponse.setHeader(name, value);
|
|
189
|
+
if (value) incomingResponse.setHeader(name, value);
|
|
193
190
|
}
|
|
194
191
|
options = {
|
|
195
192
|
pipeline,
|
|
@@ -258,12 +255,9 @@ async function handleRoute({
|
|
|
258
255
|
await writeSSRResult(request, response, incomingResponse);
|
|
259
256
|
}
|
|
260
257
|
function getStatus(matchedRoute) {
|
|
261
|
-
if (!matchedRoute)
|
|
262
|
-
|
|
263
|
-
if (matchedRoute.route.route === "/
|
|
264
|
-
return 404;
|
|
265
|
-
if (matchedRoute.route.route === "/500")
|
|
266
|
-
return 500;
|
|
258
|
+
if (!matchedRoute) return 404;
|
|
259
|
+
if (matchedRoute.route.route === "/404") return 404;
|
|
260
|
+
if (matchedRoute.route.route === "/500") return 500;
|
|
267
261
|
}
|
|
268
262
|
export {
|
|
269
263
|
handleRoute,
|
|
@@ -28,8 +28,7 @@ async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ ne
|
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
30
30
|
for (const importedModule of entry.importedModules) {
|
|
31
|
-
if (!importedModule.id)
|
|
32
|
-
continue;
|
|
31
|
+
if (!importedModule.id) continue;
|
|
33
32
|
const importedModulePathname = importedModule.id.replace(STRIP_QUERY_PARAMS_REGEX, "");
|
|
34
33
|
const isFileTypeNeedingSSR = fileExtensionsToSSR.has(npath.extname(importedModulePathname));
|
|
35
34
|
const isPropagationStoppingPoint = ASTRO_PROPAGATED_ASSET_REGEX.test(importedModule.id);
|
|
@@ -2,11 +2,9 @@ import path from "node:path";
|
|
|
2
2
|
import { normalizePath } from "vite";
|
|
3
3
|
const getConfigAlias = (settings) => {
|
|
4
4
|
const { tsConfig, tsConfigPath } = settings;
|
|
5
|
-
if (!tsConfig || !tsConfigPath || !tsConfig.compilerOptions)
|
|
6
|
-
return null;
|
|
5
|
+
if (!tsConfig || !tsConfigPath || !tsConfig.compilerOptions) return null;
|
|
7
6
|
const { baseUrl, paths } = tsConfig.compilerOptions;
|
|
8
|
-
if (!baseUrl)
|
|
9
|
-
return null;
|
|
7
|
+
if (!baseUrl) return null;
|
|
10
8
|
const resolvedBaseUrl = path.resolve(path.dirname(tsConfigPath), baseUrl);
|
|
11
9
|
const aliases = [];
|
|
12
10
|
if (paths) {
|
|
@@ -33,8 +31,7 @@ function configAliasVitePlugin({
|
|
|
33
31
|
settings
|
|
34
32
|
}) {
|
|
35
33
|
const configAlias = getConfigAlias(settings);
|
|
36
|
-
if (!configAlias)
|
|
37
|
-
return null;
|
|
34
|
+
if (!configAlias) return null;
|
|
38
35
|
const plugin = {
|
|
39
36
|
name: "astro:tsconfig-alias",
|
|
40
37
|
// use post to only resolve ids that all other plugins before it can't
|
|
@@ -43,8 +40,7 @@ function configAliasVitePlugin({
|
|
|
43
40
|
patchCreateResolver(config, plugin);
|
|
44
41
|
},
|
|
45
42
|
async resolveId(id, importer, options) {
|
|
46
|
-
if (isVirtualId(id))
|
|
47
|
-
return;
|
|
43
|
+
if (isVirtualId(id)) return;
|
|
48
44
|
for (const alias of configAlias) {
|
|
49
45
|
if (alias.find.test(id)) {
|
|
50
46
|
const updatedId = id.replace(alias.find, alias.replacement);
|
|
@@ -52,8 +48,7 @@ function configAliasVitePlugin({
|
|
|
52
48
|
return updatedId;
|
|
53
49
|
}
|
|
54
50
|
const resolved = await this.resolve(updatedId, importer, { skipSelf: true, ...options });
|
|
55
|
-
if (resolved)
|
|
56
|
-
return resolved;
|
|
51
|
+
if (resolved) return resolved;
|
|
57
52
|
}
|
|
58
53
|
}
|
|
59
54
|
}
|
|
@@ -80,15 +75,13 @@ function patchCreateResolver(config, postPlugin) {
|
|
|
80
75
|
ssr
|
|
81
76
|
};
|
|
82
77
|
const result = await resolver.apply(_createResolver, args2);
|
|
83
|
-
if (result)
|
|
84
|
-
return result;
|
|
78
|
+
if (result) return result;
|
|
85
79
|
const resolved = await postPlugin.resolveId.apply(fakePluginContext, [
|
|
86
80
|
id,
|
|
87
81
|
importer,
|
|
88
82
|
fakeResolveIdOpts
|
|
89
83
|
]);
|
|
90
|
-
if (resolved)
|
|
91
|
-
return resolved;
|
|
84
|
+
if (resolved) return resolved;
|
|
92
85
|
};
|
|
93
86
|
};
|
|
94
87
|
}
|
|
@@ -4,8 +4,7 @@ const injectExp = /(?:^\/\/|\/\/!)\s*astro-head-inject/;
|
|
|
4
4
|
function configHeadVitePlugin() {
|
|
5
5
|
let server;
|
|
6
6
|
function propagateMetadata(id, prop, value, seen = /* @__PURE__ */ new Set()) {
|
|
7
|
-
if (seen.has(id))
|
|
8
|
-
return;
|
|
7
|
+
if (seen.has(id)) return;
|
|
9
8
|
seen.add(id);
|
|
10
9
|
const mod = server.moduleGraph.getModuleById(id);
|
|
11
10
|
const info = this.getModuleInfo(id);
|
|
@@ -80,8 +79,7 @@ function astroHeadBuildPlugin(internals) {
|
|
|
80
79
|
generateBundle(_opts, bundle) {
|
|
81
80
|
const map = internals.componentMetadata;
|
|
82
81
|
function getOrCreateMetadata(id) {
|
|
83
|
-
if (map.has(id))
|
|
84
|
-
return map.get(id);
|
|
82
|
+
if (map.has(id)) return map.get(id);
|
|
85
83
|
const metadata = {
|
|
86
84
|
propagation: "none",
|
|
87
85
|
containsHead: false
|
|
@@ -90,8 +88,7 @@ function astroHeadBuildPlugin(internals) {
|
|
|
90
88
|
return metadata;
|
|
91
89
|
}
|
|
92
90
|
for (const [, output] of Object.entries(bundle)) {
|
|
93
|
-
if (output.type !== "chunk")
|
|
94
|
-
continue;
|
|
91
|
+
if (output.type !== "chunk") continue;
|
|
95
92
|
for (const [id, mod] of Object.entries(output.modules)) {
|
|
96
93
|
const modinfo = this.getModuleInfo(id);
|
|
97
94
|
if (modinfo) {
|
|
@@ -6,8 +6,7 @@ function html() {
|
|
|
6
6
|
options.plugins = options.plugins?.filter((p) => p.name !== "vite:build-html");
|
|
7
7
|
},
|
|
8
8
|
async transform(source, id) {
|
|
9
|
-
if (!id.endsWith(".html"))
|
|
10
|
-
return;
|
|
9
|
+
if (!id.endsWith(".html")) return;
|
|
11
10
|
return await transform(source, id);
|
|
12
11
|
}
|
|
13
12
|
};
|
|
@@ -12,14 +12,12 @@ const rehypeEscape = ({ s }) => {
|
|
|
12
12
|
);
|
|
13
13
|
}
|
|
14
14
|
} else if (node.type === "element") {
|
|
15
|
-
if (!node.properties)
|
|
16
|
-
return;
|
|
15
|
+
if (!node.properties) return;
|
|
17
16
|
for (let [key, value] of Object.entries(node.properties)) {
|
|
18
17
|
key = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
19
18
|
const newKey = needsEscape(key) ? escapeTemplateLiteralCharacters(key) : key;
|
|
20
19
|
const newValue = needsEscape(value) ? escapeTemplateLiteralCharacters(value) : value;
|
|
21
|
-
if (newKey === key && newValue === value)
|
|
22
|
-
continue;
|
|
20
|
+
if (newKey === key && newValue === value) continue;
|
|
23
21
|
replaceAttribute(s, node, key, value === "" ? newKey : `${newKey}="${newValue}"`);
|
|
24
22
|
}
|
|
25
23
|
}
|
|
@@ -4,8 +4,7 @@ const rehypeSlots = ({ s }) => {
|
|
|
4
4
|
return (tree, file) => {
|
|
5
5
|
visit(tree, (node) => {
|
|
6
6
|
if (node.type === "element" && node.tagName === "slot") {
|
|
7
|
-
if (typeof node.properties?.["is:inline"] !== "undefined")
|
|
8
|
-
return;
|
|
7
|
+
if (typeof node.properties?.["is:inline"] !== "undefined") return;
|
|
9
8
|
const name = node.properties?.["name"] ?? "default";
|
|
10
9
|
const start = node.position?.start.offset ?? 0;
|
|
11
10
|
const end = node.position?.end.offset ?? 0;
|
|
@@ -3,8 +3,7 @@ function replaceAttribute(s, node, key, newValue) {
|
|
|
3
3
|
splitAttrsTokenizer.lastIndex = 0;
|
|
4
4
|
const text = s.original.slice(node.position?.start.offset ?? 0, node.position?.end.offset ?? 0).toString();
|
|
5
5
|
const offset = text.indexOf(key);
|
|
6
|
-
if (offset === -1)
|
|
7
|
-
return;
|
|
6
|
+
if (offset === -1) return;
|
|
8
7
|
const start = node.position.start.offset + offset;
|
|
9
8
|
const tokens = text.slice(offset).split(splitAttrsTokenizer);
|
|
10
9
|
const token = tokens[0].replace(/([^>])>[\s\S]*$/gm, "$1");
|
|
@@ -2,7 +2,9 @@ import path from "node:path";
|
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { bold } from "kleur/colors";
|
|
4
4
|
import { normalizePath } from "vite";
|
|
5
|
-
import {
|
|
5
|
+
import { ACTIONS_TYPES_FILE } from "../actions/consts.js";
|
|
6
|
+
import { CONTENT_TYPES_FILE } from "../content/consts.js";
|
|
7
|
+
import { getContentPaths } from "../content/index.js";
|
|
6
8
|
import {} from "../core/logger/core.js";
|
|
7
9
|
function getEnvTsPath({ srcDir }) {
|
|
8
10
|
return new URL("env.d.ts", srcDir);
|
|
@@ -29,31 +31,55 @@ async function setUpEnvTs({
|
|
|
29
31
|
}) {
|
|
30
32
|
const envTsPath = getEnvTsPath(settings.config);
|
|
31
33
|
const dotAstroDir = getContentPaths(settings.config).cacheDir;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
+
const dotAstroTypeReferences = getDotAstroTypeReferences({
|
|
35
|
+
root: settings.config.root,
|
|
36
|
+
srcDir: settings.config.srcDir,
|
|
37
|
+
fs
|
|
38
|
+
});
|
|
39
|
+
const envTsPathRelativeToRoot = normalizePath(
|
|
34
40
|
path.relative(fileURLToPath(settings.config.root), fileURLToPath(envTsPath))
|
|
35
41
|
);
|
|
36
42
|
if (fs.existsSync(envTsPath)) {
|
|
37
43
|
let typesEnvContents = await fs.promises.readFile(envTsPath, "utf-8");
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
typesEnvContents = `${expectedTypeReference}
|
|
44
|
+
let addedTypes = false;
|
|
45
|
+
for (const typeReference of dotAstroTypeReferences) {
|
|
46
|
+
if (typesEnvContents.includes(typeReference)) continue;
|
|
47
|
+
typesEnvContents = `${typeReference}
|
|
43
48
|
${typesEnvContents}`;
|
|
44
49
|
await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
|
|
45
|
-
|
|
50
|
+
addedTypes = true;
|
|
51
|
+
}
|
|
52
|
+
if (addedTypes) {
|
|
53
|
+
logger.info("types", `Added ${bold(envTsPathRelativeToRoot)} type declarations`);
|
|
46
54
|
}
|
|
47
55
|
} else {
|
|
48
56
|
let referenceDefs = [];
|
|
49
57
|
referenceDefs.push('/// <reference types="astro/client" />');
|
|
50
58
|
if (fs.existsSync(dotAstroDir)) {
|
|
51
|
-
referenceDefs.push(
|
|
59
|
+
referenceDefs.push(...dotAstroTypeReferences);
|
|
52
60
|
}
|
|
53
61
|
await fs.promises.mkdir(settings.config.srcDir, { recursive: true });
|
|
54
62
|
await fs.promises.writeFile(envTsPath, referenceDefs.join("\n"), "utf-8");
|
|
55
|
-
logger.info("types", `Added ${bold(
|
|
63
|
+
logger.info("types", `Added ${bold(envTsPathRelativeToRoot)} type declarations`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function getDotAstroTypeReferences({
|
|
67
|
+
fs,
|
|
68
|
+
root,
|
|
69
|
+
srcDir
|
|
70
|
+
}) {
|
|
71
|
+
const { cacheDir } = getContentPaths({ root, srcDir });
|
|
72
|
+
let referenceDefs = [];
|
|
73
|
+
const typesFiles = [CONTENT_TYPES_FILE, ACTIONS_TYPES_FILE];
|
|
74
|
+
for (const typesFile of typesFiles) {
|
|
75
|
+
const url = new URL(typesFile, cacheDir);
|
|
76
|
+
if (!fs.existsSync(url)) continue;
|
|
77
|
+
const typesRelativeToSrcDir = normalizePath(
|
|
78
|
+
path.relative(fileURLToPath(srcDir), fileURLToPath(url))
|
|
79
|
+
);
|
|
80
|
+
referenceDefs.push(`/// <reference path=${JSON.stringify(typesRelativeToSrcDir)} />`);
|
|
56
81
|
}
|
|
82
|
+
return referenceDefs;
|
|
57
83
|
}
|
|
58
84
|
export {
|
|
59
85
|
astroInjectEnvTsPlugin,
|
|
@@ -7,13 +7,11 @@ function astroIntegrationsContainerPlugin({
|
|
|
7
7
|
return {
|
|
8
8
|
name: "astro:integration-container",
|
|
9
9
|
async configureServer(server) {
|
|
10
|
-
if (server.config.isProduction)
|
|
11
|
-
return;
|
|
10
|
+
if (server.config.isProduction) return;
|
|
12
11
|
await runHookServerSetup({ config: settings.config, server, logger });
|
|
13
12
|
},
|
|
14
13
|
async buildStart() {
|
|
15
|
-
if (settings.injectedRoutes.length === settings.resolvedInjectedRoutes.length)
|
|
16
|
-
return;
|
|
14
|
+
if (settings.injectedRoutes.length === settings.resolvedInjectedRoutes.length) return;
|
|
17
15
|
settings.resolvedInjectedRoutes = await Promise.all(
|
|
18
16
|
settings.injectedRoutes.map((route) => resolveEntryPoint.call(this, route))
|
|
19
17
|
);
|
|
@@ -22,8 +20,7 @@ function astroIntegrationsContainerPlugin({
|
|
|
22
20
|
}
|
|
23
21
|
async function resolveEntryPoint(route) {
|
|
24
22
|
const resolvedId = await this.resolve(route.entrypoint).then((res) => res?.id).catch(() => void 0);
|
|
25
|
-
if (!resolvedId)
|
|
26
|
-
return route;
|
|
23
|
+
if (!resolvedId) return route;
|
|
27
24
|
const resolvedEntryPoint = new URL(`file://${normalizePath(resolvedId)}`);
|
|
28
25
|
return { ...route, resolvedEntryPoint };
|
|
29
26
|
}
|
|
@@ -31,8 +31,7 @@ function markdown({ settings, logger }) {
|
|
|
31
31
|
async resolveId(source, importer, options) {
|
|
32
32
|
if (importer?.endsWith(".md") && source[0] !== "/") {
|
|
33
33
|
let resolved = await this.resolve(source, importer, options);
|
|
34
|
-
if (!resolved)
|
|
35
|
-
resolved = await this.resolve("./" + source, importer, options);
|
|
34
|
+
if (!resolved) resolved = await this.resolve("./" + source, importer, options);
|
|
36
35
|
return resolved;
|
|
37
36
|
}
|
|
38
37
|
},
|
|
@@ -6,5 +6,7 @@ import type { PluginObj } from '@babel/core';
|
|
|
6
6
|
*
|
|
7
7
|
* This plugin crawls each export in the file and "tags" each export with a given `rendererName`.
|
|
8
8
|
* This allows us to automatically match a component to a renderer and skip the usual `check()` calls.
|
|
9
|
+
*
|
|
10
|
+
* @deprecated This plugin is no longer used. Remove in Astro 5.0
|
|
9
11
|
*/
|
|
10
12
|
export declare const tagExportsPlugin: PluginObj;
|
|
@@ -45,8 +45,7 @@ const tagExportsPlugin = {
|
|
|
45
45
|
*/
|
|
46
46
|
enter(path) {
|
|
47
47
|
const node = path.node;
|
|
48
|
-
if (!t.isExportDefaultDeclaration(node))
|
|
49
|
-
return;
|
|
48
|
+
if (!t.isExportDefaultDeclaration(node)) return;
|
|
50
49
|
if (t.isArrowFunctionExpression(node.declaration) || t.isCallExpression(node.declaration)) {
|
|
51
50
|
const varName = t.isArrowFunctionExpression(node.declaration) ? "_arrow_function" : "_hoc_function";
|
|
52
51
|
const uidIdentifier = path.scope.generateUidIdentifier(varName);
|
|
@@ -61,10 +60,8 @@ const tagExportsPlugin = {
|
|
|
61
60
|
},
|
|
62
61
|
exit(path, state) {
|
|
63
62
|
const node = path.node;
|
|
64
|
-
if (node.exportKind === "type")
|
|
65
|
-
|
|
66
|
-
if (t.isExportAllDeclaration(node))
|
|
67
|
-
return;
|
|
63
|
+
if (node.exportKind === "type") return;
|
|
64
|
+
if (t.isExportAllDeclaration(node)) return;
|
|
68
65
|
const addTag = (id) => {
|
|
69
66
|
const tags = state.get("astro:tags") ?? [];
|
|
70
67
|
state.set("astro:tags", [...tags, id]);
|
|
@@ -17,8 +17,7 @@ async function transformJSX(code, id, ssr) {
|
|
|
17
17
|
browserslistConfigFile: false,
|
|
18
18
|
inputSourceMap: options.inputSourceMap
|
|
19
19
|
});
|
|
20
|
-
if (!result)
|
|
21
|
-
return null;
|
|
20
|
+
if (!result) return null;
|
|
22
21
|
const { astro } = result.metadata;
|
|
23
22
|
return {
|
|
24
23
|
code: result.code || "",
|
|
@@ -2,8 +2,8 @@ import { extname } from "node:path";
|
|
|
2
2
|
import { bold } from "kleur/colors";
|
|
3
3
|
import { normalizePath } from "vite";
|
|
4
4
|
import {} from "../core/logger/core.js";
|
|
5
|
-
import { isEndpoint, isPage, rootRelativePath } from "../core/util.js";
|
|
6
|
-
import { getPrerenderDefault
|
|
5
|
+
import { isEndpoint, isPage, isServerLikeOutput, rootRelativePath } from "../core/util.js";
|
|
6
|
+
import { getPrerenderDefault } from "../prerender/utils.js";
|
|
7
7
|
import { scan } from "./scan.js";
|
|
8
8
|
const KNOWN_FILE_EXTENSIONS = [".astro", ".js", ".ts"];
|
|
9
9
|
function astroScannerPlugin({
|
|
@@ -14,8 +14,7 @@ function astroScannerPlugin({
|
|
|
14
14
|
name: "astro:scanner",
|
|
15
15
|
enforce: "post",
|
|
16
16
|
async transform(code, id, options) {
|
|
17
|
-
if (!options?.ssr)
|
|
18
|
-
return;
|
|
17
|
+
if (!options?.ssr) return;
|
|
19
18
|
const filename = normalizePath(id);
|
|
20
19
|
let fileURL;
|
|
21
20
|
try {
|
|
@@ -25,8 +24,7 @@ function astroScannerPlugin({
|
|
|
25
24
|
}
|
|
26
25
|
const fileIsPage = isPage(fileURL, settings);
|
|
27
26
|
const fileIsEndpoint = isEndpoint(fileURL, settings);
|
|
28
|
-
if (!(fileIsPage || fileIsEndpoint))
|
|
29
|
-
return;
|
|
27
|
+
if (!(fileIsPage || fileIsEndpoint)) return;
|
|
30
28
|
const defaultPrerender = getPrerenderDefault(settings.config);
|
|
31
29
|
const pageOptions = await scan(code, id, settings);
|
|
32
30
|
if (typeof pageOptions.prerender === "undefined") {
|
|
@@ -3,8 +3,7 @@ import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
|
3
3
|
const BOOLEAN_EXPORTS = /* @__PURE__ */ new Set(["prerender"]);
|
|
4
4
|
function includesExport(code) {
|
|
5
5
|
for (const name of BOOLEAN_EXPORTS) {
|
|
6
|
-
if (code.includes(name))
|
|
7
|
-
return true;
|
|
6
|
+
if (code.includes(name)) return true;
|
|
8
7
|
}
|
|
9
8
|
return false;
|
|
10
9
|
}
|
|
@@ -25,8 +24,7 @@ function isFalsy(value) {
|
|
|
25
24
|
}
|
|
26
25
|
let didInit = false;
|
|
27
26
|
async function scan(code, id, settings) {
|
|
28
|
-
if (!includesExport(code))
|
|
29
|
-
return {};
|
|
27
|
+
if (!includesExport(code)) return {};
|
|
30
28
|
if (!didInit) {
|
|
31
29
|
await eslexer.init;
|
|
32
30
|
didInit = true;
|
|
@@ -9,11 +9,9 @@ function astroScriptsPostPlugin({
|
|
|
9
9
|
name: "astro:scripts:page-ssr",
|
|
10
10
|
enforce: "post",
|
|
11
11
|
transform(code, id, options) {
|
|
12
|
-
if (!options?.ssr)
|
|
13
|
-
return;
|
|
12
|
+
if (!options?.ssr) return;
|
|
14
13
|
const hasInjectedScript = settings.scripts.some((s2) => s2.stage === "page-ssr");
|
|
15
|
-
if (!hasInjectedScript)
|
|
16
|
-
return;
|
|
14
|
+
if (!hasInjectedScript) return;
|
|
17
15
|
const filename = normalizePath(id);
|
|
18
16
|
let fileURL;
|
|
19
17
|
try {
|
|
@@ -22,8 +20,7 @@ function astroScriptsPostPlugin({
|
|
|
22
20
|
return;
|
|
23
21
|
}
|
|
24
22
|
const fileIsPage = isPage(fileURL, settings);
|
|
25
|
-
if (!fileIsPage)
|
|
26
|
-
return;
|
|
23
|
+
if (!fileIsPage) return;
|
|
27
24
|
const s = new MagicString(code, { filename });
|
|
28
25
|
s.prepend(`import '${PAGE_SSR_SCRIPT_ID}';
|
|
29
26
|
`);
|