astro 1.0.2 → 1.0.5

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/cli/index.js CHANGED
@@ -20,7 +20,7 @@ function printAstroHelp() {
20
20
  printHelp({
21
21
  commandName: "astro",
22
22
  usage: "[command] [...flags]",
23
- headline: "Futuristic web development tool.",
23
+ headline: "Build faster websites.",
24
24
  tables: {
25
25
  Commands: [
26
26
  ["add", "Add an integration."],
@@ -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.
@@ -328,6 +326,24 @@ async function setAdapter(ast, adapter, exportName) {
328
326
  const configObject = path2.node.declaration.arguments[0];
329
327
  if (!t.isObjectExpression(configObject))
330
328
  return;
329
+ let outputProp = configObject.properties.find((prop) => {
330
+ if (prop.type !== "ObjectProperty")
331
+ return false;
332
+ if (prop.key.type === "Identifier") {
333
+ if (prop.key.name === "output")
334
+ return true;
335
+ }
336
+ if (prop.key.type === "StringLiteral") {
337
+ if (prop.key.value === "output")
338
+ return true;
339
+ }
340
+ return false;
341
+ });
342
+ if (!outputProp) {
343
+ configObject.properties.push(
344
+ t.objectProperty(t.identifier("output"), t.stringLiteral("server"))
345
+ );
346
+ }
331
347
  let adapterProp = configObject.properties.find((prop) => {
332
348
  if (prop.type !== "ObjectProperty")
333
349
  return false;
@@ -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
  }
@@ -157,7 +157,7 @@ async function getPathsForRoute(pageData, mod, opts, builtPaths) {
157
157
  return paths;
158
158
  }
159
159
  function addPageName(pathname, opts) {
160
- opts.pageNames.push(pathname.replace(/\/?$/, "/").replace(/^\//, ""));
160
+ opts.pageNames.push(pathname.replace(/^\//, ""));
161
161
  }
162
162
  async function generatePath(pathname, opts, gopts) {
163
163
  var _a;
@@ -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.2";
49
+ const currentVersion = "1.0.5";
50
50
  if (currentVersion.includes("-")) {
51
51
  warn(options.logging, null, msg.prerelease({ currentVersion }));
52
52
  }
@@ -47,7 +47,7 @@ function devStart({
47
47
  https,
48
48
  site
49
49
  }) {
50
- const version = "1.0.2";
50
+ const version = "1.0.5";
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.2"}`
229
+ `v${"1.0.5"}`
230
230
  )} ${headline}`
231
231
  );
232
232
  }
@@ -9,6 +9,11 @@ import * as msg from "../messages.js";
9
9
  import { getResolvedHostForHttpServer } from "./util.js";
10
10
  const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
11
11
  async function preview(config, { logging }) {
12
+ if (config.output === "server") {
13
+ throw new Error(
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
+ );
16
+ }
12
17
  const startServerTime = performance.now();
13
18
  const defaultOrigin = "http://localhost";
14
19
  const trailingSlash = config.trailingSlash;
@@ -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);
@@ -6,7 +6,10 @@ function getRouteGenerator(segments, addTrailingSlash) {
6
6
  return part.dynamic ? `:${part.content}` : part.content.normalize().replace(/\?/g, "%3F").replace(/#/g, "%23").replace(/%5B/g, "[").replace(/%5D/g, "]").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7
7
  }).join("");
8
8
  }).join("");
9
- const trailing = addTrailingSlash !== "never" && segments.length ? "/" : "";
9
+ let trailing = "";
10
+ if (addTrailingSlash === "always" && segments.length) {
11
+ trailing = "/";
12
+ }
10
13
  const toPath = compile(template + trailing);
11
14
  return toPath;
12
15
  }
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.0.2";
8
+ const ASTRO_VERSION = "1.0.5";
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
  }
package/dist/jsx/babel.js CHANGED
@@ -52,7 +52,7 @@ function addClientMetadata(node, meta) {
52
52
  }
53
53
  if (!existingAttributes.find((attr) => attr === "client:component-export")) {
54
54
  if (meta.name === "*") {
55
- meta.name = getTagName(node).split(".").at(1);
55
+ meta.name = getTagName(node).split(".").slice(1).join(".");
56
56
  }
57
57
  const componentExport = t.jsxAttribute(
58
58
  t.jsxNamespacedName(t.jsxIdentifier("client"), t.jsxIdentifier("component-export")),
@@ -157,6 +157,74 @@ function astroJSX() {
157
157
  }
158
158
  state.set("imports", imports);
159
159
  },
160
+ JSXMemberExpression(path, state) {
161
+ var _a;
162
+ const node = path.node;
163
+ if (((_a = state.filename) == null ? void 0 : _a.endsWith(".mdx")) && t.isJSXIdentifier(node.object) && node.object.name === "_components") {
164
+ return;
165
+ }
166
+ const parent = path.findParent((n) => t.isJSXElement(n));
167
+ const parentNode = parent.node;
168
+ const tagName = getTagName(parentNode);
169
+ if (!isComponent(tagName))
170
+ return;
171
+ if (!hasClientDirective(parentNode))
172
+ return;
173
+ const isClientOnly = isClientOnlyComponent(parentNode);
174
+ if (tagName === ClientOnlyPlaceholder)
175
+ return;
176
+ const imports = state.get("imports") ?? /* @__PURE__ */ new Map();
177
+ const namespace = tagName.split(".");
178
+ for (const [source, specs] of imports) {
179
+ for (const { imported, local } of specs) {
180
+ const reference = path.referencesImport(source, imported);
181
+ if (reference) {
182
+ path.setData("import", { name: imported, path: source });
183
+ break;
184
+ }
185
+ if (namespace.at(0) === local) {
186
+ path.setData("import", { name: imported, path: source });
187
+ break;
188
+ }
189
+ }
190
+ }
191
+ const meta = path.getData("import");
192
+ if (meta) {
193
+ let resolvedPath;
194
+ if (meta.path.startsWith(".")) {
195
+ const fileURL = pathToFileURL(state.filename);
196
+ resolvedPath = `/@fs${new URL(meta.path, fileURL).pathname}`;
197
+ if (resolvedPath.endsWith(".jsx")) {
198
+ resolvedPath = resolvedPath.slice(0, -4);
199
+ }
200
+ } else {
201
+ resolvedPath = meta.path;
202
+ }
203
+ if (isClientOnly) {
204
+ state.file.metadata.astro.clientOnlyComponents.push({
205
+ exportName: meta.name,
206
+ specifier: tagName,
207
+ resolvedPath
208
+ });
209
+ meta.resolvedPath = resolvedPath;
210
+ addClientOnlyMetadata(parentNode, meta);
211
+ } else {
212
+ state.file.metadata.astro.hydratedComponents.push({
213
+ exportName: "*",
214
+ specifier: tagName,
215
+ resolvedPath
216
+ });
217
+ meta.resolvedPath = resolvedPath;
218
+ addClientMetadata(parentNode, meta);
219
+ }
220
+ } else {
221
+ throw new Error(
222
+ `Unable to match <${getTagName(
223
+ parentNode
224
+ )}> with client:* directive to an import statement!`
225
+ );
226
+ }
227
+ },
160
228
  JSXIdentifier(path, state) {
161
229
  const isAttr = path.findParent((n) => t.isJSXAttribute(n));
162
230
  if (isAttr)
@@ -1,14 +1,4 @@
1
- var idle_prebuilt_default = `(self.Astro = self.Astro || {}).idle = (getHydrateCallback) => {
2
- const cb = async () => {
3
- let hydrate = await getHydrateCallback();
4
- await hydrate();
5
- };
6
- if ("requestIdleCallback" in window) {
7
- window.requestIdleCallback(cb);
8
- } else {
9
- setTimeout(cb, 200);
10
- }
11
- };`;
1
+ var idle_prebuilt_default = `(self.Astro=self.Astro||{}).idle=a=>{const e=async()=>{await(await a())()};"requestIdleCallback"in window?window.requestIdleCallback(e):setTimeout(e,200)};`;
12
2
  export {
13
3
  idle_prebuilt_default as default
14
4
  };
@@ -1,9 +1,4 @@
1
- var load_prebuilt_default = `(self.Astro = self.Astro || {}).load = (getHydrateCallback) => {
2
- (async () => {
3
- let hydrate = await getHydrateCallback();
4
- await hydrate();
5
- })();
6
- };`;
1
+ var load_prebuilt_default = `(self.Astro=self.Astro||{}).load=a=>{(async()=>await(await a())())()};`;
7
2
  export {
8
3
  load_prebuilt_default as default
9
4
  };
@@ -1,17 +1,4 @@
1
- var media_prebuilt_default = `(self.Astro = self.Astro || {}).media = (getHydrateCallback, options) => {
2
- const cb = async () => {
3
- let hydrate = await getHydrateCallback();
4
- await hydrate();
5
- };
6
- if (options.value) {
7
- const mql = matchMedia(options.value);
8
- if (mql.matches) {
9
- cb();
10
- } else {
11
- mql.addEventListener("change", cb, { once: true });
12
- }
13
- }
14
- };`;
1
+ var media_prebuilt_default = `(self.Astro=self.Astro||{}).media=(s,a)=>{const t=async()=>{await(await s())()};if(a.value){const e=matchMedia(a.value);e.matches?t():e.addEventListener("change",t,{once:!0})}};`;
15
2
  export {
16
3
  media_prebuilt_default as default
17
4
  };
@@ -1,9 +1,4 @@
1
- var only_prebuilt_default = `(self.Astro = self.Astro || {}).only = (getHydrateCallback) => {
2
- (async () => {
3
- let hydrate = await getHydrateCallback();
4
- await hydrate();
5
- })();
6
- };`;
1
+ var only_prebuilt_default = `(self.Astro=self.Astro||{}).only=a=>{(async()=>await(await a())())()};`;
7
2
  export {
8
3
  only_prebuilt_default as default
9
4
  };
@@ -1,22 +1,4 @@
1
- var visible_prebuilt_default = `(self.Astro = self.Astro || {}).visible = (getHydrateCallback, _opts, root) => {
2
- const cb = async () => {
3
- let hydrate = await getHydrateCallback();
4
- await hydrate();
5
- };
6
- let io = new IntersectionObserver((entries) => {
7
- for (const entry of entries) {
8
- if (!entry.isIntersecting)
9
- continue;
10
- io.disconnect();
11
- cb();
12
- break;
13
- }
14
- });
15
- for (let i = 0; i < root.children.length; i++) {
16
- const child = root.children[i];
17
- io.observe(child);
18
- }
19
- };`;
1
+ var visible_prebuilt_default = `(self.Astro=self.Astro||{}).visible=(i,c,n)=>{const r=async()=>{await(await i())()};let s=new IntersectionObserver(e=>{for(const t of e)if(!!t.isIntersecting){s.disconnect(),r();break}});for(let e=0;e<n.children.length;e++){const t=n.children[e];s.observe(t)}};`;
20
2
  export {
21
3
  visible_prebuilt_default as default
22
4
  };
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.0.2";
1
+ const ASTRO_VERSION = "1.0.5";
2
2
  function createDeprecatedFetchContentFn() {
3
3
  return () => {
4
4
  throw new Error("Deprecated: Astro.fetchContent() has been replaced with Astro.glob().");
@@ -72,7 +72,15 @@ var _a;
72
72
  rendererUrl ? import(rendererUrl) : () => () => {
73
73
  }
74
74
  ]);
75
- this.Component = componentModule[this.getAttribute("component-export") || "default"];
75
+ const componentExport = this.getAttribute("component-export") || "default";
76
+ if (!componentExport.includes(".")) {
77
+ this.Component = componentModule[componentExport];
78
+ } else {
79
+ this.Component = componentModule;
80
+ for (const part of componentExport.split(".")) {
81
+ this.Component = this.Component[part];
82
+ }
83
+ }
76
84
  this.hydrator = hydrator;
77
85
  return this.hydrate;
78
86
  },
@@ -1,92 +1,4 @@
1
- var astro_island_prebuilt_default = `var _a;
2
- {
3
- const propTypes = {
4
- 0: (value) => value,
5
- 1: (value) => JSON.parse(value, reviver),
6
- 2: (value) => new RegExp(value),
7
- 3: (value) => new Date(value),
8
- 4: (value) => new Map(JSON.parse(value, reviver)),
9
- 5: (value) => new Set(JSON.parse(value, reviver)),
10
- 6: (value) => BigInt(value),
11
- 7: (value) => new URL(value)
12
- };
13
- const reviver = (propKey, raw) => {
14
- if (propKey === "" || !Array.isArray(raw))
15
- return raw;
16
- const [type, value] = raw;
17
- return type in propTypes ? propTypes[type](value) : void 0;
18
- };
19
- if (!customElements.get("astro-island")) {
20
- customElements.define(
21
- "astro-island",
22
- (_a = class extends HTMLElement {
23
- constructor() {
24
- super(...arguments);
25
- this.hydrate = () => {
26
- if (!this.hydrator || this.parentElement?.closest("astro-island[ssr]")) {
27
- return;
28
- }
29
- const slotted = this.querySelectorAll("astro-slot");
30
- const slots = {};
31
- const templates = this.querySelectorAll("template[data-astro-template]");
32
- for (const template of templates) {
33
- if (!template.closest(this.tagName)?.isSameNode(this))
34
- continue;
35
- slots[template.getAttribute("data-astro-template") || "default"] = template.innerHTML;
36
- template.remove();
37
- }
38
- for (const slot of slotted) {
39
- if (!slot.closest(this.tagName)?.isSameNode(this))
40
- continue;
41
- slots[slot.getAttribute("name") || "default"] = slot.innerHTML;
42
- }
43
- const props = this.hasAttribute("props") ? JSON.parse(this.getAttribute("props"), reviver) : {};
44
- this.hydrator(this)(this.Component, props, slots, {
45
- client: this.getAttribute("client")
46
- });
47
- this.removeAttribute("ssr");
48
- window.removeEventListener("astro:hydrate", this.hydrate);
49
- window.dispatchEvent(new CustomEvent("astro:hydrate"));
50
- };
51
- }
52
- connectedCallback() {
53
- if (!this.hasAttribute("await-children") || this.firstChild) {
54
- this.childrenConnectedCallback();
55
- } else {
56
- new MutationObserver((_, mo) => {
57
- mo.disconnect();
58
- this.childrenConnectedCallback();
59
- }).observe(this, { childList: true });
60
- }
61
- }
62
- async childrenConnectedCallback() {
63
- window.addEventListener("astro:hydrate", this.hydrate);
64
- await import(this.getAttribute("before-hydration-url"));
65
- const opts = JSON.parse(this.getAttribute("opts"));
66
- Astro[this.getAttribute("client")](
67
- async () => {
68
- const rendererUrl = this.getAttribute("renderer-url");
69
- const [componentModule, { default: hydrator }] = await Promise.all([
70
- import(this.getAttribute("component-url")),
71
- rendererUrl ? import(rendererUrl) : () => () => {
72
- }
73
- ]);
74
- this.Component = componentModule[this.getAttribute("component-export") || "default"];
75
- this.hydrator = hydrator;
76
- return this.hydrate;
77
- },
78
- opts,
79
- this
80
- );
81
- }
82
- attributeChangedCallback() {
83
- if (this.hydrator)
84
- this.hydrate();
85
- }
86
- }, _a.observedAttributes = ["props"], _a)
87
- );
88
- }
89
- }`;
1
+ var astro_island_prebuilt_default = `var a;{const l={0:t=>t,1:t=>JSON.parse(t,n),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,n)),5:t=>new Set(JSON.parse(t,n)),6:t=>BigInt(t),7:t=>new URL(t)},n=(t,r)=>{if(t===""||!Array.isArray(r))return r;const[s,i]=r;return s in l?l[s](i):void 0};customElements.get("astro-island")||customElements.define("astro-island",(a=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement?.closest("astro-island[ssr]"))return;const r=this.querySelectorAll("astro-slot"),s={},i=this.querySelectorAll("template[data-astro-template]");for(const e of i)!e.closest(this.tagName)?.isSameNode(this)||(s[e.getAttribute("data-astro-template")||"default"]=e.innerHTML,e.remove());for(const e of r)!e.closest(this.tagName)?.isSameNode(this)||(s[e.getAttribute("name")||"default"]=e.innerHTML);const o=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),n):{};this.hydrator(this)(this.Component,o,s,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),window.removeEventListener("astro:hydrate",this.hydrate),window.dispatchEvent(new CustomEvent("astro:hydrate"))}}connectedCallback(){!this.hasAttribute("await-children")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((r,s)=>{s.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener("astro:hydrate",this.hydrate),await import(this.getAttribute("before-hydration-url"));const r=JSON.parse(this.getAttribute("opts"));Astro[this.getAttribute("client")](async()=>{const s=this.getAttribute("renderer-url"),[i,{default:o}]=await Promise.all([import(this.getAttribute("component-url")),s?import(s):()=>()=>{}]),e=this.getAttribute("component-export")||"default";if(!e.includes("."))this.Component=i[e];else{this.Component=i;for(const c of e.split("."))this.Component=this.Component[c]}return this.hydrator=o,this.hydrate},r,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},a.observedAttributes=["props"],a))}`;
90
2
  export {
91
3
  astro_island_prebuilt_default as default
92
4
  };
@@ -69,9 +69,9 @@ function extractDirectives(inputProps) {
69
69
  async function generateHydrateScript(scriptOptions, metadata) {
70
70
  const { renderer, result, astroId, props, attrs } = scriptOptions;
71
71
  const { hydrate, componentUrl, componentExport } = metadata;
72
- if (!componentExport) {
72
+ if (!componentExport.value) {
73
73
  throw new Error(
74
- `Unable to resolve a componentExport for "${metadata.displayName}"! Please open an issue.`
74
+ `Unable to resolve a valid export for "${metadata.displayName}"! Please open an issue at https://astro.build/issues!`
75
75
  );
76
76
  }
77
77
  const island = {
@@ -216,7 +216,7 @@ export interface AstroGlobalPartial {
216
216
  */
217
217
  glob(globStr: `${any}.astro`): Promise<AstroInstance[]>;
218
218
  glob<T extends Record<string, any>>(globStr: `${any}.md`): Promise<MarkdownInstance<T>[]>;
219
- glob<T extends Record<string, any>>(globStr: `${any}.mdx`): Promise<MarkdownInstance<T>[]>;
219
+ glob<T extends Record<string, any>>(globStr: `${any}.mdx`): Promise<MDXInstance<T>[]>;
220
220
  glob<T extends Record<string, any>>(globStr: string): Promise<T[]>;
221
221
  /**
222
222
  * Returns a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object built from the [site](https://docs.astro.build/en/reference/configuration-reference/#site) config option
@@ -782,6 +782,25 @@ export interface MarkdownInstance<T extends Record<string, any>> {
782
782
  default: AstroComponentFactory;
783
783
  }>;
784
784
  }
785
+ export interface MDXInstance<T> extends Omit<MarkdownInstance<T>, 'rawContent' | 'compiledContent' | 'Content' | 'default'> {
786
+ /** MDX does not support rawContent! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins */
787
+ rawContent: never;
788
+ /** MDX does not support compiledContent! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins */
789
+ compiledContent: never;
790
+ default: AstroComponentFactory;
791
+ Content: AstroComponentFactory;
792
+ }
793
+ export interface MarkdownLayoutProps<T extends Record<string, any>> {
794
+ frontmatter: {
795
+ file: MarkdownInstance<T>['file'];
796
+ url: MarkdownInstance<T>['url'];
797
+ } & T;
798
+ headings: MarkdownHeading[];
799
+ rawContent: MarkdownInstance<T>['rawContent'];
800
+ compiledContent: MarkdownInstance<T>['compiledContent'];
801
+ }
802
+ export interface MDXLayoutProps<T> extends Omit<MarkdownLayoutProps<T>, 'rawContent' | 'compiledContent'> {
803
+ }
785
804
  export declare type GetHydrateCallback = () => Promise<() => void | Promise<void>>;
786
805
  /**
787
806
  * getStaticPaths() options
@@ -1,5 +1,5 @@
1
1
  import type { ErrorPayload, ViteDevServer } from 'vite';
2
- import type { AstroConfig } from '../@types/astro';
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;
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro = self.Astro || {}).idle = (getHydrateCallback) => {\n const cb = async () => {\n let hydrate = await getHydrateCallback();\n await hydrate();\n };\n if (\"requestIdleCallback\" in window) {\n window.requestIdleCallback(cb);\n } else {\n setTimeout(cb, 200);\n }\n};";
6
+ declare const _default: "(self.Astro=self.Astro||{}).idle=a=>{const e=async()=>{await(await a())()};\"requestIdleCallback\"in window?window.requestIdleCallback(e):setTimeout(e,200)};";
7
7
  export default _default;
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro = self.Astro || {}).load = (getHydrateCallback) => {\n (async () => {\n let hydrate = await getHydrateCallback();\n await hydrate();\n })();\n};";
6
+ declare const _default: "(self.Astro=self.Astro||{}).load=a=>{(async()=>await(await a())())()};";
7
7
  export default _default;
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro = self.Astro || {}).media = (getHydrateCallback, options) => {\n const cb = async () => {\n let hydrate = await getHydrateCallback();\n await hydrate();\n };\n if (options.value) {\n const mql = matchMedia(options.value);\n if (mql.matches) {\n cb();\n } else {\n mql.addEventListener(\"change\", cb, { once: true });\n }\n }\n};";
6
+ declare const _default: "(self.Astro=self.Astro||{}).media=(s,a)=>{const t=async()=>{await(await s())()};if(a.value){const e=matchMedia(a.value);e.matches?t():e.addEventListener(\"change\",t,{once:!0})}};";
7
7
  export default _default;
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro = self.Astro || {}).only = (getHydrateCallback) => {\n (async () => {\n let hydrate = await getHydrateCallback();\n await hydrate();\n })();\n};";
6
+ declare const _default: "(self.Astro=self.Astro||{}).only=a=>{(async()=>await(await a())())()};";
7
7
  export default _default;
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro = self.Astro || {}).visible = (getHydrateCallback, _opts, root) => {\n const cb = async () => {\n let hydrate = await getHydrateCallback();\n await hydrate();\n };\n let io = new IntersectionObserver((entries) => {\n for (const entry of entries) {\n if (!entry.isIntersecting)\n continue;\n io.disconnect();\n cb();\n break;\n }\n });\n for (let i = 0; i < root.children.length; i++) {\n const child = root.children[i];\n io.observe(child);\n }\n};";
6
+ declare const _default: "(self.Astro=self.Astro||{}).visible=(i,c,n)=>{const r=async()=>{await(await i())()};let s=new IntersectionObserver(e=>{for(const t of e)if(!!t.isIntersecting){s.disconnect(),r();break}});for(let e=0;e<n.children.length;e++){const t=n.children[e];s.observe(t)}};";
7
7
  export default _default;
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "var _a;\n{\n const propTypes = {\n 0: (value) => value,\n 1: (value) => JSON.parse(value, reviver),\n 2: (value) => new RegExp(value),\n 3: (value) => new Date(value),\n 4: (value) => new Map(JSON.parse(value, reviver)),\n 5: (value) => new Set(JSON.parse(value, reviver)),\n 6: (value) => BigInt(value),\n 7: (value) => new URL(value)\n };\n const reviver = (propKey, raw) => {\n if (propKey === \"\" || !Array.isArray(raw))\n return raw;\n const [type, value] = raw;\n return type in propTypes ? propTypes[type](value) : void 0;\n };\n if (!customElements.get(\"astro-island\")) {\n customElements.define(\n \"astro-island\",\n (_a = class extends HTMLElement {\n constructor() {\n super(...arguments);\n this.hydrate = () => {\n if (!this.hydrator || this.parentElement?.closest(\"astro-island[ssr]\")) {\n return;\n }\n const slotted = this.querySelectorAll(\"astro-slot\");\n const slots = {};\n const templates = this.querySelectorAll(\"template[data-astro-template]\");\n for (const template of templates) {\n if (!template.closest(this.tagName)?.isSameNode(this))\n continue;\n slots[template.getAttribute(\"data-astro-template\") || \"default\"] = template.innerHTML;\n template.remove();\n }\n for (const slot of slotted) {\n if (!slot.closest(this.tagName)?.isSameNode(this))\n continue;\n slots[slot.getAttribute(\"name\") || \"default\"] = slot.innerHTML;\n }\n const props = this.hasAttribute(\"props\") ? JSON.parse(this.getAttribute(\"props\"), reviver) : {};\n this.hydrator(this)(this.Component, props, slots, {\n client: this.getAttribute(\"client\")\n });\n this.removeAttribute(\"ssr\");\n window.removeEventListener(\"astro:hydrate\", this.hydrate);\n window.dispatchEvent(new CustomEvent(\"astro:hydrate\"));\n };\n }\n connectedCallback() {\n if (!this.hasAttribute(\"await-children\") || this.firstChild) {\n this.childrenConnectedCallback();\n } else {\n new MutationObserver((_, mo) => {\n mo.disconnect();\n this.childrenConnectedCallback();\n }).observe(this, { childList: true });\n }\n }\n async childrenConnectedCallback() {\n window.addEventListener(\"astro:hydrate\", this.hydrate);\n await import(this.getAttribute(\"before-hydration-url\"));\n const opts = JSON.parse(this.getAttribute(\"opts\"));\n Astro[this.getAttribute(\"client\")](\n async () => {\n const rendererUrl = this.getAttribute(\"renderer-url\");\n const [componentModule, { default: hydrator }] = await Promise.all([\n import(this.getAttribute(\"component-url\")),\n rendererUrl ? import(rendererUrl) : () => () => {\n }\n ]);\n this.Component = componentModule[this.getAttribute(\"component-export\") || \"default\"];\n this.hydrator = hydrator;\n return this.hydrate;\n },\n opts,\n this\n );\n }\n attributeChangedCallback() {\n if (this.hydrator)\n this.hydrate();\n }\n }, _a.observedAttributes = [\"props\"], _a)\n );\n }\n}";
6
+ declare const _default: "var a;{const l={0:t=>t,1:t=>JSON.parse(t,n),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,n)),5:t=>new Set(JSON.parse(t,n)),6:t=>BigInt(t),7:t=>new URL(t)},n=(t,r)=>{if(t===\"\"||!Array.isArray(r))return r;const[s,i]=r;return s in l?l[s](i):void 0};customElements.get(\"astro-island\")||customElements.define(\"astro-island\",(a=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement?.closest(\"astro-island[ssr]\"))return;const r=this.querySelectorAll(\"astro-slot\"),s={},i=this.querySelectorAll(\"template[data-astro-template]\");for(const e of i)!e.closest(this.tagName)?.isSameNode(this)||(s[e.getAttribute(\"data-astro-template\")||\"default\"]=e.innerHTML,e.remove());for(const e of r)!e.closest(this.tagName)?.isSameNode(this)||(s[e.getAttribute(\"name\")||\"default\"]=e.innerHTML);const o=this.hasAttribute(\"props\")?JSON.parse(this.getAttribute(\"props\"),n):{};this.hydrator(this)(this.Component,o,s,{client:this.getAttribute(\"client\")}),this.removeAttribute(\"ssr\"),window.removeEventListener(\"astro:hydrate\",this.hydrate),window.dispatchEvent(new CustomEvent(\"astro:hydrate\"))}}connectedCallback(){!this.hasAttribute(\"await-children\")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((r,s)=>{s.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener(\"astro:hydrate\",this.hydrate),await import(this.getAttribute(\"before-hydration-url\"));const r=JSON.parse(this.getAttribute(\"opts\"));Astro[this.getAttribute(\"client\")](async()=>{const s=this.getAttribute(\"renderer-url\"),[i,{default:o}]=await Promise.all([import(this.getAttribute(\"component-url\")),s?import(s):()=>()=>{}]),e=this.getAttribute(\"component-export\")||\"default\";if(!e.includes(\".\"))this.Component=i[e];else{this.Component=i;for(const c of e.split(\".\"))this.Component=this.Component[c]}return this.hydrator=o,this.hydrate},r,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},a.observedAttributes=[\"props\"],a))}";
7
7
  export default _default;
@@ -35,7 +35,10 @@ async function transformJSX({
35
35
  }) {
36
36
  const { jsxTransformOptions } = renderer;
37
37
  const options = await jsxTransformOptions({ mode, ssr });
38
- const plugins = [...options.plugins || [], tagExportsPlugin({ rendererName: renderer.name })];
38
+ const plugins = [...options.plugins || []];
39
+ if (ssr) {
40
+ plugins.push(tagExportsPlugin({ rendererName: renderer.name }));
41
+ }
39
42
  const result = await babel.transformAsync(code, {
40
43
  presets: options.presets,
41
44
  plugins,
@@ -31,9 +31,7 @@ function markdown({ config, logging }) {
31
31
  const { frontmatter: injectedFrontmatter } = safelyGetAstroData(renderResult.vfile.data);
32
32
  const frontmatter = {
33
33
  ...injectedFrontmatter,
34
- ...raw.data,
35
- url: fileUrl,
36
- file: fileId
34
+ ...raw.data
37
35
  };
38
36
  const { layout } = frontmatter;
39
37
  if (frontmatter.setup) {
@@ -67,6 +65,8 @@ function markdown({ config, logging }) {
67
65
  };
68
66
  export async function Content() {
69
67
  const { layout, ...content } = frontmatter;
68
+ content.file = file;
69
+ content.url = url;
70
70
  content.astro = {};
71
71
  Object.defineProperty(content.astro, 'headings', {
72
72
  get() {
package/env.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference path="./client.d.ts" />
2
2
 
3
- type Astro = import('astro').AstroGlobal;
3
+ type Astro = import('./dist/types/@types/astro').AstroGlobal;
4
4
 
5
5
  // We duplicate the description here because editors won't show the JSDoc comment from the imported type (but will for its properties, ex: Astro.request will show the AstroGlobal.request description)
6
6
  /**
@@ -13,7 +13,7 @@ declare const Astro: Readonly<Astro>;
13
13
  declare const Fragment: any;
14
14
 
15
15
  declare module '*.md' {
16
- type MD = import('astro').MarkdownInstance<Record<string, any>>;
16
+ type MD = import('./dist/types/@types/astro').MarkdownInstance<Record<string, any>>;
17
17
 
18
18
  export const frontmatter: MD['frontmatter'];
19
19
  export const file: MD['file'];
@@ -29,6 +29,21 @@ declare module '*.md' {
29
29
  export default load;
30
30
  }
31
31
 
32
+ declare module '*.mdx' {
33
+ type MDX = import('astro').MDXInstance<Record<string, any>>;
34
+
35
+ export const frontmatter: MDX['frontmatter'];
36
+ export const file: MDX['file'];
37
+ export const url: MDX['url'];
38
+ export const getHeadings: MDX['getHeadings'];
39
+ export const Content: MDX['Content'];
40
+ export const rawContent: MDX['rawContent'];
41
+ export const compiledContent: MDX['compiledContent'];
42
+
43
+ const load: MDX['default'];
44
+ export default load;
45
+ }
46
+
32
47
  declare module '*.html' {
33
48
  const Component: { render(opts: { slots: Record<string, string> }): string };
34
49
  export default Component;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
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",
@@ -74,7 +74,7 @@
74
74
  "vendor"
75
75
  ],
76
76
  "dependencies": {
77
- "@astrojs/compiler": "^0.23.1",
77
+ "@astrojs/compiler": "^0.23.3",
78
78
  "@astrojs/language-server": "^0.20.0",
79
79
  "@astrojs/markdown-remark": "^1.0.0",
80
80
  "@astrojs/telemetry": "^1.0.0",