@astrojs/cloudflare 0.3.0 → 0.4.0

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 7d2a1e1c56d7ba86
2
- @astrojs/cloudflare:build: 
3
- @astrojs/cloudflare:build: > @astrojs/cloudflare@0.3.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 709829411c5ced06
2
+ @astrojs/cloudflare:build: 
3
+ @astrojs/cloudflare:build: > @astrojs/cloudflare@0.4.0 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,15 @@
1
1
  # @astrojs/cloudflare
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#4068](https://github.com/withastro/astro/pull/4068) [`54b33d50f`](https://github.com/withastro/astro/commit/54b33d50fdb995ac056461be7e2128d911624f2d) Thanks [@matthewp](https://github.com/matthewp)! - Add explicit errors when omitting output config
8
+
9
+ ### Patch Changes
10
+
11
+ - [#4072](https://github.com/withastro/astro/pull/4072) [`a198028b0`](https://github.com/withastro/astro/commit/a198028b04234d0b8dcb0b6bcb47c5831d7a15f9) Thanks [@matthewp](https://github.com/matthewp)! - Fixes Cloudflare throwing an error for process
12
+
3
13
  ## 0.3.0
4
14
 
5
15
  ### Minor Changes
package/dist/index.js CHANGED
@@ -8,6 +8,10 @@ function getAdapter() {
8
8
  exports: ["default"]
9
9
  };
10
10
  }
11
+ const SHIM = `globalThis.process = {
12
+ argv: [],
13
+ env: {},
14
+ };`;
11
15
  function createIntegration() {
12
16
  let _config;
13
17
  let _buildConfig;
@@ -18,12 +22,10 @@ function createIntegration() {
18
22
  setAdapter(getAdapter());
19
23
  _config = config;
20
24
  if (config.output === "static") {
21
- console.warn(
22
- `[@astrojs/cloudflare] \`output: "server"\` is required to use this adapter.`
23
- );
24
- console.warn(
25
- `[@astrojs/cloudflare] Otherwise, this adapter is not required to deploy a static site to Cloudflare.`
26
- );
25
+ throw new Error(`
26
+ [@astrojs/cloudflare] \`output: "server"\` is required to use this adapter. Otherwise, this adapter is not necessary to deploy a static site to Cloudflare.
27
+
28
+ `);
27
29
  }
28
30
  },
29
31
  "astro:build:start": ({ buildConfig }) => {
@@ -61,7 +63,10 @@ function createIntegration() {
61
63
  allowOverwrite: true,
62
64
  format: "esm",
63
65
  bundle: true,
64
- minify: true
66
+ minify: true,
67
+ banner: {
68
+ js: SHIM
69
+ }
65
70
  });
66
71
  const chunksUrl = new URL("./chunks", _buildConfig.server);
67
72
  await fs.promises.rm(chunksUrl, { recursive: true, force: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/cloudflare",
3
3
  "description": "Deploy your site to cloudflare pages functions",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -22,15 +22,17 @@
22
22
  "./package.json": "./package.json"
23
23
  },
24
24
  "dependencies": {
25
- "esbuild": "^0.14.42"
25
+ "esbuild": "^0.14.42",
26
+ "wrangler": "^2.0.23"
26
27
  },
27
28
  "devDependencies": {
28
- "astro": "1.0.0-rc.1",
29
+ "astro": "1.0.0-rc.2",
29
30
  "astro-scripts": "0.0.6"
30
31
  },
31
32
  "scripts": {
32
33
  "build": "astro-scripts build \"src/**/*.ts\" && tsc",
33
34
  "build:ci": "astro-scripts build \"src/**/*.ts\"",
34
- "dev": "astro-scripts dev \"src/**/*.ts\""
35
+ "dev": "astro-scripts dev \"src/**/*.ts\"",
36
+ "test": "mocha --exit --timeout 30000 test/"
35
37
  }
36
38
  }
package/src/index.ts CHANGED
@@ -11,6 +11,11 @@ export function getAdapter(): AstroAdapter {
11
11
  };
12
12
  }
13
13
 
