Skip to content
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
8 changes: 6 additions & 2 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jobs:
matrix:
# we test on both most recent stable version of deno (v1.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
Comment on lines +18 to +21
Copy link
Member

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!

permissions:
contents: read
steps:
Expand All @@ -33,8 +36,9 @@ jobs:
run: deno task generate-lcov
- name: Upload coverage to CodeCov
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
if: matrix.deno-version == 'v2.x'
with:
file: ./lcov.info
files: ./lcov.info
token: ${{ secrets.CODECOV_TOKEN }}

health-score:
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
samples:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
- slack-samples/deno-issue-submission
Expand All @@ -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:
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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

`import file` out content:
...
    "deno-slack-api/": "../deno-slack-api/src/",

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
Expand Down
10 changes: 6 additions & 4 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
"docs",
"README.md",
".github/maintainers_guide.md",
".github/CONTRIBUTING.md"
".github/CONTRIBUTING.md",
"testing"
]
},
"lint": {
"include": ["src", "scripts"]
"include": ["src", "scripts", "testing"]
},
"publish": {
"exclude": ["./README.md"]
},
"test": {
"include": ["src", "scripts"]
"include": ["src", "scripts", "testing"]
},
"tasks": {
"test": "deno fmt --check && deno lint && deno test",
Expand All @@ -36,7 +37,8 @@
"@std/assert": "jsr:@std/assert@^1",
"@std/cli": "jsr:@std/cli@^1",
"@std/fs": "jsr:@std/fs@^1",
"@std/http": "jsr:@std/http@^0.206",
"@std/http": "jsr:@std/http@^0.206.0",
"@std/path": "jsr:@std/path@^1.0.9",
"@std/testing": "jsr:@std/testing@^1",
"@std/text": "jsr:@std/text@^1"
}
Expand Down
75 changes: 0 additions & 75 deletions scripts/src/import_map/update.ts

This file was deleted.

82 changes: 82 additions & 0 deletions scripts/src/imports/update.ts
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/",
},
});

Check warning on line 16 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L9-L16

Added lines #L9 - L16 were not covered by tests

const importFilePath = await Deno.realPath(flags["import-file"]);
const importFileDir = dirname(importFilePath);
const apiDir = await Deno.realPath(flags.api);

Check warning on line 20 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L18-L20

Added lines #L18 - L20 were not covered by tests

const importFileJsonIn = await Deno.readTextFile(importFilePath);
console.log(`content in ${flags["import-file"]}:`, importFileJsonIn);

Check warning on line 23 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L22-L23

Added lines #L22 - L23 were not covered by tests

const importFile = JSON.parse(importFileJsonIn);
const denoSlackSdkValue = importFile["imports"]["deno-slack-sdk/"];

Check warning on line 26 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L25-L26

Added lines #L25 - L26 were not covered by tests

const apiDepsInSdk = await apiDepsIn(denoSlackSdkValue);

Check warning on line 28 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L28

Added line #L28 was not covered by tests

const apiPackageSpecifier = join(
relative(importFileDir, apiDir),
"/src/",

Check warning on line 32 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L30-L32

Added lines #L30 - L32 were not covered by tests
);

importFile["imports"]["deno-slack-api/"] = apiPackageSpecifier;
importFile["scopes"] = {
[denoSlackSdkValue]: [...apiDepsInSdk].reduce(
(sdkScopes: Record<string, string>, apiDep: string) => {
return {
...sdkScopes,
[apiDep]: apiPackageSpecifier,
};
},
{},

Check warning on line 44 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L35-L44

Added lines #L35 - L44 were not covered by tests
),
};

Check warning on line 46 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L46

Added line #L46 was not covered by tests

const parentFileJsonIn = await Deno.readTextFile(
join(apiDir, "/deno.jsonc"),

Check warning on line 49 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L48-L49

Added lines #L48 - L49 were not covered by tests
);
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];
}

Check warning on line 55 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L51-L55

Added lines #L51 - L55 were not covered by tests

const importMapJsonOut = JSON.stringify(importFile, null, 2);
console.log("`import file` out content:", importMapJsonOut);

Check warning on line 58 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L57-L58

Added lines #L57 - L58 were not covered by tests

await Deno.writeTextFile(flags["import-file"], importMapJsonOut);
}

Check warning on line 61 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L60-L61

Added lines #L60 - L61 were not covered by tests

export async function apiDepsIn(moduleUrl: string): Promise<Set<string>> {
const fileUrl = moduleUrl.endsWith("/")

Check warning on line 64 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L64

Added line #L64 was not covered by tests
? `${moduleUrl}deps.ts?source,file`
: `${moduleUrl}/deps.ts?source,file`;

Check warning on line 66 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L66

Added line #L66 was not covered by tests
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;

Check warning on line 75 in scripts/src/imports/update.ts

View check run for this annotation

Codecov / codecov/patch

scripts/src/imports/update.ts#L70-L75

Added lines #L70 - L75 were not covered by tests
}

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]/",
Expand All @@ -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]/")
Expand Down
Loading
Loading