@astrojs/cloudflare 6.0.0 → 6.1.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.
@@ -1,5 +1,5 @@
1
- @astrojs/cloudflare:build: cache hit, replaying output 8a1cfbea8c1338b8
2
- @astrojs/cloudflare:build: 
3
- @astrojs/cloudflare:build: > @astrojs/cloudflare@6.0.0 build /home/runner/work/astro/astro/packages/integrations/cloudflare
4
- @astrojs/cloudflare:build: > astro-scripts build "src/**/*.ts" && tsc
5
- @astrojs/cloudflare:build: 
1
+ @astrojs/cloudflare:build: cache hit, replaying output af3389b4b118897d
2
+ @astrojs/cloudflare:build: 
3
+ @astrojs/cloudflare:build: > @astrojs/cloudflare@6.1.1 build /home/runner/work/astro/astro/packages/integrations/cloudflare
4
+ @astrojs/cloudflare:build: > astro-scripts build "src/**/*.ts" && tsc
5
+ @astrojs/cloudflare:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @astrojs/cloudflare
2
2
 
3
+ ## 6.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#6046](https://github.com/withastro/astro/pull/6046) [`df3201165`](https://github.com/withastro/astro/commit/df320116528e00ab082396531b4deffbb0707b78) Thanks [@matthewp](https://github.com/matthewp)! - Cloudflare fix for building to directory mode
8
+
9
+ - Updated dependencies [[`41e97158b`](https://github.com/withastro/astro/commit/41e97158ba90d23d346b6e3ff6c7c14b5ecbe903), [`e779c6242`](https://github.com/withastro/astro/commit/e779c6242418d1d4102e683ca5b851b764c89688)]:
10
+ - astro@2.0.4
11
+
12
+ ## 6.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#5914](https://github.com/withastro/astro/pull/5914) [`088f5194c`](https://github.com/withastro/astro/commit/088f5194c55a6ec15b2eaf2cfb97f9ef45a24a33) Thanks [@AngusMorton](https://github.com/AngusMorton)! - Re-enable streaming in Cloudflare Pages.
17
+
18
+ ### Patch Changes
19
+
20
+ - [#5993](https://github.com/withastro/astro/pull/5993) [`9855db676`](https://github.com/withastro/astro/commit/9855db676e61ad616c64382adeaa8c74de05f7e1) Thanks [@matthewp](https://github.com/matthewp)! - Support for prerendering in the Cloudflare integration
21
+
22
+ This fixes prerendering in the Cloudflare adapter. Now any prerendered routes are added to the `_routes.json` config so that the worker script is skipped for those routes.
23
+
24
+ - Updated dependencies [[`b53e0717b`](https://github.com/withastro/astro/commit/b53e0717b7f6b042baaeec7f87999e99c76c031c), [`60b32d585`](https://github.com/withastro/astro/commit/60b32d58565d87e87573eb268408293fc28ec657), [`883e0cc29`](https://github.com/withastro/astro/commit/883e0cc29968d51ed6c7515be035a40b28bafdad), [`dabce6b8c`](https://github.com/withastro/astro/commit/dabce6b8c684f851c3535f8acead06cbef6dce2a), [`aedf23f85`](https://github.com/withastro/astro/commit/aedf23f8582e32a6b94b81ddba9b323831f2b22a)]:
25
+ - astro@2.0.2
26
+
3
27
  ## 6.0.0
4
28
 
5
29
  ### Major Changes
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import esbuild from "esbuild";
2
2
  import * as fs from "fs";
3
3
  import * as os from "os";
4
4
  import glob from "tiny-glob";
5
- import { fileURLToPath } from "url";
5
+ import { fileURLToPath, pathToFileURL } from "url";
6
6
  function getAdapter(isModeDirectory) {
7
7
  return isModeDirectory ? {
8
8
  name: "@astrojs/cloudflare",
@@ -31,7 +31,7 @@ function createIntegration(args) {
31
31
  build: {
32
32
  client: new URL(`.${config.base}`, config.outDir),
33
33
  server: new URL(`.${SERVER_BUILD_FOLDER}`, config.outDir),
34
- serverEntry: "_worker.js"
34
+ serverEntry: "_worker.mjs"
35
35
  }
36
36
  });
37
37
  },
@@ -66,8 +66,11 @@ function createIntegration(args) {
66
66
  vite.ssr.target = vite.ssr.target || "webworker";
67
67
  }
68
68
  },
69
- "astro:build:done": async () => {
70
- const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server)), entryUrl = new URL(_buildConfig.serverEntry, _config.outDir), buildPath = fileURLToPath(entryUrl);
69
+ "astro:build:done": async ({ pages }) => {
70
+ const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server));
71
+ const entryUrl = new URL(_buildConfig.serverEntry, _config.outDir);
72
+ const buildPath = fileURLToPath(entryUrl);
73
+ const finalBuildUrl = pathToFileURL(buildPath.replace(/\.mjs$/, ".js"));
71
74
  await esbuild.build({
72
75
  target: "es2020",
73
76
  platform: "browser",
@@ -81,6 +84,7 @@ function createIntegration(args) {
81
84
  js: SHIM
82
85
  }
83
86
  });
87
+ await fs.promises.rename(buildPath, finalBuildUrl);
84
88
  const serverUrl = new URL(_buildConfig.server);
85
89
  await fs.promises.rm(serverUrl, { recursive: true, force: true });
86
90
  const cloudflareSpecialFiles = ["_headers", "_redirects", "_routes.json"];
@@ -101,6 +105,9 @@ function createIntegration(args) {
101
105
  cwd: fileURLToPath(_config.outDir),
102
106
  filesOnly: true
103
107
  })).filter((file) => cloudflareSpecialFiles.indexOf(file) < 0).map((file) => `/${file}`);
