Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert prefer-default and log-line-function to TS #23677

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 @@ -36,7 +36,7 @@ const { writeRedirects } = require(`./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