Skip to content

Commit

Permalink
RTG-1182: Enabling ES modules and refactoring
Browse files Browse the repository at this point in the history
Changes:
 - Removes crypto library, since extension relies on webcrypto API and
   sjcl libraries.
 - creating a voprf module.
 - Making Jest to work with ESM.
 - Adding linter and formating files with prettier.
 - Fix return type.
 - Rename a listener file.
 - Replacing ProviderID -> ProviderId.
 - Removing plural from providers.
 - Replacing HCaptcha -> Hcaptcha.
 - Adding contributor guide.
 - Adding return types to satisfy linter.
 - Removing default exports.
 - Add strickNullChecks to configuration.
 - Removing yarn related files.
 - Removing isomorphic-webcrypto.
 - Attaching TABS variable to window global object.
  • Loading branch information
armfazh authored and ppopth committed Nov 17, 2021
1 parent 6115d58 commit b140627
Show file tree
Hide file tree
Showing 38 changed files with 2,487 additions and 1,410 deletions.
45 changes: 45 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"@typescript-eslint",
"security",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:security/recommended",
"plugin:prettier/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/member-delimiter-style": 0,
"@typescript-eslint/no-namespace": [
"warn"
],
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"no-case-declarations": 0,
"no-console": [
"error",
{
"allow": [
"warn",
"error"
]
}
]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
/node_modules
/dist
/lib
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all",
"printWidth": 100
}
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Contribution Guidelines

### Code Style

Code is written in TypeScript and is automatically formatted with prettier.

```
$ npm run lint
```

### Naming convention

It is recommended to follow style guide for [TypeScript](https://google.github.io/styleguide/tsguide.html).
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Challenge Bypass Extension
# Privacy Pass Extension

## Build Instruction

```sh
$ npm install
$ npm ci
$ npm run build
```

After that, the `dist` folder will contain all files required by the extension.

## Test Instruction
```sh
$ npm install
$ npm ci
$ npm test
```

Expand Down
22 changes: 14 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
export default {
preset: 'ts-jest/presets/js-with-ts-esm',
setupFiles: ['./jest.setup.ts'],
globals: {
'ts-jest': {
useESM: true,
},
},
transform: {},
transformIgnorePatterns: ['.js'],
testEnvironment: 'jsdom',
moduleNameMapper: {
"^@root/(.*)": "<rootDir>/$1",
"^@public/(.*)": "<rootDir>/public/$1",
"^@background/(.*)": "<rootDir>/src/background/$1",
"^@popup/(.*)": "<rootDir>/src/popup/$1"
'^@root/(.*)': '<rootDir>/$1',
'^@public/(.*)': '<rootDir>/public/$1',
'^@popup/(.*)': '<rootDir>/src/popup/$1',
},
};
verbose: true,
}
13 changes: 5 additions & 8 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import crypto from 'crypto';
// Mocking crypto with Node webcrypto API.
import { webcrypto } from 'crypto';

Object.assign(window, {
crypto: {
getRandomValues: (buffer: Int32Array) => {
return crypto.randomFillSync(buffer);
},
},
});
if (typeof crypto === 'undefined') {
global.crypto = (webcrypto as unknown) as Crypto
}
Loading

0 comments on commit b140627

Please sign in to comment.