Skip to content

Commit 471364a

Browse files
authored
Properly bundle node modules to be used by the single binary (#1701)
1 parent 2993f24 commit 471364a

File tree

8 files changed

+59
-3
lines changed

8 files changed

+59
-3
lines changed

.changeset/cold-jokes-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/gateway': patch
3+
---
4+
5+
Properly bundle node modules to be used by the single binary

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ memtest-*.svg
2020
*.heapsnapshot
2121
*.heapprofile
2222
*.out
23+
24+
# hidden during isolation testing (see internal/testing/src/isolate.ts)
25+
HIDDEN_node_modules/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@e2e/single-binary-isolate",
3+
"private": true
4+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { createExampleSetup, createTenv } from '@internal/e2e';
2+
import { expect, it } from 'vitest';
3+
4+
const { gateway, gatewayRunner } = createTenv(__dirname);
5+
const {
6+
supergraph: createSupergraph,
7+
query,
8+
result,
9+
} = createExampleSetup(__dirname);
10+
11+
it.runIf(gatewayRunner === 'bin')('should execute in isolation', async () => {
12+
const supergraph = await createSupergraph();
13+
const { execute } = await gateway({
14+
supergraph,
15+
env: {
16+
// TODO: run other e2es with this env var
17+
HIVE_IMPORTER_ONLY_PACKED_DEPS: 1,
18+
},
19+
});
20+
await expect(
21+
execute({
22+
query,
23+
}),
24+
).resolves.toEqual(result);
25+
});

packages/gateway/rollup.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ function packagejson() {
228228
// windows paths don't go in the package.json (just in case, even though we use "/" as pathSep)
229229
.replace(/\\/g, '/');
230230

231+
if (bundledFile === 'index.mjs') {
232+
// there must be a "main" field for packed node modules in the binary to work
233+
pkg.main = 'index.mjs';
234+
}
235+
231236
let entryPoint = './' + bundledFile;
232237
entryPoint = entryPoint.replace(/\.mjs$/, ''); // remove the mjs extension
233238
entryPoint = entryPoint.replace(/\/index$/, ''); // remove the trailing /index because we dont specify it on import (we don't do "import '@graphql-hive/gateway/index'")

packages/gateway/scripts/install-sea-packed-deps.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
String(process.env['SEA_CLEAN_PACKED_DEPS']),
1010
);
1111
const isDebug = ['1', 'y', 'yes', 't', 'true'].includes(
12-
String(process.env['DEBUG']),
12+
String(process.env['DEBUG'] || process.env['SEA_DEBUG']),
1313
);
1414
/**
1515
* Will log only when DEBUG env is set to a truthy value.

packages/importer/src/hooks.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,16 @@ export const resolve: module.ResolveHook = async (
113113
const resolved = resolveFilename(path.join(packedDepsPath, specifier));
114114
debug(`Possible packed dependency "${specifier}" to "${resolved}"`);
115115
return await nextResolve(fixSpecifier(resolved, context), context);
116-
} catch {
117-
// noop
116+
} catch (e) {
117+
if (
118+
['1', 't', 'true'].includes(
119+
process.env['HIVE_IMPORTER_ONLY_PACKED_DEPS'] || '',
120+
)
121+
) {
122+
throw e; // the importer enforces using only packed deps, mainly used for testing. see single-binary-isolate.e2e.ts
123+
} else {
124+
// noop
125+
}
118126
}
119127
}
120128

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,12 @@ __metadata:
33643364
languageName: unknown
33653365
linkType: soft
33663366

3367+
"@e2e/single-binary-isolate@workspace:e2e/single-binary-isolate":
3368+
version: 0.0.0-use.local
3369+
resolution: "@e2e/single-binary-isolate@workspace:e2e/single-binary-isolate"
3370+
languageName: unknown
3371+
linkType: soft
3372+
33673373
"@e2e/subscriptions-cancellation@workspace:e2e/subscriptions-cancellation":
33683374
version: 0.0.0-use.local
33693375
resolution: "@e2e/subscriptions-cancellation@workspace:e2e/subscriptions-cancellation"

0 commit comments

Comments
 (0)