Skip to content

Commit b82dba8

Browse files
authored
feat: implement in Deno (#2)
1 parent 79aca26 commit b82dba8

17 files changed

+107
-2460
lines changed

.commitlintrc.json

-5
This file was deleted.

.github/workflows/npm-publish.yml

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Package to npmjs
1+
name: Publish Package to npm
22

33
on:
44
release:
@@ -11,30 +11,29 @@ jobs:
1111
- name: Checkout git repository
1212
uses: actions/checkout@v3
1313

14-
- name: Use Node.js 18.x
15-
uses: actions/setup-node@v3
14+
- name: Setup Deno - Latest
15+
uses: denoland/setup-deno@v1
1616
with:
17-
node-version: '18.x'
18-
registry-url: 'https://registry.npmjs.org'
17+
deno-version: vx.x.x
1918

20-
- name: Cache dependencies
21-
uses: actions/cache@v3
19+
- name: Setup Node.js - 18.x
20+
uses: actions/setup-node@v3
2221
with:
23-
path: |
24-
node_modules
25-
*/*/node_modules
26-
key: yarn-deps-${{ hashFiles('**/yarn.lock') }}
22+
node-version: "18.x"
23+
registry-url: "https://registry.npmjs.org"
2724

28-
- name: Install dependencies
29-
run: |
30-
yarn
25+
- name: Get tag version
26+
if: startsWith(github.ref, 'refs/tags/')
27+
id: get_tag_version
28+
run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}
3129

32-
- name: Run tests
33-
run: yarn test
30+
- name: Build for npm
31+
run: deno run -A ./scripts/build.ts ${{steps.get_tag_version.outputs.TAG_VERSION}}
3432

35-
- name: Transpile to JavaScript
36-
run: yarn transpile
37-
38-
- run: npm publish --access=public
33+
- name: Publish to npm
34+
if: startsWith(github.ref, 'refs/tags/')
35+
run: |
36+
cd npm
37+
npm publish --access=public
3938
env:
40-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/pull-request-testing.yml

+7-48
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ name: Pull request testing
22

33
on:
44
push:
5-
branches-ignore:
5+
branches-ignore:
66
- main
77
paths:
8-
- '.github/workflows/pull-request-testing.yml'
9-
- 'jest.config.ts'
10-
- 'src/**/*.ts'
8+
- ".github/workflows/pull-request-testing.yml"
9+
- "**/*.ts"
1110

1211
jobs:
1312
dependencies:
@@ -17,52 +16,12 @@ jobs:
1716
- name: Check out Git repository
1817
uses: actions/checkout@v3
1918

20-
- name: Use Node.js 18.x
21-
uses: actions/setup-node@v1
19+
- name: Setup Deno - Latest
20+
uses: denoland/setup-deno@v1
2221
with:
23-
node-version: '18.x'
24-
25-
- name: Cache dependencies
26-
uses: actions/cache@v3
27-
with:
28-
path: |
29-
node_modules
30-
*/*/node_modules
31-
key: yarn-deps-${{ hashFiles('**/yarn.lock') }}
32-
33-
- name: Install dependencies
34-
run: |
35-
yarn
36-
37-
unit:
38-
name: Unit and integration tests
39-
needs: dependencies
40-
runs-on: ubuntu-latest
41-
steps:
42-
- name: Check out Git repository
43-
uses: actions/checkout@v3
44-
45-
- name: Wait for Docker environment to be ready
46-
run: ./scripts/wait-catena-x-at-home-ready.sh
47-
48-
- name: Use Node.js 18.x
49-
uses: actions/setup-node@v1
50-
with:
51-
node-version: '18.x'
52-
53-
- name: Cache dependencies
54-
uses: actions/cache@v3
55-
with:
56-
path: |
57-
node_modules
58-
*/*/node_modules
59-
key: yarn-deps-${{ hashFiles('**/yarn.lock') }}
60-
61-
- name: Install dependencies
62-
run: |
63-
yarn
22+
deno-version: vx.x.x
6423

6524
- name: Run tests
66-
run: yarn test
25+
run: deno test
6726
env:
6827
CI: true

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
coverage/
22
dist/
3-
node_modules/
3+
node_modules/
4+
npm/

.lintstagedrc.json

-8
This file was deleted.

