brucemcpherson / desktopliberation

hosting for desktop liberation google plus community
30 stars 1 forks source link

Moving my libraries to v8 versions #54

Open brucemcpherson opened 3 years ago

brucemcpherson commented 3 years ago

All my libraries are gradually being migrated to v8 versions and decoupled into their own library where appropriate. The legacy versions will still be available but will be frozen. This will allow all the current users to continue with no changes whether or not they are using v8. New users can instead choose to pick the v8 versions.

I'll post progress in here as I set them up. There are hundreds so it'll take a while, but it will also allow me to deprecate those that are no longer relevant

Identifiying v8 versus legacy

Previously all libraries were prefixed by a c as in cUseful. The v8 versions will be prefixed by bm, as in bmFiddler

v8 version

Here's the key for bmFiddler, and it's also on Github https://github.com/brucemcpherson/bmFiddler

13EWG4-lPrEf34itxQhAQ7b9JEbmCBfO8uE4Mhr99CHi3Pw65oxXtq-rU

Legacy version

The legacy version of  Fiddler can be found in my cUseful library as previously

brainysmurf commented 3 years ago

I've actually just published a web app that exposes the functionality of lebab in an easy-to-use interface.

Clearly, there are some incompatibilities between Rhino and V8 that requires more than just a tool to overcome. From your writings, some of your libraries might depend on this.globalThis? The tool will convert any variable declared with var to const/let to help the citizen developer get around the incompatibility of const reassignment that was possible with Rhino, but you can turn that option off.

Useful as a first pass?

brucemcpherson commented 3 years ago

Hey Adam

Nice work!

My biggest problem has been indeed with this/globalthis and also getting to the code of libraries so they could be included client side - so something like this that worked on rhino, won't work on V8 (even globalthis doesnt get me to the library namespace)

function getLibraryNamespace (library) { return this[library]; } /**

Having said that, it was probably a flaky approach anyway driven by what was possible rather than what was necessary - so I'm doing this now instead https://ramblings.mcpher.com/apps-script/apps-script-v8/provoking-server/

which gives me something very much cleaner /**

I'm not planning a wholesale conversion - just future coding will be done v8 style - this actually allows me to port a lot of stuff from node too, so it's all good.

keep up the good work! bruce

On Mon, 21 Dec 2020 at 23:02, Adam Morris notifications@github.com wrote:

I've actually just published a web app https://script.google.com/macros/s/AKfycbzlO8quQeL5pmWsw6s-5IvR0mANl4hCx2DwsIJi/exec that exposes the functionality of lebab https://github.com/brucemcpherson/desktopliberation/issues/54 in an easy-to-use interface.

Clearly, there are some incompatibilities between Rhino and V8 that requires more than just a tool to overcome. From your writings, some of your libraries might depend on this.globalThis? The tool will convert any variable declared with var to const/let to help the citizen developer get around the incompatibility of const reassignment that was possible with Rhino, but you can turn that option off.

Useful as a first pass?

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/brucemcpherson/desktopliberation/issues/54#issuecomment-749244644, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOONBDXY6SVNDOTZYISUKLSV7HYLANCNFSM4VESKDRQ .

oshliaer commented 3 years ago

@brainysmurf , it's a good app Adam! Are you going to open the code or add a translation to another language?

brainysmurf commented 3 years ago

Thanks, @contributorpw, yes an open source repo is underway.

@brucemcpherson Something I don't quite understand …

function myFunction () {
  return this[library];
}

The above doesn't work in V8 runtime? It works for me. When I add a library its identifier is present whenever I execute this:

function myFunction () {
  Logger.log(Object.keys(this));
}

Are you referring to the parsing that has changed. The key though is that as long as you're inside an endpoint, the parsing has already occurred for all the files in the global context. I'm just wondering if I'm missing something?

brucemcpherson commented 3 years ago

Ah I didn't do quite the whole story - I was using that not only to provoke library code from client side, but also to include source code from a library client side into the main htmlservice code( as described belpw), and where the library itself had various namespaces, which is where my pain first started.

https://ramblings.mcpher.com/gassnippets2/reusing-html-stuff-between-apps-script-projects/

I also noted that this is still working but the editor now complains about it, and it's been removed from the reference documentation ScriptApp.getResource(d).getDataAsString()

I rely on that to get source code from .gs files to include as .js.html files server side - ie. sharing the same code between server and client side.

So all those things together .. i decided to move on from trying to solve it all.

brainysmurf commented 3 years ago

Ah! I see. Is this of interest to you?:

The approach I’ve used is to make appscripts libraries as npm modules. For me, that solved a problem of dependencies and ease of maintenance. But since it’s an npm module, you can use a frontend framework like svelte to import it into your frontend code.

So for example my context manager library, it’s available as a regular library with a script ID, but can also be used as a dependency for another library, which can be dependency for others, etc.

Can also import these links into the svelte framework, and it gets bundled into the frontend.

brucemcpherson commented 3 years ago

Yes I generally do all my dev on node - (not too much apps script nowadays actually), but I wanted to keep the tutorials focused on the Apps Script IDE, as most apps script users are still on that, and will probably continue to be - especially since there's now a better one. So I like to try to find solutions that can be contained inside that environment.

It's a good approach otherwise though

thank you & cheers.