Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NODE_DEV_PATH_STACKTRACE env var to show tiddler filepath instead for single tiddler files #8889

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Arlen22
Copy link
Contributor

@Arlen22 Arlen22 commented Jan 9, 2025

Single tiddler files (like javascript files) will use the filepath on disk instead of the tiddler name, allowing the stack trace to be properly clickable (assuming your code editor supports that).

Error: test
    at exports.startup (/home/.../plugins/tiddlywiki/multiwikiserver/modules/startup.js:39:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This doesn't work for files in the boot folder because they have //# sourceURL=$:/boot/..., but it does work for files in core.

Other than being extremely useful, I don't know what the ramifications of this are.

Copy link

github-actions bot commented Jan 9, 2025

Confirmed: Arlen22 has already signed the Contributor License Agreement (see contributing.md)

Copy link

netlify bot commented Jan 9, 2025

Deploy Preview for tiddlywiki-previews ready!

Name Link
🔨 Latest commit 6c3a235
🔍 Latest deploy log https://app.netlify.com/sites/tiddlywiki-previews/deploys/678061722b1ccf0008f0517a
😎 Deploy Preview https://deploy-preview-8889--tiddlywiki-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Arlen22 Arlen22 mentioned this pull request Jan 9, 2025
@Arlen22
Copy link
Contributor Author

Arlen22 commented Jan 9, 2025

Someone needs to check if it changes anything about how the browser handles paths and make sure that the filepath field isn't commonly used for something else. I'm assuming not in Javascript module tiddlers.

It should affect the server edition. If you run the server edition with the env var set, stack traces should include the physical module path as well. I've never seen a good way to use this in the browser, but it would be crazy useful if there was some kind of way to click on a link in your browser and it would take you back to that line in your code editor.

Can someone please figure out whether we can do this with boot.js? I don't know why it has to have a source url set. Perhaps moving the sourceUrl to the rendering tiddler would be a good idea.

@pmario
Copy link
Member

pmario commented Jan 9, 2025

In the browser every module gets a sourceURL info set by TW core. I think it's used to by the debug-tab to show the "file structure" on the left.

The code can be found at:

fn = window["eval"](code + "\n\n//# sourceURL=" + filename);

image

@pmario
Copy link
Member

pmario commented Jan 9, 2025

I am not sure, if we add package-lock.json to a PR. IMO it should be removed. It will be rebuilt by the node build system anyway.

@pmario
Copy link
Member

pmario commented Jan 9, 2025

@Arlen22 -- Where do you set NODE_DEV_PATH_STACKTRACE and what should it contain. I can not find any useful info about this variable at nodejs.org

@Arlen22
Copy link
Contributor Author

Arlen22 commented Jan 10, 2025

@pmario

I am not sure, if we add package-lock.json to a PR. IMO it should be removed. It will be rebuilt by the node build system anyway.

Oops, thanks.

Where do you set NODE_DEV_PATH_STACKTRACE and what should it contain. I can not find any useful info about this variable at nodejs.org

It's just whatever we want to make it. I'm sure you or others here can suggest more appropriate names than that. It definitely shouldn't be found on nodejs.org.

When you enable the flag, it adds the 'filepath' field to tiddlers loaded from the file system, so that if they happen to be a module or other runnable code, the filepath can be used in the sourceUrl instead of the tiddler name.

This works because the other line I changed was in $tw.modules.execute, which checks for the filepath field. If it sees the filepath field it will use that instead of the title. This happens whether the flag is enabled or not, so anyone can use it to customize the filepath that is set in sourceUrl.

If you're using the npm run dev command (which runs the dev script in tiddlywiki's package.json file), you would just add the variable in front of it like so. The value is irrelevant, as the code I'm adding simply tests for truthiness.

NODE_DEV_PATH_STACKTRACE=whatever npm run dev

We could also call it TIDDLER_FILEPATH_STACKTRACE or TW_MODULE_FILEPATH. It just needs to be something that we aren't likely to see in the wild.

@Arlen22
Copy link
Contributor Author

Arlen22 commented Jan 10, 2025

In the browser every module gets a sourceURL info set by TW core. I think it's used to by the debug-tab to show the "file structure" on the left.

The code can be found at:

fn = window["eval"](code + "\n\n//# sourceURL=" + filename);

Yes. I believe so. The only exception is the boot folder, since those are rendered right into the HTML file. As such they do not get eval'ed by that line of code. The sourceUrl for those is set in the last line of the source file itself. That affects both node and browser stack traces, but if someone is desperate they can just remove that line since they're probably working on the file anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants