Closed vtrifonov closed 5 years ago
@vtrifonov @mbektchiev First thank for that PR! Now i think we need to discuss a bit more on how to actually use this for the user. It is not easy to actually make it all work. But i managed to end up with this:
The important thing is that i get real ts file absolute path. The great thing about this is that it allow ctrl+click to go the line/column. So useful in dev!
Now there are a few steps to make it work:
config.output
(it should work with source-map, inline-source-map ...)
devtoolModuleFilenameTemplate: info => {
return info.absoluteResourcePath.split('?')[0];
},
devtoolFallbackModuleFilenameTemplate: info => {
return info.absoluteResourcePath.split('?')[0];
}
const currentApp = knownFolders.currentApp();
process.cwd = function() {
return '';
}
require('source-map-support').install({
environment: 'node',
handleUncaughtExceptions: false,
retrieveSourceMap(source) {
const sourceMapPath = source + '.map';
const appPath = currentApp.path;
let sourceMapRelativePath = sourceMapPath
// .replace('file:///', '')
.replace('file://', '')
.replace(appPath + '/', '')
.replace(appPath + '/', '');
if (sourceMapRelativePath.startsWith('app/')) {
sourceMapRelativePath = sourceMapRelativePath.slice(4);
}
return {
url: sourceMapRelativePath,
map: currentApp.getFile(sourceMapRelativePath).readTextSync()
};
}
});
Multiple things there:
process.cwd()
because source-map-support
requires itretrieveSourceMap
to recover the file when using source-map
. there i need to cleanup the path to be able to read the file.That should be good enough. For now i got this to work perfectly on Android.
Now some issues:
prepareStackTrace
(using next runtime to have prepareStackTrace
)Maybe we can discuss all that on slack. Would love to make it work consistently on iOS and Android. I could them publish a nativescript-source-map-support
plugin.
Would it be possible for wepback templates to be updated to support this?
Related to #1135
Added support for Error.prepareStackTrace method similar to the one in V8 and changed the format of the stack trace to be the same as android (also as node and browsers) with
at ...
PR Checklist