@astrojs/cloudflare 6.6.1 → 7.0.0-beta.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.
package/dist/index.js CHANGED
@@ -1,19 +1,39 @@
1
1
  import { createRedirectsFromAstroRoutes } from "@astrojs/underscore-redirects";
2
2
  import esbuild from "esbuild";
3
- import * as fs from "fs";
4
- import * as os from "os";
5
- import { dirname } from "path";
3
+ import * as fs from "node:fs";
4
+ import * as os from "node:os";
5
+ import { sep } from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
7
  import glob from "tiny-glob";
7
- import { fileURLToPath, pathToFileURL } from "url";
8
8
  function getAdapter(isModeDirectory) {
9
9
  return isModeDirectory ? {
10
10
  name: "@astrojs/cloudflare",
11
11
  serverEntrypoint: "@astrojs/cloudflare/server.directory.js",
12
- exports: ["onRequest", "manifest"]
12
+ exports: ["onRequest", "manifest"],
13
+ supportedAstroFeatures: {
14
+ hybridOutput: "stable",
15
+ staticOutput: "unsupported",
16
+ serverOutput: "stable",
17
+ assets: {
18
+ supportKind: "unsupported",
19
+ isSharpCompatible: false,
20
+ isSquooshCompatible: false
21
+ }
22
+ }
13
23
  } : {
14
24
  name: "@astrojs/cloudflare",
15
25
  serverEntrypoint: "@astrojs/cloudflare/server.advanced.js",
16
- exports: ["default"]
26
+ exports: ["default"],
27
+ supportedAstroFeatures: {
28
+ hybridOutput: "stable",
29
+ staticOutput: "unsupported",
30
+ serverOutput: "stable",
31
+ assets: {
32
+ supportKind: "stable",
33
+ isSharpCompatible: false,
34
+ isSquooshCompatible: false
35
+ }
36
+ }
17
37
  };
18
38
  }
