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

Deno 2 support #937

Merged
merged 4 commits into from
Oct 16, 2024
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
path: |
/home/runner/.deno
/home/runner/.cache/deno/deps/https/deno.land
- uses: denoland/setup-deno@v1
- uses: denoland/setup-deno@v2
with:
deno-version: v1.x
deno-version: v2.x
- name: Bundle Apps
run: deno run -A --lock=deno.lock --lock-write --reload scripts/start.ts
run: deno run -A --lock=deno.lock --frozen=false --reload scripts/start.ts

- name: Check
run: deno task check
Expand All @@ -47,8 +47,8 @@ jobs:

- name: Test
continue-on-error: true
run: deno test --lock=deno.lock --lock-write -A .
run: deno test --lock=deno.lock --frozen=false -A .

- name: Benchmark
continue-on-error: true
run: deno bench --lock=deno.lock --lock-write -A .
run: deno bench --lock=deno.lock --frozen=false -A .
2 changes: 1 addition & 1 deletion .github/workflows/issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
LABELS: triage
LABELS: triage
16 changes: 8 additions & 8 deletions .github/workflows/releaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:
- main

permissions:
contents: write # Necessary for accessing and modifying repository content
pull-requests: write # Necessary for interacting with pull requests
actions: write # Necessary for triggering other workflows
contents: write # Necessary for accessing and modifying repository content
pull-requests: write # Necessary for interacting with pull requests
actions: write # Necessary for triggering other workflows

jobs:
tag-discussion:
Expand All @@ -21,9 +21,9 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }} # Checkout the base branch (target repository)
repository: ${{ github.event.pull_request.base.repo.full_name }} # Checkout from the target repo
ref: ${{ github.event.pull_request.base.ref }} # Checkout the base branch (target repository)
repository: ${{ github.event.pull_request.base.repo.full_name }} # Checkout from the target repo

- name: Calculate new versions
id: calculate_versions
run: |
Expand Down Expand Up @@ -162,11 +162,11 @@ jobs:
run: |
git tag ${{ steps.determine_version.outputs.new_version }}
git push origin ${{ steps.determine_version.outputs.new_version }}

- name: Trigger Release Workflow
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.everest-preview+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/release.yaml/dispatches \
-d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}'
-d '{"ref":"main", "inputs":{"tag_name":"${{ steps.determine_version.outputs.new_version }}"}}'
12 changes: 9 additions & 3 deletions ai-assistants/actions/describeImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AssistantIds } from "../types.ts";
import { AppContext } from "../mod.ts";
import { logger, meter, ValueType } from "@deco/deco/o11y";
import { shortcircuit } from "@deco/deco";

