From 581402bb7469a3a3e76f39fc61741d7c63ec6b2b Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Fri, 25 Feb 2022 18:14:30 +0100 Subject: [PATCH] fix production e2e? --- .../src/schema/graphql-engine/bundle-webpack.ts | 2 +- .../src/schema/graphql-engine/lmdb-bundling-patch.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts b/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts index b7248a3bbec30..adf5de41dd2b8 100644 --- a/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts +++ b/packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts @@ -71,7 +71,7 @@ export async function createGraphqlEngineBundle( module: { rules: [ { - test: require.resolve(`lmdb`), + test: /node_modules[/\\]lmdb[/\\]/, parser: { amd: false }, use: [ { diff --git a/packages/gatsby/src/schema/graphql-engine/lmdb-bundling-patch.ts b/packages/gatsby/src/schema/graphql-engine/lmdb-bundling-patch.ts index 06241aa2b68d0..ab4dbc82c4c7a 100644 --- a/packages/gatsby/src/schema/graphql-engine/lmdb-bundling-patch.ts +++ b/packages/gatsby/src/schema/graphql-engine/lmdb-bundling-patch.ts @@ -1,4 +1,6 @@ +/* eslint-disable @babel/no-invalid-this */ import { createRequireFromPath } from "gatsby-core-utils" +import path from "path" // This is hacky webpack loader that does string replacements to // allow lmdb@2 to be bundled by webpack for engines. @@ -19,13 +21,13 @@ import { createRequireFromPath } from "gatsby-core-utils" export default function (source: string): string { let lmdbBinaryLocation try { - const lmdbRequire = createRequireFromPath(require.resolve(`lmdb`)) + const lmdbRoot = + this?._module.resourceResolveData?.descriptionFileRoot || + path.dirname(this.resourcePath).replace(`/dist`, ``) + const lmdbRequire = createRequireFromPath(lmdbRoot) const nodeGypBuild = lmdbRequire(`node-gyp-build`) - const path = require(`path`) - lmdbBinaryLocation = nodeGypBuild.path( - path.dirname(require.resolve(`lmdb`)).replace(`/dist`, ``) - ) + lmdbBinaryLocation = nodeGypBuild.path(lmdbRoot) } catch (e) { return source }