From 20fe65ce4119727a0f2b35a630b0cbc568ae3724 Mon Sep 17 00:00:00 2001 From: Anderson Leite Date: Mon, 31 Dec 2018 05:44:27 -0800 Subject: [PATCH] Implement tslint for core files (#5952) Fixes #5845 Implement tslint for core files **What is this?** Implements tslint for both next and next-server, but keeps standardjs/eslint for the .js files that are still there, we're gradually migrating to Typescript. **How does it work?** Before every commit (pre-commit) we execute the following `tslint` command: `tslint -c tslint.json 'packages/**/*.ts` **TSLint Rules** In order to avoid as much changes as possible I marked some rules as false. This way we can improve the linter but making sure this step will not break things. (see tslint.json) **Note** After merging this PR, you'll need to update your dependencies since it adds tslint to package.json --- package.json | 6 +- .../server/get-dynamic-import-bundles.ts | 4 +- packages/next-server/server/get-page-files.ts | 7 ++- .../next-server/server/load-components.ts | 8 +-- packages/next-server/server/next-server.ts | 63 ++++++++++--------- .../next-server/server/normalize-page-path.ts | 2 +- packages/next-server/server/require.ts | 7 ++- packages/next-server/server/router.ts | 8 +-- packages/next-server/server/send-html.ts | 2 +- packages/next-server/server/serve-static.ts | 2 +- packages/next-server/server/utils.ts | 6 +- packages/next/bin/next-build.ts | 3 +- packages/next/bin/next-dev.ts | 11 ++-- packages/next/bin/next-export.ts | 5 +- packages/next/bin/next-start.ts | 5 +- packages/next/bin/next.ts | 25 +++++--- tslint.json | 30 +++++++++ 17 files changed, 122 insertions(+), 72 deletions(-) create mode 100644 tslint.json diff --git a/package.json b/package.json index 3023cc92..403f08a7 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "git add" ], "*.ts": [ - "standard --parser typescript-eslint-parser --plugin typescript --fix", + "tslint -c tslint.json 'packages/**/*.ts'", "git add" ], "packages/**/bin/*": [ @@ -44,7 +44,7 @@ "standard": { "parser": "babel-eslint", "ignore": [ - "packages/next-server/server/next-server.ts", + "packages/**/*.ts", "**/*.d.ts", "**/node_modules/**", "examples/with-ioc/**", @@ -89,6 +89,8 @@ "rimraf": "2.6.2", "standard": "11.0.1", "taskr": "1.1.0", + "tslint": "5.12.0", + "typescript": "3.1.1", "typescript-eslint-parser": "21.0.1", "wait-port": "0.2.2", "wd": "1.10.3", diff --git a/packages/next-server/server/get-dynamic-import-bundles.ts b/packages/next-server/server/get-dynamic-import-bundles.ts index 81ae8300..12df48fe 100644 --- a/packages/next-server/server/get-dynamic-import-bundles.ts +++ b/packages/next-server/server/get-dynamic-import-bundles.ts @@ -2,7 +2,7 @@ export type ManifestItem = { id: number|string, name: string, file: string, - publicPath: string + publicPath: string, } export type Manifest = {[moduleId: string]: ManifestItem[]} @@ -10,7 +10,7 @@ export type Manifest = {[moduleId: string]: ManifestItem[]} type DynamicImportBundles = Set // Based on https://github.com/jamiebuilds/react-loadable/pull/132 -export function getDynamicImportBundles (manifest: Manifest, moduleIds: string[]): DynamicImportBundles { +export function getDynamicImportBundles(manifest: Manifest, moduleIds: string[]): DynamicImportBundles { return moduleIds.reduce((bundles: DynamicImportBundles, moduleId: string): DynamicImportBundles => { if (typeof manifest[moduleId] === 'undefined') { return bundles diff --git a/packages/next-server/server/get-page-files.ts b/packages/next-server/server/get-page-files.ts index 6e230959..cad6c0ea 100644 --- a/packages/next-server/server/get-page-files.ts +++ b/packages/next-server/server/get-page-files.ts @@ -3,15 +3,16 @@ import { normalizePagePath } from './normalize-page-path' export type BuildManifest = { devFiles: string[], pages: { - [page: string]: string[] - } + [page: string]: string[], + }, } -export function getPageFiles (buildManifest: BuildManifest, page: string): string[] { +export function getPageFiles(buildManifest: BuildManifest, page: string): string[] { const normalizedPage = normalizePagePath(page) const files = buildManifest.pages[normalizedPage] if (!files) { + // tslint:disable-next-line console.warn(`Could not find files for ${normalizedPage} in .next/build-manifest.json`) return [] } diff --git a/packages/next-server/server/load-components.ts b/packages/next-server/server/load-components.ts index df5ff8bd..cd03201d 100644 --- a/packages/next-server/server/load-components.ts +++ b/packages/next-server/server/load-components.ts @@ -2,19 +2,19 @@ import {join} from 'path' import {CLIENT_STATIC_FILES_PATH, BUILD_MANIFEST, REACT_LOADABLE_MANIFEST, SERVER_DIRECTORY} from 'next-server/constants' import {requirePage} from './require' -function interopDefault (mod: any) { +function interopDefault(mod: any) { return mod.default || mod } -export async function loadComponents (distDir: string, buildId: string, pathname: string) { +export async function loadComponents(distDir: string, buildId: string, pathname: string) { const documentPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_document') const appPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_app') - let [buildManifest, reactLoadableManifest, Component, Document, App] = await Promise.all([ + const [buildManifest, reactLoadableManifest, Component, Document, App] = await Promise.all([ require(join(distDir, BUILD_MANIFEST)), require(join(distDir, REACT_LOADABLE_MANIFEST)), interopDefault(requirePage(pathname, distDir)), interopDefault(require(documentPath)), - interopDefault(require(appPath)) + interopDefault(require(appPath)), ]) return {buildManifest, reactLoadableManifest, Component, Document, App} diff --git a/packages/next-server/server/next-server.ts b/packages/next-server/server/next-server.ts index ee1ec065..564d9234 100644 --- a/packages/next-server/server/next-server.ts +++ b/packages/next-server/server/next-server.ts @@ -21,7 +21,7 @@ type ServerConstructor = { dir?: string, staticMarkup?: boolean, quiet?: boolean, - conf?: NextConfig + conf?: NextConfig, } export default class Server { @@ -35,11 +35,11 @@ export default class Server { buildId: string, generateEtags: boolean, runtimeConfig?: {[key: string]: any}, - assetPrefix?: string + assetPrefix?: string, } router: Router - public constructor ({ dir = '.', staticMarkup = false, quiet = false, conf = null }: ServerConstructor = {}) { + public constructor({ dir = '.', staticMarkup = false, quiet = false, conf = null }: ServerConstructor = {}) { this.dir = resolve(dir) this.quiet = quiet const phase = this.currentPhase() @@ -54,7 +54,7 @@ export default class Server { this.renderOpts = { staticMarkup, buildId: this.buildId, - generateEtags + generateEtags, } // Only the `publicRuntimeConfig` key is exposed to the client side @@ -66,7 +66,7 @@ export default class Server { // Initialize next/config with the environment configuration envConfig.setConfig({ serverRuntimeConfig, - publicRuntimeConfig + publicRuntimeConfig, }) const routes = this.generateRoutes() @@ -74,16 +74,17 @@ export default class Server { this.setAssetPrefix(assetPrefix) } - private currentPhase (): string { + private currentPhase(): string { return PHASE_PRODUCTION_SERVER } private logError(...args: any): void { - if(this.quiet) return + if (this.quiet) return + // tslint:disable-next-line console.error(...args) } - private handleRequest (req: IncomingMessage, res: ServerResponse, parsedUrl?: UrlWithParsedQuery): Promise { + private handleRequest(req: IncomingMessage, res: ServerResponse, parsedUrl?: UrlWithParsedQuery): Promise { // Parse url if parsedUrl not provided if (!parsedUrl || typeof parsedUrl !== 'object') { const url: any = req.url @@ -104,26 +105,26 @@ export default class Server { }) } - public getRequestHandler () { + public getRequestHandler() { return this.handleRequest.bind(this) } - public setAssetPrefix (prefix?: string) { + public setAssetPrefix(prefix?: string) { this.renderOpts.assetPrefix = prefix ? prefix.replace(/\/$/, '') : '' asset.setAssetPrefix(this.renderOpts.assetPrefix) } // Backwards compatibility - public async prepare (): Promise {} + public async prepare(): Promise {} // Backwards compatibility - private async close (): Promise {} + private async close(): Promise {} - private setImmutableAssetCacheControl (res: ServerResponse) { + private setImmutableAssetCacheControl(res: ServerResponse) { res.setHeader('Cache-Control', 'public, max-age=31536000, immutable') } - private generateRoutes (): Route[] { + private generateRoutes(): Route[] { const routes: Route[] = [ { match: route('/_next/static/:path*'), @@ -136,14 +137,14 @@ export default class Server { } const p = join(this.distDir, CLIENT_STATIC_FILES_PATH, ...(params.path || [])) await this.serveStatic(req, res, p, parsedUrl) - } + }, }, { match: route('/_next/:path*'), // This path is needed because `render()` does a check for `/_next` and the calls the routing again fn: async (req, res, _params, parsedUrl) => { await this.render404(req, res, parsedUrl) - } + }, }, { // It's very important to keep this route's param optional. @@ -154,8 +155,8 @@ export default class Server { fn: async (req, res, params, parsedUrl) => { const p = join(this.dir, 'static', ...(params.path || [])) await this.serveStatic(req, res, p, parsedUrl) - } - } + }, + }, ] if (this.nextConfig.useFileSystemPublicRoutes) { @@ -167,18 +168,18 @@ export default class Server { match: route('/:path*'), fn: async (req, res, _params, parsedUrl) => { const { pathname, query } = parsedUrl - if(!pathname) { + if (!pathname) { throw new Error('pathname is undefined') } await this.render(req, res, pathname, query, parsedUrl) - } + }, }) } return routes } - private async run (req: IncomingMessage, res: ServerResponse, parsedUrl: UrlWithParsedQuery) { + private async run(req: IncomingMessage, res: ServerResponse, parsedUrl: UrlWithParsedQuery) { try { const fn = this.router.match(req, res, parsedUrl) if (fn) { @@ -206,7 +207,7 @@ export default class Server { return sendHTML(req, res, html, {generateEtags}) } - public async render (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}, parsedUrl?: UrlWithParsedQuery): Promise { + public async render(req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}, parsedUrl?: UrlWithParsedQuery): Promise { const url: any = req.url if (isInternalUrl(url)) { return this.handleRequest(req, res, parsedUrl) @@ -233,7 +234,7 @@ export default class Server { return renderToHTML(req, res, pathname, query, {...result, ...opts}) } - public async renderToHTML (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}): Promise { + public async renderToHTML(req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}): Promise { try { // To make sure the try/catch is executed const html = await this.renderToHTMLWithComponents(req, res, pathname, query, this.renderOpts) @@ -250,30 +251,30 @@ export default class Server { } } - public async renderError (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}): Promise { + public async renderError(err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}): Promise { res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate') const html = await this.renderErrorToHTML(err, req, res, pathname, query) - if(html === null) { + if (html === null) { return } return this.sendHTML(req, res, html) } - public async renderErrorToHTML (err: Error|null, req: IncomingMessage, res: ServerResponse, _pathname: string, query: ParsedUrlQuery = {}) { + public async renderErrorToHTML(err: Error|null, req: IncomingMessage, res: ServerResponse, _pathname: string, query: ParsedUrlQuery = {}) { return this.renderToHTMLWithComponents(req, res, '/_error', query, {...this.renderOpts, err}) } - public async render404 (req: IncomingMessage, res: ServerResponse, parsedUrl?: UrlWithParsedQuery): Promise { + public async render404(req: IncomingMessage, res: ServerResponse, parsedUrl?: UrlWithParsedQuery): Promise { const url: any = req.url const { pathname, query } = parsedUrl ? parsedUrl : parseUrl(url, true) - if(!pathname) { + if (!pathname) { throw new Error('pathname is undefined') } res.statusCode = 404 return this.renderError(null, req, res, pathname, query) } - public async serveStatic (req: IncomingMessage, res: ServerResponse, path: string, parsedUrl?: UrlWithParsedQuery): Promise { + public async serveStatic(req: IncomingMessage, res: ServerResponse, path: string, parsedUrl?: UrlWithParsedQuery): Promise { if (!this.isServeableUrl(path)) { return this.render404(req, res, parsedUrl) } @@ -289,7 +290,7 @@ export default class Server { } } - private isServeableUrl (path: string): boolean { + private isServeableUrl(path: string): boolean { const resolved = resolve(path) if ( resolved.indexOf(join(this.distDir) + sep) !== 0 && @@ -302,7 +303,7 @@ export default class Server { return true } - private readBuildId (): string { + private readBuildId(): string { const buildIdFile = join(this.distDir, BUILD_ID_FILE) try { return fs.readFileSync(buildIdFile, 'utf8').trim() diff --git a/packages/next-server/server/normalize-page-path.ts b/packages/next-server/server/normalize-page-path.ts index 58afe2b4..1102a4ec 100644 --- a/packages/next-server/server/normalize-page-path.ts +++ b/packages/next-server/server/normalize-page-path.ts @@ -1,5 +1,5 @@ import { posix } from 'path' -export function normalizePagePath (page: string): string { +export function normalizePagePath(page: string): string { // If the page is `/` we need to append `/index`, otherwise the returned directory root will be bundles instead of pages if (page === '/') { page = '/index' diff --git a/packages/next-server/server/require.ts b/packages/next-server/server/require.ts index 8f30eb01..5c6e46e4 100644 --- a/packages/next-server/server/require.ts +++ b/packages/next-server/server/require.ts @@ -2,19 +2,20 @@ import {join} from 'path' import {PAGES_MANIFEST, SERVER_DIRECTORY} from 'next-server/constants' import { normalizePagePath } from './normalize-page-path' -export function pageNotFoundError (page: string): Error { +export function pageNotFoundError(page: string): Error { const err: any = new Error(`Cannot find module for page: ${page}`) err.code = 'ENOENT' return err } -export function getPagePath (page: string, distDir: string): string { +export function getPagePath(page: string, distDir: string): string { const serverBuildPath = join(distDir, SERVER_DIRECTORY) const pagesManifest = require(join(serverBuildPath, PAGES_MANIFEST)) try { page = normalizePagePath(page) } catch (err) { + // tslint:disable-next-line console.error(err) throw pageNotFoundError(page) } @@ -26,7 +27,7 @@ export function getPagePath (page: string, distDir: string): string { return join(serverBuildPath, pagesManifest[page]) } -export function requirePage (page: string, distDir: string): any { +export function requirePage(page: string, distDir: string): any { const pagePath = getPagePath(page, distDir) return require(pagePath) } diff --git a/packages/next-server/server/router.ts b/packages/next-server/server/router.ts index 4ec4adf1..4ee46932 100644 --- a/packages/next-server/server/router.ts +++ b/packages/next-server/server/router.ts @@ -8,20 +8,20 @@ type Params = {[param: string]: string} export type Route = { match: (pathname: string|undefined) => false|Params, - fn: (req: IncomingMessage, res: ServerResponse, params: Params, parsedUrl: UrlWithParsedQuery) => void + fn: (req: IncomingMessage, res: ServerResponse, params: Params, parsedUrl: UrlWithParsedQuery) => void, } export default class Router { routes: Route[] - constructor (routes: Route[] = []) { + constructor(routes: Route[] = []) { this.routes = routes } - add (route: Route) { + add(route: Route) { this.routes.unshift(route) } - match (req: IncomingMessage, res: ServerResponse, parsedUrl: UrlWithParsedQuery) { + match(req: IncomingMessage, res: ServerResponse, parsedUrl: UrlWithParsedQuery) { if (req.method !== 'GET' && req.method !== 'HEAD') { return } diff --git a/packages/next-server/server/send-html.ts b/packages/next-server/server/send-html.ts index ae1395a9..e2304056 100644 --- a/packages/next-server/server/send-html.ts +++ b/packages/next-server/server/send-html.ts @@ -3,7 +3,7 @@ import generateETag from 'etag' import fresh from 'fresh' import { isResSent } from '../lib/utils' -export function sendHTML (req: IncomingMessage, res: ServerResponse, html: string, { generateEtags }: {generateEtags: boolean}) { +export function sendHTML(req: IncomingMessage, res: ServerResponse, html: string, { generateEtags }: {generateEtags: boolean}) { if (isResSent(res)) return const etag = generateEtags ? generateETag(html) : undefined diff --git a/packages/next-server/server/serve-static.ts b/packages/next-server/server/serve-static.ts index a946e247..e96c593b 100644 --- a/packages/next-server/server/serve-static.ts +++ b/packages/next-server/server/serve-static.ts @@ -4,7 +4,7 @@ import send from 'send' // since send doesn't support wasm yet send.mime.define({ 'application/wasm': ['wasm'] }) -export function serveStatic (req: IncomingMessage, res: ServerResponse, path: string): Promise { +export function serveStatic(req: IncomingMessage, res: ServerResponse, path: string): Promise { return new Promise((resolve, reject) => { send(req, path) .on('directory', () => { diff --git a/packages/next-server/server/utils.ts b/packages/next-server/server/utils.ts index 4e752e54..a1bdb4fa 100644 --- a/packages/next-server/server/utils.ts +++ b/packages/next-server/server/utils.ts @@ -2,10 +2,10 @@ import { BLOCKED_PAGES } from 'next-server/constants' const internalPrefixes = [ /^\/_next\//, - /^\/static\// + /^\/static\//, ] -export function isInternalUrl (url: string): boolean { +export function isInternalUrl(url: string): boolean { for (const prefix of internalPrefixes) { if (prefix.test(url)) { return true @@ -15,6 +15,6 @@ export function isInternalUrl (url: string): boolean { return false } -export function isBlockedPage (pathname: string): boolean { +export function isBlockedPage(pathname: string): boolean { return (BLOCKED_PAGES.indexOf(pathname) !== -1) } diff --git a/packages/next/bin/next-build.ts b/packages/next/bin/next-build.ts index 04988be8..2eb8a18f 100755 --- a/packages/next/bin/next-build.ts +++ b/packages/next/bin/next-build.ts @@ -9,7 +9,7 @@ const args = arg({ // Types '--help': Boolean, // Aliases - '-h': '--help' + '-h': '--help', }) if (args['--help']) { @@ -45,6 +45,7 @@ if (!existsSync(join(dir, 'pages'))) { build(dir) .catch((err) => { + // tslint:disable-next-line console.error('> Build error occurred') printAndExit(err) }) diff --git a/packages/next/bin/next-dev.ts b/packages/next/bin/next-dev.ts index 2e9500d9..dfb64d0b 100755 --- a/packages/next/bin/next-dev.ts +++ b/packages/next/bin/next-dev.ts @@ -14,10 +14,11 @@ const args = arg({ // Aliases '-h': '--help', '-p': '--port', - '-H': '--hostname' + '-H': '--hostname', }) if (args['--help']) { + // tslint:disable-next-line console.log(` Description Starts the application in development mode (hot-code reloading, error @@ -56,6 +57,7 @@ if (!existsSync(join(dir, 'pages'))) { const port = args['--port'] || 3000 startServer({dir, dev: true}, port, args['--hostname']) .then(async (app) => { + // tslint:disable-next-line console.log(`> Ready on http://${args['--hostname'] || 'localhost'}:${port}`) await app.prepare() }) @@ -63,18 +65,19 @@ startServer({dir, dev: true}, port, args['--hostname']) if (err.code === 'EADDRINUSE') { let errorMessage = `Port ${port} is already in use.` const pkgAppPath = require('find-up').sync('package.json', { - cwd: dir + cwd: dir, }) const appPackage = require(pkgAppPath) if (appPackage.scripts) { - const nextScript = Object.entries(appPackage.scripts).find(scriptLine => scriptLine[1] === 'next') + const nextScript = Object.entries(appPackage.scripts).find((scriptLine) => scriptLine[1] === 'next') if (nextScript) { errorMessage += `\nUse \`npm run ${nextScript[0]} -- -p \`.` } } - + // tslint:disable-next-line console.error(errorMessage) } else { + // tslint:disable-next-line console.error(err) } process.nextTick(() => process.exit(1)) diff --git a/packages/next/bin/next-export.ts b/packages/next/bin/next-export.ts index 88d78713..93ded9ad 100755 --- a/packages/next/bin/next-export.ts +++ b/packages/next/bin/next-export.ts @@ -16,10 +16,11 @@ const args = arg({ // Aliases '-h': '--help', '-s': '--silent', - '-o': '--outdir' + '-o': '--outdir', }) if (args['--help']) { + // tslint:disable-next-line console.log(` Description Exports the application for production deployment @@ -57,7 +58,7 @@ const options = { silent: args['--silent'] || false, threads: args['--threads'], concurrency: args['--concurrency'], - outdir: args['--outdir'] ? resolve(args['--outdir']) : join(dir, 'out') + outdir: args['--outdir'] ? resolve(args['--outdir']) : join(dir, 'out'), } exportApp(dir, options) diff --git a/packages/next/bin/next-start.ts b/packages/next/bin/next-start.ts index db7e5ab3..4acb26b6 100755 --- a/packages/next/bin/next-start.ts +++ b/packages/next/bin/next-start.ts @@ -13,10 +13,11 @@ const args = arg({ // Aliases '-h': '--help', '-p': '--port', - '-H': '--hostname' + '-H': '--hostname', }) if (args['--help']) { + // tslint:disable-next-line console.log(` Description Starts the application in production mode. @@ -42,10 +43,12 @@ const dir = resolve(args._[0] || '.') const port = args['--port'] || 3000 startServer({dir}, port, args['--hostname']) .then(async (app) => { + // tslint:disable-next-line console.log(`> Ready on http://${args['--hostname']}:${port}`) await app.prepare() }) .catch((err) => { + // tslint:disable-next-line console.error(err) process.exit(1) }) diff --git a/packages/next/bin/next.ts b/packages/next/bin/next.ts index 037eb62f..edb683af 100755 --- a/packages/next/bin/next.ts +++ b/packages/next/bin/next.ts @@ -3,11 +3,12 @@ import { join } from 'path' import spawn from 'cross-spawn' import arg from 'arg' -['react', 'react-dom'].forEach(dependency => { +['react', 'react-dom'].forEach((dependency) => { try { // When 'npm link' is used it checks the clone location. Not the project. require.resolve(dependency) } catch (err) { + // tslint:disable-next-line console.warn(`The module '${dependency}' was not found. Next.js requires that you include it in 'dependencies' of your 'package.json'. To add it, run 'npm install --save ${dependency}'`) } }) @@ -17,7 +18,7 @@ const commands = [ 'build', 'start', 'export', - defaultCommand + defaultCommand, ] const args = arg({ @@ -28,34 +29,36 @@ const args = arg({ // Aliases '-v': '--version', - '-h': '--help' + '-h': '--help', }, { - permissive: true + permissive: true, }) // Version is inlined into the file using taskr build pipeline if (args['--version']) { + // tslint:disable-next-line console.log(`Next.js v${process.env.NEXT_VERSION}`) process.exit(0) } // Check if we are running `next ` or `next` -const foundCommand = args._.find(cmd => commands.includes(cmd)) +const foundCommand = args._.find((cmd) => commands.includes(cmd)) // Makes sure the `next --help` case is covered // This help message is only showed for `next --help` if (!foundCommand && args['--help']) { + // tslint:disable-next-line console.log(` Usage $ next Available commands ${commands.join(', ')} - + Options --version, -p Version number --inspect Enable the Node.js inspector - --help, -h Displays this message + --help, -h Displays this message For more information run a command with the --help flag $ next build --help @@ -65,12 +68,13 @@ if (!foundCommand && args['--help']) { const nodeArguments: string[] = [] if (args['--inspect']) { + // tslint:disable-next-line console.log('Passing "--inspect" to Node.js') nodeArguments.push('--inspect') } const command = foundCommand || defaultCommand -const forwardedArgs = args._.filter(arg => arg !== command) +const forwardedArgs = args._.filter((arg) => arg !== command) // Make sure the `next --help` case is covered if (args['--help']) { @@ -92,12 +96,14 @@ const startProcess = () => { if (signal === 'SIGKILL') { process.exit(137) } + // tslint:disable-next-line console.log(`got signal ${signal}, exiting`) process.exit(signal === 'SIGINT' ? 0 : 1) } process.exit(0) }) proc.on('error', (err) => { + // tslint:disable-next-line console.error(err) process.exit(1) }) @@ -106,7 +112,7 @@ const startProcess = () => { let proc = startProcess() -function wrapper () { +function wrapper() { if (proc) { proc.kill() } @@ -121,6 +127,7 @@ if (command === 'dev') { const {watchFile} = require('fs') watchFile(`${process.cwd()}/${CONFIG_FILE}`, (cur: any, prev: any) => { if (cur.size > 0 || prev.size > 0) { + // tslint:disable-next-line console.log(`\n> Found a change in ${CONFIG_FILE}, restarting the server...`) // Don't listen to 'close' now since otherwise parent gets killed by listener proc.removeAllListeners('close') diff --git a/tslint.json b/tslint.json new file mode 100644 index 00000000..f09da122 --- /dev/null +++ b/tslint.json @@ -0,0 +1,30 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": { + "curly": false, + "no-empty": false, + "object-literal-sort-keys": false, + "variable-name": false, + "max-line-length": false, + "interface-over-type-literal": false, + "no-shadowed-variable": false, + "no-var-requires": false, + "semicolon": false, + "quotemark": false, + "ordered-imports": false, + "member-access": false, + "member-ordering": false + }, + "rulesDirectory": [], + "linterOptions": { + "exclude": [ + "**/node_modules/**", + "**/build/**", + "**/types/**" + ] + } +}