mirror of
https://github.com/withastro/astro.git
synced 2025-01-23 11:01:54 -05:00
Fix compatibility for @astrojs/db with cloudflare (#10677)
* Fix compatibility for @astrojs/db with cloudflare * Use a manual implementation * Update lockfile
This commit is contained in:
parent
45414a21cc
commit
1662aa8a85
4 changed files with 68 additions and 2 deletions
5
.changeset/eleven-eyes-sip.md
Normal file
5
.changeset/eleven-eyes-sip.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/db": patch
|
||||
---
|
||||
|
||||
Fix compatibility of @astrojs/db with Cloudflare
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue