Skip to content

Commit 784d20f

Browse files
sidharthachatterjeeGatsbyJS Bot
authored and
GatsbyJS Bot
committed
refactor(gatsby-plugin-create-client-paths): remove promise (#15015)
1 parent e69800b commit 784d20f

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

packages/gatsby-plugin-create-client-paths/src/gatsby-node.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,29 @@ const validatePrefixEntry = prefix => {
77
}
88
}
99

10-
exports.onCreatePage = ({ page, store, actions }, { prefixes }) => {
10+
exports.onCreatePage = ({ page, actions }, { prefixes }) => {
1111
const { createPage } = actions
1212
const re = {}
1313
prefixes.forEach(validatePrefixEntry)
1414

15-
return new Promise(resolve => {
16-
// Don't set matchPath again if it's already been set.
17-
if (page.matchPath || page.path.match(/dev-404-page/)) {
18-
return resolve()
19-
}
20-
21-
prefixes.forEach(prefix => {
22-
if (!re[prefix]) {
23-
// Remove the * from the prefix and memoize
24-
const trimmedPrefix = prefix.replace(/\*$/, ``)
25-
re[prefix] = new RegExp(`^${trimmedPrefix}`)
26-
}
27-
28-
// Ensure that the path ends in a trailing slash, since it can be removed.
29-
const path = page.path.match(/\/$/) ? page.path : `${page.path}/`
15+
// Don't set matchPath again if it's already been set.
16+
if (page.matchPath || page.path.match(/dev-404-page/)) {
17+
return
18+
}
3019

31-
if (path.match(re[prefix])) {
32-
page.matchPath = prefix.replace(/\*$/, `*`)
33-
createPage(page)
34-
return true
35-
}
20+
prefixes.forEach(prefix => {
21+
if (!re[prefix]) {
22+
// Remove the * from the prefix and memoize
23+
const trimmedPrefix = prefix.replace(/\*$/, ``)
24+
re[prefix] = new RegExp(`^${trimmedPrefix}`)
25+
}
3626

37-
return false
38-
})
27+
// Ensure that the path ends in a trailing slash, since it can be removed.
28+
const path = page.path.match(/\/$/) ? page.path : `${page.path}/`
3929

40-
return resolve()
30+
if (path.match(re[prefix])) {
31+
page.matchPath = prefix.replace(/\*$/, `*`)
32+
createPage(page)
33+
}
4134
})
4235
}

0 commit comments

Comments
 (0)