Skip to content

Commit 068dbf5

Browse files
authored
Merge pull request #1 from MatrixAI/errors
Release error chaining and formalise custom errors
2 parents fb198c1 + dc258b8 commit 068dbf5

Some content is hidden

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

54 files changed

+2971
-7355
lines changed

.github/workflows/codesee-arch-diagram.yml

Lines changed: 0 additions & 81 deletions
This file was deleted.

.gitlab-ci.yml

Lines changed: 4 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ variables:
66

77
stages:
88
- check
9-
- build
10-
- quality
11-
- release
9+
10+
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
1211

1312
lint:
1413
stage: check
15-
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
14+
interruptible: true
1615
script:
1716
- >
1817
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs --run '
@@ -22,142 +21,10 @@ lint:
2221
2322
test:
2423
stage: check
25-
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
24+
interruptible: true
2625
script:
2726
- >
2827
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs --run '
2928
npm install;
3029
npm run test;
3130
'
32-
33-
nix-dry:
34-
stage: check
35-
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
36-
script:
37-
- nix-build -v -v --dry-run ./release.nix --attr application
38-
- nix-build -v -v --dry-run ./release.nix --attr docker
39-
- nix-build -v -v --dry-run ./release.nix --attr package.linux.x64.elf
40-
- nix-build -v -v --dry-run ./release.nix --attr package.windows.x64.exe
41-
- nix-build -v -v --dry-run ./release.nix --attr package.macos.x64.macho
42-
43-
nix:
44-
stage: build
45-
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
46-
script:
47-
- mkdir -p ./builds
48-
# nix-specific application target
49-
- >
50-
build_application="$(nix-build \
51-
--max-jobs "$(nproc)" --cores "$(nproc)" \
52-
./release.nix \
53-
--attr application \
54-
)"
55-
- >
56-
nix-store --export $( \
57-
nix-store --query --requisites "$build_application" \
58-
) | gzip > ./builds/typescript-demo-lib.closure.gz
59-
# non-nix targets
60-
- >
61-
builds="$(nix-build \
62-
--max-jobs "$(nproc)" --cores "$(nproc)" \
63-
./release.nix \
64-
--attr docker \
65-
--attr package.linux.x64.elf \
66-
--attr package.windows.x64.exe \
67-
--attr package.macos.x64.macho)"
68-
- cp -r $builds ./builds/
69-
only:
70-
- master
71-
artifacts:
72-
paths:
73-
- ./builds/
74-
75-
application run:
76-
stage: quality
77-
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
78-
dependencies:
79-
- nix
80-
script:
81-
- >
82-
build_application="$( \
83-
gunzip -c ./builds/typescript-demo-lib.closure.gz | \
84-
nix-store --import | \
85-
tail -1 \
86-
)"
87-
- $build_application/bin/typescript-demo-lib
88-
only:
89-
- master
90-
91-
docker run:
92-
stage: quality
93-
image: docker:20.10.11
94-
dependencies:
95-
- nix
96-
services:
97-
- docker:20.10.11-dind
98-
variables:
99-
DOCKER_TLS_CERTDIR: "/certs"
100-
before_script:
101-
- docker info
102-
script:
103-
- image="$(docker load --input ./builds/*docker* | cut -d' ' -f3)"
104-
- docker run "$image"
105-
only:
106-
- master
107-
108-
linux run:
109-
stage: quality
110-
image: ubuntu:latest
111-
dependencies:
112-
- nix
113-
script:
114-
- for f in ./builds/*-linux-*; do "$f"; done
115-
only:
116-
- master
117-
118-
windows run:
119-
stage: quality
120-
dependencies:
121-
- nix
122-
script:
123-
- Get-ChildItem -File ./builds/*-win32-* | ForEach {& $_.FullName}
124-
tags:
125-
- windows
126-
only:
127-
- master
128-
129-
# macos is disabled until this repo has access
130-
# macos run:
131-
# stage: quality
132-
# image: macos-11-xcode-12
133-
# dependencies:
134-
# - nix
135-
# script:
136-
# - for f in ./builds/*-macos-*; do "$f"; done
137-
# only:
138-
# - master
139-
# tags:
140-
# - shared-macos-amd64
141-
142-
packages:
143-
stage: release
144-
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
145-
dependencies:
146-
- nix
147-
script:
148-
- >
149-
nix-shell -I nixpkgs=./pkgs.nix --packages git gitAndTools.gh --run '
150-
commit="$(git rev-parse --short HEAD)";
151-
gh release \
152-
create "$commit" \
153-
builds/*.closure.gz \
154-
builds/*-linux-* \
155-
builds/*-win32-* \
156-
builds/*-macos-* \
157-
--title "Build-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
158-
--prerelease \
159-
--notes "" \
160-
--repo MatrixAI/TypeScript-Demo-Lib;
161-
'
162-
only:
163-
- master

README.md

Lines changed: 5 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,13 @@
1-
# TypeScript-Demo-Lib
1+
# js-errors
22

3-
[![pipeline status](https://gitlab.com/MatrixAI/open-source/TypeScript-Demo-Lib/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/TypeScript-Demo-Lib/commits/master)
3+
[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-errors/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-errors/commits/master)
44

5-
## Installation
6-
7-
Note that JavaScript libraries are not packaged in Nix. Only JavaScript applications are.
8-
9-
Building the package:
10-
11-
```sh
12-
nix-build -E '(import ./pkgs.nix).callPackage ./default.nix {}'
13-
```
14-
15-
Building the releases:
16-
17-
```sh
18-
nix-build ./release.nix --attr application
19-
nix-build ./release.nix --attr docker
20-
```
21-
22-
Install into Nix user profile:
23-
24-
```sh
25-
nix-env -f ./release.nix --install --attr application
26-
```
5+
Exception system with error chaining.
276

28-
Install into Docker:
7+
## Installation
298

309
```sh
31-
loaded="$(docker load --input "$(nix-build ./release.nix --attr docker)")"
32-
image="$(cut -d' ' -f3 <<< "$loaded")"
33-
docker run -it "$image"
10+
npm install --save @matrixai/errors
3411
```
3512

3613
## Development
@@ -52,101 +29,6 @@ npm run lint
5229
npm run lintfix
5330
```
5431

55-
### Calling Executables
56-
57-
When calling executables in development, use this style:
58-
59-
```
60-
npm run typescript-demo-lib -- p1 p2 p3
61-
```
62-
63-
The `--` is necessary to make `npm` understand that the parameters are for your own executable, and not parameters to `npm`.
64-
65-
### Using the REPL
66-
67-
```
68-
$ npm run ts-node
69-
> import fs from 'fs';
70-
> fs
71-
> import { Library } from '@';
72-
> Library
73-
> import Library as Library2 from './src/lib/Library';
74-
```
75-
76-
You can also create test files in `./src`, and run them with `npm run ts-node ./src/test.ts`.
77-
78-
This allows you to test individual pieces of typescript code, and it makes it easier when doing large scale architecting of TypeScript code.
79-
80-
### Path Aliases
81-
82-
Due to https://github.com/microsoft/TypeScript/issues/10866, you cannot use path aliases without a bundler like Webpack to further transform the generated JavaScript code in order to resolve the path aliases. Because this is a simple library demonstration, there's no need to use a bundler. In fact, for such libraries, it is far more efficient to not bundle the code.
83-
84-
However, we have left the path alias configuration in `tsconfig.json`, `jest.config.js` and in the tests we are making use of the `@` alias.
85-
86-
### Native Module Toolchain
87-
88-
There are some nuances when packaging with native modules.
89-
Included native modules are level witch include leveldown and utp-native.
90-
91-
If a module is not set to public then pkg defaults to including it as bytecode.
92-
To avoid this breaking with the `--no-bytecode` flag we need to add `--public-packages "*"`
93-
94-
#### leveldown
95-
96-
To get leveldown to work with pkg we need to include the prebuilds with the executable.
97-
after building with pkg you need to copy from `node_modules/leveldown/prebuilds` -> `path_to_executable/prebuilds`
98-
You only need to include the prebuilds for the arch you are targeting. e.g. for linux-x64 you need `prebuild/linux-x64`.
99-
100-
The folder structure for the executable should look like this.
101-
- linux_executable_elf
102-
- prebuilds
103-
- linux-x64
104-
- (node files)
105-
106-
#### utp-native
107-
108-
Including utp-native is simpler, you just need to add it as an asset for pkg.
109-
Add the following lines to the package.json.
110-
```json
111-
"pkg": {
112-
"assets": "node_modules/utp-native/**/*"
113-
}
114-
```
115-
116-
#### threads.js
117-
118-
To make sure that the worker threads work properly you need to include the compiled worker scripts as an asset.
119-
This can be fixed by adding the following to `package.json`
120-
121-
```json
122-
"pkg": {
123-
"assets": "dist/bin/worker.js"
124-
}
125-
```
126-
127-
If you need to include multiple assets then add them as an array.
128-
129-
```json
130-
"pkg": {
131-
"assets": [
132-
"node_modules/utp-native/**/*",
133-
"dist/bin/worker.js"
134-
]
135-
}
136-
```
137-
138-
#### Integration into Nix
139-
140-
Nix build uses node2nix to create the dependencies of the node modules. this does a fairly good job of detecting dependencies but with native modules it may fail to detect CLI tools like `node-gyp-build`.
141-
142-
To ensure the proper dependencies exist while building we need to bring in these utilities during the build:
143-
144-
```
145-
buildInputs = attrs.buildInputs ++ [ nodePackages.node-gyp-build ];
146-
```
147-
148-
This has to be done to both `node2nixProd` and `node2nixDev`.
149-
15032
### Docs Generation
15133

15234
```sh

0 commit comments

Comments
 (0)