14
+ const SHIM = `globalThis.process = {
15
+ argv: [],
16
+ env: {},
17
+ };`;
18
+
14
19
  export default function createIntegration(): AstroIntegration {
15
20
  let _config: AstroConfig;
16
21
  let _buildConfig: BuildConfig;
@@ -23,12 +28,10 @@ export default function createIntegration(): AstroIntegration {
23
28
  _config = config;
24
29
 
25
30
  if (config.output === 'static') {
26
- console.warn(
27
- `[@astrojs/cloudflare] \`output: "server"\` is required to use this adapter.`
28
- );
29
- console.warn(
30
- `[@astrojs/cloudflare] Otherwise, this adapter is not required to deploy a static site to Cloudflare.`
31
- );
31
+ throw new Error(`
32
+ [@astrojs/cloudflare] \`output: "server"\` is required to use this adapter. Otherwise, this adapter is not necessary to deploy a static site to Cloudflare.
33
+
34
+ `);
32
35
  }
33
36
  },
34
37
  'astro:build:start': ({ buildConfig }) => {
@@ -71,6 +74,9 @@ export default function createIntegration(): AstroIntegration {
71
74
  format: 'esm',
72
75
  bundle: true,
73
76
  minify: true,
77
+ banner: {
78
+ js: SHIM,
79
+ },
74
80
  });
75
81
 
76
82
  // throw the server folder in the bin
@@ -0,0 +1,31 @@
1
+ import { loadFixture, runCLI } from './test-utils.js';
2
+ import { expect } from 'chai';
3
+ import * as cheerio from 'cheerio';
4
+
5
+ describe('Basic app', () => {
6
+ /** @type {import('./test-utils').Fixture} */
7
+ let fixture;
8
+
9
+ before(async () => {
10
+ fixture = await loadFixture({
11
+ root: './fixtures/basics/',
12
+ });
13
+ await fixture.build();
14
+ });
15
+
16
+ it('can render', async () => {
17
+ const { ready, stop } = runCLI('./fixtures/basics/', { silent: true });
18
+
19
+ try {
20
+ await ready;
21
+
22
+ let res = await fetch(`http://localhost:8787/`);
23
+ expect(res.status).to.equal(200);
24
+ let html = await res.text();
25
+ let $ = cheerio.load(html);
26
+ expect($('h1').text()).to.equal('Testing');
27
+ } finally {
28
+ await stop();
29
+ }
30
+ });
31
+ });
@@ -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-basics",
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,6 @@
1
+ import { defineConfig } from 'astro/config';
2
+ import cloudflare from '@astrojs/cloudflare';
3
+
4
+ export default defineConfig({
5
+ adapter: cloudflare()
6
+ });
@@ -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-no-output",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "dependencies": {
6
+ "@astrojs/cloudflare": "workspace:*",
7
+ "astro": "workspace:*"
8
+ }
9
+ }
@@ -0,0 +1,24 @@
1
+ import { loadFixture } from './test-utils.js';
2
+ import { expect } from 'chai';
3
+
4
+ describe('Missing output config', () => {
5
+ /** @type {import('./test-utils').Fixture} */
6
+ let fixture;
7
+
8
+ before(async () => {
9
+ fixture = await loadFixture({
10
+ root: './fixtures/no-output/',
11
+ });
12
+ });
13
+
14
+ it('throws during the build', async () => {
15
+ let error = undefined;
16
+ try {
17
+ await fixture.build();
18
+ } catch (err) {
19
+ error = err;
20
+ }
21
+ expect(error).to.not.be.equal(undefined);
22
+ expect(error.message).to.include(`output: "server"`);
23
+ });
24
+ });
@@ -0,0 +1,67 @@
1
+ import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js';
2
+ import { spawn } from 'child_process';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ export { fixLineEndings } from '../../../astro/test/test-utils.js';
6
+
7
+ export function loadFixture(config) {
8
+ if (config?.root) {
9
+ config.root = new URL(config.root, import.meta.url);
10
+ }
11
+ return baseLoadFixture(config);
12
+ }
13
+
14
+ const wranglerPath = fileURLToPath(
15
+ new URL('../node_modules/wrangler/bin/wrangler.js', import.meta.url)
16
+ );
17
+
18
+ export function runCLI(basePath, { silent }) {
19
+ const script = fileURLToPath(new URL(`${basePath}/dist/_worker.js`, import.meta.url));
20
+ const p = spawn('node', [wranglerPath, 'dev', '-l', script]);
21
+
22
+ p.stderr.setEncoding('utf-8');
23
+ p.stdout.setEncoding('utf-8');
24
+
25
+ const timeout = 10000;
26
+
27
+ const ready = new Promise(async (resolve, reject) => {
28
+ const failed = setTimeout(
29
+ () => reject(new Error(`Timed out starting the wrangler CLI`)),
30
+ timeout
31
+ );
32
+
33
+ (async function () {
34
+ for (const msg of p.stderr) {
35
+ if (!silent) {
36
+ // eslint-disable-next-line
37
+ console.error(msg);
38
+ }
39
+ }
40
+ })();
41
+
42
+ for await (const msg of p.stdout) {
43
+ if (!silent) {
44
+ // eslint-disable-next-line
45
+ console.log(msg);
46
+ }
47
+ if (msg.includes(`Listening on`)) {
48
+ break;
49
+ }
50
+ }
51
+
52
+ clearTimeout(failed);
53
+ resolve();
54
+ });
55
+
56
+ return {
57
+ ready,
58
+ stop() {
59
+ p.kill();
60
+ return new Promise((resolve) => {
61
+ p.addListener('exit', () => {
62
+ resolve();
63
+ });
64
+ });
65
+ },
66
+ };
67
+ }