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/core/dev/index.js
CHANGED
|
@@ -1,83 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
runHookConfigDone,
|
|
5
|
-
runHookConfigSetup,
|
|
6
|
-
runHookServerDone,
|
|
7
|
-
runHookServerSetup,
|
|
8
|
-
runHookServerStart
|
|
9
|
-
} from "../../integrations/index.js";
|
|
10
|
-
import { createVite } from "../create-vite.js";
|
|
11
|
-
import { info, warn } from "../logger/core.js";
|
|
12
|
-
import * as msg from "../messages.js";
|
|
13
|
-
import { apply as applyPolyfill } from "../polyfill.js";
|
|
14
|
-
async function dev(settings, options) {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
const devStart = performance.now();
|
|
17
|
-
applyPolyfill();
|
|
18
|
-
await options.telemetry.record([]);
|
|
19
|
-
settings = await runHookConfigSetup({
|
|
20
|
-
settings,
|
|
21
|
-
command: "dev",
|
|
22
|
-
logging: options.logging,
|
|
23
|
-
isRestart: options.isRestart
|
|
24
|
-
});
|
|
25
|
-
const { host, port } = settings.config.server;
|
|
26
|
-
const { isRestart = false } = options;
|
|
27
|
-
const rendererClientEntries = settings.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
|
|
28
|
-
const viteConfig = await createVite(
|
|
29
|
-
{
|
|
30
|
-
mode: "development",
|
|
31
|
-
server: { host },
|
|
32
|
-
optimizeDeps: {
|
|
33
|
-
include: rendererClientEntries
|
|
34
|
-
},
|
|
35
|
-
define: {
|
|
36
|
-
"import.meta.env.BASE_URL": settings.config.base ? `'${settings.config.base}'` : "undefined"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
{ settings, logging: options.logging, mode: "dev" }
|
|
40
|
-
);
|
|
41
|
-
await runHookConfigDone({ settings, logging: options.logging });
|
|
42
|
-
const viteServer = await vite.createServer(viteConfig);
|
|
43
|
-
runHookServerSetup({ config: settings.config, server: viteServer, logging: options.logging });
|
|
44
|
-
await viteServer.listen(port);
|
|
45
|
-
const site = settings.config.site ? new URL(settings.config.base, settings.config.site) : void 0;
|
|
46
|
-
info(
|
|
47
|
-
options.logging,
|
|
48
|
-
null,
|
|
49
|
-
msg.serverStart({
|
|
50
|
-
startupTime: performance.now() - devStart,
|
|
51
|
-
resolvedUrls: viteServer.resolvedUrls || { local: [], network: [] },
|
|
52
|
-
host: settings.config.server.host,
|
|
53
|
-
site,
|
|
54
|
-
isRestart
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
const currentVersion = "1.6.2";
|
|
58
|
-
if (currentVersion.includes("-")) {
|
|
59
|
-
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
60
|
-
}
|
|
61
|
-
if (((_b = (_a = viteConfig.server) == null ? void 0 : _a.fs) == null ? void 0 : _b.strict) === false) {
|
|
62
|
-
warn(options.logging, null, msg.fsStrictWarning());
|
|
63
|
-
}
|
|
64
|
-
const devServerAddressInfo = viteServer.httpServer.address();
|
|
65
|
-
await runHookServerStart({
|
|
66
|
-
config: settings.config,
|
|
67
|
-
address: devServerAddressInfo,
|
|
68
|
-
logging: options.logging
|
|
69
|
-
});
|
|
70
|
-
return {
|
|
71
|
-
address: devServerAddressInfo,
|
|
72
|
-
get watcher() {
|
|
73
|
-
return viteServer.watcher;
|
|
74
|
-
},
|
|
75
|
-
stop: async () => {
|
|
76
|
-
await viteServer.close();
|
|
77
|
-
await runHookServerDone({ config: settings.config, logging: options.logging });
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
1
|
+
import { createContainer, isStarted, runInContainer, startContainer } from "./container.js";
|
|
2
|
+
import { default as default2 } from "./dev.js";
|
|
3
|
+
import { createContainerWithAutomaticRestart } from "./restart.js";
|
|
81
4
|
export {
|
|
82
|
-
|
|
5
|
+
createContainer,
|
|
6
|
+
createContainerWithAutomaticRestart,
|
|
7
|
+
default2 as default,
|
|
8
|
+
isStarted,
|
|
9
|
+
runInContainer,
|
|
10
|
+
startContainer
|
|
83
11
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Container, CreateContainerParams } from './container';
|
|
2
|
+
export declare function shouldRestartContainer({ settings, configFlag, configFlagPath, restartInFlight }: Container, changedFile: string): boolean;
|
|
3
|
+
interface RestartContainerParams {
|
|
4
|
+
container: Container;
|
|
5
|
+
flags: any;
|
|
6
|
+
logMsg: string;
|
|
7
|
+
handleConfigError: (err: Error) => Promise<void> | void;
|
|
8
|
+
beforeRestart?: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function restartContainer({ container, flags, logMsg, handleConfigError, beforeRestart, }: RestartContainerParams): Promise<{
|
|
11
|
+
container: Container;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
}>;
|
|
14
|
+
export interface CreateContainerWithAutomaticRestart {
|
|
15
|
+
flags: any;
|
|
16
|
+
params: CreateContainerParams;
|
|
17
|
+
handleConfigError?: (error: Error) => void | Promise<void>;
|
|
18
|
+
beforeRestart?: () => void;
|
|
19
|
+
}
|
|
20
|
+
interface Restart {
|
|
21
|
+
container: Container;
|
|
22
|
+
restarted: () => Promise<Error | null>;
|
|
23
|
+
}
|
|
24
|
+
export declare function createContainerWithAutomaticRestart({ flags, handleConfigError, beforeRestart, params, }: CreateContainerWithAutomaticRestart): Promise<Restart>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import * as vite from "vite";
|
|
2
|
+
import { createSettings, openConfig } from "../config/index.js";
|
|
3
|
+
import { createSafeError } from "../errors/index.js";
|
|
4
|
+
import { info } from "../logger/core.js";
|
|
5
|
+
import { createContainer, isStarted, startContainer } from "./container.js";
|
|
6
|
+
async function createRestartedContainer(container, settings, needsStart) {
|
|
7
|
+
const { logging, fs, resolvedRoot, configFlag, configFlagPath } = container;
|
|
8
|
+
const newContainer = await createContainer({
|
|
9
|
+
isRestart: true,
|
|
10
|
+
logging,
|
|
11
|
+
settings,
|
|
12
|
+
fs,
|
|
13
|
+
root: resolvedRoot,
|
|
14
|
+
configFlag,
|
|
15
|
+
configFlagPath
|
|
16
|
+
});
|
|
17
|
+
if (needsStart) {
|
|
18
|
+
await startContainer(newContainer);
|
|
19
|
+
}
|
|
20
|
+
return newContainer;
|
|
21
|
+
}
|
|
22
|
+
function shouldRestartContainer({ settings, configFlag, configFlagPath, restartInFlight }, changedFile) {
|
|
23
|
+
if (restartInFlight)
|
|
24
|
+
return false;
|
|
25
|
+
let shouldRestart = false;
|
|
26
|
+
if (configFlag) {
|
|
27
|
+
if (!!configFlagPath) {
|
|
28
|
+
shouldRestart = vite.normalizePath(configFlagPath) === vite.normalizePath(changedFile);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
const exp = new RegExp(`.*astro.config.((mjs)|(cjs)|(js)|(ts))$`);
|
|
32
|
+
const normalizedChangedFile = vite.normalizePath(changedFile);
|
|
33
|
+
shouldRestart = exp.test(normalizedChangedFile);
|
|
34
|
+
}
|
|
35
|
+
if (!shouldRestart && settings.watchFiles.length > 0) {
|
|
36
|
+
shouldRestart = settings.watchFiles.some(
|
|
37
|
+
(path) => vite.normalizePath(path) === vite.normalizePath(changedFile)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return shouldRestart;
|
|
41
|
+
}
|
|
42
|
+
async function restartContainer({
|
|
43
|
+
container,
|
|
44
|
+
flags,
|
|
45
|
+
logMsg,
|
|
46
|
+
handleConfigError,
|
|
47
|
+
beforeRestart
|
|
48
|
+
}) {
|
|
49
|
+
const { logging, close, resolvedRoot, settings: existingSettings } = container;
|
|
50
|
+
container.restartInFlight = true;
|
|
51
|
+
if (beforeRestart) {
|
|
52
|
+
beforeRestart();
|
|
53
|
+
}
|
|
54
|
+
const needsStart = isStarted(container);
|
|
55
|
+
try {
|
|
56
|
+
const newConfig = await openConfig({
|
|
57
|
+
cwd: resolvedRoot,
|
|
58
|
+
flags,
|
|
59
|
+
cmd: "dev",
|
|
60
|
+
logging,
|
|
61
|
+
isRestart: true,
|
|
62
|
+
fsMod: container.fs
|
|
63
|
+
});
|
|
64
|
+
info(logging, "astro", logMsg + "\n");
|
|
65
|
+
let astroConfig = newConfig.astroConfig;
|
|
66
|
+
const settings = createSettings(astroConfig, resolvedRoot);
|
|
67
|
+
await close();
|
|
68
|
+
return {
|
|
69
|
+
container: await createRestartedContainer(container, settings, needsStart),
|
|
70
|
+
error: null
|
|
71
|
+
};
|
|
72
|
+
} catch (_err) {
|
|
73
|
+
const error = createSafeError(_err);
|
|
74
|
+
await handleConfigError(error);
|
|
75
|
+
await close();
|
|
76
|
+
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
77
|
+
return {
|
|
78
|
+
container: await createRestartedContainer(container, existingSettings, needsStart),
|
|
79
|
+
error
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function createContainerWithAutomaticRestart({
|
|
84
|
+
flags,
|
|
85
|
+
handleConfigError = (_e) => {
|
|
86
|
+
},
|
|
87
|
+
beforeRestart,
|
|
88
|
+
params
|
|
89
|
+
}) {
|
|
90
|
+
const initialContainer = await createContainer(params);
|
|
91
|
+
let resolveRestart;
|
|
92
|
+
let restartComplete = new Promise((resolve) => {
|
|
93
|
+
resolveRestart = resolve;
|
|
94
|
+
});
|
|
95
|
+
let restart = {
|
|
96
|
+
container: initialContainer,
|
|
97
|
+
restarted() {
|
|
98
|
+
return restartComplete;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
function handleServerRestart(logMsg) {
|
|
102
|
+
const container = restart.container;
|
|
103
|
+
return async function(changedFile) {
|
|
104
|
+
if (shouldRestartContainer(container, changedFile)) {
|
|
105
|
+
const { container: newContainer, error } = await restartContainer({
|
|
106
|
+
beforeRestart,
|
|
107
|
+
container,
|
|
108
|
+
flags,
|
|
109
|
+
logMsg,
|
|
110
|
+
async handleConfigError(err) {
|
|
111
|
+
await handleConfigError(err);
|
|
112
|
+
container.viteServer.ws.send({
|
|
113
|
+
type: "error",
|
|
114
|
+
err: {
|
|
115
|
+
message: err.message,
|
|
116
|
+
stack: err.stack || ""
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
restart.container = newContainer;
|
|
122
|
+
addWatches();
|
|
123
|
+
resolveRestart(error);
|
|
124
|
+
restartComplete = new Promise((resolve) => {
|
|
125
|
+
resolveRestart = resolve;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function addWatches() {
|
|
131
|
+
const watcher = restart.container.viteServer.watcher;
|
|
132
|
+
watcher.on("change", handleServerRestart("Configuration updated. Restarting..."));
|
|
133
|
+
watcher.on("unlink", handleServerRestart("Configuration removed. Restarting..."));
|
|
134
|
+
watcher.on("add", handleServerRestart("Configuration added. Restarting..."));
|
|
135
|
+
}
|
|
136
|
+
addWatches();
|
|
137
|
+
return restart;
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
createContainerWithAutomaticRestart,
|
|
141
|
+
restartContainer,
|
|
142
|
+
shouldRestartContainer
|
|
143
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { EndpointHandler } from '../../@types/astro';
|
|
2
|
+
import type { AstroConfig, EndpointHandler } from '../../@types/astro';
|
|
3
3
|
import type { Environment, RenderContext } from '../render/index';
|
|
4
4
|
import { AstroCookies } from '../cookies/index.js';
|
|
5
5
|
declare type EndpointCallResult = {
|
|
@@ -12,4 +12,5 @@ declare type EndpointCallResult = {
|
|
|
12
12
|
response: Response;
|
|
13
13
|
};
|
|
14
14
|
export declare function call(mod: EndpointHandler, env: Environment, ctx: RenderContext): Promise<EndpointCallResult>;
|
|
15
|
+
export declare function throwIfRedirectNotAllowed(response: Response, config: AstroConfig): void;
|
|
15
16
|
export {};
|
|
@@ -79,6 +79,17 @@ async function call(mod, env, ctx) {
|
|
|
79
79
|
cookies: context.cookies
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
+
function isRedirect(statusCode) {
|
|
83
|
+
return statusCode >= 300 && statusCode < 400;
|
|
84
|
+
}
|
|
85
|
+
function throwIfRedirectNotAllowed(response, config) {
|
|
86
|
+
if (config.output !== "server" && isRedirect(response.status)) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Redirects are only available when using output: 'server'. Update your Astro config if you need SSR features.`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
82
92
|
export {
|
|
83
|
-
call
|
|
93
|
+
call,
|
|
94
|
+
throwIfRedirectNotAllowed
|
|
84
95
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type ErrorPayload, type Logger, type LogLevel
|
|
1
|
+
import { type ErrorPayload, type Logger, type LogLevel } from 'vite';
|
|
2
|
+
import type { ModuleLoader } from '../../module-loader/index.js';
|
|
2
3
|
import { AstroError, type ErrorWithMetadata } from '../errors.js';
|
|
3
4
|
/**
|
|
4
5
|
* Custom logger with better error reporting for incompatible packages
|
|
5
6
|
*/
|
|
6
7
|
export declare function createCustomViteLogger(logLevel: LogLevel): Logger;
|
|
7
|
-
export declare function enhanceViteSSRError(error: Error, filePath?: URL,
|
|
8
|
+
export declare function enhanceViteSSRError(error: Error, filePath?: URL, loader?: ModuleLoader): AstroError;
|
|
8
9
|
/**
|
|
9
10
|
* Generate a payload for Vite's error overlay
|
|
10
11
|
*/
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
|
-
import {
|
|
4
|
-
createLogger
|
|
5
|
-
} from "vite";
|
|
3
|
+
import { createLogger } from "vite";
|
|
6
4
|
import { AstroErrorCodes } from "../codes.js";
|
|
7
5
|
import { AstroError } from "../errors.js";
|
|
8
6
|
import { incompatPackageExp } from "./utils.js";
|
|
@@ -18,11 +16,11 @@ function createCustomViteLogger(logLevel) {
|
|
|
18
16
|
};
|
|
19
17
|
return logger;
|
|
20
18
|
}
|
|
21
|
-
function enhanceViteSSRError(error, filePath,
|
|
19
|
+
function enhanceViteSSRError(error, filePath, loader) {
|
|
22
20
|
var _a, _b;
|
|
23
|
-
if (
|
|
21
|
+
if (loader) {
|
|
24
22
|
try {
|
|
25
|
-
|
|
23
|
+
loader.fixStacktrace(error);
|
|
26
24
|
} catch {
|
|
27
25
|
}
|
|
28
26
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.6.
|
|
50
|
+
const version = "1.6.4";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -255,7 +255,7 @@ function printHelp({
|
|
|
255
255
|
message.push(
|
|
256
256
|
linebreak(),
|
|
257
257
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
258
|
-
`v${"1.6.
|
|
258
|
+
`v${"1.6.4"}`
|
|
259
259
|
)} ${headline}`
|
|
260
260
|
);
|
|
261
261
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type * as fs from 'fs';
|
|
3
|
+
import type TypedEmitter from '../../@types/typed-emitter';
|
|
4
|
+
export declare type LoaderEvents = {
|
|
5
|
+
'file-add': (msg: [path: string, stats?: fs.Stats | undefined]) => void;
|
|
6
|
+
'file-change': (msg: [path: string, stats?: fs.Stats | undefined]) => void;
|
|
7
|
+
'file-unlink': (msg: [path: string, stats?: fs.Stats | undefined]) => void;
|
|
8
|
+
'hmr-error': (msg: {
|
|
9
|
+
type: 'error';
|
|
10
|
+
err: {
|
|
11
|
+
message: string;
|
|
12
|
+
stack: string;
|
|
13
|
+
};
|
|
14
|
+
}) => void;
|
|
15
|
+
};
|
|
16
|
+
export declare type ModuleLoaderEventEmitter = TypedEmitter<LoaderEvents>;
|
|
17
|
+
export interface ModuleLoader {
|
|
18
|
+
import: (src: string) => Promise<Record<string, any>>;
|
|
19
|
+
resolveId: (specifier: string, parentId: string | undefined) => Promise<string | undefined>;
|
|
20
|
+
getModuleById: (id: string) => ModuleNode | undefined;
|
|
21
|
+
getModulesByFile: (file: string) => Set<ModuleNode> | undefined;
|
|
22
|
+
getModuleInfo: (id: string) => ModuleInfo | null;
|
|
23
|
+
eachModule(callbackfn: (value: ModuleNode, key: string) => void): void;
|
|
24
|
+
invalidateModule(mod: ModuleNode): void;
|
|
25
|
+
fixStacktrace: (error: Error) => void;
|
|
26
|
+
clientReload: () => void;
|
|
27
|
+
webSocketSend: (msg: any) => void;
|
|
28
|
+
isHttps: () => boolean;
|
|
29
|
+
events: TypedEmitter<LoaderEvents>;
|
|
30
|
+
}
|
|
31
|
+
export interface ModuleNode {
|
|
32
|
+
id: string | null;
|
|
33
|
+
url: string;
|
|
34
|
+
ssrModule: Record<string, any> | null;
|
|
35
|
+
ssrError: Error | null;
|
|
36
|
+
importedModules: Set<ModuleNode>;
|
|
37
|
+
}
|
|
38
|
+
export interface ModuleInfo {
|
|
39
|
+
id: string;
|
|
40
|
+
meta?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
export declare function createLoader(overrides: Partial<ModuleLoader>): ModuleLoader;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
function createLoader(overrides) {
|
|
3
|
+
return {
|
|
4
|
+
import() {
|
|
5
|
+
throw new Error(`Not implemented`);
|
|
6
|
+
},
|
|
7
|
+
resolveId(id) {
|
|
8
|
+
return Promise.resolve(id);
|
|
9
|
+
},
|
|
10
|
+
getModuleById() {
|
|
11
|
+
return void 0;
|
|
12
|
+
},
|
|
13
|
+
getModulesByFile() {
|
|
14
|
+
return void 0;
|
|
15
|
+
},
|
|
16
|
+
getModuleInfo() {
|
|
17
|
+
return null;
|
|
18
|
+
},
|
|
19
|
+
eachModule() {
|
|
20
|
+
throw new Error(`Not implemented`);
|
|
21
|
+
},
|
|
22
|
+
invalidateModule() {
|
|
23
|
+
},
|
|
24
|
+
fixStacktrace() {
|
|
25
|
+
},
|
|
26
|
+
clientReload() {
|
|
27
|
+
},
|
|
28
|
+
webSocketSend() {
|
|
29
|
+
},
|
|
30
|
+
isHttps() {
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
events: new EventEmitter(),
|
|
34
|
+
...overrides
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
createLoader
|
|
39
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
function createViteLoader(viteServer) {
|
|
3
|
+
const events = new EventEmitter();
|
|
4
|
+
viteServer.watcher.on("add", (...args) => events.emit("file-add", args));
|
|
5
|
+
viteServer.watcher.on("unlink", (...args) => events.emit("file-unlink", args));
|
|
6
|
+
viteServer.watcher.on("change", (...args) => events.emit("file-change", args));
|
|
7
|
+
wrapMethod(viteServer.ws, "send", (msg) => {
|
|
8
|
+
if ((msg == null ? void 0 : msg.type) === "error") {
|
|
9
|
+
events.emit("hmr-error", msg);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
import(src) {
|
|
14
|
+
return viteServer.ssrLoadModule(src);
|
|
15
|
+
},
|
|
16
|
+
async resolveId(spec, parent) {
|
|
17
|
+
const ret = await viteServer.pluginContainer.resolveId(spec, parent);
|
|
18
|
+
return ret == null ? void 0 : ret.id;
|
|
19
|
+
},
|
|
20
|
+
getModuleById(id) {
|
|
21
|
+
return viteServer.moduleGraph.getModuleById(id);
|
|
22
|
+
},
|
|
23
|
+
getModulesByFile(file) {
|
|
24
|
+
return viteServer.moduleGraph.getModulesByFile(file);
|
|
25
|
+
},
|
|
26
|
+
getModuleInfo(id) {
|
|
27
|
+
return viteServer.pluginContainer.getModuleInfo(id);
|
|
28
|
+
},
|
|
29
|
+
eachModule(cb) {
|
|
30
|
+
return viteServer.moduleGraph.idToModuleMap.forEach(cb);
|
|
31
|
+
},
|
|
32
|
+
invalidateModule(mod) {
|
|
33
|
+
viteServer.moduleGraph.invalidateModule(mod);
|
|
34
|
+
},
|
|
35
|
+
fixStacktrace(err) {
|
|
36
|
+
return viteServer.ssrFixStacktrace(err);
|
|
37
|
+
},
|
|
38
|
+
clientReload() {
|
|
39
|
+
viteServer.ws.send({
|
|
40
|
+
type: "full-reload",
|
|
41
|
+
path: "*"
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
webSocketSend(msg) {
|
|
45
|
+
return viteServer.ws.send(msg);
|
|
46
|
+
},
|
|
47
|
+
isHttps() {
|
|
48
|
+
return !!viteServer.config.server.https;
|
|
49
|
+
},
|
|
50
|
+
events
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function wrapMethod(object, method, newFn) {
|
|
54
|
+
const orig = object[method];
|
|
55
|
+
object[method] = function(...args) {
|
|
56
|
+
newFn.apply(this, args);
|
|
57
|
+
return orig.apply(this, args);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
createViteLoader
|
|
62
|
+
};
|
|
@@ -34,7 +34,8 @@ async function preview(_settings, { logging }) {
|
|
|
34
34
|
client: settings.config.build.client,
|
|
35
35
|
serverEntrypoint: new URL(settings.config.build.serverEntry, settings.config.build.server),
|
|
36
36
|
host,
|
|
37
|
-
port
|
|
37
|
+
port,
|
|
38
|
+
base: settings.config.base
|
|
38
39
|
});
|
|
39
40
|
return server;
|
|
40
41
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { ModuleLoader } from '../../module-loader/index';
|
|
2
2
|
import { RuntimeMode } from '../../../@types/astro.js';
|
|
3
3
|
/** Given a filePath URL, crawl Vite’s module graph to find all style imports. */
|
|
4
|
-
export declare function getStylesForURL(filePath: URL,
|
|
4
|
+
export declare function getStylesForURL(filePath: URL, loader: ModuleLoader, mode: RuntimeMode): Promise<{
|
|
5
5
|
urls: Set<string>;
|
|
6
6
|
stylesMap: Map<string, string>;
|
|
7
7
|
}>;
|
|
@@ -2,13 +2,13 @@ import path from "path";
|
|
|
2
2
|
import { viteID } from "../../util.js";
|
|
3
3
|
import { STYLE_EXTENSIONS } from "../util.js";
|
|
4
4
|
import { crawlGraph } from "./vite.js";
|
|
5
|
-
async function getStylesForURL(filePath,
|
|
5
|
+
async function getStylesForURL(filePath, loader, mode) {
|
|
6
6
|
const importedCssUrls = /* @__PURE__ */ new Set();
|
|
7
7
|
const importedStylesMap = /* @__PURE__ */ new Map();
|
|
8
|
-
for await (const importedModule of crawlGraph(
|
|
8
|
+
for await (const importedModule of crawlGraph(loader, viteID(filePath), true)) {
|
|
9
9
|
const ext = path.extname(importedModule.url).toLowerCase();
|
|
10
10
|
if (STYLE_EXTENSIONS.has(ext)) {
|
|
11
|
-
const ssrModule = importedModule.ssrModule ?? await
|
|
11
|
+
const ssrModule = importedModule.ssrModule ?? await loader.import(importedModule.url);
|
|
12
12
|
if (mode === "development" && typeof (ssrModule == null ? void 0 : ssrModule.default) === "string") {
|
|
13
13
|
importedStylesMap.set(importedModule.url, ssrModule.default);
|
|
14
14
|
} else {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ViteDevServer } from 'vite';
|
|
2
1
|
import type { AstroSettings } from '../../../@types/astro';
|
|
3
2
|
import type { LogOptions } from '../../logger/core.js';
|
|
3
|
+
import type { ModuleLoader } from '../../module-loader/index';
|
|
4
4
|
import type { Environment } from '../index';
|
|
5
5
|
export declare type DevelopmentEnvironment = Environment & {
|
|
6
|
+
loader: ModuleLoader;
|
|
6
7
|
settings: AstroSettings;
|
|
7
|
-
viteServer: ViteDevServer;
|
|
8
8
|
};
|
|
9
|
-
export declare function createDevelopmentEnvironment(settings: AstroSettings, logging: LogOptions,
|
|
9
|
+
export declare function createDevelopmentEnvironment(settings: AstroSettings, logging: LogOptions, loader: ModuleLoader): DevelopmentEnvironment;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createEnvironment } from "../index.js";
|
|
2
2
|
import { RouteCache } from "../route-cache.js";
|
|
3
3
|
import { createResolve } from "./resolve.js";
|
|
4
|
-
function createDevelopmentEnvironment(settings, logging,
|
|
4
|
+
function createDevelopmentEnvironment(settings, logging, loader) {
|
|
5
5
|
var _a;
|
|
6
6
|
const mode = "development";
|
|
7
7
|
let env = createEnvironment({
|
|
@@ -13,7 +13,7 @@ function createDevelopmentEnvironment(settings, logging, viteServer) {
|
|
|
13
13
|
},
|
|
14
14
|
mode,
|
|
15
15
|
renderers: [],
|
|
16
|
-
resolve: createResolve(
|
|
16
|
+
resolve: createResolve(loader),
|
|
17
17
|
routeCache: new RouteCache(logging, mode),
|
|
18
18
|
site: settings.config.site,
|
|
19
19
|
ssr: settings.config.output === "server",
|
|
@@ -21,7 +21,7 @@ function createDevelopmentEnvironment(settings, logging, viteServer) {
|
|
|
21
21
|
});
|
|
22
22
|
return {
|
|
23
23
|
...env,
|
|
24
|
-
|
|
24
|
+
loader,
|
|
25
25
|
settings
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ViteDevServer } from 'vite';
|
|
2
1
|
import type { AstroSettings, ComponentInstance, RouteData, RuntimeMode, SSRLoadedRenderer } from '../../../@types/astro';
|
|
3
2
|
import { LogOptions } from '../../logger/core.js';
|
|
3
|
+
import type { ModuleLoader } from '../../module-loader/index';
|
|
4
4
|
import { RouteCache } from '../route-cache.js';
|
|
5
5
|
import type { DevelopmentEnvironment } from './environment';
|
|
6
6
|
export { createDevelopmentEnvironment } from './environment.js';
|
|
@@ -22,8 +22,8 @@ export interface SSROptionsOld {
|
|
|
22
22
|
route?: RouteData;
|
|
23
23
|
/** pass in route cache because SSR can’t manage cache-busting */
|
|
24
24
|
routeCache: RouteCache;
|
|
25
|
-
/** Vite
|
|
26
|
-
|
|
25
|
+
/** Module loader (Vite) */
|
|
26
|
+
loader: ModuleLoader;
|
|
27
27
|
/** Request */
|
|
28
28
|
request: Request;
|
|
29
29
|
}
|
|
@@ -44,6 +44,6 @@ export interface SSROptions {
|
|
|
44
44
|
route?: RouteData;
|
|
45
45
|
}
|
|
46
46
|
export declare type ComponentPreload = [SSRLoadedRenderer[], ComponentInstance];
|
|
47
|
-
export declare function loadRenderers(
|
|
47
|
+
export declare function loadRenderers(moduleLoader: ModuleLoader, settings: AstroSettings): Promise<SSRLoadedRenderer[]>;
|
|
48
48
|
export declare function preload({ env, filePath, }: Pick<SSROptions, 'env' | 'filePath'>): Promise<ComponentPreload>;
|
|
49
49
|
export declare function renderPage(options: SSROptions): Promise<Response>;
|