astro 1.1.7 → 1.2.1
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 +4 -2
- package/dist/cli/index.js +56 -23
- package/dist/core/add/index.js +73 -69
- package/dist/core/build/generate.js +3 -1
- package/dist/core/build/vite-plugin-analyzer.js +7 -1
- package/dist/{vite-plugin-astro → core/compile}/compile.d.ts +3 -8
- package/dist/{vite-plugin-astro → core/compile}/compile.js +23 -56
- package/dist/core/compile/index.d.ts +3 -0
- package/dist/core/compile/index.js +7 -0
- package/dist/core/compile/style.d.ts +5 -0
- package/dist/core/compile/style.js +31 -0
- package/dist/core/compile/types.d.ts +7 -0
- package/dist/core/compile/types.js +0 -0
- package/dist/core/config.d.ts +6 -2
- package/dist/core/config.js +58 -37
- package/dist/core/dev/index.d.ts +1 -0
- package/dist/core/dev/index.js +4 -2
- package/dist/core/endpoint/dev/index.d.ts +2 -0
- package/dist/core/endpoint/index.d.ts +2 -0
- package/dist/core/endpoint/index.js +2 -1
- package/dist/core/messages.d.ts +2 -1
- package/dist/core/messages.js +5 -4
- package/dist/core/util.d.ts +13 -0
- package/dist/core/util.js +10 -2
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/runtime/server/render/page.js +1 -1
- package/dist/runtime/server/serialize.js +24 -14
- package/dist/vite-plugin-astro/hmr.d.ts +1 -1
- package/dist/vite-plugin-astro/hmr.js +3 -1
- package/dist/vite-plugin-astro/index.js +18 -26
- package/dist/vite-plugin-markdown-legacy/index.js +16 -10
- package/dist/vite-style-transform/index.d.ts +2 -0
- package/dist/vite-style-transform/index.js +5 -0
- package/dist/vite-style-transform/style-transform.d.ts +10 -0
- package/dist/vite-style-transform/style-transform.js +36 -0
- package/dist/{vite-plugin-astro/styles.d.ts → vite-style-transform/transform-with-vite.d.ts} +0 -0
- package/dist/{vite-plugin-astro/styles.js → vite-style-transform/transform-with-vite.js} +0 -0
- package/package.json +8 -7
package/dist/core/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "fs";
|
|
1
2
|
import load, { ProloadError, resolve } from "@proload/core";
|
|
2
3
|
import loadTypeScript from "@proload/plugin-tsm";
|
|
3
4
|
import * as colors from "kleur/colors";
|
|
@@ -224,6 +225,9 @@ function resolveFlags(flags) {
|
|
|
224
225
|
drafts: typeof flags.drafts === "boolean" ? flags.drafts : void 0
|
|
225
226
|
};
|
|
226
227
|
}
|
|
228
|
+
function resolveRoot(cwd) {
|
|
229
|
+
return cwd ? path.resolve(cwd) : process.cwd();
|
|
230
|
+
}
|
|
227
231
|
function mergeCLIFlags(astroConfig, flags, cmd) {
|
|
228
232
|
astroConfig.server = astroConfig.server || {};
|
|
229
233
|
astroConfig.markdown = astroConfig.markdown || {};
|
|
@@ -239,38 +243,35 @@ function mergeCLIFlags(astroConfig, flags, cmd) {
|
|
|
239
243
|
}
|
|
240
244
|
return astroConfig;
|
|
241
245
|
}
|
|
242
|
-
async function
|
|
243
|
-
const root =
|
|
246
|
+
async function resolveConfigPath(configOptions) {
|
|
247
|
+
const root = resolveRoot(configOptions.cwd);
|
|
244
248
|
const flags = resolveFlags(configOptions.flags || {});
|
|
245
249
|
let userConfigPath;
|
|
246
250
|
if (flags == null ? void 0 : flags.config) {
|
|
247
251
|
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
|
|
248
252
|
userConfigPath = fileURLToPath(new URL(userConfigPath, `file://${root}/`));
|
|
249
253
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return
|
|
254
|
+
try {
|
|
255
|
+
const configPath = await resolve("astro", {
|
|
256
|
+
mustExist: !!userConfigPath,
|
|
257
|
+
cwd: root,
|
|
258
|
+
filePath: userConfigPath
|
|
259
|
+
});
|
|
260
|
+
return configPath;
|
|
261
|
+
} catch (e) {
|
|
262
|
+
if (e instanceof ProloadError && flags.config) {
|
|
263
|
+
throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
|
|
264
|
+
}
|
|
265
|
+
throw e;
|
|
257
266
|
}
|
|
258
267
|
}
|
|
259
268
|
async function openConfig(configOptions) {
|
|
260
|
-
const root =
|
|
269
|
+
const root = resolveRoot(configOptions.cwd);
|
|
261
270
|
const flags = resolveFlags(configOptions.flags || {});
|
|
262
271
|
let userConfig = {};
|
|
263
|
-
|
|
264
|
-
if (flags == null ? void 0 : flags.config) {
|
|
265
|
-
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
|
|
266
|
-
userConfigPath = fileURLToPath(
|
|
267
|
-
new URL(userConfigPath, appendForwardSlash(pathToFileURL(root).toString()))
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
const config = await tryLoadConfig(configOptions, flags, userConfigPath, root);
|
|
272
|
+
const config = await tryLoadConfig(configOptions, flags, root);
|
|
271
273
|
if (config) {
|
|
272
274
|
userConfig = config.value;
|
|
273
|
-
userConfigPath = config.filePath;
|
|
274
275
|
}
|
|
275
276
|
const astroConfig = await resolveConfig(
|
|
276
277
|
userConfig,
|
|
@@ -282,56 +283,74 @@ async function openConfig(configOptions) {
|
|
|
282
283
|
return {
|
|
283
284
|
astroConfig,
|
|
284
285
|
userConfig,
|
|
285
|
-
userConfigPath,
|
|
286
286
|
flags,
|
|
287
287
|
root
|
|
288
288
|
};
|
|
289
289
|
}
|
|
290
|
-
async function tryLoadConfig(configOptions, flags,
|
|
290
|
+
async function tryLoadConfig(configOptions, flags, root) {
|
|
291
|
+
let finallyCleanup = async () => {
|
|
292
|
+
};
|
|
291
293
|
try {
|
|
294
|
+
let configPath = await resolveConfigPath({
|
|
295
|
+
cwd: configOptions.cwd,
|
|
296
|
+
flags: configOptions.flags
|
|
297
|
+
});
|
|
298
|
+
if (!configPath)
|
|
299
|
+
return void 0;
|
|
300
|
+
if (configOptions.isConfigReload) {
|
|
301
|
+
const tempConfigPath = path.join(
|
|
302
|
+
root,
|
|
303
|
+
`.temp.${Date.now()}.config${path.extname(configPath)}`
|
|
304
|
+
);
|
|
305
|
+
await fs.promises.writeFile(tempConfigPath, await fs.promises.readFile(configPath));
|
|
306
|
+
finallyCleanup = async () => {
|
|
307
|
+
try {
|
|
308
|
+
await fs.promises.unlink(tempConfigPath);
|
|
309
|
+
} catch {
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
configPath = tempConfigPath;
|
|
313
|
+
}
|
|
292
314
|
const config = await load("astro", {
|
|
293
|
-
mustExist: !!
|
|
315
|
+
mustExist: !!configPath,
|
|
294
316
|
cwd: root,
|
|
295
|
-
filePath:
|
|
317
|
+
filePath: configPath
|
|
296
318
|
});
|
|
297
319
|
return config;
|
|
298
320
|
} catch (e) {
|
|
299
321
|
if (e instanceof ProloadError && flags.config) {
|
|
300
322
|
throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
|
|
301
323
|
}
|
|
302
|
-
const
|
|
303
|
-
if (!
|
|
324
|
+
const configPath = await resolveConfigPath(configOptions);
|
|
325
|
+
if (!configPath) {
|
|
304
326
|
throw e;
|
|
305
327
|
}
|
|
306
328
|
const viteServer = await vite.createServer({
|
|
307
329
|
server: { middlewareMode: true, hmr: false },
|
|
330
|
+
optimizeDeps: { entries: [] },
|
|
331
|
+
clearScreen: false,
|
|
308
332
|
appType: "custom"
|
|
309
333
|
});
|
|
310
334
|
try {
|
|
311
|
-
const mod = await viteServer.ssrLoadModule(
|
|
335
|
+
const mod = await viteServer.ssrLoadModule(configPath);
|
|
312
336
|
if (mod == null ? void 0 : mod.default) {
|
|
313
337
|
return {
|
|
314
338
|
value: mod.default,
|
|
315
|
-
filePath:
|
|
339
|
+
filePath: configPath
|
|
316
340
|
};
|
|
317
341
|
}
|
|
318
342
|
} finally {
|
|
319
343
|
await viteServer.close();
|
|
320
344
|
}
|
|
345
|
+
} finally {
|
|
346
|
+
await finallyCleanup();
|
|
321
347
|
}
|
|
322
348
|
}
|
|
323
349
|
async function loadConfig(configOptions) {
|
|
324
|
-
const root =
|
|
350
|
+
const root = resolveRoot(configOptions.cwd);
|
|
325
351
|
const flags = resolveFlags(configOptions.flags || {});
|
|
326
352
|
let userConfig = {};
|
|
327
|
-
|
|
328
|
-
if (flags == null ? void 0 : flags.config) {
|
|
329
|
-
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
|
|
330
|
-
userConfigPath = fileURLToPath(
|
|
331
|
-
new URL(userConfigPath, appendForwardSlash(pathToFileURL(root).toString()))
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
const config = await tryLoadConfig(configOptions, flags, userConfigPath, root);
|
|
353
|
+
const config = await tryLoadConfig(configOptions, flags, root);
|
|
335
354
|
if (config) {
|
|
336
355
|
userConfig = config.value;
|
|
337
356
|
}
|
|
@@ -380,6 +399,8 @@ export {
|
|
|
380
399
|
mergeConfig,
|
|
381
400
|
openConfig,
|
|
382
401
|
resolveConfig,
|
|
383
|
-
|
|
402
|
+
resolveConfigPath,
|
|
403
|
+
resolveFlags,
|
|
404
|
+
resolveRoot,
|
|
384
405
|
validateConfig
|
|
385
406
|
};
|
package/dist/core/dev/index.d.ts
CHANGED
package/dist/core/dev/index.js
CHANGED
|
@@ -18,6 +18,7 @@ async function dev(config, options) {
|
|
|
18
18
|
await options.telemetry.record([]);
|
|
19
19
|
config = await runHookConfigSetup({ config, command: "dev", logging: options.logging });
|
|
20
20
|
const { host, port } = config.server;
|
|
21
|
+
const { isRestart = false } = options;
|
|
21
22
|
const rendererClientEntries = config._ctx.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
|
|
22
23
|
const viteConfig = await createVite(
|
|
23
24
|
{
|
|
@@ -43,10 +44,11 @@ async function dev(config, options) {
|
|
|
43
44
|
config,
|
|
44
45
|
devServerAddressInfo,
|
|
45
46
|
site,
|
|
46
|
-
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
|
|
47
|
+
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https),
|
|
48
|
+
isRestart
|
|
47
49
|
})
|
|
48
50
|
);
|
|
49
|
-
const currentVersion = "1.1
|
|
51
|
+
const currentVersion = "1.2.1";
|
|
50
52
|
if (currentVersion.includes("-")) {
|
|
51
53
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
52
54
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { SSROptions } from '../../render/dev';
|
|
2
3
|
export declare function call(ssrOpts: SSROptions): Promise<{
|
|
3
4
|
type: "simple";
|
|
4
5
|
body: string;
|
|
6
|
+
encoding?: BufferEncoding | undefined;
|
|
5
7
|
} | {
|
|
6
8
|
type: "response";
|
|
7
9
|
response: Response;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { EndpointHandler } from '../../@types/astro';
|
|
2
3
|
import type { RenderOptions } from '../render/core';
|
|
3
4
|
export declare type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | 'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr' | 'status'>;
|
|
4
5
|
declare type EndpointCallResult = {
|
|
5
6
|
type: 'simple';
|
|
6
7
|
body: string;
|
|
8
|
+
encoding?: BufferEncoding;
|
|
7
9
|
} | {
|
|
8
10
|
type: 'response';
|
|
9
11
|
response: Response;
|
package/dist/core/messages.d.ts
CHANGED
|
@@ -17,12 +17,13 @@ export declare function hmr({ file, style }: {
|
|
|
17
17
|
style?: boolean;
|
|
18
18
|
}): string;
|
|
19
19
|
/** Display dev server host and startup time */
|
|
20
|
-
export declare function devStart({ startupTime, devServerAddressInfo, config, https, site, }: {
|
|
20
|
+
export declare function devStart({ startupTime, devServerAddressInfo, config, https, site, isRestart, }: {
|
|
21
21
|
startupTime: number;
|
|
22
22
|
devServerAddressInfo: AddressInfo;
|
|
23
23
|
config: AstroConfig;
|
|
24
24
|
https: boolean;
|
|
25
25
|
site: URL | undefined;
|
|
26
|
+
isRestart?: boolean;
|
|
26
27
|
}): string;
|
|
27
28
|
export declare function telemetryNotice(): string;
|
|
28
29
|
export declare function telemetryEnabled(): string;
|
package/dist/core/messages.js
CHANGED
|
@@ -44,9 +44,10 @@ function devStart({
|
|
|
44
44
|
devServerAddressInfo,
|
|
45
45
|
config,
|
|
46
46
|
https,
|
|
47
|
-
site
|
|
47
|
+
site,
|
|
48
|
+
isRestart = false
|
|
48
49
|
}) {
|
|
49
|
-
const version = "1.1
|
|
50
|
+
const version = "1.2.1";
|
|
50
51
|
const rootPath = site ? site.pathname : "/";
|
|
51
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -77,7 +78,7 @@ function devStart({
|
|
|
77
78
|
}
|
|
78
79
|
const messages = [
|
|
79
80
|
`${emoji("\u{1F680} ", "")}${bgGreen(black(` astro `))} ${green(`v${version}`)} ${dim(
|
|
80
|
-
|
|
81
|
+
`${isRestart ? "re" : ""}started in ${Math.round(startupTime)}ms`
|
|
81
82
|
)}`,
|
|
82
83
|
"",
|
|
83
84
|
local,
|
|
@@ -225,7 +226,7 @@ function printHelp({
|
|
|
225
226
|
message.push(
|
|
226
227
|
linebreak(),
|
|
227
228
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
228
|
-
`v${"1.1
|
|
229
|
+
`v${"1.2.1"}`
|
|
229
230
|
)} ${headline}`
|
|
230
231
|
);
|
|
231
232
|
}
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { ErrorPayload, ViteDevServer } from 'vite';
|
|
2
3
|
import type { AstroConfig, RouteType } from '../@types/astro';
|
|
3
4
|
export declare const ASTRO_VERSION: string;
|
|
@@ -46,3 +47,15 @@ export declare function getLocalAddress(serverAddress: string, host: string | bo
|
|
|
46
47
|
* through a script tag or a dynamic import as-is.
|
|
47
48
|
*/
|
|
48
49
|
export declare function resolveIdToUrl(viteServer: ViteDevServer, id: string): Promise<string>;
|
|
50
|
+
export declare const AggregateError: AggregateErrorConstructor | {
|
|
51
|
+
new (errors: Iterable<any>, message?: string | undefined): {
|
|
52
|
+
errors: Array<any>;
|
|
53
|
+
name: string;
|
|
54
|
+
message: string;
|
|
55
|
+
stack?: string | undefined;
|
|
56
|
+
cause?: Error | undefined;
|
|
57
|
+
};
|
|
58
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
59
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
60
|
+
stackTraceLimit: number;
|
|
61
|
+
};
|
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.1
|
|
8
|
+
const ASTRO_VERSION = "1.2.1";
|
|
9
9
|
function isObject(value) {
|
|
10
10
|
return typeof value === "object" && value != null;
|
|
11
11
|
}
|
|
@@ -87,7 +87,7 @@ function resolveDependency(dep, projectRoot) {
|
|
|
87
87
|
return pathToFileURL(resolved).toString();
|
|
88
88
|
}
|
|
89
89
|
function viteID(filePath) {
|
|
90
|
-
return slash(fileURLToPath(filePath));
|
|
90
|
+
return slash(fileURLToPath(filePath) + filePath.search);
|
|
91
91
|
}
|
|
92
92
|
const VALID_ID_PREFIX = `/@id/`;
|
|
93
93
|
function unwrapId(id) {
|
|
@@ -170,8 +170,16 @@ async function resolveIdToUrl(viteServer, id) {
|
|
|
170
170
|
}
|
|
171
171
|
return VALID_ID_PREFIX + result.id;
|
|
172
172
|
}
|
|
173
|
+
const AggregateError = typeof globalThis.AggregateError !== "undefined" ? globalThis.AggregateError : class extends Error {
|
|
174
|
+
constructor(errors, message) {
|
|
175
|
+
super(message);
|
|
176
|
+
this.errors = [];
|
|
177
|
+
this.errors = Array.from(errors);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
173
180
|
export {
|
|
174
181
|
ASTRO_VERSION,
|
|
182
|
+
AggregateError,
|
|
175
183
|
VALID_ID_PREFIX,
|
|
176
184
|
arraify,
|
|
177
185
|
codeFrame,
|
|
@@ -56,7 +56,7 @@ async function renderPage(result, componentFactory, props, children, streaming)
|
|
|
56
56
|
controller.enqueue(encoder.encode("<!DOCTYPE html>\n"));
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
controller.enqueue(encoder.encode(html));
|
|
59
|
+
controller.enqueue(encoder.encode(String(html)));
|
|
60
60
|
i++;
|
|
61
61
|
}
|
|
62
62
|
controller.close();
|
|
@@ -8,23 +8,35 @@ const PROP_TYPE = {
|
|
|
8
8
|
BigInt: 6,
|
|
9
9
|
URL: 7
|
|
10
10
|
};
|
|
11
|
-
function serializeArray(value, metadata) {
|
|
12
|
-
|
|
11
|
+
function serializeArray(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
|
12
|
+
if (parents.has(value)) {
|
|
13
|
+
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
|
|
14
|
+
|
|
15
|
+
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
|
|
16
|
+
}
|
|
17
|
+
parents.add(value);
|
|
18
|
+
const serialized = value.map((v) => {
|
|
19
|
+
return convertToSerializedForm(v, metadata, parents);
|
|
20
|
+
});
|
|
21
|
+
parents.delete(value);
|
|
22
|
+
return serialized;
|
|
13
23
|
}
|
|
14
|
-
function serializeObject(value, metadata) {
|
|
15
|
-
if (
|
|
24
|
+
function serializeObject(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
|
25
|
+
if (parents.has(value)) {
|
|
16
26
|
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
|
|
17
27
|
|
|
18
28
|
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
|
|
19
29
|
}
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
parents.add(value);
|
|
31
|
+
const serialized = Object.fromEntries(
|
|
22
32
|
Object.entries(value).map(([k, v]) => {
|
|
23
|
-
return [k, convertToSerializedForm(v, metadata)];
|
|
33
|
+
return [k, convertToSerializedForm(v, metadata, parents)];
|
|
24
34
|
})
|
|
25
35
|
);
|
|
36
|
+
parents.delete(value);
|
|
37
|
+
return serialized;
|
|
26
38
|
}
|
|
27
|
-
function convertToSerializedForm(value, metadata) {
|
|
39
|
+
function convertToSerializedForm(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
|
28
40
|
const tag = Object.prototype.toString.call(value);
|
|
29
41
|
switch (tag) {
|
|
30
42
|
case "[object Date]": {
|
|
@@ -36,13 +48,13 @@ function convertToSerializedForm(value, metadata) {
|
|
|
36
48
|
case "[object Map]": {
|
|
37
49
|
return [
|
|
38
50
|
PROP_TYPE.Map,
|
|
39
|
-
JSON.stringify(serializeArray(Array.from(value), metadata))
|
|
51
|
+
JSON.stringify(serializeArray(Array.from(value), metadata, parents))
|
|
40
52
|
];
|
|
41
53
|
}
|
|
42
54
|
case "[object Set]": {
|
|
43
55
|
return [
|
|
44
56
|
PROP_TYPE.Set,
|
|
45
|
-
JSON.stringify(serializeArray(Array.from(value), metadata))
|
|
57
|
+
JSON.stringify(serializeArray(Array.from(value), metadata, parents))
|
|
46
58
|
];
|
|
47
59
|
}
|
|
48
60
|
case "[object BigInt]": {
|
|
@@ -52,21 +64,19 @@ function convertToSerializedForm(value, metadata) {
|
|
|
52
64
|
return [PROP_TYPE.URL, value.toString()];
|
|
53
65
|
}
|
|
54
66
|
case "[object Array]": {
|
|
55
|
-
return [PROP_TYPE.JSON, JSON.stringify(serializeArray(value, metadata))];
|
|
67
|
+
return [PROP_TYPE.JSON, JSON.stringify(serializeArray(value, metadata, parents))];
|
|
56
68
|
}
|
|
57
69
|
default: {
|
|
58
70
|
if (value !== null && typeof value === "object") {
|
|
59
|
-
return [PROP_TYPE.Value, serializeObject(value, metadata)];
|
|
71
|
+
return [PROP_TYPE.Value, serializeObject(value, metadata, parents)];
|
|
60
72
|
} else {
|
|
61
73
|
return [PROP_TYPE.Value, value];
|
|
62
74
|
}
|
|
63
75
|
}
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
|
-
let cyclicRefs = /* @__PURE__ */ new WeakSet();
|
|
67
78
|
function serializeProps(props, metadata) {
|
|
68
79
|
const serialized = JSON.stringify(serializeObject(props, metadata));
|
|
69
|
-
cyclicRefs = /* @__PURE__ */ new WeakSet();
|
|
70
80
|
return serialized;
|
|
71
81
|
}
|
|
72
82
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HmrContext, ModuleNode } from 'vite';
|
|
2
2
|
import type { AstroConfig } from '../@types/astro';
|
|
3
|
+
import { cachedCompilation } from '../core/compile/index.js';
|
|
3
4
|
import type { LogOptions } from '../core/logger/core.js';
|
|
4
|
-
import { cachedCompilation } from './compile.js';
|
|
5
5
|
export interface HandleHotUpdateOptions {
|
|
6
6
|
config: AstroConfig;
|
|
7
7
|
logging: LogOptions;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { invalidateCompilation, isCached } from "../core/compile/index.js";
|
|
2
3
|
import { info } from "../core/logger/core.js";
|
|
3
4
|
import * as msg from "../core/messages.js";
|
|
4
|
-
import { invalidateCompilation, isCached } from "./compile.js";
|
|
5
5
|
import { isAstroScript } from "./query.js";
|
|
6
6
|
const PKG_PREFIX = new URL("../../", import.meta.url);
|
|
7
7
|
const isPkgFile = (id) => {
|
|
@@ -83,6 +83,8 @@ async function handleHotUpdate(ctx, { config, logging, compile }) {
|
|
|
83
83
|
}
|
|
84
84
|
const isSelfAccepting = mods.every((m) => m.isSelfAccepting || m.url.endsWith(".svelte"));
|
|
85
85
|
if (isSelfAccepting) {
|
|
86
|
+
if (/astro\.config\.[cm][jt]s$/.test(file))
|
|
87
|
+
return mods;
|
|
86
88
|
info(logging, "astro", msg.hmr({ file }));
|
|
87
89
|
} else {
|
|
88
90
|
info(logging, "astro", msg.reload({ file }));
|
|
@@ -2,12 +2,16 @@ import ancestor from "common-ancestor-path";
|
|
|
2
2
|
import esbuild from "esbuild";
|
|
3
3
|
import slash from "slash";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
-
import {
|
|
5
|
+
import { cachedCompilation, getCachedSource } from "../core/compile/index.js";
|
|
6
|
+
import { isRelativePath, prependForwardSlash, startsWithForwardSlash } from "../core/path.js";
|
|
7
|
+
import { viteID } from "../core/util.js";
|
|
6
8
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
7
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
createTransformStyles,
|
|
11
|
+
createViteStyleTransformer
|
|
12
|
+
} from "../vite-style-transform/index.js";
|
|
8
13
|
import { handleHotUpdate } from "./hmr.js";
|
|
9
14
|
import { parseAstroRequest } from "./query.js";
|
|
10
|
-
import { createTransformStyleWithViteFn } from "./styles.js";
|
|
11
15
|
const FRONTMATTER_PARSE_REGEXP = /^\-\-\-(.*)^\-\-\-/ms;
|
|
12
16
|
function astro({ config, logging }) {
|
|
13
17
|
function normalizeFilename(filename) {
|
|
@@ -24,10 +28,11 @@ function astro({ config, logging }) {
|
|
|
24
28
|
return slash(fileURLToPath(url)) + url.search;
|
|
25
29
|
}
|
|
26
30
|
let resolvedConfig;
|
|
27
|
-
let
|
|
31
|
+
let styleTransformer;
|
|
28
32
|
let viteDevServer;
|
|
29
33
|
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
|
|
30
34
|
const isBrowserPath = (path) => path.startsWith(srcRootWeb);
|
|
35
|
+
const isFullFilePath = (path) => path.startsWith(prependForwardSlash(slash(fileURLToPath(config.root))));
|
|
31
36
|
function resolveRelativeFromAstroParent(id, parsedFrom) {
|
|
32
37
|
const filename = normalizeFilename(parsedFrom.filename);
|
|
33
38
|
const resolvedURL = new URL(id, `file://${filename}`);
|
|
@@ -42,10 +47,11 @@ function astro({ config, logging }) {
|
|
|
42
47
|
enforce: "pre",
|
|
43
48
|
configResolved(_resolvedConfig) {
|
|
44
49
|
resolvedConfig = _resolvedConfig;
|
|
45
|
-
|
|
50
|
+
styleTransformer = createViteStyleTransformer(_resolvedConfig);
|
|
46
51
|
},
|
|
47
52
|
configureServer(server) {
|
|
48
53
|
viteDevServer = server;
|
|
54
|
+
styleTransformer.viteDevServer = server;
|
|
49
55
|
},
|
|
50
56
|
async resolveId(id, from, opts) {
|
|
51
57
|
if (from) {
|
|
@@ -63,6 +69,9 @@ function astro({ config, logging }) {
|
|
|
63
69
|
if (query.type === "style" && isBrowserPath(id)) {
|
|
64
70
|
return relativeToRoot(id);
|
|
65
71
|
}
|
|
72
|
+
if (isFullFilePath(id)) {
|
|
73
|
+
return viteID(new URL("file://" + id));
|
|
74
|
+
}
|
|
66
75
|
return id;
|
|
67
76
|
}
|
|
68
77
|
},
|
|
@@ -86,10 +95,7 @@ function astro({ config, logging }) {
|
|
|
86
95
|
filename,
|
|
87
96
|
moduleId: id,
|
|
88
97
|
source,
|
|
89
|
-
|
|
90
|
-
transformStyleWithVite,
|
|
91
|
-
viteDevServer,
|
|
92
|
-
pluginContext: this
|
|
98
|
+
transformStyle: createTransformStyles(styleTransformer, filename, Boolean(opts == null ? void 0 : opts.ssr), this)
|
|
93
99
|
};
|
|
94
100
|
switch (query.type) {
|
|
95
101
|
case "style": {
|
|
@@ -163,7 +169,7 @@ File: ${filename}`
|
|
|
163
169
|
}
|
|
164
170
|
},
|
|
165
171
|
async transform(source, id, opts) {
|
|
166
|
-
var _a
|
|
172
|
+
var _a;
|
|
167
173
|
const parsedId = parseAstroRequest(id);
|
|
168
174
|
const query = parsedId.query;
|
|
169
175
|
if (!id.endsWith(".astro") || query.astro) {
|
|
@@ -178,10 +184,7 @@ File: ${filename}`
|
|
|
178
184
|
filename,
|
|
179
185
|
moduleId: id,
|
|
180
186
|
source,
|
|
181
|
-
|
|
182
|
-
transformStyleWithVite,
|
|
183
|
-
viteDevServer,
|
|
184
|
-
pluginContext: this
|
|
187
|
+
transformStyle: createTransformStyles(styleTransformer, filename, Boolean(opts == null ? void 0 : opts.ssr), this)
|
|
185
188
|
};
|
|
186
189
|
try {
|
|
187
190
|
const transformResult = await cachedCompilation(compileProps);
|
|
@@ -203,16 +206,8 @@ const $$url = ${JSON.stringify(
|
|
|
203
206
|
)};export { $$file as file, $$url as url };
|
|
204
207
|
`;
|
|
205
208
|
if (!resolvedConfig.isProduction) {
|
|
206
|
-
const metadata = transformResult.code.split("$$createMetadata(")[1].split("});\n")[0];
|
|
207
|
-
const pattern = /specifier:\s*'([^']*)'/g;
|
|
208
|
-
const deps = /* @__PURE__ */ new Set();
|
|
209
|
-
let match;
|
|
210
|
-
while (match = (_b = pattern.exec(metadata)) == null ? void 0 : _b[1]) {
|
|
211
|
-
deps.add(match);
|
|
212
|
-
}
|
|
213
209
|
let i = 0;
|
|
214
210
|
while (i < transformResult.scripts.length) {
|
|
215
|
-
deps.add(`${id}?astro&type=script&index=${i}&lang.ts`);
|
|
216
211
|
SUFFIX += `import "${id}?astro&type=script&index=${i}&lang.ts";`;
|
|
217
212
|
i++;
|
|
218
213
|
}
|
|
@@ -288,10 +283,7 @@ ${source}
|
|
|
288
283
|
filename: context.file,
|
|
289
284
|
moduleId: context.file,
|
|
290
285
|
source: await context.read(),
|
|
291
|
-
|
|
292
|
-
transformStyleWithVite,
|
|
293
|
-
viteDevServer,
|
|
294
|
-
pluginContext: this
|
|
286
|
+
transformStyle: createTransformStyles(styleTransformer, context.file, true, this)
|
|
295
287
|
};
|
|
296
288
|
const compile = () => cachedCompilation(compileProps);
|
|
297
289
|
return handleHotUpdate.call(this, context, {
|
|
@@ -5,12 +5,13 @@ import fs from "fs";
|
|
|
5
5
|
import matter from "gray-matter";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import { pagesVirtualModuleId } from "../core/app/index.js";
|
|
8
|
+
import { cachedCompilation } from "../core/compile/index.js";
|
|
8
9
|
import { collectErrorMetadata } from "../core/errors.js";
|
|
9
|
-
import { cachedCompilation } from "../vite-plugin-astro/compile.js";
|
|
10
|
-
import {
|
|
11
|
-
createTransformStyleWithViteFn
|
|
12
|
-
} from "../vite-plugin-astro/styles.js";
|
|
13
10
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
11
|
+
import {
|
|
12
|
+
createTransformStyles,
|
|
13
|
+
createViteStyleTransformer
|
|
14
|
+
} from "../vite-style-transform/index.js";
|
|
14
15
|
const MARKDOWN_IMPORT_FLAG = "?mdImport";
|
|
15
16
|
const MARKDOWN_CONTENT_FLAG = "?content";
|
|
16
17
|
function safeMatter(source, id) {
|
|
@@ -43,13 +44,16 @@ function markdown({ config, logging }) {
|
|
|
43
44
|
}
|
|
44
45
|
return false;
|
|
45
46
|
}
|
|
46
|
-
let
|
|
47
|
+
let styleTransformer;
|
|
47
48
|
let viteDevServer;
|
|
48
49
|
return {
|
|
49
50
|
name: "astro:markdown",
|
|
50
51
|
enforce: "pre",
|
|
51
52
|
configResolved(_resolvedConfig) {
|
|
52
|
-
|
|
53
|
+
styleTransformer = createViteStyleTransformer(_resolvedConfig);
|
|
54
|
+
},
|
|
55
|
+
configureServer(server) {
|
|
56
|
+
styleTransformer.viteDevServer = server;
|
|
53
57
|
},
|
|
54
58
|
async resolveId(id, importer, options) {
|
|
55
59
|
if (id.endsWith(`.md${MARKDOWN_CONTENT_FLAG}`)) {
|
|
@@ -161,10 +165,12 @@ ${astroResult}
|
|
|
161
165
|
filename,
|
|
162
166
|
moduleId: id,
|
|
163
167
|
source: astroResult,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
transformStyle: createTransformStyles(
|
|
169
|
+
styleTransformer,
|
|
170
|
+
filename,
|
|
171
|
+
Boolean(opts == null ? void 0 : opts.ssr),
|
|
172
|
+
this
|
|
173
|
+
)
|
|
168
174
|
};
|
|
169
175
|
let transformResult = await cachedCompilation(compileProps);
|
|
170
176
|
let { code: tsResult } = transformResult;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PluginContext } from 'rollup';
|
|
2
|
+
import type { TransformStyle } from '../core/compile/index';
|
|
3
|
+
import { TransformStyleWithVite } from './transform-with-vite.js';
|
|
4
|
+
import type * as vite from 'vite';
|
|
5
|
+
export declare type ViteStyleTransformer = {
|
|
6
|
+
viteDevServer?: vite.ViteDevServer;
|
|
7
|
+
transformStyleWithVite: TransformStyleWithVite;
|
|
8
|
+
};
|
|
9
|
+
export declare function createViteStyleTransformer(viteConfig: vite.ResolvedConfig): ViteStyleTransformer;
|
|
10
|
+
export declare function createTransformStyles(viteStyleTransformer: ViteStyleTransformer, filename: string, ssr: boolean, pluginContext: PluginContext): TransformStyle;
|