Skip to content

Commit 2cef73b

Browse files
authored
fix(gatsby-plugin-page-creator): juggle reporter dont depend on cli (#26357)
* fix(gatsby-plugin-page-creator): juggle reporter rather than depend on cli * Add missing reporter type
1 parent 87babc9 commit 2cef73b

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

packages/gatsby-plugin-page-creator/src/__tests__/is-valid-collection-path-implementation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe(`isValidCollectionPathImplementation`, () => {
1515
`%o passes`,
1616
path => {
1717
expect(() =>
18-
isValidCollectionPathImplementation(compatiblePath(path))
18+
isValidCollectionPathImplementation(compatiblePath(path), reporter)
1919
).not.toThrow()
2020
}
2121
)
@@ -29,7 +29,7 @@ describe(`isValidCollectionPathImplementation`, () => {
2929
])(`%o throws as expected`, path => {
3030
const part = path.split(`/`)[2]
3131

32-
isValidCollectionPathImplementation(compatiblePath(path))
32+
isValidCollectionPathImplementation(compatiblePath(path), reporter)
3333
expect(reporter.panicOnBuild)
3434
.toBeCalledWith(`Collection page builder encountered an error parsing the filepath. To use collection paths the schema to follow is {Model.field}. The problematic part is: ${part}.
3535
filePath: ${compatiblePath(path)}`)

packages/gatsby-plugin-page-creator/src/create-page-wrapper.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createClientOnlyPage } from "./create-client-only-page"
44
import { createPagesFromCollectionBuilder } from "./create-pages-from-collection-builder"
55
import systemPath from "path"
66
import { trackFeatureIsUsed } from "gatsby-telemetry"
7+
import { Reporter } from "gatsby"
78

89
function pathIsCollectionBuilder(path: string): boolean {
910
return path.includes(`{`)
@@ -18,7 +19,8 @@ export function createPage(
1819
pagesDirectory: string,
1920
actions: Actions,
2021
ignore: string[],
21-
graphql: CreatePagesArgs["graphql"]
22+
graphql: CreatePagesArgs["graphql"],
23+
reporter: Reporter
2224
): void {
2325
// Filter out special components that shouldn't be made into
2426
// pages.
@@ -41,7 +43,13 @@ export function createPage(
4143
`PageCreator: Found a collection route, but the proper env was not set to enable this experimental feature. Please run again with \`GATSBY_EXPERIMENTAL_ROUTING_APIS=1\` to enable.`
4244
)
4345
}
44-
createPagesFromCollectionBuilder(filePath, absolutePath, actions, graphql)
46+
createPagesFromCollectionBuilder(
47+
filePath,
48+
absolutePath,
49+
actions,
50+
graphql,
51+
reporter
52+
)
4553
return
4654
}
4755

packages/gatsby-plugin-page-creator/src/create-pages-from-collection-builder.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@ import { derivePath } from "./derive-path"
88
import { watchCollectionBuilder } from "./watch-collection-builder"
99
import { collectionExtractQueryString } from "./collection-extract-query-string"
1010
import { isValidCollectionPathImplementation } from "./is-valid-collection-path-implementation"
11-
import reporter from "gatsby-cli/lib/reporter"
11+
import { Reporter } from "gatsby"
1212

1313
// TODO: Do we need the ignore argument?
1414
export async function createPagesFromCollectionBuilder(
1515
filePath: string,
1616
absolutePath: string,
1717
actions: Actions,
18-
graphql: CreatePagesArgs["graphql"]
18+
graphql: CreatePagesArgs["graphql"],
19+
reporter: Reporter
1920
): Promise<void> {
20-
if (isValidCollectionPathImplementation(absolutePath) === false) {
21+
if (isValidCollectionPathImplementation(absolutePath, reporter) === false) {
2122
watchCollectionBuilder(absolutePath, ``, [], actions, () =>
22-
createPagesFromCollectionBuilder(filePath, absolutePath, actions, graphql)
23+
createPagesFromCollectionBuilder(
24+
filePath,
25+
absolutePath,
26+
actions,
27+
graphql,
28+
reporter
29+
)
2330
)
2431
return
2532
}
@@ -30,7 +37,13 @@ export async function createPagesFromCollectionBuilder(
3037
// 1.a If the query string is not findable, we can't move on. So we stop and watch
3138
if (queryString === null) {
3239
watchCollectionBuilder(absolutePath, ``, [], actions, () =>
33-
createPagesFromCollectionBuilder(filePath, absolutePath, actions, graphql)
40+
createPagesFromCollectionBuilder(
41+
filePath,
42+
absolutePath,
43+
actions,
44+
graphql,
45+
reporter
46+
)
3447
)
3548
return
3649
}
@@ -51,7 +64,13 @@ ${errors.map(error => error.message).join(`\n`)}`.trim()
5164
)
5265

5366
watchCollectionBuilder(absolutePath, queryString, [], actions, () =>
54-
createPagesFromCollectionBuilder(filePath, absolutePath, actions, graphql)
67+
createPagesFromCollectionBuilder(
68+
filePath,
69+
absolutePath,
70+
actions,
71+
graphql,
72+
reporter
73+
)
5574
)
5675

5776
return
@@ -97,6 +116,12 @@ ${errors.map(error => error.message).join(`\n`)}`.trim()
97116
})
98117

99118
watchCollectionBuilder(absolutePath, queryString, paths, actions, () =>
100-
createPagesFromCollectionBuilder(filePath, absolutePath, actions, graphql)
119+
createPagesFromCollectionBuilder(
120+
filePath,
121+
absolutePath,
122+
actions,
123+
graphql,
124+
reporter
125+
)
101126
)
102127
}

packages/gatsby-plugin-page-creator/src/gatsby-node.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,22 @@ Please pick a path to an existing directory.`)
6767
// Get initial list of files.
6868
let files = await glob(pagesGlob, { cwd: pagesPath })
6969
files.forEach(file => {
70-
createPage(file, pagesDirectory, actions, ignore, graphql)
70+
createPage(file, pagesDirectory, actions, ignore, graphql, reporter)
7171
})
7272

7373
watchDirectory(
7474
pagesPath,
7575
pagesGlob,
7676
addedPath => {
7777
if (!_.includes(files, addedPath)) {
78-
createPage(addedPath, pagesDirectory, actions, ignore, graphql)
78+
createPage(
79+
addedPath,
80+
pagesDirectory,
81+
actions,
82+
ignore,
83+
graphql,
84+
reporter
85+
)
7986
files.push(addedPath)
8087
}
8188
},

packages/gatsby-plugin-page-creator/src/is-valid-collection-path-implementation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import sysPath from "path"
2-
import reporter from "gatsby-cli/lib/reporter"
2+
import { Reporter } from "gatsby"
33

44
// This file is a helper for consumers. It's going to log an error to them if they
55
// in any way have an incorrect filepath setup for us to predictably use collection
66
// querying.
77
//
88
// Without this, users will can get mystic errors.
9-
export function isValidCollectionPathImplementation(filePath: string): boolean {
9+
export function isValidCollectionPathImplementation(
10+
filePath: string,
11+
reporter: Reporter
12+
): boolean {
1013
const parts = filePath.split(sysPath.sep)
1114
let passing = true
1215

0 commit comments

Comments
 (0)