Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/supabase runtime #654

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions engine/releases/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,27 @@ export const newFsProviderFromPath = (
},
).then((result) => {
(async () => {
const watcher = Deno.watchFs(fullPath);
const updateState = debounce(async () => {
const state = await Deno.readTextFile(fullPath)
.then(JSON.parse)
.catch((_e) => null);
if (state === null) {
return;
if (Deno.watchFs) {
const watcher = Deno.watchFs(fullPath);
const updateState = debounce(async () => {
const state = await Deno.readTextFile(fullPath)
.then(JSON.parse)
.catch((_e) => null);
if (state === null) {
return;
}
currResolvables = Promise.resolve({
state,
archived: {},
revision: `${Date.now()}`,
});
for (const cb of onChangeCbs) {
cb();
}
}, 300);
for await (const _event of watcher) {
updateState();
}
currResolvables = Promise.resolve({
state,
archived: {},
revision: `${Date.now()}`,
});
for (const cb of onChangeCbs) {
cb();
}
}, 300);
for await (const _event of watcher) {
updateState();
}
})();

Expand Down
1 change: 1 addition & 0 deletions engine/releases/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const DECO_RELEASE_VERSION_ENV_VAR = "DECO_RELEASE";

export const DECOFILE_REL_PATH = join(".deco", "decofile.json");
const DECOFILE_PATH_DEFAULT = join(Deno.cwd(), DECOFILE_REL_PATH);
console.log({PATH: DECOFILE_PATH_DEFAULT});
const decofileExistsPromise = exists(DECOFILE_PATH_DEFAULT, {
isFile: true,
isReadable: true,
Expand Down
9 changes: 2 additions & 7 deletions runtime/caches/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
isFileSystemAvailable,
} from "./fileSystem.ts";
import { caches as redisCache, redis } from "./redis.ts";
import { caches as cachesS3, isS3Available } from "./s3.ts";
//import { caches as cachesS3, isS3Available } from "./s3.ts";
import { createTieredCache } from "./tiered.ts";

export const ENABLE_LOADER_CACHE =
Expand All @@ -24,8 +24,7 @@ export type CacheEngine =
| "REDIS"
| "KV"
| "CACHE_API"
| "FILE_SYSTEM"
| "S3";
| "FILE_SYSTEM";

const cacheImplByEngine: Record<CacheEngine, CacheStorageOption> = {
REDIS: {
Expand All @@ -44,10 +43,6 @@ const cacheImplByEngine: Record<CacheEngine, CacheStorageOption> = {
implementation: cachesFileSystem,
isAvailable: isFileSystemAvailable,
},
S3: {
implementation: cachesS3,
isAvailable: isS3Available,
},
};

for (const [engine, cache] of Object.entries(cacheImplByEngine)) {
Expand Down
2 changes: 1 addition & 1 deletion runtime/caches/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NoSuchKey,
PutObjectCommand,
S3Client,
} from "https://esm.sh/@aws-sdk/[email protected]";
} from "npm:@aws-sdk/[email protected]";
import { Context } from "../../deco.ts";
import { ValueType } from "../../deps.ts";
import { logger, tracer } from "../../observability/otel/config.ts";
Expand Down
40 changes: 21 additions & 19 deletions runtime/fs/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,33 @@ export const DenoFs: IVFS = {
readTextFile: Deno.readTextFile,
};

for (const [func, impl] of Object.entries(DenoFs)) {
const funcKey = func as keyof typeof DenoFs;
// @ts-ignore: trust-me
Deno[funcKey] = (...args) => {
const fs = Context.active().fs;
if (!Deno.env.has("AVOID_OVERRIDE_DENO_FS")) {
for (const [func, impl] of Object.entries(DenoFs)) {
const funcKey = func as keyof typeof DenoFs;
// @ts-ignore: trust-me
const fsMk = fs?.[funcKey]?.bind(fs);
if (typeof fsMk !== "function") {
return impl(...args);
}
const [arg0, ...rest] = args ?? []; // always should be path
if (arg0 instanceof URL || typeof arg0 === "string") {
const path = arg0.toString();
if (path.startsWith(Deno.cwd())) {
// @ts-ignore: trust-me
Deno[funcKey] = (...args) => {
const fs = Context.active().fs;
// @ts-ignore: trust-me
const fsMk = fs?.[funcKey]?.bind(fs);
if (typeof fsMk !== "function") {
return impl(...args);
}
const [arg0, ...rest] = args ?? []; // always should be path
if (arg0 instanceof URL || typeof arg0 === "string") {
const path = arg0.toString();
if (path.startsWith(Deno.cwd())) {
// @ts-ignore: trust-me
return fsMk(...[
fileSeparatorToSlash(path.replace(Deno.cwd(), "")),
...rest,
]);
}
return impl(...args);
}
return impl(...args);
}
// @ts-ignore: trust-me
return fsMk(...args);
};
// @ts-ignore: trust-me
return fsMk(...args);
};
}
}

const textEncoder = new TextEncoder();
Expand Down
Loading