Skip to content

Commit

Permalink
feat: add default export, TypeScript and Flow type defs
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Jul 17, 2020
1 parent a1d4359 commit 4632337
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 20 deletions.
11 changes: 11 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ignore]

[include]

[libs]

[lints]

[options]

[strict]
10 changes: 0 additions & 10 deletions .npmignore

This file was deleted.

8 changes: 3 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChildProcess, SpawnOptions } from 'child_process'

interface LaunchOptions {
export interface LaunchOptions {
main: string
command?: string
commandOptions?: ReadonlyArray<string>
Expand All @@ -19,11 +19,9 @@ interface LaunchOptions {
restartOnExit?: boolean
}

interface LaunchProcess {
export interface LaunchProcess {
restart(): void
kill(signal?: number): void
}

declare const launch: (opts: LaunchOptions) => LaunchProcess

export = launch
export default function launch(opts: LaunchOptions): LaunchProcess
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function log(...args) {
console.log(chalk.bold.red('[smart-restart]'), ...args)
}

module.exports = function launch(ops) {
function launch(ops) {
let lastErr = ''
let child
let watcher
Expand Down Expand Up @@ -174,12 +174,15 @@ module.exports = function launch(ops) {
}
}

module.exports = launch
launch.default = launch

if (!module.parent) {
const mainIndex = process.argv.findIndex((arg, i) => i > 1 && arg[0] !== '-')
const main = process.argv[mainIndex]
const commandOptions = process.argv.slice(3, mainIndex)
const args = process.argv.slice(mainIndex + 1)
module.exports({
launch({
main,
commandOptions,
args,
Expand Down
29 changes: 29 additions & 0 deletions index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @flow

import { type ChildProcess } from 'child_process'

export type LaunchOptions = $ReadOnly<{
main: string,
command?: ?string,
commandOptions?: ?$ReadOnlyArray<string>,
args?: ?$ReadOnlyArray<string>,
spawnOptions?: ?child_process$spawnOpts,
onChildSpawned?: ?(child: ChildProcess) => mixed,
ignore?: ?RegExp,
usePolling?: ?boolean,
interval?: ?number,
binaryInterval?: ?number,
includeModules?: ?boolean,
killSignal?: ?string,
killTimeout?: ?number,
deleteRequireCache?: ?$ReadOnlyArray<string>,
restartOnError?: ?boolean,
restartOnExit?: ?boolean,
}>

export interface LaunchProcess {
restart(): void;
kill(signal?: number): void;
}

declare export default function launch(opts: LaunchOptions): LaunchProcess
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "smart-restart",
"version": "2.4.0",
"version": "0.0.0-development",
"description": "Like nodemon but only watches require()d files. Like piping but easy to use with node-inspector.",
"engines": {
"node": ">=8"
},
"files": [
"*.js",
"*.js.flow",
"*.d.ts"
],
"main": "index.js",
"author": "Andy Edwards",
"license": "MIT",
Expand All @@ -18,7 +23,7 @@
"test:watch": "mocha --watch $npm_package_config_mocha",
"test:debug": "mocha --inspect-brk $npm_package_config_mocha",
"codecov": "nyc report --reporter=text-lcov > coverage.lcov; codecov",
"prepublishOnly": "npm run lint",
"prepublishOnly": "npm run lint && flow && tsc",
"open:coverage": "open coverage/lcov-report/index.html",
"semantic-release": "semantic-release"
},
Expand Down Expand Up @@ -78,20 +83,23 @@
"@commitlint/config-conventional": "^6.0.2",
"@jedwards1211/commitlint-config": "^1.0.0",
"@jedwards1211/eslint-config": "^2.0.0",
"@types/node": "^14.0.23",
"chai": "^4.1.2",
"codecov": "^3.0.0",
"cross-env": "^5.2.0",
"eslint": "^4.16.0",
"eslint-config-prettier": "^3.3.0",
"eslint-watch": "^3.1.3",
"flow-bin": "^0.129.0",
"husky": "^1.1.4",
"istanbul": "^0.4.5",
"lint-staged": "^8.0.4",
"mocha": "^5.0.0",
"nyc": "^11.4.1",
"prettier": "^1.15.1",
"prettier-eslint": "^8.8.2",
"semantic-release": "^15.13.3"
"semantic-release": "^15.13.3",
"typescript": "^3.9.7"
},
"renovate": {
"extends": [
Expand Down
70 changes: 70 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"include": ["*.d.ts"],
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true /* Do not emit outputs. */,
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@
into-stream "^4.0.0"
lodash "^4.17.4"

"@types/node@^14.0.23":
version "14.0.23"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.23.tgz#676fa0883450ed9da0bb24156213636290892806"
integrity sha512-Z4U8yDAl5TFkmYsZdFPdjeMa57NOvnaf1tljHzhouaPEp7LCj2JKkejpI1ODviIAQuW4CcQmxkQ77rnLsOOoKw==

JSONStream@^1.0.4, JSONStream@^1.3.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down Expand Up @@ -2293,6 +2298,11 @@ flat-cache@^1.2.1:
rimraf "~2.6.2"
write "^0.2.1"

flow-bin@^0.129.0:
version "0.129.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.129.0.tgz#50294d6e335dd97d095c27b096ea0b94c2415d55"
integrity sha512-WLXOj09oCK6nODVKM5uxvAzBpxXeI304E60tELMeQd/TJsyfbykNCZ+e4xml9eUOyoac9nDL3YrJpPZMzq0tMA==

flush-write-stream@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/flush-write-stream/-/flush-write-stream-1.1.0.tgz#2e89a8bd5eee42f8ec97e43aae81e3d5099c2ddc"
Expand Down Expand Up @@ -6616,6 +6626,11 @@ typescript@^2.5.1:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==

typescript@^3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

uglify-js@^3.1.4:
version "3.4.9"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3"
Expand Down

0 comments on commit 4632337

Please sign in to comment.