astro 4.11.2 → 4.11.4
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/dist/@types/astro.d.ts +6 -4
- package/dist/cli/install-package.js +2 -1
- package/dist/container/index.js +2 -2
- package/dist/container/pipeline.js +0 -3
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +2 -2
- package/dist/core/build/plugins/plugin-manifest.js +0 -1
- package/dist/core/compile/compile.js +1 -1
- package/dist/core/config/config.d.ts +1 -3
- package/dist/core/config/config.js +13 -19
- package/dist/core/config/validate.d.ts +3 -0
- package/dist/core/config/validate.js +8 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/overlay.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.js +38 -37
- package/dist/core/util.d.ts +0 -11
- package/dist/core/util.js +1 -44
- package/dist/core/viteUtils.d.ts +11 -0
- package/dist/core/viteUtils.js +49 -0
- package/dist/jsx/babel.js +1 -1
- package/dist/jsx/rehype.js +1 -1
- package/dist/runtime/server/render/util.js +5 -11
- package/dist/virtual-modules/i18n.js +3 -2
- package/dist/vite-plugin-astro-server/pipeline.js +4 -6
- package/dist/vite-plugin-astro-server/resolve.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +1 -2
- package/dist/vite-plugin-astro-server/scripts.js +2 -1
- package/dist/vite-plugin-scanner/index.js +2 -1
- package/package.json +6 -6
package/dist/@types/astro.d.ts
CHANGED
|
@@ -648,10 +648,12 @@ export interface AstroUserConfig {
|
|
|
648
648
|
* @default `true`
|
|
649
649
|
* @description
|
|
650
650
|
*
|
|
651
|
-
* This is an option to minify your HTML output and reduce the size of your HTML files
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
651
|
+
* This is an option to minify your HTML output and reduce the size of your HTML files.
|
|
652
|
+
*
|
|
653
|
+
* By default, Astro removes whitespace from your HTML, including line breaks, from `.astro` components in a lossless manner.
|
|
654
|
+
* Some whitespace may be kept as needed to preserve the visual rendering of your HTML. This occurs both in development mode and in the final build.
|
|
655
|
+
*
|
|
656
|
+
* To disable HTML compression, set `compressHTML` to false.
|
|
655
657
|
*
|
|
656
658
|
* ```js
|
|
657
659
|
* {
|
|
@@ -7,9 +7,10 @@ import ora from "ora";
|
|
|
7
7
|
import preferredPM from "preferred-pm";
|
|
8
8
|
import prompts from "prompts";
|
|
9
9
|
import whichPm from "which-pm";
|
|
10
|
+
const require2 = createRequire(import.meta.url);
|
|
10
11
|
async function getPackage(packageName, logger, options, otherDeps = []) {
|
|
11
12
|
try {
|
|
12
|
-
|
|
13
|
+
require2.resolve(packageName, { paths: [options.cwd ?? process.cwd()] });
|
|
13
14
|
const packageImport = await import(packageName);
|
|
14
15
|
return packageImport;
|
|
15
16
|
} catch (e) {
|
package/dist/container/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import { validateConfig } from "../core/config/config.js";
|
|
3
2
|
import { ASTRO_CONFIG_DEFAULTS } from "../core/config/schema.js";
|
|
3
|
+
import { validateConfig } from "../core/config/validate.js";
|
|
4
4
|
import { Logger } from "../core/logger/core.js";
|
|
5
5
|
import { nodeLogDestination } from "../core/logger/node.js";
|
|
6
6
|
import { removeLeadingForwardSlash } from "../core/path.js";
|
|
@@ -73,7 +73,7 @@ class experimental_AstroContainer {
|
|
|
73
73
|
async #containerResolve(specifier, astroConfig) {
|
|
74
74
|
const found = this.#pipeline.manifest.entryModules[specifier];
|
|
75
75
|
if (found) {
|
|
76
|
-
return new URL(found, astroConfig
|
|
76
|
+
return new URL(found, astroConfig?.build.client).toString();
|
|
77
77
|
}
|
|
78
78
|
return found;
|
|
79
79
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Pipeline } from "../core/base-pipeline.js";
|
|
2
|
-
import { RouteNotFound } from "../core/errors/errors-data.js";
|
|
3
|
-
import { AstroError } from "../core/errors/index.js";
|
|
4
2
|
import {
|
|
5
3
|
createModuleScriptElement,
|
|
6
4
|
createStylesheetElementSet
|
|
7
5
|
} from "../core/render/ssr-element.js";
|
|
8
|
-
import { DEFAULT_404_ROUTE } from "../core/routing/astro-designed-error-pages.js";
|
|
9
6
|
import { findRouteToRewrite } from "../core/routing/rewrite.js";
|
|
10
7
|
class ContainerPipeline extends Pipeline {
|
|
11
8
|
/**
|
|
@@ -3,11 +3,11 @@ import { extname } from "node:path";
|
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import glob from "fast-glob";
|
|
5
5
|
import pLimit from "p-limit";
|
|
6
|
-
import {} from "vite";
|
|
7
6
|
import { encodeName } from "../core/build/util.js";
|
|
8
7
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
8
|
import { appendForwardSlash, removeFileExtension } from "../core/path.js";
|
|
10
|
-
import { isServerLikeOutput
|
|
9
|
+
import { isServerLikeOutput } from "../core/util.js";
|
|
10
|
+
import { rootRelativePath } from "../core/viteUtils.js";
|
|
11
11
|
import {
|
|
12
12
|
CONTENT_FLAG,
|
|
13
13
|
CONTENT_RENDER_FLAG,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import glob from "fast-glob";
|
|
3
|
-
import {} from "vite";
|
|
4
3
|
import { getAssetsPrefix } from "../../../assets/utils/getAssetsPrefix.js";
|
|
5
4
|
import { normalizeTheLocale } from "../../../i18n/index.js";
|
|
6
5
|
import { toRoutingStrategy } from "../../../i18n/utils.js";
|
|
@@ -3,7 +3,7 @@ import { transform } from "@astrojs/compiler";
|
|
|
3
3
|
import { normalizePath } from "vite";
|
|
4
4
|
import { AggregateError, CompilerError } from "../errors/errors.js";
|
|
5
5
|
import { AstroErrorData } from "../errors/index.js";
|
|
6
|
-
import { resolvePath } from "../
|
|
6
|
+
import { resolvePath } from "../viteUtils.js";
|
|
7
7
|
import { createStylePreprocessor } from "./style.js";
|
|
8
8
|
async function compile({
|
|
9
9
|
astroConfig,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import type { Arguments as Flags } from 'yargs-parser';
|
|
2
3
|
import type { AstroConfig, AstroInlineConfig, AstroUserConfig, CLIFlags } from '../../@types/astro.js';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
/** Turn raw config values into normalized values */
|
|
5
|
-
export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
|
|
6
4
|
/** Convert the generic "yargs" flag object into our own, custom TypeScript object. */
|
|
7
5
|
export declare function resolveFlags(flags: Partial<Flags>): CLIFlags;
|
|
8
6
|
export declare function resolveRoot(cwd?: string | URL): string;
|
|
@@ -8,23 +8,8 @@ import { trackAstroConfigZodError } from "../errors/errors.js";
|
|
|
8
8
|
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
9
9
|
import { formatConfigErrorMessage } from "../messages.js";
|
|
10
10
|
import { mergeConfig } from "./merge.js";
|
|
11
|
-
import {
|
|
11
|
+
import { validateConfig } from "./validate.js";
|
|
12
12
|
import { loadConfigWithVite } from "./vite-load.js";
|
|
13
|
-
async function validateConfig(userConfig, root, cmd) {
|
|
14
|
-
const AstroConfigRelativeSchema = createRelativeSchema(cmd, root);
|
|
15
|
-
let result;
|
|
16
|
-
try {
|
|
17
|
-
result = await AstroConfigRelativeSchema.parseAsync(userConfig);
|
|
18
|
-
} catch (e) {
|
|
19
|
-
if (e instanceof ZodError) {
|
|
20
|
-
trackAstroConfigZodError(e);
|
|
21
|
-
console.error(formatConfigErrorMessage(e) + "\n");
|
|
22
|
-
telemetry.record(eventConfigError({ cmd, err: e, isFatal: true }));
|
|
23
|
-
}
|
|
24
|
-
throw e;
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
13
|
function resolveFlags(flags) {
|
|
29
14
|
return {
|
|
30
15
|
root: typeof flags.root === "string" ? flags.root : void 0,
|
|
@@ -113,7 +98,17 @@ async function resolveConfig(inlineConfig, command, fsMod = fs) {
|
|
|
113
98
|
}
|
|
114
99
|
const userConfig = await loadConfig(root, inlineOnlyConfig.configFile, fsMod);
|
|
115
100
|
const mergedConfig = mergeConfig(userConfig, inlineUserConfig);
|
|
116
|
-
|
|
101
|
+
let astroConfig;
|
|
102
|
+
try {
|
|
103
|
+
astroConfig = await validateConfig(mergedConfig, root, command);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
if (e instanceof ZodError) {
|
|
106
|
+
trackAstroConfigZodError(e);
|
|
107
|
+
console.error(formatConfigErrorMessage(e) + "\n");
|
|
108
|
+
telemetry.record(eventConfigError({ cmd: command, err: e, isFatal: true }));
|
|
109
|
+
}
|
|
110
|
+
throw e;
|
|
111
|
+
}
|
|
117
112
|
return { userConfig: mergedConfig, astroConfig };
|
|
118
113
|
}
|
|
119
114
|
export {
|
|
@@ -121,6 +116,5 @@ export {
|
|
|
121
116
|
resolveConfig,
|
|
122
117
|
resolveConfigPath,
|
|
123
118
|
resolveFlags,
|
|
124
|
-
resolveRoot
|
|
125
|
-
validateConfig
|
|
119
|
+
resolveRoot
|
|
126
120
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRelativeSchema } from "./schema.js";
|
|
2
|
+
async function validateConfig(userConfig, root, cmd) {
|
|
3
|
+
const AstroConfigRelativeSchema = createRelativeSchema(cmd, root);
|
|
4
|
+
return await AstroConfigRelativeSchema.parseAsync(userConfig);
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
validateConfig
|
|
8
|
+
};
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -19,7 +19,7 @@ async function dev(inlineConfig) {
|
|
|
19
19
|
await telemetry.record([]);
|
|
20
20
|
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
|
|
21
21
|
const logger = restart.container.logger;
|
|
22
|
-
const currentVersion = "4.11.
|
|
22
|
+
const currentVersion = "4.11.4";
|
|
23
23
|
const isPrerelease = currentVersion.includes("-");
|
|
24
24
|
if (!isPrerelease) {
|
|
25
25
|
try {
|
|
@@ -76,7 +76,7 @@ const style = (
|
|
|
76
76
|
--astro-code-token-parameter: #aa0000;
|
|
77
77
|
--astro-code-token-function: #4ca48f;
|
|
78
78
|
--astro-code-token-string-expression: #9f722a;
|
|
79
|
-
--astro-code-token-punctuation: #
|
|
79
|
+
--astro-code-token-punctuation: #000000;
|
|
80
80
|
--astro-code-token-link: #9f722a;
|
|
81
81
|
}
|
|
82
82
|
|
package/dist/core/messages.js
CHANGED
|
@@ -37,7 +37,7 @@ function serverStart({
|
|
|
37
37
|
host,
|
|
38
38
|
base
|
|
39
39
|
}) {
|
|
40
|
-
const version = "4.11.
|
|
40
|
+
const version = "4.11.4";
|
|
41
41
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
42
42
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
43
43
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -269,7 +269,7 @@ function printHelp({
|
|
|
269
269
|
message.push(
|
|
270
270
|
linebreak(),
|
|
271
271
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
272
|
-
`v${"4.11.
|
|
272
|
+
`v${"4.11.4"}`
|
|
273
273
|
)} ${headline}`
|
|
274
274
|
);
|
|
275
275
|
}
|
|
@@ -113,8 +113,9 @@ class RenderContext {
|
|
|
113
113
|
this.routeData = routeData;
|
|
114
114
|
componentInstance = component;
|
|
115
115
|
this.isRewriting = true;
|
|
116
|
+
this.status = 200;
|
|
116
117
|
} else {
|
|
117
|
-
this.pipeline.logger.
|
|
118
|
+
this.pipeline.logger.error(
|
|
118
119
|
"router",
|
|
119
120
|
"The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config."
|
|
120
121
|
);
|
|
@@ -179,30 +180,47 @@ class RenderContext {
|
|
|
179
180
|
getActionResult: createGetActionResult(context.locals)
|
|
180
181
|
});
|
|
181
182
|
}
|
|
183
|
+
async #executeRewrite(reroutePayload) {
|
|
184
|
+
this.pipeline.logger.debug("router", "Calling rewrite: ", reroutePayload);
|
|
185
|
+
if (!this.pipeline.manifest.rewritingEnabled) {
|
|
186
|
+
this.pipeline.logger.error(
|
|
187
|
+
"router",
|
|
188
|
+
"The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config."
|
|
189
|
+
);
|
|
190
|
+
return new Response(
|
|
191
|
+
"The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config.",
|
|
192
|
+
{
|
|
193
|
+
status: 500,
|
|
194
|
+
statusText: "The rewrite API is experimental. To use this feature, add the `rewriting` flag to the `experimental` object in your Astro config."
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const [routeData, component, newURL] = await this.pipeline.tryRewrite(
|
|
199
|
+
reroutePayload,
|
|
200
|
+
this.request,
|
|
201
|
+
this.originalRoute
|
|
202
|
+
);
|
|
203
|
+
this.routeData = routeData;
|
|
204
|
+
if (reroutePayload instanceof Request) {
|
|
205
|
+
this.request = reroutePayload;
|
|
206
|
+
} else {
|
|
207
|
+
this.request = this.#copyRequest(newURL, this.request);
|
|
208
|
+
}
|
|
209
|
+
this.url = new URL(this.request.url);
|
|
210
|
+
this.cookies = new AstroCookies(this.request);
|
|
211
|
+
this.params = getParams(routeData, this.url.pathname);
|
|
212
|
+
this.pathname = this.url.pathname;
|
|
213
|
+
this.isRewriting = true;
|
|
214
|
+
this.status = 200;
|
|
215
|
+
return await this.render(component);
|
|
216
|
+
}
|
|
182
217
|
createActionAPIContext() {
|
|
183
218
|
const renderContext = this;
|
|
184
219
|
const { cookies, params, pipeline, url } = this;
|
|
185
220
|
const generator = `Astro v${ASTRO_VERSION}`;
|
|
186
221
|
const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
|
|
187
222
|
const rewrite = async (reroutePayload) => {
|
|
188
|
-
|
|
189
|
-
const [routeData, component, newURL] = await pipeline.tryRewrite(
|
|
190
|
-
reroutePayload,
|
|
191
|
-
this.request,
|
|
192
|
-
this.originalRoute
|
|
193
|
-
);
|
|
194
|
-
this.routeData = routeData;
|
|
195
|
-
if (reroutePayload instanceof Request) {
|
|
196
|
-
this.request = reroutePayload;
|
|
197
|
-
} else {
|
|
198
|
-
this.request = this.#copyRequest(newURL, this.request);
|
|
199
|
-
}
|
|
200
|
-
this.url = newURL;
|
|
201
|
-
this.cookies = new AstroCookies(this.request);
|
|
202
|
-
this.params = getParams(routeData, this.url.pathname);
|
|
203
|
-
this.isRewriting = true;
|
|
204
|
-
this.pathname = this.url.pathname;
|
|
205
|
-
return await this.render(component);
|
|
223
|
+
return await this.#executeRewrite(reroutePayload);
|
|
206
224
|
};
|
|
207
225
|
return {
|
|
208
226
|
cookies,
|
|
@@ -345,24 +363,7 @@ class RenderContext {
|
|
|
345
363
|
return new Response(null, { status, headers: { Location: path } });
|
|
346
364
|
};
|
|
347
365
|
const rewrite = async (reroutePayload) => {
|
|
348
|
-
|
|
349
|
-
const [routeData, component, newURL] = await pipeline.tryRewrite(
|
|
350
|
-
reroutePayload,
|
|
351
|
-
this.request,
|
|
352
|
-
this.originalRoute
|
|
353
|
-
);
|
|
354
|
-
this.routeData = routeData;
|
|
355
|
-
if (reroutePayload instanceof Request) {
|
|
356
|
-
this.request = reroutePayload;
|
|
357
|
-
} else {
|
|
358
|
-
this.request = this.#copyRequest(newURL, this.request);
|
|
359
|
-
}
|
|
360
|
-
this.url = new URL(this.request.url);
|
|
361
|
-
this.cookies = new AstroCookies(this.request);
|
|
362
|
-
this.params = getParams(routeData, this.url.pathname);
|
|
363
|
-
this.pathname = this.url.pathname;
|
|
364
|
-
this.isRewriting = true;
|
|
365
|
-
return await this.render(component);
|
|
366
|
+
return await this.#executeRewrite(reroutePayload);
|
|
366
367
|
};
|
|
367
368
|
return {
|
|
368
369
|
generator: astroStaticPartial.generator,
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro.js';
|
|
2
|
-
import type { ModuleLoader } from './module-loader/index.js';
|
|
3
2
|
/** Returns true if argument is an object of any prototype/class (but not null). */
|
|
4
3
|
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
5
4
|
/** Cross-realm compatible URL */
|
|
@@ -40,18 +39,8 @@ export declare function isServerLikeOutput(config: AstroConfig): boolean;
|
|
|
40
39
|
export declare function isModeServerWithNoAdapter(settings: AstroSettings): boolean;
|
|
41
40
|
export declare function isContentCollectionsCacheEnabled(config: AstroConfig): boolean;
|
|
42
41
|
export declare function relativeToSrcDir(config: AstroConfig, idOrUrl: URL | string): string;
|
|
43
|
-
export declare function rootRelativePath(root: URL, idOrUrl: URL | string, shouldPrependForwardSlash?: boolean): string;
|
|
44
42
|
export declare function emoji(char: string, fallback: string): string;
|
|
45
|
-
/**
|
|
46
|
-
* Simulate Vite's resolve and import analysis so we can import the id as an URL
|
|
47
|
-
* through a script tag or a dynamic import as-is.
|
|
48
|
-
*/
|
|
49
|
-
export declare function resolveIdToUrl(loader: ModuleLoader, id: string, root?: URL): Promise<string>;
|
|
50
43
|
export declare function resolveJsToTs(filePath: string): string;
|
|
51
|
-
/**
|
|
52
|
-
* Resolve the hydration paths so that it can be imported in the client
|
|
53
|
-
*/
|
|
54
|
-
export declare function resolvePath(specifier: string, importer: string): string;
|
|
55
44
|
/**
|
|
56
45
|
* Set a default NODE_ENV so Vite doesn't set an incorrect default when loading the Astro config
|
|
57
46
|
*/
|
package/dist/core/util.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { normalizePath } from "vite";
|
|
5
4
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./constants.js";
|
|
6
|
-
import {
|
|
5
|
+
import { removeTrailingForwardSlash, slash } from "./path.js";
|
|
7
6
|
function isObject(value) {
|
|
8
7
|
return typeof value === "object" && value != null;
|
|
9
8
|
}
|
|
@@ -123,40 +122,9 @@ function relativeToSrcDir(config, idOrUrl) {
|
|
|
123
122
|
}
|
|
124
123
|
return id.slice(slash(fileURLToPath(config.srcDir)).length);
|
|
125
124
|
}
|
|
126
|
-
function rootRelativePath(root, idOrUrl, shouldPrependForwardSlash = true) {
|
|
127
|
-
let id;
|
|
128
|
-
if (typeof idOrUrl !== "string") {
|
|
129
|
-
id = unwrapId(viteID(idOrUrl));
|
|
130
|
-
} else {
|
|
131
|
-
id = idOrUrl;
|
|
132
|
-
}
|
|
133
|
-
const normalizedRoot = normalizePath(fileURLToPath(root));
|
|
134
|
-
if (id.startsWith(normalizedRoot)) {
|
|
135
|
-
id = id.slice(normalizedRoot.length);
|
|
136
|
-
}
|
|
137
|
-
return shouldPrependForwardSlash ? prependForwardSlash(id) : id;
|
|
138
|
-
}
|
|
139
125
|
function emoji(char, fallback) {
|
|
140
126
|
return process.platform !== "win32" ? char : fallback;
|
|
141
127
|
}
|
|
142
|
-
async function resolveIdToUrl(loader, id, root) {
|
|
143
|
-
let resultId = await loader.resolveId(id, void 0);
|
|
144
|
-
if (!resultId && id.endsWith(".jsx")) {
|
|
145
|
-
resultId = await loader.resolveId(id.slice(0, -4), void 0);
|
|
146
|
-
}
|
|
147
|
-
if (!resultId) {
|
|
148
|
-
return VALID_ID_PREFIX + id;
|
|
149
|
-
}
|
|
150
|
-
if (path.isAbsolute(resultId)) {
|
|
151
|
-
const normalizedRoot = root && normalizePath(fileURLToPath(root));
|
|
152
|
-
if (normalizedRoot && resultId.startsWith(normalizedRoot)) {
|
|
153
|
-
return resultId.slice(normalizedRoot.length - 1);
|
|
154
|
-
} else {
|
|
155
|
-
return "/@fs" + prependForwardSlash(resultId);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return VALID_ID_PREFIX + resultId;
|
|
159
|
-
}
|
|
160
128
|
function resolveJsToTs(filePath) {
|
|
161
129
|
if (filePath.endsWith(".jsx") && !fs.existsSync(filePath)) {
|
|
162
130
|
const tryPath = filePath.slice(0, -4) + ".tsx";
|
|
@@ -166,14 +134,6 @@ function resolveJsToTs(filePath) {
|
|
|
166
134
|
}
|
|
167
135
|
return filePath;
|
|
168
136
|
}
|
|
169
|
-
function resolvePath(specifier, importer) {
|
|
170
|
-
if (specifier.startsWith(".")) {
|
|
171
|
-
const absoluteSpecifier = path.resolve(path.dirname(importer), specifier);
|
|
172
|
-
return resolveJsToTs(normalizePath(absoluteSpecifier));
|
|
173
|
-
} else {
|
|
174
|
-
return specifier;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
137
|
function ensureProcessNodeEnv(defaultNodeEnv) {
|
|
178
138
|
if (!process.env.NODE_ENV) {
|
|
179
139
|
process.env.NODE_ENV = defaultNodeEnv;
|
|
@@ -197,11 +157,8 @@ export {
|
|
|
197
157
|
padMultilineString,
|
|
198
158
|
parseNpmName,
|
|
199
159
|
relativeToSrcDir,
|
|
200
|
-
resolveIdToUrl,
|
|
201
160
|
resolveJsToTs,
|
|
202
161
|
resolvePages,
|
|
203
|
-
resolvePath,
|
|
204
|
-
rootRelativePath,
|
|
205
162
|
unwrapId,
|
|
206
163
|
viteID
|
|
207
164
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ModuleLoader } from './module-loader/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the hydration paths so that it can be imported in the client
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolvePath(specifier: string, importer: string): string;
|
|
6
|
+
export declare function rootRelativePath(root: URL, idOrUrl: URL | string, shouldPrependForwardSlash?: boolean): string;
|
|
7
|
+
/**
|
|
8
|
+
* Simulate Vite's resolve and import analysis so we can import the id as an URL
|
|
9
|
+
* through a script tag or a dynamic import as-is.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveIdToUrl(loader: ModuleLoader, id: string, root?: URL): Promise<string>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { normalizePath } from "vite";
|
|
4
|
+
import { prependForwardSlash } from "../core/path.js";
|
|
5
|
+
import { VALID_ID_PREFIX, resolveJsToTs, unwrapId, viteID } from "./util.js";
|
|
6
|
+
function resolvePath(specifier, importer) {
|
|
7
|
+
if (specifier.startsWith(".")) {
|
|
8
|
+
const absoluteSpecifier = path.resolve(path.dirname(importer), specifier);
|
|
9
|
+
return resolveJsToTs(normalizePath(absoluteSpecifier));
|
|
10
|
+
} else {
|
|
11
|
+
return specifier;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function rootRelativePath(root, idOrUrl, shouldPrependForwardSlash = true) {
|
|
15
|
+
let id;
|
|
16
|
+
if (typeof idOrUrl !== "string") {
|
|
17
|
+
id = unwrapId(viteID(idOrUrl));
|
|
18
|
+
} else {
|
|
19
|
+
id = idOrUrl;
|
|
20
|
+
}
|
|
21
|
+
const normalizedRoot = normalizePath(fileURLToPath(root));
|
|
22
|
+
if (id.startsWith(normalizedRoot)) {
|
|
23
|
+
id = id.slice(normalizedRoot.length);
|
|
24
|
+
}
|
|
25
|
+
return shouldPrependForwardSlash ? prependForwardSlash(id) : id;
|
|
26
|
+
}
|
|
27
|
+
async function resolveIdToUrl(loader, id, root) {
|
|
28
|
+
let resultId = await loader.resolveId(id, void 0);
|
|
29
|
+
if (!resultId && id.endsWith(".jsx")) {
|
|
30
|
+
resultId = await loader.resolveId(id.slice(0, -4), void 0);
|
|
31
|
+
}
|
|
32
|
+
if (!resultId) {
|
|
33
|
+
return VALID_ID_PREFIX + id;
|
|
34
|
+
}
|
|
35
|
+
if (path.isAbsolute(resultId)) {
|
|
36
|
+
const normalizedRoot = root && normalizePath(fileURLToPath(root));
|
|
37
|
+
if (normalizedRoot && resultId.startsWith(normalizedRoot)) {
|
|
38
|
+
return resultId.slice(normalizedRoot.length - 1);
|
|
39
|
+
} else {
|
|
40
|
+
return "/@fs" + prependForwardSlash(resultId);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return VALID_ID_PREFIX + resultId;
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
resolveIdToUrl,
|
|
47
|
+
resolvePath,
|
|
48
|
+
rootRelativePath
|
|
49
|
+
};
|
package/dist/jsx/babel.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
2
|
import { AstroError } from "../core/errors/errors.js";
|
|
3
3
|
import { AstroErrorData } from "../core/errors/index.js";
|
|
4
|
-
import { resolvePath } from "../core/
|
|
4
|
+
import { resolvePath } from "../core/viteUtils.js";
|
|
5
5
|
const ClientOnlyPlaceholder = "astro-client-only";
|
|
6
6
|
function isComponent(tagName) {
|
|
7
7
|
return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^a-zA-Z]/.test(tagName[0]);
|
package/dist/jsx/rehype.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
2
|
import { AstroError } from "../core/errors/errors.js";
|
|
3
3
|
import { AstroErrorData } from "../core/errors/index.js";
|
|
4
|
-
import { resolvePath } from "../core/
|
|
4
|
+
import { resolvePath } from "../core/viteUtils.js";
|
|
5
5
|
const ClientOnlyPlaceholder = "astro-client-only";
|
|
6
6
|
const rehypeAnalyzeAstroMetadata = () => {
|
|
7
7
|
return (tree, file) => {
|
|
@@ -2,8 +2,6 @@ import { clsx } from "clsx";
|
|
|
2
2
|
import { HTMLString, markHTMLString } from "../escape.js";
|
|
3
3
|
const voidElementNames = /^(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/i;
|
|
4
4
|
const htmlBooleanAttributes = /^(?:allowfullscreen|async|autofocus|autoplay|controls|default|defer|disabled|disablepictureinpicture|disableremoteplayback|formnovalidate|hidden|loop|nomodule|novalidate|open|playsinline|readonly|required|reversed|scoped|seamless|itemscope)$/i;
|
|
5
|
-
const htmlEnumAttributes = /^(?:contenteditable|draggable|spellcheck|value)$/i;
|
|
6
|
-
const svgEnumAttributes = /^(?:autoReverse|externalResourcesRequired|focusable|preserveAlpha)$/i;
|
|
7
5
|
const AMPERSAND_REGEX = /&/g;
|
|
8
6
|
const DOUBLE_QUOTE_REGEX = /"/g;
|
|
9
7
|
const STATIC_DIRECTIVES = /* @__PURE__ */ new Set(["set:html", "set:text"]);
|
|
@@ -38,12 +36,6 @@ function addAttribute(value, key, shouldEscape = true) {
|
|
|
38
36
|
if (value == null) {
|
|
39
37
|
return "";
|
|
40
38
|
}
|
|
41
|
-
if (value === false) {
|
|
42
|
-
if (htmlEnumAttributes.test(key) || svgEnumAttributes.test(key)) {
|
|
43
|
-
return markHTMLString(` ${key}="false"`);
|
|
44
|
-
}
|
|
45
|
-
return "";
|
|
46
|
-
}
|
|
47
39
|
if (STATIC_DIRECTIVES.has(key)) {
|
|
48
40
|
console.warn(`[astro] The "${key}" directive cannot be applied dynamically at runtime. It will not be rendered as an attribute.
|
|
49
41
|
|
|
@@ -73,11 +65,13 @@ Make sure to use the static attribute syntax (\`${key}={value}\`) instead of the
|
|
|
73
65
|
if (typeof value === "string" && value.includes("&") && isHttpUrl(value)) {
|
|
74
66
|
return markHTMLString(` ${key}="${toAttributeString(value, false)}"`);
|
|
75
67
|
}
|
|
76
|
-
if (
|
|
68
|
+
if (htmlBooleanAttributes.test(key)) {
|
|
69
|
+
return markHTMLString(value ? ` ${key}` : "");
|
|
70
|
+
}
|
|
71
|
+
if (value === "") {
|
|
77
72
|
return markHTMLString(` ${key}`);
|
|
78
|
-
} else {
|
|
79
|
-
return markHTMLString(` ${key}="${toAttributeString(value, shouldEscape)}"`);
|
|
80
73
|
}
|
|
74
|
+
return markHTMLString(` ${key}="${toAttributeString(value, shouldEscape)}"`);
|
|
81
75
|
}
|
|
82
76
|
function internalSpreadAttributes(values, shouldEscape = true) {
|
|
83
77
|
let output = "";
|
|
@@ -9,7 +9,7 @@ const { trailingSlash, format, site, i18n, isBuild } = (
|
|
|
9
9
|
);
|
|
10
10
|
const { defaultLocale, locales, domains, fallback, routing } = i18n;
|
|
11
11
|
const base = import.meta.env.BASE_URL;
|
|
12
|
-
|
|
12
|
+
let strategy = toRoutingStrategy(routing, domains);
|
|
13
13
|
const noop = (method) => function() {
|
|
14
14
|
throw new AstroError({
|
|
15
15
|
...IncorrectStrategyForI18n,
|
|
@@ -123,10 +123,11 @@ if (i18n?.routing === "manual") {
|
|
|
123
123
|
let middleware;
|
|
124
124
|
if (i18n?.routing === "manual") {
|
|
125
125
|
middleware = (customOptions) => {
|
|
126
|
+
strategy = toRoutingStrategy(customOptions, {});
|
|
126
127
|
const manifest = {
|
|
127
128
|
...i18n,
|
|
128
129
|
fallback: void 0,
|
|
129
|
-
strategy
|
|
130
|
+
strategy,
|
|
130
131
|
domainLookupTable: {}
|
|
131
132
|
};
|
|
132
133
|
return I18nInternals.createMiddleware(manifest, base, trailingSlash, format);
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import { getInfoOutput } from "../cli/info/index.js";
|
|
3
3
|
import {} from "../core/base-pipeline.js";
|
|
4
|
-
import { shouldAppendForwardSlash } from "../core/build/util.js";
|
|
5
4
|
import { ASTRO_VERSION, DEFAULT_404_COMPONENT } from "../core/constants.js";
|
|
6
5
|
import { enhanceViteSSRError } from "../core/errors/dev/index.js";
|
|
7
|
-
import {
|
|
8
|
-
import { AggregateError, AstroError, CSSError, MarkdownError } from "../core/errors/index.js";
|
|
9
|
-
import { prependForwardSlash, removeTrailingForwardSlash } from "../core/path.js";
|
|
6
|
+
import { AggregateError, CSSError, MarkdownError } from "../core/errors/index.js";
|
|
10
7
|
import { Pipeline, loadRenderer } from "../core/render/index.js";
|
|
11
|
-
import {
|
|
8
|
+
import { default404Page } from "../core/routing/astro-designed-error-pages.js";
|
|
12
9
|
import { findRouteToRewrite } from "../core/routing/rewrite.js";
|
|
13
|
-
import { isPage, isServerLikeOutput,
|
|
10
|
+
import { isPage, isServerLikeOutput, viteID } from "../core/util.js";
|
|
11
|
+
import { resolveIdToUrl } from "../core/viteUtils.js";
|
|
14
12
|
import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
|
|
15
13
|
import { getStylesForURL } from "./css.js";
|
|
16
14
|
import { getComponentMetadata } from "./metadata.js";
|
|
@@ -11,9 +11,8 @@ import { getProps } from "../core/render/index.js";
|
|
|
11
11
|
import { createRequest } from "../core/request.js";
|
|
12
12
|
import { default404Page } from "../core/routing/astro-designed-error-pages.js";
|
|
13
13
|
import { matchAllRoutes } from "../core/routing/index.js";
|
|
14
|
-
import { normalizeTheLocale } from "../i18n/index.js";
|
|
15
14
|
import { getSortedPreloadedMatches } from "../prerender/routing.js";
|
|
16
|
-
import {
|
|
15
|
+
import { writeSSRResult, writeWebResponse } from "./response.js";
|
|
17
16
|
function isLoggedRequest(url) {
|
|
18
17
|
return url !== "/favicon.ico";
|
|
19
18
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createModuleScriptElementWithSrc } from "../core/render/ssr-element.js";
|
|
2
|
-
import {
|
|
2
|
+
import { viteID } from "../core/util.js";
|
|
3
|
+
import { rootRelativePath } from "../core/viteUtils.js";
|
|
3
4
|
import { crawlGraph } from "./vite.js";
|
|
4
5
|
async function getScriptsForURL(filePath, root, loader) {
|
|
5
6
|
const elements = /* @__PURE__ */ new Set();
|
|
@@ -2,7 +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, isServerLikeOutput
|
|
5
|
+
import { isEndpoint, isPage, isServerLikeOutput } from "../core/util.js";
|
|
6
|
+
import { rootRelativePath } from "../core/viteUtils.js";
|
|
6
7
|
import { getPrerenderDefault } from "../prerender/utils.js";
|
|
7
8
|
import { scan } from "./scan.js";
|
|
8
9
|
const KNOWN_FILE_EXTENSIONS = [".astro", ".js", ".ts"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "4.11.
|
|
3
|
+
"version": "4.11.4",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -156,13 +156,13 @@
|
|
|
156
156
|
"prompts": "^2.4.2",
|
|
157
157
|
"rehype": "^13.0.1",
|
|
158
158
|
"semver": "^7.6.2",
|
|
159
|
-
"shiki": "^1.
|
|
160
|
-
"string-width": "^7.
|
|
159
|
+
"shiki": "^1.10.0",
|
|
160
|
+
"string-width": "^7.2.0",
|
|
161
161
|
"strip-ansi": "^7.1.0",
|
|
162
|
-
"tsconfck": "^3.1.
|
|
162
|
+
"tsconfck": "^3.1.1",
|
|
163
163
|
"unist-util-visit": "^5.0.0",
|
|
164
164
|
"vfile": "^6.0.1",
|
|
165
|
-
"vite": "^5.3.
|
|
165
|
+
"vite": "^5.3.2",
|
|
166
166
|
"vitefu": "^0.2.5",
|
|
167
167
|
"which-pm": "^2.2.0",
|
|
168
168
|
"yargs-parser": "^21.1.1",
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
},
|
|
178
178
|
"devDependencies": {
|
|
179
179
|
"@astrojs/check": "^0.7.0",
|
|
180
|
-
"@playwright/test": "^1.
|
|
180
|
+
"@playwright/test": "^1.45.0",
|
|
181
181
|
"@types/aria-query": "^5.0.4",
|
|
182
182
|
"@types/babel__generator": "^7.6.8",
|
|
183
183
|
"@types/babel__traverse": "^7.20.6",
|