toastdotdev / toast

The best place to stack your JAM. Toast is a Jamstack framework
153 stars 13 forks source link

Binary is not cached by netlify #9

Open ChristopherBiscardi opened 3 years ago

ChristopherBiscardi commented 3 years ago

When running a Toast site on Netlify (and potentially other providers) sometimes NPM is not run, which means the postinstall lifecycle is not run, which means the binary that was downloaded doesn't get cached (and then doesn't get re-downloaded). This results in the following error:

9:11:26 PM: > toast incremental .
9:11:26 PM: internal/process/esm_loader.js:74
9:11:26 PM:     internalBinding('errors').triggerUncaughtException(
9:11:26 PM:                               ^
9:11:26 PM: You have not installed toast

There are two problems here: the first is that the error message is awful. The user has installed toast, we failed to properly cache or inform them, etc. The second issue is that the binary is not actually around to be used. Ideally you wouldn't need to use the netlify toast cache plugin (but we can fix this there), so maybe there's a second lifecycle we can run to ensure the binary exists? maybe install() before run() when process.env.CI?

pantharshit00 commented 3 years ago

At my work, we download the binary at first execution if it is not already there. I think you can do something like that here as well.

ChristopherBiscardi commented 3 years ago

yeah I'm thinking that we should do some kind of "is the binary here" check when the toast node binary wrapper run command starts up

jlengstorf commented 3 years ago

the Cypress plugin always installs — I think it skips if it's already there? maybe something to borrow from here https://github.com/cypress-io/netlify-plugin-cypress/blob/master/src/index.js#L108-L127

jbolda commented 3 years ago

I believe our initial thought was that it was not getting cached because it was outside node_modules. In working on the integration test, it seems that based on our current setup it actually places it in node_modules in binary-install by default: https://github.com/cloudflare/binary-install/blob/master/packages/binary-install/src/binary.js#L45 (note on L83 we get another bin). It seems it might be a general path issue in binary-install rather than lack of being cached.

ChristopherBiscardi commented 3 years ago

@jbolda I have reason to believe that the code in binary-install is different in the installed package vs the source. Or at least behaves differently. When I forked the source, it did bin in a package in node_modules, but when it's installed from npm it goes into /Users/chris/Library/Preferences/toast-nodejs/bin/

jbolda commented 3 years ago

oh were you saying that yesterday? (sorry, tired brain) That would make a fair bit of sense and explain things....

If no one else has a chance, I can probably take a look tonight and see. The path issue seems to be the last thing to resolve. Do we look at taking a queue from Cypress and allowing the location to be set with an env var? (or even checking if CI=true) That way we could toss it in node_modules as needed.

current progress: https://github.com/toastdotdev/toast/blob/feat/integration-test/toast-node-wrapper/binary-management/binary.js