Skip to content

Commit

Permalink
Convert to typescript (#88)
Browse files Browse the repository at this point in the history
* Add typescript dependency

* Convert /model to ts

* Convert utils to TS

* Convert webrtc/stats/ to TS

* Add type depedencies

* Convert /webrtc/ to TS

* Convert tests/model and tests/utils to TS

* Convert tests/webrtc/stats/ to TS

* Convert tests/webrtc/ to TS

* Configure eslint

* Bump version

* Add build step to workflows

* Add rollup config

* Add back assert.ts

* Add more types

* Add ts-ignore for webrtc-adapter

* Add prettier rule to eslintrc

* Rebase on latest main

* fix errors with lax constraints

* revert to evaluating error constraint

* update mediadevices unit-tests

---------

Co-authored-by: Pontus Fagerström <pontus.fagerstrom@whereby.com>
  • Loading branch information
thyal and pnts-se-whereby authored Mar 22, 2024
1 parent 5ad66c2 commit af48e36
Show file tree
Hide file tree
Showing 74 changed files with 2,546 additions and 1,290 deletions.
31 changes: 24 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
{
"parser": "@babel/eslint-parser",
"env": {
"browser": true,
"es6": true,
"jest/globals": true,
"node": true
"jest": true,
"node": true,
},
"extends": ["./config/eslint/browser", "prettier"],
"ignorePatterns": ["dist/*"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"requireConfigFile": false
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
},
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"plugins": ["prettier", "jest"],
"rules": {
"no-console": ["error", { "allow": ["warn", "error"] }],
"prettier/prettier": "error"
}
"prettier/prettier": "error",
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"prefer-spread": "off",
"prefer-destructuring": "off",
"prefer-rest-params": "off",
"@typescript-eslint/no-var-requires": "off",
"no-inner-declarations": "off",
"no-unsafe-optional-chaining": "off",
"no-prototype-builtins": "off",
"no-case-declarations": "off",
"no-empty": "off",
"@typescript-eslint/ban-types": "off",
},
}
7 changes: 4 additions & 3 deletions .github/workflows/deploy-release-worflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ jobs:
- name: Setup npmrc
run: echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc

- name: Use Node.js ${{ vars.NODE_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}

- uses: voxmedia/github-action-slack-notify-build@v1
id: slack
Expand All @@ -39,6 +37,9 @@ jobs:
- name: Install
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Create Release
run: npm publish

Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/pr-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ jobs:
- name: Setup npmrc
run: echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc

- name: Use Node.js ${{ vars.NODE_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}

- name: Install
run: yarn install --frozen-lockfile
Expand Down Expand Up @@ -55,13 +53,14 @@ jobs:
- name: Setup npmrc
run: echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc

- name: Use Node.js ${{ vars.NODE_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}

- name: Install
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Create Release
run: yarn run auto shipit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/
test-report/

dist/
6 changes: 0 additions & 6 deletions config/eslint/browser.js

This file was deleted.

111 changes: 0 additions & 111 deletions config/eslint/es6.js

This file was deleted.

3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module.exports = {
testEnvironment: "jsdom",
testMatch: ["<rootDir>/tests/**/?(*.)+(spec|test).[jt]s?(x)"],
transform: {
"^.+\\.(j|t)sx?$": "ts-jest",
},
roots: ["<rootDir>"],
coverageDirectory: "test-report/unit-tests",
};
5 changes: 0 additions & 5 deletions jsconfig.json

This file was deleted.

37 changes: 35 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@whereby/jslib-media",
"description": "Media library for Whereby",
"version": "1.9.9",
"version": "2.0.0",
"private": false,
"license": "MIT",
"homepage": "https://github.com/whereby/jslib-media",
Expand All @@ -13,13 +13,33 @@
"url": "https://github.com/whereby/jslib-media/issues"
},
"scripts": {
"build": "rimraf dist && rollup -c rollup.config.js",
"lint": "eslint src tests",
"test": "npm run lint && npm run test:unit",
"test:unit": "jest",
"test:unit:coverage": "jest --collectCoverage",
"format:fix": "prettier --write './**/*.{js,ts,yml,json}'",
"format:check": "prettier --check './**/*.{js,ts,yml,json}'"
},
"main": "./dist/index.esm.js",
"module": "./dist/index.esm.js",
"exports": {
".": {
"import": "./dist/index.esm.js",
"types": "./dist/index.d.ts"
}
},
"typesVersions": {
"*": {
"*": [
"./dist/index.d.ts"
]
}
},
"files": [
"dist/**/*.js",
"dist/**/*.d.ts"
],
"dependencies": {
"check-ip": "^1.1.1",
"events": "^3.3.0",
Expand All @@ -29,6 +49,7 @@
"sdp": "^3.2.0",
"sdp-transform": "^2.14.2",
"socket.io-client": "4.7.2",
"typescript": "^5.3.3",
"uuid": "^9.0.1",
"uuid-validate": "^0.0.3",
"webrtc-adapter": "^8.2.3"
Expand All @@ -38,6 +59,14 @@
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.22.15",
"@babel/preset-env": "^7.23.2",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-replace": "^5.0.5",
"@types/jest": "^29.5.12",
"@types/sdp-transform": "^2.4.9",
"@types/uuid": "^9.0.8",
"@types/uuid-validate": "^0.0.3",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"auto": "^11.1.1",
"babel-jest": "^29.7.0",
"eslint": "^8.56.0",
Expand All @@ -47,7 +76,11 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "3.2.5",
"process": "^0.11.10"
"process": "^0.11.10",
"rollup": "^4.12.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-typescript2": "^0.36.0",
"ts-jest": "^29.1.2"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
Expand Down
46 changes: 46 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const typescript = require("rollup-plugin-typescript2");
const commonjs = require("@rollup/plugin-commonjs");
const replace = require("@rollup/plugin-replace");
const pkg = require("./package.json");
const { dts } = require("rollup-plugin-dts");

const dependencies = [...Object.keys(pkg.dependencies || {})];
const peerDependencies = [...Object.keys(pkg.peerDependencies || {})];

const tsOptions = {
tsconfig: "tsconfig.build.json",
};

const plugins = [
replace({
preventAssignment: true,
// jslib-media uses global.navigator for some gUM calls, replace these
delimiters: [" ", "."],
values: { "global.navigator.mediaDevices": " navigator.mediaDevices." },
}),
commonjs(),
typescript(tsOptions),
];

const external = [...dependencies, ...peerDependencies];

module.exports = [
// Esm build of lib, to be used with bundlers
{
input: "src/index.ts",
output: {
file: "dist/index.esm.js",
format: "esm",
exports: "named",
},
plugins,
external,
},
{
input: "src/index.ts",
output: [{ file: "dist/index.d.ts", format: "es" }],
external,
plugins: [dts(tsOptions)],
},
];
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./webrtc";
export * from "./utils";
export * from "./model";
Loading

0 comments on commit af48e36

Please sign in to comment.