Skip to content

Commit

Permalink
AbstractError with chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Apr 5, 2022
1 parent fb198c1 commit 22152c2
Show file tree
Hide file tree
Showing 27 changed files with 362 additions and 2,096 deletions.
81 changes: 0 additions & 81 deletions .github/workflows/codesee-arch-diagram.yml

This file was deleted.

141 changes: 4 additions & 137 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ variables:

stages:
- check
- build
- quality
- release

image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner

lint:
stage: check
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
interruptible: true
script:
- >
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs --run '
Expand All @@ -22,142 +21,10 @@ lint:
test:
stage: check
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
interruptible: true
script:
- >
nix-shell -I nixpkgs=./pkgs.nix --packages nodejs --run '
npm install;
npm run test;
'
nix-dry:
stage: check
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
script:
- nix-build -v -v --dry-run ./release.nix --attr application
- nix-build -v -v --dry-run ./release.nix --attr docker
- nix-build -v -v --dry-run ./release.nix --attr package.linux.x64.elf
- nix-build -v -v --dry-run ./release.nix --attr package.windows.x64.exe
- nix-build -v -v --dry-run ./release.nix --attr package.macos.x64.macho

nix:
stage: build
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
script:
- mkdir -p ./builds
# nix-specific application target
- >
build_application="$(nix-build \
--max-jobs "$(nproc)" --cores "$(nproc)" \
./release.nix \
--attr application \
)"
- >
nix-store --export $( \
nix-store --query --requisites "$build_application" \
) | gzip > ./builds/typescript-demo-lib.closure.gz
# non-nix targets
- >
builds="$(nix-build \
--max-jobs "$(nproc)" --cores "$(nproc)" \
./release.nix \
--attr docker \
--attr package.linux.x64.elf \
--attr package.windows.x64.exe \
--attr package.macos.x64.macho)"
- cp -r $builds ./builds/
only:
- master
artifacts:
paths:
- ./builds/

application run:
stage: quality
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
dependencies:
- nix
script:
- >
build_application="$( \
gunzip -c ./builds/typescript-demo-lib.closure.gz | \
nix-store --import | \
tail -1 \
)"
- $build_application/bin/typescript-demo-lib
only:
- master

docker run:
stage: quality
image: docker:20.10.11
dependencies:
- nix
services:
- docker:20.10.11-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- docker info
script:
- image="$(docker load --input ./builds/*docker* | cut -d' ' -f3)"
- docker run "$image"
only:
- master

linux run:
stage: quality
image: ubuntu:latest
dependencies:
- nix
script:
- for f in ./builds/*-linux-*; do "$f"; done
only:
- master

windows run:
stage: quality
dependencies:
- nix
script:
- Get-ChildItem -File ./builds/*-win32-* | ForEach {& $_.FullName}
tags:
- windows
only:
- master

# macos is disabled until this repo has access
# macos run:
# stage: quality
# image: macos-11-xcode-12
# dependencies:
# - nix
# script:
# - for f in ./builds/*-macos-*; do "$f"; done
# only:
# - master
# tags:
# - shared-macos-amd64

packages:
stage: release
image: registry.gitlab.com/matrixai/engineering/maintenance/gitlab-runner
dependencies:
- nix
script:
- >
nix-shell -I nixpkgs=./pkgs.nix --packages git gitAndTools.gh --run '
commit="$(git rev-parse --short HEAD)";
gh release \
create "$commit" \
builds/*.closure.gz \
builds/*-linux-* \
builds/*-win32-* \
builds/*-macos-* \
--title "Build-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--prerelease \
--notes "" \
--repo MatrixAI/TypeScript-Demo-Lib;
'
only:
- master
128 changes: 5 additions & 123 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
# TypeScript-Demo-Lib
# js-errors

[![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)
[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-errors/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-errors/commits/master)

## Installation

Note that JavaScript libraries are not packaged in Nix. Only JavaScript applications are.

Building the package:

```sh
nix-build -E '(import ./pkgs.nix).callPackage ./default.nix {}'
```

Building the releases:

```sh
nix-build ./release.nix --attr application
nix-build ./release.nix --attr docker
```

Install into Nix user profile:

```sh
nix-env -f ./release.nix --install --attr application
```
Exception system with error chaining.

Install into Docker:
## Installation

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

## Development
Expand All @@ -52,101 +29,6 @@ npm run lint
npm run lintfix
```

### Calling Executables

When calling executables in development, use this style:

```
npm run typescript-demo-lib -- p1 p2 p3
```

The `--` is necessary to make `npm` understand that the parameters are for your own executable, and not parameters to `npm`.

### Using the REPL

```
$ npm run ts-node
> import fs from 'fs';
> fs
> import { Library } from '@';
> Library
> import Library as Library2 from './src/lib/Library';
```

You can also create test files in `./src`, and run them with `npm run ts-node ./src/test.ts`.

This allows you to test individual pieces of typescript code, and it makes it easier when doing large scale architecting of TypeScript code.

### Path Aliases

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.

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.

### Native Module Toolchain

There are some nuances when packaging with native modules.
Included native modules are level witch include leveldown and utp-native.

If a module is not set to public then pkg defaults to including it as bytecode.
To avoid this breaking with the `--no-bytecode` flag we need to add `--public-packages "*"`

#### leveldown

To get leveldown to work with pkg we need to include the prebuilds with the executable.
after building with pkg you need to copy from `node_modules/leveldown/prebuilds` -> `path_to_executable/prebuilds`
You only need to include the prebuilds for the arch you are targeting. e.g. for linux-x64 you need `prebuild/linux-x64`.

The folder structure for the executable should look like this.
- linux_executable_elf
- prebuilds
- linux-x64
- (node files)

#### utp-native

Including utp-native is simpler, you just need to add it as an asset for pkg.
Add the following lines to the package.json.
```json
"pkg": {
"assets": "node_modules/utp-native/**/*"
}
```

#### threads.js

To make sure that the worker threads work properly you need to include the compiled worker scripts as an asset.
This can be fixed by adding the following to `package.json`

```json
"pkg": {
"assets": "dist/bin/worker.js"
}
```

If you need to include multiple assets then add them as an array.

```json
"pkg": {
"assets": [
"node_modules/utp-native/**/*",
"dist/bin/worker.js"
]
}
```

#### Integration into Nix

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`.

To ensure the proper dependencies exist while building we need to bring in these utilities during the build:

```
buildInputs = attrs.buildInputs ++ [ nodePackages.node-gyp-build ];
```

This has to be done to both `node2nixProd` and `node2nixDev`.

### Docs Generation

```sh
Expand Down
Loading

0 comments on commit 22152c2

Please sign in to comment.