.npmignore

-6
This file was deleted.

.prettierrc.json

-8
This file was deleted.

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deno.enable": true
3+
}

README.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<h1>TypedError ⌨️💥</h1>
33
<p>
44
<b>
5-
JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" target="_blank">Error</a> for TypeScript projects.
5+
A better JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" target="_blank">Error</a> for Node.js, Deno and the browser.
66
</b>
77
</p>
88
<sub>
@@ -17,7 +17,7 @@ large projects.
1717
The [JavaScript `Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
1818
is a necessary component of the error handling story, but it's often too limited.
1919

20-
The main difficulty is categorising errors; when building the main business logic
20+
The main difficulty is categorizing errors; when building the main business logic
2121
of any project, it's common to encounter similar errors (e.g. duplicate entities,
2222
forbidden access, etc.), and relying on
2323
[`Error.prototype.message`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
@@ -29,6 +29,8 @@ a smoother error handling story.
2929

3030
## Usage
3131

32+
### Node.js
33+
3234
Install via `npm` or `yarn`
3335

3436
```sh
@@ -39,11 +41,17 @@ npm install @think-it-labs/typed-error
3941
yarn add @think-it-labs/typed-error
4042
```
4143

42-
Then it's possible to create a custom `Error` class extending the `TypedError`
44+
### Deno
45+
46+
Import as ES module
4347

4448
```ts
45-
import { TypedError } from "@think-it-labs/typed-error"
49+
import { TypedError } from "https://deno.land/x/typederror/mod.ts"
50+
```
4651

52+
Then it's possible to create a custom `Error` class extending the `TypedError`
53+
54+
```ts
4755
enum MyErrorType {
4856
Unknown,
4957
HTTP,
@@ -53,7 +61,7 @@ export class MyError extends TypedError<MyErrorType> {}
5361

5462
```
5563

56-
Now, during error handling code can inspect the `type` error and define behaviour accordingly
64+
Now, during error handling code can inspect the `type` error and define behavior accordingly
5765

5866
```ts
5967
import { MyError, MyErrorType } from "./my-error"
@@ -66,7 +74,7 @@ export function errorHandling(error: unknown) {
6674
}
6775
case MyErrorType.Unknown:
6876
default: {
69-
// red alert: unknown behaviour
77+
// red alert: unknown behavior
7078
}
7179
}
7280
}

jest.config.ts

-15
This file was deleted.

src/index.ts mod.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* `TypedError` is a superset of the `Error` class.
3-
* It extends it by allowing the specialisation to a custom _type_.
3+
* It extends it by allowing the specialization to a custom _type_.
44
*
55
* **Example:**
66
* ```ts
@@ -14,7 +14,7 @@
1414
* ```
1515
*/
1616
export class TypedError<T> extends Error {
17-
/** Specialisation type */
17+
/** Specialization type */
1818
type: T;
1919

2020
constructor(type: T, message?: string, options?: ErrorOptions) {

package.json

-24
This file was deleted.

scripts/build.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ex. scripts/build_npm.ts
2+
import { build, emptyDir } from "https://deno.land/x/dnt@0.32.1/mod.ts";
3+
4+
await emptyDir("./npm");
5+
6+
await build({
7+
entryPoints: ["./mod.ts"],
8+
outDir: "./npm",
9+
shims: {
10+
deno: true,
11+
},
12+
compilerOptions: {
13+
lib: ["es2022"],
14+
},
15+
package: {
16+
// package.json properties
17+
name: "@think-it-labs/typed-error",
18+
version: Deno.args[0],
19+
description:
20+
"A better JavaScript Error for for Node.js, Deno and the browser.",
21+
license: "MIT",
22+
repository: {
23+
type: "git",
24+
url: "git+https://github.com/think-it-labs/typed-error.git",
25+
},
26+
engines: {
27+
node: ">=16.9",
28+
},
29+
bugs: {
30+
url: "https://github.com/think-it-labs/typed-error/issues",
31+
},
32+
},
33+
});
34+
35+
// post build steps
36+
// Deno.copyFileSync("LICENSE", "npm/LICENSE");
37+
// Deno.copyFileSync("README.md", "npm/README.md");

tests/tsconfig.json

-15
This file was deleted.

0 commit comments

Comments
 (0)