astro 0.25.3 → 0.26.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.
Files changed (111) hide show
  1. package/astro.js +12 -4
  2. package/dist/cli/check.js +4 -4
  3. package/dist/cli/index.js +21 -32
  4. package/dist/core/add/index.js +36 -20
  5. package/dist/core/app/index.js +17 -11
  6. package/dist/core/build/common.js +4 -5
  7. package/dist/core/build/generate.js +69 -73
  8. package/dist/core/build/index.js +90 -77
  9. package/dist/core/build/page-data.js +10 -9
  10. package/dist/core/build/static-build.js +41 -24
  11. package/dist/core/build/vite-plugin-hoisted-scripts.js +1 -1
  12. package/dist/core/build/vite-plugin-ssr.js +5 -2
  13. package/dist/core/config.js +89 -79
  14. package/dist/core/create-vite.js +17 -8
  15. package/dist/core/dev/index.js +22 -9
  16. package/dist/core/endpoint/dev/index.js +5 -10
  17. package/dist/core/endpoint/index.js +1 -3
  18. package/dist/core/errors.js +45 -0
  19. package/dist/core/logger/console.js +43 -0
  20. package/dist/core/logger/core.js +103 -0
  21. package/dist/core/logger/node.js +94 -0
  22. package/dist/core/messages.js +79 -28
  23. package/dist/core/preview/index.js +15 -9
  24. package/dist/core/preview/util.js +3 -6
  25. package/dist/core/render/core.js +21 -6
  26. package/dist/core/render/dev/css.js +5 -6
  27. package/dist/core/render/dev/index.js +43 -38
  28. package/dist/core/render/paginate.js +3 -1
  29. package/dist/core/render/pretty-feed.js +103 -0
  30. package/dist/core/render/result.js +33 -15
  31. package/dist/core/render/route-cache.js +12 -3
  32. package/dist/core/render/rss.js +5 -4
  33. package/dist/core/render/ssr-element.js +1 -1
  34. package/dist/core/render/util.js +35 -0
  35. package/dist/core/request.js +33 -0
  36. package/dist/core/routing/manifest/create.js +8 -6
  37. package/dist/core/routing/validation.js +1 -1
  38. package/dist/core/util.js +57 -125
  39. package/dist/integrations/index.js +38 -6
  40. package/dist/runtime/server/index.js +51 -41
  41. package/dist/template/4xx.js +8 -2
  42. package/dist/template/5xx.js +8 -1
  43. package/dist/types/@types/astro.d.ts +290 -232
  44. package/dist/types/cli/index.d.ts +1 -1
  45. package/dist/types/core/add/index.d.ts +1 -1
  46. package/dist/types/core/build/common.d.ts +0 -1
  47. package/dist/types/core/build/generate.d.ts +1 -1
  48. package/dist/types/core/build/index.d.ts +1 -1
  49. package/dist/types/core/build/page-data.d.ts +1 -1
  50. package/dist/types/core/config.d.ts +125 -116
  51. package/dist/types/core/create-vite.d.ts +1 -1
  52. package/dist/types/core/dev/index.d.ts +1 -1
  53. package/dist/types/core/endpoint/index.d.ts +1 -1
  54. package/dist/types/core/errors.d.ts +23 -0
  55. package/dist/types/core/logger/console.d.ts +4 -0
  56. package/dist/types/core/{logger.d.ts → logger/core.d.ts} +7 -22
  57. package/dist/types/core/logger/node.d.ts +34 -0
  58. package/dist/types/core/messages.d.ts +5 -3
  59. package/dist/types/core/preview/index.d.ts +1 -1
  60. package/dist/types/core/preview/util.d.ts +1 -2
  61. package/dist/types/core/render/core.d.ts +2 -3
  62. package/dist/types/core/render/dev/css.d.ts +0 -2
  63. package/dist/types/core/render/dev/index.d.ts +5 -7
  64. package/dist/types/core/render/pretty-feed.d.ts +2 -0
  65. package/dist/types/core/render/result.d.ts +2 -3
  66. package/dist/types/core/render/route-cache.d.ts +2 -2
  67. package/dist/types/core/render/util.d.ts +6 -0
  68. package/dist/types/core/request.d.ts +14 -0
  69. package/dist/types/core/routing/manifest/create.d.ts +1 -1
  70. package/dist/types/core/routing/validation.d.ts +1 -1
  71. package/dist/types/core/util.d.ts +11 -7
  72. package/dist/types/integrations/index.d.ts +11 -5
  73. package/dist/types/runtime/server/index.d.ts +1 -2
  74. package/dist/types/template/4xx.d.ts +1 -1
  75. package/dist/types/template/5xx.d.ts +1 -1
  76. package/dist/types/vite-plugin-astro/hmr.d.ts +1 -1
  77. package/dist/types/vite-plugin-astro/index.d.ts +1 -1
  78. package/dist/types/vite-plugin-astro/styles.d.ts +1 -1
  79. package/dist/types/vite-plugin-astro-server/index.d.ts +1 -1
  80. package/dist/types/vite-plugin-build-html/extract-assets.d.ts +1 -1
  81. package/dist/types/vite-plugin-build-html/index.d.ts +3 -3
  82. package/dist/types/vite-plugin-config-alias/index.d.ts +1 -1
  83. package/dist/types/vite-plugin-env/index.d.ts +1 -1
  84. package/dist/types/vite-plugin-integrations-container/index.d.ts +1 -1
  85. package/dist/types/vite-plugin-jsx/index.d.ts +1 -1
  86. package/dist/vite-plugin-astro/compile.js +12 -14
  87. package/dist/vite-plugin-astro/hmr.js +2 -2
  88. package/dist/vite-plugin-astro/index.js +41 -13
  89. package/dist/vite-plugin-astro/styles.js +8 -2
  90. package/dist/vite-plugin-astro-postprocess/index.js +35 -34
  91. package/dist/vite-plugin-astro-server/index.js +66 -25
  92. package/dist/vite-plugin-build-css/index.js +6 -2
  93. package/dist/vite-plugin-build-html/index.js +43 -23
  94. package/dist/vite-plugin-config-alias/index.js +4 -2
  95. package/dist/vite-plugin-env/index.js +8 -3
  96. package/dist/vite-plugin-integrations-container/index.js +3 -1
  97. package/dist/vite-plugin-jsx/index.js +22 -4
  98. package/dist/vite-plugin-markdown/index.js +93 -18
  99. package/env.d.ts +1 -1
  100. package/package.json +13 -9
  101. package/dist/core/build/scan-based-build.js +0 -62
  102. package/dist/core/dev/util.js +0 -44
  103. package/dist/core/logger.js +0 -174
  104. package/dist/core/render/dev/error.js +0 -34
  105. package/dist/core/render/request.js +0 -23
  106. package/dist/core/render/sitemap.js +0 -18
  107. package/dist/types/core/build/scan-based-build.d.ts +0 -18
  108. package/dist/types/core/dev/util.d.ts +0 -9
  109. package/dist/types/core/render/dev/error.d.ts +0 -7
  110. package/dist/types/core/render/request.d.ts +0 -15
  111. package/dist/types/core/render/sitemap.d.ts +0 -2
