astro 1.0.0 → 1.0.3

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.
@@ -255,10 +255,8 @@ async function parseAstroConfig(configURL) {
255
255
  return result;
256
256
  }
257
257
  const toIdent = (name) => {
258
- if (name.includes("-")) {
259
- return name.split("-")[0];
260
- }
261
- return name;
258
+ const ident = name.trim().replace(/[-_\.]?astro(?:js)?[-_\.]?/g, "").replace(/\.js/, "").replace(/(?:[\.\-\_\/]+)([a-zA-Z])/g, (_, w) => w.toUpperCase()).replace(/^[^a-zA-Z$_]+/, "");
259
+ return `${ident[0].toLowerCase()}${ident.slice(1)}`;
262
260
  };
263
261
  function createPrettyError(err) {
264
262
  err.message = `Astro could not update your astro.config.js file safely.
@@ -610,7 +608,7 @@ function parseIntegrationName(spec) {
610
608
  return { scope, name, tag };
611
609
  }
612
610
  async function askToContinue({ flags }) {
613
- if (flags.yes)
611
+ if (flags.yes || flags.y)
614
612
  return true;
615
613
  const response = await prompts({
616
614
  type: "confirm",
@@ -87,6 +87,9 @@ class App {
87
87
  });
88
88
  }
89
89
  }
90
+ if (routeData.route === "/404") {
91
+ defaultStatus = 404;
92
+ }
90
93
  let mod = __privateGet(this, _manifest).pageMap.get(routeData.component);
91
94
  if (routeData.type === "page") {
92
95
  let response = await __privateMethod(this, _renderPage, renderPage_fn).call(this, request, routeData, mod, defaultStatus);
@@ -19,10 +19,10 @@ function createRequestFromNodeRequest(req, body) {
19
19
  return request;
20
20
  }
21
21
  class NodeApp extends App {
22
- match(req) {
23
- return super.match(req instanceof Request ? req : createRequestFromNodeRequest(req));
22
+ match(req, opts = {}) {
23
+ return super.match(req instanceof Request ? req : createRequestFromNodeRequest(req), opts);
24
24
  }
25
- render(req) {
25
+ render(req, routeData) {
26
26
  if ("on" in req) {
27
27
  let body = Buffer.from([]);
28
28
  let reqBodyComplete = new Promise((resolve, reject) => {
@@ -37,10 +37,16 @@ class NodeApp extends App {
37
37
  });
38
38
  });
39
39
  return reqBodyComplete.then(() => {
40
- return super.render(req instanceof Request ? req : createRequestFromNodeRequest(req, body));
40
+ return super.render(
41
+ req instanceof Request ? req : createRequestFromNodeRequest(req, body),
42
+ routeData
43
+ );
41
44
  });
42
45
  }
43
- return super.render(req instanceof Request ? req : createRequestFromNodeRequest(req));
46
+ return super.render(
47
+ req instanceof Request ? req : createRequestFromNodeRequest(req),
48
+ routeData
49
+ );
44
50
  }
45
51
  }
46
52
  async function loadManifest(rootFolder) {
@@ -108,7 +108,7 @@ async function generatePage(opts, internals, pageData, ssrEntry, builtPaths) {
108
108
  const timeEnd = performance.now();
109
109
  const timeChange = getTimeStat(timeStart, timeEnd);
110
110
  const timeIncrease = `(+${timeChange})`;
111
- const filePath = getOutputFilename(opts.astroConfig, path);
111
+ const filePath = getOutputFilename(opts.astroConfig, path, pageData.route.type);
112
112
  const lineIcon = i === paths.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
113
113
  info(opts.logging, null, ` ${cyan(lineIcon)} ${dim(filePath)} ${dim(timeIncrease)}`);
114
114
  }
@@ -1,7 +1,6 @@
1
1
  import fs from "fs";
2
2
  import * as colors from "kleur/colors";
3
3
  import { performance } from "perf_hooks";
4
- import * as vite from "vite";
5
4
  import {
6
5
  runHookBuildDone,
7
6
  runHookBuildStart,
@@ -14,7 +13,6 @@ import { debug, info, levels, timerMessage } from "../logger/core.js";
14
13
  import { apply as applyPolyfill } from "../polyfill.js";
15
14
  import { RouteCache } from "../render/route-cache.js";
16
15
  import { createRouteManifest } from "../routing/index.js";
17
- import { createSafeError } from "../util.js";
18
16
  import { collectPagesData } from "./page-data.js";
19
17
  import { staticBuild } from "./static-build.js";
20
18
  import { getTimeStat } from "./util.js";
@@ -40,7 +38,6 @@ class AstroBuilder {
40
38
  debug("build", "Initial setup...");
41
39
  const { logging } = this;
42
40
  this.timer.init = performance.now();
43
- this.timer.viteStart = performance.now();
44
41
  this.config = await runHookConfigSetup({ config: this.config, command: "build" });
45
42
  this.manifest = createRouteManifest({ config: this.config }, this.logging);
46
43
  const viteConfig = await createVite(
@@ -55,15 +52,9 @@ class AstroBuilder {
55
52
  { astroConfig: this.config, logging, mode: "build" }
56
53
  );
57
54
  await runHookConfigDone({ config: this.config });
58
- const viteServer = await vite.createServer(viteConfig);
59
- debug("build", timerMessage("Vite started", this.timer.viteStart));
60
- return { viteConfig, viteServer };
55
+ return { viteConfig };
61
56
  }
62
- async build({
63
- viteConfig,
64
- viteServer
65
- }) {
66
- const { origin } = this;
57
+ async build({ viteConfig }) {
67
58
  const buildConfig = {
68
59
  client: new URL("./client/", this.config.outDir),
69
60
  server: new URL("./server/", this.config.outDir),
@@ -79,11 +70,7 @@ class AstroBuilder {
79
70
  const { assets, allPages } = await collectPagesData({
80
71
  astroConfig: this.config,
81
72
  logging: this.logging,
82
- manifest: this.manifest,
83
- origin,
84
- routeCache: this.routeCache,
85
- viteServer,
86
- ssr: this.config.output === "server"
73
+ manifest: this.manifest
87
74
  });
88
75
  debug("build", timerMessage("All pages loaded", this.timer.loadStart));
89
76
  const pageNames = [];
@@ -93,23 +80,18 @@ class AstroBuilder {
93
80
  "build",
94
81
  colors.dim(`Completed in ${getTimeStat(this.timer.init, performance.now())}.`)
95
82
  );
96
- try {
97
- await staticBuild({
98
- allPages,
99
- astroConfig: this.config,
100
- logging: this.logging,
101
- manifest: this.manifest,
102
- mode: this.mode,
103
- origin: this.origin,
104
- pageNames,
105
- routeCache: this.routeCache,
106
- viteConfig,
107
- buildConfig
108
- });
109
- } catch (err) {
110
- await viteServer.close();
111
- throw err;
112
- }
83
+ await staticBuild({
84
+ allPages,
85
+ astroConfig: this.config,
86
+ logging: this.logging,
87
+ manifest: this.manifest,
88
+ mode: this.mode,
89
+ origin: this.origin,
90
+ pageNames,
91
+ routeCache: this.routeCache,
92
+ viteConfig,
93
+ buildConfig
94
+ });
113
95
  this.timer.assetsStart = performance.now();
114
96
  Object.keys(assets).map((k) => {
115
97
  if (!assets[k])
@@ -120,7 +102,6 @@ class AstroBuilder {
120
102
  delete assets[k];
121
103
  });
122
104
  debug("build", timerMessage("Additional assets copied", this.timer.assetsStart));
123
- await viteServer.close();
124
105
  await runHookBuildDone({
125
106
  config: this.config,
126
107
  buildConfig,
@@ -141,7 +122,7 @@ class AstroBuilder {
141
122
  try {
142
123
  await this.build(setupData);
143
124
  } catch (_err) {
144
- throw fixViteErrorMessage(createSafeError(_err), setupData.viteServer);
125
+ throw fixViteErrorMessage(_err);
145
126
  }
146
127
  }
147
128
  async printStats({
@@ -46,7 +46,7 @@ async function dev(config, options) {
46
46
  https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
47
47
  })
48
48
  );
49
- const currentVersion = "1.0.0";
49
+ const currentVersion = "1.0.3";
50
50
  if (currentVersion.includes("-")) {
51
51
  warn(options.logging, null, msg.prerelease({ currentVersion }));
52
52
  }
@@ -17,7 +17,7 @@ function cleanErrorStack(stack) {
17
17
  function fixViteErrorMessage(_err, server, filePath) {
18
18
  var _a, _b;
19
19
  const err = createSafeError(_err);
20
- server.ssrFixStacktrace(err);
20
+ server == null ? void 0 : server.ssrFixStacktrace(err);
21
21
  if (err.message === "import.meta.glob() can only accept string literals.") {
22
22
  err.message = "Astro.glob() and import.meta.glob() can only accept string literals.";
23
23
  }
@@ -47,7 +47,7 @@ function devStart({
47
47
  https,
48
48
  site
49
49
  }) {
50
- const version = "1.0.0";
50
+ const version = "1.0.3";
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.0.0"}`
229
+ `v${"1.0.3"}`
230
230
  )} ${headline}`
231
231
  );
232
232
  }
@@ -1,7 +1,6 @@
1
1
  import { fileURLToPath } from "url";
2
- import { prependForwardSlash } from "../../../core/path.js";
3
2
  import { PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
4
- import { isPage } from "../../util.js";
3
+ import { isPage, resolveIdToUrl } from "../../util.js";
5
4
  import { render as coreRender } from "../core.js";
6
5
  import { collectMdMetadata } from "../util.js";
7
6
  import { getStylesForURL } from "./css.js";
@@ -54,7 +53,7 @@ async function render(renderers, mod, ssrOpts) {
54
53
  scripts.add({
55
54
  props: {
56
55
  type: "module",
57
- src: "/@id/astro/runtime/client/hmr.js"
56
+ src: await resolveIdToUrl(viteServer, "astro/runtime/client/hmr.js")
58
57
  },
59
58
  children: ""
60
59
  });
@@ -115,7 +114,7 @@ async function render(renderers, mod, ssrOpts) {
115
114
  if (s.startsWith("/@fs")) {
116
115
  return resolveClientDevPath(s);
117
116
  }
118
- return "/@id" + prependForwardSlash(s);
117
+ return await resolveIdToUrl(viteServer, s);
119
118
  },
120
119
  renderers,
121
120
  request,
@@ -2,6 +2,7 @@ import npath from "path";
2
2
  import { unwrapId } from "../../util.js";
3
3
  import { STYLE_EXTENSIONS } from "../util.js";
4
4
  const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ".md"]);
5
+ const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
5
6
  async function* crawlGraph(viteServer, _id, isFile, scanned = /* @__PURE__ */ new Set()) {
6
7
  const id = unwrapId(_id);
7
8
  const importedModules = /* @__PURE__ */ new Set();
@@ -15,11 +16,11 @@ async function* crawlGraph(viteServer, _id, isFile, scanned = /* @__PURE__ */ ne
15
16
  const entryIsStyle = STYLE_EXTENSIONS.has(npath.extname(id));
16
17
  for (const importedModule of entry.importedModules) {
17
18
  if (importedModule.id) {
18
- const { pathname } = new URL(`file://${importedModule.id}`);
19
- if (entryIsStyle && !STYLE_EXTENSIONS.has(npath.extname(pathname))) {
19
+ const importedModulePathname = importedModule.id.replace(STRIP_QUERY_PARAMS_REGEX, "");
20
+ if (entryIsStyle && !STYLE_EXTENSIONS.has(npath.extname(importedModulePathname))) {
20
21
  continue;
21
22
  }
22
- if (fileExtensionsToSSR.has(npath.extname(pathname))) {
23
+ if (fileExtensionsToSSR.has(npath.extname(importedModulePathname))) {
23
24
  const mod = viteServer.moduleGraph.getModuleById(importedModule.id);
24
25
  if (!(mod == null ? void 0 : mod.ssrModule)) {
25
26
  await viteServer.ssrLoadModule(importedModule.id);
package/dist/core/util.js CHANGED
@@ -4,8 +4,8 @@ import path from "path";
4
4
  import resolve from "resolve";
5
5
  import slash from "slash";
6
6
  import { fileURLToPath, pathToFileURL } from "url";
7
- import { removeTrailingForwardSlash } from "./path.js";
8
- const ASTRO_VERSION = "1.0.0";
7
+ import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
8
+ const ASTRO_VERSION = "1.0.3";
9
9
  function isObject(value) {
10
10
  return typeof value === "object" && value != null;
11
11
  }
@@ -18,7 +18,10 @@ function padMultilineString(source, n = 2) {
18
18
  `);
19
19
  }
20
20
  const STATUS_CODE_REGEXP = /^\/?[0-9]{3}$/;
21
- function getOutputFilename(astroConfig, name) {
21
+ function getOutputFilename(astroConfig, name, type) {
22
+ if (type === "endpoint") {
23
+ return name;
24
+ }
22
25
  if (name === "/" || name === "") {
23
26
  return path.posix.join(name, "index.html");
24
27
  }
@@ -157,6 +160,16 @@ function getLocalAddress(serverAddress, host) {
157
160
  return serverAddress;
158
161
  }
159
162
  }
163
+ async function resolveIdToUrl(viteServer, id) {
164
+ const result = await viteServer.pluginContainer.resolveId(id);
165
+ if (!result) {
166
+ return VALID_ID_PREFIX + id;
167
+ }
168
+ if (path.isAbsolute(result.id)) {
169
+ return "/@fs" + prependForwardSlash(result.id);
170
+ }
171
+ return VALID_ID_PREFIX + result.id;
172
+ }
160
173
  export {
161
174
  ASTRO_VERSION,
162
175
  VALID_ID_PREFIX,
@@ -175,6 +188,7 @@ export {
175
188
  relativeToSrcDir,
176
189
  removeDir,
177
190
  resolveDependency,
191
+ resolveIdToUrl,
178
192
  resolvePages,
179
193
  unwrapId,
180
194
  viteID
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.0.0";
1
+ const ASTRO_VERSION = "1.0.3";
2
2
  function createDeprecatedFetchContentFn() {
3
3
  return () => {
4
4
  throw new Error("Deprecated: Astro.fetchContent() has been replaced with Astro.glob().");
@@ -67,7 +67,7 @@ function extractDirectives(inputProps) {
67
67
  return extracted;
68
68
  }
69
69
  async function generateHydrateScript(scriptOptions, metadata) {
70
- const { renderer, result, astroId, props } = scriptOptions;
70
+ const { renderer, result, astroId, props, attrs } = scriptOptions;
71
71
  const { hydrate, componentUrl, componentExport } = metadata;
72
72
  if (!componentExport) {
73
73
  throw new Error(
@@ -80,6 +80,11 @@ async function generateHydrateScript(scriptOptions, metadata) {
80
80
  uid: astroId
81
81
  }
82
82
  };
83
+ if (attrs) {
84
+ for (const [key, value] of Object.entries(attrs)) {
85
+ island.props[key] = value;
86
+ }
87
+ }
83
88
  island.props["component-url"] = await result.resolve(componentUrl);
84
89
  if (renderer.clientEntrypoint) {
85
90
  island.props["component-export"] = componentExport.value;
@@ -77,6 +77,7 @@ Did you forget to import the component or is it possible there is a typo?`
77
77
  const metadata = { displayName };
78
78
  const { hydration, isPage, props } = extractDirectives(_props);
79
79
  let html = "";
80
+ let attrs = void 0;
80
81
  if (hydration) {
81
82
  metadata.hydrate = hydration.directive;
82
83
  metadata.hydrateArgs = hydration.value;
@@ -164,7 +165,7 @@ but ${plural ? "none were" : "it was not"} able to server-side render ${metadata
164
165
  Did you mean to enable ${formatList(probableRendererNames.map((r) => "`" + r + "`"))}?`);
165
166
  } else if (matchingRenderers.length === 1) {
166
167
  renderer = matchingRenderers[0];
167
- ({ html } = await renderer.ssr.renderToStaticMarkup.call(
168
+ ({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
168
169
  { result },
169
170
  Component,
170
171
  props,
@@ -189,7 +190,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
189
190
  if (metadata.hydrate === "only") {
190
191
  html = await renderSlot(result, slots == null ? void 0 : slots.fallback);
191
192
  } else {
192
- ({ html } = await renderer.ssr.renderToStaticMarkup.call(
193
+ ({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
193
194
  { result },
194
195
  Component,
195
196
  props,
@@ -229,7 +230,7 @@ ${serializeProps(
229
230
  )}`
230
231
  );
231
232
  const island = await generateHydrateScript(
232
- { renderer, result, astroId, props },
233
+ { renderer, result, astroId, props, attrs },
233
234
  metadata
234
235
  );
235
236
  let unrenderedSlots = [];
@@ -917,6 +917,7 @@ export interface SSRLoadedRenderer extends AstroRenderer {
917
917
  check: AsyncRendererComponentFn<boolean>;
918
918
  renderToStaticMarkup: AsyncRendererComponentFn<{
919
919
  html: string;
920
+ attrs?: Record<string, string>;
920
921
  }>;
921
922
  };
922
923
  }
@@ -1,10 +1,11 @@
1
1
  /// <reference types="node" />
2
+ import type { RouteData } from '../../@types/astro';
2
3
  import type { SSRManifest } from './types';
3
4
  import { IncomingMessage } from 'http';
4
- import { App } from './index.js';
5
+ import { App, MatchOptions } from './index.js';
5
6
  export declare class NodeApp extends App {
6
- match(req: IncomingMessage | Request): import("../../@types/astro").RouteData | undefined;
7
- render(req: IncomingMessage | Request): Promise<Response>;
7
+ match(req: IncomingMessage | Request, opts?: MatchOptions): RouteData | undefined;
8
+ render(req: IncomingMessage | Request, routeData?: RouteData): Promise<Response>;
8
9
  }
9
10
  export declare function loadManifest(rootFolder: URL): Promise<SSRManifest>;
10
11
  export declare function loadApp(rootFolder: URL): Promise<NodeApp>;
@@ -1,16 +1,10 @@
1
- import type { ViteDevServer } from 'vite';
2
1
  import type { AstroConfig, ManifestData } from '../../@types/astro';
3
2
  import type { LogOptions } from '../logger/core';
4
3
  import type { AllPagesData } from './types';
5
- import { RouteCache } from '../render/route-cache.js';
6
4
  export interface CollectPagesDataOptions {
7
5
  astroConfig: AstroConfig;
8
6
  logging: LogOptions;
9
7
  manifest: ManifestData;
10
- origin: string;
11
- routeCache: RouteCache;
12
- viteServer: ViteDevServer;
13
- ssr: boolean;
14
8
  }
15
9
  export interface CollectPagesDataResult {
16
10
  assets: Record<string, string>;
@@ -22,8 +22,11 @@ export interface ErrorWithMetadata {
22
22
  };
23
23
  }
24
24
  export declare function cleanErrorStack(stack: string): string;
25
- /** Update the error message to correct any vite-isms that we don't want to expose to the user. */
26
- export declare function fixViteErrorMessage(_err: unknown, server: ViteDevServer, filePath?: URL): Error;
25
+ /**
26
+ * Update the error message to correct any vite-isms that we don't want to expose to the user.
27
+ * The `server` is required if the error may come from `server.ssrLoadModule()`.
28
+ */
29
+ export declare function fixViteErrorMessage(_err: unknown, server?: ViteDevServer, filePath?: URL): Error;
27
30
  export declare function createCustomViteLogger(logLevel: LogLevel): Logger;
28
31
  /**
29
32
  * Takes any error-like object and returns a standardized Error + metadata object.
@@ -1,5 +1,5 @@
1
- import type { ErrorPayload } from 'vite';
2
- import type { AstroConfig } from '../@types/astro';
1
+ import type { ErrorPayload, ViteDevServer } from 'vite';
2
+ import type { AstroConfig, RouteType } from '../@types/astro';
3
3
  export declare const ASTRO_VERSION: string;
4
4
  /** Returns true if argument is an object of any prototype/class (but not null). */
5
5
  export declare function isObject(value: unknown): value is Record<string, any>;
@@ -11,7 +11,7 @@ export declare function padMultilineString(source: string, n?: number): string;
11
11
  * Handles both "/foo" and "foo" `name` formats.
12
12
  * Handles `/404` and `/` correctly.
13
13
  */
14
- export declare function getOutputFilename(astroConfig: AstroConfig, name: string): string;
14
+ export declare function getOutputFilename(astroConfig: AstroConfig, name: string, type: RouteType): string;
15
15
  /** is a specifier an npm package? */
16
16
  export declare function parseNpmName(spec: string): {
17
17
  scope?: string;
@@ -41,3 +41,8 @@ export declare function isModeServerWithNoAdapter(config: AstroConfig): boolean;
41
41
  export declare function relativeToSrcDir(config: AstroConfig, idOrUrl: URL | string): string;
42
42
  export declare function emoji(char: string, fallback: string): string;
43
43
  export declare function getLocalAddress(serverAddress: string, host: string | boolean): string;
44
+ /**
45
+ * Simulate Vite's resolve and import analysis so we can import the id as an URL
46
+ * through a script tag or a dynamic import as-is.
47
+ */
48
+ export declare function resolveIdToUrl(viteServer: ViteDevServer, id: string): Promise<string>;
@@ -19,6 +19,7 @@ interface HydrateScriptOptions {
19
19
  result: SSRResult;
20
20
  astroId: string;
21
21
  props: Record<string | number, any>;
22
+ attrs: Record<string, string> | undefined;
22
23
  }
23
24
  /** For hydrated components, generate a <script type="module"> to load the component */
24
25
  export declare function generateHydrateScript(scriptOptions: HydrateScriptOptions, metadata: Required<AstroComponentMetadata>): Promise<SSRElement>;
@@ -11,3 +11,4 @@ export interface ParsedRequestResult {
11
11
  query: AstroQuery;
12
12
  }
13
13
  export declare function parseAstroRequest(id: string): ParsedRequestResult;
14
+ export declare function isAstroScript(id: string): boolean;
@@ -2,6 +2,7 @@ import { fileURLToPath } from "node:url";
2
2
  import { info } from "../core/logger/core.js";
3
3
  import * as msg from "../core/messages.js";
4
4
  import { invalidateCompilation, isCached } from "./compile.js";
5
+ import { isAstroScript } from "./query.js";
5
6
  async function trackCSSDependencies(opts) {
6
7
  const { viteDevServer, filename, deps, id } = opts;
7
8
  if (viteDevServer) {
@@ -29,7 +30,6 @@ const isPkgFile = (id) => {
29
30
  return (id == null ? void 0 : id.startsWith(fileURLToPath(PKG_PREFIX))) || (id == null ? void 0 : id.startsWith(PKG_PREFIX.pathname));
30
31
  };
31
32
  async function handleHotUpdate(ctx, { config, logging, compile }) {
32
- var _a;
33
33
  let isStyleOnlyChange = false;
34
34
  if (ctx.file.endsWith(".astro")) {
35
35
  const oldResult = await compile();
@@ -81,17 +81,25 @@ async function handleHotUpdate(ctx, { config, logging, compile }) {
81
81
  if (isStyleOnlyChange) {
82
82
  info(logging, "astro", msg.hmr({ file, style: true }));
83
83
  return mods.filter((mod) => {
84
- var _a2;
85
- return mod.id !== ctx.file && !((_a2 = mod.id) == null ? void 0 : _a2.endsWith(".ts"));
84
+ var _a;
85
+ return mod.id !== ctx.file && !((_a = mod.id) == null ? void 0 : _a.endsWith(".ts"));
86
86
  });
87
87
  }
88
88
  for (const mod of mods) {
89
89
  for (const imp of mod.importedModules) {
90
- if ((_a = imp.id) == null ? void 0 : _a.includes("?astro&type=script")) {
90
+ if (imp.id && isAstroScript(imp.id)) {
91
91
  mods.push(imp);
92
92
  }
93
93
  }
94
94
  }
95
+ for (const mod of filtered) {
96
+ if (mod.id && isAstroScript(mod.id) && mod.file) {
97
+ const astroMod = ctx.server.moduleGraph.getModuleById(mod.file);
98
+ if (astroMod) {
99
+ mods.unshift(astroMod);
100
+ }
101
+ }
102
+ }
95
103
  const isSelfAccepting = mods.every((m) => m.isSelfAccepting || m.url.endsWith(".svelte"));
96
104
  if (isSelfAccepting) {
97
105
  info(logging, "astro", msg.hmr({ file }));
@@ -294,7 +294,11 @@ ${source}
294
294
  pluginContext: this
295
295
  };
296
296
  const compile = () => cachedCompilation(compileProps);
297
- return handleHotUpdate.call(this, context, { config, logging, compile });
297
+ return handleHotUpdate.call(this, context, {
298
+ config,
299
+ logging,
300
+ compile
301
+ });
298
302
  }
299
303
  };
300
304
  }
@@ -18,6 +18,11 @@ function parseAstroRequest(id) {
18
18
  query
19
19
  };
20
20
  }
21
+ function isAstroScript(id) {
22
+ const parsed = parseAstroRequest(id);
23
+ return parsed.query.type === "script";
24
+ }
21
25
  export {
26
+ isAstroScript,
22
27
  parseAstroRequest
23
28
  };
@@ -73,8 +73,26 @@ function markdown({ config, logging }) {
73
73
  throw new Error('The "astro" property is no longer supported! To access "headings" from your layout, try using "Astro.props.headings."')
74
74
  }
75
75
  });
76
+ Object.defineProperty(content.astro, 'html', {
77
+ get() {
78
+ throw new Error('The "astro" property is no longer supported! To access "html" from your layout, try using "Astro.props.compiledContent()."')
79
+ }
80
+ });
81
+ Object.defineProperty(content.astro, 'source', {
82
+ get() {
83
+ throw new Error('The "astro" property is no longer supported! To access "source" from your layout, try using "Astro.props.rawContent()."')
84
+ }
85
+ });
76
86
  const contentFragment = h(Fragment, { 'set:html': html });
77
- return ${layout ? `h(Layout, { content, frontmatter: content, headings: getHeadings(), 'server:root': true, children: contentFragment })` : `contentFragment`};
87
+ return ${layout ? `h(Layout, {
88
+ content,
89
+ frontmatter: content,
90
+ headings: getHeadings(),
91
+ rawContent,
92
+ compiledContent,
93
+ 'server:root': true,
94
+ children: contentFragment
95
+ })` : `contentFragment`};
78
96
  }
79
97
  export default Content;
80
98
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
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",
@@ -126,7 +126,7 @@
126
126
  "tsconfig-resolver": "^3.0.1",
127
127
  "unist-util-visit": "^4.1.0",
128
128
  "vfile": "^5.3.2",
129
- "vite": "3.0.4",
129
+ "vite": "3.0.5",
130
130
  "yargs-parser": "^21.0.1",
131
131
  "zod": "^3.17.3"
132
132
  },