astro 4.0.8 → 4.0.9

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.
@@ -8,7 +8,7 @@ function propsToFilename(transform, hash) {
8
8
  isESMImportedImage(transform.src) ? transform.src.src : transform.src
9
9
  );
10
10
  const ext = extname(filename);
11
- filename = basename(filename, ext);
11
+ filename = decodeURIComponent(basename(filename, ext));
12
12
  let outputExt = transform.format ? `.${transform.format}` : ext;
13
13
  return `/${filename}_${hash}${outputExt}`;
14
14
  }
@@ -100,9 +100,9 @@ function assets({
100
100
  });
101
101
  }
102
102
  if (settings.config.build.assetsPrefix) {
103
- return joinPaths(settings.config.build.assetsPrefix, finalFilePath);
103
+ return encodeURI(joinPaths(settings.config.build.assetsPrefix, finalFilePath));
104
104
  } else {
105
- return prependForwardSlash(joinPaths(settings.config.base, finalFilePath));
105
+ return encodeURI(prependForwardSlash(joinPaths(settings.config.base, finalFilePath)));
106
106
  }
107
107
  };
108
108
  },
@@ -93,6 +93,7 @@ async function add(names, { flags }) {
93
93
  ["lit", "astro add lit"],
94
94
  ["alpinejs", "astro add alpinejs"]
95
95
  ],
