astro 1.4.7 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Code.astro +1 -1
- package/dist/@types/astro.d.ts +200 -19
- package/dist/cli/index.js +35 -36
- package/dist/config/index.js +2 -7
- package/dist/core/add/index.js +140 -23
- package/dist/core/build/index.js +3 -3
- package/dist/core/config/config.d.ts +1 -1
- package/dist/core/config/config.js +6 -2
- package/dist/core/config/index.d.ts +1 -1
- package/dist/core/config/index.js +2 -1
- package/dist/core/config/schema.d.ts +139 -1
- package/dist/core/config/schema.js +24 -2
- package/dist/core/config/settings.d.ts +1 -7
- package/dist/core/config/settings.js +7 -4
- package/dist/core/config/tsconfig.d.ts +10 -1
- package/dist/core/config/tsconfig.js +73 -7
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +4 -0
- package/dist/core/cookies/cookies.d.ts +1 -1
- package/dist/core/dev/index.js +7 -2
- package/dist/core/endpoint/dev/index.js +4 -1
- package/dist/core/endpoint/index.d.ts +1 -1
- package/dist/core/endpoint/index.js +44 -4
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.d.ts +2 -11
- package/dist/core/preview/index.js +31 -125
- package/dist/core/preview/static-preview-server.d.ts +17 -0
- package/dist/core/preview/static-preview-server.js +127 -0
- package/dist/core/render/core.d.ts +1 -1
- package/dist/core/render/result.js +2 -2
- package/dist/core/util.d.ts +3 -14
- package/dist/core/util.js +4 -2
- package/dist/events/index.js +1 -1
- package/dist/integrations/index.d.ts +3 -2
- package/dist/integrations/index.js +39 -2
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/vite-plugin-jsx/index.js +9 -5
- package/dist/vite-plugin-jsx/tag.d.ts +3 -2
- package/dist/vite-plugin-jsx/tag.js +10 -4
- package/package.json +4 -2
|
@@ -1,134 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import sirv from "sirv";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
import { notFoundTemplate, subpathNotUsedTemplate } from "../../template/4xx.js";
|
|
7
|
-
import { error, info } from "../logger/core.js";
|
|
8
|
-
import * as msg from "../messages.js";
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
import { runHookConfigDone, runHookConfigSetup } from "../../integrations/index.js";
|
|
3
|
+
import createStaticPreviewServer from "./static-preview-server.js";
|
|
9
4
|
import { getResolvedHostForHttpServer } from "./util.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
const startServerTime = performance.now();
|
|
18
|
-
const defaultOrigin = "http://localhost";
|
|
19
|
-
const trailingSlash = settings.config.trailingSlash;
|
|
20
|
-
let baseURL = new URL(settings.config.base, new URL(settings.config.site || "/", defaultOrigin));
|
|
21
|
-
const staticFileServer = sirv(fileURLToPath(settings.config.outDir), {
|
|
22
|
-
dev: true,
|
|
23
|
-
etag: true,
|
|
24
|
-
maxAge: 0
|
|
25
|
-
});
|
|
26
|
-
const server = http.createServer((req, res) => {
|
|
27
|
-
var _a;
|
|
28
|
-
const requestURL = new URL(req.url, defaultOrigin);
|
|
29
|
-
if (!requestURL.pathname.startsWith(baseURL.pathname)) {
|
|
30
|
-
res.statusCode = 404;
|
|
31
|
-
res.end(subpathNotUsedTemplate(baseURL.pathname, requestURL.pathname));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const pathname = requestURL.pathname.slice(baseURL.pathname.length - 1);
|
|
35
|
-
const isRoot = pathname === "/";
|
|
36
|
-
const hasTrailingSlash = isRoot || pathname.endsWith("/");
|
|
37
|
-
function sendError(message) {
|
|
38
|
-
res.statusCode = 404;
|
|
39
|
-
res.end(notFoundTemplate(pathname, message));
|
|
40
|
-
}
|
|
41
|
-
switch (true) {
|
|
42
|
-
case (hasTrailingSlash && trailingSlash == "never" && !isRoot):
|
|
43
|
-
sendError('Not Found (trailingSlash is set to "never")');
|
|
44
|
-
return;
|
|
45
|
-
case (!hasTrailingSlash && trailingSlash == "always" && !isRoot && !HAS_FILE_EXTENSION_REGEXP.test(pathname)):
|
|
46
|
-
sendError('Not Found (trailingSlash is set to "always")');
|
|
47
|
-
return;
|
|
48
|
-
default: {
|
|
49
|
-
req.url = "/" + ((_a = req.url) == null ? void 0 : _a.replace(baseURL.pathname, ""));
|
|
50
|
-
staticFileServer(req, res, () => {
|
|
51
|
-
const errorPagePath = fileURLToPath(settings.config.outDir + "/404.html");
|
|
52
|
-
if (fs.existsSync(errorPagePath)) {
|
|
53
|
-
res.statusCode = 404;
|
|
54
|
-
res.setHeader("Content-Type", "text/html;charset=utf-8");
|
|
55
|
-
res.end(fs.readFileSync(errorPagePath));
|
|
56
|
-
} else {
|
|
57
|
-
staticFileServer(req, res, () => {
|
|
58
|
-
sendError("Not Found");
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
5
|
+
async function preview(_settings, { logging }) {
|
|
6
|
+
const settings = await runHookConfigSetup({
|
|
7
|
+
settings: _settings,
|
|
8
|
+
command: "preview",
|
|
9
|
+
logging
|
|
65
10
|
});
|
|
66
|
-
|
|
11
|
+
await runHookConfigDone({ settings, logging });
|
|
67
12
|
const host = getResolvedHostForHttpServer(settings.config.server.host);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!showedListenMsg) {
|
|
76
|
-
const resolvedUrls = msg.resolveServerUrls({
|
|
77
|
-
address: server.address(),
|
|
78
|
-
host: settings.config.server.host,
|
|
79
|
-
https: false
|
|
80
|
-
});
|
|
81
|
-
info(
|
|
82
|
-
logging,
|
|
83
|
-
null,
|
|
84
|
-
msg.serverStart({
|
|
85
|
-
startupTime: performance.now() - timerStart,
|
|
86
|
-
resolvedUrls,
|
|
87
|
-
host: settings.config.server.host,
|
|
88
|
-
site: baseURL
|
|
89
|
-
})
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
showedListenMsg = true;
|
|
93
|
-
resolve();
|
|
94
|
-
});
|
|
95
|
-
httpServer == null ? void 0 : httpServer.on("error", onError);
|
|
96
|
-
};
|
|
97
|
-
const onError = (err) => {
|
|
98
|
-
if (err.code && err.code === "EADDRINUSE") {
|
|
99
|
-
if (!showedPortTakenMsg) {
|
|
100
|
-
info(logging, "astro", msg.portInUse({ port }));
|
|
101
|
-
showedPortTakenMsg = true;
|
|
102
|
-
}
|
|
103
|
-
port++;
|
|
104
|
-
return listen();
|
|
105
|
-
} else {
|
|
106
|
-
error(logging, "astro", err.stack || err.message);
|
|
107
|
-
httpServer == null ? void 0 : httpServer.removeListener("error", onError);
|
|
108
|
-
reject(err);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
listen();
|
|
112
|
-
});
|
|
13
|
+
const { port } = settings.config.server;
|
|
14
|
+
if (settings.config.output === "static") {
|
|
15
|
+
const server2 = await createStaticPreviewServer(settings, { logging, host, port });
|
|
16
|
+
return server2;
|
|
17
|
+
}
|
|
18
|
+
if (!settings.adapter) {
|
|
19
|
+
throw new Error(`[preview] No adapter found.`);
|
|
113
20
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return new Promise((resolve, reject) => {
|
|
117
|
-
httpServer.addListener("close", resolve);
|
|
118
|
-
httpServer.addListener("error", reject);
|
|
119
|
-
});
|
|
21
|
+
if (!settings.adapter.previewEntrypoint) {
|
|
22
|
+
throw new Error(`[preview] adapter does not have previewEntrypoint.`);
|
|
120
23
|
}
|
|
121
|
-
|
|
24
|
+
const require2 = createRequire(settings.config.root);
|
|
25
|
+
const previewEntrypoint = require2.resolve(settings.adapter.previewEntrypoint);
|
|
26
|
+
const previewModule = await import(previewEntrypoint);
|
|
27
|
+
if (typeof previewModule.default !== "function") {
|
|
28
|
+
throw new Error(`[preview] ${settings.adapter.name} cannot preview your app.`);
|
|
29
|
+
}
|
|
30
|
+
const server = await previewModule.default({
|
|
31
|
+
outDir: settings.config.outDir,
|
|
32
|
+
client: settings.config.build.client,
|
|
33
|
+
serverEntrypoint: new URL(settings.config.build.serverEntry, settings.config.build.server),
|
|
122
34
|
host,
|
|
123
|
-
port
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
stop: async () => {
|
|
127
|
-
await new Promise((resolve, reject) => {
|
|
128
|
-
httpServer.close((err) => err ? reject(err) : resolve(void 0));
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
35
|
+
port
|
|
36
|
+
});
|
|
37
|
+
return server;
|
|
132
38
|
}
|
|
133
39
|
export {
|
|
134
40
|
preview as default
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { AstroSettings } from '../../@types/astro';
|
|
3
|
+
import type { LogOptions } from '../logger/core';
|
|
4
|
+
import http from 'http';
|
|
5
|
+
export interface PreviewServer {
|
|
6
|
+
host?: string;
|
|
7
|
+
port: number;
|
|
8
|
+
server: http.Server;
|
|
9
|
+
closed(): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/** The primary dev action */
|
|
13
|
+
export default function createStaticPreviewServer(settings: AstroSettings, { logging, host, port }: {
|
|
14
|
+
logging: LogOptions;
|
|
15
|
+
host: string | undefined;
|
|
16
|
+
port: number;
|
|
17
|
+
}): Promise<PreviewServer>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import http from "http";
|
|
3
|
+
import { performance } from "perf_hooks";
|
|
4
|
+
import sirv from "sirv";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import { notFoundTemplate, subpathNotUsedTemplate } from "../../template/4xx.js";
|
|
7
|
+
import { error, info } from "../logger/core.js";
|
|
8
|
+
import * as msg from "../messages.js";
|
|
9
|
+
const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
|
|
10
|
+
async function createStaticPreviewServer(settings, { logging, host, port }) {
|
|
11
|
+
const startServerTime = performance.now();
|
|
12
|
+
const defaultOrigin = "http://localhost";
|
|
13
|
+
const trailingSlash = settings.config.trailingSlash;
|
|
14
|
+
let baseURL = new URL(settings.config.base, new URL(settings.config.site || "/", defaultOrigin));
|
|
15
|
+
const staticFileServer = sirv(fileURLToPath(settings.config.outDir), {
|
|
16
|
+
dev: true,
|
|
17
|
+
etag: true,
|
|
18
|
+
maxAge: 0
|
|
19
|
+
});
|
|
20
|
+
const server = http.createServer((req, res) => {
|
|
21
|
+
var _a;
|
|
22
|
+
const requestURL = new URL(req.url, defaultOrigin);
|
|
23
|
+
if (!requestURL.pathname.startsWith(baseURL.pathname)) {
|
|
24
|
+
res.statusCode = 404;
|
|
25
|
+
res.end(subpathNotUsedTemplate(baseURL.pathname, requestURL.pathname));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const pathname = requestURL.pathname.slice(baseURL.pathname.length - 1);
|
|
29
|
+
const isRoot = pathname === "/";
|
|
30
|
+
const hasTrailingSlash = isRoot || pathname.endsWith("/");
|
|
31
|
+
function sendError(message) {
|
|
32
|
+
res.statusCode = 404;
|
|
33
|
+
res.end(notFoundTemplate(pathname, message));
|
|
34
|
+
}
|
|
35
|
+
switch (true) {
|
|
36
|
+
case (hasTrailingSlash && trailingSlash == "never" && !isRoot):
|
|
37
|
+
sendError('Not Found (trailingSlash is set to "never")');
|
|
38
|
+
return;
|
|
39
|
+
case (!hasTrailingSlash && trailingSlash == "always" && !isRoot && !HAS_FILE_EXTENSION_REGEXP.test(pathname)):
|
|
40
|
+
sendError('Not Found (trailingSlash is set to "always")');
|
|
41
|
+
return;
|
|
42
|
+
default: {
|
|
43
|
+
req.url = "/" + ((_a = req.url) == null ? void 0 : _a.replace(baseURL.pathname, ""));
|
|
44
|
+
staticFileServer(req, res, () => {
|
|
45
|
+
const errorPagePath = fileURLToPath(settings.config.outDir + "/404.html");
|
|
46
|
+
if (fs.existsSync(errorPagePath)) {
|
|
47
|
+
res.statusCode = 404;
|
|
48
|
+
res.setHeader("Content-Type", "text/html;charset=utf-8");
|
|
49
|
+
res.end(fs.readFileSync(errorPagePath));
|
|
50
|
+
} else {
|
|
51
|
+
staticFileServer(req, res, () => {
|
|
52
|
+
sendError("Not Found");
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
let httpServer;
|
|
61
|
+
function startServer(timerStart) {
|
|
62
|
+
let showedPortTakenMsg = false;
|
|
63
|
+
let showedListenMsg = false;
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const listen = () => {
|
|
66
|
+
httpServer = server.listen(port, host, async () => {
|
|
67
|
+
if (!showedListenMsg) {
|
|
68
|
+
const resolvedUrls = msg.resolveServerUrls({
|
|
69
|
+
address: server.address(),
|
|
70
|
+
host: settings.config.server.host,
|
|
71
|
+
https: false
|
|
72
|
+
});
|
|
73
|
+
info(
|
|
74
|
+
logging,
|
|
75
|
+
null,
|
|
76
|
+
msg.serverStart({
|
|
77
|
+
startupTime: performance.now() - timerStart,
|
|
78
|
+
resolvedUrls,
|
|
79
|
+
host: settings.config.server.host,
|
|
80
|
+
site: baseURL
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
showedListenMsg = true;
|
|
85
|
+
resolve();
|
|
86
|
+
});
|
|
87
|
+
httpServer == null ? void 0 : httpServer.on("error", onError);
|
|
88
|
+
};
|
|
89
|
+
const onError = (err) => {
|
|
90
|
+
if (err.code && err.code === "EADDRINUSE") {
|
|
91
|
+
if (!showedPortTakenMsg) {
|
|
92
|
+
info(logging, "astro", msg.portInUse({ port }));
|
|
93
|
+
showedPortTakenMsg = true;
|
|
94
|
+
}
|
|
95
|
+
port++;
|
|
96
|
+
return listen();
|
|
97
|
+
} else {
|
|
98
|
+
error(logging, "astro", err.stack || err.message);
|
|
99
|
+
httpServer == null ? void 0 : httpServer.removeListener("error", onError);
|
|
100
|
+
reject(err);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
listen();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
await startServer(startServerTime);
|
|
107
|
+
function closed() {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
httpServer.addListener("close", resolve);
|
|
110
|
+
httpServer.addListener("error", reject);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
host,
|
|
115
|
+
port,
|
|
116
|
+
closed,
|
|
117
|
+
server: httpServer,
|
|
118
|
+
stop: async () => {
|
|
119
|
+
await new Promise((resolve, reject) => {
|
|
120
|
+
httpServer.close((err) => err ? reject(err) : resolve(void 0));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export {
|
|
126
|
+
createStaticPreviewServer as default
|
|
127
|
+
};
|
|
@@ -15,7 +15,7 @@ export declare const enum GetParamsAndPropsError {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function getParamsAndProps(opts: GetParamsAndPropsOptions): Promise<[Params, Props] | GetParamsAndPropsError>;
|
|
17
17
|
export interface RenderOptions {
|
|
18
|
-
adapterName
|
|
18
|
+
adapterName?: string;
|
|
19
19
|
logging: LogOptions;
|
|
20
20
|
links: Set<SSRElement>;
|
|
21
21
|
styles?: Set<SSRElement>;
|
|
@@ -166,9 +166,9 @@ function createResult(args) {
|
|
|
166
166
|
props,
|
|
167
167
|
request,
|
|
168
168
|
url,
|
|
169
|
-
redirect: args.ssr ? (path) => {
|
|
169
|
+
redirect: args.ssr ? (path, status) => {
|
|
170
170
|
return new Response(null, {
|
|
171
|
-
status: 302,
|
|
171
|
+
status: status || 302,
|
|
172
172
|
headers: {
|
|
173
173
|
Location: path
|
|
174
174
|
}
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { ErrorPayload, ViteDevServer } from 'vite';
|
|
3
2
|
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
|
|
4
|
-
export declare const ASTRO_VERSION: string;
|
|
5
3
|
/** Returns true if argument is an object of any prototype/class (but not null). */
|
|
6
4
|
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
5
|
+
/** Cross-realm compatible URL */
|
|
6
|
+
export declare function isURL(value: unknown): value is URL;
|
|
7
7
|
/** Wraps an object in an array. If an array is passed, ignore it. */
|
|
8
8
|
export declare function arraify<T>(target: T | T[]): T[];
|
|
9
9
|
export declare function padMultilineString(source: string, n?: number): string;
|
|
@@ -45,15 +45,4 @@ export declare function getLocalAddress(serverAddress: string, host: string | bo
|
|
|
45
45
|
*/
|
|
46
46
|
export declare function resolveIdToUrl(viteServer: ViteDevServer, id: string): Promise<string>;
|
|
47
47
|
export declare function resolveJsToTs(filePath: string): string;
|
|
48
|
-
export declare const AggregateError:
|
|
49
|
-
new (errors: Iterable<any>, message?: string | undefined): {
|
|
50
|
-
errors: Array<any>;
|
|
51
|
-
name: string;
|
|
52
|
-
message: string;
|
|
53
|
-
stack?: string | undefined;
|
|
54
|
-
cause?: unknown;
|
|
55
|
-
};
|
|
56
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
57
|
-
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
58
|
-
stackTraceLimit: number;
|
|
59
|
-
};
|
|
48
|
+
export declare const AggregateError: any;
|
package/dist/core/util.js
CHANGED
|
@@ -5,10 +5,12 @@ import resolve from "resolve";
|
|
|
5
5
|
import slash from "slash";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
7
|
import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
|
|
8
|
-
const ASTRO_VERSION = "1.4.7";
|
|
9
8
|
function isObject(value) {
|
|
10
9
|
return typeof value === "object" && value != null;
|
|
11
10
|
}
|
|
11
|
+
function isURL(value) {
|
|
12
|
+
return Object.prototype.toString.call(value) === "[object URL]";
|
|
13
|
+
}
|
|
12
14
|
function arraify(target) {
|
|
13
15
|
return Array.isArray(target) ? target : [target];
|
|
14
16
|
}
|
|
@@ -175,7 +177,6 @@ const AggregateError = typeof globalThis.AggregateError !== "undefined" ? global
|
|
|
175
177
|
}
|
|
176
178
|
};
|
|
177
179
|
export {
|
|
178
|
-
ASTRO_VERSION,
|
|
179
180
|
AggregateError,
|
|
180
181
|
VALID_ID_PREFIX,
|
|
181
182
|
arraify,
|
|
@@ -187,6 +188,7 @@ export {
|
|
|
187
188
|
isModeServerWithNoAdapter,
|
|
188
189
|
isObject,
|
|
189
190
|
isPage,
|
|
191
|
+
isURL,
|
|
190
192
|
padMultilineString,
|
|
191
193
|
parseNpmName,
|
|
192
194
|
relativeToSrcDir,
|
package/dist/events/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AstroTelemetry } from "@astrojs/telemetry";
|
|
2
2
|
import { createRequire } from "module";
|
|
3
|
-
import { ASTRO_VERSION } from "../core/
|
|
3
|
+
import { ASTRO_VERSION } from "../core/constants.js";
|
|
4
4
|
const require2 = createRequire(import.meta.url);
|
|
5
5
|
function getViteVersion() {
|
|
6
6
|
try {
|
|
@@ -5,10 +5,11 @@ import { AstroConfig, AstroSettings, BuildConfig, RouteData } from '../@types/as
|
|
|
5
5
|
import type { SerializedSSRManifest } from '../core/app/types';
|
|
6
6
|
import type { PageBuildData } from '../core/build/types';
|
|
7
7
|
import { LogOptions } from '../core/logger/core.js';
|
|
8
|
-
export declare function runHookConfigSetup({ settings, command, logging, }: {
|
|
8
|
+
export declare function runHookConfigSetup({ settings, command, logging, isRestart, }: {
|
|
9
9
|
settings: AstroSettings;
|
|
10
|
-
command: 'dev' | 'build';
|
|
10
|
+
command: 'dev' | 'build' | 'preview';
|
|
11
11
|
logging: LogOptions;
|
|
12
|
+
isRestart?: boolean;
|
|
12
13
|
}): Promise<AstroSettings>;
|
|
13
14
|
export declare function runHookConfigDone({ settings, logging, }: {
|
|
14
15
|
settings: AstroSettings;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bold } from "kleur/colors";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
2
3
|
import { mergeConfig } from "../core/config/config.js";
|
|
3
|
-
import { info } from "../core/logger/core.js";
|
|
4
|
+
import { info, warn } from "../core/logger/core.js";
|
|
4
5
|
async function withTakingALongTimeMsg({
|
|
5
6
|
name,
|
|
6
7
|
hookResult,
|
|
@@ -17,7 +18,8 @@ async function withTakingALongTimeMsg({
|
|
|
17
18
|
async function runHookConfigSetup({
|
|
18
19
|
settings,
|
|
19
20
|
command,
|
|
20
|
-
logging
|
|
21
|
+
logging,
|
|
22
|
+
isRestart = false
|
|
21
23
|
}) {
|
|
22
24
|
var _a;
|
|
23
25
|
if (settings.config.adapter) {
|
|
@@ -35,6 +37,7 @@ async function runHookConfigSetup({
|
|
|
35
37
|
const hooks = {
|
|
36
38
|
config: updatedConfig,
|
|
37
39
|
command,
|
|
40
|
+
isRestart,
|
|
38
41
|
addRenderer(renderer) {
|
|
39
42
|
if (!renderer.name) {
|
|
40
43
|
throw new Error(`Integration ${bold(integration.name)} has an unnamed renderer.`);
|
|
@@ -52,6 +55,9 @@ async function runHookConfigSetup({
|
|
|
52
55
|
},
|
|
53
56
|
injectRoute: (injectRoute) => {
|
|
54
57
|
updatedSettings.injectedRoutes.push(injectRoute);
|
|
58
|
+
},
|
|
59
|
+
addWatchFile: (path) => {
|
|
60
|
+
updatedSettings.watchFiles.push(path instanceof URL ? fileURLToPath(path) : path);
|
|
55
61
|
}
|
|
56
62
|
};
|
|
57
63
|
Object.defineProperty(hooks, "addPageExtension", {
|
|
@@ -147,13 +153,44 @@ async function runHookBuildStart({
|
|
|
147
153
|
logging
|
|
148
154
|
}) {
|
|
149
155
|
var _a;
|
|
156
|
+
function warnDeprecated(integration, prop) {
|
|
157
|
+
let value = Reflect.get(buildConfig, prop);
|
|
158
|
+
Object.defineProperty(buildConfig, prop, {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get() {
|
|
161
|
+
return value;
|
|
162
|
+
},
|
|
163
|
+
set(newValue) {
|
|
164
|
+
value = newValue;
|
|
165
|
+
warn(
|
|
166
|
+
logging,
|
|
167
|
+
"astro:build:start",
|
|
168
|
+
`Your adapter ${bold(integration.name)} is using a deprecated API, buildConfig. ${bold(
|
|
169
|
+
prop
|
|
170
|
+
)} config should be set via config.build.${prop} instead.`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
return () => {
|
|
175
|
+
Object.defineProperty(buildConfig, prop, {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
value
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
}
|
|
150
181
|
for (const integration of config.integrations) {
|
|
151
182
|
if ((_a = integration == null ? void 0 : integration.hooks) == null ? void 0 : _a["astro:build:start"]) {
|
|
183
|
+
const undoClientWarning = warnDeprecated(integration, "client");
|
|
184
|
+
const undoServerWarning = warnDeprecated(integration, "server");
|
|
185
|
+
const undoServerEntryWarning = warnDeprecated(integration, "serverEntry");
|
|
152
186
|
await withTakingALongTimeMsg({
|
|
153
187
|
name: integration.name,
|
|
154
188
|
hookResult: integration.hooks["astro:build:start"]({ buildConfig }),
|
|
155
189
|
logging
|
|
156
190
|
});
|
|
191
|
+
undoClientWarning();
|
|
192
|
+
undoServerEntryWarning();
|
|
193
|
+
undoServerWarning();
|
|
157
194
|
}
|
|
158
195
|
}
|
|
159
196
|
}
|
|
@@ -61,13 +61,14 @@ async function transformJSX({
|
|
|
61
61
|
mode,
|
|
62
62
|
id,
|
|
63
63
|
ssr,
|
|
64
|
-
renderer
|
|
64
|
+
renderer,
|
|
65
|
+
root
|
|
65
66
|
}) {
|
|
66
67
|
const { jsxTransformOptions } = renderer;
|
|
67
68
|
const options = await jsxTransformOptions({ mode, ssr });
|
|
68
69
|
const plugins = [...options.plugins || []];
|
|
69
70
|
if (ssr) {
|
|
70
|
-
plugins.push(tagExportsPlugin({ rendererName: renderer.name }));
|
|
71
|
+
plugins.push(await tagExportsPlugin({ rendererName: renderer.name, root }));
|
|
71
72
|
}
|
|
72
73
|
const result = await babel.transformAsync(code, {
|
|
73
74
|
presets: options.presets,
|
|
@@ -142,7 +143,8 @@ function jsx({ settings, logging }) {
|
|
|
142
143
|
id,
|
|
143
144
|
renderer: astroJSXRenderer,
|
|
144
145
|
mode,
|
|
145
|
-
ssr
|
|
146
|
+
ssr,
|
|
147
|
+
root: settings.config.root
|
|
146
148
|
});
|
|
147
149
|
}
|
|
148
150
|
if (defaultJSXRendererEntry && jsxRenderersIntegrationOnly.size === 1) {
|
|
@@ -157,7 +159,8 @@ function jsx({ settings, logging }) {
|
|
|
157
159
|
id,
|
|
158
160
|
renderer: defaultJSXRendererEntry[1],
|
|
159
161
|
mode,
|
|
160
|
-
ssr
|
|
162
|
+
ssr,
|
|
163
|
+
root: settings.config.root
|
|
161
164
|
});
|
|
162
165
|
}
|
|
163
166
|
let importSource = detectImportSourceFromComments(code);
|
|
@@ -214,7 +217,8 @@ https://docs.astro.build/en/core-concepts/framework-components/#installing-integ
|
|
|
214
217
|
id,
|
|
215
218
|
renderer: selectedJsxRenderer,
|
|
216
219
|
mode,
|
|
217
|
-
ssr
|
|
220
|
+
ssr,
|
|
221
|
+
root: settings.config.root
|
|
218
222
|
});
|
|
219
223
|
}
|
|
220
224
|
};
|
|
@@ -7,6 +7,7 @@ import type { PluginObj } from '@babel/core';
|
|
|
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
9
|
*/
|
|
10
|
-
export default function tagExportsWithRenderer({ rendererName, }: {
|
|
10
|
+
export default function tagExportsWithRenderer({ rendererName, root, }: {
|
|
11
11
|
rendererName: string;
|
|
12
|
-
|
|
12
|
+
root: URL;
|
|
13
|
+
}): Promise<PluginObj>;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { resolve as importMetaResolve } from "import-meta-resolve";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
async function tagExportsWithRenderer({
|
|
5
|
+
rendererName,
|
|
6
|
+
root
|
|
4
7
|
}) {
|
|
8
|
+
const astroServerPath = fileURLToPath(
|
|
9
|
+
await importMetaResolve("astro/server/index.js", root.toString())
|
|
10
|
+
);
|
|
5
11
|
return {
|
|
6
12
|
visitor: {
|
|
7
13
|
Program: {
|
|
@@ -16,7 +22,7 @@ function tagExportsWithRenderer({
|
|
|
16
22
|
t.identifier("__astro_tag_component__")
|
|
17
23
|
)
|
|
18
24
|
],
|
|
19
|
-
t.stringLiteral(
|
|
25
|
+
t.stringLiteral(astroServerPath)
|
|
20
26
|
)
|
|
21
27
|
);
|
|
22
28
|
},
|
|
@@ -83,7 +89,7 @@ function tagExportsWithRenderer({
|
|
|
83
89
|
addTag(property.key.name);
|
|
84
90
|
}
|
|
85
91
|
});
|
|
86
|
-
} else if (t.isExportNamedDeclaration(node)) {
|
|
92
|
+
} else if (t.isExportNamedDeclaration(node) && !node.source) {
|
|
87
93
|
node.specifiers.forEach((specifier) => {
|
|
88
94
|
if (t.isExportSpecifier(specifier) && t.isIdentifier(specifier.exported)) {
|
|
89
95
|
addTag(specifier.local.name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
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",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"vendor"
|
|
83
83
|
],
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@astrojs/compiler": "^0.
|
|
85
|
+
"@astrojs/compiler": "^0.27.1",
|
|
86
86
|
"@astrojs/language-server": "^0.26.2",
|
|
87
87
|
"@astrojs/markdown-remark": "^1.1.3",
|
|
88
88
|
"@astrojs/telemetry": "^1.0.1",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"common-ancestor-path": "^1.0.1",
|
|
104
104
|
"cookie": "^0.5.0",
|
|
105
105
|
"debug": "^4.3.4",
|
|
106
|
+
"deepmerge-ts": "^4.2.2",
|
|
106
107
|
"diff": "^5.1.0",
|
|
107
108
|
"eol": "^0.9.1",
|
|
108
109
|
"es-module-lexer": "^0.10.5",
|
|
@@ -113,6 +114,7 @@
|
|
|
113
114
|
"gray-matter": "^4.0.3",
|
|
114
115
|
"html-entities": "^2.3.3",
|
|
115
116
|
"html-escaper": "^3.0.3",
|
|
117
|
+
"import-meta-resolve": "^2.1.0",
|
|
116
118
|
"kleur": "^4.1.4",
|
|
117
119
|
"magic-string": "^0.25.9",
|
|
118
120
|
"mime": "^3.0.0",
|