Skip to content

Commit f3bce8c

Browse files
committed
allow for injecting multiple files at once into webpack entry entries
1 parent 6611e0a commit f3bce8c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as path from 'path';
66

77
import {
88
BuildContext,
9-
EntryPointValue,
109
EntryPropertyObject,
1110
NextConfigObject,
1211
SentryWebpackPluginOptions,
@@ -163,51 +162,52 @@ export function getUserConfigFile(projectDir: string, platform: 'server' | 'clie
163162
}
164163

165164
/**
166-
* Add a file to a specific element of the given `entry` webpack config property.
165+
* Add files to a specific element of the given `entry` webpack config property.
167166
*
168167
* @param entryProperty The existing `entry` config object
169168
* @param entryPointName The key where the file should be injected
170-
* @param filepath The path to the injected file
169+
* @param filepaths An array of paths to the injected files
171170
*/
172-
function addFileToExistingEntryPoint(
171+
function addFilesToExistingEntryPoint(
173172
entryProperty: EntryPropertyObject,
174173
entryPointName: string,
175-
filepath: string,
174+
filepaths: string[],
176175
): void {
177176
// can be a string, array of strings, or object whose `import` property is one of those two
178177
const currentEntryPoint = entryProperty[entryPointName];
179-
let newEntryPoint: EntryPointValue;
178+
let newEntryPoint = currentEntryPoint;
180179

181180
if (typeof currentEntryPoint === 'string') {
182-
newEntryPoint = [filepath, currentEntryPoint];
181+
newEntryPoint = [...filepaths, currentEntryPoint];
183182
} else if (Array.isArray(currentEntryPoint)) {
184-
newEntryPoint = [filepath, ...currentEntryPoint];
183+
newEntryPoint = [...filepaths, ...currentEntryPoint];
185184
}
186185
// descriptor object (webpack 5+)
187186
else if (typeof currentEntryPoint === 'object' && 'import' in currentEntryPoint) {
188187
const currentImportValue = currentEntryPoint.import;
189188
let newImportValue;
190189

191190
if (typeof currentImportValue === 'string') {
192-
newImportValue = [filepath, currentImportValue];
191+
newImportValue = [...filepaths, currentImportValue];
193192
} else {
194-
newImportValue = [filepath, ...currentImportValue];
193+
newImportValue = [...filepaths, ...currentImportValue];
195194
}
196195

197196
newEntryPoint = {
198197
...currentEntryPoint,
199198
import: newImportValue,
200199
};
201-
} else {
202-
// mimic the logger prefix in order to use `console.warn` (which will always be printed, regardless of SDK settings)
200+
}
201+
// malformed entry point (use `console.error` rather than `logger.error` because it will always be printed, regardless
202+
// of SDK settings)
203+
else {
203204
// eslint-disable-next-line no-console
204205
console.error(
205206
'Sentry Logger [Error]:',
206-
`Could not inject SDK initialization code into entry point ${entryPointName}, as it is not a recognized format.\n`,
207+
`Could not inject SDK initialization code into entry point ${entryPointName}, as its current value is not in a recognized format.\n`,
207208
`Expected: string | Array<string> | { [key:string]: any, import: string | Array<string> }\n`,
208209
`Got: ${currentEntryPoint}`,
209210
);
210-
return;
211211
}
212212

213213
entryProperty[entryPointName] = newEntryPoint;

0 commit comments

Comments
 (0)