Skip to content

Commit

Permalink
refactor(js)!: initialize js/js package (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
IceHe authored Jan 14, 2022
1 parent d858085 commit 07322cb
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/js/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
coveragePathIgnorePatterns: ['/node_modules/', '/lib/'],
coverageReporters: ['text-summary', 'lcov'],
moduleFileExtensions: ['ts', 'js'],
setupFilesAfterEnv: ['./jest.setup.js'],
testPathIgnorePatterns: ['lib'],
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|js)$',
transform: {
'.ts': 'ts-jest',
},
};
12 changes: 12 additions & 0 deletions packages/js/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Need to disable following rules to mock text-decode/text-encoder and crypto for jsdom
// https://github.com/jsdom/jsdom/issues/1612
/* eslint-disable @silverhand/fp/no-mutation */
/* eslint-disable unicorn/prefer-module */
const { Crypto } = require('@peculiar/webcrypto');
const fetch = require('node-fetch');
const { TextDecoder, TextEncoder } = require('text-encoder');

global.crypto = new Crypto();
global.fetch = fetch;
global.TextDecoder = TextDecoder;
global.TextEncoder = TextEncoder;
48 changes: 48 additions & 0 deletions packages/js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@logto/js",
"version": "0.0.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"license": "MPL-2.0",
"scripts": {
"dev:tsc": "tsc -b -w --preserveWatchOutput",
"preinstall": "npx only-allow pnpm",
"precommit": "lint-staged",
"build": "tsc",
"lint": "eslint --ext .ts src",
"package": "webpack",
"test": "jest",
"test:coverage": "jest --silent --coverage",
"test:report": "codecov -F js",
"prepublish": "npm run build && npm run package",
"report": "WITH_REPORT=true npm run package"
},
"dependencies": {
"@silverhand/essentials": "^1.1.2"
},
"devDependencies": {
"@peculiar/webcrypto": "^1.1.7",
"@silverhand/eslint-config": "^0.5.0",
"@silverhand/ts-config": "^0.5.0",
"@types/jest": "^26.0.24",
"@types/webpack": "^5.28.0",
"codecov": "^3.8.3",
"eslint": "^8.1.0",
"jest": "^27.0.6",
"lint-staged": "^11.1.2",
"nock": "^13.1.3",
"node-fetch": "2.6.6",
"prettier": "^2.3.2",
"text-encoder": "^0.0.4",
"ts-jest": "^27.0.4",
"ts-loader": "^9.2.6",
"typescript": "^4.3.5",
"webpack": "^5.58.2",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.1"
},
"eslintConfig": {
"extends": "@silverhand/eslint-config"
},
"prettier": "@silverhand/eslint-config/.prettierrc"
}
9 changes: 9 additions & 0 deletions packages/js/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Temporary content, for `pnpm test` to pass CI, will be deleted later
import { TODO } from '.';

describe('TODO', () => {
test('TODO', async () => {
const todo: TODO = 'todo';
expect(todo).toEqual(todo);
});
});
4 changes: 4 additions & 0 deletions packages/js/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Temporary content, for `pnpm build` to pass CI, will be deleted later
import { Optional } from '@silverhand/essentials';

export type TODO = Optional<string>;
10 changes: 10 additions & 0 deletions packages/js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"target": "es5"
},
"include": [
"src"
]
}
32 changes: 32 additions & 0 deletions packages/js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const path = require('path');

const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');

module.exports = () => {
const { WITH_REPORT } = process.env;

return {
mode: 'production',
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'logto.min.js',
library: {
type: 'umd',
name: 'logto',
},
},
module: {
rules: [
{
exclude: /node_modules/,
use: 'ts-loader',
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
plugins: WITH_REPORT ? [new BundleAnalyzerPlugin()] : [],
};
};
62 changes: 61 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 07322cb

Please sign in to comment.