From 54a76c173b3b16e0c6ca711214bb185318f39a12 Mon Sep 17 00:00:00 2001 From: Alisue Date: Tue, 14 May 2024 10:53:35 +0900 Subject: [PATCH 1/8] :bug: Do NOT use imports feature to support deno.land --- deno.jsonc | 5 ----- error_object.ts | 2 +- error_object_test.ts | 2 +- raise_test.ts | 2 +- scripts/build_npm.ts | 2 +- try_or_test.ts | 2 +- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/deno.jsonc b/deno.jsonc index 1cadc5f..3195944 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -7,10 +7,5 @@ "check": "deno check ./**/*.ts", "test": "deno test -A --parallel --shuffle --doc --coverage=.coverage", "coverage": "deno coverage .coverage" - }, - "imports": { - "@core/unknownutil": "jsr:@core/unknownutil@^3.17.2", - "@deno/dnt": "jsr:@deno/dnt@^0.41.1", - "@std/assert": "jsr:@std/assert@^0.221.0" } } diff --git a/error_object.ts b/error_object.ts index 3bb639c..0077bb5 100644 --- a/error_object.ts +++ b/error_object.ts @@ -1,4 +1,4 @@ -import { is, type Predicate } from "@core/unknownutil"; +import { is, type Predicate } from "jsr:@core/unknownutil"; export type ErrorObject = { proto: string; diff --git a/error_object_test.ts b/error_object_test.ts index 34404f7..7e1d051 100644 --- a/error_object_test.ts +++ b/error_object_test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertInstanceOf } from "@std/assert"; +import { assertEquals, assertInstanceOf } from "jsr:@std/assert"; import { fromErrorObject, toErrorObject } from "./error_object.ts"; class CustomError extends Error { diff --git a/raise_test.ts b/raise_test.ts index 86844ee..3aade56 100644 --- a/raise_test.ts +++ b/raise_test.ts @@ -1,4 +1,4 @@ -import { assertThrows } from "@std/assert"; +import { assertThrows } from "jsr:@std/assert"; import { raise } from "./raise.ts"; Deno.test("raise", () => { diff --git a/scripts/build_npm.ts b/scripts/build_npm.ts index e0fed7a..3c1b8ee 100644 --- a/scripts/build_npm.ts +++ b/scripts/build_npm.ts @@ -1,4 +1,4 @@ -import { build, emptyDir } from "@deno/dnt"; +import { build, emptyDir } from "jsr:@deno/dnt"; const name = "@lambdalisue/errorutil"; const version = Deno.args[0]; diff --git a/try_or_test.ts b/try_or_test.ts index 718b957..abd6f47 100644 --- a/try_or_test.ts +++ b/try_or_test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertRejects, assertThrows } from "@std/assert"; +import { assertEquals, assertRejects, assertThrows } from "jsr:@std/assert"; import { raise } from "./raise.ts"; import { tryOr, tryOrElse } from "./try_or.ts"; From 388af7a40ef490f97b9b24d8c01c34a051b01427 Mon Sep 17 00:00:00 2001 From: Alisue Date: Tue, 14 May 2024 10:57:41 +0900 Subject: [PATCH 2/8] :memo: Improve documentations --- deno.jsonc | 3 +++ raise.ts | 2 +- try_or.ts | 8 ++++---- unimplemented.ts | 2 +- unreachable.ts | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/deno.jsonc b/deno.jsonc index 3195944..5e1a1b8 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -7,5 +7,8 @@ "check": "deno check ./**/*.ts", "test": "deno test -A --parallel --shuffle --doc --coverage=.coverage", "coverage": "deno coverage .coverage" + }, + "imports": { + "https://deno.land/x/errorutil@$MODULE_VERSION/": "./" } } diff --git a/raise.ts b/raise.ts index 9be374d..b67923e 100644 --- a/raise.ts +++ b/raise.ts @@ -4,7 +4,7 @@ * This is function thus can be used as an expression. * * ```typescript - * import { raise } from "./raise.ts"; + * import { raise } from "https://deno.land/x/errorutil@$MODULE_VERSION/raise.ts"; * * const fn = () => raise(new Error("fail")); * ``` diff --git a/try_or.ts b/try_or.ts index b65cdcb..f413a60 100644 --- a/try_or.ts +++ b/try_or.ts @@ -2,8 +2,8 @@ * Try to execute a function and return the result or a default value. * * ```ts - * import { tryOr } from "./try_or.ts"; - * import { raise } from "./raise.ts"; + * import { tryOr } from "https://deno.land/x/errorutil@$MODULE_VERSION/try_or.ts"; + * import { raise } from "https://deno.land/x/errorutil@$MODULE_VERSION/raise.ts"; * * // Sync * console.log(tryOr(() => 1, 2)); // 1 @@ -30,8 +30,8 @@ export function tryOr( * Try to execute a function and return the result or execute another function. * * ```ts - * import { tryOrElse } from "./try_or.ts"; - * import { raise } from "./raise.ts"; + * import { tryOrElse } from "https://deno.land/x/errorutil@$MODULE_VERSION/try_or.ts"; + * import { raise } from "https://deno.land/x/errorutil@$MODULE_VERSION/raise.ts"; * * // Sync * console.log(tryOrElse(() => 1, () => 2)); // 1 diff --git a/unimplemented.ts b/unimplemented.ts index f432b0e..66d4de4 100644 --- a/unimplemented.ts +++ b/unimplemented.ts @@ -16,7 +16,7 @@ export class UnimplementedError extends Error { * For example, defining a mock object with `unimplemented` function should look like this: * * ```ts - * import { unimplemented } from "./unimplemented.ts"; + * import { unimplemented } from "https://deno.land/x/errorutil@$MODULE_VERSION/unimplemented.ts"; * * type Service = { * get(id: string): Promise; diff --git a/unreachable.ts b/unreachable.ts index 87638e4..0888651 100644 --- a/unreachable.ts +++ b/unreachable.ts @@ -19,7 +19,7 @@ export class UnreachableError extends Error { * For example, the following code passed type checking. * * ```ts - * import { unreachable } from "./unreachable.ts"; + * import { unreachable } from "https://deno.land/x/errorutil@$MODULE_VERSION/unreachable.ts"; * * type Animal = "dog" | "cat"; * @@ -41,7 +41,7 @@ export class UnreachableError extends Error { * But the following code because a case for "bird" is missing. * * ```ts - * import { unreachable } from "./unreachable.ts"; + * import { unreachable } from "https://deno.land/x/errorutil@$MODULE_VERSION/unreachable.ts"; * * type Animal = "dog" | "cat" | "bird"; * From 18709d5fc80a35a1bb6bff231fc4005efd97661d Mon Sep 17 00:00:00 2001 From: Alisue Date: Tue, 14 May 2024 10:58:24 +0900 Subject: [PATCH 3/8] :+1: Do NOT expose `Predicate` of `unknownutil` Close #2 --- error_object.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/error_object.ts b/error_object.ts index 0077bb5..a716608 100644 --- a/error_object.ts +++ b/error_object.ts @@ -1,4 +1,4 @@ -import { is, type Predicate } from "jsr:@core/unknownutil"; +import { is } from "jsr:@core/unknownutil"; export type ErrorObject = { proto: string; @@ -8,7 +8,7 @@ export type ErrorObject = { attributes: Record; }; -export const isErrorObject: Predicate = is.ObjectOf({ +export const isErrorObject: (x: unknown) => x is ErrorObject = is.ObjectOf({ proto: is.String, name: is.String, message: is.String, From a494971b3c36d4e13a264a52f9296633dde5f56e Mon Sep 17 00:00:00 2001 From: Alisue Date: Tue, 14 May 2024 11:03:13 +0900 Subject: [PATCH 4/8] :coffee: Refine `deno.jsonc` --- deno.jsonc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/deno.jsonc b/deno.jsonc index 5e1a1b8..160e050 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -2,11 +2,18 @@ "name": "@lambdalisue/errorutil", "version": "0.0.0", "exports": "./mod.ts", + "exclude": [ + ".coverage", + "npm" + ], "tasks": { "build-npm": "deno run -A scripts/build_npm.ts $(git describe --tags --always --dirty)", - "check": "deno check ./**/*.ts", - "test": "deno test -A --parallel --shuffle --doc --coverage=.coverage", - "coverage": "deno coverage .coverage" + "check": "deno check **/*.ts", + "test": "deno test -A --doc --parallel --shuffle", + "test:coverage": "deno task test --coverage=.coverage", + "coverage": "deno coverage .coverage", + "update": "deno run --allow-env --allow-read --allow-write=. --allow-run=git,deno --allow-net=jsr.io,registry.npmjs.org jsr:@molt/cli ./*.ts", + "update:commit": "deno task -q update --commit --pre-commit=fmt,lint" }, "imports": { "https://deno.land/x/errorutil@$MODULE_VERSION/": "./" From 6fd11550e6d00c8d273d50a2fc44bd35652c89af Mon Sep 17 00:00:00 2001 From: Alisue Date: Tue, 14 May 2024 11:03:23 +0900 Subject: [PATCH 5/8] :coffee: Add `update` CI --- .github/workflows/update.yml | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/update.yml diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..081d3ea --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,48 @@ +name: update + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + update: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: denoland/setup-deno@v1 + with: + deno-version: 1.x + - name: Configure Git + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + - name: Update dependencies and commit changes + run: deno task -q update:commit --summary ../title.txt --report ../body.md + - name: Check result + id: result + uses: andstor/file-existence-action@v2 + with: + files: ../title.txt, ../body.md + - name: Read title.txt + id: title + if: steps.result.outputs.files_exists == 'true' + uses: juliangruber/read-file-action@v1 + with: + path: ../title.txt + - name: Read body.md + id: body + if: steps.result.outputs.files_exists == 'true' + uses: juliangruber/read-file-action@v1 + with: + path: ../body.md + - name: Create a pull request + if: steps.result.outputs.files_exists == 'true' + uses: peter-evans/create-pull-request@v6 + with: + author: github-actions[bot] + branch: automation/update-dependencies + title: ${{ steps.title.outputs.content }} + body: ${{ steps.body.outputs.content }} + labels: automation + delete-branch: true From 50656943bd2c8ad6439f68d687823fa8f0a986c7 Mon Sep 17 00:00:00 2001 From: Alisue Date: Tue, 14 May 2024 11:03:38 +0900 Subject: [PATCH 6/8] :coffee: Refine `test` CI --- .github/workflows/test.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4188de..13c8e40 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,12 +5,15 @@ env: NODE_VERSION: 16.x on: - schedule: - - cron: "0 7 * * 0" push: branches: - main pull_request: + paths: + - "**.md" + - "**.ts" + - "deno.jsonc" + - ".github/workflows/test.yml" workflow_dispatch: jobs: @@ -40,9 +43,6 @@ jobs: run: | deno task test timeout-minutes: 5 - - name: JSR publish (dry-run) - run: | - deno publish --dry-run build-npm: runs-on: ubuntu-latest @@ -57,3 +57,14 @@ jobs: registry-url: "https://registry.npmjs.org" - name: Build run: deno task build-npm + + jsr-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: denoland/setup-deno@v1 + with: + deno-version: ${{ env.DENO_VERSION }} + - name: Publish (dry-run) + run: | + deno publish --dry-run From 502dddffe6e449705a71b2523d7fee0575429b3e Mon Sep 17 00:00:00 2001 From: Alisue Date: Tue, 14 May 2024 11:04:56 +0900 Subject: [PATCH 7/8] :memo: Fix README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5ff7b90..2a41ecf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # errorutil -[![jsr](https://img.shields.io/jsr/v/%40lambdalisue/errorutil?logo=javascript&logoColor=white)](https://jsr.io/@lambdalisue/errorutil) -[![denoland](https://img.shields.io/github/v/release/lambdalisue/deno-errorutil?logo=deno&label=denoland)](https://github.com/lambdalisue/deno-errorutil/releases) +[![JSR](https://jsr.io/badges/@lambdalisue/errorutil)](https://jsr.io/@lambdalisue/errorutil) +[![denoland](https://img.shields.io/github/v/release/lambdalisue/deno-errorutil?logo=deno&label=denoland)](https://deno.land/x/errorutil) [![npm](http://img.shields.io/badge/available%20on-npm-lightgrey.svg?logo=npm&logoColor=white)](https://www.npmjs.com/package/@lambdalisue/errorutil) [![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/errorutil/mod.ts) [![Test](https://github.com/lambdalisue/deno-errorutil/workflows/Test/badge.svg)](https://github.com/lambdalisue/deno-errorutil/actions?query=workflow%3ATest) From 9d4070d8f18093dbeef12802fa65b5ae42c70973 Mon Sep 17 00:00:00 2001 From: Alisue Date: Tue, 14 May 2024 11:06:14 +0900 Subject: [PATCH 8/8] :coffee: Add Codecov action --- .github/workflows/test.yml | 9 ++++++++- README.md | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13c8e40..b4e8167 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,8 +41,15 @@ jobs: deno-version: ${{ env.DENO_VERSION }} - name: Test run: | - deno task test + deno task test:coverage timeout-minutes: 5 + - run: | + deno task coverage --lcov > coverage.lcov + - uses: codecov/codecov-action@v4 + with: + os: ${{ runner.os }} + files: ./coverage.lcov + token: ${{ secrets.CODECOV_TOKEN }} build-npm: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 2a41ecf..1c8628d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/errorutil/mod.ts) [![Test](https://github.com/lambdalisue/deno-errorutil/workflows/Test/badge.svg)](https://github.com/lambdalisue/deno-errorutil/actions?query=workflow%3ATest) [![npm version](https://badge.fury.io/js/@lambdalisue%2Ferrorutil.svg)](https://badge.fury.io/js/@lambdalisue%2Ferrorutil) +[![codecov](https://codecov.io/gh/lambdalisue/deno-errorutil/graph/badge.svg?token=O0cA5Xj5la)](https://codecov.io/gh/lambdalisue/deno-errorutil) A utility pack for handling error.