mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
33af645bea
This suite installed `sqlite` and `sqlite3` on every run to prerender a page from a checked-in SQLite database. Neither package was needed for what the test covers. The pinned `sqlite3@5.0.2` has no linux-arm64 prebuild, and every job that runs this suite is linux-arm64, so each one compiled the SQLite amalgamation from source. That pin is also Node-API based and therefore context-aware, so it could no longer reproduce the abort the suite was originally added for. The fixture now uses its own compiled `native-addon` plus a dependency-free JS wrapper standing in for `sqlite`'s role, and reads its rows from a plain JSON file. The `path.join(process.cwd(), ...)` expression stays in the page, because output file tracing only follows it from the app's own code, so moving it into the wrapper would stop the data file being traced. The emitted traces were read rather than assumed. Turbopack and `@vercel/nft` produce the same fixture entries, including the compiled binary at `native-addon/build/Release/native_addon.node` and the `process.cwd()`-derived `users.json`. The trace assertion now checks each pattern separately instead of collapsing them into a single `every(...)`, which could only report that something did not match. The `notTests` block went away with it, since `[].some(...)` asserted nothing.
63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
// A minimal stand-in for the `bindings` npm package, reproducing only the part
|
|
// both bundlers model: locate the calling package's root by walking up for a
|
|
// `package.json`, then load the compiled binary from `build/Release`.
|
|
//
|
|
// Neither bundler evaluates this file. `@vercel/nft` maps the `bindings`
|
|
// specifier to its own bundled copy, and Turbopack maps it to
|
|
// `WellKnownFunctionKind::NodeBindings`; both then resolve the binary's path
|
|
// themselves. `build/Release/<name>` is node-gyp's default output location and
|
|
// is on both of their candidate lists, so this agrees with what they trace.
|
|
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
function getCallerFile() {
|
|
const { prepareStackTrace } = Error
|
|
try {
|
|
Error.prepareStackTrace = (_error, stack) => stack
|
|
for (const frame of new Error().stack) {
|
|
const fileName = frame.getFileName()
|
|
if (typeof fileName === 'string' && fileName !== __filename) {
|
|
return fileName
|
|
}
|
|
}
|
|
} finally {
|
|
Error.prepareStackTrace = prepareStackTrace
|
|
}
|
|
throw new Error('bindings: could not determine the calling file')
|
|
}
|
|
|
|
function getPackageRoot(file) {
|
|
let dir = path.dirname(file)
|
|
while (!fs.existsSync(path.join(dir, 'package.json'))) {
|
|
const parent = path.dirname(dir)
|
|
if (parent === dir) {
|
|
throw new Error(`bindings: found no package.json above ${file}`)
|
|
}
|
|
dir = parent
|
|
}
|
|
return dir
|
|
}
|
|
|
|
module.exports = function bindings(name) {
|
|
const binary = path.join(
|
|
getPackageRoot(getCallerFile()),
|
|
'build',
|
|
'Release',
|
|
name
|
|
)
|
|
|
|
if (!fs.existsSync(binary)) {
|
|
throw new Error(
|
|
`bindings: ${binary} does not exist. The fixture addon is compiled by ` +
|
|
`node-gyp during install, which requires the package to be listed in ` +
|
|
`the test's pnpm.onlyBuiltDependencies.`
|
|
)
|
|
}
|
|
|
|
// Deliberately not wrapped. A non-context-aware addon fails on this line with
|
|
// Node's own `ERR_DLOPEN_FAILED` / "Module did not self-register", and the
|
|
// worker-thread tests assert on that message.
|
|
return require(binary)
|
|
}
|