Commit Graph

54 Commits

Author SHA1 Message Date
Jeff See
9db0298981 Switch from jest to vitest for remix builder (#11652) 2024-05-28 17:02:45 +00:00
Nathan Rajlich
ea774628d5 [remix] Don't build the "example" template in legacy e2e tests (#11481)
This template is being done in the "vite" integration suite, so no need to do it in the legacy suite as well.
2024-04-23 23:05:27 +00:00
Nathan Rajlich
b58dcc5733 [remix] Add custom entry.server for Vite test (#11408)
Adds an e2e test fixture which tests that a custom `app/entry.server` file is supported.

Related to:

* https://github.com/vercel/remix/pull/85
* https://github.com/vercel/remix/pull/89
2024-04-10 23:53:49 +00:00
Nathan Rajlich
c82a55c460 [tests] Use AL2 build container for relevant e2e tests (#11329)
* Forces the AL2 build container image for fixtures that depend on it,
via `engines.node` in package.json for most cases.
* The `testDeployment()` function was updated to send
`projectSettings.nodeVersion` in the POST body, to mimic the behavior in
CLI.
* For Go, Ruby, and Python tests, the `projectSettings.nodeVersion`
property is set "globally" in the Jest setup file, so that individual
fixtures didn't need to be adjusted.
2024-03-27 12:19:30 -07:00
Nathan Rajlich
75346d45cc [remix] Add SPA mode e2e tests (#11257)
Adds a couple e2e tests for [Remix SPA](https://remix.run/docs/en/main/future/spa-mode) mode (both with and without using the Vercel Preset).
2024-03-15 23:47:17 +00:00
Nathan Rajlich
58ef91bfe8 [remix] Improve hueristics for detecting Remix + Vite (#11256)
In particular, when both `remix.config` and `vite.config` files exist,
run some additional checks to try to detect if the project is using the
Vite plugin or not.
2024-03-12 15:05:32 -07:00
Shohei Maeda
37b193c845 [build-utils] increase max memory limit (#11209)
internal ref. https://github.com/vercel/api/pull/25997

increasing max limit from 3008 -> 3009 MB

---------

Co-authored-by: Nathan Rajlich <n@n8.io>
2024-03-01 08:23:11 +09:00
Nathan Rajlich
6ed0fe6fb1 [remix] Ensure the symlink directory exists in ensureSymlink() (#11205)
Customer reported an edge case where (in a monorepo) their project's
`package.json` did not list any dependencies (instead they are listed at
the root-level `package.json`) and this caused the `node_modules`
directory to not exist in the app subdirectory, causing
`ensureSymlink()` to fail.
2024-02-29 10:44:18 -08:00
Nathan Rajlich
1333071a3a Remix Vite plugin support (#11031)
Adds support for Remix apps which use the new Remix Vite plugin.

* The vanilla Remix + Vite template deploys correctly out-of-the-box,
however only a single Node.js function will be used, and a warning will
be printed saying to configure the `vercelPreset()` Preset.
* When used in conjunction with the `vercelPreset()` Preset
(https://github.com/vercel/remix/pull/81), allows for the application to
utilize Vercel-specific features, like per-route `export const config`
configuration, including multi-runtime (Node.js / Edge runtimes) within
the same app.

## To test this today

1. Generate a Remix + Vite project from the template:
    ```
    npx create-remix@latest --template remix-run/remix/templates/vite
    ```
1. Install `@vercel/remix`:
    ```
    npm i --save-dev @vercel/remix
    ```
1. **(Before Remix v2.8.0 is released)** - Update the `@remix-run/dev`
dependency to use the "pre" tag which contains [a bug
fix](https://github.com/remix-run/remix/pull/8864):
    ```
    npm i --save--dev @remix-run/dev@pre @remix-run/serve@pre
    ```
1. Configure the `vercelPreset()` in the `vite.config.ts` file:
    ```diff
    --- a/vite.config.ts
    +++ b/vite.config.ts
    @@ -1,10 +1,11 @@
     import { vitePlugin as remix } from "@remix-run/dev";
     import { installGlobals } from "@remix-run/node";
     import { defineConfig } from "vite";
    +import { vercelPreset } from "@vercel/remix/vite";
     import tsconfigPaths from "vite-tsconfig-paths";
    
     installGlobals();
    
     export default defineConfig({
    -  plugins: [remix(), tsconfigPaths()],
    +  plugins: [remix({ presets: [vercelPreset()] }), tsconfigPaths()],
     });
    ```
1. Create a new Vercel Project in the dashboard, and ensure the Vercel
preset is set to "Remix" in the Project Settings. The autodetection will
work correctly once this PR is merged, but for now it gets incorrectly
detected as "Vite" preset.
* **Hint**: You can create a new empty Project by running the `vercel
link` command.
<img width="545" alt="Screenshot 2024-02-27 at 10 37 11"
src="https://github.com/vercel/vercel/assets/71256/f46baf57-5d97-4bde-9529-c9165632cb30">
1. Deploy to Vercel, setting the `VERCEL_CLI_VERSION` environment
variable to use the changes in this PR:
    ```
vercel deploy -b
VERCEL_CLI_VERSION=https://vercel-git-tootallnate-zero-1217-research-remix-v-next-vite.vercel.sh/tarballs/vercel.tgz
    ```
2024-02-28 11:22:05 -06:00
Nathan Rajlich
644721a90d [remix] Add serverBundles post-build sanity check and fallback (#11153)
Adds a check to ensure the `serverBuildPath` for the server bundles was created. If it was not, then that means the Vercel forked Remix compiler was not used, and we must fall back to a singular server bundle.
2024-02-13 22:04:40 +00:00
Steven
0d034b6820 [build-utils] change default package manager when no lockfile detected from yarn to npm (gated behind feature flag) (#11131)
This PR changes the default package manager from `yarn` to `npm` in the case that no lockfile is present.

Many years ago when `yarn` was first released, it was much faster than `npm` so we used it by default. That is no longer the case today and `yarn@1` is no longer receiving new features.

For example, `sharp` and `esbuild` no longer works with `yarn@1`:


### Related

- https://github.com/lovell/sharp/issues/3750
- https://github.com/evanw/esbuild/issues/2949

Note that this change will not impact most projects because most used a lockfile.
2024-02-08 21:26:01 +00:00
Nathan Rajlich
90d0455e1f [remix] Fix functions without a output path edge case (#11038)
Fixes an edge case where a route without a path was causing the build to
fail. Reproducible with this `remix.config.js` file:

```js
export default {
    ignoredRouteFiles: ["**/.*"],
    routes(defineRoutes) {
        return defineRoutes((route) => {
            route("/", "foo.tsx", { index: true });
        });
    },
};
```
2024-01-16 14:37:05 -08:00
Chris Barber
ca2cbf06fb [remix] Resolve static dir using non-parent publicPath segments (#10685) 2023-11-28 17:22:36 -06:00
Chris Barber
5e6ef3d569 Enable source maps in tests (#10725)
The `tsconfig` files were unified with a common configuration in https://github.com/vercel/vercel/pull/10667 including disabling source maps. The source maps greatly increase the distribution size, but they are invaluable when the tests run, so this PR enables source maps for tests including adding a `tsconfig.json` where absent.

Linear: https://linear.app/vercel/issue/ZERO-364/enable-sourcemaps-in-all-testtsconfigjson-files
2023-10-17 15:15:29 +00:00
Nathan Rajlich
f6f16b0347 [remix] Fix ESM mode for Edge runtime, add Remix v2 E2E test (#10530)
Similar to the default import fix from #10525 which was for Node runtime, but this one fixes Edge runtime.

Also adds an E2E test for Remix v2, including both a Node route and Edge route.
2023-09-18 18:26:53 +00:00
Nathan Rajlich
cb784aeb9c [remix] Fixes for Remix v2 (#10525)
The Remix v2 template now uses `"type": "module"` by default, so adjust our bundling logic to account for that possibility.
2023-09-18 14:32:08 +00:00
Nathan Rajlich
844fb6e880 [remix] Set default env vars for Hydrogen v2 deployments (#10341)
In order to make the default mock shop created from `npm create @shopify/hydrogen@latest` work out-of-the-box and without additional configuration, set the necessary default environment variables to make the server not render an error.
2023-08-15 01:11:01 +00:00
Nathan Rajlich
0945d24cbe [remix] Add initial support for Hydrogen v2 (#10305)
Enables support for Hydrogen v2 apps using the "Remix" preset. This initial support works with the Hydrogen demo store template unmodified, and all pages will use Edge functions.

Node.js runtime, and also any other configuration via `export const config`, are not supported at this time, due to some pending blockers.
2023-08-08 21:39:57 +00:00
Nathan Rajlich
d1b0dbe3a7 [remix] Install @vercel/remix-run-dev at build-time instead of using symlink (#9784)
Instead of including the fork `@remix-run/dev` package as a regular dependency of `@vercel/remix-builder`, install it at build-time by modifying the project's `package.json` file. The reasons for this are:

* Avoids deprecation warnings from a few packages that currently exist on the `@remix-run/dev` package when installing Vercel CLI (those warnings already show up in the build logs anyways, so nothing new there).
* Allows us to install a version as close as possible to the version specified in the user's `package.json` (similar to how we do when auto-injecting the `@vercel/remix` package). This will be especially important once Remix v2 is released, which will have breaking changes compared to v1.

**Note:** `@vercel/remix-run-dev` is still a _dev_ dependency, so that we can use TypeScript types from it, as well as, at runtime, we use the version in the Builder's `package.json` to determine the maximum versions of `@vercel/remix-run-dev` and/or `@vercel/remix` which can safely be installed.

Fixes #10027.
Fixes #10222.
2023-07-28 20:49:32 +00:00
Nathan Rajlich
5439d7c0c9 [remix] Create ensured dependency symlink at the start directory, instead of root of repo (#10224)
When the `ensureResolvable()` function runs in a monorepo, the symlink should be created in the `node_modules` directory within the app subdirectory, rather than the root of the repository. Fixes the following issue:

![image](https://github.com/vercel/vercel/assets/71256/c0171533-881a-425e-85b9-82318ef19032)
2023-07-18 18:27:19 +00:00
Nathan Rajlich
64b15d2409 [remix] Fix zero matching on sub catch-all routes (#9707)
Fixes https://github.com/vercel/remix/issues/20.
2023-03-23 12:35:46 -07:00
Nathan Rajlich
1c2ef37173 [remix] Remove symlink creation warning (#9679)
We're now going to encourage users to use `@vercel/remix` instead of `@remix-run/node`. So switch the symlink warning to a `debug()` call instead.
2023-03-16 09:47:13 +00:00
Nathan Rajlich
13d54b2095 [remix] Support optional entry.{server,client}.tsx file (#9620)
Remix v1.14.0 added support for having no `app/entry.server.tsx`/`app/entry.client.tsx` files in a project (there are default versions bundled into `@remix-run/dev`). Projects configured like this are currently failing because we symlink our forked version of the `remix` CLI into the project, so it cannot resolve the necessary modules at build time.

To solve this, instead of relying on the default versions of these files in `@remix-run/dev` package, we'll include our own versions in `@vercel/remix`, and physically copy them into the project dir. This way, the modules used will be properly resolved relative to the project's own `node_modules` dir.

Our default version of `app/entry.server.tsx` is also slightly different then upstream one, because it uses `@vercel/remix-entry-server` to enable isomorphic React streaming on both Node + Edge runtimes. Because of this, if that dependency is not present, then we'll automatically install the dependency at build-time.
2023-03-13 20:47:56 +00:00
Sean Massa
9bc8817f92 [tests] remove eslint from fixture (#9629)
In a previous PR https://github.com/vercel/vercel/pull/9622/files#diff-508a8f08333e1f42e2b2f02e99081c181802b6b2e7baa4e75c18e51e1e703ce4, this fixture was added which contained an eslint config file. We do have these fixtures eslint ignored, but it seems the presence of this config file re-enables it. This causes eslint failures inside the fixture to bubble up and fail lint checks.

This PR removes eslint from the fixture.
2023-03-08 16:42:11 +00:00
Nathan Rajlich
d8cf3e8831 [remix] Add turborepo monorepo E2E test (#9622)
Adds a Remix E2E test with a Turborepo monorepo configuration.
2023-03-08 06:58:18 +00:00
Nathan Rajlich
57e8ec13cf [remix] Support optional static path segments (#9607)
Fixes https://github.com/orgs/vercel/discussions/1707.
2023-03-07 00:50:37 +00:00
Nathan Rajlich
9ae84ba05f [remix] Add test for escaped route paths (#9516)
In Remix routes, you can [use bracket notation to escape the filesystem routing behavior](https://remix.run/docs/en/1.14.0/file-conventions/routes-files#escaping-special-characters). For example `app/routes/receipt[.]pdf.tsx` would be available at path `/receipt.pdf` (whereas, unescaped, it would be at `/receipt/pdf`).

This adds an e2e test for that behavior.
2023-03-03 21:33:12 +00:00
Ethan Arrowood
7f89aca52c [tests] Add more remix tests (#9600)
Adds some more tests to the remix project. 

- 05-root-only : tests a remix app with only a `root.jsx` route.
  - https://kentcdodds.com/blog/super-simple-start-to-remix
- 06-v2-routing : tests the remix v2 routing works
2023-03-03 18:18:14 +00:00
Nathan Rajlich
fb37ad22ab [remix] Fix support for optional path params (#9590)
Changes the way that routes with optional params are stored on Vercel to not use `?` in the name, because it's not possible to have a route destination with a `?` that's pointing to a function.

So instead of the function with a name such as `:lang?`, it will be stored on Vercel with a name like `(:lang)`, which can be routed to.
2023-03-02 23:28:26 +00:00
Nathan Rajlich
0bbb06daa7 [remix] Support "regions", "memory" and "maxDuration" in static config (#9442)
Apply the `regions` configuration (for both Edge and Node) and `memory`/`maxDuration` (only for Node) in a page's static config export, i.e.

```js
export const config = { runtime: 'edge', regions: ['iad1'] }

// or for Node
export const config = { runtime: 'nodejs', regions: ['iad1'], maxDuration: 5, memory: 3008 }
```

Similar to `runtime`, these config values can be inherited from a parent layout route to apply to all sub-routes. Routes with common config settings get placed into a common server bundle, meaning that there may now be more than 2 functions created (previously was one Edge, one Node), allowing for more granularity between the server build bundles.
2023-03-01 21:45:10 +00:00
Nathan Rajlich
61de63d285 [remix] Split Edge and Node server builds using serverBundles config (#9504)
Utilize the [`serverBundles`](https://github.com/remix-run/remix/pull/5479) config option to generate two server bundle builds. One contains only the routes that should run in Node.js, and the other contains only the routes that should run in the Edge runtime. In the future we could update this configuration to generate more than two bundles to be more granular and allow for infinite scalability.

Because the `serverBundles` PR is not yet merged, this PR introduces usage of a forked version of `@remix-run/dev` which incorporates our changes. Hopefully usage of a fork is temporary, but it gets us unblocked for now.
2023-03-01 03:10:42 +00:00
Nathan Rajlich
ae4180b287 [tests] Use probes.json instead of vercel.json for e2e tests (#9556)
Makes it easier to test fixtures directly via CLI deployments.

Coincidentally, this also revealed that auto-detection of Remix apps wasn't working correctly if there's a `remix.config.mjs` file. So `@vercel/frameworks` is updated to account for that case as well.
2023-03-01 01:02:43 +00:00
Nathan Rajlich
1390f6d2ee [remix] Gracefully handle symlink creation when updating Remix packages (#9569)
Fixes an edge-case error when changing the version of Remix and then making a deployment to Vercel when there is already an existing build cache:

> Error: EEXIST: file already exists, symlink '../.pnpm/@remix-run+server-runtime@1.5.0_biqbaboplfbrettd7655fr4n2y/node_modules/@remix-run/server-runtime' -> '/vercel/path0/node_modules/@remix-run/server-runtime'

This would happen because the symlink was created in a previous run, but no longer points to a valid path because it's a different version. To fix we'll delete the previous symlink when the target value does not match.
2023-02-28 22:51:58 +00:00
Nathan Rajlich
4e6659ace7 [remix] Fix sending multiple response headers with the same name with Node.js (#9533)
i.e. `Set-Cookie`. Right now only one will be sent and others will be lost. This update matches the code being used in `@remix-run/vercel`.
2023-02-27 07:19:58 +00:00
Nathan Rajlich
769234b6a6 [remix] Inject Edge entrypoint into @remix-run/vercel during Edge Function creation (#9553)
There's [a PR](https://github.com/remix-run/remix/pull/5537) opened on
Remix to add an Edge compatible entrypoint to `@remix-run/vercel`. This
is only really needed specifically for projects that have a custom
server.js entrypoint file, which is not strictly necessary anymore, but
there are some edge cases where a project might still want to have one.
So this PR is necessary for those kinds of projects to be able to use
Edge runtime.

Even when they merge the PR, it would be good to leave this injection
code around for some time to continue support for older
`@remix-run/vercel` versions in existing projects.
2023-02-25 00:53:30 -08:00
Nathan Rajlich
3a65acfb32 [remix] Don't create output for Pathless Layout Routes without any child routes at the root level (#9539)
Fixes https://github.com/vercel/community/discussions/1587.
2023-02-25 01:17:01 +00:00
Nathan Rajlich
fea05383b9 [remix] Ignore serverBuildPath from Remix config (#9531)
We are explicitly overriding `serverBuildPath` so there is no need to use the value that `readConfig()` gives to us.

Fixes #9524.
2023-02-23 23:52:27 +00:00
Nathan Rajlich
73d6f0d0fa [remix] Update @remix-run/dev dep to v1.13.0 (#9519)
There were some fixes to thier new v2 filesystem routing that this will help with.

Related to https://github.com/remix-run/remix/issues/5322 and https://github.com/remix-run/remix/pull/5228.
2023-02-23 03:44:37 +00:00
Nathan Rajlich
a91690fb8a [tests] Remove watchPaths from remix test fixture (#9517)
Follow-up to https://github.com/vercel/vercel/pull/9512 which is a
revert of the test fixture.

The fixture was actually broken in the previous commit
(https://github.com/vercel/vercel/pull/9506) since it now is trying to
read the config file before running the Build Command. Having a setup
like this will not be able to be supported, especially in order to land
https://github.com/vercel/vercel/pull/9504.
2023-02-22 19:07:37 -05:00
Nathan Rajlich
b8cce66eff [remix] Simplify ESM detection of remix.config.js (#9512)
In a Turborepo setup, there was this in the `remix.config.js` file:

```js
  watchPaths: [require.resolve("ui")],
```

Since we attempt to `require()` the `remix.config.js` file in order to
determine whether or not it is using ESM syntax, this would fail since
the require happens before the Build Command is executed.

To fix, treat any non `ERR_REQUIRE_ESM` error as CJS, instead of
re-throwing the error. If there really is an issue with importing the
config, then that'll happen right after when `remix build` is doing it.
2023-02-22 15:22:18 -08:00
Nathan Rajlich
cbad57d14f [remix] Restore support for a custom server.js entrypoint file (#9506)
When the project defines a custom `server.js` file in `remix.config.js`,
then don't override that with the bundled
`server-node.mjs`/`server-edge.mjs` file. This allows for a custom
`getLoadContext()` function to remain supported.

In order for Edge runtime to be supported, a [companion
PR](https://github.com/remix-run/remix/pull/5537) for
`@remix-run/vercel` adapter has been created with a dedicated entrypoint
for when Edge runtime is being used. In order to support Edge on
previous versions of the adapter, we may end up patching the package to
enable support, but that will happen in a follow-up PR.

Related to https://github.com/orgs/vercel/discussions/1596.

---------

Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
2023-02-22 14:19:40 -08:00
Nathan Rajlich
4da176d26f [remix] Allow runtime to be defined from a parent route (#9473)
Make it so that the `export const config = { runtime }` value is "inherited" from a parent route, if it is defined.

For example, "edge" can be defined in `app/root.tsx`, and so all routes will use the Edge runtime by default, unless `"runtime": "nodejs"` is used more specifically in a route deeper in the route hierarchy.
2023-02-22 20:35:12 +00:00
Nathan Rajlich
63211b8b89 [remix] Add unit tests (#9469)
Moves parts of the `@vercel/remix` builder into util functions that have isolated unit tests. No functionality changes.
2023-02-17 18:46:33 +00:00
Nathan Rajlich
d52d26eaac [remix] Install Node globals (#9467)
Fixes https://github.com/vercel/community/discussions/1547.
Fixes https://github.com/vercel/community/discussions/1549.
2023-02-16 21:25:19 +00:00
Nathan Rajlich
ca81c133b9 [remix] Fix root-level splat path (#9457)
Fixes https://github.com/orgs/vercel/discussions/1545.
2023-02-16 07:32:53 +00:00
Nathan Rajlich
25747a7621 [remix] Support per-page Edge functions and replace "@remix-run/vercel" (#9375)
Adds support for server-side rendered Remix using Edge Functions. This runtime can be enabled on a per-page basis, by adding the following to a page within the `app/routes` directory:

```js
export const config = {
  runtime: 'edge'
};
```

Additionally, this PR further supersedes the `@remix-run/vercel` runtime adapter, because we will always inject our own server entrypoint. So the logic to ensure that package exists in the project's `package.json` has been removed (so this closes #9011). The only requirement is that the Remix project has `@remix-run/node` as a dependency, which is the case for the vanilla Remix template so I think that's a fair assumption.

To make Edge Functions work, we need to ensure that `remix build` is executed with a few specific configuration values in place, so this change wraps the existing `remix.config.js` file and adds our own to make sure those values are in place (and then cleans itself up after the build command is executed).

Finally, the reading of the Remix config logic was simplified by using the `readConfig()` function from the `@remix-run/dev` package, which also includes the routes manifest, so the hacky `vm` running logic to retrieve the manifest was able to be removed.

Closes #8784.
Closes #9011.

---

# To test this out:

1. Ensure that Remix dependencies are running _at least version `1.5.0`_ (which is when `writeReadableStreamToWritable()` was added to `@remix-run/node`).

2. Add the following line of code to any page in your Remix application’s `app/routes/*` directory:
    
    ```jsx
    export const config = { runtime: 'edge' };
    ```
    
3. Set an Environment Variable on your Vercel Project:
    - Name: `VERCEL_CLI_VERSION`
    - Value: `https://vercel-git-update-remix-edge.vercel.sh/tarballs/vercel.tgz`
    
4. Make a deployment, either by running `vercel deploy` in the CLI, or by pushing a Git commit to your repository which has a Vercel Git integration enabled.
2023-02-14 01:01:46 +00:00
Nathan Rajlich
946f7f0bfc [remix] Remove render path (#9365)
Instead of outputting a single SSR function at `/render` path, scan the
build manifest file to determine the proper paths to output the SSR
function at.
2023-02-02 14:29:52 -08:00
Steven
aaceeef604 [tests] Add test for ./examples/remix (#9251)
- Related to #9249
2023-01-18 19:13:55 +00:00
Nathan Rajlich
02ff265074 [remix] Fix config file dynamic import (#9249)
Follow-up to https://github.com/vercel/vercel/pull/8793, which breaks dynamic import of the config file, causing some issues for remix users: https://github.com/orgs/vercel/discussions/1282

The underlying error is `MODULE_NOT_FOUND`.

`import()` should work with `file://` URIs, however, since it's using typescript, the `import` gets compiled to `require()`, which does not support `file://` protocol scheme.

Supersedes https://github.com/vercel/vercel/pull/9248.
2023-01-18 11:24:42 +00:00
Logan McAnsh
74c0b3e1bb [remix] Add support for .cjs and .mjs extensions for "remix.config" (#8793)
Adds support for `remix.config.mjs` and `remix.config.cjs` and
also updates the example/fixtures to the latest version of Remix.

See: https://github.com/remix-run/remix/pull/3675
2023-01-12 19:26:52 -08:00