KSP-KOS / KSLib

The standard library and examples for the Kerboscript language
MIT License
119 stars 40 forks source link

[discussion] Build tools #107

Open brantwedel opened 6 years ago

brantwedel commented 6 years ago

Working on a build tool similar to "webpack" or "make", written in kerboscript. Just wondering if I should make a PR to this library when it is ready, or if it should be a separate repo.

Also opening a discussion for what build tools / workflow would be useful. Ideally, tools that can be written in kerboscript.


You can take a look at it here in the meantime, lots of abstractions to work out, code to refactor: https://github.com/KSP-KOS/KSLib/compare/master...brantwedel:bw/lib-pack-initial

Notable features of lib_pack:

Example lib_pack supporting json library (PR coming, with or without #directives, depending on results of this discussion): https://gist.github.com/brantwedel/218147d6fde9e6da8855646fcacef286

Note: Looking through the history, this discussion is similar to https://github.com/KSP-KOS/KSLib/issues/6 but with a bit more reach than just a stripper (also an "auto doc" plugin would be nice, and maybe sourcemaps for debugging single line minification).

meltingSnowdrift commented 4 years ago

Inlining of files may change the meaning of programs because the separation between files affects variable scope. From the changelog in the documentation:

File scope was also modified so that each file properly defines a scope. This means that local variables declared in script files called from other scripts are no longer treated as part of the global scope. It also means that script parameters are local to the file itself and will not overwrite global variables.

brantwedel commented 4 years ago

Good point! Altho, with the local name minification/obfuscation, you should be able to maintain the original file local scoping.

meltingSnowdrift commented 4 years ago

Would such a system also correctly treat variables declared as global in a file to make it accessible across all the files of the project? In a simpler but related case, how would it treat global variable declarations that occur inside functions but are still global to the file? (I am not sure if they are also global to the project.)

brantwedel commented 4 years ago

Yes, the minification shouldn't change/minify globals, only locals, since it can't know if globals might be used in other files etc., so should be no behavior change there regardless of if globals redefined in a function since globals are shared between scopes.

Altho, my initial example packing tool doesn't fully handle lazyglobals: TODO: https://github.com/brantwedel/KSLib/blob/9037e446661de6cb70b028e4fb38d549f5773e0b/library/lib_pack.ks#L545 Docs: http://ksp-kos.github.io/KOS/language/user_functions.html#accidentally-using-globals