Skip to content

Commit

Permalink
feat: migrate to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Dec 23, 2020
2 parents be73043 + 7617de5 commit 56f1c04
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 191 deletions.
14 changes: 7 additions & 7 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ import {
createLightship
} from 'lightship';

const configuration: ConfigurationInputType = {};
const configuration: ConfigurationInput = {};

const lightship: LightshipType = createLightship(configuration);
const lightship: Lightship = createLightship(configuration);

```

Expand All @@ -86,7 +86,7 @@ The following types describe the configuration shape and the resulting Lightship
/**
* A teardown function called when shutdown is initialized.
*/
type ShutdownHandlerType = () => Promise<void> | void;
type ShutdownHandler = () => Promise<void> | void;

/**
* @property detectKubernetes Run Lightship in local mode when Kubernetes is not detected. Default: true.
Expand All @@ -97,7 +97,7 @@ type ShutdownHandlerType = () => Promise<void> | void;
* @property signals An a array of [signal events]{@link https://nodejs.org/api/process.html#process_signal_events}. Default: [SIGTERM].
* @property terminate Method used to terminate Node.js process. Default: `() => { process.exit(1) };`.
*/
export type ConfigurationInputType = {|
export type ConfigurationInput = {|
+detectKubernetes?: boolean,
+gracefulShutdownTimeout?: number,
+port?: number,
Expand All @@ -115,12 +115,12 @@ export type ConfigurationInputType = {|
* @property signalReady Changes server state to SERVER_IS_READY.
* @property whenFirstReady Resolves the first time the service goes from `SERVER_IS_NOT_READY` to `SERVER_IS_READY` state.
*/
type LightshipType = {|
+createBeacon: (context?: BeaconContextType) => BeaconControllerType,
type Lightship = {|
+createBeacon: (context?: BeaconContext) => BeaconController,
+isServerReady: () => boolean,
+isServerShuttingDown: () => boolean,
+queueBlockingTask: (blockingTask: Promise<any>) => void,
+registerShutdownHandler: (shutdownHandler: ShutdownHandlerType) => void,
+registerShutdownHandler: (shutdownHandler: ShutdownHandler) => void,
+server: http$Server,
+shutdown: () => Promise<void>,
+signalNotReady: () => void,
Expand Down
6 changes: 2 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
]
}
},
"plugins": [
"@babel/transform-flow-strip-types"
],
"presets": [
[
"@babel/env",
Expand All @@ -17,6 +14,7 @@
"node": "10"
}
}
]
],
"@babel/preset-typescript"
]
}
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"canonical",
"canonical/flowtype"
"canonical/typescript"
],
"root": true
}
6 changes: 0 additions & 6 deletions .flowconfig

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ node_modules
!.editorconfig
!.eslintignore
!.eslintrc
!.flowconfig
!.gitignore
!.npmignore
!.README
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ import {
createLightship
} from 'lightship';

const configuration: ConfigurationInputType = {};
const configuration: ConfigurationInput = {};

const lightship: LightshipType = createLightship(configuration);
const lightship: Lightship = createLightship(configuration);

```

Expand All @@ -116,7 +116,7 @@ The following types describe the configuration shape and the resulting Lightship
/**
* A teardown function called when shutdown is initialized.
*/
type ShutdownHandlerType = () => Promise<void> | void;
type ShutdownHandler = () => Promise<void> | void;

/**
* @property detectKubernetes Run Lightship in local mode when Kubernetes is not detected. Default: true.
Expand All @@ -127,7 +127,7 @@ type ShutdownHandlerType = () => Promise<void> | void;
* @property signals An a array of [signal events]{@link https://nodejs.org/api/process.html#process_signal_events}. Default: [SIGTERM].
* @property terminate Method used to terminate Node.js process. Default: `() => { process.exit(1) };`.
*/
export type ConfigurationInputType = {|
export type ConfigurationInput = {|
+detectKubernetes?: boolean,
+gracefulShutdownTimeout?: number,
+port?: number,
Expand All @@ -145,12 +145,12 @@ export type ConfigurationInputType = {|
* @property signalReady Changes server state to SERVER_IS_READY.
* @property whenFirstReady Resolves the first time the service goes from `SERVER_IS_NOT_READY` to `SERVER_IS_READY` state.
*/
type LightshipType = {|
+createBeacon: (context?: BeaconContextType) => BeaconControllerType,
type Lightship = {|
+createBeacon: (context?: BeaconContext) => BeaconController,
+isServerReady: () => boolean,
+isServerShuttingDown: () => boolean,
+queueBlockingTask: (blockingTask: Promise<any>) => void,
+registerShutdownHandler: (shutdownHandler: ShutdownHandlerType) => void,
+registerShutdownHandler: (shutdownHandler: ShutdownHandler) => void,
+server: http$Server,
+shutdown: () => Promise<void>,
+signalNotReady: () => void,
Expand Down
45 changes: 26 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"url": "http://gajus.com"
},
"ava": {
"extensions": [
"ts"
],
"babel": {
"compileAsTests": [
"test/helpers/**/*"
Expand All @@ -14,14 +17,13 @@
"test/lightship/**/*"
],
"require": [
"@babel/register"
"ts-node/register"
]
},
"dependencies": {
"delay": "^4.4.0",
"express": "^4.17.1",
"http-terminator": "^2.0.3",
"promise-deferred": "^2.0.3",
"roarr": "^2.15.4",
"serialize-error": "^7.0.1"
},
Expand All @@ -31,60 +33,65 @@
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/node": "^7.12.10",
"@babel/plugin-transform-flow-strip-types": "^7.12.10",
"@babel/preset-env": "^7.12.10",
"@babel/register": "^7.12.10",
"@babel/preset-typescript": "^7.12.7",
"@types/express": "^4.17.9",
"@types/http-terminator": "^2.0.1",
"@types/node": "^14.14.14",
"@types/roarr": "^2.14.2",
"@types/sinon": "^9.0.9",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"ava": "^3.14.0",
"axios": "^0.21.0",
"babel-plugin-istanbul": "^6.0.0",
"coveralls": "^3.1.0",
"eslint": "^7.15.0",
"eslint-config-canonical": "^24.4.4",
"flow-bin": "^0.140.0",
"flow-copy-source": "^2.0.9",
"get-port": "^5.1.1",
"gitdown": "^3.1.3",
"husky": "^4.3.6",
"nyc": "^15.1.0",
"semantic-release": "^17.3.0",
"sinon": "^9.2.2"
"sinon": "^9.2.2",
"source-map-support": "^0.5.19",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"engines": {
"node": ">=10"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run test && npm run build"
"pre-commit": "npm run lint && npm run typecheck && npm run test && npm run build"
}
},
"keywords": [
"kubernetes"
],
"license": "BSD-3-Clause",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"name": "lightship",
"nyc": {
"include": [
"src/**/*.js"
],
"instrument": false,
"reporter": [
"text-lcov"
"src/**/*.ts"
],
"require": [
"@babel/register"
],
"sourceMap": false
"ts-node/register",
"source-map-support/register"
]
},
"repository": {
"type": "git",
"url": "https://github.com/gajus/lightship"
},
"scripts": {
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files --source-maps && flow-copy-source src dist",
"build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --source-maps --extensions \".ts\" && tsc --emitDeclarationOnly",
"generate-readme": "gitdown ./.README/README.md --output-file ./README.md",
"lint": "eslint ./src ./test && flow",
"test": "NODE_ENV=test ava --verbose --serial"
"lint": "eslint ./src ./test --ext .js --ext .ts",
"test": "NODE_ENV=test ava --verbose --serial",
"typecheck": "tsc --noEmit"
},
"version": "1.0.0"
}
2 changes: 0 additions & 2 deletions src/Logger.js → src/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @flow

import Roarr from 'roarr';

export default Roarr.child({
Expand Down
Loading

0 comments on commit 56f1c04

Please sign in to comment.