Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 7 additions & 6 deletions bin/bundling/esbuild-plugin-graphiql-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ const resolveGraphiQLAssetHelper = `function resolveGraphiQLAsset(asset) {
const GraphiQLImportsPlugin = {
name: 'GraphiQLImportsPlugin',
setup(build) {
// GraphiQL uses require.resolve with paths that won't work with esbuild
// We need to replace them with valid paths
// graphiql/server.ts uses require.resolve('@shopify/cli-kit/assets/...'). The bundled CLI does not ship
// @shopify/cli-kit as a dependency; assets are copied to dist/assets. Rewrite to a resolver that works whether
// esbuild emits the GraphiQL server into a top-level shared chunk or a nested command file.
// GraphiQL uses require.resolve with paths that won't work after esbuild moves this module.
// We need to replace them with valid paths. The bundled CLI copies cli-kit assets to dist/assets,
// so rewrite to a resolver that works whether esbuild emits the GraphiQL server into a top-level
// shared chunk or a nested command file.
build.onLoad({filter: /[/\\]graphiql[/\\]server\.[cm]?[jt]s$/}, async (args) => {
const contents = await readFile(args.path, 'utf8')
if (!createRequireStatement.test(contents)) {
Expand All @@ -41,7 +40,9 @@ const GraphiQLImportsPlugin = {
contents: contents
.replace(createRequireStatement, (match) => `${match}\n${resolveGraphiQLAssetHelper}`)
.replace("require.resolve('@shopify/cli-kit/assets/graphiql/favicon.ico')", "resolveGraphiQLAsset('favicon.ico')")
.replace("require.resolve('@shopify/cli-kit/assets/graphiql/style.css')", "resolveGraphiQLAsset('style.css')"),
.replace("require.resolve('@shopify/cli-kit/assets/graphiql/style.css')", "resolveGraphiQLAsset('style.css')")
.replace("require.resolve('../../../../assets/graphiql/favicon.ico')", "resolveGraphiQLAsset('favicon.ico')")
.replace("require.resolve('../../../../assets/graphiql/style.css')", "resolveGraphiQLAsset('style.css')"),
}
})
},
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-kit/src/public/node/graphiql/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ export function setupGraphiQLServer(options: SetupGraphiQLServerOptions): Server
)
}

const faviconPath = require.resolve('@shopify/cli-kit/assets/graphiql/favicon.ico')
const faviconPath = require.resolve('../../../../assets/graphiql/favicon.ico')
const faviconContent = readFileSync(faviconPath)
const stylePath = require.resolve('@shopify/cli-kit/assets/graphiql/style.css')
const stylePath = require.resolve('../../../../assets/graphiql/style.css')
const styleContent = readFileSync(stylePath, 'utf8')

app.use(
Expand Down
Loading