astro 1.2.5 → 1.2.7
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 +14 -13
- package/dist/cli/check/index.d.ts +2 -2
- package/dist/cli/check/index.js +2 -2
- package/dist/cli/index.js +28 -9
- package/dist/core/add/index.js +1 -1
- package/dist/core/build/generate.d.ts +3 -3
- package/dist/core/build/generate.js +27 -27
- package/dist/core/build/index.d.ts +2 -2
- package/dist/core/build/index.js +23 -19
- package/dist/core/build/internal.js +5 -2
- package/dist/core/build/page-data.d.ts +2 -2
- package/dist/core/build/page-data.js +2 -2
- package/dist/core/build/static-build.js +26 -28
- package/dist/core/build/types.d.ts +2 -2
- package/dist/core/build/vite-plugin-css.d.ts +0 -2
- package/dist/core/build/vite-plugin-css.js +3 -3
- package/dist/core/build/vite-plugin-hoisted-scripts.d.ts +2 -2
- package/dist/core/build/vite-plugin-hoisted-scripts.js +3 -3
- package/dist/core/build/vite-plugin-pages.js +2 -2
- package/dist/core/build/vite-plugin-ssr.js +15 -11
- package/dist/core/config/config.d.ts +41 -0
- package/dist/core/{config.js → config/config.js} +5 -166
- package/dist/core/config/index.d.ts +4 -0
- package/dist/core/config/index.js +18 -0
- package/dist/core/config/schema.d.ts +478 -0
- package/dist/core/config/schema.js +148 -0
- package/dist/core/config/settings.d.ts +8 -0
- package/dist/core/config/settings.js +16 -0
- package/dist/core/config/tsconfig.d.ts +2 -0
- package/dist/core/config/tsconfig.js +13 -0
- package/dist/core/create-vite.d.ts +3 -3
- package/dist/core/create-vite.js +21 -21
- package/dist/core/dev/index.d.ts +2 -2
- package/dist/core/dev/index.js +16 -12
- package/dist/core/endpoint/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.d.ts +2 -2
- package/dist/core/preview/index.js +9 -9
- package/dist/core/render/dev/index.d.ts +5 -5
- package/dist/core/render/dev/index.js +14 -14
- package/dist/core/render/dev/scripts.d.ts +2 -2
- package/dist/core/render/dev/scripts.js +4 -7
- package/dist/core/routing/manifest/create.d.ts +3 -3
- package/dist/core/routing/manifest/create.js +9 -12
- package/dist/core/util.d.ts +3 -3
- package/dist/core/util.js +9 -9
- package/dist/integrations/index.d.ts +6 -6
- package/dist/integrations/index.js +19 -17
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/vite-plugin-astro/index.d.ts +3 -3
- package/dist/vite-plugin-astro/index.js +2 -1
- package/dist/vite-plugin-astro-postprocess/index.d.ts +3 -3
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/index.d.ts +4 -4
- package/dist/vite-plugin-astro-server/index.js +27 -24
- package/dist/vite-plugin-config-alias/index.d.ts +3 -3
- package/dist/vite-plugin-config-alias/index.js +6 -5
- package/dist/vite-plugin-env/index.d.ts +3 -3
- package/dist/vite-plugin-env/index.js +2 -3
- package/dist/vite-plugin-integrations-container/index.d.ts +3 -3
- package/dist/vite-plugin-integrations-container/index.js +2 -2
- package/dist/vite-plugin-jsx/index.d.ts +3 -3
- package/dist/vite-plugin-jsx/index.js +3 -3
- package/dist/vite-plugin-markdown/index.d.ts +3 -3
- package/dist/vite-plugin-markdown/index.js +3 -3
- package/dist/vite-plugin-markdown-legacy/index.d.ts +3 -3
- package/dist/vite-plugin-markdown-legacy/index.js +2 -1
- package/dist/vite-plugin-scripts/index.d.ts +3 -3
- package/dist/vite-plugin-scripts/index.js +5 -5
- package/dist/vite-plugin-scripts/page-ssr.d.ts +3 -3
- package/dist/vite-plugin-scripts/page-ssr.js +7 -5
- package/package.json +2 -2
- package/dist/core/config.d.ts +0 -260
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as tsr from "tsconfig-resolver";
|
|
2
|
+
function loadTSConfig(cwd) {
|
|
3
|
+
for (const searchName of ["tsconfig.json", "jsconfig.json"]) {
|
|
4
|
+
const config = tsr.tsconfigResolverSync({ cwd, searchName });
|
|
5
|
+
if (config.exists) {
|
|
6
|
+
return config;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
loadTSConfig
|
|
13
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AstroSettings } from '../@types/astro';
|
|
2
2
|
import type { LogOptions } from './logger/core';
|
|
3
3
|
import * as vite from 'vite';
|
|
4
4
|
export declare type ViteConfigWithSSR = vite.InlineConfig & {
|
|
5
5
|
ssr?: vite.SSROptions;
|
|
6
6
|
};
|
|
7
7
|
interface CreateViteOptions {
|
|
8
|
-
|
|
8
|
+
settings: AstroSettings;
|
|
9
9
|
logging: LogOptions;
|
|
10
10
|
mode: 'dev' | 'build' | string;
|
|
11
11
|
}
|
|
12
12
|
/** Return a common starting point for all Vite actions */
|
|
13
|
-
export declare function createVite(commandConfig: ViteConfigWithSSR, {
|
|
13
|
+
export declare function createVite(commandConfig: ViteConfigWithSSR, { settings, logging, mode }: CreateViteOptions): Promise<ViteConfigWithSSR>;
|
|
14
14
|
export {};
|
package/dist/core/create-vite.js
CHANGED
|
@@ -34,10 +34,10 @@ function getSsrNoExternalDeps(projectRoot) {
|
|
|
34
34
|
}
|
|
35
35
|
return noExternalDeps;
|
|
36
36
|
}
|
|
37
|
-
async function createVite(commandConfig, {
|
|
38
|
-
const thirdPartyAstroPackages = await getAstroPackages(
|
|
37
|
+
async function createVite(commandConfig, { settings, logging, mode }) {
|
|
38
|
+
const thirdPartyAstroPackages = await getAstroPackages(settings);
|
|
39
39
|
const commonConfig = {
|
|
40
|
-
cacheDir: fileURLToPath(new URL("./node_modules/.vite/",
|
|
40
|
+
cacheDir: fileURLToPath(new URL("./node_modules/.vite/", settings.config.root)),
|
|
41
41
|
clearScreen: false,
|
|
42
42
|
logLevel: "warn",
|
|
43
43
|
appType: "custom",
|
|
@@ -46,23 +46,23 @@ async function createVite(commandConfig, { astroConfig, logging, mode }) {
|
|
|
46
46
|
exclude: ["node-fetch"]
|
|
47
47
|
},
|
|
48
48
|
plugins: [
|
|
49
|
-
configAliasVitePlugin({
|
|
50
|
-
astroVitePlugin({
|
|
51
|
-
astroScriptsPlugin({
|
|
52
|
-
mode !== "build" && astroViteServerPlugin({
|
|
53
|
-
envVitePlugin({
|
|
54
|
-
|
|
49
|
+
configAliasVitePlugin({ settings }),
|
|
50
|
+
astroVitePlugin({ settings, logging }),
|
|
51
|
+
astroScriptsPlugin({ settings }),
|
|
52
|
+
mode !== "build" && astroViteServerPlugin({ settings, logging }),
|
|
53
|
+
envVitePlugin({ settings }),
|
|
54
|
+
settings.config.legacy.astroFlavoredMarkdown ? legacyMarkdownVitePlugin({ settings, logging }) : markdownVitePlugin({ settings, logging }),
|
|
55
55
|
htmlVitePlugin(),
|
|
56
|
-
jsxVitePlugin({
|
|
57
|
-
astroPostprocessVitePlugin({
|
|
58
|
-
astroIntegrationsContainerPlugin({
|
|
59
|
-
astroScriptsPageSSRPlugin({
|
|
56
|
+
jsxVitePlugin({ settings, logging }),
|
|
57
|
+
astroPostprocessVitePlugin({ settings }),
|
|
58
|
+
astroIntegrationsContainerPlugin({ settings, logging }),
|
|
59
|
+
astroScriptsPageSSRPlugin({ settings })
|
|
60
60
|
],
|
|
61
|
-
publicDir: fileURLToPath(
|
|
62
|
-
root: fileURLToPath(
|
|
61
|
+
publicDir: fileURLToPath(settings.config.publicDir),
|
|
62
|
+
root: fileURLToPath(settings.config.root),
|
|
63
63
|
envPrefix: "PUBLIC_",
|
|
64
64
|
define: {
|
|
65
|
-
"import.meta.env.SITE":
|
|
65
|
+
"import.meta.env.SITE": settings.config.site ? `'${settings.config.site}'` : "undefined"
|
|
66
66
|
},
|
|
67
67
|
server: {
|
|
68
68
|
hmr: process.env.NODE_ENV === "test" || process.env.NODE_ENV === "production" ? false : void 0,
|
|
@@ -72,7 +72,7 @@ async function createVite(commandConfig, { astroConfig, logging, mode }) {
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
css: {
|
|
75
|
-
postcss:
|
|
75
|
+
postcss: settings.config.style.postcss || {}
|
|
76
76
|
},
|
|
77
77
|
resolve: {
|
|
78
78
|
alias: [
|
|
@@ -88,11 +88,11 @@ async function createVite(commandConfig, { astroConfig, logging, mode }) {
|
|
|
88
88
|
conditions: ["astro"]
|
|
89
89
|
},
|
|
90
90
|
ssr: {
|
|
91
|
-
noExternal: [...getSsrNoExternalDeps(
|
|
91
|
+
noExternal: [...getSsrNoExternalDeps(settings.config.root), ...thirdPartyAstroPackages]
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
let result = commonConfig;
|
|
95
|
-
result = vite.mergeConfig(result,
|
|
95
|
+
result = vite.mergeConfig(result, settings.config.vite || {});
|
|
96
96
|
result = vite.mergeConfig(result, commandConfig);
|
|
97
97
|
if (result.plugins) {
|
|
98
98
|
sortPlugins(result.plugins);
|
|
@@ -117,8 +117,8 @@ function sortPlugins(pluginOptions) {
|
|
|
117
117
|
pluginOptions.splice(mdxPluginIndex, 1);
|
|
118
118
|
pluginOptions.splice(jsxPluginIndex, 0, mdxPlugin);
|
|
119
119
|
}
|
|
120
|
-
async function getAstroPackages(
|
|
121
|
-
const { astroPackages } = new DependencyWalker(root);
|
|
120
|
+
async function getAstroPackages(settings) {
|
|
121
|
+
const { astroPackages } = new DependencyWalker(settings.config.root);
|
|
122
122
|
return astroPackages;
|
|
123
123
|
}
|
|
124
124
|
class DependencyWalker {
|
package/dist/core/dev/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { AstroTelemetry } from '@astrojs/telemetry';
|
|
3
3
|
import type { AddressInfo } from 'net';
|
|
4
4
|
import * as vite from 'vite';
|
|
5
|
-
import type {
|
|
5
|
+
import type { AstroSettings } from '../../@types/astro';
|
|
6
6
|
import { LogOptions } from '../logger/core.js';
|
|
7
7
|
export interface DevOptions {
|
|
8
8
|
logging: LogOptions;
|
|
@@ -15,4 +15,4 @@ export interface DevServer {
|
|
|
15
15
|
stop(): Promise<void>;
|
|
16
16
|
}
|
|
17
17
|
/** `astro dev` */
|
|
18
|
-
export default function dev(
|
|
18
|
+
export default function dev(settings: AstroSettings, options: DevOptions): Promise<DevServer>;
|
package/dist/core/dev/index.js
CHANGED
|
@@ -11,15 +11,15 @@ import { createVite } from "../create-vite.js";
|
|
|
11
11
|
import { info, warn } from "../logger/core.js";
|
|
12
12
|
import * as msg from "../messages.js";
|
|
13
13
|
import { apply as applyPolyfill } from "../polyfill.js";
|
|
14
|
-
async function dev(
|
|
14
|
+
async function dev(settings, options) {
|
|
15
15
|
var _a, _b, _c;
|
|
16
16
|
const devStart = performance.now();
|
|
17
17
|
applyPolyfill();
|
|
18
18
|
await options.telemetry.record([]);
|
|
19
|
-
|
|
20
|
-
const { host, port } = config.server;
|
|
19
|
+
settings = await runHookConfigSetup({ settings, command: "dev", logging: options.logging });
|
|
20
|
+
const { host, port } = settings.config.server;
|
|
21
21
|
const { isRestart = false } = options;
|
|
22
|
-
const rendererClientEntries =
|
|
22
|
+
const rendererClientEntries = settings.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
|
|
23
23
|
const viteConfig = await createVite(
|
|
24
24
|
{
|
|
25
25
|
mode: "development",
|
|
@@ -28,34 +28,38 @@ async function dev(config, options) {
|
|
|
28
28
|
include: rendererClientEntries
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
-
{
|
|
31
|
+
{ settings, logging: options.logging, mode: "dev" }
|
|
32
32
|
);
|
|
33
|
-
await runHookConfigDone({
|
|
33
|
+
await runHookConfigDone({ settings, logging: options.logging });
|
|
34
34
|
const viteServer = await vite.createServer(viteConfig);
|
|
35
|
-
runHookServerSetup({ config, server: viteServer, logging: options.logging });
|
|
35
|
+
runHookServerSetup({ config: settings.config, server: viteServer, logging: options.logging });
|
|
36
36
|
await viteServer.listen(port);
|
|
37
37
|
const devServerAddressInfo = viteServer.httpServer.address();
|
|
38
|
-
const site = config.site ? new URL(config.base, config.site) : void 0;
|
|
38
|
+
const site = settings.config.site ? new URL(settings.config.base, settings.config.site) : void 0;
|
|
39
39
|
info(
|
|
40
40
|
options.logging,
|
|
41
41
|
null,
|
|
42
42
|
msg.devStart({
|
|
43
43
|
startupTime: performance.now() - devStart,
|
|
44
|
-
config,
|
|
44
|
+
config: settings.config,
|
|
45
45
|
devServerAddressInfo,
|
|
46
46
|
site,
|
|
47
47
|
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https),
|
|
48
48
|
isRestart
|
|
49
49
|
})
|
|
50
50
|
);
|
|
51
|
-
const currentVersion = "1.2.
|
|
51
|
+
const currentVersion = "1.2.7";
|
|
52
52
|
if (currentVersion.includes("-")) {
|
|
53
53
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
54
54
|
}
|
|
55
55
|
if (((_c = (_b = viteConfig.server) == null ? void 0 : _b.fs) == null ? void 0 : _c.strict) === false) {
|
|
56
56
|
warn(options.logging, null, msg.fsStrictWarning());
|
|
57
57
|
}
|
|
58
|
-
await runHookServerStart({
|
|
58
|
+
await runHookServerStart({
|
|
59
|
+
config: settings.config,
|
|
60
|
+
address: devServerAddressInfo,
|
|
61
|
+
logging: options.logging
|
|
62
|
+
});
|
|
59
63
|
return {
|
|
60
64
|
address: devServerAddressInfo,
|
|
61
65
|
get watcher() {
|
|
@@ -63,7 +67,7 @@ async function dev(config, options) {
|
|
|
63
67
|
},
|
|
64
68
|
stop: async () => {
|
|
65
69
|
await viteServer.close();
|
|
66
|
-
await runHookServerDone({ config, logging: options.logging });
|
|
70
|
+
await runHookServerDone({ config: settings.config, logging: options.logging });
|
|
67
71
|
}
|
|
68
72
|
};
|
|
69
73
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function devStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.2.
|
|
50
|
+
const version = "1.2.7";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -226,7 +226,7 @@ function printHelp({
|
|
|
226
226
|
message.push(
|
|
227
227
|
linebreak(),
|
|
228
228
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
229
|
-
`v${"1.2.
|
|
229
|
+
`v${"1.2.7"}`
|
|
230
230
|
)} ${headline}`
|
|
231
231
|
);
|
|
232
232
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { AstroTelemetry } from '@astrojs/telemetry';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AstroSettings } from '../../@types/astro';
|
|
4
4
|
import type { LogOptions } from '../logger/core';
|
|
5
5
|
import http from 'http';
|
|
6
6
|
interface PreviewOptions {
|
|
@@ -15,5 +15,5 @@ export interface PreviewServer {
|
|
|
15
15
|
stop(): Promise<void>;
|
|
16
16
|
}
|
|
17
17
|
/** The primary dev action */
|
|
18
|
-
export default function preview(
|
|
18
|
+
export default function preview(settings: AstroSettings, { logging }: PreviewOptions): Promise<PreviewServer>;
|
|
19
19
|
export {};
|
|
@@ -8,17 +8,17 @@ import { error, info } from "../logger/core.js";
|
|
|
8
8
|
import * as msg from "../messages.js";
|
|
9
9
|
import { getResolvedHostForHttpServer } from "./util.js";
|
|
10
10
|
const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
|
|
11
|
-
async function preview(
|
|
12
|
-
if (config.output === "server") {
|
|
11
|
+
async function preview(settings, { logging }) {
|
|
12
|
+
if (settings.config.output === "server") {
|
|
13
13
|
throw new Error(
|
|
14
14
|
`[preview] 'output: server' not supported. Use your deploy platform's preview command directly instead, if one exists. (ex: 'netlify dev', 'vercel dev', 'wrangler', etc.)`
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
const startServerTime = performance.now();
|
|
18
18
|
const defaultOrigin = "http://localhost";
|
|
19
|
-
const trailingSlash = config.trailingSlash;
|
|
20
|
-
let baseURL = new URL(config.base, new URL(config.site || "/", defaultOrigin));
|
|
21
|
-
const staticFileServer = sirv(fileURLToPath(config.outDir), {
|
|
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
22
|
dev: true,
|
|
23
23
|
etag: true,
|
|
24
24
|
maxAge: 0
|
|
@@ -48,7 +48,7 @@ async function preview(config, { logging }) {
|
|
|
48
48
|
default: {
|
|
49
49
|
req.url = "/" + ((_a = req.url) == null ? void 0 : _a.replace(baseURL.pathname, ""));
|
|
50
50
|
staticFileServer(req, res, () => {
|
|
51
|
-
const errorPagePath = fileURLToPath(config.outDir + "/404.html");
|
|
51
|
+
const errorPagePath = fileURLToPath(settings.config.outDir + "/404.html");
|
|
52
52
|
if (fs.existsSync(errorPagePath)) {
|
|
53
53
|
res.statusCode = 404;
|
|
54
54
|
res.setHeader("Content-Type", "text/html;charset=utf-8");
|
|
@@ -63,8 +63,8 @@ async function preview(config, { logging }) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
|
-
let { port } = config.server;
|
|
67
|
-
const host = getResolvedHostForHttpServer(config.server.host);
|
|
66
|
+
let { port } = settings.config.server;
|
|
67
|
+
const host = getResolvedHostForHttpServer(settings.config.server.host);
|
|
68
68
|
let httpServer;
|
|
69
69
|
function startServer(timerStart) {
|
|
70
70
|
let showedPortTakenMsg = false;
|
|
@@ -79,7 +79,7 @@ async function preview(config, { logging }) {
|
|
|
79
79
|
null,
|
|
80
80
|
msg.devStart({
|
|
81
81
|
startupTime: performance.now() - timerStart,
|
|
82
|
-
config,
|
|
82
|
+
config: settings.config,
|
|
83
83
|
devServerAddressInfo,
|
|
84
84
|
https: false,
|
|
85
85
|
site: baseURL
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ViteDevServer } from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings, ComponentInstance, RouteData, RuntimeMode, SSRLoadedRenderer } from '../../../@types/astro';
|
|
3
3
|
import { LogOptions } from '../../logger/core.js';
|
|
4
4
|
import { RouteCache } from '../route-cache.js';
|
|
5
5
|
export interface SSROptions {
|
|
6
|
-
/** an instance of the
|
|
7
|
-
|
|
6
|
+
/** an instance of the AstroSettings */
|
|
7
|
+
settings: AstroSettings;
|
|
8
8
|
/** location of file on disk */
|
|
9
9
|
filePath: URL;
|
|
10
10
|
/** logging options */
|
|
@@ -25,8 +25,8 @@ export interface SSROptions {
|
|
|
25
25
|
request: Request;
|
|
26
26
|
}
|
|
27
27
|
export declare type ComponentPreload = [SSRLoadedRenderer[], ComponentInstance];
|
|
28
|
-
export declare function loadRenderers(viteServer: ViteDevServer,
|
|
29
|
-
export declare function preload({
|
|
28
|
+
export declare function loadRenderers(viteServer: ViteDevServer, settings: AstroSettings): Promise<SSRLoadedRenderer[]>;
|
|
29
|
+
export declare function preload({ settings, filePath, viteServer, }: Pick<SSROptions, 'settings' | 'filePath' | 'viteServer'>): Promise<ComponentPreload>;
|
|
30
30
|
/** use Vite to SSR */
|
|
31
31
|
export declare function render(renderers: SSRLoadedRenderer[], mod: ComponentInstance, ssrOpts: SSROptions): Promise<Response>;
|
|
32
32
|
export declare function ssr(preloadedComponent: ComponentPreload, ssrOpts: SSROptions): Promise<Response>;
|
|
@@ -11,15 +11,15 @@ async function loadRenderer(viteServer, renderer) {
|
|
|
11
11
|
const mod = await viteServer.ssrLoadModule(renderer.serverEntrypoint);
|
|
12
12
|
return { ...renderer, ssr: mod.default };
|
|
13
13
|
}
|
|
14
|
-
async function loadRenderers(viteServer,
|
|
15
|
-
return Promise.all(
|
|
14
|
+
async function loadRenderers(viteServer, settings) {
|
|
15
|
+
return Promise.all(settings.renderers.map((r) => loadRenderer(viteServer, r)));
|
|
16
16
|
}
|
|
17
17
|
async function preload({
|
|
18
|
-
|
|
18
|
+
settings,
|
|
19
19
|
filePath,
|
|
20
20
|
viteServer
|
|
21
21
|
}) {
|
|
22
|
-
const renderers = await loadRenderers(viteServer,
|
|
22
|
+
const renderers = await loadRenderers(viteServer, settings);
|
|
23
23
|
const mod = await viteServer.ssrLoadModule(fileURLToPath(filePath));
|
|
24
24
|
if (viteServer.config.mode === "development" || !(mod == null ? void 0 : mod.$$metadata)) {
|
|
25
25
|
return [renderers, mod];
|
|
@@ -33,7 +33,7 @@ async function preload({
|
|
|
33
33
|
async function render(renderers, mod, ssrOpts) {
|
|
34
34
|
var _a;
|
|
35
35
|
const {
|
|
36
|
-
|
|
36
|
+
settings,
|
|
37
37
|
filePath,
|
|
38
38
|
logging,
|
|
39
39
|
mode,
|
|
@@ -44,8 +44,8 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
44
44
|
routeCache,
|
|
45
45
|
viteServer
|
|
46
46
|
} = ssrOpts;
|
|
47
|
-
const scripts = await getScriptsForURL(filePath,
|
|
48
|
-
if (isPage(filePath,
|
|
47
|
+
const scripts = await getScriptsForURL(filePath, viteServer);
|
|
48
|
+
if (isPage(filePath, settings) && mode === "development") {
|
|
49
49
|
scripts.add({
|
|
50
50
|
props: { type: "module", src: "/@vite/client" },
|
|
51
51
|
children: ""
|
|
@@ -58,13 +58,13 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
58
58
|
children: ""
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
for (const script of
|
|
61
|
+
for (const script of settings.scripts) {
|
|
62
62
|
if (script.stage === "head-inline") {
|
|
63
63
|
scripts.add({
|
|
64
64
|
props: {},
|
|
65
65
|
children: script.content
|
|
66
66
|
});
|
|
67
|
-
} else if (script.stage === "page" && isPage(filePath,
|
|
67
|
+
} else if (script.stage === "page" && isPage(filePath, settings)) {
|
|
68
68
|
scripts.add({
|
|
69
69
|
props: { type: "module", src: `/@id/${PAGE_SCRIPT_ID}` },
|
|
70
70
|
children: ""
|
|
@@ -97,13 +97,13 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
97
97
|
});
|
|
98
98
|
});
|
|
99
99
|
let response = await coreRender({
|
|
100
|
-
adapterName: (_a =
|
|
100
|
+
adapterName: (_a = settings.config.adapter) == null ? void 0 : _a.name,
|
|
101
101
|
links,
|
|
102
102
|
styles,
|
|
103
103
|
logging,
|
|
104
104
|
markdown: {
|
|
105
|
-
...
|
|
106
|
-
isAstroFlavoredMd:
|
|
105
|
+
...settings.config.markdown,
|
|
106
|
+
isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
|
|
107
107
|
},
|
|
108
108
|
mod,
|
|
109
109
|
mode,
|
|
@@ -120,8 +120,8 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
120
120
|
request,
|
|
121
121
|
route,
|
|
122
122
|
routeCache,
|
|
123
|
-
site:
|
|
124
|
-
ssr:
|
|
123
|
+
site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : void 0,
|
|
124
|
+
ssr: settings.config.output === "server",
|
|
125
125
|
streaming: true
|
|
126
126
|
});
|
|
127
127
|
return response;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import vite from 'vite';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function getScriptsForURL(filePath: URL,
|
|
2
|
+
import type { SSRElement } from '../../../@types/astro';
|
|
3
|
+
export declare function getScriptsForURL(filePath: URL, viteServer: vite.ViteDevServer): Promise<Set<SSRElement>>;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import slash from "slash";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
3
1
|
import { viteID } from "../../util.js";
|
|
4
2
|
import { createModuleScriptElementWithSrc } from "../ssr-element.js";
|
|
5
3
|
import { crawlGraph } from "./vite.js";
|
|
6
|
-
async function getScriptsForURL(filePath,
|
|
4
|
+
async function getScriptsForURL(filePath, viteServer) {
|
|
7
5
|
const elements = /* @__PURE__ */ new Set();
|
|
8
6
|
const rootID = viteID(filePath);
|
|
9
|
-
let rootProjectFolder = slash(fileURLToPath(astroConfig.root));
|
|
10
7
|
const modInfo = viteServer.pluginContainer.getModuleInfo(rootID);
|
|
11
|
-
addHoistedScripts(elements, modInfo
|
|
8
|
+
addHoistedScripts(elements, modInfo);
|
|
12
9
|
for await (const moduleNode of crawlGraph(viteServer, rootID, true)) {
|
|
13
10
|
const id = moduleNode.id;
|
|
14
11
|
if (id) {
|
|
15
12
|
const info = viteServer.pluginContainer.getModuleInfo(id);
|
|
16
|
-
addHoistedScripts(elements, info
|
|
13
|
+
addHoistedScripts(elements, info);
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
16
|
return elements;
|
|
20
17
|
}
|
|
21
|
-
function addHoistedScripts(set, info
|
|
18
|
+
function addHoistedScripts(set, info) {
|
|
22
19
|
var _a, _b;
|
|
23
20
|
if (!((_a = info == null ? void 0 : info.meta) == null ? void 0 : _a.astro)) {
|
|
24
21
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AstroSettings, ManifestData } from '../../../@types/astro';
|
|
2
2
|
import type { LogOptions } from '../../logger/core';
|
|
3
3
|
/** Create manifest of all static routes */
|
|
4
|
-
export declare function createRouteManifest({
|
|
5
|
-
|
|
4
|
+
export declare function createRouteManifest({ settings, cwd }: {
|
|
5
|
+
settings: AstroSettings;
|
|
6
6
|
cwd?: string;
|
|
7
7
|
}, logging: LogOptions): ManifestData;
|
|
@@ -122,21 +122,17 @@ function injectedRouteToItem({ config, cwd }, { pattern, entryPoint }) {
|
|
|
122
122
|
routeSuffix: pattern.slice(pattern.indexOf("."), -ext.length)
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
function createRouteManifest({
|
|
126
|
-
var _a
|
|
125
|
+
function createRouteManifest({ settings, cwd }, logging) {
|
|
126
|
+
var _a;
|
|
127
127
|
const components = [];
|
|
128
128
|
const routes = [];
|
|
129
|
-
const validPageExtensions = /* @__PURE__ */ new Set([
|
|
130
|
-
".astro",
|
|
131
|
-
".md",
|
|
132
|
-
...config._ctx.pageExtensions
|
|
133
|
-
]);
|
|
129
|
+
const validPageExtensions = /* @__PURE__ */ new Set([".astro", ".md", ...settings.pageExtensions]);
|
|
134
130
|
const validEndpointExtensions = /* @__PURE__ */ new Set([".js", ".ts"]);
|
|
135
131
|
function walk(dir, parentSegments, parentParams) {
|
|
136
132
|
let items = [];
|
|
137
133
|
fs.readdirSync(dir).forEach((basename) => {
|
|
138
134
|
const resolved = path.join(dir, basename);
|
|
139
|
-
const file = slash(path.relative(cwd || fileURLToPath(config.root), resolved));
|
|
135
|
+
const file = slash(path.relative(cwd || fileURLToPath(settings.config.root), resolved));
|
|
140
136
|
const isDir = fs.statSync(resolved).isDirectory();
|
|
141
137
|
const ext = path.extname(basename);
|
|
142
138
|
const name = ext ? basename.slice(0, -ext.length) : basename;
|
|
@@ -202,7 +198,7 @@ function createRouteManifest({ config, cwd }, logging) {
|
|
|
202
198
|
} else {
|
|
203
199
|
components.push(item.file);
|
|
204
200
|
const component = item.file;
|
|
205
|
-
const trailingSlash = item.isPage ? config.trailingSlash : "never";
|
|
201
|
+
const trailingSlash = item.isPage ? settings.config.trailingSlash : "never";
|
|
206
202
|
const pattern = getPattern(segments, trailingSlash);
|
|
207
203
|
const generate = getRouteGenerator(segments, trailingSlash);
|
|
208
204
|
const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
|
|
@@ -220,14 +216,15 @@ function createRouteManifest({ config, cwd }, logging) {
|
|
|
220
216
|
}
|
|
221
217
|
});
|
|
222
218
|
}
|
|
219
|
+
const { config } = settings;
|
|
223
220
|
const pages = resolvePages(config);
|
|
224
221
|
if (fs.existsSync(pages)) {
|
|
225
222
|
walk(fileURLToPath(pages), [], []);
|
|
226
|
-
} else if (
|
|
227
|
-
const pagesDirRootRelative = pages.href.slice(config.root.href.length);
|
|
223
|
+
} else if (settings.injectedRoutes.length === 0) {
|
|
224
|
+
const pagesDirRootRelative = pages.href.slice(settings.config.root.href.length);
|
|
228
225
|
warn(logging, "astro", `Missing pages directory: ${pagesDirRootRelative}`);
|
|
229
226
|
}
|
|
230
|
-
(
|
|
227
|
+
(_a = settings.injectedRoutes) == null ? void 0 : _a.sort(
|
|
231
228
|
(a, b) => comparator(injectedRouteToItem({ config, cwd }, a), injectedRouteToItem({ config, cwd }, b))
|
|
232
229
|
).reverse().forEach(({ pattern: name, entryPoint }) => {
|
|
233
230
|
const resolved = require2.resolve(entryPoint, { paths: [cwd || fileURLToPath(config.root)] });
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { ErrorPayload, ViteDevServer } from 'vite';
|
|
3
|
-
import type { AstroConfig, RouteType } from '../@types/astro';
|
|
3
|
+
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
|
|
4
4
|
export declare const ASTRO_VERSION: string;
|
|
5
5
|
/** Returns true if argument is an object of any prototype/class (but not null). */
|
|
6
6
|
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
@@ -37,8 +37,8 @@ export declare function unwrapId(id: string): string;
|
|
|
37
37
|
export declare function removeDir(_dir: URL): void;
|
|
38
38
|
export declare function emptyDir(_dir: URL, skip?: Set<string>): void;
|
|
39
39
|
export declare function resolvePages(config: AstroConfig): URL;
|
|
40
|
-
export declare function isPage(file: URL,
|
|
41
|
-
export declare function isModeServerWithNoAdapter(
|
|
40
|
+
export declare function isPage(file: URL, settings: AstroSettings): boolean;
|
|
41
|
+
export declare function isModeServerWithNoAdapter(settings: AstroSettings): boolean;
|
|
42
42
|
export declare function relativeToSrcDir(config: AstroConfig, idOrUrl: URL | string): string;
|
|
43
43
|
export declare function emoji(char: string, fallback: string): string;
|
|
44
44
|
export declare function getLocalAddress(serverAddress: string, host: string | boolean): string;
|
package/dist/core/util.js
CHANGED
|
@@ -5,7 +5,7 @@ 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.2.
|
|
8
|
+
const ASTRO_VERSION = "1.2.7";
|
|
9
9
|
function isObject(value) {
|
|
10
10
|
return typeof value === "object" && value != null;
|
|
11
11
|
}
|
|
@@ -124,22 +124,22 @@ function isPublicRoute(file, config) {
|
|
|
124
124
|
}
|
|
125
125
|
return true;
|
|
126
126
|
}
|
|
127
|
-
function endsWithPageExt(file,
|
|
128
|
-
for (const ext of
|
|
127
|
+
function endsWithPageExt(file, settings) {
|
|
128
|
+
for (const ext of settings.pageExtensions) {
|
|
129
129
|
if (file.toString().endsWith(ext))
|
|
130
130
|
return true;
|
|
131
131
|
}
|
|
132
132
|
return false;
|
|
133
133
|
}
|
|
134
|
-
function isPage(file,
|
|
135
|
-
if (!isInPagesDir(file, config))
|
|
134
|
+
function isPage(file, settings) {
|
|
135
|
+
if (!isInPagesDir(file, settings.config))
|
|
136
136
|
return false;
|
|
137
|
-
if (!isPublicRoute(file, config))
|
|
137
|
+
if (!isPublicRoute(file, settings.config))
|
|
138
138
|
return false;
|
|
139
|
-
return endsWithPageExt(file,
|
|
139
|
+
return endsWithPageExt(file, settings);
|
|
140
140
|
}
|
|
141
|
-
function isModeServerWithNoAdapter(
|
|
142
|
-
return config.output === "server" && !
|
|
141
|
+
function isModeServerWithNoAdapter(settings) {
|
|
142
|
+
return settings.config.output === "server" && !settings.adapter;
|
|
143
143
|
}
|
|
144
144
|
function relativeToSrcDir(config, idOrUrl) {
|
|
145
145
|
let id;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { AddressInfo } from 'net';
|
|
3
3
|
import type { ViteDevServer } from 'vite';
|
|
4
|
-
import { AstroConfig, BuildConfig, RouteData } from '../@types/astro.js';
|
|
4
|
+
import { AstroConfig, AstroSettings, BuildConfig, RouteData } from '../@types/astro.js';
|
|
5
5
|
import type { SerializedSSRManifest } from '../core/app/types';
|
|
6
6
|
import type { PageBuildData } from '../core/build/types';
|
|
7
7
|
import type { ViteConfigWithSSR } from '../core/create-vite.js';
|
|
8
8
|
import { LogOptions } from '../core/logger/core.js';
|
|
9
|
-
export declare function runHookConfigSetup({
|
|
10
|
-
|
|
9
|
+
export declare function runHookConfigSetup({ settings, command, logging, }: {
|
|
10
|
+
settings: AstroSettings;
|
|
11
11
|
command: 'dev' | 'build';
|
|
12
12
|
logging: LogOptions;
|
|
13
|
-
}): Promise<
|
|
14
|
-
export declare function runHookConfigDone({
|
|
15
|
-
|
|
13
|
+
}): Promise<AstroSettings>;
|
|
14
|
+
export declare function runHookConfigDone({ settings, logging, }: {
|
|
15
|
+
settings: AstroSettings;
|
|
16
16
|
logging: LogOptions;
|
|
17
17
|
}): Promise<void>;
|
|
18
18
|
export declare function runHookServerSetup({ config, server, logging, }: {
|