96
+ "Documentation Frameworks": [["starlight", "astro add starlight"]],
96
97
  "SSR Adapters": [
97
98
  ["netlify", "astro add netlify"],
98
99
  ["vercel", "astro add vercel"],
@@ -9,6 +9,9 @@ async function preview({ flags }) {
9
9
  usage: "[...flags]",
10
10
  tables: {
11
11
  Flags: [
12
+ ["--port", `Specify which port to run on. Defaults to 4321.`],
13
+ ["--host", `Listen on all addresses, including LAN and public addresses.`],
14
+ ["--host <custom-address>", `Expose on a network IP address at <custom-address>`],
12
15
  ["--open", "Automatically open the app in the browser on server start"],
13
16
  ["--help (-h)", "See all available flags."]
14
17
  ]
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.0.8";
1
+ const ASTRO_VERSION = "4.0.9";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -21,7 +21,7 @@ async function dev(inlineConfig) {
21
21
  base: restart.container.settings.config.base
22
22
  })
23
23
  );
24
- const currentVersion = "4.0.8";
24
+ const currentVersion = "4.0.9";
25
25
  if (currentVersion.includes("-")) {
26
26
  logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
27
27
  }
@@ -15,7 +15,7 @@ function collectErrorMetadata(e, rootFolder) {
15
15
  err.forEach((error) => {
16
16
  if (e.stack) {
17
17
  const stackInfo = collectInfoFromStacktrace(e);
18
- error.stack = stackInfo.stack;
18
+ error.stack = stripAnsi(stackInfo.stack);
19
19
  error.loc = stackInfo.loc;
20
20
  error.plugin = stackInfo.plugin;
21
21
  error.pluginCode = stackInfo.pluginCode;
@@ -30,7 +30,7 @@ function collectErrorMetadata(e, rootFolder) {
30
30
  const fileContents = fs.readFileSync(error.loc.file, "utf8");
31
31
  if (!error.frame) {
32
32
  const frame = codeFrame(fileContents, error.loc);
33
- error.frame = frame;
33
+ error.frame = stripAnsi(frame);
34
34
  }
35
35
  if (!error.fullCode) {
36
36
  error.fullCode = fileContents;
@@ -39,6 +39,9 @@ function collectErrorMetadata(e, rootFolder) {
39
39
  }
40
40
  }
41
41
  error.hint = generateHint(e);
42
+ if (error.message) {
43
+ error.message = stripAnsi(error.message);
44
+ }
42
45
  });
43
46
  if (!AggregateError.is(e) && Array.isArray(e.errors)) {
44
47
  e.errors.forEach((buildError, i) => {
@@ -16,7 +16,7 @@ export interface AstroErrorPayload {
16
16
  hint?: string;
17
17
  docslink?: string;
18
18
  highlightedCode?: string;
19
- loc: {
19
+ loc?: {
20
20
  file?: string;
21
21
  line?: number;
22
22
  column?: number;
@@ -621,7 +621,7 @@ class ErrorOverlay extends HTMLElement {
621
621
  docslink.appendChild(this.createLink(`See Docs Reference${openNewWindowIcon}`, err.docslink));
622
622
  }
623
623
  const code = this.root.querySelector("#code");
624
- if (code && err.loc.file) {
624
+ if (code && err.loc?.file) {
625
625
  code.style.display = "block";
626
626
  const codeHeader = code.querySelector("#code header");
627
627
  const codeContent = code.querySelector("#code-content");
@@ -647,7 +647,7 @@ class ErrorOverlay extends HTMLElement {
647
647
  if (errorLine.parentElement?.parentElement) {
648
648
  errorLine.parentElement.parentElement.scrollTop = errorLine.offsetTop - errorLine.parentElement.parentElement.offsetTop - 8;
649
649
  }
650
- if (err.loc.column) {
650
+ if (err.loc?.column) {
651
651
  errorLine.insertAdjacentHTML(
652
652
  "afterend",
653
653
  `
@@ -36,7 +36,7 @@ function serverStart({
36
36
  host,
37
37
  base
38
38
  }) {
39
- const version = "4.0.8";
39
+ const version = "4.0.9";
40
40
  const localPrefix = `${dim("\u2503")} Local `;
41
41
  const networkPrefix = `${dim("\u2503")} Network `;
42
42
  const emptyPrefix = " ".repeat(11);
@@ -258,7 +258,7 @@ function printHelp({
258
258
  message.push(
259
259
  linebreak(),
260
260
  ` ${bgGreen(black(` ${commandName} `))} ${green(
261
- `v${"4.0.8"}`
261
+ `v${"4.0.9"}`
262
262
  )} ${headline}`
263
263
  );
264
264
  }
@@ -53,7 +53,7 @@ export declare function getPathByLocale(locale: string, locales: Locales): strin
53
53
  /**
54
54
  * An utility function that retrieves the preferred locale that correspond to a path.
55
55
  *
56
- * @param locale
56
+ * @param path
57
57
  * @param locales
58
58
  */
59
59
  export declare function getLocaleByPath(path: string, locales: Locales): string | undefined;
@@ -99,10 +99,13 @@ function getPathByLocale(locale, locales) {
99
99
  function getLocaleByPath(path, locales) {
100
100
  for (const locale of locales) {
101
101
  if (typeof locale !== "string") {
102
- const code = locale.codes.at(0);
103
- return code;
102
+ if (locale.path === path) {
103
+ const code = locale.codes.at(0);
104
+ return code;
105
+ }
106
+ } else if (locale === path) {
107
+ return locale;
104
108
  }
105
- 1;
106
109
  }
107
110
  return void 0;
108
111
  }
@@ -54,7 +54,7 @@ function astroInternationalization({
54
54
  export const getAbsoluteLocaleUrlList = (path = "", opts) => _getLocaleAbsoluteUrlList({ base, path, trailingSlash, format, site, ...i18n, ...opts });
55
55
 
56
56
  export const getPathByLocale = (locale) => _getPathByLocale(locale, i18n.locales);
57
- export const getLocaleByPath = (locale) => _getLocaleByPath(locale, i18n.locales);
57
+ export const getLocaleByPath = (path) => _getLocaleByPath(path, i18n.locales);
58
58
  `;
59
59
  }
60
60
  }
@@ -3,6 +3,7 @@ import { getIconElement, isDefinedIcon } from "./ui-library/icons.js";
3
3
  const WS_EVENT_NAME = "astro-dev-toolbar";
4
4
  const WS_EVENT_NAME_DEPRECATED = "astro-dev-overlay";
5
5
  const HOVER_DELAY = 2 * 1e3;
6
+ const DEVBAR_HITBOX_ABOVE = 42;
6
7
  class AstroDevOverlay extends HTMLElement {
7
8
  shadowRoot;
8
9
  delayedHideTimeout;
@@ -62,7 +63,7 @@ class AstroDevOverlay extends HTMLElement {
62
63
  pointer-events: auto;
63
64
  }
64
65
  #dev-bar-hitbox-above {
65
- height: 42px;
66
+ height: ${DEVBAR_HITBOX_ABOVE}px;
66
67
  }
67
68
  #dev-bar-hitbox-below {
68
69
  height: 16px;
@@ -131,7 +132,7 @@ class AstroDevOverlay extends HTMLElement {
131
132
  border-radius: 4px;
132
133
  padding: 4px 8px;
133
134
  position: absolute;
134
- top: 4px;
135
+ top: ${4 - DEVBAR_HITBOX_ABOVE}px;
135
136
  font-size: 14px;
136
137
  opacity: 0;
137
138
  transition: opacity 0.2s ease-in-out 0s;
@@ -423,16 +424,21 @@ class AstroDevOverlay extends HTMLElement {
423
424
  setOverlayVisible(newStatus) {
424
425
  const barContainer = this.shadowRoot.querySelector("#bar-container");
425
426
  const devBar = this.shadowRoot.querySelector("#dev-bar");
427
+ const devBarHitboxAbove = this.shadowRoot.querySelector("#dev-bar-hitbox-above");
426
428
  if (newStatus === true) {
427
429
  this.devOverlay?.removeAttribute("data-hidden");
428
430
  barContainer?.removeAttribute("inert");
429
431
  devBar?.removeAttribute("tabindex");
432
+ if (devBarHitboxAbove)
433
+ devBarHitboxAbove.style.height = "0";
430
434
  return;
431
435
  }
432
436
  if (newStatus === false) {
433
437
  this.devOverlay?.setAttribute("data-hidden", "");
434
438
  barContainer?.setAttribute("inert", "");
435
439
  devBar?.setAttribute("tabindex", "0");
440
+ if (devBarHitboxAbove)
441
+ devBarHitboxAbove.style.height = `${DEVBAR_HITBOX_ABOVE}px`;
436
442
  return;
437
443
  }
438
444
  }
@@ -10,7 +10,12 @@ function baseMiddleware(settings, logger) {
10
10
  const devRootReplacement = devRoot.endsWith("/") ? "/" : "";
11
11
  return function devBaseMiddleware(req, res, next) {
12
12
  const url = req.url;
13
- const pathname = decodeURI(new URL(url, "http://localhost").pathname);
13
+ let pathname;
14
+ try {
15
+ pathname = decodeURI(new URL(url, "http://localhost").pathname);
16
+ } catch (e) {
17
+ return next(e);
18
+ }
14
19
  if (pathname.startsWith(devRoot)) {
15
20
  req.url = url.replace(devRoot, devRootReplacement);
16
21
  return next();
@@ -1,5 +1,5 @@
1
1
  import { collectErrorMetadata } from "../core/errors/dev/index.js";
2
- import { createSafeError } from "../core/errors/index.js";
2
+ import { createSafeError, AstroErrorData } from "../core/errors/index.js";
3
3
  import { formatErrorMessage } from "../core/messages.js";
4
4
  import { eventError, telemetry } from "../events/index.js";
5
5
  function recordServerError(loader, config, pipeline, _err) {
@@ -9,7 +9,9 @@ function recordServerError(loader, config, pipeline, _err) {
9
9
  } catch {
10
10
  }
11
11
  const errorWithMetadata = collectErrorMetadata(err, config.root);
12
- telemetry.record(eventError({ cmd: "dev", err: errorWithMetadata, isFatal: false }));
12
+ if (errorWithMetadata.name !== AstroErrorData.UnhandledRejection.name) {
13
+ telemetry.record(eventError({ cmd: "dev", err: errorWithMetadata, isFatal: false }));
14
+ }
13
15
  pipeline.logger.error(
14
16
  null,
15
17
  formatErrorMessage(errorWithMetadata, pipeline.logger.level() === "debug")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.0.8",
3
+ "version": "4.0.9",
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",