astro 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -187,7 +187,7 @@ async function runCommand(cmd, flags) {
187
187
  });
188
188
  }
189
189
  case "build": {
190
- return await build(settings, { logging, telemetry });
190
+ return await build(settings, { ...flags, logging, telemetry });
191
191
  }
192
192
  case "check": {
193
193
  const ret = await check(settings);
@@ -64,6 +64,7 @@ class AstroBuilder {
64
64
  serverEntry: "entry.mjs"
65
65
  };
66
66
  await runHookBuildStart({ config: this.settings.config, buildConfig, logging: this.logging });
67
+ this.validateConfig();
67
68
  info(this.logging, "build", `output target: ${colors.green(this.settings.config.output)}`);
68
69
  if (this.settings.adapter) {
69
70
  info(this.logging, "build", `deploy adapter: ${colors.green(this.settings.adapter.name)}`);
@@ -129,6 +130,14 @@ class AstroBuilder {
129
130
  throw fixViteErrorMessage(_err);
130
131
  }
131
132
  }
133
+ validateConfig() {
134
+ const { config } = this.settings;
135
+ if (config.outDir.toString() === config.root.toString()) {
136
+ throw new Error(
137
+ `the outDir cannot be the root folder. Please build to a folder such as dist.`
138
+ );
139
+ }
140
+ }
132
141
  async printStats({
133
142
  logging,
134
143
  timeStart,
@@ -1,6 +1,7 @@
1
1
  import glob from "fast-glob";
2
2
  import fs from "fs";
3
3
  import { bgGreen, bgMagenta, black, dim } from "kleur/colors";
4
+ import path from "path";
4
5
  import { fileURLToPath } from "url";
5
6
  import * as vite from "vite";
6
7
  import { createBuildInternals } from "../../core/build/internal.js";
@@ -82,8 +83,8 @@ async function ssrBuild(opts, internals, input) {
82
83
  const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(settings.config.outDir);
83
84
  const viteBuildConfig = {
84
85
  ...viteConfig,
86
+ mode: viteConfig.mode || "production",
85
87
  logLevel: opts.viteConfig.logLevel ?? "error",
86
- mode: "production",
87
88
  build: {
88
89
  target: "esnext",
89
90
  ...viteConfig.build,
@@ -147,8 +148,8 @@ async function clientBuild(opts, internals, input) {
147
148
  ${bgGreen(black(" building client "))}`);
148
149
  const viteBuildConfig = {
149
150
  ...viteConfig,
151
+ mode: viteConfig.mode || "production",
150
152
  logLevel: "info",
151
- mode: "production",
152
153
  build: {
153
154
  target: "esnext",
154
155
  ...viteConfig.build,
@@ -194,19 +195,38 @@ ${bgGreen(black(" building client "))}`);
194
195
  }
195
196
  async function cleanSsrOutput(opts) {
196
197
  const out = getOutDirWithinCwd(opts.settings.config.outDir);
198
+ const files = await glob("**/*.mjs", {
199
+ cwd: fileURLToPath(out)
200
+ });
201
+ if (files.length) {
202
+ await Promise.all(
203
+ files.map(async (filename) => {
204
+ const url = new URL(filename, out);
205
+ await fs.promises.rm(url);
206
+ })
207
+ );
208
+ const directories = /* @__PURE__ */ new Set();
209
+ files.forEach((i) => {
210
+ const splitFilePath = i.split(path.sep);
211
+ if (splitFilePath.length > 1) {
212
+ directories.add(splitFilePath[0]);
213
+ }
214
+ });
215
+ await Promise.all(
216
+ Array.from(directories).map(async (filename) => {
217
+ const url = new URL(filename, out);
218
+ const folder = await fs.promises.readdir(url);
219
+ if (!folder.length) {
220
+ await fs.promises.rmdir(url, { recursive: true });
221
+ }
222
+ })
223
+ );
224
+ }
197
225
  if (out.toString() !== opts.settings.config.outDir.toString()) {
226
+ copyFiles(out, opts.settings.config.outDir);
198
227
  await fs.promises.rm(out, { recursive: true });
199
228
  return;
200
229
  }
201
- const files = await glob("**/*.mjs", {
202
- cwd: fileURLToPath(out)
203
- });
204
- await Promise.all(
205
- files.map(async (filename) => {
206
- const url = new URL(filename, out);
207
- await fs.promises.rm(url);
208
- })
209
- );
210
230
  }
211
231
  async function copyFiles(fromFolder, toFolder) {
212
232
  const files = await glob("**/*", {
@@ -46,7 +46,7 @@ async function dev(settings, options) {
46
46
  isRestart
47
47
  })
48
48
  );
49
- const currentVersion = "1.3.0";
49
+ const currentVersion = "1.3.1";
50
50
  if (currentVersion.includes("-")) {
51
51
  warn(options.logging, null, msg.prerelease({ currentVersion }));
52
52
  }
@@ -8,7 +8,7 @@ async function call(mod, opts) {
8
8
  );
9
9
  }
10
10
  const [params] = paramsAndPropsResp;
11
- const response = await renderEndpoint(mod, opts.request, params);
11
+ const response = await renderEndpoint(mod, opts.request, params, opts.ssr);
12
12
  if (response instanceof Response) {
13
13
  return {
14
14
  type: "response",
@@ -47,7 +47,7 @@ function serverStart({
47
47
  site,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "1.3.0";
50
+ const version = "1.3.1";
51
51
  const rootPath = site ? site.pathname : "/";
52
52
  const localPrefix = `${dim("\u2503")} Local `;
53
53
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -97,12 +97,12 @@ function resolveServerUrls({
97
97
  const ipv4Networks = Object.values(os.networkInterfaces()).flatMap((networkInterface) => networkInterface ?? []).filter(
98
98
  (networkInterface) => (networkInterface == null ? void 0 : networkInterface.address) && (networkInterface == null ? void 0 : networkInterface.family) === (nodeVersion < 18 || nodeVersion >= 18.4 ? "IPv4" : 4)
99
99
  );
100
- for (let { address: address2 } of ipv4Networks) {
101
- if (address2.includes("127.0.0.1")) {
102
- const displayAddress = address2.replace("127.0.0.1", localAddress);
100
+ for (let { address: ipv4Address } of ipv4Networks) {
101
+ if (ipv4Address.includes("127.0.0.1")) {
102
+ const displayAddress = ipv4Address.replace("127.0.0.1", localAddress);
103
103
  local = toDisplayUrl(displayAddress);
104
104
  } else {
105
- network = toDisplayUrl(address2);
105
+ network = toDisplayUrl(ipv4Address);
106
106
  }
107
107
  }
108
108
  }
@@ -250,7 +250,7 @@ function printHelp({
250
250
  message.push(
251
251
  linebreak(),
252
252
  ` ${bgGreen(black(` ${commandName} `))} ${green(
253
- `v${"1.3.0"}`
253
+ `v${"1.3.1"}`
254
254
  )} ${headline}`
255
255
  );
256
256
  }
@@ -1,3 +1,4 @@
1
+ export declare function appendExtension(path: string, extension: string): string;
1
2
  export declare function appendForwardSlash(path: string): string;
2
3
  export declare function prependForwardSlash(path: string): string;
3
4
  export declare function removeTrailingForwardSlash(path: string): string;
package/dist/core/path.js CHANGED
@@ -1,3 +1,6 @@
1
+ function appendExtension(path, extension) {
2
+ return path + "." + extension;
3
+ }
1
4
  function appendForwardSlash(path) {
2
5
  return path.endsWith("/") ? path : path + "/";
3
6
  }
@@ -41,6 +44,7 @@ function removeFileExtension(path) {
41
44
  return idx === -1 ? path : path.slice(0, idx);
42
45
  }
43
46
  export {
47
+ appendExtension,
44
48
  appendForwardSlash,
45
49
  isRelativePath,
46
50
  joinPaths,
@@ -62,14 +62,11 @@ class RouteCache {
62
62
  }
63
63
  function findPathItemByKey(staticPaths, params) {
64
64
  const paramsKey = stringifyParams(params);
65
- let matchedStaticPath = staticPaths.keyed.get(paramsKey);
65
+ const matchedStaticPath = staticPaths.keyed.get(paramsKey);
66
66
  if (matchedStaticPath) {
67
67
  return matchedStaticPath;
68
68
  }
69
69
  debug("findPathItemByKey", `Unexpected cache miss looking for ${paramsKey}`);
70
- matchedStaticPath = staticPaths.find(
71
- ({ params: _params }) => JSON.stringify(_params) === paramsKey
72
- );
73
70
  }
74
71
  export {
75
72
  RouteCache,
@@ -17,7 +17,7 @@ function stringifyParams(params) {
17
17
  const validatedParams = Object.entries(params).reduce((acc, next) => {
18
18
  validateGetStaticPathsParameter(next);
19
19
  const [key, value] = next;
20
- acc[key] = `${value}`;
20
+ acc[key] = typeof value === "undefined" ? void 0 : `${value}`;
21
21
  return acc;
22
22
  }, {});
23
23
  return JSON.stringify(validatedParams, Object.keys(params).sort());
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.3.0";
8
+ const ASTRO_VERSION = "1.3.1";
9
9
  function isObject(value) {
10
10
  return typeof value === "object" && value != null;
11
11
  }
@@ -87,7 +87,7 @@ function resolveDependency(dep, projectRoot) {
87
87
  return pathToFileURL(resolved).toString();
88
88
  }
89
89
  function viteID(filePath) {
90
- return slash(fileURLToPath(filePath) + filePath.search);
90
+ return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, "/");
91
91
  }
92
92
  const VALID_ID_PREFIX = `/@id/`;
93
93
  function unwrapId(id) {
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.3.0";
1
+ const ASTRO_VERSION = "1.3.1";
2
2
  function createDeprecatedFetchContentFn() {
3
3
  return () => {
4
4
  throw new Error("Deprecated: Astro.fetchContent() has been replaced with Astro.glob().");
@@ -1,3 +1,3 @@
1
1
  import type { EndpointHandler, Params } from '../../@types/astro';
2
2
  /** Renders an endpoint request to completion, returning the body. */
3
- export declare function renderEndpoint(mod: EndpointHandler, request: Request, params: Params): Promise<Response | import("../../@types/astro").EndpointOutput>;
3
+ export declare function renderEndpoint(mod: EndpointHandler, request: Request, params: Params, ssr?: boolean): Promise<Response | import("../../@types/astro").EndpointOutput>;
@@ -10,10 +10,14 @@ function getHandlerFromModule(mod, method) {
10
10
  }
11
11
  return void 0;
12
12
  }
13
- async function renderEndpoint(mod, request, params) {
13
+ async function renderEndpoint(mod, request, params, ssr) {
14
14
  var _a;
15
15
  const chosenMethod = (_a = request.method) == null ? void 0 : _a.toLowerCase();
16
16
  const handler = getHandlerFromModule(mod, chosenMethod);
17
+ if (!ssr && ssr === false && chosenMethod && chosenMethod !== "get") {
18
+ console.warn(`
19
+ ${chosenMethod} requests are not available when building a static site. Update your config to output: 'server' to handle ${chosenMethod} requests.`);
20
+ }
17
21
  if (!handler || typeof handler !== "function") {
18
22
  let response = new Response(null, {
19
23
  status: 404,
@@ -1,7 +1,6 @@
1
1
  import { escape } from 'html-escaper';
2
2
  export declare const escapeHTML: typeof escape;
3
3
  export declare class HTMLBytes extends Uint8Array {
4
- get [Symbol.toStringTag](): string;
5
4
  }
6
5
  /**
7
6
  * A "blessed" extension of String that tells Astro that the string
@@ -1,10 +1,12 @@
1
1
  import { escape } from "html-escaper";
2
2
  const escapeHTML = escape;
3
3
  class HTMLBytes extends Uint8Array {
4
- get [Symbol.toStringTag]() {
4
+ }
5
+ Object.defineProperty(HTMLBytes.prototype, Symbol.toStringTag, {
6
+ get() {
5
7
  return "HTMLBytes";
6
8
  }
7
- }
9
+ });
8
10
  class HTMLString extends String {
9
11
  get [Symbol.toStringTag]() {
10
12
  return "HTMLString";
@@ -59,7 +59,9 @@ function extractDirectives(inputProps) {
59
59
  }
60
60
  }
61
61
  } else if (key === "class:list") {
62
- extracted.props[key.slice(0, -5)] = serializeListValue(value);
62
+ if (value) {
63
+ extracted.props[key.slice(0, -5)] = serializeListValue(value);
64
+ }
63
65
  } else {
64
66
  extracted.props[key] = value;
65
67
  }
@@ -88,9 +88,11 @@ async function renderPage(result, componentFactory, props, children, streaming)
88
88
  }
89
89
  let response = createResponse(body, { ...init, headers });
90
90
  return response;
91
- } else {
92
- return factoryReturnValue;
93
91
  }
92
+ if (!(factoryReturnValue instanceof Response)) {
93
+ throw new Error("Only instance of Response can be returned from an Astro file");
94
+ }
95
+ return factoryReturnValue;
94
96
  }
95
97
  export {
96
98
  renderPage
@@ -5,7 +5,7 @@ const htmlBooleanAttributes = /^(allowfullscreen|async|autofocus|autoplay|contro
5
5
  const htmlEnumAttributes = /^(contenteditable|draggable|spellcheck|value)$/i;
6
6
  const svgEnumAttributes = /^(autoReverse|externalResourcesRequired|focusable|preserveAlpha)$/i;
7
7
  const STATIC_DIRECTIVES = /* @__PURE__ */ new Set(["set:html", "set:text"]);
8
- const toIdent = (k) => k.trim().replace(/(?:(?<!^)\b\w|\s+|[^\w]+)/g, (match, index) => {
8
+ const toIdent = (k) => k.trim().replace(/(?:(?!^)\b\w|\s+|[^\w]+)/g, (match, index) => {
9
9
  if (/[^\w]|\s/.test(match))
10
10
  return "";
11
11
  return index === 0 ? match : match.toUpperCase();
@@ -16,7 +16,7 @@ const toStyleString = (obj) => Object.entries(obj).map(([k, v]) => `${kebab(k)}:
16
16
  function defineScriptVars(vars) {
17
17
  let output = "";
18
18
  for (const [key, value] of Object.entries(vars)) {
19
- output += `let ${toIdent(key)} = ${JSON.stringify(value)};
19
+ output += `const ${toIdent(key)} = ${JSON.stringify(value)};
20
20
  `;
21
21
  }
22
22
  return markHTMLString(output);
@@ -3,9 +3,10 @@ import { invalidateCompilation, isCached } from "../core/compile/index.js";
3
3
  import { info } from "../core/logger/core.js";
4
4
  import * as msg from "../core/messages.js";
5
5
  import { isAstroScript } from "./query.js";
6
- const PKG_PREFIX = new URL("../../", import.meta.url);
6
+ const PKG_PREFIX = fileURLToPath(new URL("../../", import.meta.url));
7
+ const E2E_PREFIX = fileURLToPath(new URL("../../e2e", import.meta.url));
7
8
  const isPkgFile = (id) => {
8
- return (id == null ? void 0 : id.startsWith(fileURLToPath(PKG_PREFIX))) || (id == null ? void 0 : id.startsWith(PKG_PREFIX.pathname));
9
+ return id && id.startsWith(PKG_PREFIX) && !id.startsWith(E2E_PREFIX);
9
10
  };
10
11
  async function handleHotUpdate(ctx, { config, logging, compile }) {
11
12
  let isStyleOnlyChange = false;
@@ -1,6 +1,8 @@
1
1
  import { renderMarkdown } from "@astrojs/markdown-remark";
2
2
  import fs from "fs";
3
3
  import matter from "gray-matter";
4
+ import { fileURLToPath } from "node:url";
5
+ import { normalizePath } from "vite";
4
6
  import { collectErrorMetadata } from "../core/errors.js";
5
7
  import { warn } from "../core/logger/core.js";
6
8
  import { getFileInfo, safelyGetAstroData } from "../vite-plugin-utils/index.js";
@@ -12,6 +14,9 @@ function safeMatter(source, id) {
12
14
  throw collectErrorMetadata(e);
13
15
  }
14
16
  }
17
+ const astroJsxRuntimeModulePath = normalizePath(
18
+ fileURLToPath(new URL("../jsx-runtime/index.js", import.meta.url))
19
+ );
15
20
  function markdown({ settings, logging }) {
16
21
  return {
17
22
  enforce: "pre",
@@ -42,7 +47,7 @@ function markdown({ settings, logging }) {
42
47
  );
43
48
  }
44
49
  const code = escapeViteEnvReferences(`
45
- import { Fragment, jsx as h } from 'astro/jsx-runtime';
50
+ import { Fragment, jsx as h } from '${astroJsxRuntimeModulePath}';
46
51
  ${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
47
52
 
48
53
  const html = ${JSON.stringify(html)};
@@ -1,4 +1,4 @@
1
- import { appendForwardSlash } from "../core/path.js";
1
+ import { appendExtension, appendForwardSlash } from "../core/path.js";
2
2
  function getFileInfo(id, config) {
3
3
  const sitePathname = appendForwardSlash(
4
4
  config.site ? new URL(config.base, config.site).pathname : config.base
@@ -8,6 +8,9 @@ function getFileInfo(id, config) {
8
8
  if (fileUrl && config.trailingSlash === "always") {
9
9
  fileUrl = appendForwardSlash(fileUrl);
10
10
  }
11
+ if (fileUrl && config.build.format === "file") {
12
+ fileUrl = appendExtension(fileUrl, "html");
13
+ }
11
14
  return { fileId, fileUrl };
12
15
  }
13
16
  function isValidAstroData(obj) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.3.0",
3
+ "version": "1.3.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",
@@ -86,7 +86,7 @@
86
86
  "@astrojs/language-server": "^0.26.2",
87
87
  "@astrojs/markdown-remark": "^1.1.2",
88
88
  "@astrojs/telemetry": "^1.0.0",
89
- "@astrojs/webapi": "^1.0.0",
89
+ "@astrojs/webapi": "^1.1.0",
90
90
  "@babel/core": "^7.18.2",
91
91
  "@babel/generator": "^7.18.2",
92
92
  "@babel/parser": "^7.18.4",
@@ -161,7 +161,7 @@
161
161
  "@types/send": "^0.17.1",
162
162
  "@types/unist": "^2.0.6",
163
163
  "ast-types": "^0.14.2",
164
- "astro-scripts": "0.0.7",
164
+ "astro-scripts": "0.0.8",
165
165
  "chai": "^4.3.6",
166
166
  "cheerio": "^1.0.0-rc.11",
167
167
  "mocha": "^9.2.2",