Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/solidstart/src/vite/buildInstrumentationFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export function makeBuildInstrumentationFilePlugin(options: SentrySolidStartPlug
async config(config: UserConfig, { command }) {
const instrumentationFilePath = options.instrumentation || './src/instrument.server.ts';
const router = (config as UserConfig & { router: { target: string; name: string; root: string } }).router;
const build = config.build || {};
// SolidStart builds with vinxi's Vite, which predates `rolldownOptions`
// `rollupOptions` is a deprecated alias of `rolldownOptions` in Vite 8+, but the only option in older Vite.
// Returning both makes Vite 8 ignore `rollupOptions`, so only write back the one that is in use.
// oxlint-disable-next-line typescript/no-deprecated
const rollupOptions = build.rollupOptions || {};
const input = [...((rollupOptions.input || []) as string[])];
const { rollupOptions, rolldownOptions, ...build } = config.build || {};
const bundlerOptionsKey = rolldownOptions ? 'rolldownOptions' : 'rollupOptions';
const bundlerOptions = rolldownOptions || rollupOptions || {};
const input = [...((bundlerOptions.input || []) as string[])];
Comment thread
Lms24 marked this conversation as resolved.

// plugin runs for client, server and sever-fns, we only want to run it for the server once.
if (command !== 'build' || router.target !== 'server' || router.name === 'server-fns') {
Expand All @@ -46,9 +48,8 @@ export function makeBuildInstrumentationFilePlugin(options: SentrySolidStartPlug
...config,
build: {
...build,
// oxlint-disable-next-line typescript/no-deprecated
rollupOptions: {
...rollupOptions,
[bundlerOptionsKey]: {
...bundlerOptions,
input,
},
},
Expand Down
22 changes: 22 additions & 0 deletions packages/solidstart/test/vite/buildInstrumentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ describe('makeBuildInstrumentationFilePlugin()', () => {
expect(config.build.rollupOptions.input).toContain('/some/project/path/src/myapp/instrument.server.ts');
});

it('adds the instrumentation file to `rolldownOptions` if the config uses them', async () => {
const buildInstrumentationFilePlugin = makeBuildInstrumentationFilePlugin();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - this is always defined and always a function
const config = await buildInstrumentationFilePlugin.config(
{
...viteConfig,
build: {
rolldownOptions: {
input: ['/path/to/entry1.js'],
},
},
},
{ command: 'build' },
);
expect(config.build.rolldownOptions.input).toEqual([
'/path/to/entry1.js',
'/some/project/path/src/instrument.server.ts',
]);
expect(config.build).not.toHaveProperty('rollupOptions');
});

it("doesn't add the instrumentation file for server function builds", async () => {
const buildInstrumentationFilePlugin = makeBuildInstrumentationFilePlugin();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
Loading