Skip to content

Commit 0a7a819

Browse files
lambtroniuioiua
andauthored
add JSR support (#110)
* update * consolidate * lint * refactor: better improve codebase for JSR * work * work * fix --------- Co-authored-by: Asher Gomez <[email protected]>
1 parent 9105487 commit 0a7a819

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+214
-214
lines changed

.github/workflows/publish.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write # The OIDC ID token is used for authentication with JSR.
14+
steps:
15+
- uses: actions/checkout@v4
16+
- run: npx jsr publish

.github/workflows/samples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
--allow-read --allow-write --allow-net
4343
deno-slack-api/scripts/import_map/update.ts
4444
--import-map "./sample/import_map.json"
45+
--parent-import-map "./deno-slack-api/deno.jsonc"
4546
--api "../deno-slack-api/src/"
4647
4748
- name: Deno check **/*.ts

deno.jsonc

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
{
22
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
33
"fmt": {
4-
"files": {
5-
"include": [
6-
"src",
7-
"scripts",
8-
"docs",
9-
"README.md",
10-
".github/maintainers_guide.md",
11-
".github/CONTRIBUTING.md"
12-
]
13-
},
14-
"options": {
15-
"semiColons": true,
16-
"indentWidth": 2,
17-
"lineWidth": 80,
18-
"proseWrap": "always",
19-
"singleQuote": false,
20-
"useTabs": false
21-
}
4+
"include": [
5+
"src",
6+
"scripts",
7+
"docs",
8+
"README.md",
9+
".github/maintainers_guide.md",
10+
".github/CONTRIBUTING.md"
11+
]
2212
},
2313
"lint": {
24-
"files": {
25-
"include": ["src", "scripts"]
26-
}
14+
"include": ["src", "scripts"]
15+
},
16+
"publish": {
17+
"exclude": ["./README.md"]
2718
},
2819
"test": {
29-
"files": {
30-
"include": ["src", "scripts"]
31-
}
20+
"include": ["src", "scripts"]
3221
},
3322
"tasks": {
3423
"test": "deno fmt --check && deno lint && deno test",
3524
"generate-lcov": "rm -rf .coverage && deno test --reporter=dot --coverage=.coverage && deno coverage --exclude=fixtures --exclude=test --exclude=scripts --exclude=src/generated --lcov --output=lcov.info .coverage",
3625
"test:coverage": "deno task generate-lcov && deno coverage --exclude=fixtures --exclude=test --exclude=scripts --exclude=src/generated .coverage src"
3726
},
38-
"lock": false
27+
"lock": false,
28+
"name": "@slack/api",
29+
"version": "2.9.0",
30+
"exports": {
31+
".": "./src/mod.ts",
32+
"./types": "./src/types.ts"
33+
},
34+
"imports": {
35+
"@deno/dnt": "jsr:@deno/dnt@^0.41",
36+
"@std/assert": "jsr:@std/assert@^1",
37+
"@std/cli": "jsr:@std/cli@^1",
38+
"@std/fs": "jsr:@std/fs@^1",
39+
"@std/http": "jsr:@std/http@^0.206",
40+
"@std/testing": "jsr:@std/testing@^1",
41+
"@std/text": "jsr:@std/text@^1"
42+
}
3943
}

docs/client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To instantiate the Slack API Client, use the top level `SlackAPI` export.
1111
default this is set to `"https://slack.com/api/"`
1212

1313
```ts
14-
import { SlackAPI } from "https://deno.land/x/[email protected]/mod.ts";
14+
import { SlackAPI } from "jsr:@slack/api";
1515

1616
// create a client with defaults
1717
const client = SlackAPI(token);

scripts/build_npm.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// ex. scripts/build_npm.ts
2-
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts";
2+
import { emptyDir } from "@std/fs";
3+
import { build } from "@deno/dnt";
34

45
await emptyDir("./npm");
56

@@ -10,7 +11,7 @@ await build({
1011
outDir: "./npm",
1112
// ensures that the emitted package is compatible with node v14 later
1213
compilerOptions: {
13-
lib: ["es2022.error"], // fix ErrorOptions not exported in ES2020
14+
lib: ["ES2022.Error"], // fix ErrorOptions not exported in ES2020
1415
target: "ES2020",
1516
},
1617
shims: {

scripts/import_map/update.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
2-
import {
3-
createHttpError,
4-
} from "https://deno.land/[email protected]/http/http_errors.ts";
1+
import { parseArgs } from "@std/cli/parse-args";
2+
import { createHttpError } from "@std/http/http-errors";
53

64
// Regex for https://deno.land/x/deno_slack_api@x.x.x/
75
const API_REGEX =
8-
/(https:\/\/deno.land\/x\/deno_slack_api@[0-9]+\.[0-9]+\.[0-9]+\/)/g;
6+
/(https:\/\/deno.land\/x\/deno_slack_api@[0-9]\.[0-9]+\.[0-9]+\/)/g;
97

108
async function main() {
11-
const flags = parse(Deno.args, {
12-
string: ["import-map", "api"],
9+
const flags = parseArgs(Deno.args, {
10+
string: ["import-map", "api", "parent-import-map"],
1311
default: {
1412
"import-map": `${Deno.cwd()}/import_map.json`,
1513
"api": "../deno-slack-api/src/",
14+
"parent-import-map": undefined,
1615
},
1716
});
1817

@@ -37,7 +36,18 @@ async function main() {
3736
),
3837
};
3938

40-
const importMapJsonOut = JSON.stringify(importMap);
39+
if (flags["parent-import-map"]) {
40+
const parentImportMapJsonIn = await Deno.readTextFile(
41+
flags["parent-import-map"],
42+
);
43+
console.log("parent `import_map.json` in content:", parentImportMapJsonIn);
44+
const parentImportMap = JSON.parse(parentImportMapJsonIn);
45+
for (const entry of Object.entries(parentImportMap["imports"])) {
46+
importMap["imports"][entry[0]] = entry[1];
47+
}
48+
}
49+
50+
const importMapJsonOut = JSON.stringify(importMap, null, 2);
4151
console.log("`import_map.json` out content:", importMapJsonOut);
4252

4353
await Deno.writeTextFile(flags["import-map"], importMapJsonOut);

scripts/import_map/update_test.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { HttpError } from "../../src/deps.ts";
2-
import {
3-
afterEach,
4-
assertEquals,
5-
assertRejects,
6-
beforeAll,
7-
mf,
8-
} from "../../src/dev_deps.ts";
1+
import { isHttpError } from "@std/http/http-errors";
2+
import { mf } from "../../src/dev_deps.ts";
3+
import { assertEquals, assertRejects } from "@std/assert";
4+
import { afterEach, beforeAll } from "@std/testing/bdd";
95
import { apiDepsIn } from "./update.ts";
106

117
const depsTsMock =
@@ -47,12 +43,8 @@ Deno.test("apiDepsIn should throw http error on response not ok", async () => {
4743
return new Response("error", { status: 500 });
4844
});
4945

50-
await assertRejects(
51-
async () => {
52-
return await apiDepsIn(
53-
"https://deno.land/x/[email protected]/",
54-
);
55-
},
56-
HttpError,
46+
const error = await assertRejects(() =>
47+
apiDepsIn("https://deno.land/x/[email protected]/")
5748
);
49+
isHttpError(error);
5850
});

scripts/src/generate.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { emptyDir, ensureDir, pascalCase } from "../../src/deps.ts";
1+
import { toPascalCase } from "@std/text/to-pascal-case";
2+
import { emptyDir, ensureDir } from "@std/fs";
23
import { APIMethodNode } from "./api-method-node.ts";
34
import { getPublicAPIMethods } from "./public-api-methods.ts";
45

@@ -67,12 +68,12 @@ run();
6768

6869
const getMainAPICode = (api: APIMethodNode): string => {
6970
const imports = api.childNodes.map((node) => {
70-
const groupAPITypeName = `${pascalCase(node.name)}APIType`;
71+
const groupAPITypeName = `${toPascalCase(node.name)}APIType`;
7172
return `import { type ${groupAPITypeName} } from "./${node.name}.ts";`;
7273
}).join("\n");
7374

7475
const apiTypeMixins = api.childNodes.map((node) => {
75-
const groupAPIName = pascalCase(node.name);
76+
const groupAPIName = toPascalCase(node.name);
7677
return `${node.name}: ${groupAPIName}APIType,`;
7778
}).join("\n");
7879

@@ -120,7 +121,7 @@ const getTestCode = (api: APIMethodNode) => {
120121
visitMethodNodes(api);
121122

122123
return `
123-
import { assertEquals } from "../../dev_deps.ts";
124+
import { assertEquals } from "@std/assert";
124125
import { SlackAPI } from "../../mod.ts";
125126
126127
Deno.test("SlackAPIMethodsType generated types", () => {

src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Slack API Client for Deno Run on Slack projects
66

77
```ts
8-
import { SlackAPI } from "https://deno.land/x/[email protected]/mod.ts";
8+
import { SlackAPI } from "jsr:@slack/api";
99

1010
const client = SlackAPI(token);
1111

src/api-proxy.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { BaseSlackAPIClient } from "./base-client.ts";
2-
import { BaseResponse, SlackAPIClient, SlackAPIMethodArgs } from "./types.ts";
1+
import type { BaseSlackAPIClient } from "./base-client.ts";
2+
import type {
3+
BaseResponse,
4+
SlackAPIClient,
5+
SlackAPIMethodArgs,
6+
} from "./types.ts";
37

48
const DO_NOT_PROXY = ["then"];
59

0 commit comments

Comments
 (0)