Skip to content

Commit c2e3979

Browse files
author
Luca Forstner
committed
Very dumb poc
1 parent e9d2295 commit c2e3979

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
> NOTE: These are docs for the maintainers of the TanStack Start SDK and not for users of the package.
2+
3+
# Hosting Provider ESM Loader Hooks
4+
5+
This file contains the code for ESM loader hooks that can be base64 encoded and passed to the `NODE_OPTIONS` environment variable as `--import "data:text/javascript;base64,1234BASE64HERE1324"`.
6+
7+
Before encoding the snippets below and pasting them in docs or whatever, make sure to minify them as much as possible.
8+
9+
In their current state the hooks are as minimal as possible. Do not remove things from them because you think they can be smaller - unless thoroughly testing them beforehand!
10+
11+
## Vercel
12+
13+
```mjs
14+
import { register, createRequire } from 'module';
15+
if (!process.env.CI) {
16+
try {
17+
const moduleResolutionContext = `file://${process.cwd()}/index.js`;
18+
const req = createRequire(moduleResolutionContext);
19+
const { createAddHookMessageChannel } = req('import-in-the-middle');
20+
const { addHookMessagePort } = createAddHookMessageChannel();
21+
register('import-in-the-middle/hook.mjs', moduleResolutionContext, {
22+
data: { addHookMessagePort, include: [] },
23+
transferList: [addHookMessagePort],
24+
});
25+
globalThis._sentryEsmLoaderHookRegistered = true;
26+
} catch (e) {
27+
globalThis._sentryEsmLoaderHookError = `${e}`;
28+
}
29+
}
30+
```

packages/tanstackstart/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"@sentry/core": "9.2.0",
5555
"@sentry/node": "9.2.0",
5656
"@sentry/opentelemetry": "9.2.0",
57-
"@sentry/react": "9.2.0"
57+
"@sentry/react": "9.2.0",
58+
"import-in-the-middle": "^1.13.0"
5859
},
5960
"scripts": {
6061
"build": "run-p build:transpile build:types",

packages/tanstackstart/rollup.npm.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export default [
1010
'src/server/index.ts',
1111
'src/config/index.ts',
1212
],
13+
packageSpecificConfig: {
14+
external: ['import-in-the-middle/hook.mjs'],
15+
},
1316
}),
1417
),
1518
...makeOtelLoaders('./build', 'sentry-node'),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
export * from '@sentry/node';
2+
3+
// We're importing this hook to explicitly tell tools like Vercel's `nft` not to throw the file away because it seems unused, because it is actually used by ESM loader hooks the user defines via node CLI arguments.
4+
import 'import-in-the-middle/hook.mjs';
5+
import 'import-in-the-middle';

0 commit comments

Comments
 (0)