Skip to content

Commit

Permalink
fix(gatsby): warnOnce => reportOnce for verbose support (gatsbyjs#33529)
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts authored Oct 14, 2021
1 parent e4c6efe commit eb7fb9a
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/gatsby/src/query/__tests__/data-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
verbose: jest.fn(),
panicOnBuild: console.log,
activityTimer: () => {
return {
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby/src/redux/actions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const { getPageMode } = require(`../../utils/page-mode`)
const normalizePath = require(`../../utils/normalize-path`).default
import { createJobV2FromInternalJob } from "./internal"
import { maybeSendJobToMainProcess } from "../../utils/jobs/worker-messaging"
import { warnOnce } from "../../utils/warn-once"
import { reportOnce } from "../../utils/report-once"
import fs from "fs-extra"

const isNotTestEnv = process.env.NODE_ENV !== `test`
Expand Down Expand Up @@ -1198,7 +1198,7 @@ actions.createJob = (job: Job, plugin?: ?Plugin = null) => {
if (plugin?.name) {
msg = msg + ` (called by ${plugin.name})`
}
warnOnce(msg)
reportOnce(msg)

return {
type: `CREATE_JOB`,
Expand Down Expand Up @@ -1252,7 +1252,7 @@ actions.setJob = (job: Job, plugin?: ?Plugin = null) => {
if (plugin?.name) {
msg = msg + ` (called by ${plugin.name})`
}
warnOnce(msg)
reportOnce(msg)

return {
type: `SET_JOB`,
Expand All @@ -1279,7 +1279,7 @@ actions.endJob = (job: Job, plugin?: ?Plugin = null) => {
if (plugin?.name) {
msg = msg + ` (called by ${plugin.name})`
}
warnOnce(msg)
reportOnce(msg)

return {
type: `END_JOB`,
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/schema/__tests__/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
verbose: jest.fn(),
activityTimer: () => {
return {
start: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/schema/__tests__/rebuild-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
verbose: jest.fn(),
activityTimer: () => {
return {
start: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/schema/infer/__tests__/infer-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
verbose: jest.fn(),
activityTimer: () => {
return {
start: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/schema/infer/__tests__/infer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
verbose: jest.fn(),
activityTimer: () => {
return {
start: jest.fn(),
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/schema/infer/__tests__/merge-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
verbose: jest.fn(),
activityTimer: () => {
return {
start: jest.fn(),
Expand Down
7 changes: 4 additions & 3 deletions packages/gatsby/src/schema/infer/add-inferred-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const report = require(`gatsby-cli/lib/reporter`)
import { isFile } from "./is-file"
import { isDate } from "../types/date"
import { addDerivedType } from "../types/derived-types"
import { warnOnce } from "../../utils/warn-once"
import { reportOnce } from "../../utils/report-once"
import { is32BitInteger } from "../../utils/is-32-bit-integer"
const { getDataStore } = require(`../../datastore`)

Expand Down Expand Up @@ -35,10 +35,11 @@ const addInferredFields = ({
})

if (deprecatedNodeKeys.size > 0) {
warnOnce(
reportOnce(
`The ___NODE convention is deprecated. Please use the @link directive instead.\nType: ${typeComposer.getTypeName()}, Keys: ${Array.from(
deprecatedNodeKeys
).join(`, `)}\nMigration: https://gatsby.dev/node-convention-deprecation`
).join(`, `)}\nMigration: https://gatsby.dev/node-convention-deprecation`,
`verbose`
)
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/schema/types/__tests__/filter-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
verbose: jest.fn(),
activityTimer: () => {
return {
start: jest.fn(),
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/utils/page-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
IMaterializePageMode,
PageMode,
} from "../redux/types"
import { warnOnce } from "./warn-once"
import { reportOnce } from "./report-once"

/**
* In develop IGatsbyPage["mode"] can change at any time, so as a general rule we need to resolve it
Expand Down Expand Up @@ -48,7 +48,7 @@ function resolvePageMode(
pageMode !== `SSG` &&
(page.path === `/404.html` || page.path === `/500.html`)
) {
warnOnce(
reportOnce(
`Status page "${page.path}" ignores page mode ("${pageMode}") and force sets it to SSG (this page can't be lazily rendered).`
)
pageMode = `SSG`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { isWorker } from "gatsby-worker"

const displayedWarnings = new Set<string>()

export const warnOnce = (message: string, key?: string): void => {
export const reportOnce = (
message: string,
method: "log" | "warn" | "info" | "success" | "verbose" | "error" = `warn`,
key?: string
): void => {
const messageId = key ?? message
if (!displayedWarnings.has(messageId) && !isWorker) {
displayedWarnings.add(messageId)
reporter.warn(message)
reporter[method](message)
}
}

0 comments on commit eb7fb9a

Please sign in to comment.