Scripting: Implement 'require' module resolution

Post your suggestions here
Post Reply
Jakob Hubbard
Posts: 1210
Joined: Fri Nov 24, 2017 3:16 am
Team: Phil's
Location: Cold
Contact:

Scripting: Implement 'require' module resolution

Post by Jakob Hubbard »

Currently my biggest gripe with the scripting so far is having to deal with all my scripts in one massive file, making it difficult to navigate and organize.

It's less noticeable with server-side scripting as you can just create multiple files and have them all in the server args, however it's still difficult to understand what files are dependent on each other if you don't have any module resolution for other files.

I've been doing some reading into Duktape, (for those who don't know it's the embedded Javascript engine sim uses to turn your js code into something the game can execute) and it looks like you'd have to manually implement some sort of handler for module resolution. [Stack overflow question on the topic]

I've never personally worked with it so I'm not sure how difficult it would be but would be nice to see, especially if you plan on adding UI scripting.
Image
ShortyMX
Posts: 253
Joined: Fri Sep 14, 2012 1:00 pm
Team: JIBR
Location: Germany
Contact:

Re: Scripting: Implement 'require' module resolution

Post by ShortyMX »

+1, but I feel like that would be a lot of work to get right.

Until then, you could probably write a config for rollup, so anyone can write modern js with es6 features and then have it bundled into a single frills.js file
Image
jlv
Site Admin
Posts: 15261
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Scripting: Implement 'require' module resolution

Post by jlv »

One file simplifies things for the checked js files. If I was doing something super complex I'd probably just use "make" and "cat" to combine the files.
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
Jakob Hubbard
Posts: 1210
Joined: Fri Nov 24, 2017 3:16 am
Team: Phil's
Location: Cold
Contact:

Re: Scripting: Implement 'require' module resolution

Post by Jakob Hubbard »

ShortyMX wrote: Fri Sep 05, 2025 7:24 am +1, but I feel like that would be a lot of work to get right.

Until then, you could probably write a config for rollup, so anyone can write modern js with es6 features and then have it bundled into a single frills.js file
Rollup actually looks pretty sweet! Definitely will have a look into this!
Image
Jakob Hubbard
Posts: 1210
Joined: Fri Nov 24, 2017 3:16 am
Team: Phil's
Location: Cold
Contact:

Re: Scripting: Implement 'require' module resolution

Post by Jakob Hubbard »

jlv wrote: Sat Sep 06, 2025 2:41 am One file simplifies things for the checked js files. If I was doing something super complex I'd probably just use "make" and "cat" to combine the files.
Is it not possible to have import logic that works relatively similar to loading a decal or statue? Something like

Code: Select all

require("@yourtrackname/files/js/othermodule.js")
Image
jlv
Site Admin
Posts: 15261
Joined: Fri Nov 02, 2007 5:39 am
Team: No Frills Racing
Contact:

Re: Scripting: Implement 'require' module resolution

Post by jlv »

Jakob Hubbard wrote: Sat Sep 06, 2025 3:46 pm Is it not possible to have import logic that works relatively similar to loading a decal or statue? Something like

Code: Select all

require("@yourtrackname/files/js/othermodule.js")
It'd be easy to do but I'd rather just have one file. I don't want to make more ways to get track mismatches.

Why not just use "cpp" or "cat" to join the files? Would "#include <something.js>" be that bad?
Josh Vanderhoof
Sole Proprietor
jlv@mxsimulator.com
If you email, put "MX Simulator" in the subject to make sure it gets through my spam filter.
Jakob Hubbard
Posts: 1210
Joined: Fri Nov 24, 2017 3:16 am
Team: Phil's
Location: Cold
Contact:

Re: Scripting: Implement 'require' module resolution

Post by Jakob Hubbard »

jlv wrote: Sun Sep 07, 2025 3:35 am It'd be easy to do but I'd rather just have one file. I don't want to make more ways to get track mismatches.

Why not just use "cpp" or "cat" to join the files? Would "#include <something.js>" be that bad?
I understand your reasoning but it seems like a bit of an edge case as most people don't even use the nofrills.js file for scripting. Most just use the frills.js that isn't in the track checksum. If something fails along the way it would just halt execution of the script and wouldn't work for them.

It's not hard to concatenate the files, could write a batch script or use cpp like you said to do that. It's just something that would make the development cycle much more enjoyable for me since organizing imports and modules is something I'm very used to for work.
Image
Post Reply