From 6eda1f78d5ef8b0d91e9ecd79e01f5203cc836be Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 19 Nov 2023 05:14:17 +0100 Subject: [PATCH] Turn on --enable-source-maps Turn on source map deduction in stack traces from thrown errors. This feature is off by default due to potential performance degration in certain corner cases. For the dev environment add instructions for passing the option to node. --- docs/contributing.md | 2 ++ packages/create/create.js | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/contributing.md b/docs/contributing.md index d8729a33..34ac895d 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -72,6 +72,8 @@ The documentation uses the binaries provided by the packages, but for the develo npx clusteriohost -> node packages/host npx clusterioctl -> node packages/ctl +By default node does not enable source maps, to get stack traces pointing to the `.ts` files you will need to pass `--enable-source-maps` to `node` or set the environment variable `NODE_OPTIONS=--enable-source-maps`. + Note that to use `clusterioctl` you will have to create a control config first: node packages/controller bootstrap create-ctl-config [admin-user] diff --git a/packages/create/create.js b/packages/create/create.js index cacb19ef..4c252f93 100755 --- a/packages/create/create.js +++ b/packages/create/create.js @@ -375,17 +375,26 @@ async function writeScripts(mode) { if (process.platform === "win32") { await safeOutputFile( "run-controller.cmd", - "@echo off\n.\\node_modules\\.bin\\clusteriocontroller.cmd run\n" + `\ +@echo off. +set "NODE_OPTIONS=--enable-source-maps %NODE_OPTIONS%" +\\node_modules\\.bin\\clusteriocontroller.cmd run +` ); } else { await safeOutputFile( "run-controller.sh", - "#!/bin/sh\nexec ./node_modules/.bin/clusteriocontroller run\n", + `\ +#!/bin/sh +export "NODE_OPTIONS=--enable-source-maps $NODE_OPTIONS" +exec ./node_modules/.bin/clusteriocontroller run +`, { mode: 0o755 }, ); await safeOutputFile( "systemd/clusteriocontroller.service", - `[Unit] + `\ +[Unit] Description=Clusterio Controller [Service] @@ -394,6 +403,7 @@ Group=${await groupIdToName(os.userInfo().gid)} WorkingDirectory=${process.cwd()} KillMode=mixed KillSignal=SIGINT +Environment=NODE_OPTIONS=--enable-source-maps ExecStart=${process.cwd()}/node_modules/.bin/clusteriocontroller run --log-level=warn [Install]