Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
prom candy
Dec 16, 2005

Only I may dance

teen phone cutie posted:

these are the type of software projects that make me feel like i need to be doing something else with my life. this is 1000x cooler than anything i'll ever work on

for every developer that does something like this there are probably a million that just do business line work. if i compare myself to jarred sumner i'm just gonna get depressed so I just try to compare myself to myself from a year ago. i'm way smarter than that guy.

Adbot
ADBOT LOVES YOU

Vino
Aug 11, 2010
I'm having trouble figuring out coroutines. This is Typescript.

code:
	let c = C();
	c.next();

	console.log(c.next().value); 
	c.next(1);
}

function* C(): Generator<string, number> {
	while (true) {
		yield "hello";
		let command: any = yield; // error TS2322: Type 'undefined' is not assignable to type 'string'.
		console.log(command);
	}
}
No matter what or how many parameters of Generator<> I pick I get the same error. I can't seem to send values into the coroutine. Maybe Typescript doesn't support it or something? What's going on here?

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

Vino posted:

I'm having trouble figuring out coroutines. This is Typescript.

code:
		let command: any = yield; // error TS2322: Type 'undefined' is not assignable to type 'string'.
What's going on here?

I think you're trying to yield an undefined value - isn't that what 'yield' with no argument does?

Stockwell
Mar 29, 2005
Ask me about personal watercraft.
This seems to work, vanilla js
JavaScript code:

const foo = function* () {
  while (true) yield 'buttes';
};

const generator = foo();
setInterval(() => console.log(generator.next().value),1000);

huhu
Feb 24, 2006

Vino posted:

I'm having trouble figuring out coroutines. This is Typescript.

code:
	let c = C();
	c.next();

	console.log(c.next().value); 
	c.next(1);
}

function* C(): Generator<string, number> {
	while (true) {
		yield "hello";
		let command: any = yield; // error TS2322: Type 'undefined' is not assignable to type 'string'.
		console.log(command);
	}
}
No matter what or how many parameters of Generator<> I pick I get the same error. I can't seem to send values into the coroutine. Maybe Typescript doesn't support it or something? What's going on here?

I found this code sample which I think is what you're looking for:

code:
function* sumNaturalNumbers(): Generator<number, any, number> {
    let value = 1;
    while(true) {
        const input = yield value;
        value += input;
    }
}
const it = sumNaturalNumbers();
it.next();
console.log(it.next(2).value); //3
console.log(it.next(3).value); //6
console.log(it.next(4).value); //10
console.log(it.next(5).value); //15
https://blog.logrocket.com/understanding-typescript-generators/

El Gar
Apr 12, 2007

Hey Trophy...

teen phone cutie posted:

just installed our node_modules with bun instead of npm and it was 1.7 seconds vs. 14

are you loving kidding me?

Global cache w/ the packages already un-tarred and the files hard linked in. You're sharing your node_modules with every other installation on your hard drive, that's the tradeoff.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself

El Gar posted:

Global cache w/ the packages already un-tarred and the files hard linked in. You're sharing your node_modules with every other installation on your hard drive, that's the tradeoff.

are you loving kidding me??

necrotic
Aug 2, 2005
I owe my brother big time for this!
No. Thats how pnp or whatever works too, if I remember right.

huhu
Feb 24, 2006
I went to convert a project to bun last night. All went well until I saw it just doesn't work with Electron. That's a bummer.

teen phone cutie posted:

are you loving kidding me??


Why is this so wrong?

MrMoo
Sep 14, 2000

huhu posted:

I went to convert a project to bun last night. All went well until I saw it just doesn't work with Electron. That's a bummer.


How were you expecting that to work? Electron is literally Blink + NodeJS

https://github.com/electron/electron/issues/34876

Electron barely supports NodeJS properly, like where is ESM support?

There are alternatives that use Webkit instead of Blink, although how ugly they are :shrug:

https://github.com/Elanis/web-to-desktop-framework-comparison

Also comedy option, WPE:

https://webkit.org/wpe/

MrMoo fucked around with this message at 01:20 on Sep 15, 2023

smackfu
Jun 7, 2004

huhu posted:

Why is this so wrong?

A decent number of packages broke when yarn did it but that was years ago so I would think most stuff can deal with a shared location now.

Vino
Aug 11, 2010

huhu posted:

I found this code sample which I think is what you're looking for:

