I know what I’m doing is unsupported, but maybe someone has ideas on how to make it work anyway?
I have server-side Dart working fine but to get client-side Dart compiled (or even to just use shared packages on the server) I need pub packages working (pub is Dart’s equiv of npm).
Packages are restored by calling pub get. I can call this from the install hook in package.json and it seems to work fine (output shows it download packages and no errors). By default these packages go into ~/.pub-cache (~ is /app here). However if I list that folder immediately after, it appears empty:
dart-sdk/bin/pub get && ls -la /app/.pub-cache
This is sorta confusing… it’s like /app/.pub-cache is some magic black hole (or Dart failed to report it couldn’t write here, or it put these files elsewhere, both of which are possible, but unexpected… even --verbose doesn’t make it spit the location out to confirm).
So, maybe anything outside /app/src is readonly and pub is just bad at reporting failures? I tried setting PUB_CACHE which the docs say will change the location of the pub cache:
PUB_CACHE=/app/src/.pub-cache && echo $PUB_CACHE && dart-sdk/bin/pub get && ls -la /app/src/.pub-cache
However still, the files aren’t there. Is there something weird with the filesystem here or am I doing something dopey?
So, after learning a little more about the shell (and the difference between export, env etc) I managed to make this work for both the package restore and dart runtime.
My node script (which downloads and installs Dart) now restores packages like this:
This seems to work; my server-side app is now finding pub packages on disk I do have to edit packages.json if I change pub packages (to trigger pub get with a writeable fs) but if I use dart2js dynamically to compile the client-side scripts, at least they will update immediately.
This is currently in another project, but once I get the client stuff working I’ll pull it back into the simple Dart sample I linked elsewhere.
That’d be great! As fun as it has been abusing node/npm config to run TypeScript and Dart (and I actually mean that; I’ve learned new stuff about node, npm, ts and dart in doing this!) it’s not how I’d choose to run an app for real