Remote debugging and Source Maps are supported for either the V8
or NodeJS
backends. (See Switching Backends)
Remote Debugging
You can use DevTools for this (i.e. chrome://inspect
for Chrome or edge://inspect
for Edge). Just make sure to enable Debugger Support
on ScriptEngine first, then you’ll be able to find the Remote Target named “Puerts Inspector” in the DevTools.
Source Maps
You’ll need to install the source-map-support
npm package first. Then, include something like the following block before doing anything else in your code:
require("source-map-support").install({
retrieveSourceMap: (source: string) => {
const fullpath = require('path').join(___workingDir, source + ".map")
if (!require('fs').existsSync(fullpath))
return null
return {
map: require('fs').readFileSync(fullpath, 'utf8')
}
}
})
For Source Maps to show up properly in DevTools, you should also modify your esbuild.mjs
file to change from sourcemap: true
to sourcemap: "inline"
.
For V8
, you’ll also need to polyfill require()
(i.e. as a preload on ScriptEngine) with something like this:
const require = function(name) {
if (name === 'fs') {
return {
existsSync: function(path) {
return CS.System.IO.File.Exists(path);
},
readFileSync: function(path) {
return CS.System.IO.File.ReadAllText(path);
}
}
} else if (name === 'path') {
return {
dirname: function(path) {
return CS.System.IO.Path.GetDirectoryName(path);
},
resolve: function(dir, url) {
url = url.replace(/\\/g, "/");
while (url.startsWith("../")) {
dir = CS.System.IO.Path.GetDirectoryName(dir);
url = url.substr(3);
}
return CS.System.IO.Path.Combine(dir, url);
},
join: function() {
return CS.System.IO.Path.Combine(...arguments);
}
}
}
return null;
};
(This is also available as OneJS/Misc Assets/Preloads/sms.mjs.txt
)