const stats = {
promptTokens: meter.createHistogram("assistant_image_prompt_tokens", {
description: "Tokens used in Sales Assistant Describe Image Input - OpenAI",
Expand Down Expand Up @@ -78,13 +79,18 @@ export default async function describeImage(
});
return response;
} catch (error) {
const errorObj = error as {
error: { message: string };
status: number;
headers: Headers;
};
stats.describeImageError.add(1, {
assistantId,
});
shortcircuit(
new Response(JSON.stringify({ error: error.error.message }), {
status: error.status,
headers: error.headers,
new Response(JSON.stringify({ error: errorObj.error.message }), {
status: errorObj.status,
headers: errorObj.headers,
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion ai-assistants/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from "https://esm.sh/aws-sdk@2.1585.0";
import AWS from "npm:aws-sdk@2.1585.0";
import { deferred } from "std/async/deferred.ts";
import openai, {
Props as OpenAIProps,
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"lock": false,
"tasks": {
"check": "deno fmt && deno lint && deno check **/mod.ts",
"check": "deno fmt && deno lint && deno check --allow-import **/mod.ts",
"release": "deno eval 'import \"deco/scripts/release.ts\"'",
"start": "deno run -A ./scripts/start.ts",
"bundle": "deno run -A jsr:@deco/deco/scripts/bundle",
Expand Down
5 changes: 3 additions & 2 deletions konfidency/loaders/productDetailsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ export default function productDetailsPage(
},
};
} catch (error) {
logger.error(`{ errorName: ${error.name},
errorMessage: ${error.message} }`);
const errorObj = error as { name: string; message: string };
logger.error(`{ errorName: ${errorObj.name},
errorMessage: ${errorObj.message} }`);
return productDetailsPage;
}
};
Expand Down
2 changes: 1 addition & 1 deletion posthog/components/PostHog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const snippet = () => {
const trackPageview = () =>
globalThis.window.posthog?.capture("$pageview", {
...props,
"$current_url": window.location.href,
"$current_url": globalThis.location.href,
});
// Attach pushState and popState listeners
const originalPushState = history.pushState;
Expand Down
2 changes: 1 addition & 1 deletion records/deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { context } from "@deco/deco";
export * from "https://esm.sh/drizzle-orm@0.30.10/libsql";
export * from "npm:drizzle-orm@0.30.10/libsql";
export * from "npm:@libsql/client@0.7.0";
export const createLocalClient = !context.isDeploy &&
(await import("npm:@libsql/client@0.7.0/node")).createClient;
2 changes: 1 addition & 1 deletion smarthint/components/Click.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SmarthintSendEventOnClick = ({
}

elem.addEventListener("click", () => {
window.smarthint.click(event);
globalThis.smarthint.click(event);
});
},
id,
Expand Down
2 changes: 1 addition & 1 deletion smarthint/sections/Analytics/SmarthintTracking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const listener = (
ReturnType<typeof loader>,
) => {
const prodURL = new URL(publicUrl);
const url = new URL(window.location.href);
const url = new URL(globalThis.location.href);
url.host = prodURL.host;
url.port = "";
const pageType =
Expand Down
2 changes: 2 additions & 0 deletions utils/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const createPool = <T>(resources: T[]) => {

const index = free.values().next().value;

if (index === undefined) return;

taken.add(index);
free.delete(index);

Expand Down
2 changes: 1 addition & 1 deletion vtex/sections/Analytics/Vtex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ISCookies {
session: any;
}
const snippet = (account: string, agent: string, cookies: ISCookies | null) => {
const url = new URL(window.location.href);
const url = new URL(globalThis.location.href);
const isSearch = url.searchParams.get("q");
const apiUrl = `https://sp.vtex.com/event-api/v1/${account}/event`;
const eventFetch = (props: SPEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion wake/hooks/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const enqueue2 = (
return;
}

const isLocalhost = window.location.hostname === "localhost";
const isLocalhost = globalThis.location.hostname === "localhost";

if (!isLocalhost) {
const url = new URL("/api/carrinho", shop.checkoutUrl);
Expand Down
6 changes: 3 additions & 3 deletions website/components/Clickhouse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const snippet = ({ siteId, siteName, serviceEndpoint, userId, sessionId }: {
return match ? match[1].replace("_", ".") : "Unknown";
}
function getUrlParam(param: string) {
const urlParams = new URLSearchParams(window.location.search);
const urlParams = new URLSearchParams(globalThis.location.search);
return urlParams.get(param);
}
function getReferrerSource(referrer: string) {
Expand All @@ -245,7 +245,7 @@ const snippet = ({ siteId, siteName, serviceEndpoint, userId, sessionId }: {
start_time: new Date().toISOString(),
timestamp: undefined, // get server side
pathname: globalThis.window.location.pathname +
(window.location.hash ?? ""),
(globalThis.location.hash ?? ""),
navigation_from: globalThis.window.navigation.activation.from,
entry_meta: {
key: Object.keys(values),
Expand All @@ -266,7 +266,7 @@ const snippet = ({ siteId, siteName, serviceEndpoint, userId, sessionId }: {
ip_timezone: undefined, // get server side
ip_lat: undefined, // get server side
ip_long: undefined, // get server side
screen_size: `${window.screen.width}x${window.screen.height}`,
screen_size: `${globalThis.screen.width}x${globalThis.screen.height}`,
device: getDeviceType(),
operating_system: getOperatingSystem(),
operating_system_version: getOSVersion(),
Expand Down
6 changes: 4 additions & 2 deletions website/handlers/fresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
isDeferred,
RequestContext,
} from "@deco/deco";
import type { Exception } from "npm:@opentelemetry/api@1.9.0";

type ConnInfo = Deno.ServeHandlerInfo;
/**
* @title Fresh Config
Expand Down Expand Up @@ -120,7 +122,7 @@ export default function Fresh(
try {
return await getPage();
} catch (e) {
span.recordException(e);
span.recordException(e as Exception);
throw e;
} finally {
span.end();
Expand Down Expand Up @@ -163,7 +165,7 @@ export default function Fresh(
}
return response;
} catch (err) {
span.recordException(err);
span.recordException(err as Exception);
throw err;
} finally {
span.end();
Expand Down
5 changes: 3 additions & 2 deletions website/loaders/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ const handler = async (

return response;
} catch (error) {
const errorObj = error as { message?: string; status: number };
console.error(error);

return new Response(error.message ?? Deno.inspect(error), {
status: error instanceof HttpError ? error.status : 500,
return new Response(errorObj.message ?? Deno.inspect(error), {
status: error instanceof HttpError ? errorObj.status : 500,
headers: {
"cache-control": "no-cache, no-store",
"vary": "Accept",
Expand Down
4 changes: 2 additions & 2 deletions website/pages/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class ErrorBoundary extends Component<{
// deno-lint-ignore no-explicit-any
fallback: ComponentFunc<any>;
}> {
state = { error: null as Error | null };
override state = { error: null as Error | null };
// deno-lint-ignore no-explicit-any
static getDerivedStateFromError(error: any) {
static override getDerivedStateFromError(error: any) {
return { error };
}
render() {
Expand Down
24 changes: 15 additions & 9 deletions website/utils/image/engines/cloudflare/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ export const engine: Engine = {

const format = prefferedMediaType?.replace("image/", "");

return fetch(src, {
// @ts-expect-error Only available when deployed into cloudflare workers
cf: {
image: { format, fit, width, height, quality },
cacheKey: `${format}-${src}`,
cacheEverything: true,
cacheTtlByStatus: { "200-299": 15552000, "400-499": 10, "500-599": 0 },
},
});
return fetch(
src,
{
cf: {
image: { format, fit, width, height, quality },
cacheKey: `${format}-${src}`,
cacheEverything: true,
cacheTtlByStatus: {
"200-299": 15552000,
"400-499": 10,
"500-599": 0,
},
},
} as RequestInit & { cf: unknown },
);
},

// is Cloudflare worker
Expand Down
Loading