-
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
Changes from 16 commits
2e85948
7617f70
c0c6338
bef57d2
2195f03
10f15bf
ef1595b
9a4ee3b
16bde2e
537bb9e
00a4ee5
c6f5e2d
ffb8623
e8fc13b
55ac943
6b19a48
d1991d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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.45.4 | ||
|
||
| - 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 was deleted.
| 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(); | ||
| 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]/") | ||
|
|
||
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!