astro 1.6.2 → 1.6.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 +1 -0
- package/dist/@types/typed-emitter.d.ts +42 -0
- package/dist/@types/typed-emitter.js +0 -0
- package/dist/cli/index.js +18 -56
- package/dist/core/add/babel.d.ts +3 -1
- package/dist/core/app/index.d.ts +1 -0
- package/dist/core/app/index.js +16 -4
- package/dist/core/build/generate.js +10 -6
- package/dist/core/build/vite-plugin-ssr.js +5 -2
- package/dist/core/compile/compile.d.ts +3 -3
- package/dist/core/compile/compile.js +15 -10
- package/dist/core/compile/style.d.ts +7 -4
- package/dist/core/compile/style.js +65 -12
- package/dist/core/config/config.d.ts +7 -3
- package/dist/core/config/config.js +15 -12
- package/dist/core/config/index.d.ts +2 -2
- package/dist/core/config/index.js +4 -1
- package/dist/core/config/schema.d.ts +69 -69
- package/dist/core/config/settings.d.ts +3 -1
- package/dist/core/config/settings.js +23 -5
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.d.ts +4 -1
- package/dist/core/create-vite.js +6 -3
- package/dist/core/dev/container.d.ts +36 -0
- package/dist/core/dev/container.js +109 -0
- package/dist/core/dev/dev.d.ts +24 -0
- package/dist/core/dev/dev.js +55 -0
- package/dist/core/dev/index.d.ts +3 -18
- package/dist/core/dev/index.js +9 -81
- package/dist/core/dev/restart.d.ts +25 -0
- package/dist/core/dev/restart.js +143 -0
- package/dist/core/endpoint/index.d.ts +2 -1
- package/dist/core/endpoint/index.js +12 -1
- package/dist/core/errors/dev/vite.d.ts +3 -2
- package/dist/core/errors/dev/vite.js +4 -6
- package/dist/core/messages.js +2 -2
- package/dist/core/module-loader/index.d.ts +3 -0
- package/dist/core/module-loader/index.js +6 -0
- package/dist/core/module-loader/loader.d.ts +42 -0
- package/dist/core/module-loader/loader.js +39 -0
- package/dist/core/module-loader/vite.d.ts +3 -0
- package/dist/core/module-loader/vite.js +62 -0
- package/dist/core/preview/index.js +2 -1
- package/dist/core/render/dev/css.d.ts +2 -2
- package/dist/core/render/dev/css.js +3 -3
- package/dist/core/render/dev/environment.d.ts +3 -3
- package/dist/core/render/dev/environment.js +3 -3
- package/dist/core/render/dev/index.d.ts +4 -4
- package/dist/core/render/dev/index.js +8 -8
- package/dist/core/render/dev/resolve.d.ts +2 -2
- package/dist/core/render/dev/resolve.js +2 -2
- package/dist/core/render/dev/scripts.d.ts +2 -2
- package/dist/core/render/dev/scripts.js +4 -4
- package/dist/core/render/dev/vite.d.ts +2 -2
- package/dist/core/render/dev/vite.js +5 -5
- package/dist/core/routing/manifest/create.d.ts +10 -3
- package/dist/core/routing/manifest/create.js +7 -6
- package/dist/core/util.d.ts +3 -4
- package/dist/core/util.js +10 -17
- package/dist/vite-plugin-astro/hmr.js +1 -1
- package/dist/vite-plugin-astro/index.js +10 -21
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/base.d.ts +4 -0
- package/dist/vite-plugin-astro-server/base.js +36 -0
- package/dist/vite-plugin-astro-server/common.d.ts +2 -0
- package/dist/vite-plugin-astro-server/common.js +8 -0
- package/dist/vite-plugin-astro-server/controller.d.ts +26 -0
- package/dist/vite-plugin-astro-server/controller.js +77 -0
- package/dist/vite-plugin-astro-server/index.d.ts +3 -10
- package/dist/vite-plugin-astro-server/index.js +7 -336
- package/dist/vite-plugin-astro-server/plugin.d.ts +11 -0
- package/dist/vite-plugin-astro-server/plugin.js +54 -0
- package/dist/vite-plugin-astro-server/request.d.ts +7 -0
- package/dist/vite-plugin-astro-server/request.js +52 -0
- package/dist/vite-plugin-astro-server/response.d.ts +9 -0
- package/dist/vite-plugin-astro-server/response.js +85 -0
- package/dist/vite-plugin-astro-server/route.d.ts +13 -0
- package/dist/vite-plugin-astro-server/route.js +144 -0
- package/dist/vite-plugin-astro-server/server-state.d.ts +15 -0
- package/dist/vite-plugin-astro-server/server-state.js +42 -0
- package/dist/vite-plugin-jsx/index.js +2 -2
- package/dist/vite-plugin-load-fallback/index.d.ts +11 -0
- package/dist/vite-plugin-load-fallback/index.js +59 -0
- package/dist/vite-plugin-markdown/index.js +1 -1
- package/dist/vite-plugin-markdown-legacy/index.js +8 -24
- package/package.json +4 -2
- package/types.d.ts +1 -1
- package/dist/vite-style-transform/index.d.ts +0 -2
- package/dist/vite-style-transform/index.js +0 -5
- package/dist/vite-style-transform/style-transform.d.ts +0 -10
- package/dist/vite-style-transform/style-transform.js +0 -80
- package/dist/vite-style-transform/transform-with-vite.d.ts +0 -18
- package/dist/vite-style-transform/transform-with-vite.js +0 -33
package/dist/@types/astro.d.ts
CHANGED
|
@@ -1289,6 +1289,7 @@ export interface PreviewServerParams {
|
|
|
1289
1289
|
serverEntrypoint: URL;
|
|
1290
1290
|
host: string | undefined;
|
|
1291
1291
|
port: number;
|
|
1292
|
+
base: string;
|
|
1292
1293
|
}
|
|
1293
1294
|
export declare type CreatePreviewServer = (params: PreviewServerParams) => PreviewServer | Promise<PreviewServer>;
|
|
1294
1295
|
export interface PreviewModule {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
* Copyright (c) 2018 Andy Wermke
|
|
4
|
+
* https://github.com/andywer/typed-emitter/blob/9a139b6fa0ec6b0db6141b5b756b784e4f7ef4e4/LICENSE
|
|
5
|
+
*/
|
|
6
|
+
export declare type EventMap = {
|
|
7
|
+
[key: string]: (...args: any[]) => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Type-safe event emitter.
|
|
11
|
+
*
|
|
12
|
+
* Use it like this:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* type MyEvents = {
|
|
16
|
+
* error: (error: Error) => void;
|
|
17
|
+
* message: (from: string, content: string) => void;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* const myEmitter = new EventEmitter() as TypedEmitter<MyEvents>;
|
|
21
|
+
*
|
|
22
|
+
* myEmitter.emit("error", "x") // <- Will catch this type error;
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface TypedEventEmitter<Events extends EventMap> {
|
|
26
|
+
addListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
27
|
+
on<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
28
|
+
once<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
29
|
+
prependListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
30
|
+
prependOnceListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
31
|
+
off<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
32
|
+
removeAllListeners<E extends keyof Events>(event?: E): this;
|
|
33
|
+
removeListener<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
34
|
+
emit<E extends keyof Events>(event: E, ...args: Parameters<Events[E]>): boolean;
|
|
35
|
+
eventNames(): (keyof Events | string | symbol)[];
|
|
36
|
+
rawListeners<E extends keyof Events>(event: E): Events[E][];
|
|
37
|
+
listeners<E extends keyof Events>(event: E): Events[E][];
|
|
38
|
+
listenerCount<E extends keyof Events>(event: E): number;
|
|
39
|
+
getMaxListeners(): number;
|
|
40
|
+
setMaxListeners(maxListeners: number): this;
|
|
41
|
+
}
|
|
42
|
+
export default TypedEventEmitter;
|
|
File without changes
|
package/dist/cli/index.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import * as colors from "kleur/colors";
|
|
2
2
|
import { pathToFileURL } from "url";
|
|
3
|
-
import { normalizePath } from "vite";
|
|
4
3
|
import yargs from "yargs-parser";
|
|
5
4
|
import { z } from "zod";
|
|
6
|
-
import add from "../core/add/index.js";
|
|
7
|
-
import build from "../core/build/index.js";
|
|
8
5
|
import {
|
|
9
6
|
createSettings,
|
|
10
7
|
openConfig,
|
|
11
8
|
resolveConfigPath,
|
|
12
|
-
resolveFlags
|
|
13
|
-
resolveRoot
|
|
9
|
+
resolveFlags
|
|
14
10
|
} from "../core/config/index.js";
|
|
15
11
|
import { ASTRO_VERSION } from "../core/constants.js";
|
|
16
|
-
import devServer from "../core/dev/index.js";
|
|
17
12
|
import { collectErrorMetadata } from "../core/errors/dev/index.js";
|
|
18
13
|
import { createSafeError } from "../core/errors/index.js";
|
|
19
14
|
import { debug, error, info } from "../core/logger/core.js";
|
|
20
15
|
import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js";
|
|
21
16
|
import { formatConfigErrorMessage, formatErrorMessage, printHelp } from "../core/messages.js";
|
|
22
|
-
import { appendForwardSlash } from "../core/path.js";
|
|
23
|
-
import preview from "../core/preview/index.js";
|
|
24
17
|
import * as event from "../events/index.js";
|
|
25
18
|
import { eventConfigError, eventError, telemetry } from "../events/index.js";
|
|
26
19
|
import { check } from "./check/index.js";
|
|
27
20
|
import { openInBrowser } from "./open.js";
|
|
28
|
-
import * as telemetryHandler from "./telemetry.js";
|
|
29
21
|
function printAstroHelp() {
|
|
30
22
|
printHelp({
|
|
31
23
|
commandName: "astro",
|
|
@@ -109,6 +101,7 @@ async function runCommand(cmd, flags) {
|
|
|
109
101
|
}
|
|
110
102
|
switch (cmd) {
|
|
111
103
|
case "add": {
|
|
104
|
+
const { default: add } = await import("../core/add/index.js");
|
|
112
105
|
telemetry.record(event.eventCliSession(cmd));
|
|
113
106
|
const packages = flags._.slice(3);
|
|
114
107
|
return await add(packages, { cwd: root, flags, logging, telemetry });
|
|
@@ -118,6 +111,7 @@ async function runCommand(cmd, flags) {
|
|
|
118
111
|
return await openInBrowser("https://docs.astro.build/");
|
|
119
112
|
}
|
|
120
113
|
case "telemetry": {
|
|
114
|
+
const telemetryHandler = await import("./telemetry.js");
|
|
121
115
|
const subcommand = (_a = flags._[3]) == null ? void 0 : _a.toString();
|
|
122
116
|
return await telemetryHandler.update(subcommand, { flags, telemetry });
|
|
123
117
|
}
|
|
@@ -137,57 +131,24 @@ async function runCommand(cmd, flags) {
|
|
|
137
131
|
let settings = createSettings(initialAstroConfig, root);
|
|
138
132
|
switch (cmd) {
|
|
139
133
|
case "dev": {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (!shouldRestart && settings.watchFiles.length > 0) {
|
|
154
|
-
shouldRestart = settings.watchFiles.some(
|
|
155
|
-
(path) => normalizePath(path) === normalizePath(changedFile)
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (!shouldRestart)
|
|
159
|
-
return;
|
|
160
|
-
restartInFlight = true;
|
|
161
|
-
console.clear();
|
|
162
|
-
try {
|
|
163
|
-
const newConfig = await openConfig({
|
|
164
|
-
cwd: root,
|
|
165
|
-
flags,
|
|
166
|
-
cmd,
|
|
167
|
-
logging,
|
|
168
|
-
isRestart: true
|
|
169
|
-
});
|
|
170
|
-
info(logging, "astro", logMsg + "\n");
|
|
171
|
-
let astroConfig = newConfig.astroConfig;
|
|
172
|
-
settings = createSettings(astroConfig, root);
|
|
173
|
-
await stop();
|
|
174
|
-
await startDevServer({ isRestart: true });
|
|
175
|
-
} catch (e) {
|
|
176
|
-
await handleConfigError(e, { cwd: root, flags, logging });
|
|
177
|
-
await stop();
|
|
178
|
-
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
179
|
-
await startDevServer({ isRestart: true });
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
watcher.on("change", handleServerRestart("Configuration updated. Restarting..."));
|
|
183
|
-
watcher.on("unlink", handleServerRestart("Configuration removed. Restarting..."));
|
|
184
|
-
watcher.on("add", handleServerRestart("Configuration added. Restarting..."));
|
|
185
|
-
}
|
|
186
|
-
await startDevServer({ isRestart: false });
|
|
134
|
+
const { default: devServer } = await import("../core/dev/index.js");
|
|
135
|
+
const configFlag = resolveFlags(flags).config;
|
|
136
|
+
const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags }) : void 0;
|
|
137
|
+
await devServer(settings, {
|
|
138
|
+
configFlag,
|
|
139
|
+
configFlagPath,
|
|
140
|
+
logging,
|
|
141
|
+
telemetry,
|
|
142
|
+
handleConfigError(e) {
|
|
143
|
+
handleConfigError(e, { cwd: root, flags, logging });
|
|
144
|
+
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
145
|
+
}
|
|
146
|
+
});
|
|
187
147
|
return await new Promise(() => {
|
|
188
148
|
});
|
|
189
149
|
}
|
|
190
150
|
case "build": {
|
|
151
|
+
const { default: build } = await import("../core/build/index.js");
|
|
191
152
|
return await build(settings, { ...flags, logging, telemetry });
|
|
192
153
|
}
|
|
193
154
|
case "check": {
|
|
@@ -195,6 +156,7 @@ async function runCommand(cmd, flags) {
|
|
|
195
156
|
return process.exit(ret);
|
|
196
157
|
}
|
|
197
158
|
case "preview": {
|
|
159
|
+
const { default: preview } = await import("../core/preview/index.js");
|
|
198
160
|
const server = await preview(settings, { logging, telemetry });
|
|
199
161
|
return await server.closed();
|
|
200
162
|
}
|
package/dist/core/add/babel.d.ts
CHANGED
|
@@ -9,4 +9,6 @@ export declare const visit: {
|
|
|
9
9
|
};
|
|
10
10
|
export { t };
|
|
11
11
|
export declare function generate(ast: t.File): Promise<string>;
|
|
12
|
-
export declare const parse: (code: string) =>
|
|
12
|
+
export declare const parse: (code: string) => t.File & {
|
|
13
|
+
errors: parser.ParseError[];
|
|
14
|
+
};
|
package/dist/core/app/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface MatchOptions {
|
|
|
9
9
|
export declare class App {
|
|
10
10
|
#private;
|
|
11
11
|
constructor(manifest: Manifest, streaming?: boolean);
|
|
12
|
+
removeBase(pathname: string): string;
|
|
12
13
|
match(request: Request, { matchNotFound }?: MatchOptions): RouteData | undefined;
|
|
13
14
|
render(request: Request, routeData?: RouteData): Promise<Response>;
|
|
14
15
|
setCookieHeaders(response: Response): Generator<string, void, unknown>;
|
package/dist/core/app/index.js
CHANGED
|
@@ -20,13 +20,13 @@ var __privateMethod = (obj, member, method) => {
|
|
|
20
20
|
__accessCheck(obj, member, "access private method");
|
|
21
21
|
return method;
|
|
22
22
|
};
|
|
23
|
-
var _env, _manifest, _manifestData, _routeDataToRouteInfo, _encoder, _logging, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
|
|
23
|
+
var _env, _manifest, _manifestData, _routeDataToRouteInfo, _encoder, _logging, _base, _baseWithoutTrailingSlash, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
|
|
24
24
|
import mime from "mime";
|
|
25
25
|
import { attachToResponse, getSetCookiesFromResponse } from "../cookies/index.js";
|
|
26
26
|
import { call as callEndpoint } from "../endpoint/index.js";
|
|
27
27
|
import { consoleLogDestination } from "../logger/console.js";
|
|
28
28
|
import { error } from "../logger/core.js";
|
|
29
|
-
import { joinPaths, prependForwardSlash } from "../path.js";
|
|
29
|
+
import { joinPaths, prependForwardSlash, removeTrailingForwardSlash } from "../path.js";
|
|
30
30
|
import {
|
|
31
31
|
createEnvironment,
|
|
32
32
|
createRenderContext,
|
|
@@ -54,6 +54,8 @@ class App {
|
|
|
54
54
|
dest: consoleLogDestination,
|
|
55
55
|
level: "info"
|
|
56
56
|
});
|
|
57
|
+
__privateAdd(this, _base, void 0);
|
|
58
|
+
__privateAdd(this, _baseWithoutTrailingSlash, void 0);
|
|
57
59
|
__privateSet(this, _manifest, manifest);
|
|
58
60
|
__privateSet(this, _manifestData, {
|
|
59
61
|
routes: manifest.routes.map((route) => route.routeData)
|
|
@@ -85,13 +87,22 @@ class App {
|
|
|
85
87
|
ssr: true,
|
|
86
88
|
streaming
|
|
87
89
|
}));
|
|
90
|
+
__privateSet(this, _base, __privateGet(this, _manifest).base || "/");
|
|
91
|
+
__privateSet(this, _baseWithoutTrailingSlash, removeTrailingForwardSlash(__privateGet(this, _base)));
|
|
92
|
+
}
|
|
93
|
+
removeBase(pathname) {
|
|
94
|
+
if (pathname.startsWith(__privateGet(this, _base))) {
|
|
95
|
+
return pathname.slice(__privateGet(this, _baseWithoutTrailingSlash).length + 1);
|
|
96
|
+
}
|
|
97
|
+
return pathname;
|
|
88
98
|
}
|
|
89
99
|
match(request, { matchNotFound = false } = {}) {
|
|
90
100
|
const url = new URL(request.url);
|
|
91
101
|
if (__privateGet(this, _manifest).assets.has(url.pathname)) {
|
|
92
102
|
return void 0;
|
|
93
103
|
}
|
|
94
|
-
let
|
|
104
|
+
let pathname = "/" + this.removeBase(url.pathname);
|
|
105
|
+
let routeData = matchRoute(pathname, __privateGet(this, _manifestData));
|
|
95
106
|
if (routeData) {
|
|
96
107
|
return routeData;
|
|
97
108
|
} else if (matchNotFound) {
|
|
@@ -149,11 +160,12 @@ _manifestData = new WeakMap();
|
|
|
149
160
|
_routeDataToRouteInfo = new WeakMap();
|
|
150
161
|
_encoder = new WeakMap();
|
|
151
162
|
_logging = new WeakMap();
|
|
163
|
+
_base = new WeakMap();
|
|
164
|
+
_baseWithoutTrailingSlash = new WeakMap();
|
|
152
165
|
_renderPage = new WeakSet();
|
|
153
166
|
renderPage_fn = async function(request, routeData, mod, status = 200) {
|
|
154
167
|
const url = new URL(request.url);
|
|
155
168
|
const manifest = __privateGet(this, _manifest);
|
|
156
|
-
const renderers = manifest.renderers;
|
|
157
169
|
const info = __privateGet(this, _routeDataToRouteInfo).get(routeData);
|
|
158
170
|
const links = createLinkStylesheetElementSet(info.links, manifest.site);
|
|
159
171
|
let scripts = /* @__PURE__ */ new Set();
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "../../core/path.js";
|
|
12
12
|
import { runHookBuildGenerated } from "../../integrations/index.js";
|
|
13
13
|
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
14
|
-
import { call as callEndpoint } from "../endpoint/index.js";
|
|
14
|
+
import { call as callEndpoint, throwIfRedirectNotAllowed } from "../endpoint/index.js";
|
|
15
15
|
import { debug, info } from "../logger/core.js";
|
|
16
16
|
import { createEnvironment, createRenderContext, renderPage } from "../render/index.js";
|
|
17
17
|
import { callGetStaticPaths } from "../render/route-cache.js";
|
|
@@ -254,15 +254,19 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
254
254
|
const endpointHandler = mod;
|
|
255
255
|
const result = await callEndpoint(endpointHandler, env, ctx);
|
|
256
256
|
if (result.type === "response") {
|
|
257
|
-
|
|
257
|
+
throwIfRedirectNotAllowed(result.response, opts.settings.config);
|
|
258
|
+
if (!result.response.body)
|
|
259
|
+
return;
|
|
260
|
+
body = await result.response.text();
|
|
261
|
+
} else {
|
|
262
|
+
body = result.body;
|
|
263
|
+
encoding = result.encoding;
|
|
258
264
|
}
|
|
259
|
-
body = result.body;
|
|
260
|
-
encoding = result.encoding;
|
|
261
265
|
} else {
|
|
262
266
|
const response = await renderPage(mod, ctx, env);
|
|
263
|
-
|
|
267
|
+
throwIfRedirectNotAllowed(response, opts.settings.config);
|
|
268
|
+
if (!response.body)
|
|
264
269
|
return;
|
|
265
|
-
}
|
|
266
270
|
body = await response.text();
|
|
267
271
|
}
|
|
268
272
|
const outFolder = getOutFolder(settings.config, pathname, pageData.route.type);
|
|
@@ -4,6 +4,7 @@ import { fileURLToPath } from "url";
|
|
|
4
4
|
import { runHookBuildSsr } from "../../integrations/index.js";
|
|
5
5
|
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
6
6
|
import { pagesVirtualModuleId } from "../app/index.js";
|
|
7
|
+
import { removeLeadingForwardSlash, removeTrailingForwardSlash } from "../path.js";
|
|
7
8
|
import { serializeRouteData } from "../routing/index.js";
|
|
8
9
|
import { addRollupInput } from "./add-rollup-input.js";
|
|
9
10
|
import { eachPageData, sortedCSS } from "./internal.js";
|
|
@@ -112,9 +113,11 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
112
113
|
if (settings.scripts.some((script) => script.stage === "page")) {
|
|
113
114
|
scripts.push({ type: "external", value: entryModules[PAGE_SCRIPT_ID] });
|
|
114
115
|
}
|
|
116
|
+
const bareBase = removeTrailingForwardSlash(removeLeadingForwardSlash(settings.config.base));
|
|
117
|
+
const links = sortedCSS(pageData).map((pth) => bareBase ? bareBase + "/" + pth : pth);
|
|
115
118
|
routes.push({
|
|
116
119
|
file: "",
|
|
117
|
-
links
|
|
120
|
+
links,
|
|
118
121
|
scripts: [
|
|
119
122
|
...scripts,
|
|
120
123
|
...settings.scripts.filter((script) => script.stage === "head-inline").map(({ stage, content }) => ({ stage, children: content }))
|
|
@@ -137,7 +140,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
137
140
|
pageMap: null,
|
|
138
141
|
renderers: [],
|
|
139
142
|
entryModules,
|
|
140
|
-
assets: staticFiles.map((s) =>
|
|
143
|
+
assets: staticFiles.map((s) => settings.config.base + s)
|
|
141
144
|
};
|
|
142
145
|
return ssrManifest;
|
|
143
146
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { TransformResult } from '@astrojs/compiler';
|
|
2
|
+
import type { ResolvedConfig } from 'vite';
|
|
2
3
|
import type { AstroConfig } from '../../@types/astro';
|
|
3
|
-
import type { TransformStyle } from './types';
|
|
4
4
|
declare type CompileResult = TransformResult & {
|
|
5
5
|
cssDeps: Set<string>;
|
|
6
6
|
source: string;
|
|
7
7
|
};
|
|
8
8
|
export interface CompileProps {
|
|
9
|
-
|
|
9
|
+
astroConfig: AstroConfig;
|
|
10
|
+
viteConfig: ResolvedConfig;
|
|
10
11
|
filename: string;
|
|
11
12
|
source: string;
|
|
12
|
-
transformStyle: TransformStyle;
|
|
13
13
|
}
|
|
14
14
|
export declare function isCached(config: AstroConfig, filename: string): boolean;
|
|
15
15
|
export declare function getCachedSource(config: AstroConfig, filename: string): string | null;
|
|
@@ -6,25 +6,30 @@ import { resolvePath, viteID } from "../util.js";
|
|
|
6
6
|
import { createStylePreprocessor } from "./style.js";
|
|
7
7
|
const configCache = /* @__PURE__ */ new WeakMap();
|
|
8
8
|
async function compile({
|
|
9
|
-
|
|
9
|
+
astroConfig,
|
|
10
|
+
viteConfig,
|
|
10
11
|
filename,
|
|
11
|
-
source
|
|
12
|
-
transformStyle
|
|
12
|
+
source
|
|
13
13
|
}) {
|
|
14
14
|
var _a;
|
|
15
15
|
let cssDeps = /* @__PURE__ */ new Set();
|
|
16
16
|
let cssTransformErrors = [];
|
|
17
17
|
const transformResult = await transform(source, {
|
|
18
18
|
pathname: filename,
|
|
19
|
-
projectRoot:
|
|
20
|
-
site: (_a =
|
|
19
|
+
projectRoot: astroConfig.root.toString(),
|
|
20
|
+
site: (_a = astroConfig.site) == null ? void 0 : _a.toString(),
|
|
21
21
|
sourcefile: filename,
|
|
22
22
|
sourcemap: "both",
|
|
23
23
|
internalURL: `/@fs${prependForwardSlash(
|
|
24
24
|
viteID(new URL("../../runtime/server/index.js", import.meta.url))
|
|
25
25
|
)}`,
|
|
26
26
|
experimentalStaticExtraction: true,
|
|
27
|
-
preprocessStyle: createStylePreprocessor(
|
|
27
|
+
preprocessStyle: createStylePreprocessor({
|
|
28
|
+
filename,
|
|
29
|
+
viteConfig,
|
|
30
|
+
cssDeps,
|
|
31
|
+
cssTransformErrors
|
|
32
|
+
}),
|
|
28
33
|
async resolvePath(specifier) {
|
|
29
34
|
return resolvePath(specifier, filename);
|
|
30
35
|
}
|
|
@@ -96,13 +101,13 @@ function invalidateCompilation(config, filename) {
|
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
async function cachedCompilation(props) {
|
|
99
|
-
const {
|
|
104
|
+
const { astroConfig, filename } = props;
|
|
100
105
|
let cache;
|
|
101
|
-
if (!configCache.has(
|
|
106
|
+
if (!configCache.has(astroConfig)) {
|
|
102
107
|
cache = /* @__PURE__ */ new Map();
|
|
103
|
-
configCache.set(
|
|
108
|
+
configCache.set(astroConfig, cache);
|
|
104
109
|
} else {
|
|
105
|
-
cache = configCache.get(
|
|
110
|
+
cache = configCache.get(astroConfig);
|
|
106
111
|
}
|
|
107
112
|
if (cache.has(filename)) {
|
|
108
113
|
return cache.get(filename);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { TransformOptions } from '@astrojs/compiler';
|
|
2
|
-
import
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { ResolvedConfig } from 'vite';
|
|
3
|
+
export declare function createStylePreprocessor({ filename, viteConfig, cssDeps, cssTransformErrors, }: {
|
|
4
|
+
filename: string;
|
|
5
|
+
viteConfig: ResolvedConfig;
|
|
6
|
+
cssDeps: Set<string>;
|
|
7
|
+
cssTransformErrors: Error[];
|
|
8
|
+
}): TransformOptions['preprocessStyle'];
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { preprocessCSS } from "vite";
|
|
3
|
+
import { AstroErrorCodes } from "../errors/codes.js";
|
|
4
|
+
import { CSSError } from "../errors/errors.js";
|
|
5
|
+
import { positionAt } from "../errors/index.js";
|
|
6
|
+
function createStylePreprocessor({
|
|
7
|
+
filename,
|
|
8
|
+
viteConfig,
|
|
9
|
+
cssDeps,
|
|
10
|
+
cssTransformErrors
|
|
11
|
+
}) {
|
|
12
|
+
return async (content, attrs) => {
|
|
13
|
+
var _a;
|
|
3
14
|
const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
|
|
15
|
+
const id = `${filename}?astro&type=style&lang${lang}`;
|
|
4
16
|
try {
|
|
5
|
-
const result = await
|
|
6
|
-
|
|
7
|
-
return null;
|
|
8
|
-
for (const dep of result.deps) {
|
|
17
|
+
const result = await preprocessCSS(content, id, viteConfig);
|
|
18
|
+
(_a = result.deps) == null ? void 0 : _a.forEach((dep) => {
|
|
9
19
|
cssDeps.add(dep);
|
|
10
|
-
}
|
|
20
|
+
});
|
|
11
21
|
let map;
|
|
12
22
|
if (result.map) {
|
|
13
23
|
if (typeof result.map === "string") {
|
|
@@ -18,13 +28,56 @@ function createStylePreprocessor(transformStyle, cssDeps, errors) {
|
|
|
18
28
|
}
|
|
19
29
|
return { code: result.code, map };
|
|
20
30
|
} catch (err) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
31
|
+
try {
|
|
32
|
+
err = enhanceCSSError(err, filename);
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
cssTransformErrors.push(err);
|
|
36
|
+
return { error: err + "" };
|
|
25
37
|
}
|
|
26
38
|
};
|
|
27
|
-
|
|
39
|
+
}
|
|
40
|
+
function enhanceCSSError(err, filename) {
|
|
41
|
+
var _a;
|
|
42
|
+
const fileContent = fs.readFileSync(filename).toString();
|
|
43
|
+
const styleTagBeginning = fileContent.indexOf(((_a = err.input) == null ? void 0 : _a.source) ?? err.code);
|
|
44
|
+
if (err.name === "CssSyntaxError") {
|
|
45
|
+
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
|
|
46
|
+
return new CSSError({
|
|
47
|
+
errorCode: AstroErrorCodes.CssSyntaxError,
|
|
48
|
+
message: err.reason,
|
|
49
|
+
location: {
|
|
50
|
+
file: filename,
|
|
51
|
+
line: errorLine,
|
|
52
|
+
column: err.column
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (err.line && err.column) {
|
|
57
|
+
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
|
|
58
|
+
return new CSSError({
|
|
59
|
+
errorCode: AstroErrorCodes.CssUnknownError,
|
|
60
|
+
message: err.message,
|
|
61
|
+
location: {
|
|
62
|
+
file: filename,
|
|
63
|
+
line: errorLine,
|
|
64
|
+
column: err.column
|
|
65
|
+
},
|
|
66
|
+
frame: err.frame
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const errorPosition = positionAt(styleTagBeginning, fileContent);
|
|
70
|
+
errorPosition.line += 1;
|
|
71
|
+
return new CSSError({
|
|
72
|
+
errorCode: AstroErrorCodes.CssUnknownError,
|
|
73
|
+
message: err.message,
|
|
74
|
+
location: {
|
|
75
|
+
file: filename,
|
|
76
|
+
line: errorPosition.line,
|
|
77
|
+
column: 0
|
|
78
|
+
},
|
|
79
|
+
frame: err.frame
|
|
80
|
+
});
|
|
28
81
|
}
|
|
29
82
|
export {
|
|
30
83
|
createStylePreprocessor
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { Arguments as Flags } from 'yargs-parser';
|
|
2
3
|
import type { AstroConfig, AstroUserConfig, CLIFlags } from '../../@types/astro';
|
|
4
|
+
import fs from 'fs';
|
|
3
5
|
import { LogOptions } from '../logger/core.js';
|
|
4
6
|
export declare const LEGACY_ASTRO_CONFIG_KEYS: Set<string>;
|
|
5
7
|
/** Turn raw config values into normalized values */
|
|
6
|
-
export declare function validateConfig(userConfig: any, root: string, cmd: string
|
|
8
|
+
export declare function validateConfig(userConfig: any, root: string, cmd: string): Promise<AstroConfig>;
|
|
7
9
|
/** Convert the generic "yargs" flag object into our own, custom TypeScript object. */
|
|
8
10
|
export declare function resolveFlags(flags: Partial<Flags>): CLIFlags;
|
|
9
|
-
export declare function resolveRoot(cwd?: string): string;
|
|
11
|
+
export declare function resolveRoot(cwd?: string | URL): string;
|
|
10
12
|
interface LoadConfigOptions {
|
|
11
13
|
cwd?: string;
|
|
12
14
|
flags?: Flags;
|
|
@@ -15,6 +17,7 @@ interface LoadConfigOptions {
|
|
|
15
17
|
logging: LogOptions;
|
|
16
18
|
/** Invalidate when reloading a previously loaded config */
|
|
17
19
|
isRestart?: boolean;
|
|
20
|
+
fsMod?: typeof fs;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
|
|
@@ -36,6 +39,7 @@ export declare function openConfig(configOptions: LoadConfigOptions): Promise<Op
|
|
|
36
39
|
*/
|
|
37
40
|
export declare function loadConfig(configOptions: LoadConfigOptions): Promise<AstroConfig>;
|
|
38
41
|
/** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */
|
|
39
|
-
export declare function resolveConfig(userConfig: AstroUserConfig, root: string, flags: CLIFlags | undefined, cmd: string
|
|
42
|
+
export declare function resolveConfig(userConfig: AstroUserConfig, root: string, flags: CLIFlags | undefined, cmd: string): Promise<AstroConfig>;
|
|
43
|
+
export declare function createDefaultDevConfig(userConfig?: AstroUserConfig, root?: string): Promise<AstroConfig>;
|
|
40
44
|
export declare function mergeConfig(defaults: Record<string, any>, overrides: Record<string, any>, isRoot?: boolean): Record<string, any>;
|
|
41
45
|
export {};
|
|
@@ -20,7 +20,7 @@ const LEGACY_ASTRO_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
20
20
|
"buildOptions",
|
|
21
21
|
"devOptions"
|
|
22
22
|
]);
|
|
23
|
-
async function validateConfig(userConfig, root, cmd
|
|
23
|
+
async function validateConfig(userConfig, root, cmd) {
|
|
24
24
|
const fileProtocolRoot = pathToFileURL(root + path.sep);
|
|
25
25
|
if (userConfig.hasOwnProperty("renderers")) {
|
|
26
26
|
console.error('Astro "renderers" are now "integrations"!');
|
|
@@ -80,6 +80,9 @@ function resolveFlags(flags) {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
function resolveRoot(cwd) {
|
|
83
|
+
if (cwd instanceof URL) {
|
|
84
|
+
cwd = fileURLToPath(cwd);
|
|
85
|
+
}
|
|
83
86
|
return cwd ? path.resolve(cwd) : process.cwd();
|
|
84
87
|
}
|
|
85
88
|
function mergeCLIFlags(astroConfig, flags, cmd) {
|
|
@@ -129,13 +132,7 @@ async function openConfig(configOptions) {
|
|
|
129
132
|
if (config) {
|
|
130
133
|
userConfig = config.value;
|
|
131
134
|
}
|
|
132
|
-
const astroConfig = await resolveConfig(
|
|
133
|
-
userConfig,
|
|
134
|
-
root,
|
|
135
|
-
flags,
|
|
136
|
-
configOptions.cmd,
|
|
137
|
-
configOptions.logging
|
|
138
|
-
);
|
|
135
|
+
const astroConfig = await resolveConfig(userConfig, root, flags, configOptions.cmd);
|
|
139
136
|
return {
|
|
140
137
|
astroConfig,
|
|
141
138
|
userConfig,
|
|
@@ -144,6 +141,7 @@ async function openConfig(configOptions) {
|
|
|
144
141
|
};
|
|
145
142
|
}
|
|
146
143
|
async function tryLoadConfig(configOptions, flags, root) {
|
|
144
|
+
const fsMod = configOptions.fsMod ?? fs;
|
|
147
145
|
let finallyCleanup = async () => {
|
|
148
146
|
};
|
|
149
147
|
try {
|
|
@@ -158,7 +156,8 @@ async function tryLoadConfig(configOptions, flags, root) {
|
|
|
158
156
|
root,
|
|
159
157
|
`.temp.${Date.now()}.config${path.extname(configPath)}`
|
|
160
158
|
);
|
|
161
|
-
|
|
159
|
+
const currentConfigContent = await fsMod.promises.readFile(configPath, "utf-8");
|
|
160
|
+
await fs.promises.writeFile(tempConfigPath, currentConfigContent);
|
|
162
161
|
finallyCleanup = async () => {
|
|
163
162
|
try {
|
|
164
163
|
await fs.promises.unlink(tempConfigPath);
|
|
@@ -213,13 +212,16 @@ async function loadConfig(configOptions) {
|
|
|
213
212
|
if (config) {
|
|
214
213
|
userConfig = config.value;
|
|
215
214
|
}
|
|
216
|
-
return resolveConfig(userConfig, root, flags, configOptions.cmd
|
|
215
|
+
return resolveConfig(userConfig, root, flags, configOptions.cmd);
|
|
217
216
|
}
|
|
218
|
-
async function resolveConfig(userConfig, root, flags = {}, cmd
|
|
217
|
+
async function resolveConfig(userConfig, root, flags = {}, cmd) {
|
|
219
218
|
const mergedConfig = mergeCLIFlags(userConfig, flags, cmd);
|
|
220
|
-
const validatedConfig = await validateConfig(mergedConfig, root, cmd
|
|
219
|
+
const validatedConfig = await validateConfig(mergedConfig, root, cmd);
|
|
221
220
|
return validatedConfig;
|
|
222
221
|
}
|
|
222
|
+
function createDefaultDevConfig(userConfig = {}, root = process.cwd()) {
|
|
223
|
+
return resolveConfig(userConfig, root, void 0, "dev");
|
|
224
|
+
}
|
|
223
225
|
function mergeConfigRecursively(defaults, overrides, rootPath) {
|
|
224
226
|
const merged = { ...defaults };
|
|
225
227
|
for (const key in overrides) {
|
|
@@ -257,6 +259,7 @@ function mergeConfig(defaults, overrides, isRoot = true) {
|
|
|
257
259
|
}
|
|
258
260
|
export {
|
|
259
261
|
LEGACY_ASTRO_CONFIG_KEYS,
|
|
262
|
+
createDefaultDevConfig,
|
|
260
263
|
loadConfig,
|
|
261
264
|
mergeConfig,
|
|
262
265
|
openConfig,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { openConfig, resolveConfigPath, resolveFlags, resolveRoot, validateConfig, } from './config.js';
|
|
1
|
+
export { createDefaultDevConfig, openConfig, resolveConfigPath, resolveFlags, resolveRoot, validateConfig, } from './config.js';
|
|
2
2
|
export type { AstroConfigSchema } from './schema';
|
|
3
|
-
export { createSettings } from './settings.js';
|
|
3
|
+
export { createDefaultDevSettings, createSettings } from './settings.js';
|
|
4
4
|
export { loadTSConfig, updateTSConfigForFramework } from './tsconfig.js';
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
+
createDefaultDevConfig,
|
|
2
3
|
openConfig,
|
|
3
4
|
resolveConfigPath,
|
|
4
5
|
resolveFlags,
|
|
5
6
|
resolveRoot,
|
|
6
7
|
validateConfig
|
|
7
8
|
} from "./config.js";
|
|
8
|
-
import { createSettings } from "./settings.js";
|
|
9
|
+
import { createDefaultDevSettings, createSettings } from "./settings.js";
|
|
9
10
|
import { loadTSConfig, updateTSConfigForFramework } from "./tsconfig.js";
|
|
10
11
|
export {
|
|
12
|
+
createDefaultDevConfig,
|
|
13
|
+
createDefaultDevSettings,
|
|
11
14
|
createSettings,
|
|
12
15
|
loadTSConfig,
|
|
13
16
|
openConfig,
|