-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(gatsby): upgrade from lmdb-store to lmdb #34576
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7eff1b1
optimistic bump
pieh 91aca6d
.clear -> clearSync
pieh abc1c35
tmp: patch lmdb so we can bundle it for engines
pieh 9b010e6
adjust cache-resilience to import from lmdb
pieh 95c0f65
Merge remote-tracking branch 'origin/master' into chore/upgrade/lmdb
pieh 94ff52b
bump lmdb to latest
pieh f5c7283
use clearKeptObjects()
pieh 1b806f7
fix mocking os.platform() in tests causing loading of wrong lmdb binary
pieh 73749b2
ensure single instance of lmdb in a process - for gatsby serve case m…
pieh 8641c49
add comment about lmdb webpack loader patch
pieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
46 changes: 46 additions & 0 deletions
46
packages/gatsby/src/schema/graphql-engine/lmdb-bundling-patch.ts
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,46 @@ | ||
import { createRequireFromPath } from "gatsby-core-utils" | ||
|
||
// This is hacky webpack loader that does string replacements to | ||
// allow lmdb@2 to be bundled by webpack for engines. | ||
// Currently `@vercel/webpack-asset-relocator-loader doesn't handle | ||
// the way lmdb is loading binaries and dictionary file | ||
// (can't statically analyze it). So we perform few localized changes | ||
// and we replace dynamic values with hardcoded ones to allow | ||
// asset-relocator to pick those assets up and handle them. | ||
// | ||
// Because lmdb code can diverge, we also pin version in gatsby | ||
// dependencies and will have manually bump it (with renovate most likely). | ||
// | ||
// To solve this upstream few things would need to change: | ||
// - https://github.com/DoctorEvidence/lmdb-js/blob/544b3fda402f24a70a0e946921e4c9134c5adf85/node-index.js#L14-L16 | ||
// - https://github.com/DoctorEvidence/lmdb-js/blob/544b3fda402f24a70a0e946921e4c9134c5adf85/open.js#L77 | ||
// Reliance on `import.meta.url` + usage of `.replace` is what seems to cause problems currently. | ||
|
||
export default function (source: string): string { | ||
pieh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let lmdbBinaryLocation | ||
try { | ||
const lmdbRequire = createRequireFromPath(require.resolve(`lmdb`)) | ||
const nodeGypBuild = lmdbRequire(`node-gyp-build`) | ||
const path = require(`path`) | ||
|
||
lmdbBinaryLocation = nodeGypBuild.path( | ||
path.dirname(require.resolve(`lmdb`)).replace(`/dist`, ``) | ||
) | ||
} catch (e) { | ||
return source | ||
} | ||
|
||
return source | ||
.replace( | ||
`require$1('node-gyp-build')(dirName)`, | ||
`require(${JSON.stringify(lmdbBinaryLocation)})` | ||
) | ||
.replace( | ||
`require$2.resolve('./dict/dict.txt')`, | ||
`require.resolve('../dict/dict.txt')` | ||
) | ||
.replace( | ||
/fs\.readFileSync\(new URL\('\.\/dict\/dict\.txt',\s*\(typeof\s*document\s*===\s*'undefined'\s*\?\s*new\s*\(require\('u'\s*\+\s*'rl'\)\.URL\)\s*\('file:'\s*\+\s*__filename\).href\s*:\s*\(document\.currentScript\s*&&\s*document\.currentScript\.src\s*\|\|\s*new URL\('index\.cjs',\s*document\.baseURI\)\.href\)\)\.replace\(\/dist\[\\\\\\\/\]index\.cjs\$\/,\s*''\)\)\)/g, | ||
`fs.readFileSync(require.resolve('../dict/dict.txt'))` | ||
) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems new with
lmdb@2
- we have trailing slashes in master and released generally and not seeing it there (withlmdb-store@1
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and also to clarify - this module does already prevent opening multiple DBs. The problem with
gatsby serve
that this module is used as-is and then it can be used in bundled graphql-engine, so just there are 2 separate instances of this module aliveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooo good catch!