@@ -17,31 +17,53 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import {
21
+ createElement,
22
+ createScript,
23
+ getAttribute,
24
+ hasAttribute,
25
+ insertBefore,
26
+ remove,
27
+ setAttribute
28
+ } from "@web/parse5-utils";
29
+ import { promises as fs } from "fs";
20
30
  import parse5 from "parse5";
21
- import srcsetParse from "srcset-parse";
22
31
  import * as npath from "path";
23
- import { promises as fs } from "fs";
24
- import { getAttribute, hasAttribute, insertBefore, remove, createScript, createElement, setAttribute } from "@web/parse5-utils";
25
- import { addRollupInput } from "./add-rollup-input.js";
26
- import { findAssets, findExternalScripts, findInlineScripts, findInlineStyles, getTextContent, getAttributes } from "./extract-assets.js";
27
- import { isBuildableImage, isBuildableLink, isHoistedScript, isInSrcDirectory, hasSrcSet } from "./util.js";
32
+ import srcsetParse from "srcset-parse";
33
+ import { prependDotSlash } from "../core/path.js";
28
34
  import { render as ssrRender } from "../core/render/dev/index.js";
29
- import { getAstroStyleId, getAstroPageStyleId } from "../vite-plugin-build-css/index.js";
30
- import { prependDotSlash, removeEndingForwardSlash } from "../core/path.js";
35
+ import { getOutputFilename } from "../core/util.js";
36
+ import { getAstroPageStyleId, getAstroStyleId } from "../vite-plugin-build-css/index.js";
37
+ import { addRollupInput } from "./add-rollup-input.js";
38
+ import {
39
+ findAssets,
40
+ findExternalScripts,
41
+ findInlineScripts,
42
+ findInlineStyles,
43
+ getAttributes,
44
+ getTextContent
45
+ } from "./extract-assets.js";
46
+ import {
47
+ hasSrcSet,
48
+ isBuildableImage,
49
+ isBuildableLink,
50
+ isHoistedScript,
51
+ isInSrcDirectory
52
+ } from "./util.js";
53
+ import { createRequest } from "../core/request.js";
31
54
  const matchSrcset = srcsetParse.default;
