Skip to content

Commit d5be3cc

Browse files
authored
fix: add fs.promises to linked filesystem (#441)
* fix: add fs.promises to linked filesystem * test: add coverage for linking of fs.promises * fix: accidentally removed a logging statement
1 parent 54c5e45 commit d5be3cc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

plugin/src/templates/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ export async function prepareFilesystem(
9494
lfs[key].native = fs[key].native
9595
}
9696
}
97+
98+
// 'promises' is not initially linked within the 'linkfs'
99+
// package, and is needed by underlying Gatsby code (the
100+
// @graphql-tools/code-file-loader)
101+
lfs.promises = link(fs.promises, rewrites)
102+
97103
// Gatsby uses this instead of fs if present
98104
// eslint-disable-next-line no-underscore-dangle
99105
global._fsWrapper = lfs

plugin/test/unit/templates/utils.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ describe('prepareFilesystem', () => {
6262
delete process.env.GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE
6363
}, TEST_TIMEOUT)
6464

65+
it(
66+
'links fs.promises to ensure it is available on global._fsWrapper',
67+
async () => {
68+
await moveGatsbyDir()
69+
70+
const cacheDir = resolve('.cache')
71+
await templateUtils.prepareFilesystem(cacheDir, chance.url())
72+
73+
// eslint-disable-next-line no-underscore-dangle
74+
expect(global._fsWrapper.promises).toBeDefined()
75+
},
76+
TEST_TIMEOUT,
77+
)
78+
6579
it(
6680
'downloads file from the CDN when GATSBY_EXCLUDE_DATASTORE_FROM_BUNDLE is enabled',
6781
async () => {

0 commit comments

Comments
 (0)