-
Notifications
You must be signed in to change notification settings - Fork 17
fix: support deno version 2.x #122
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
Merged
WilliamBergamin
merged 17 commits into
slackapi:main
from
WilliamBergamin:ci-deno-version-2.x
Jun 4, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2e85948
what am I doing?
WilliamBergamin 7617f70
stop using mockfetch in favor of std
WilliamBergamin c0c6338
Update samples.yml
WilliamBergamin bef57d2
Update samples.yml
WilliamBergamin 2195f03
update-deps
WilliamBergamin 10f15bf
Fix HTTP error
WilliamBergamin ef1595b
clean up tests
WilliamBergamin 9a4ee3b
Update samples.yml
WilliamBergamin 16bde2e
improve testing helpers
WilliamBergamin 537bb9e
update sample CI
WilliamBergamin 00a4ee5
Merge branch 'main' into ci-deno-version-2.x
WilliamBergamin c6f5e2d
fix broken test
WilliamBergamin ffb8623
Merge branch 'ci-deno-version-2.x' of https://github.com/WilliamBerga…
WilliamBergamin e8fc13b
update sample action
WilliamBergamin 55ac943
Update update.ts
WilliamBergamin 6b19a48
Update deno.yml
WilliamBergamin d1991d2
Update samples.yml
WilliamBergamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ jobs: | |
| samples: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| sample: | ||
| - slack-samples/deno-issue-submission | ||
|
|
@@ -21,9 +22,12 @@ jobs: | |
| - slack-samples/deno-message-translator | ||
| - slack-samples/deno-request-time-off | ||
| - slack-samples/deno-simple-survey | ||
| # we test on both most recent stable version of deno (v1.x) as well as | ||
| # we test on both most recent stable version of deno (v1.x, v2.x) as well as | ||
| # the version of deno used by Run on Slack (as noted in https://api.slack.com/slackcli/metadata.json) | ||
| deno-version: [v1.x, v1.45.4] | ||
| deno-version: | ||
| - v1.x | ||
| - v1.46.2 | ||
| - v2.x | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
|
|
@@ -44,14 +48,13 @@ jobs: | |
| path: ./sample | ||
| persist-credentials: false | ||
|
|
||
| - name: Set imports.deno-slack-api/ to ../deno-slack-api/src/ in import_map.json | ||
| - name: Set imports.deno-slack-api/ to ../deno-slack-api/src/ in imports | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 The logging in this updated file is so helpful! https://github.com/slackapi/deno-slack-api/actions/runs/15397083256/job/43320475967#step:5:205 |
||
| run: > | ||
| deno run | ||
| --allow-read --allow-write --allow-net | ||
| deno-slack-api/scripts/src/import_map/update.ts | ||
| --import-map "./sample/import_map.json" | ||
| --parent-import-map "./deno-slack-api/deno.jsonc" | ||
| --api "../deno-slack-api/src/" | ||
| deno-slack-api/scripts/src/imports/update.ts | ||
| --import-file "./sample/deno.jsonc" | ||
| --api "./deno-slack-api/" | ||
|
|
||
| - name: Deno check **/*.ts | ||
| working-directory: ./sample | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { parseArgs } from "@std/cli/parse-args"; | ||
| import { createHttpError } from "@std/http/http-errors"; | ||
| import { dirname, join, relative } from "@std/path"; | ||
|
|
||
| // Regex for https://deno.land/x/[email protected]/ | ||
| const API_REGEX = | ||
| /(https:\/\/deno.land\/x\/deno_slack_api@[0-9]\.[0-9]+\.[0-9]+\/)/g; | ||
|
|
||
| async function main() { | ||
| const flags = parseArgs(Deno.args, { | ||
| string: ["import-file", "api"], | ||
| default: { | ||
| "import-file": `${Deno.cwd()}/deno.jsonc`, | ||
| "api": "./deno-slack-api/", | ||
| }, | ||
| }); | ||
|
|
||
| const importFilePath = await Deno.realPath(flags["import-file"]); | ||
| const importFileDir = dirname(importFilePath); | ||
| const apiDir = await Deno.realPath(flags.api); | ||
|
|
||
| const importFileJsonIn = await Deno.readTextFile(importFilePath); | ||
| console.log(`content in ${flags["import-file"]}:`, importFileJsonIn); | ||
|
|
||
| const importFile = JSON.parse(importFileJsonIn); | ||
| const denoSlackSdkValue = importFile["imports"]["deno-slack-sdk/"]; | ||
|
|
||
| const apiDepsInSdk = await apiDepsIn(denoSlackSdkValue); | ||
|
|
||
| const apiPackageSpecifier = join( | ||
| relative(importFileDir, apiDir), | ||
| "/src/", | ||
| ); | ||
|
|
||
| importFile["imports"]["deno-slack-api/"] = apiPackageSpecifier; | ||
| importFile["scopes"] = { | ||
| [denoSlackSdkValue]: [...apiDepsInSdk].reduce( | ||
| (sdkScopes: Record<string, string>, apiDep: string) => { | ||
| return { | ||
| ...sdkScopes, | ||
| [apiDep]: apiPackageSpecifier, | ||
| }; | ||
| }, | ||
| {}, | ||
| ), | ||
| }; | ||
|
|
||
| const parentFileJsonIn = await Deno.readTextFile( | ||
| join(apiDir, "/deno.jsonc"), | ||
| ); | ||
| console.log("parent `import file` in content:", parentFileJsonIn); | ||
| const parentImportFile = JSON.parse(parentFileJsonIn); | ||
| for (const entry of Object.entries(parentImportFile["imports"])) { | ||
| importFile["imports"][entry[0]] = entry[1]; | ||
| } | ||
|
|
||
| const importMapJsonOut = JSON.stringify(importFile, null, 2); | ||
| console.log("`import file` out content:", importMapJsonOut); | ||
|
|
||
| await Deno.writeTextFile(flags["import-file"], importMapJsonOut); | ||
| } | ||
|
|
||
| export async function apiDepsIn(moduleUrl: string): Promise<Set<string>> { | ||
| const fileUrl = moduleUrl.endsWith("/") | ||
| ? `${moduleUrl}deps.ts?source,file` | ||
| : `${moduleUrl}/deps.ts?source,file`; | ||
| const response = await fetch(fileUrl); | ||
|
|
||
| if (!response.ok) { | ||
| const err = createHttpError(response.status, await response.text(), { | ||
| expose: true, | ||
| headers: response.headers, | ||
| }); | ||
| console.error(err); | ||
| throw err; | ||
| } | ||
|
|
||
| const depsTs = await response.text(); | ||
| return new Set(depsTs.match(API_REGEX)); | ||
| } | ||
|
|
||
| if (import.meta.main) main(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,19 @@ | ||
| import { isHttpError } from "@std/http/http-errors"; | ||
| import { mf } from "../../../src/dev_deps.ts"; | ||
| import { assertEquals, assertRejects } from "@std/assert"; | ||
| import { afterEach, beforeAll } from "@std/testing/bdd"; | ||
| import { apiDepsIn } from "./update.ts"; | ||
| import { stubFetch } from "../../../testing/http.ts"; | ||
|
|
||
| const depsTsMock = | ||
| `export { SlackAPI } from "https://deno.land/x/[email protected]/mod.ts"; | ||
| export type {SlackAPIClient, Trigger} from "https://deno.land/x/[email protected]/types.ts";`; | ||
|
|
||
| beforeAll(() => { | ||
| mf.install(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| mf.reset(); | ||
| }); | ||
|
|
||
| Deno.test("apiDepsIn should return a list of the api module urls used by a module", async () => { | ||
| mf.mock("GET@/x/[email protected]/deps.ts", (req: Request) => { | ||
| using _fetchStub = stubFetch((req) => { | ||
| assertEquals( | ||
| req.url, | ||
| "https://deno.land/x/[email protected]/deps.ts?source,file", | ||
| ); | ||
| return new Response(depsTsMock); | ||
| }); | ||
| }, new Response(depsTsMock)); | ||
|
|
||
| const apiDeps = await apiDepsIn( | ||
| "https://deno.land/x/[email protected]/", | ||
|
|
@@ -39,9 +29,12 @@ Deno.test("apiDepsIn should return a list of the api module urls used by a modul | |
| }); | ||
|
|
||
| Deno.test("apiDepsIn should throw http error on response not ok", async () => { | ||
| mf.mock("GET@/x/[email protected]/deps.ts", () => { | ||
| return new Response("error", { status: 500 }); | ||
| }); | ||
| using _fetchStub = stubFetch( | ||
| (req) => { | ||
| assertEquals(req.url, "https://deno.land/x/[email protected]/deps.ts"); | ||
| }, | ||
| new Response("error", { status: 500 }), | ||
| ); | ||
|
|
||
| const error = await assertRejects(() => | ||
| apiDepsIn("https://deno.land/x/[email protected]/") | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Thanks for expanding this out!