@astrojs/cloudflare 3.0.0 → 3.1.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 3257cd3ed40cd0ec
1
+ @astrojs/cloudflare:build: cache hit, replaying output bb5a25392613b0d2
2
2
  @astrojs/cloudflare:build: 
3
- @astrojs/cloudflare:build: > @astrojs/cloudflare@3.0.0 build /home/runner/work/astro/astro/packages/integrations/cloudflare
3
+ @astrojs/cloudflare:build: > @astrojs/cloudflare@3.1.0 build /home/runner/work/astro/astro/packages/integrations/cloudflare
4
4
  @astrojs/cloudflare:build: > astro-scripts build "src/**/*.ts" && tsc
5
5
  @astrojs/cloudflare:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @astrojs/cloudflare
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#5056](https://github.com/withastro/astro/pull/5056) [`e55af8a23`](https://github.com/withastro/astro/commit/e55af8a23233b6335f45b7a04b9d026990fb616c) Thanks [@matthewp](https://github.com/matthewp)! - # New build configuration
8
+
9
+ The ability to customize SSR build configuration more granularly is now available in Astro. You can now customize the output folder for `server` (the server code for SSR), `client` (your client-side JavaScript and assets), and `serverEntry` (the name of the entrypoint server module). Here are the defaults:
10
+
11
+ ```js
12
+ import { defineConfig } from 'astro/config';
13
+
14
+ export default defineConfig({
15
+ output: 'server',
16
+ build: {
17
+ server: './dist/server/',
18
+ client: './dist/client/',
19
+ serverEntry: 'entry.mjs',
20
+ },
21
+ });
22
+ ```
23
+
24
+ These new configuration options are only supported in SSR mode and are ignored when building to SSG (a static site).
25
+
26
+ ## Integration hook change
27
+
28
+ The integration hook `astro:build:start` includes a param `buildConfig` which includes all of these same options. You can continue to use this param in Astro 1.x, but it is deprecated in favor of the new `build.config` options. All of the built-in adapters have been updated to the new format. If you have an integration that depends on this param we suggest upgrading to do this instead:
29
+
30
+ ```js
31
+ export default function myIntegration() {
32
+ return {
33
+ name: 'my-integration',
34
+ hooks: {
35
+ 'astro:config:setup': ({ updateConfig }) => {
36
+ updateConfig({
37
+ build: {
38
+ server: '...',
39
+ },
40
+ });
41
+ },
42
+ },
43
+ };
44
+ }
45
+ ```
46
+
3
47
  ## 3.0.0
4
48
 
5
49
  ### Major Changes
package/dist/index.js CHANGED
@@ -19,13 +19,25 @@ const SHIM = `globalThis.process = {
19
19
  function createIntegration(args) {
20
20
  let _config;
21
21
  let _buildConfig;
22
+ let needsBuildConfig = false;
22
23
  const isModeDirectory = (args == null ? void 0 : args.mode) === "directory";
23
24
  return {
24
25
  name: "@astrojs/cloudflare",
25
26
  hooks: {
27
+ "astro:config:setup": ({ config, updateConfig }) => {
28
+ needsBuildConfig = !config.build.client;
29
+ updateConfig({
30
+ build: {
31
+ client: new URL("./static/", config.outDir),
32
+ server: new URL("./", config.outDir),
33
+ serverEntry: "_worker.js"
34
+ }
35
+ });
36
+ },
26
37
  "astro:config:done": ({ setAdapter, config }) => {
27
38
  setAdapter(getAdapter(isModeDirectory));
28
39
  _config = config;
40
+ _buildConfig = config.build;
29
41
  if (config.output === "static") {
30
42
  throw new Error(`
31
43
  [@astrojs/cloudflare] \`output: "server"\` is required to use this adapter. Otherwise, this adapter is not necessary to deploy a static site to Cloudflare.
@@ -33,12 +45,6 @@ function createIntegration(args) {
33
45
  `);
34
46
  }
35
47
  },
