Allow plugins to provide Sourcemap files for debugging
Describe the problem to be solved
When developing a plugin, generated Sourcemap files for client scripts are not accessible to browser.
This is because of this function: https://github.com/Chocobozzz/PeerTube/blob/2a491182e483b97afb1b65c908b23cb48d591807/server/controllers/plugins.ts#L128-L136
function servePluginClientScripts (req: express.Request, res: express.Response) {
const plugin: RegisteredPlugin = res.locals.registeredPlugin
const staticEndpoint = req.params.staticEndpoint
const file = plugin.clientScripts[staticEndpoint]
if (!file) return res.status(HttpStatusCode.NOT_FOUND_404).end()
return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions)
}
The controller only allow files that are declared in the plugin package.json (clientScripts entry).
Describe the solution you would like
I suggest to add a test: if the requested filename ends with ".map", and the part before .map is a known clientScripts, and the .map files exist: serve the file.
If you do so, you can then add this line in your quickstart plugin:
const configs = clientFiles.map(f => ({
entryPoints: [ path.resolve(__dirname, '..', 'client', f) ],
bundle: true,
minify: true,
sourcemap: true, // <======================
format: 'esm',
target: 'safari11',
outfile: path.resolve(__dirname, '..', 'dist', f),
}))
https://framagit.org/framasoft/peertube/peertube-plugin-quickstart/-/blob/master/scripts/build.js#L8-15
Thumbs up for this :+1: ! Not having Sourcemap makes it pretty difficult for us to debug anything