summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/eleven-eyes-sip.md5
-rw-r--r--packages/db/src/runtime/index.ts2
-rw-r--r--packages/db/src/runtime/utils.ts26
-rw-r--r--pnpm-lock.yaml37
4 files changed, 68 insertions, 2 deletions
diff --git a/.changeset/eleven-eyes-sip.md b/.changeset/eleven-eyes-sip.md
new file mode 100644
index 000000000..29ad8a5c0
--- /dev/null
+++ b/.changeset/eleven-eyes-sip.md
@@ -0,0 +1,5 @@
+---
+"@astrojs/db": patch
+---
+
+Fix compatibility of @astrojs/db with Cloudflare
diff --git a/packages/db/src/runtime/index.ts b/packages/db/src/runtime/index.ts
index c4643b86a..0cc91e57b 100644
--- a/packages/db/src/runtime/index.ts
+++ b/packages/db/src/runtime/index.ts
@@ -1,4 +1,4 @@
-import { pathToFileURL } from 'url';
+import { pathToFileURL } from './utils.js';
import { type ColumnBuilderBaseConfig, type ColumnDataType, sql } from 'drizzle-orm';
import {
type IndexBuilder,
diff --git a/packages/db/src/runtime/utils.ts b/packages/db/src/runtime/utils.ts
index ac6cfeda6..098417fcc 100644
--- a/packages/db/src/runtime/utils.ts
+++ b/packages/db/src/runtime/utils.ts
@@ -1,5 +1,7 @@
import { AstroError } from 'astro/errors';
+const isWindows = process?.platform === "win32";
+
/**
* Small wrapper around fetch that throws an error if the response is not OK. Allows for custom error handling as well through the onNotOK callback.
*/
@@ -22,3 +24,27 @@ export async function safeFetch(
export class AstroDbError extends AstroError {
name = 'Astro DB Error';
}
+
+export default function slash(path: string) {
+ const isExtendedLengthPath = path.startsWith('\\\\?\\');
+
+ if (isExtendedLengthPath) {
+ return path;
+ }
+
+ return path.replace(/\\/g, '/');
+}
+
+export function pathToFileURL(path: string): URL {
+ if(isWindows) {
+ let slashed = slash(path);
+ // Windows like C:/foo/bar
+ if(!slashed.startsWith('/')) {
+ slashed = '/' + slashed;
+ }
+ return new URL('file://' + slashed);
+ }
+
+ // Unix is easy
+ return new URL('file://' + path);
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 99bfc70f5..6b3ce627a 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3922,7 +3922,7 @@ importers:
version: 5.4.3
vite:
specifier: ^5.1.4
- version: 5.2.7(@types/node@18.19.28)(sass@1.72.0)
+ version: 5.2.7
packages/db/test/fixtures/basics:
dependencies:
@@ -16729,6 +16729,41 @@ packages:
svgo: 3.2.0
dev: false
+ /vite@5.2.7:
+ resolution: {integrity: sha512-k14PWOKLI6pMaSzAuGtT+Cf0YmIx12z9YGon39onaJNy8DLBfBJrzg9FQEmkAM5lpHBZs9wksWAsyF/HkpEwJA==}
+ engines: {node: ^18.0.0 || >=20.0.0}
+ hasBin: true
+ peerDependencies:
+ '@types/node': ^18.0.0 || >=20.0.0
+ less: '*'
+ lightningcss: ^1.21.0
+ sass: '*'
+ stylus: '*'
+ sugarss: '*'
+ terser: ^5.4.0
+ peerDependenciesMeta:
+ '@types/node':
+ optional: true
+ less:
+ optional: true
+ lightningcss:
+ optional: true
+ sass:
+ optional: true
+ stylus:
+ optional: true
+ sugarss:
+ optional: true
+ terser:
+ optional: true
+ dependencies:
+ esbuild: 0.20.2
+ postcss: 8.4.38
+ rollup: 4.13.2
+ optionalDependencies:
+ fsevents: 2.3.3
+ dev: true
+
/vite@5.2.7(@types/node@18.19.28)(sass@1.72.0):
resolution: {integrity: sha512-k14PWOKLI6pMaSzAuGtT+Cf0YmIx12z9YGon39onaJNy8DLBfBJrzg9FQEmkAM5lpHBZs9wksWAsyF/HkpEwJA==}
engines: {node: ^18.0.0 || >=20.0.0}