Skip to content

Commit d09d645

Browse files
committed
review suggestions
1 parent c6d6fbb commit d09d645

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

dev-packages/e2e-tests/test-applications/nuxt-3-dynamic-import/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export default defineNuxtConfig({
1818
},
1919
},
2020
sentry: {
21-
autoInjectServerSentry: 'top-level-import',
21+
autoInjectServerSentry: 'experimental_dynamic-import',
2222
},
2323
});

dev-packages/e2e-tests/test-applications/nuxt-3-top-level-import/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export default defineNuxtConfig({
1818
},
1919
},
2020
sentry: {
21-
autoInjectServerSentry: 'experimental_dynamic-import',
21+
autoInjectServerSentry: 'top-level-import',
2222
},
2323
});

packages/nuxt/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ export default defineNuxtModule<ModuleOptions>({
5959

6060
if (serverConfigFile) {
6161
if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {
62-
// Inject the server-side Sentry config file with a side effect import
6362
addPluginTemplate({
6463
mode: 'server',
6564
filename: 'sentry-server-config.mjs',
6665
getContents: () =>
66+
// This won't actually import the server config in the build output (so no double init call). The import here is only needed for correctly resolving the Sentry release injection.
6767
`import "${buildDirResolver.resolve(`/${serverConfigFile}`)}";
6868
import { defineNuxtPlugin } from "#imports";
6969
export default defineNuxtPlugin(() => {});`,

packages/nuxt/src/vite/addServerConfig.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
SENTRY_WRAPPED_FUNCTIONS,
1313
constructFunctionReExport,
1414
constructWrappedFunctionExportQuery,
15-
getFilenameFromPath,
15+
getFilenameFromNodeStartCommand,
1616
removeSentryQueryFromPath,
1717
} from './utils';
1818

@@ -84,7 +84,8 @@ export function addServerConfigToBuild(
8484
*/
8585
export function addSentryTopImport(moduleOptions: SentryNuxtModuleOptions, nitro: Nitro): void {
8686
nitro.hooks.hook('close', async () => {
87-
const fileNameFromCommand = nitro.options.commands.preview && getFilenameFromPath(nitro.options.commands.preview);
87+
const fileNameFromCommand =
88+
nitro.options.commands.preview && getFilenameFromNodeStartCommand(nitro.options.commands.preview);
8889

8990
// other presets ('node-server' or 'vercel') have an index.mjs
9091
const presetsWithServerFile = ['netlify'];

packages/nuxt/src/vite/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export function findDefaultSdkInitFile(type: 'server' | 'client'): string | unde
2727
}
2828

2929
/**
30-
* Extracts the filename from a path.
30+
* Extracts the filename from a node command with a path.
3131
*/
32-
export function getFilenameFromPath(path: string): string | null {
32+
export function getFilenameFromNodeStartCommand(nodeCommand: string): string | null {
3333
const regex = /[^/\\]+$/;
34-
const match = path.match(regex);
34+
const match = nodeCommand.match(regex);
3535
return match ? match[0] : null;
3636
}
3737

@@ -98,7 +98,7 @@ export function extractFunctionReexportQueryParameters(query: string): { wrap: s
9898
*/
9999
export function constructWrappedFunctionExportQuery(
100100
exportedBindings: Record<string, string[]> | null,
101-
experimental_entrypointWrappedFunctions: string[],
101+
entrypointWrappedFunctions: string[],
102102
debug?: boolean,
103103
): string {
104104
const functionsToExport: { wrap: string[]; reexport: string[] } = {
@@ -110,7 +110,7 @@ export function constructWrappedFunctionExportQuery(
110110
// The key `.` refers to exports within the current file, while other keys show from where exports were imported first.
111111
Object.values(exportedBindings || {}).forEach(functions =>
112112
functions.forEach(fn => {
113-
if (experimental_entrypointWrappedFunctions.includes(fn)) {
113+
if (entrypointWrappedFunctions.includes(fn)) {
114114
functionsToExport.wrap.push(fn);
115115
} else {
116116
functionsToExport.reexport.push(fn);

packages/nuxt/test/vite/utils.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
constructWrappedFunctionExportQuery,
1010
extractFunctionReexportQueryParameters,
1111
findDefaultSdkInitFile,
12-
getFilenameFromPath,
12+
getFilenameFromNodeStartCommand,
1313
removeSentryQueryFromPath,
1414
} from '../../src/vite/utils';
1515

@@ -74,37 +74,37 @@ describe('findDefaultSdkInitFile', () => {
7474
describe('getFilenameFromPath', () => {
7575
it('should return the filename from a simple path', () => {
7676
const path = 'node ./server/index.mjs';
77-
const filename = getFilenameFromPath(path);
77+
const filename = getFilenameFromNodeStartCommand(path);
7878
expect(filename).toBe('index.mjs');
7979
});
8080

8181
it('should return the filename from a nested path', () => {
8282
const path = 'node ./.output/whatever/path/server.js';
83-
const filename = getFilenameFromPath(path);
83+
const filename = getFilenameFromNodeStartCommand(path);
8484
expect(filename).toBe('server.js');
8585
});
8686

8787
it('should return the filename from a Windows-style path', () => {
8888
const path = '.\\Projects\\my-app\\src\\main.js';
89-
const filename = getFilenameFromPath(path);
89+
const filename = getFilenameFromNodeStartCommand(path);
9090
expect(filename).toBe('main.js');
9191
});
9292

9393
it('should return null for an empty path', () => {
9494
const path = '';
95-
const filename = getFilenameFromPath(path);
95+
const filename = getFilenameFromNodeStartCommand(path);
9696
expect(filename).toBeNull();
9797
});
9898

9999
it('should return the filename when there are no directory separators', () => {
100100
const path = 'index.mjs';
101-
const filename = getFilenameFromPath(path);
101+
const filename = getFilenameFromNodeStartCommand(path);
102102
expect(filename).toBe('index.mjs');
103103
});
104104

105105
it('should return null for paths with trailing slashes', () => {
106106
const path = 'node ./server/';
107-
const filename = getFilenameFromPath(path);
107+
const filename = getFilenameFromNodeStartCommand(path);
108108
expect(filename).toBeNull();
109109
});
110110
});

0 commit comments

Comments
 (0)