@@ -238,35 +238,34 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
238
238
args . sourceMapPathOverrides [ 'webpack:///*' ] = `${ fullAppDirPath } /*` ;
239
239
}
240
240
241
- // Apply sourceMapPathOverrides for all file extions: "webpack://name_package/*.extensionFile": "${workspaceRoot}/*.extensionFile"
242
241
const packageFilePath = join ( args . webRoot , 'package.json' ) ;
242
+ const webpackConfig = this . getWebpackConfig ( args . webRoot , args . platform && args . platform . toLowerCase ( ) ) ;
243
+
244
+ // Apply sourceMapPathOverrides for all file extensions: "webpack://packageName|devtoolNamespace/*.extensionFile": "${workspaceRoot}/*.extensionFile"
243
245
if ( existsSync ( packageFilePath ) ) {
244
246
try {
245
247
const packageFile = require ( packageFilePath ) as { name : string } ;
246
248
const extensions = [ "js" , "ts" , "vue" , "svelte" , "jsx" , "tsx" ] ;
249
+ let sourceMap = packageFile . name ;
250
+
251
+ // if user declare devtoolNamespace, use this property for sourceMaps
252
+ if ( webpackConfig ?. output ?. devtoolNamespace ) {
253
+ sourceMap = webpackConfig . output . devtoolNamespace ;
254
+ }
255
+
247
256
extensions . forEach ( extension => {
248
- args . sourceMapPathOverrides [ `webpack://${ packageFile . name } /*.${ extension } ` ] = `${ args . webRoot } /*.${ extension } ` ;
257
+ args . sourceMapPathOverrides [ `webpack://${ sourceMap } /*.${ extension } ` ] = `${ args . webRoot } /*.${ extension } ` ;
249
258
} )
250
259
} catch ( err ) {
251
260
logger . warn ( `Error when trying to require package.json file from path '${ packageFilePath } '. Error is: ${ err } ` ) ;
252
261
}
253
262
}
254
- const webpackConfigFile = join ( args . webRoot , 'webpack.config.js' ) ;
255
- if ( existsSync ( webpackConfigFile ) ) {
256
- try {
257
- const webpackConfig = require ( webpackConfigFile ) ;
258
- const platform = args . platform && args . platform . toLowerCase ( ) ;
259
- const config = webpackConfig ( { [ `${ platform } ` ] : platform } ) ;
260
263
261
- if ( config && config . output && config . output . library ) {
262
- const sourceMapPathOverrideWithLib = `webpack://${ config . output . library } /*` ;
264
+ if ( webpackConfig ? .output ? .library ) {
265
+ const sourceMapPathOverrideWithLib = `webpack://${ webpackConfig . output . library } /*` ;
263
266
264
- args . sourceMapPathOverrides [ sourceMapPathOverrideWithLib ] = args . sourceMapPathOverrides [ sourceMapPathOverrideWithLib ] ||
265
- `${ fullAppDirPath } /*` ;
266
- }
267
- } catch ( err ) {
268
- logger . warn ( `Error when trying to require webpack.config.js file from path '${ webpackConfigFile } '. Error is: ${ err } ` ) ;
269
- }
267
+ args . sourceMapPathOverrides [ sourceMapPathOverrideWithLib ] = args . sourceMapPathOverrides [ sourceMapPathOverrideWithLib ] ||
268
+ `${ fullAppDirPath } /*` ;
270
269
}
271
270
272
271
return args ;
@@ -289,4 +288,17 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
289
288
}
290
289
return address ;
291
290
}
291
+
292
+ private getWebpackConfig ( webRoot : string , platform : string ) {
293
+ const webpackConfigFile = join ( webRoot , 'webpack.config.js' ) ;
294
+ if ( existsSync ( webpackConfigFile ) ) {
295
+ try {
296
+ const webpackConfig = require ( webpackConfigFile ) ;
297
+ return webpackConfig ( { [ `${ platform } ` ] : platform } ) ;
298
+ } catch ( err ) {
299
+ logger . warn ( `Error when trying to require webpack.config.js file from path '${ webpackConfigFile } '. Error is: ${ err } ` ) ;
300
+ }
301
+ }
302
+ return null ;
303
+ }
292
304
}
0 commit comments