Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(solid-start-vercel): use @vercel/nft to include un-bundable dependancies #702

Merged
merged 14 commits into from
Feb 1, 2023

Conversation

arbassett
Copy link
Contributor

@arbassett arbassett commented Jan 31, 2023

This is a companion/alternative for Vercel pr to #644. Discord discussion

Vercel functions expect all required files to be within the *.func folder while normally this is done automatically with the build process but some files can't be bundled notably prisma's *engine.node and schema.prisma files

in order to do this we use vercels nft (node file trace) package which is used is used internally by next. unlike next we can't just include a [file].js.nft.json file along side the handler due to it not being supported in their Build Output v3. So what we have to do is recreate the folder structure of the app from the root of the filesystem within the .func folder. astro does this to solve the same issue

Example output

.vercel
├── output
│   ├── config.json
│   ├── functions
│   │   ├── api.func
│   │   │   ├── etc
│   │   │   │   └── os-release
│   │   │   └── vercel
│   │   │       └── path0
│   │   │           ├── dist
│   │   │           │   └── index.js
│   │   │           ├── node_modules
│   │   │           └── package.json
│   │   └── render.func
│   │       ├── etc
│   │       │   └── os-release
│   │       └── vercel
│   │           └── path0
│   │               ├── dist
│   │               │   └── index.js
│   │               ├── node_modules
│   │               └── package.json
│   └── static
│       ├── assets
│       │   ├── entry-client.912e70b6.css
│       │   ├── entry-client.bc62b30c.js
│       │   └── index.1502606f.js
│       ├── favicon.ico
│       ├── manifest.json
│       ├── route-manifest.json
│       └── ssr-manifest.json
└── project.json

why from the root? its due to a limitation of @vercel/nft. @vercel/nft will not return files that is outside of what you pass in as root which by default is the cwd. so if a package gets hoisted or files are included from a sibling package we can't copy it

The alternative to this would be to detect if we are inside a workspace and use the workspace root as the root directory only have to create the folder structure from there. But I haven't found a consistent way to determine the package root of an unknown package manager. and would also require keeping up with changes to how workspaces are handled in the future.

since we no longer output directly to .vercel/output for server build we can follow what other adapters do and output the result of the build to dist and then copy it inside .vercel/output/fucntions/[func].func/[workspacePath]

  • Base case (not in workspace)
  • @vercel/nft warnings (some can just be ignored like trying to parse a .env file)
  • Include and exclude globs.
  • Symlinks
  • Workspace support
  • Serverless deployment
  • Test edge deployment (need help testing)
  • Test pre-render deployment (need help test)

@arbassett
Copy link
Contributor Author

to make working with absolute path easier i used URL objects.. for now i left in the equivalent path.join call in a comment for easier reading

@arbassett arbassett marked this pull request as ready for review February 1, 2023 03:01
@ryansolid ryansolid merged commit a0c71fc into solidjs:main Feb 1, 2023
@ryansolid
Copy link
Member

Thank you so much. Very much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants