Skip to content

Commit db83405

Browse files
committed
fix apply user devtoolNamespace to default sourcemaps
1 parent 495cf65 commit db83405

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

src/debug-adapter/nativeScriptDebugAdapter.ts

+28-16
Original file line numberDiff line numberDiff line change
@@ -238,35 +238,34 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
238238
args.sourceMapPathOverrides['webpack:///*'] = `${fullAppDirPath}/*`;
239239
}
240240

241-
// Apply sourceMapPathOverrides for all file extions: "webpack://name_package/*.extensionFile": "${workspaceRoot}/*.extensionFile"
242241
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"
243245
if (existsSync(packageFilePath)) {
244246
try {
245247
const packageFile = require(packageFilePath) as { name: string };
246248
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+
247256
extensions.forEach(extension => {
248-
args.sourceMapPathOverrides[`webpack://${packageFile.name}/*.${extension}`] = `${args.webRoot}/*.${extension}`;
257+
args.sourceMapPathOverrides[`webpack://${sourceMap}/*.${extension}`] = `${args.webRoot}/*.${extension}`;
249258
})
250259
} catch (err) {
251260
logger.warn(`Error when trying to require package.json file from path '${packageFilePath}'. Error is: ${err}`);
252261
}
253262
}
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 });
260263

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}/*`;
263266

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}/*`;
270269
}
271270

272271
return args;
@@ -289,4 +288,17 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
289288
}
290289
return address;
291290
}
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+
}
292304
}

0 commit comments

Comments
 (0)