crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Grafserv imports Ruru which breaks bundling

Open innermatrix opened this issue 2 years ago • 3 comments

  1. I am deploying to AWS lambda, which involves bundling
  2. grafserv imports ruru
  3. ruru does all kinds of bundler-incompatible things like trying to readFileSync package.json etc

The stack looks like

Error: ENOENT: no such file or directory, open '/var/package.json'
    at Object.openSync (node:fs:603:3)
    at readFileSync (node:fs:471:35)
    at mapIterator (/node_modules/ruru/src/server.ts:7:3)
    at file:///var/task/pglambda-v2.mjs:9:495
    at getGrafservHooks (/node_modules/grafserv/src/middleware/graphiql.ts:2:1)
    at file:///var/task/pglambda-v2.mjs:9:495
    at optionsFromConfig (/node_modules/grafserv/src/core/base.ts:22:1)
    at file:///var/task/pglambda-v2.mjs:9:495
    at <anonymous> (/node_modules/grafserv/src/index.ts:1:1)
    at file:///var/task/pglambda-v2.mjs:9:495

As a first pass, I suggest making ruru lazily evaluate non-bundleable code so that it can be imported in bundled contexts without error.

innermatrix avatar Sep 29 '23 21:09 innermatrix

Also: https://github.com/graphile/crystal/blob/7d5a40fa581e307ef48b51b18185355f0d49f3de/grafast/ruru/src/server.ts#L9-L11 which seems to cause issues with Nuxt bundling.

benjie avatar Oct 03 '23 18:10 benjie

We actually have a "version" script that we use to keep the versions in sync without requiring a read of package.json, so should be trivial to expand that to this package.json read; see:

https://github.com/graphile/crystal/blob/main/grafast/grafast/src/version.ts

Fixing the above read of ruru.min.js is going to be a different thing; but I think we can just use something like this to inline it into JS instead of reading from file:

https://github.com/graphile/worker/blob/aae7527fe4a2e3464bb2f198a228c4219ffc6cd9/scripts/buildSqlModule.js#L10-L22

benjie avatar Oct 03 '23 18:10 benjie

Darn, just hit this one as well when deploying to Vercel which, uses AWS Lambda.

psirenny avatar Oct 03 '23 22:10 psirenny