-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby): support node: protocol when bundling engines (#36506)
Co-authored-by: Josh Johnson <jcjohnson77@gmail.com>
- Loading branch information
Showing
9 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
e2e-tests/production-runtime/plugins/gatsby-plugin-node-protocol-test/gatsby-node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const path = require(`node:path`) | ||
|
||
exports.createResolvers = ({ createResolvers }) => { | ||
createResolvers({ | ||
Query: { | ||
fieldWithResolverThatMakeUseOfImportWithNodeProtocol: { | ||
type: `String`, | ||
args: { | ||
left: `String!`, | ||
right: `String!`, | ||
}, | ||
resolve: (_, args) => { | ||
return path.posix.join(args.left, args.right) | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |
1 change: 1 addition & 0 deletions
1
e2e-tests/production-runtime/plugins/gatsby-plugin-node-protocol-test/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// noop |
1 change: 1 addition & 0 deletions
1
e2e-tests/production-runtime/plugins/gatsby-plugin-node-protocol-test/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
21 changes: 21 additions & 0 deletions
21
e2e-tests/production-runtime/polyfill-node-protocol-imports.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// this polyfill adds support for "require('node:<node_builtin>')" imports | ||
// this feature is available in Node v14.18.0+ and v16.0.0+ | ||
// gatsby's minimal version (v14.15.0) does not support this feature | ||
// so the environment we run our e2e tests in doesn't support it | ||
// and we need to use polyfill to test if our bundlers support it correctly | ||
|
||
// this file is injected with NODE_OPTIONS env var via package.json's | ||
// "build" script | ||
|
||
try { | ||
require(`node:path`) | ||
} catch (e) { | ||
const mod = require("module") | ||
const originalModuleLoad = mod._load | ||
mod._load = (request, parent, isMain) => { | ||
if (request.startsWith(`node:`)) { | ||
request = request.replace(`node:`, ``) | ||
} | ||
return originalModuleLoad(request, parent, isMain) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
e2e-tests/production-runtime/src/pages/ssr/using-node-protocol.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default function StaticPath({ data, serverData }) { | ||
return ( | ||
<> | ||
<pre data-testid="field-result"> | ||
{JSON.stringify( | ||
data?.fieldWithResolverThatMakeUseOfImportWithNodeProtocol | ||
)} | ||
</pre> | ||
<pre data-testid="is-ssr"> | ||
{JSON.stringify(serverData?.usingEngines ?? false)} | ||
</pre> | ||
</> | ||
) | ||
} | ||
|
||
// just mark it as page that will use engine | ||
export async function getServerData() { | ||
return { | ||
props: { | ||
usingEngines: true, | ||
}, | ||
} | ||
} | ||
|
||
export const q = graphql` | ||
{ | ||
fieldWithResolverThatMakeUseOfImportWithNodeProtocol( | ||
left: "foo" | ||
right: "bar" | ||
) | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters