Skip to content

Commit

Permalink
Convert prefer-default and log-line-function to TS (#23677)
Browse files Browse the repository at this point in the history
* chore(ts): convert log-line-function to TS

* chore(ts): convert prefer-default to TS
  • Loading branch information
gabrieluizramos authored May 5, 2020
1 parent 56f91a5 commit f4cb5b0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const loadThemes = require(`./load-themes`)
const report = require(`gatsby-cli/lib/reporter`)
import { getConfigFile } from "./get-config-file"
const tracer = require(`opentracing`).globalTracer()
const preferDefault = require(`./prefer-default`)
import { preferDefault } from "./prefer-default"
import { removeStaleJobs } from "./remove-stale-jobs"

// Show stack trace on unhandled promises.
Expand All @@ -37,7 +37,7 @@ import { writeRedirects, startRedirectListener } from "./redirects-writer"
// Override console.log to add the source file + line number.
// Useful for debugging if you lose a console.log somewhere.
// Otherwise leave commented out.
// require(`./log-line-function`)
// import "./log-line-function"

type BootstrapArgs = {
directory: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/load-themes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const mergeGatsbyConfig = require(`../../utils/merge-gatsby-config`)
const Promise = require(`bluebird`)
const _ = require(`lodash`)
const debug = require(`debug`)(`gatsby:load-themes`)
const preferDefault = require(`../prefer-default`)
import { preferDefault } from "../prefer-default"
import { getConfigFile } from "../get-config-file"
const { resolvePlugin } = require(`../load-plugins/load`)
const reporter = require(`gatsby-cli/lib/reporter`)
Expand Down
12 changes: 0 additions & 12 deletions packages/gatsby/src/bootstrap/log-line-function.js

This file was deleted.

20 changes: 20 additions & 0 deletions packages/gatsby/src/bootstrap/log-line-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
;[`log`, `warn`].forEach((method: string): void => {
const old = console[method]

console[method] = (...methodArgs: []): void => {
const error: Error = new Error()
let stack = error.stack ? error.stack.split(/\n/) : []

// Chrome includes a single "Error" line, FF doesn't.
if (stack[0].indexOf(`Error`) === 0) {
stack = stack.slice(1)
}

const [, trace] = stack[1] || ``
const args: string[] = ([] as string[]).slice
.apply(methodArgs)
.concat([trace.trim()])

return old.apply(console, args)
}
})
1 change: 0 additions & 1 deletion packages/gatsby/src/bootstrap/prefer-default.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/gatsby/src/bootstrap/prefer-default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const preferDefault = (m: any): any => (m && m.default) || m
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import telemetry from "gatsby-telemetry"

import { detectPortInUseAndPrompt } from "../utils/detect-port-in-use-and-prompt"
import { getConfigFile } from "../bootstrap/get-config-file"
import preferDefault from "../bootstrap/prefer-default"
import { preferDefault } from "../bootstrap/prefer-default"
import { IProgram } from "./types"

interface IMatchPath {
Expand Down

0 comments on commit f4cb5b0

Please sign in to comment.