108
+ for (let page of pages) {
109
+ staticPathList.push(prependForwardSlash(page.pathname));
110
+ }
104
111
  const redirectsExists = await fs.promises.stat(new URL("./_redirects", _config.outDir)).then((stat) => stat.isFile()).catch(() => false);
105
112
  if (redirectsExists) {
106
113
  const redirects = (await fs.promises.readFile(new URL("./_redirects", _config.outDir), "utf-8")).split(os.EOL).map((line) => {
@@ -134,12 +141,15 @@ function createIntegration(args) {
134
141
  const functionsUrl = new URL(`file://${process.cwd()}/functions/`);
135
142
  await fs.promises.mkdir(functionsUrl, { recursive: true });
136
143
  const directoryUrl = new URL("[[path]].js", functionsUrl);
137
- await fs.promises.rename(entryUrl, directoryUrl);
144
+ await fs.promises.rename(finalBuildUrl, directoryUrl);
138
145
  }
139
146
  }
140
147
  }
141
148
  };
142
149
  }
150
+ function prependForwardSlash(path) {
151
+ return path[0] === "/" ? path : "/" + path;
152
+ }
143
153
  export {
144
154
  createIntegration as default,
145
155
  getAdapter
@@ -1,8 +1,10 @@
1
1
  import { App } from "astro/app";
2
- import { getProcessEnvProxy } from "./util.js";
3
- process.env = getProcessEnvProxy();
2
+ import { getProcessEnvProxy, isNode } from "./util.js";
3
+ if (!isNode) {
4
+ process.env = getProcessEnvProxy();
5
+ }
4
6
  function createExports(manifest) {
5
- const app = new App(manifest, false);
7
+ const app = new App(manifest);
6
8
  const fetch = async (request, env, context) => {
7
9
  process.env = env;
8
10
  const { pathname } = new URL(request.url);
@@ -1,8 +1,10 @@
1
1
  import { App } from "astro/app";
2
- import { getProcessEnvProxy } from "./util.js";
3
- process.env = getProcessEnvProxy();
2
+ import { getProcessEnvProxy, isNode } from "./util.js";
3
+ if (!isNode) {
4
+ process.env = getProcessEnvProxy();
5
+ }
4
6
  function createExports(manifest) {
5
- const app = new App(manifest, false);
7
+ const app = new App(manifest);
6
8
  const onRequest = async ({
7
9
  request,
8
10
  next,
package/dist/util.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export declare const isNode: boolean;
1
2
  export declare function getProcessEnvProxy(): {};
package/dist/util.js CHANGED
@@ -1,3 +1,4 @@
1
+ const isNode = typeof process === "object" && Object.prototype.toString.call(process) === "[object process]";
1
2
  function getProcessEnvProxy() {
2
3
  return new Proxy(
3
4
  {},
@@ -11,5 +12,6 @@ function getProcessEnvProxy() {
11
12
  );
12
13
  }
13
14
  export {
14
- getProcessEnvProxy
15
+ getProcessEnvProxy,
16
+ isNode
15
17
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/cloudflare",
3
3
  "description": "Deploy your site to cloudflare workers or cloudflare pages",
4
- "version": "6.0.0",
4
+ "version": "6.1.1",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -32,10 +32,10 @@
32
32
  "tiny-glob": "^0.2.9"
33
33
  },
34
34
  "peerDependencies": {
35
- "astro": "^2.0.0"
35
+ "astro": "^2.0.4"
36
36
  },
37
37
  "devDependencies": {
38
- "astro": "2.0.0",
38
+ "astro": "2.0.4",
39
39
  "astro-scripts": "0.0.10",
40
40
  "chai": "^4.3.6",
41
41
  "cheerio": "^1.0.0-rc.11",
package/src/index.ts CHANGED
@@ -3,7 +3,7 @@ import esbuild from 'esbuild';
3
3
  import * as fs from 'fs';
4
4
  import * as os from 'os';
5
5
  import glob from 'tiny-glob';
6
- import { fileURLToPath } from 'url';
6
+ import { fileURLToPath, pathToFileURL } from 'url';
7
7
 
8
8
  type Options = {
9
9
  mode: 'directory' | 'advanced';
@@ -49,7 +49,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
49
49
  build: {
50
50
  client: new URL(`.${config.base}`, config.outDir),
51
51
  server: new URL(`.${SERVER_BUILD_FOLDER}`, config.outDir),
52
- serverEntry: '_worker.js',
52
+ serverEntry: '_worker.mjs',
53
53
  },
54
54
  });
55
55
  },
@@ -88,10 +88,13 @@ export default function createIntegration(args?: Options): AstroIntegration {
88
88
  vite.ssr.target = vite.ssr.target || 'webworker';
89
89
  }
90
90
  },
91
- 'astro:build:done': async () => {
92
- const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server)),
93
- entryUrl = new URL(_buildConfig.serverEntry, _config.outDir),
94
- buildPath = fileURLToPath(entryUrl);
91
+ 'astro:build:done': async ({ pages }) => {
92
+ const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server));
93
+ const entryUrl = new URL(_buildConfig.serverEntry, _config.outDir);
94
+ const buildPath = fileURLToPath(entryUrl);
95
+ // A URL for the final build path after renaming
96
+ const finalBuildUrl = pathToFileURL(buildPath.replace(/\.mjs$/, '.js'));
97
+
95
98
  await esbuild.build({
96
99
  target: 'es2020',
97
100
  platform: 'browser',
@@ -106,6 +109,9 @@ export default function createIntegration(args?: Options): AstroIntegration {
106
109
  },
107
110
  });
108
111
 
112
+ // Rename to worker.js
113
+ await fs.promises.rename(buildPath, finalBuildUrl);
114
+
109
115
  // throw the server folder in the bin
110
116
  const serverUrl = new URL(_buildConfig.server);
111
117
  await fs.promises.rm(serverUrl, { recursive: true, force: true });
@@ -143,6 +149,10 @@ export default function createIntegration(args?: Options): AstroIntegration {
143
149
  .filter((file: string) => cloudflareSpecialFiles.indexOf(file) < 0)
144
150
  .map((file: string) => `/${file}`);
145
151
 
152
+ for (let page of pages) {
153
+ staticPathList.push(prependForwardSlash(page.pathname));
154
+ }
155
+
146
156
  const redirectsExists = await fs.promises
147
157
  .stat(new URL('./_redirects', _config.outDir))
148
158
  .then((stat) => stat.isFile())
@@ -196,9 +206,13 @@ export default function createIntegration(args?: Options): AstroIntegration {
196
206
  const functionsUrl = new URL(`file://${process.cwd()}/functions/`);
197
207
  await fs.promises.mkdir(functionsUrl, { recursive: true });
198
208
  const directoryUrl = new URL('[[path]].js', functionsUrl);
199
- await fs.promises.rename(entryUrl, directoryUrl);
209
+ await fs.promises.rename(finalBuildUrl, directoryUrl);
200
210
  }
201
211
  },
202
212
  },
203
213
  };
204
214
  }