code:
function* sumNaturalNumbers(): Generator<number, any, number> {
    let value = 1;
    while(true) {
        const input = yield value;
        value += input;
    }
}
const it = sumNaturalNumbers();
it.next();
console.log(it.next(2).value); //3
console.log(it.next(3).value); //6
console.log(it.next(4).value); //10
console.log(it.next(5).value); //15
https://blog.logrocket.com/understanding-typescript-generators/

OK so looks like you can read a value from yield so long as you also actually yield a value. Makes sense I suppose. Just confuses me because if you don't yield a value the type of yield is undefined but if you do yield it the type is not the type of what you yielded but the type that was passed into next(). Could be a language bug.

edit: Also works if you make the first template parameter of Generator have |undefined

edit 2: Oh wait I misunderstood the message, it's talking about the 'parameter' of yield. Not a language bug.

Vino fucked around with this message at 02:39 on Sep 15, 2023

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!

MrMoo posted:

Electron barely supports NodeJS properly, like where is ESM support?
Its in nightly. It took tons of hair dragging for them to finally work on it. Last I tried it, resolving nested references to ES modules inside an asar is broken.

El Gar
Apr 12, 2007

Hey Trophy...

necrotic posted:

No. Thats how pnp or whatever works too, if I remember right.

Yes pnpm works the same way.

huhu posted:

Why is this so wrong?

Nothing inherently wrong with this it's just a different way of doing things. It's up to you to decide if you're ok with it.

smackfu posted:

A decent number of packages broke when yarn did it but that was years ago so I would think most stuff can deal with a shared location now.

Yarn has a "pnp" mode still it's just not the default.

npm has one too but it still untars the package from the cache and each project is in isolation from the next, untarred packages are in a local ".store/" directory inside node_modules.

Vino
Aug 11, 2010
I have imports in my code rather than requires and everything was going relatively fine until I tried to start using electron and now I am getting real strange errors. Im hoping someone will tell me a magic bean to fix this but if not, what are my options?

1. Update to a new version of everything to see if theres a bug somewhere
2. Change my toolset to emit code using require and integrate some common js browser polyfill

Both of these seem like huge pains in my asses mainly because I still have no idea what Im doing and none of this has anything to do with making my game. Any pointers?

Of all JavaScript quirks by far the one that has been giving me the most problems is the whole modules situation, where some stuff uses require and other import and never the twain shall meet. What a mess.

MrMoo
Sep 14, 2000

Electron didnt support ESM, ie JavaScript modules. Apparently nightly builds do. Electron is very much behind on NodeJS support. The renderer threads should be ok. But not the preload.

Vino
Aug 11, 2010
Oh interesting thats reasonably good news. I googled around and found a lot of references to adding ESM support to electron but some of them were very old except for this one

https://github.com/electron/electron/pull/37535

That one is only six months old. It says in the comments its in nightly right now. Is that what you mean?

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
Yeah, that's the PR for ESM.

Last I tried, it can't resolve ESM modules properly, when they're inside an asar. It doesn't walk up the directory tree to look into other node_modules directories. Works fine for a loose unpacked resource directory, tho. So if you're using a deduped module tree, you're SOL.

MrMoo
Sep 14, 2000

The critical piece that is still non-final is import maps, you really need them to make module resolution not insane.

Vino
Aug 11, 2010
First I tried to use electron nightly and it's easy enough to get npm to download electron nightly but I was unable to figure out how to get the build process working (electron-forge make) with the nightly, or even to get the nightly to run my game

So I figured maybe I would wait out the nightly being promoted to stable and in the meantime have the typescript compiler spit out CommonJS modules and use some kind of CommonJS browser implementation to get (number 2 from my list from before)

I tried common.js, which had some stupid and obvious bugs that I don't know how they ever managed to release software with clearly obvious bugs like that

I tried browserify, and I got stuck at an un-googlable error

I'm currently looking at webpack and webmake but I'm exhausted

Hoping someone here has a better solution?

huhu
Feb 24, 2006

Vino posted:

First I tried to use electron nightly and it's easy enough to get npm to download electron nightly but I was unable to figure out how to get the build process working (electron-forge make) with the nightly, or even to get the nightly to run my game

So I figured maybe I would wait out the nightly being promoted to stable and in the meantime have the typescript compiler spit out CommonJS modules and use some kind of CommonJS browser implementation to get (number 2 from my list from before)

I tried common.js, which had some stupid and obvious bugs that I don't know how they ever managed to release software with clearly obvious bugs like that

I tried browserify, and I got stuck at an un-googlable error

I'm currently looking at webpack and webmake but I'm exhausted

Hoping someone here has a better solution?

I built an Electron app like a year ago and knew my build process was poo poo. Wanted to redo it. I started here https://www.electronforge.io/guides/framework-integration/react-with-typescript and got a basic boilerplate Electron, react, webpack, and ts helloworld app(what my project is written in) up and working. Then I copied my old React app code and Electron app code over bit by bit until everything was working. Took maybe an hour or two. Had to fight with a few cryptic errors but they were all googleable.

spiritual bypass
Feb 19, 2008

Grimey Drawer
I'm writing my first serious application backend in JavaScript and need a session library. All signs point to express-session, but I'm not using express. This application is SvelteKit, if that matters. I'm hoping to find a session library that's framework/server neutral. Any suggestions?

necrotic
Aug 2, 2005
I owe my brother big time for this!
You can use express with sveltekit

https://kit.svelte.dev/docs/adapter-node#custom-server

If you opted for another server, surely it has a session middleware that can be used.

huhu
Feb 24, 2006
Edit - For whatever loving reason, Electron just spits out jibberish at you if two duplicate apps are open at the same time...

Whelp now I got Electron issues. Curious if anyone might know where to look next.

I used the following CLI to bootstrap an Electron App
code:
yarn create electron-app demo --template=webpack-typescript
I then added React support as they officially recommend.

I then moved all my React code over from my old project.

I can run electron-forge start just fine and do local development. However, when I do electron-forge package, the app opens with the following rendering as HTML

