Migrate project foundations to TypeScript (#342)

This commit is contained in:
Michał Leszczyński
2024-07-14 10:45:24 -07:00
committed by GitHub
parent ce798f60f9
commit daa5bd2417
67 changed files with 1123 additions and 185 deletions

View File

@@ -1,40 +0,0 @@
name: Check halocli tool
on:
push:
paths-ignore:
- 'README.md'
- 'cli/README.md'
- 'docs/**'
pull_request:
paths-ignore:
- 'README.md'
- 'cli/README.md'
- 'docs/**'
branches:
- master
jobs:
check_cli_tool:
runs-on: ubuntu-22.04
steps:
- name: Install native dependencies (Linux)
run: |
sudo apt-get update && sudo apt-get install -y libpcsclite-dev
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install Node.JS
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies (root)
run: |
yarn install --frozen-lockfile --production=false
- name: Install dependencies (cli)
run: |
cd cli
yarn install --frozen-lockfile --production=false
- name: Package HaLo CLI tool (Linux)
run: |
cd cli
node_modules/.bin/pkg -t node18-linux-x64 package.json

View File

@@ -1,33 +0,0 @@
name: Check libhalo.js
on:
push:
paths-ignore:
- 'README.md'
- 'cli/README.md'
- 'docs/**'
pull_request:
paths-ignore:
- 'README.md'
- 'cli/README.md'
- 'docs/**'
branches:
- master
jobs:
check_js_lib:
runs-on: ubuntu-22.04
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install Node.JS
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies (root)
run: |
yarn install --frozen-lockfile --production=false
- name: Run webpack
run: |
cd web
webpack

View File

@@ -77,7 +77,9 @@ jobs:
- name: Install dependencies (root)
shell: bash
run: |
cd core
yarn install --frozen-lockfile --production=false
./node_modules/.bin/tsc
- name: Install dependencies (cli)
shell: bash
run: |
@@ -86,13 +88,13 @@ jobs:
- name: Build libhalo with webpack
shell: bash
run: |
cd web
../node_modules/.bin/webpack
cd core
./node_modules/.bin/webpack
- name: Build halo-tools with webpack
shell: bash
run: |
cd cli
../node_modules/.bin/webpack
./node_modules/.bin/webpack
mv dist_webpack/* .
mkdir build
cp node_modules/@pokusew/pcsclite/build/Release/pcsclite.node build/pcsclite.node

View File

@@ -56,10 +56,11 @@ jobs:
node-version: 20
- name: Install dependencies (root)
run: |
cd core
yarn install --frozen-lockfile --production=false
- name: Run webpack
run: |
cd web
cd core
webpack
- name: Download release upload URL
uses: actions/download-artifact@v4
@@ -73,7 +74,7 @@ jobs:
uses: sigstore/cosign-installer@v3.5.0
- name: Sign libhalo.js with cosign
run: |
cd ./web/dist
cd ./core/dist
echo y | cosign sign-blob ./libhalo.js --output-certificate ./libhalo.js-keyless.pem --output-signature ./libhalo.js-keyless.sig
cosign verify-blob --cert ./libhalo.js-keyless.pem --signature ./libhalo.js-keyless.sig --certificate-identity "https://github.com/arx-research/libhalo/.github/workflows/prod_build_lib.yml@${GITHUB_REF}" --certificate-oidc-issuer https://token.actions.githubusercontent.com ./libhalo.js
- name: Upload release asset (JS bundle)
@@ -83,7 +84,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.out_store.outputs.release_upload_url }}
asset_path: ./web/dist/libhalo.js
asset_path: ./core/dist/libhalo.js
asset_name: libhalo.js
asset_content_type: text/javascript
- name: Upload release asset (LICENSE file)
@@ -93,7 +94,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.out_store.outputs.release_upload_url }}
asset_path: ./web/dist/libhalo.js.LICENSE.txt
asset_path: ./core/dist/libhalo.js.LICENSE.txt
asset_name: libhalo.js.LICENSE.txt
asset_content_type: text/plain
- name: Upload release asset (cosign pem)
@@ -103,7 +104,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.out_store.outputs.release_upload_url }}
asset_path: ./web/dist/libhalo.js-keyless.pem
asset_path: ./core/dist/libhalo.js-keyless.pem
asset_name: libhalo.js-keyless.pem
asset_content_type: application/octet-stream
- name: Upload release asset (cosign sig)
@@ -113,7 +114,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.out_store.outputs.release_upload_url }}
asset_path: ./web/dist/libhalo.js-keyless.sig
asset_path: ./core/dist/libhalo.js-keyless.sig
asset_name: libhalo.js-keyless.sig
asset_content_type: application/octet-stream
@@ -143,7 +144,10 @@ jobs:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- name: Run npm ci
run: yarn install --frozen-lockfile --production=false
run: |
cd core
yarn install --frozen-lockfile --production=false
./node_modules/.bin/tsc
- name: Publish package to npmjs
run: yarn publish
env:

9
cli/.gitignore vendored
View File

@@ -1,3 +1,6 @@
assets/static/*.js
assets/static/*.js.*
.pkg-cache/
/node_modules/
/lib.esm/
/assets/static/*.js
/assets/static/*.js.*
/.pkg-cache/

View File

@@ -25,8 +25,6 @@
"bugs": {
"url": "https://github.com/arx-research/libhalo/issues/new/choose"
},
"main": "entry_cli.js",
"bin": "entry_cli.js",
"pkg": {
"targets": [
"node20"
@@ -40,9 +38,12 @@
},
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"reload-libhalo": "cd ../core && ./node_modules/.bin/tsc && cd ../cli && yarn add ../core"
},
"dependencies": {
"@arx-research/libhalo": "../core",
"bufferutil": "^4.0.8",
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2",
"nfc-pcsc": "^0.8.1",
@@ -53,6 +54,8 @@
"devDependencies": {
"@yao-pkg/pkg": "^5.12.0",
"resedit": "^2.0.2",
"ts-loader": "^9.5.1",
"typescript": "^5.5.3",
"webpack": "^5.92.1",
"webpack-cli": "^5.1.4"
}

View File

@@ -8,7 +8,7 @@ import {Buffer} from 'buffer/index.js';
import {NFC} from 'nfc-pcsc';
import open from 'open';
import {__runTestSuite} from "../halo/tests.js";
import {__runTestSuite} from "@arx-research/libhalo/__tests";
import util from "util";
import {
wsEventCardDisconnected,
@@ -18,7 +18,7 @@ import {
wsEventCardIncompatible,
wsEventReaderDisconnected
} from "./ws_server.js";
import {execHaloCmdPCSC} from "../api/desktop.js";
import {execHaloCmdPCSC} from "@arx-research/libhalo/api/desktop";
const nfc = new NFC();
let stopPCSCTimeout = null;

View File

@@ -1,7 +1,10 @@
import { fileURLToPath } from 'node:url';
import { dirname as path_dirname } from 'node:path';
import crypto from "crypto";
import {randomBuffer} from "../halo/util.js";
function randomBuffer() {
return Buffer.from(crypto.getRandomValues(new Uint8Array(32)));
}
let dirname;

View File

@@ -1,7 +1,6 @@
import express from 'express';
import nunjucks from "nunjucks";
import {WebSocketServer} from 'ws';
import {webcrypto as crypto} from 'crypto';
import {dirname, randomBuffer} from "./util.js";
import jwt from 'jsonwebtoken';
import https from "https";
@@ -9,9 +8,9 @@ import fs from "fs";
import path from "path";
import os from "os";
import util from "util";
import {execHaloCmdPCSC} from "../api/desktop.js";
import {execHaloCmdPCSC} from "@arx-research/libhalo/api/desktop";
import {getBuildInfo} from "./version.js";
import {NFCOperationError} from "../halo/exceptions.js";
import {NFCOperationError} from "@arx-research/libhalo/api/common";
let wss = null;

36
cli/tsconfig.json Normal file
View File

@@ -0,0 +1,36 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"lib": [
"es2020",
"es5",
"dom"
],
"moduleResolution": "node16",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"preserveSymlinks": true,
"preserveWatchOutput": true,
"pretty": false,
"rootDir": "./src.ts/",
"strict": true,
"sourceMap": true,
"target": "es2022",
"module": "node16",
"outDir": "./lib.esm",
"allowJs": true
},
"include": [
"./src.ts/**/*.tsx",
"./src.ts/**/*.js"
],
"exclude": []
}

View File

@@ -1,14 +1,14 @@
import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export default {
entry: {
entry_cli: './entry_cli.js',
entry_bridge: './entry_bridge.js',
entry_gateway: './entry_gateway.js',
entry_cli: './src.ts/entry_cli.js',
entry_bridge: './src.ts/entry_bridge.js',
entry_gateway: './src.ts/entry_gateway.js',
},
output: {
filename: '[name].bundle.js',
@@ -16,9 +16,21 @@ export default {
},
mode: 'production',
target: 'node',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
vm: false
vm: false,
chokidar: false,
"utf-8-validate": false
}
},
optimization: {

File diff suppressed because it is too large Load Diff

3
core/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/node_modules/
/dist/
/lib.esm/

1
core/.npmignore Normal file
View File

@@ -0,0 +1 @@
/dist/

View File

@@ -25,8 +25,29 @@
"bugs": {
"url": "https://github.com/arx-research/libhalo/issues/new/choose"
},
"main": "index.js",
"main": "./lib.esm/index.js",
"module": "./lib.esm/index.js",
"type": "module",
"exports": {
".": {
"import": "./lib.esm/index.js"
},
"./api/common": {
"import": "./lib.esm/api/common.js"
},
"./api/desktop": {
"import": "./lib.esm/api/desktop.js"
},
"./api/react-native": {
"import": "./lib.esm/api/react-native.js"
},
"./api/web": {
"import": "./lib.esm/api/web.js"
},
"./__tests": {
"import": "./lib.esm/halo/tests.js"
}
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
@@ -46,6 +67,7 @@
"crypto-browserify": "^3.12.0",
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"typescript": "^5.5.3",
"webpack": "^5.92.1",
"webpack-cli": "^5.1.4"
}

36
core/tsconfig.json Normal file
View File

@@ -0,0 +1,36 @@
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"lib": [
"es2020",
"es5",
"dom"
],
"moduleResolution": "node16",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"preserveSymlinks": true,
"preserveWatchOutput": true,
"pretty": false,
"rootDir": "./src.ts/",
"strict": true,
"sourceMap": true,
"target": "es2022",
"module": "node16",
"outDir": "./lib.esm",
"allowJs": true
},
"include": [
"./src.ts/**/*.tsx",
"./src.ts/**/*.js"
],
"exclude": []
}

View File

@@ -1,28 +1,39 @@
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import webpack from "webpack";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
import fs from 'fs';
import webpack from "webpack";
import path from "path";
export default {
entry: {
app: './weblib.js',
app: './src.ts/web/weblib.js',
},
output: {
filename: 'libhalo.js'
filename: 'libhalo.js',
path: resolve(__dirname, 'dist')
},
mode: 'production',
target: 'web',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
vm: false,
buffer: path.resolve(__dirname, '../node_modules/buffer/index.js'),
crypto: path.resolve(__dirname, '../node_modules/crypto-browserify'),
stream: path.resolve(__dirname, '../node_modules/stream-browserify'),
buffer: resolve(__dirname, './node_modules/buffer/index.js'),
crypto: resolve(__dirname, './node_modules/crypto-browserify'),
stream: resolve(__dirname, './node_modules/stream-browserify')
},
},
plugins: [

View File

@@ -40,9 +40,9 @@
"@jridgewell/trace-mapping" "^0.3.25"
"@jridgewell/sourcemap-codec@^1.4.10", "@jridgewell/sourcemap-codec@^1.4.14":
version "1.4.15"
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32"
integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==
version "1.5.0"
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz#3188bcb273a414b0d215fd22a58540b989b9409a"
integrity sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==
"@jridgewell/trace-mapping@^0.3.20", "@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25":
version "0.3.25"
@@ -409,14 +409,14 @@ browserify-sign@^4.0.0:
safe-buffer "^5.2.1"
browserslist@^4.21.10:
version "4.23.1"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.23.1.tgz#ce4af0534b3d37db5c1a4ca98b9080f985041e96"
integrity sha512-TUfofFo/KsK/bWZ9TWQ5O26tsWW4Uhmt8IYklbnUa70udB6P2wA7w7o4PY4muaEPBQaAX+CEnmmIA41NVHtPVw==
version "4.23.2"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.23.2.tgz#244fe803641f1c19c28c48c4b6ec9736eb3d32ed"
integrity sha512-qkqSyistMYdxAcw+CzbZwlBy8AGmS/eEWs+sEV5TnLRGDOL+C5M2EnH6tlZyg0YoAxGJAFKh61En9BR941GnHA==
dependencies:
caniuse-lite "^1.0.30001629"
electron-to-chromium "^1.4.796"
caniuse-lite "^1.0.30001640"
electron-to-chromium "^1.4.820"
node-releases "^2.0.14"
update-browserslist-db "^1.0.16"
update-browserslist-db "^1.1.0"
buffer-from@^1.0.0:
version "1.1.2"
@@ -452,10 +452,10 @@ camelcase@^5.0.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
caniuse-lite@^1.0.30001629:
version "1.0.30001640"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001640.tgz#32c467d4bf1f1a0faa63fc793c2ba81169e7652f"
integrity sha512-lA4VMpW0PSUrFnkmVuEKBUovSWKhj7puyCg8StBChgu298N1AtuF1sKWEvfDuimSEDbhlb/KqPKC3fs1HbuQUA==
caniuse-lite@^1.0.30001640:
version "1.0.30001642"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001642.tgz#6aa6610eb24067c246d30c57f055a9d0a7f8d05f"
integrity sha512-3XQ0DoRgLijXJErLSl+bLnJ+Et4KqV1PY6JJBGAFlsNsz31zeAIncyeZfLCabHK/jtSh+671RM9YMldxjUPZtA==
chnl@^1.2.0:
version "1.2.0"
@@ -659,10 +659,10 @@ dijkstrajs@^1.0.1:
resolved "https://registry.yarnpkg.com/dijkstrajs/-/dijkstrajs-1.0.3.tgz#4c8dbdea1f0f6478bff94d9c49c784d623e4fc23"
integrity sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==
electron-to-chromium@^1.4.796:
version "1.4.820"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.820.tgz#1195660c157535392a09442540a08ee63fea8c40"
integrity sha512-kK/4O/YunacfboFEk/BDf7VO1HoPmDudLTJAU9NmXIOSjsV7qVIX3OrI4REZo0VmdqhcpUcncQc6N8Q3aEXlHg==
electron-to-chromium@^1.4.820:
version "1.4.827"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.827.tgz#76068ed1c71dd3963e1befc8ae815004b2da6a02"
integrity sha512-VY+J0e4SFcNfQy19MEoMdaIcZLmDCprqvBtkii1WTCTQHpRvf5N8+3kTYCgL/PcntvwQvmMJWTuDPsq+IlhWKQ==
elliptic@^6.5.3, elliptic@^6.5.5:
version "6.5.5"
@@ -1784,9 +1784,9 @@ terser-webpack-plugin@^5.3.10:
terser "^5.26.0"
terser@^5.26.0:
version "5.31.1"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.31.1.tgz#735de3c987dd671e95190e6b98cfe2f07f3cf0d4"
integrity sha512-37upzU1+viGvuFtBo9NPufCb9dwM0+l9hMxYyWfBA+fbwrPqNJAhbZ6W47bBFnZHKHTUBnMvi87434qq+qnxOg==
version "5.31.2"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.31.2.tgz#b5ca188107b706084dca82f988089fa6102eba11"
integrity sha512-LGyRZVFm/QElZHy/CPr/O4eNZOZIzsrQ92y4v9UJe/pFJjypje2yI3C2FmPtvUEnhadlSbmG2nXtdcjHOjCfxw==
dependencies:
"@jridgewell/source-map" "^0.3.3"
acorn "^8.8.2"
@@ -1842,6 +1842,11 @@ typed-array-length@^1.0.6:
is-typed-array "^1.1.13"
possible-typed-array-names "^1.0.0"
typescript@^5.5.3:
version "5.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.3.tgz#e1b0a3c394190838a0b168e771b0ad56a0af0faa"
integrity sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==
unbox-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e"
@@ -1857,7 +1862,7 @@ undici-types@~5.26.4:
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
update-browserslist-db@^1.0.16:
update-browserslist-db@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.0.tgz#7ca61c0d8650766090728046e416a8cde682859e"
integrity sha512-EdRAaAyk2cUE1wOf2DkEhzxqOQvFOoRJFNS6NeyJ01Gp2beMRpBAINjM2iDXE3KCuKhwnvHIQCJm6ThL2Z+HzQ==
@@ -1919,9 +1924,9 @@ webpack-sources@^3.2.3:
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==
webpack@^5.92.1:
version "5.92.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.92.1.tgz#eca5c1725b9e189cffbd86e8b6c3c7400efc5788"
integrity sha512-JECQ7IwJb+7fgUFBlrJzbyu3GEuNBcdqr1LD7IbSzwkSmIevTm8PF+wej3Oxuz/JFBUZ6O1o43zsPkwm1C4TmA==
version "5.93.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.93.0.tgz#2e89ec7035579bdfba9760d26c63ac5c3462a5e5"
integrity sha512-Y0m5oEY1LRuwly578VqluorkXbvXKh7U3rLoQCEO04M97ScRr44afGVkI0FQFsXzysk5OgFAxjZAb9rsGQVihA==
dependencies:
"@types/eslint-scope" "^3.7.3"
"@types/estree" "^1.0.5"