Skip to content

Commit

Permalink
replace deprecated methods and use importMaps for Deno
Browse files Browse the repository at this point in the history
  • Loading branch information
fwqaaq committed Apr 10, 2024
1 parent 4cb8e68 commit dea338a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 5 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"dev": "deno fmt && deno lint && deno task test && deno task check",
"coverage": "rm -rf ./test/cov_profile && deno task test --coverage=./test/cov_profile && deno coverage --lcov --output=./coverage.lcov ./test/cov_profile",
"report": "genhtml ./coverage.lcov --output-directory ./test/coverage/ && echo 'Point your browser to test/coverage/index.html to see the test coverage report.'",
"bundle": "cd bundling && ./bundle-all.sh",
"bundle-web": "mkdir -p out deno_cache && cd bundling && DENO_DIR=$PWD/../deno_cache deno run --unstable --quiet --allow-net --allow-read --allow-env=DENO_DIR,XDG_CACHE_HOME,HOME,DENO_AUTH_TOKENS --allow-write=../out,$PWD/../deno_cache bundle-web.ts dev ../src/mod.ts",
"contribs": "deno run --allow-env --allow-read --allow-write=. --allow-net=api.github.com --allow-sys npm:all-contributors-cli"
},
Expand All @@ -31,5 +30,10 @@
"./package-lock.json",
"./bundling/bundles"
]
},
"imports": {
"@std/path": "jsr:@std/path@^0.221.0",
"grammy_types": "https://deno.land/x/[email protected]/mod.ts",
"debug": "https://cdn.skypack.dev/[email protected]"
}
}
2 changes: 1 addition & 1 deletion src/platform.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export const isDeno = typeof Deno !== "undefined";

// === Export debug
import debug from "https://cdn.skypack.dev/debug@4.3.4";
import debug from "debug";
export { debug };
const DEBUG = "DEBUG";
if (isDeno) {
Expand Down
13 changes: 6 additions & 7 deletions src/types.deno.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// === Needed imports
import { basename } from "https://deno.land/[email protected]/path/basename.ts";
import { iterateReader } from "https://deno.land/[email protected]/streams/iterate_reader.ts";
import { basename } from "@std/path";
import {
type ApiMethods as ApiMethodsF,
type InputMedia as InputMediaF,
Expand All @@ -11,13 +10,13 @@ import {
type InputMediaVideo as InputMediaVideoF,
type InputSticker as InputStickerF,
type Opts as OptsF,
} from "https://deno.land/x/grammy_types@v3.6.2/mod.ts";
} from "grammy_types";
import { debug as d, isDeno } from "./platform.deno.ts";

const debug = d("grammy:warn");

// === Export all API types
export * from "https://deno.land/x/grammy_types@v3.6.2/mod.ts";
export * from "grammy_types";

/** A value, or a potentially async function supplying that value */
type MaybeSupplier<T> = T | (() => T | Promise<T>);
Expand Down Expand Up @@ -114,11 +113,11 @@ export class InputFile {
"Reading files by path requires a Deno environment",
);
}
const file = await Deno.open(data);
return iterateReader(file);
using file = await Deno.open(data);
return file.readable;
}
if (data instanceof Blob) return data.stream();
if (isDenoFile(data)) return iterateReader(data);
if (isDenoFile(data)) return data.readable;
// Handle Response objects
if (data instanceof Response) {
if (data.body === null) throw new Error(`No response body!`);
Expand Down

0 comments on commit dea338a

Please sign in to comment.