19
39
  const SHIM = `globalThis.process = {
@@ -24,7 +44,7 @@ const SERVER_BUILD_FOLDER = "/$server_build/";
24
44
  function createIntegration(args) {
25
45
  let _config;
26
46
  let _buildConfig;
27
- const isModeDirectory = (args == null ? void 0 : args.mode) === "directory";
47
+ const isModeDirectory = args?.mode === "directory";
28
48
  let _entryPoints = /* @__PURE__ */ new Map();
29
49
  return {
30
50
  name: "@astrojs/cloudflare",
@@ -68,23 +88,26 @@ function createIntegration(args) {
68
88
  }
69
89
  vite.ssr ||= {};
70
90
  vite.ssr.target = "webworker";
91
+ vite.define = {
92
+ "process.env": "process.env",
93
+ ...vite.define
94
+ };
71
95
  }
72
96
  },
73
97
  "astro:build:ssr": ({ entryPoints }) => {
74
98
  _entryPoints = entryPoints;
75
99
  },
76
100
  "astro:build:done": async ({ pages, routes, dir }) => {
77
- var _a, _b, _c, _d;
78
101
  const functionsUrl = new URL("functions/", _config.root);
79
102
  if (isModeDirectory) {
80
103
  await fs.promises.mkdir(functionsUrl, { recursive: true });
81
104
  }
82
105
  if (isModeDirectory && _buildConfig.split) {
83
- const entryPointsRouteData = [..._entryPoints.keys()];
84
106
  const entryPointsURL = [..._entryPoints.values()];
85
107
  const entryPaths = entryPointsURL.map((entry) => fileURLToPath(entry));
86
- const outputDir = fileURLToPath(new URL(".astro", _buildConfig.server));
87
- const { outputFiles } = await esbuild.build({
108
+ const outputUrl = new URL("$astro", _buildConfig.server);
109
+ const outputDir = fileURLToPath(outputUrl);
110
+ await esbuild.build({
88
111
  target: "es2020",
89
112
  platform: "browser",
90
113
  conditions: ["workerd", "worker", "browser"],
@@ -93,25 +116,37 @@ function createIntegration(args) {
93
116
  allowOverwrite: true,
94
117
  format: "esm",
95
118
  bundle: true,
96
- minify: ((_b = (_a = _config.vite) == null ? void 0 : _a.build) == null ? void 0 : _b.minify) !== false,
119
+ minify: _config.vite?.build?.minify !== false,
97
120
  banner: {
98
121
  js: SHIM
99
122
  },
100
123
  logOverride: {
101
124
  "ignored-bare-import": "silent"
102
- },
103
- write: false
125
+ }
126
+ });
127
+ const outputFiles = await glob(`**/*`, {
128
+ cwd: outputDir,
129
+ filesOnly: true
104
130
  });
105
- for (const [index, outputFile] of outputFiles.entries()) {
106
- const fileName = entryPointsRouteData[index].component.replace("src/pages/", "").replace(".astro", ".js").replace(/(\[\.\.\.)(\w+)(\])/g, (_match, _p1, p2) => {
107
- return `[[${p2}]]`;
131
+ for (const outputFile of outputFiles) {
132
+ const path = outputFile.split(sep);
133
+ const finalSegments = path.map(
134
+ (segment) => segment.replace(/(\_)(\w+)(\_)/g, (_, __, prop) => {
135
+ return `[${prop}]`;
136
+ }).replace(/(\_\-\-\-)(\w+)(\_)/g, (_, __, prop) => {
137
+ return `[[${prop}]]`;
138
+ })
139
+ );
140
+ finalSegments[finalSegments.length - 1] = finalSegments[finalSegments.length - 1].replace("entry.", "").replace(/(.*)\.(\w+)\.(\w+)$/g, (_, fileName, __, newExt) => {
141
+ return `${fileName}.${newExt}`;
108
142
  });
109
- const fileUrl = new URL(fileName, functionsUrl);
110
- const newFileDir = dirname(fileURLToPath(fileUrl));
111
- if (!fs.existsSync(newFileDir)) {
112
- fs.mkdirSync(newFileDir, { recursive: true });
113
- }
114
- await fs.promises.writeFile(fileUrl, outputFile.contents);
143
+ const finalDirPath = finalSegments.slice(0, -1).join(sep);
144
+ const finalPath = finalSegments.join(sep);
145
+ const newDirUrl = new URL(finalDirPath, functionsUrl);
146
+ await fs.promises.mkdir(newDirUrl, { recursive: true });
147
+ const oldFileUrl = new URL(`$astro/${outputFile}`, outputUrl);
148
+ const newFileUrl = new URL(finalPath, functionsUrl);
149
+ await fs.promises.rename(oldFileUrl, newFileUrl);
115
150
  }
116
151
  } else {
117
152
  const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server));
@@ -127,7 +162,7 @@ function createIntegration(args) {
127
162
  allowOverwrite: true,
128
163
  format: "esm",
129
164
  bundle: true,
130
- minify: ((_d = (_c = _config.vite) == null ? void 0 : _c.build) == null ? void 0 : _d.minify) !== false,
165
+ minify: _config.vite?.build?.minify !== false,
131
166
  banner: {
132
167
  js: SHIM
133
168
  },
@@ -1,4 +1,4 @@
1
- import type { ExecutionContext, Request as CFRequest } from '@cloudflare/workers-types';
1
+ import type { Request as CFRequest, ExecutionContext } from '@cloudflare/workers-types';
2
2
  import type { SSRManifest } from 'astro';
3
3
  type Env = {
4
4
  ASSETS: {
@@ -1,10 +1,10 @@
1
- import type { EventContext, Request as CFRequest } from '@cloudflare/workers-types';
1
+ import type { Request as CFRequest, EventContext } from '@cloudflare/workers-types';
2
2
  import type { SSRManifest } from 'astro';
3
3
  export declare function createExports(manifest: SSRManifest): {
4
4
  onRequest: ({ request, next, ...runtimeEnv }: {
5
5
  request: Request & CFRequest;
6
6
  next: (request: Request) => void;
7
7
  waitUntil: EventContext<unknown, any, unknown>['waitUntil'];
8
- } & Record<string, unknown>) => Promise<void | Response>;
8
+ } & Record<string, unknown>) => Promise<import("@cloudflare/workers-types").Response | Response>;
9
9
  manifest: SSRManifest;
10
10
  };
@@ -13,7 +13,9 @@ function createExports(manifest) {
13
13
  process.env = runtimeEnv.env;
14
14
  const { pathname } = new URL(request.url);
15
15
  if (manifest.assets.has(pathname)) {
16
- return next(request);
16
+ return runtimeEnv.env.ASSETS.fetch(
17
+ request
18
+ );
17
19
  }
18
20
  let routeData = app.match(request, { matchNotFound: true });
19
21
  if (routeData) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/cloudflare",
3
3
  "description": "Deploy your site to Cloudflare Workers/Pages",
4
- "version": "6.6.1",
4
+ "version": "7.0.0-beta.0",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -32,20 +32,20 @@
32
32
  "runtime.d.ts"
33
33
  ],
34
34
  "dependencies": {
35
- "@astrojs/underscore-redirects": "^0.2.0",
36
35
  "@cloudflare/workers-types": "^4.20230518.0",
37
- "esbuild": "^0.17.19",
38
- "tiny-glob": "^0.2.9"
36
+ "esbuild": "^0.18.16",
37
+ "tiny-glob": "^0.2.9",
38
+ "@astrojs/underscore-redirects": "0.3.0-beta.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "astro": "^2.8.2"
41
+ "astro": "^3.0.0-beta.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "chai": "^4.3.7",
45
45
  "cheerio": "1.0.0-rc.12",
46
46
  "mocha": "^9.2.2",
47
47
  "wrangler": "^2.0.23",
48
- "astro": "2.8.2",
48
+ "astro": "3.0.0-beta.0",
49
49
  "astro-scripts": "0.0.14"
50
50
  },
51
51
  "scripts": {