@astrojs/cloudflare 13.3.0 → 13.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.
@@ -88,7 +88,7 @@ function serverStart({
88
88
  host,
89
89
  base
90
90
  }) {
91
- const version = "13.3.0";
91
+ const version = "13.3.1";
92
92
  const localPrefix = `${colors.dim("\u2503")} Local `;
93
93
  const networkPrefix = `${colors.dim("\u2503")} Network `;
94
94
  const emptyPrefix = " ".repeat(11);
@@ -1,5 +1,12 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---/;
3
+ const RETURN_REPLACE_RE = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|`(?:[^`\\]|\\.)*`|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')|(?<!\.)\breturn(\s*;|\b)/g;
4
+ function replaceTopLevelReturns(code) {
5
+ return code.replace(RETURN_REPLACE_RE, (_match, skip, tail) => {
6
+ if (skip !== void 0) return skip;
7
+ return tail.trim() === ";" ? "throw 0;" : "throw ";
8
+ });
9
+ }
3
10
  function astroFrontmatterScanPlugin() {
4
11
  return {
5
12
  name: "astro-frontmatter-scan",
@@ -9,7 +16,7 @@ function astroFrontmatterScanPlugin() {
9
16
  const code = await readFile(args.path, "utf-8");
10
17
  const frontmatterMatch = FRONTMATTER_RE.exec(code);
11
18
  if (frontmatterMatch) {
12
- const contents = frontmatterMatch[1].replace(/\breturn\s*;/g, "throw 0;").replace(/\breturn\b/g, "throw ");
19
+ const contents = replaceTopLevelReturns(frontmatterMatch[1]);
13
20
  return {
14
21
  contents: contents + "\nexport default {}",
15
22
  loader: "ts"
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createReadStream, existsSync, readFileSync } from "node:fs";
2
- import { appendFile, stat } from "node:fs/promises";
2
+ import { appendFile, rename, stat } from "node:fs/promises";
3
3
  import { createInterface } from "node:readline/promises";
4
4
  import { removeLeadingForwardSlash } from "@astrojs/internal-helpers/path";
5
5
  import { createRedirectsFromAstroRoutes, printAsRedirects } from "@astrojs/underscore-redirects";
@@ -57,6 +57,7 @@ function createIntegration({
57
57
  ...cloudflareOptions
58
58
  } = {}) {
59
59
  let _config;
60
+ let _originalClientDir;
60
61
  let _routes;
61
62
  let _isFullyStatic = false;
62
63
  let cfPluginConfig;
@@ -256,6 +257,10 @@ function createIntegration({
256
257
  },
257
258
  "astro:config:done": ({ setAdapter, config, injectTypes, logger }) => {
258
259
  _config = config;
260
+ _originalClientDir = new URL(config.build.client.href);
261
+ if (config.base !== "/") {
262
+ config.build.client = new URL("." + config.base + "/", config.build.client);
263
+ }
259
264
  injectTypes({
260
265
  filename: "cloudflare.d.ts",
261
266
  content: '/// <reference types="@astrojs/cloudflare/types.d.ts" />'
@@ -330,9 +335,20 @@ function createIntegration({
330
335
  }
331
336
  },
332
337
  "astro:build:done": async ({ dir, logger, assets }) => {
338
+ if (_config.base !== "/") {
339
+ for (const file of [".assetsignore", "_headers"]) {
340
+ try {
341
+ await rename(
342
+ new URL(`./${file}`, _config.build.client),
343
+ new URL(`./${file}`, _originalClientDir)
344
+ );
345
+ } catch {
346
+ }
347
+ }
348
+ }
333
349
  let redirectsExists = false;
334
350
  try {
335
- const redirectsStat = await stat(new URL("./_redirects", _config.build.client));
351
+ const redirectsStat = await stat(new URL("./_redirects", _originalClientDir));
336
352
  if (redirectsStat.isFile()) {
337
353
  redirectsExists = true;
338
354
  }
@@ -342,7 +358,7 @@ function createIntegration({
342
358
  const redirects = [];
343
359
  if (redirectsExists) {
344
360
  const rl = createInterface({
345
- input: createReadStream(new URL("./_redirects", _config.build.client)),
361
+ input: createReadStream(new URL("./_redirects", _originalClientDir)),
346
362
  crlfDelay: Number.POSITIVE_INFINITY
347
363
  });
348
364
  for await (const line of rl) {
@@ -370,7 +386,7 @@ function createIntegration({
370
386
  if (!trueRedirects.empty()) {
371
387
  try {
372
388
  await appendFile(
373
- new URL("./_redirects", _config.build.client),
389
+ new URL("./_redirects", _originalClientDir),
374
390
  printAsRedirects(trueRedirects)
375
391
  );
376
392
  } catch (_error) {
package/dist/wrangler.js CHANGED
@@ -2,6 +2,11 @@ const DEFAULT_SESSION_KV_BINDING_NAME = "SESSION";
2
2
  const DEFAULT_IMAGES_BINDING_NAME = "IMAGES";
3
3
  const DEFAULT_ASSETS_BINDING_NAME = "ASSETS";
4
4
  const DEFAULT_COMPATIBILITY_DATE = "2026-04-15";
5
+ function withSessionKVBinding(existing, sessionBinding) {
6
+ const namespaces = existing ? [...existing] : [];
7
+ namespaces.push({ binding: sessionBinding });
8
+ return namespaces;
9
+ }
5
10
  function cloudflareConfigCustomizer(options) {
6
11
  const sessionKVBindingName = options?.sessionKVBindingName ?? DEFAULT_SESSION_KV_BINDING_NAME;
7
12
  const needsSessionKVBinding = options?.needsSessionKVBinding ?? true;
@@ -13,11 +18,7 @@ function cloudflareConfigCustomizer(options) {
13
18
  );
14
19
  const hasImagesBinding = nonInheritableConfig?.images?.binding !== void 0;
15
20
  return {
16
- kv_namespaces: !needsSessionKVBinding || hasSessionBinding ? void 0 : [
17
- {
18
- binding: sessionKVBindingName
19
- }
20
- ],
21
+ kv_namespaces: !needsSessionKVBinding || hasSessionBinding ? void 0 : withSessionKVBinding(nonInheritableConfig?.kv_namespaces, sessionKVBindingName),
21
22
  images: hasImagesBinding || !imagesBindingName ? void 0 : {
22
23
  binding: imagesBindingName
23
24
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/cloudflare",
3
3
  "description": "Deploy your site to Cloudflare Workers",
4
- "version": "13.3.0",
4
+ "version": "13.3.1",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -39,8 +39,8 @@
39
39
  "piccolore": "^0.1.3",
40
40
  "tinyglobby": "^0.2.15",
41
41
  "vite": "^7.3.2",
42
- "@astrojs/underscore-redirects": "1.0.3",
43
- "@astrojs/internal-helpers": "0.9.0"
42
+ "@astrojs/internal-helpers": "0.9.0",
43
+ "@astrojs/underscore-redirects": "1.0.3"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "astro": "^6.0.0",
@@ -51,7 +51,7 @@
51
51
  "@types/node": "^25.2.2",
52
52
  "cheerio": "1.2.0",
53
53
  "devalue": "^5.6.3",
54
- "astro": "6.2.0",
54
+ "astro": "6.2.2",
55
55
  "astro-scripts": "0.0.14"
56
56
  },
57
57
  "publishConfig": {