215
+
216
+ function prependForwardSlash(path: string) {
217
+ return path[0] === '/' ? path : '/' + path;
218
+ }
@@ -1,8 +1,10 @@
1
1
  import type { SSRManifest } from 'astro';
2
2
  import { App } from 'astro/app';
3
- import { getProcessEnvProxy } from './util.js';
3
+ import { getProcessEnvProxy, isNode } from './util.js';
4
4
 
5
- process.env = getProcessEnvProxy();
5
+ if (!isNode) {
6
+ process.env = getProcessEnvProxy();
7
+ }
6
8
 
7
9
  type Env = {
8
10
  ASSETS: { fetch: (req: Request) => Promise<Response> };
@@ -10,7 +12,7 @@ type Env = {
10
12
  };
11
13
 
12
14
  export function createExports(manifest: SSRManifest) {
13
- const app = new App(manifest, false);
15
+ const app = new App(manifest);
14
16
 
15
17
  const fetch = async (request: Request, env: Env, context: any) => {
16
18
  process.env = env as any;
@@ -1,11 +1,13 @@
1
1
  import type { SSRManifest } from 'astro';
2
2
  import { App } from 'astro/app';
3
- import { getProcessEnvProxy } from './util.js';
3
+ import { getProcessEnvProxy, isNode } from './util.js';
4
4
 
5
- process.env = getProcessEnvProxy();
5
+ if (!isNode) {
6
+ process.env = getProcessEnvProxy();
7
+ }
6
8
 
7
9
  export function createExports(manifest: SSRManifest) {
8
- const app = new App(manifest, false);
10
+ const app = new App(manifest);
9
11
 
10
12
  const onRequest = async ({
11
13
  request,
package/src/util.ts CHANGED
@@ -1,3 +1,6 @@
1
+ export const isNode =
2
+ typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]';
3
+
1
4
  export function getProcessEnvProxy() {
2
5
  return new Proxy(
3
6
  {},
@@ -0,0 +1,20 @@
1
+ import { loadFixture, runCLI } from './test-utils.js';
2
+ import { expect } from 'chai';
3
+ import * as cheerio from 'cheerio';
4
+ import cloudflare from '../dist/index.js';
5
+
6
+ describe('mode: "directory"', () => {
7
+ /** @type {import('./test-utils').Fixture} */
8
+ let fixture;
9
+
10
+ before(async () => {
11
+ fixture = await loadFixture({
12
+ root: './fixtures/basics/',
13
+ adapter: cloudflare({ mode: 'directory' }),
14
+ });
15
+ });
16
+
17
+ it('Builds', async () => {
18
+ await fixture.build();
19
+ });
20
+ });
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from 'astro/config';
2
+ import cloudflare from '@astrojs/cloudflare';
3
+
4
+ export default defineConfig({
5
+ adapter: cloudflare(),
6
+ output: 'server',
7
+ });
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="$NODE_PATH:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
15
+ else
16
+ exec node "$basedir/../../../../../../../astro/astro.js" "$@"
17
+ fi
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@test/astro-cloudflare-prerender",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "dependencies": {
6
+ "@astrojs/cloudflare": "workspace:*",
7
+ "astro": "workspace:*"
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>Testing</title>
4
+ </head>
5
+ <body>
6
+ <h1>Testing</h1>
7
+ </body>
8
+ </html>
@@ -0,0 +1,11 @@
1
+ ---
2
+ export const prerender = true;
3
+ ---
4
+ <html>
5
+ <head>
6
+ <title>Testing</title>
7
+ </head>
8
+ <body>
9
+ <h1>Testing</h1>
10
+ </body>
11
+ </html>
@@ -0,0 +1,19 @@
1
+ import { loadFixture } from './test-utils.js';
2
+ import { expect } from 'chai';
3
+
4
+ describe('Prerendering', () => {
5
+ /** @type {import('./test-utils').Fixture} */
6
+ let fixture;
7
+
8
+ before(async () => {
9
+ fixture = await loadFixture({
10
+ root: './fixtures/prerender/',
11
+ });
12
+ await fixture.build();
13
+ });
14
+
15
+ it('includes prerendered routes in the routes.json config', async () => {
16
+ const routes = JSON.parse(await fixture.readFile('/_routes.json'));
17
+ expect(routes.exclude).to.include('/one/');
18
+ });
19
+ });