32
55
  const PLUGIN_NAME = "@astro/rollup-plugin-build";
33
56
  const ASTRO_PAGE_PREFIX = "@astro-page";
34
57
  const ASTRO_SCRIPT_PREFIX = "@astro-script";
35
58
  const ASTRO_EMPTY = "@astro-empty";
36
- const STATUS_CODE_REGEXP = /^[0-9]{3}$/;
37
59
  function relativePath(from, to) {
38
60
  const rel = npath.posix.relative(from, to);
39
61
  return prependDotSlash(rel);
40
62
  }
41
63
  function rollupPluginAstroScanHTML(options) {
42
64
  const { astroConfig, internals, logging, origin, allPages, routeCache, viteServer, pageNames } = options;
43
- const srcRoot = astroConfig.src.pathname;
44
- const srcRootWeb = srcRoot.substr(astroConfig.projectRoot.pathname.length - 1);
65
+ const srcRoot = astroConfig.srcDir.pathname;
66
+ const srcRootWeb = srcRoot.substr(astroConfig.root.pathname.length - 1);
45
67
  const renderedPageMap = /* @__PURE__ */ new Map();
46
68
  const astroScriptMap = /* @__PURE__ */ new Map();
47
69
  const astroPageMap = /* @__PURE__ */ new Map();
@@ -65,10 +87,13 @@ function rollupPluginAstroScanHTML(options) {
65
87
  const id = ASTRO_PAGE_PREFIX + pathname;
66
88
  const response = await ssrRender(renderers, mod, {
67
89
  astroConfig,
68
- filePath: new URL(`./${component}`, astroConfig.projectRoot),
90
+ filePath: new URL(`./${component}`, astroConfig.root),
69
91
  logging,
70
- headers: new Headers(),
71
- method: "GET",
92
+ request: createRequest({
93
+ url: new URL(origin + pathname),
94
+ headers: new Headers(),
95
+ logging
96
+ }),
72
97
  mode: "production",
73
98
  origin,
74
99
  pathname,
@@ -131,7 +156,7 @@ function rollupPluginAstroScanHTML(options) {
131
156
  if ((src == null ? void 0 : src.startsWith(srcRoot)) && !astroAssetMap.has(src)) {
132
157
  astroAssetMap.set(src, fs.readFile(new URL(`file://${src}`)));
133
158
  } else if ((src == null ? void 0 : src.startsWith(srcRootWeb)) && !astroAssetMap.has(src)) {
134
- const resolved = new URL("." + src, astroConfig.projectRoot);
159
+ const resolved = new URL("." + src, astroConfig.root);
135
160
  astroAssetMap.set(src, fs.readFile(resolved));
136
161
  }
137
162
  }
@@ -141,7 +166,7 @@ function rollupPluginAstroScanHTML(options) {
141
166
  if (url.startsWith(srcRoot) && !astroAssetMap.has(url)) {
142
167
  astroAssetMap.set(url, fs.readFile(new URL(`file://${url}`)));
143
168
  } else if (url.startsWith(srcRootWeb) && !astroAssetMap.has(url)) {
144
- const resolved = new URL("." + url, astroConfig.projectRoot);
169
+ const resolved = new URL("." + url, astroConfig.root);
145
170
  astroAssetMap.set(url, fs.readFile(resolved));
146
171
  }
147
172
  }
@@ -313,7 +338,7 @@ function rollupPluginAstroScanHTML(options) {
313
338
  } else if (isInSrcDirectory(script, "src", srcRoot, srcRootWeb)) {
314
339
  let src = getAttribute(script, "src");
315
340
  if (src == null ? void 0 : src.startsWith(srcRootWeb)) {
316
- src = new URL("." + src, astroConfig.projectRoot).pathname;
341
+ src = new URL("." + src, astroConfig.root).pathname;
317
342
  }
318
343
  if (src && (facadeIdMap.has(src) || facadeIdMap.has(src.substr(1)))) {
319
344
  const assetRootPath = "/" + (facadeIdMap.get(src) || facadeIdMap.get(src.substr(1)));
@@ -386,12 +411,7 @@ function rollupPluginAstroScanHTML(options) {
386
411
  }
387
412
  const outHTML = parse5.serialize(document);
388
413
  const name = pathname.substr(1);
389
- let outPath;
390
- if (astroConfig.buildOptions.pageUrlFormat === "file" || STATUS_CODE_REGEXP.test(name)) {
391
- outPath = `${removeEndingForwardSlash(name || "index")}.html`;
392
- } else {
393
- outPath = npath.posix.join(name, "index.html");
394
- }
414
+ const outPath = getOutputFilename(astroConfig, name);
395
415
  this.emitFile({
396
416
  fileName: outPath,
397
417
  source: outHTML,
@@ -47,7 +47,7 @@ const getConfigAlias = (cwd) => {
47
47
  return aliases;
48
48
  };
49
49
  function configAliasVitePlugin(astroConfig) {
50
- const configAlias = getConfigAlias(astroConfig.projectRoot && url.fileURLToPath(astroConfig.projectRoot));
50
+ const configAlias = getConfigAlias(astroConfig.root && url.fileURLToPath(astroConfig.root));
51
51
  if (!configAlias)
52
52
  return {};
53
53
  return {
@@ -60,7 +60,9 @@ function configAliasVitePlugin(astroConfig) {
60
60
  for (const alias of configAlias) {
61
61
  if (alias.find.test(sourceId)) {
62
62
  const aliasedSourceId = sourceId.replace(alias.find, alias.replacement);
63
- const resolvedAliasedId = await this.resolve(aliasedSourceId, importer, __spreadValues({ skipSelf: true }, options));
63
+ const resolvedAliasedId = await this.resolve(aliasedSourceId, importer, __spreadValues({
64
+ skipSelf: true
65
+ }, options));
64
66
  if (resolvedAliasedId)
65
67
  return resolvedAliasedId;
66
68
  }
@@ -6,7 +6,7 @@ function getPrivateEnv(viteConfig, astroConfig) {
6
6
  if (viteConfig.envPrefix) {
7
7
  envPrefixes = Array.isArray(viteConfig.envPrefix) ? viteConfig.envPrefix : [viteConfig.envPrefix];
8
8
  }
9
- const fullEnv = loadEnv(viteConfig.mode, viteConfig.envDir ?? fileURLToPath(astroConfig.projectRoot), "");
9
+ const fullEnv = loadEnv(viteConfig.mode, viteConfig.envDir ?? fileURLToPath(astroConfig.root), "");
10
10
  const privateKeys = Object.keys(fullEnv).filter((key) => {
11
11
  if (typeof process.env[key] !== "undefined")
12
12
  return false;
@@ -30,7 +30,9 @@ function getReferencedPrivateKeys(source, privateEnv) {
30
30
  }
31
31
  return references;
32
32
  }
33
- function envVitePlugin({ config: astroConfig }) {
33
+ function envVitePlugin({
34
+ config: astroConfig
35
+ }) {
34
36
  let privateEnv;
35
37
  let config;
36
38
  let replacements;
@@ -52,7 +54,10 @@ function envVitePlugin({ config: astroConfig }) {
52
54
  if (typeof privateEnv === "undefined") {
53
55
  privateEnv = getPrivateEnv(config, astroConfig);
54
56
  if (privateEnv) {
55
- const entries = Object.entries(privateEnv).map(([key, value]) => [`import.meta.env.${key}`, value]);
57
+ const entries = Object.entries(privateEnv).map(([key, value]) => [
58
+ `import.meta.env.${key}`,
59
+ value
60
+ ]);
56
61
  replacements = Object.fromEntries(entries);
57
62
  replacements = Object.assign(replacements, {
58
63
  "import.meta.env": `({})`
@@ -1,5 +1,7 @@
1
1
  import { runHookServerSetup } from "../integrations/index.js";
2
- function astroIntegrationsContainerPlugin({ config }) {
2
+ function astroIntegrationsContainerPlugin({
3
+ config
4
+ }) {
3
5
  return {
4
6
  name: "astro:integration-container",
5
7
  configureServer(server) {
@@ -3,7 +3,7 @@ import esbuild from "esbuild";
3
3
  import * as colors from "kleur/colors";
4
4
  import * as eslexer from "es-module-lexer";
5
5
  import path from "path";
6
- import { error } from "../core/logger.js";
6
+ import { error } from "../core/logger/core.js";
7
7
  import { parseNpmName } from "../core/util.js";
8
8
  const JSX_RENDERER_CACHE = /* @__PURE__ */ new WeakMap();
9
9
  const JSX_EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx"]);
@@ -20,7 +20,13 @@ function collectJSXRenderers(renderers) {
20
20
  const renderersWithJSXSupport = renderers.filter((r) => r.jsxImportSource);
21
21
  return new Map(renderersWithJSXSupport.map((r) => [r.jsxImportSource, r]));
22
22
  }
23
- async function transformJSX({ code, mode, id, ssr, renderer }) {
23
+ async function transformJSX({
24
+ code,
25
+ mode,
26
+ id,
27
+ ssr,
28
+ renderer
29
+ }) {
24
30
  const { jsxTransformOptions } = renderer;
25
31
  const options = await jsxTransformOptions({ mode, ssr });
26
32
  const plugins = [...options.plugins || []];
@@ -76,7 +82,13 @@ Unable to resolve a JSX renderer! Did you forget to include one? Add a JSX integ
76
82
  sourcefile: id,
77
83
  sourcemap: "inline"
78
84
  });
79
- return transformJSX({ code: jsxCode, id, renderer: [...jsxRenderers.values()][0], mode, ssr });
85
+ return transformJSX({
86
+ code: jsxCode,
87
+ id,
88
+ renderer: [...jsxRenderers.values()][0],
89
+ mode,
90
+ ssr
91
+ });
80
92
  }
81
93
  const { code: jsCode } = await esbuild.transform(code + PREVENT_UNUSED_IMPORTS, {
82
94
  loader: getEsbuildLoader(path.extname(id)),
@@ -125,7 +137,13 @@ Unable to resolve a JSX renderer! Did you forget to include one? Add a JSX integ
125
137
  sourcefile: id,
126
138
  sourcemap: "inline"
127
139
  });
128
- return await transformJSX({ code: jsxCode, id, renderer: jsxRenderers.get(importSource), mode, ssr });
140
+ return await transformJSX({
141
+ code: jsxCode,
142
+ id,
143
+ renderer: jsxRenderers.get(importSource),
144
+ mode,
145
+ ssr
146
+ });
129
147
  }
130
148
  const defaultRenderer = [...jsxRenderers.keys()][0];
131
149
  error(logging, "renderer", `${colors.yellow(id)}
@@ -1,6 +1,19 @@
1
+ var __defProp = Object.defineProperty;
1
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
3
4
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
4
17
  var __objRest = (source, exclude) => {
5
18
  var target = {};
6
19
  for (var prop in source)
@@ -13,41 +26,99 @@ var __objRest = (source, exclude) => {
13
26
  }
14
27
  return target;
15
28
  };
29
+ import astroRemark from "@astrojs/markdown-remark";
16
30
  import { transform } from "@astrojs/compiler";
17
31
  import ancestor from "common-ancestor-path";
18
32
  import esbuild from "esbuild";
19
33
  import fs from "fs";
34
+ import matter from "gray-matter";
35
+ import { fileURLToPath } from "url";
20
36
  import { PAGE_SSR_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
37
+ import { virtualModuleId as pagesVirtualModuleId } from "../core/build/vite-plugin-pages.js";
38
+ import { appendForwardSlash } from "../core/path.js";
39
+ import { resolvePages } from "../core/util.js";
40
+ const VIRTUAL_MODULE_ID_PREFIX = "astro:markdown";
41
+ const VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID_PREFIX;
21
42
  function markdown({ config }) {
22
43
  function normalizeFilename(filename) {
23
44
  if (filename.startsWith("/@fs")) {
24
45
  filename = filename.slice("/@fs".length);
25
- } else if (filename.startsWith("/") && !ancestor(filename, config.projectRoot.pathname)) {
26
- filename = new URL("." + filename, config.projectRoot).pathname;
46
+ } else if (filename.startsWith("/") && !ancestor(filename, config.root.pathname)) {
47
+ filename = new URL("." + filename, config.root).pathname;
27
48
  }
28
49
  return filename;
29
50
  }
51
+ const fakeRootImporter = fileURLToPath(new URL("index.html", config.root));
52
+ function isRootImport(importer) {
53
+ if (!importer) {
54
+ return true;
55
+ }
56
+ if (importer === fakeRootImporter) {
57
+ return true;
58
+ }
59
+ if (importer === "\0" + pagesVirtualModuleId) {
60
+ return true;
61
+ }
62
+ return false;
63
+ }
30
64
  return {
31
65
  name: "astro:markdown",
32
66
  enforce: "pre",
67
+ async resolveId(id, importer, options) {
68
+ if (id.startsWith(VIRTUAL_MODULE_ID)) {
69
+ return id;
70
+ }
71
+ if (id.endsWith(".md?content")) {
72
+ const resolvedId = await this.resolve(id, importer, __spreadValues({ skipSelf: true }, options));
73
+ return resolvedId == null ? void 0 : resolvedId.id.replace("?content", "");
74
+ }
75
+ if (id.endsWith(".md") && !isRootImport(importer)) {
76
+ const resolvedId = await this.resolve(id, importer, __spreadValues({ skipSelf: true }, options));
77
+ if (resolvedId) {
78
+ return VIRTUAL_MODULE_ID + resolvedId.id;
79
+ }
80
+ }
81
+ return void 0;
82
+ },
33
83
  async load(id) {
84
+ if (id.startsWith(VIRTUAL_MODULE_ID)) {
85
+ const sitePathname = config.site ? appendForwardSlash(new URL(config.base, config.site).pathname) : "/";
86
+ const fileId = id.substring(VIRTUAL_MODULE_ID.length);
87
+ const fileUrl = fileId.includes("/pages/") ? fileId.replace(/^.*\/pages\//, sitePathname).replace(/(\/index)?\.md$/, "") : void 0;
88
+ const source = await fs.promises.readFile(fileId, "utf8");
89
+ const { data: frontmatter } = matter(source);
90
+ return {
91
+ code: `
92
+ // Static
93
+ export const frontmatter = ${JSON.stringify(frontmatter)};
94
+ export const file = ${JSON.stringify(fileId)};
95
+ export const url = ${JSON.stringify(fileUrl)};
96
+
97
+ // Deferred
98
+ export default async function load() {
99
+ return (await import(${JSON.stringify(fileId + "?content")}));
100
+ };
101
+ export function Content(...args) {
102
+ return load().then((m) => m.default(...args))
103
+ }
104
+ Content.isAstroComponentFactory = true;
105
+ export function getHeaders() {
106
+ return load().then((m) => m.metadata.headers)
107
+ };`,
108
+ map: null
109
+ };
110
+ }
34
111
  if (id.endsWith(".md")) {
35
112
  const source = await fs.promises.readFile(id, "utf8");
36
- let render = config.markdownOptions.render;
37
- let renderOpts = {};
38
- if (Array.isArray(render)) {
39
- renderOpts = render[1];
40
- render = render[0];
41
- }
42
- if (typeof render === "string") {
43
- ({ default: render } = await import(render));
44
- }
45
- let renderResult = await render(source, renderOpts);
46
- let { frontmatter, metadata, code: astroResult } = renderResult;
113
+ const render = astroRemark;
114
+ const renderOpts = config.markdown;
47
115
  const filename = normalizeFilename(id);
48
116
  const fileUrl = new URL(`file://${filename}`);
49
- const isPage = fileUrl.pathname.startsWith(config.pages.pathname);
117
+ const isPage = fileUrl.pathname.startsWith(resolvePages(config).pathname);
50
118
  const hasInjectedScript = isPage && config._ctx.scripts.some((s) => s.stage === "page-ssr");
119
+ const { data: frontmatter, content: markdownContent } = matter(source);
120
+ let renderResult = await render(markdownContent, renderOpts);
121
+ let { code: astroResult, metadata } = renderResult;
51
122
  const _a = frontmatter, { layout = "", components = "", setup = "" } = _a, content = __objRest(_a, ["layout", "components", "setup"]);
52
123
  content.astro = metadata;
53
124
  const prelude = `---
@@ -72,9 +143,9 @@ ${astroResult}
72
143
  ${astroResult}`;
73
144
  }
74
145
  let { code: tsResult } = await transform(astroResult, {
75
- pathname: fileUrl.pathname.substr(config.projectRoot.pathname.length - 1),
76
- projectRoot: config.projectRoot.toString(),
77
- site: config.buildOptions.site,
146
+ pathname: fileUrl.pathname.substr(config.root.pathname.length - 1),
147
+ projectRoot: config.root.toString(),
148
+ site: config.site ? new URL(config.base, config.site).toString() : void 0,
78
149
  sourcefile: id,
79
150
  sourcemap: "inline",
80
151
  internalURL: `/@fs${new URL("../runtime/server/index.js", import.meta.url).pathname}`
@@ -83,7 +154,11 @@ ${astroResult}`;
83
154
  export const metadata = ${JSON.stringify(metadata)};
84
155
  export const frontmatter = ${JSON.stringify(content)};
85
156
  ${tsResult}`;
86
- const { code, map } = await esbuild.transform(tsResult, { loader: "ts", sourcemap: "inline", sourcefile: id });
157
+ const { code } = await esbuild.transform(tsResult, {
158
+ loader: "ts",
159
+ sourcemap: false,
160
+ sourcefile: id
161
+ });
87
162
  return {
88
163
  code,
89
164
  map: null
package/env.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="vite/client" />
2
2
 
3
- type Astro = import('./dist/types/@types/astro').AstroGlobal;
3
+ type Astro = import('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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "0.25.3",
3
+ "version": "0.26.1",
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",
@@ -64,9 +64,9 @@
64
64
  "vendor"
65
65
  ],
66
66
  "dependencies": {
67
- "@astrojs/compiler": "^0.13.1",
68
- "@astrojs/language-server": "^0.13.2",
69
- "@astrojs/markdown-remark": "^0.7.0",
67
+ "@astrojs/compiler": "^0.14.1",
68
+ "@astrojs/language-server": "^0.13.3",
69
+ "@astrojs/markdown-remark": "^0.8.1",
70
70
  "@astrojs/prism": "0.4.1",
71
71
  "@astrojs/webapi": "^0.11.0",
72
72
  "@babel/core": "^7.17.8",
@@ -76,6 +76,7 @@
76
76
  "@proload/core": "^0.2.2",
77
77
  "@proload/plugin-tsm": "^0.1.1",
78
78
  "@web/parse5-utils": "^1.3.0",
79
+ "ast-types": "^0.14.2",
79
80
  "boxen": "^6.2.1",
80
81
  "ci-info": "^3.3.0",
81
82
  "common-ancestor-path": "^1.0.1",
@@ -88,7 +89,7 @@
88
89
  "execa": "^6.1.0",
89
90
  "fast-glob": "^3.2.11",
90
91
  "fast-xml-parser": "^4.0.7",
91
- "html-entities": "^2.3.2",
92
+ "html-entities": "^2.3.3",
92
93
  "html-escaper": "^3.0.3",
93
94
  "htmlparser2": "^7.2.0",
94
95
  "kleur": "^4.1.4",
@@ -97,12 +98,14 @@
97
98
  "mime": "^3.0.0",
98
99
  "ora": "^6.1.0",
99
100
  "parse5": "^6.0.1",
101
+ "path-browserify": "^1.0.1",
100
102
  "path-to-regexp": "^6.2.0",
101
103
  "postcss": "^8.4.12",
102
- "postcss-load-config": "^3.1.3",
104
+ "postcss-load-config": "^3.1.4",
103
105
  "preferred-pm": "^3.0.3",
104
106
  "prismjs": "^1.27.0",
105
107
  "prompts": "^2.4.2",
108
+ "recast": "^0.20.5",
106
109
  "rehype-slug": "^5.0.1",
107
110
  "resolve": "^1.22.0",
108
111
  "rollup": "^2.70.1",
@@ -118,9 +121,9 @@
118
121
  "strip-ansi": "^7.0.1",
119
122
  "supports-esm": "^1.0.0",
120
123
  "tsconfig-resolver": "^3.0.1",
121
- "vite": "^2.8.6",
124
+ "vite": "^2.9.1",
122
125
  "yargs-parser": "^21.0.1",
123
- "zod": "^3.14.2"
126
+ "zod": "^3.14.3"
124
127
  },
125
128
  "devDependencies": {
126
129
  "@babel/types": "^7.17.0",
@@ -137,6 +140,7 @@
137
140
  "@types/mime": "^2.0.3",
138
141
  "@types/mocha": "^9.1.0",
139
142
  "@types/parse5": "^6.0.3",
143
+ "@types/path-browserify": "^1.0.0",
140
144
  "@types/prettier": "^2.4.4",
141
145
  "@types/resolve": "^1.20.1",
142
146
  "@types/rimraf": "^3.0.2",
@@ -146,7 +150,7 @@
146
150
  "chai": "^4.3.6",
147
151
  "cheerio": "^1.0.0-rc.10",
148
152
  "mocha": "^9.2.2",
149
- "sass": "^1.49.9"
153
+ "sass": "^1.49.11"
150
154
  },
151
155
  "engines": {
152
156
  "node": "^14.15.0 || >=16.0.0",
@@ -1,62 +0,0 @@
1
- import { fileURLToPath } from "url";
2
- import * as vite from "vite";
3
- import { createBuildInternals } from "../../core/build/internal.js";
4
- import { rollupPluginAstroScanHTML } from "../../vite-plugin-build-html/index.js";
5
- import { rollupPluginAstroBuildCSS } from "../../vite-plugin-build-css/index.js";
6
- function entryIsType(type) {
7
- return function withPage([_, pageData]) {
8
- return pageData.route.type === type;
9
- };
10
- }
11
- function reduceEntries(acc, [key, value]) {
12
- acc[key] = value;
13
- return acc;
14
- }
15
- function routesOfType(type, allPages) {
16
- return Object.entries(allPages).filter(entryIsType(type)).reduce(reduceEntries, {});
17
- }
18
- async function build(opts) {
19
- const { allPages, astroConfig, logging, origin, pageNames, routeCache, viteConfig, viteServer } = opts;
20
- const internals = createBuildInternals();
21
- return await vite.build({
22
- logLevel: "warn",
23
- mode: "production",
24
- build: {
25
- emptyOutDir: true,
26
- minify: "esbuild",
27
- outDir: fileURLToPath(astroConfig.dist),
28
- rollupOptions: {
29
- input: [],
30
- output: {
31
- format: "esm"
32
- }
33
- },
34
- target: "es2020"
35
- },
36
- plugins: [
37
- rollupPluginAstroScanHTML({
38
- astroConfig,
39
- internals,
40
- logging,
41
- origin,
42
- allPages: routesOfType("page", allPages),
43
- pageNames,
44
- routeCache,
45
- viteServer
46
- }),
47
- rollupPluginAstroBuildCSS({
48
- internals,
49
- legacy: true
50
- }),
51
- ...viteConfig.plugins || []
52
- ],
53
- publicDir: viteConfig.publicDir,
54
- root: viteConfig.root,
55
- envPrefix: "PUBLIC_",
56
- server: viteConfig.server,
57
- base: astroConfig.buildOptions.site ? new URL(astroConfig.buildOptions.site).pathname : "/"
58
- });
59
- }
60
- export {
61
- build
62
- };
@@ -1,44 +0,0 @@
1
- const localIps = /* @__PURE__ */ new Set(["localhost", "127.0.0.1"]);
2
- function pad(input, minLength, dir) {
3
- let output = input;
4
- while (output.length < minLength) {
5
- output = dir === "left" ? " " + output : output + " ";
6
- }
7
- return output;
8
- }
9
- function emoji(char, fallback) {
10
- return process.platform !== "win32" ? char : fallback;
11
- }
12
- function getResolvedHostForVite(config) {
13
- if (config.devOptions.host === false && config.devOptions.hostname !== "localhost") {
14
- return config.devOptions.hostname;
15
- } else {
16
- return config.devOptions.host;
17
- }
18
- }
19
- function getLocalAddress(serverAddress, config) {
20
- const host = getResolvedHostForVite(config);
21
- if (typeof host === "boolean" || host === "localhost") {
22
- return "localhost";
23
- } else {
24
- return serverAddress;
25
- }
26
- }
27
- function getNetworkLogging(config) {
28
- const host = getResolvedHostForVite(config);
29
- if (host === false) {
30
- return "host-to-expose";
31
- } else if (typeof host === "string" && localIps.has(host)) {
32
- return "none";
33
- } else {
34
- return "visible";
35
- }
36
- }
37
- export {
38
- emoji,
39
- getLocalAddress,
40
- getNetworkLogging,
41
- getResolvedHostForVite,
42
- localIps,
43
- pad
44
- };