Skip to content

Commit

Permalink
Generate TypeScript types declaration (#656)
Browse files Browse the repository at this point in the history
* Generate bundled types declaration

* Use named exports

* Simplify building types

* Fix enum export

* Fix Webpack export type

* Remove useless test
  • Loading branch information
kmjennison authored Jul 3, 2023
1 parent 06ff195 commit 4370cce
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 303 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
// Let eslint manage semicolons
'@typescript-eslint/no-extra-semi': 0,
'import/no-unresolved': 'error',
'import/prefer-default-export': 0,
'import/extensions': [
'error',
'ignorePackages',
Expand Down
167 changes: 0 additions & 167 deletions index.d.ts

This file was deleted.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
"author": "Gladly Team",
"license": "MIT",
"scripts": {
"build": "npm-run-all -s build:clean build:src",
"build": "npm-run-all -s build:clean build:src build:types-declaration",
"build:clean": "rm -rf ./build",
"build:src": "NODE_ENV=production webpack",
"build:types-declaration": "dts-bundle-generator ./src/index.server.ts --out-file ./build/index.d.ts",
"lint": "tsc --noEmit && eslint ./",
"bundlesize": "npm-run-all -s build bundlesize:no-build",
"bundlesize:no-build": "bundlesize",
Expand Down Expand Up @@ -58,6 +59,7 @@
"copy-webpack-plugin": "^11.0.0",
"core-js": "^3.23.5",
"datwd": "^0.2.0",
"dts-bundle-generator": "^8.0.1",
"eslint": "^8.20.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
Expand Down
4 changes: 1 addition & 3 deletions src/AuthAction.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Different behaviors when the user's auth status is pending
// or mismatches the page requirements.

enum AuthAction {
export enum AuthAction {
RENDER = 'render',
SHOW_LOADER = 'showLoader',
RETURN_NULL = 'returnNull',
REDIRECT_TO_LOGIN = 'redirectToLogin',
REDIRECT_TO_APP = 'redirectToApp',
}

export default AuthAction
16 changes: 0 additions & 16 deletions src/__tests__/AuthAction.test.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/__tests__/index.server.moduleLoad.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Tests for index.server.js that require resetting all
// Tests for index.server.ts that require resetting all
// modules between tests. Most tests should reside in
// index.server.test.js.
// eslint-disable-next-line jest/no-export
Expand All @@ -10,7 +10,7 @@ afterEach(() => {
jest.resetModules()
})

describe('index.server.js (resetting modules)', () => {
describe('index.server.ts (resetting modules)', () => {
it('imports without error when missing optional dependencies', () => {
expect.assertions(0)

Expand Down Expand Up @@ -44,7 +44,7 @@ describe('index.server.js (resetting modules)', () => {
})

// eslint-disable-next-line no-unused-expressions
require('src/index.server').default
require('src/index.server')
})

it('throws an error when calling useAuthUser without react installed', () => {
Expand All @@ -59,7 +59,7 @@ describe('index.server.js (resetting modules)', () => {
moduleName: 'react',
})
})
const { useAuthUser } = require('src/index.server').default
const { useAuthUser } = require('src/index.server')
expect(() => {
useAuthUser()
}).toThrow(expectedErr)
Expand Down
Loading

0 comments on commit 4370cce

Please sign in to comment.