36
- "astro:build:start": ({ buildConfig }) => {
37
- _buildConfig = buildConfig;
38
- buildConfig.client = new URL("./static/", _config.outDir);
39
- buildConfig.serverEntry = "_worker.js";
40
- buildConfig.server = new URL("./", _config.outDir);
41
- },
42
48
  "astro:build:setup": ({ vite, target }) => {
43
49
  if (target === "server") {
44
50
  vite.resolve = vite.resolve || {};
@@ -55,6 +61,13 @@ function createIntegration(args) {
55
61
  vite.ssr.target = vite.ssr.target || "webworker";
56
62
  }
57
63
  },
64
+ "astro:build:start": ({ buildConfig }) => {
65
+ if (needsBuildConfig) {
66
+ buildConfig.client = new URL("./static/", _config.outDir);
67
+ buildConfig.server = new URL("./", _config.outDir);
68
+ buildConfig.serverEntry = "_worker.js";
69
+ }
70
+ },
58
71
  "astro:build:done": async () => {
59
72
  const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server);
60
73
  const pkg = fileURLToPath(entryUrl);
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": "3.0.0",
4
+ "version": "3.1.0",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -27,7 +27,7 @@
27
27
  "esbuild": "^0.14.42"
28
28
  },
29
29
  "devDependencies": {
30
- "astro": "1.4.5",
30
+ "astro": "1.5.0",
31
31
  "astro-scripts": "0.0.8",
32
32
  "chai": "^4.3.6",
33
33
  "cheerio": "^1.0.0-rc.11",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AstroAdapter, AstroConfig, AstroIntegration, BuildConfig } from 'astro';
1
+ import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro';
2
2
  import esbuild from 'esbuild';
3
3
  import * as fs from 'fs';
4
4
  import { fileURLToPath } from 'url';
@@ -7,6 +7,12 @@ type Options = {
7
7
  mode: 'directory' | 'advanced';
8
8
  };
9
9
 
10
+ interface BuildConfig {
11
+ server: URL;
12
+ client: URL;
13
+ serverEntry: string;
14
+ }
15
+
10
16
  export function getAdapter(isModeDirectory: boolean): AstroAdapter {
11
17
  return isModeDirectory
12
18
  ? {
@@ -29,14 +35,26 @@ const SHIM = `globalThis.process = {
29
35
  export default function createIntegration(args?: Options): AstroIntegration {
30
36
  let _config: AstroConfig;
31
37
  let _buildConfig: BuildConfig;
38
+ let needsBuildConfig = false;
32
39
  const isModeDirectory = args?.mode === 'directory';
33
40
 
34
41
  return {
35
42
  name: '@astrojs/cloudflare',
36
43
  hooks: {
44
+ 'astro:config:setup': ({ config, updateConfig }) => {
45
+ needsBuildConfig = !config.build.client;
46
+ updateConfig({
47
+ build: {
48
+ client: new URL('./static/', config.outDir),
49
+ server: new URL('./', config.outDir),
50
+ serverEntry: '_worker.js',
51
+ },
52
+ });
53
+ },
37
54
  'astro:config:done': ({ setAdapter, config }) => {
38
55
  setAdapter(getAdapter(isModeDirectory));
39
56
  _config = config;
57
+ _buildConfig = config.build;
40
58
 
41
59
  if (config.output === 'static') {
42
60
  throw new Error(`
@@ -45,12 +63,6 @@ export default function createIntegration(args?: Options): AstroIntegration {
45
63
  `);
46
64
  }
47
65
  },
48
- 'astro:build:start': ({ buildConfig }) => {
49
- _buildConfig = buildConfig;
50
- buildConfig.client = new URL('./static/', _config.outDir);
51
- buildConfig.serverEntry = '_worker.js';
52
- buildConfig.server = new URL('./', _config.outDir);
53
- },
54
66
  'astro:build:setup': ({ vite, target }) => {
55
67
  if (target === 'server') {
56
68
  vite.resolve = vite.resolve || {};
@@ -69,6 +81,14 @@ export default function createIntegration(args?: Options): AstroIntegration {
69
81
  vite.ssr.target = vite.ssr.target || 'webworker';
70
82
  }
71
83
  },
84
+ 'astro:build:start': ({ buildConfig }) => {
85
+ // Backwards compat
86
+ if (needsBuildConfig) {
87
+ buildConfig.client = new URL('./static/', _config.outDir);
88
+ buildConfig.server = new URL('./', _config.outDir);
89
+ buildConfig.serverEntry = '_worker.js';
90
+ }
91
+ },
72
92
  'astro:build:done': async () => {
73
93
  const entryUrl = new URL(_buildConfig.serverEntry, _buildConfig.server);
74
94
  const pkg = fileURLToPath(entryUrl);