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

feat: shim reporter from gatsby #29669

Merged
merged 2 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sysPath from "path"
import fs from "fs-extra"
import { collectionExtractQueryString } from "../collection-extract-query-string"
import reporter from "gatsby-cli/lib/reporter"
import reporter from "gatsby/reporter"

jest.mock(`gatsby-cli/lib/reporter`)
jest.mock(`gatsby/reporter`, () => {
return {
panicOnBuild: jest.fn(),
}
})

// This makes the tests work on windows properly
const createPath = (path: string): string => path.replace(/\//g, sysPath.sep)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { derivePath } from "../derive-path"
import reporter from "gatsby-cli/lib/reporter"
import reporter from "gatsby/reporter"

describe(`derive-path`, () => {
it(`has basic support`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { isValidCollectionPathImplementation } from "../is-valid-collection-path-implementation"
import reporter from "gatsby-cli/lib/reporter"
import reporter from "gatsby/reporter"
import syspath from "path"

jest.mock(`gatsby-cli/lib/reporter`)
jest.mock(`gatsby/reporter`, () => {
return {
panicOnBuild: jest.fn(),
}
})

// windows and mac have different seperators, all code is written with unix-like
// file systems, but the underlying code uses `path.sep`. So when running tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { generateQueryFromString } from "./extract-query"
import fs from "fs-extra"
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"
import { extractModel } from "./path-utils"
import { CODES, prefixId } from "./error-utils"

type Reporter = typeof reporter

// This Function opens up the actual collection file and extracts the queryString used in the
export function collectionExtractQueryString(
absolutePath: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { createClientOnlyPage } from "./create-client-only-page"
import { createPagesFromCollectionBuilder } from "./create-pages-from-collection-builder"
import systemPath from "path"
import { trackFeatureIsUsed } from "gatsby-telemetry"
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"

type Reporter = typeof reporter

function pathIsCollectionBuilder(path: string): boolean {
return path.includes(`{`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Move this to gatsby-core-utils?
import { Actions, CreatePagesArgs } from "gatsby"
import { createPath } from "gatsby-page-utils"
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"
import { Options as ISlugifyOptions } from "@sindresorhus/slugify"
import { reverseLookupParams } from "./extract-query"
import { getMatchPath } from "./get-match-path"
Expand All @@ -12,6 +12,8 @@ import { collectionExtractQueryString } from "./collection-extract-query-string"
import { isValidCollectionPathImplementation } from "./is-valid-collection-path-implementation"
import { CODES, prefixId } from "./error-utils"

type Reporter = typeof reporter

export async function createPagesFromCollectionBuilder(
filePath: string,
absolutePath: string,
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-page-creator/src/derive-path.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import _ from "lodash"
import slugify, { Options as ISlugifyOptions } from "@sindresorhus/slugify"
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"
import {
extractFieldWithoutUnion,
extractAllCollectionSegments,
switchToPeriodDelimiters,
stripTrailingSlash,
} from "./path-utils"

type Reporter = typeof reporter
Copy link
Contributor Author

@wardpeet wardpeet Feb 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if there is a better way for this? Maybe also export { IReporter} from gatsby/reporter

cc @ascorbic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, adding a type export would be good. gatsby-cli/lib/reporter/reporter includes a type export for Reporter, so you could add export { Reporter } from "gatsby-cli/lib/reporter/reporter" inside reporter.d.ts


const doubleForwardSlashes = /\/\/+/g

// Generates the path for the page from the file path
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-page-creator/src/error-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"

type Reporter = typeof reporter

export const CODES = {
Generic: `12101`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sysPath from "path"
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"
import { CODES, prefixId } from "./error-utils"
import { matchAllPolyfill } from "./path-utils"

type Reporter = typeof reporter

// This file is a helper for consumers. It's going to log an error to them if they
// in any way have an incorrect filepath setup for us to predictably use collection
// querying.
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const {
setPluginOptions,
} = require(`../plugin-options`)

jest.mock(`gatsby-cli/lib/reporter`, () => {
jest.mock(`gatsby/reporter`, () => {
return {
log: jest.fn(),
info: jest.fn(),
Expand Down
5 changes: 2 additions & 3 deletions packages/gatsby-plugin-sharp/src/__tests__/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
jest.mock(`gatsby-cli/lib/reporter`)
jest.mock(`gatsby/reporter`)
jest.mock(`progress`)
const { calculateImageSizes } = require(`../utils`)
const reporter = require(`gatsby-cli/lib/reporter`)
const progress = require(`progress`)
const reporter = require(`gatsby/reporter`)
const sharp = require(`sharp`)

const file = {
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-sharp/src/image-data.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* eslint-disable no-unused-expressions */
import { IGatsbyImageData, ISharpGatsbyImageArgs } from "gatsby-plugin-image"
import { GatsbyCache, Node } from "gatsby"
import { Reporter } from "gatsby-cli/lib/reporter/reporter"
import reporter from "gatsby/reporter"
import { rgbToHex, calculateImageSizes, getSrcSet, getSizes } from "./utils"
import { traceSVG, getImageSizeAsync, base64, batchQueueImageResizing } from "."
import sharp from "./safe-sharp"
import { createTransformObject, mergeDefaults } from "./plugin-options"
import { reportError } from "./report-error"

type Reporter = typeof reporter

const DEFAULT_BLURRED_IMAGE_WIDTH = 20

const DEFAULT_BREAKPOINTS = [750, 1080, 1366, 1920]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jest.mock(`fs`, () => {
}
})
jest.mock(`recursive-readdir`, () => jest.fn())
jest.mock(`gatsby-cli/lib/reporter`, () => {
jest.mock(`gatsby/reporter`, () => {
return {
panic: jest.fn(),
}
Expand All @@ -15,7 +15,7 @@ const fs = require(`fs`)
const nodePath = require(`path`)
const readdir = require(`recursive-readdir`)

const reporter = require(`gatsby-cli/lib/reporter`)
const reporter = require(`gatsby/reporter`)

const {
OPTION_DEFAULT_REPL_DIRECTORY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jest.mock(`../create-file-node`, () => {
createFileNode: jest.fn(),
}
})
const reporter = require(`gatsby-cli/lib/reporter`)
const reporter = require(`gatsby/reporter`)

const got = require(`got`)
const createRemoteFileNode = require(`../create-remote-file-node`)
Expand Down
2 changes: 0 additions & 2 deletions packages/gatsby-source-filesystem/src/__tests__/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
jest.mock(`gatsby-cli/lib/reporter`)
jest.mock(`progress`)
const { getRemoteFileExtension, getRemoteFileName } = require(`../utils`)

describe(`create remote file node`, () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-source-wordpress/src/models/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"
import { formatLogMessage } from "~/utils/format-log-message"
import { IPluginOptions } from "./gatsby-api"

type Reporter = typeof reporter

type ITimerReporter = ReturnType<Reporter["activityTimer"]>

export interface ILoggerState {
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-source-wordpress/src/steps/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { formatLogMessage } from "~/utils/format-log-message"
import { touchValidNodes } from "../source-nodes/update-nodes/fetch-node-updates"

import { IPluginOptions } from "~/models/gatsby-api"
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"

type Reporter = typeof reporter

export const inPreviewMode = (): boolean =>
!!process.env.ENABLE_GATSBY_REFRESH_ENDPOINT &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Reporter } from "gatsby"
import reporter from "gatsby/reporter"
import { formatLogMessage } from "../utils/format-log-message"

type Reporter = typeof reporter

let isWpSourcePluginInstalled = false

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const extendNodeType = require(`../extend-node-type`)
const { createContentDigest } = require(`gatsby-core-utils`)
const { typeDefs } = require(`../create-schema-customization`)

jest.mock(`gatsby-cli/lib/reporter`, () => {
jest.mock(`gatsby/reporter`, () => {
return {
log: jest.fn(),
info: jest.fn(),
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@
"gatsby-admin-public/",
"graphql.js",
"graphql.d.ts",
"reporter.js",
"reporter.d.ts",
"index.d.ts",
"scripts/postinstall.js",
"utils.js",
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/reporter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "gatsby-cli/lib/reporter"
3 changes: 3 additions & 0 deletions packages/gatsby/reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict"

module.exports = require('gatsby-cli/lib/reporter/index.js').default;