-
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.
fix: re-install lmdb when detecting the absence of @LMDB prebuilt pac…
…kages (#38691) * fix: re-install lmdb when detecting the absence of @LMDB prebuilt packages * chore: set the correct root lmdb and add further comments * chore: linter * chore: linting * chore: make the install check for reliable and install @LMDB instead of lmdb * fix: no need to touch the patch, we can leverage the force binary flag * chore: add integration test for lmdb fix * chore: add CCI config for new integration test * add integration_tests_esm_in_gatsby_files to jobs * fix: integration test for lmdb-regeneration * fix: cli path in test * chore: actually add lmdb's dist directory * fix: back to the npmrc and just rm -rf @LMDB modules --------- Co-authored-by: Michal Piechowiak <[email protected]>
- Loading branch information
Showing
13 changed files
with
299 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__tests__/__debug__ | ||
node_modules | ||
yarn.lock |
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 @@ | ||
build_from_source=true |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 gatsbyjs | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,3 @@ | ||
## Artifacts test suite | ||
|
||
This integration test suite helps us assert our mechanism to heal back from a broken lmdb installation is working by validating we install and use the correct prebundled binary for our platform |
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,59 @@ | ||
const path = require(`path`) | ||
const execa = require(`execa`) | ||
const mod = require("module") | ||
const fs = require(`fs-extra`) | ||
|
||
jest.setTimeout(100000) | ||
|
||
const rootPath = path.resolve(__dirname, "../") | ||
|
||
describe(`Lmdb regeneration`, () => { | ||
test(`gatbsy build detects lmdb setup built from source and installs pre-buit package`, async () => { | ||
const lmdbNodeModulesPath = path.resolve(rootPath, "node_modules", "lmdb") | ||
// Make sure we clear out the current `@lmdb` optional dependencies | ||
const pathsToRemove = [ | ||
path.resolve(rootPath, "node_modules", "@lmdb"), | ||
path.resolve(rootPath, "node_modules", "gatsby", "node_modules", "@lmdb"), | ||
] | ||
for (let path of pathsToRemove) { | ||
fs.rmSync(path, { force: true, recursive: true }) | ||
} | ||
// Check the lmdb instance we have installed does have a binary built from source since we need it to reproduce the fix we're trying to test | ||
// If this check fails then it means our fixture is wrong and we're relying on an lmdb instance with prebuilt binaries | ||
const builtFromSource = fs.existsSync( | ||
path.resolve(lmdbNodeModulesPath, "build", "Release", "lmdb.node") | ||
) | ||
expect(builtFromSource).toEqual(true) | ||
|
||
const options = { | ||
stderr: `inherit`, | ||
stdout: `inherit`, | ||
cwd: rootPath, | ||
} | ||
const gatsbyBin = path.resolve(rootPath, `node_modules`, `gatsby`, `cli.js`) | ||
await execa(gatsbyBin, [`build`], options) | ||
|
||
// lmdb module with prebuilt binaries for our platform | ||
const lmdbPackage = `@lmdb/lmdb-${process.platform}-${process.arch}` | ||
|
||
// If the fix worked correctly we should have installed the prebuilt binary for our platform under our `.cache` directory | ||
const lmdbRequire = mod.createRequire( | ||
path.resolve(rootPath, ".cache", "internal-packages", "package.json") | ||
) | ||
expect(() => { | ||
lmdbRequire.resolve(lmdbPackage) | ||
}).not.toThrow() | ||
|
||
// The resulting query-engine bundle should not contain the binary built from source | ||
const binaryBuiltFromSource = path.resolve( | ||
rootPath, | ||
".cache", | ||
"query-engine", | ||
"assets", | ||
"build", | ||
"Release", | ||
"lmdb.node" | ||
) | ||
expect(fs.existsSync(binaryBuiltFromSource)).toEqual(false) | ||
}) | ||
}) |
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,9 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
siteUrl: `https://www.yourdomain.tld`, | ||
}, | ||
plugins: [], | ||
flags: { | ||
DEV_SSR: true, | ||
}, | ||
} |
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,3 @@ | ||
module.exports = { | ||
testPathIgnorePatterns: [`/node_modules/`, `__tests__/fixtures`, `.cache`], | ||
} |
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,22 @@ | ||
{ | ||
"name": "lmdb-regeneration", | ||
"private": true, | ||
"author": "Sid Chatterjee", | ||
"description": "A simplified bare-bones starter for Gatsby with DSG", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "gatsby build", | ||
"clean": "gatsby clean", | ||
"test": "jest --runInBand" | ||
}, | ||
"dependencies": { | ||
"gatsby": "next", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"fs-extra": "^11.1.0", | ||
"jest": "^29.3.1" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,49 @@ | ||
import * as React from "react" | ||
import { Link } from "gatsby" | ||
|
||
const pageStyles = { | ||
color: "#232129", | ||
padding: "96px", | ||
fontFamily: "-apple-system, Roboto, sans-serif, serif", | ||
} | ||
const headingStyles = { | ||
marginTop: 0, | ||
marginBottom: 64, | ||
maxWidth: 320, | ||
} | ||
|
||
const paragraphStyles = { | ||
marginBottom: 48, | ||
} | ||
const codeStyles = { | ||
color: "#8A6534", | ||
padding: 4, | ||
backgroundColor: "#FFF4DB", | ||
fontSize: "1.25rem", | ||
borderRadius: 4, | ||
} | ||
|
||
const NotFoundPage = () => { | ||
return ( | ||
<main style={pageStyles}> | ||
<h1 style={headingStyles}>Page not found</h1> | ||
<p style={paragraphStyles}> | ||
Sorry 😔, we couldn’t find what you were looking for. | ||
<br /> | ||
{process.env.NODE_ENV === "development" ? ( | ||
<> | ||
<br /> | ||
Try creating a page in <code style={codeStyles}>src/pages/</code>. | ||
<br /> | ||
</> | ||
) : null} | ||
<br /> | ||
<Link to="/">Go home</Link>. | ||
</p> | ||
</main> | ||
) | ||
} | ||
|
||
export default NotFoundPage | ||
|
||
export const Head = () => <title>Not found</title> |
17 changes: 17 additions & 0 deletions
17
integration-tests/lmdb-regeneration/src/pages/test-dsg.jsx
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,17 @@ | ||
import * as React from "react"; | ||
|
||
const DSG = () => { | ||
return <h1>DSG</h1>; | ||
}; | ||
|
||
export default DSG; | ||
|
||
export const Head = () => <title>DSG</title>; | ||
|
||
export async function config() { | ||
return () => { | ||
return { | ||
defer: true, | ||
}; | ||
}; | ||
} |
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