code:
er-radius: 10px; } *::-webkit-scrollbar-thumb { background-color: var(--mui-palette-primary-main); border: solid 3px var(--mui-palette-background-default); border-radius: 10px; }
/*! For license information please see index.js.LICENSE.txt */ (()=>{var e,t,c={7377:(e,t,c)=>{"use strict";c.d(t,{Z:()=>he});var h=function(){function e(e){var t=this;this._insertTag=function(e){va
Which is a super random collection of text to render. Part of it appears to be code I have in my index.html file, Not quite sure where the "For license information..." bit is coming from.

Any clues that stand out here?

huhu fucked around with this message at 06:05 on Sep 19, 2023

spiritual bypass
Feb 19, 2008

Grimey Drawer

necrotic posted:

You can use express with sveltekit

https://kit.svelte.dev/docs/adapter-node#custom-server

If you opted for another server, surely it has a session middleware that can be used.

Thanks, I'd overlooked that completely. From the example and StackOverflow chatter, using a custom server breaks the nice live dev refresh from Vite since it depends on the prod build output. To preserve that dev behavior, I might be stuck rolling my own non-middleware session handler :/

MrMoo
Sep 14, 2000

huhu posted:

Edit - For whatever loving reason, Electron just spits out jibberish at you if two duplicate apps are open at the same time...


The Electron API covers this, you can find many examples of workarounds before this came to be

https://github.com/electron/electron/blob/main/docs/api/app.md#apprequestsingleinstancelock

Of course noted on Snackoverflow,

https://stackoverflow.com/a/52633637

huhu
Feb 24, 2006

MrMoo posted:

The Electron API covers this, you can find many examples of workarounds before this came to be

https://github.com/electron/electron/blob/main/docs/api/app.md#apprequestsingleinstancelock

Of course noted on Snackoverflow,

https://stackoverflow.com/a/52633637
Thank you for this.

Now I'm getting the error
code:
Uncaught SyntaxError: Invalid or unexpected token (at index.js:205:218774)
When I click it seems to bring up some lookup table like so.

code:
t({À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E"
There appears to be valid Javascript before and after this block. Not even sure where to look.

N.Z.'s Champion
Jun 8, 2003

Yam Slacker

huhu posted:

code:
t({:"A",:"A",:"A",:"A",:"A",:"A",:"a",:"a",:"a",:"a",:"a",:"a",:"C",:"c",:"D",:"d",:"E",:"E",:"E"
what the heck is that object? Is its purpose to normalize characters?

It vaguely resembles the garbage you'd get when UTF-8 is parsed as extended ASCII / ISO-8859 text

Deadite
Aug 30, 2003

A fat guy, a watermelon, and a stack of magazines?
Family.
edit: wrong thread

Deadite fucked around with this message at 14:11 on Sep 21, 2023

huhu
Feb 24, 2006
Ended up just finding a better documented dev/packaging setup and piece by piece copied my entire app over. What a pain. But now I've got my first app Running Vite so that's fun.

Vino
Aug 11, 2010

huhu posted:

I built an Electron app like a year ago and knew my build process was poo poo. Wanted to redo it. I started here https://www.electronforge.io/guides/framework-integration/react-with-typescript and got a basic boilerplate Electron, react, webpack, and ts helloworld app(what my project is written in) up and working. Then I copied my old React app code and Electron app code over bit by bit until everything was working. Took maybe an hour or two. Had to fight with a few cryptic errors but they were all googleable.

This almost got me everything I need in that I managed to get a typescript + electron/webpack + i write my code with ESM and not CJS, but I can't seem to figure out how to preserve this build path and also regular running it on the web without webpack at the same time. Is that something I should aspire to or should I lean 100% into webpack? The main reason I'm hesitant to go 100% webpack is I'm skeptical of the debugging experience of a webpack'd app.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Vino posted:

This almost got me everything I need in that I managed to get a typescript + electron/webpack + i write my code with ESM and not CJS, but I can't seem to figure out how to preserve this build path and also regular running it on the web without webpack at the same time. Is that something I should aspire to or should I lean 100% into webpack? The main reason I'm hesitant to go 100% webpack is I'm skeptical of the debugging experience of a webpack'd app.
Webpack configured right with map files is pretty debuggable (even has a devmode with dynamic updates if your app can run locally). Getting it into that state correctly can be quite a chore though. The big curse of webpack is that the config structure has been through multiple not-backwards-compatible iterations so if you ask the internet how to do a thing it's about 50:50 whether the answers will be completely wrong for the version you have.

Vino
Aug 11, 2010
Finally I said gently caress it lets just see if I can get a working package of my app in electron and after some effort I did and I discovered that since webpack renames global variables and functions but misses some that I have stored in strings I cant use webpack. So I cant use electron with webpack and I cant use electron without webpack. So I think I cant use electron. :(

Maybe there are some alternatives that try ti be less clever.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
If you have a dedicated webpack config, you can disable the minifier, which is the transformation step that messes with variable and function names. Maybe thatll help.

Ima Computer
Oct 28, 2007

Stop all the downloading!

Help computer.

Vino posted:

but misses some that I have stored in strings

Why are you storing variable/function names in strings? That's a pretty abnormal thing to do.

Vino
Aug 11, 2010
It's a game with a lot of text and I have basically a simple text templating system that accesses game variables to do stuff like determine character genders. It's a bit hacky of course.

necrotic
Aug 2, 2005
I owe my brother big time for this!
You can reference a function itself without calling it, and then the mangling wont matter. Phone posting but I can edit an example in shortly

edit:

code:
function foo() {
  return 'foo';
}

const funcRefs = {
  foo: foo,
};

console.info(funcRefs['foo']());
Now if webpack mangles foo to e.g. a, the reference in funcRefs will also update and point to a, with the key still 'foo'.

necrotic fucked around with this message at 21:00 on Sep 22, 2023

Vino
Aug 11, 2010
When I was using regular ES modules the problem was that "electron-forge start" was working fine but "electron-forge package" would produce a binary that wouldn't work properly. Finally I thought to myself, if the debug environment works OK then why don't i just copy everything out of node_modules/electron/dist and copy my game's web distribution both into a folder and have a batch script run electron with the command line parameter of my web distribution? Turns out that works. My app isn't terribly intensive so perf isn't a problem. It's hacky but I think it'll tide me over until electron has proper ESM support.

Thanks for everyone who helped me, you're all sovereigns of gender unknown to me and deserving of crowns.

go play outside Skyler
Nov 7, 2005


i went through the pain of getting an electron+ts+import app running and also had some problems with debug working but release failing. it took me a whole loving day of fiddling with webpack and i hope i never have to do it again

Adbot
ADBOT LOVES YOU

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

go play outside Skyler posted:

i went through the pain of getting an electron+ts+import app running and also had some problems with debug working but release failing. it took me a whole loving day of fiddling with webpack and i hope i never have to do it again
I have a project that I keep occasionally coming back to, and I have to remember how the webpack mess works each time. I ended up also putting some one-liner scripts in the folder so I don't have to remember, I can just do "./build" and "./run" and the like. Pro tip.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply