Commit Graph

53 Commits

Author SHA1 Message Date
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
67fa2f3dd6 [build-utils] Extend Node v16 discontinue date to 2024-06-15 (#10967)
AWS has extended the discontinue date for `nodejs16.x` Lambda runtime, so we will follow suit.
2023-12-18 23:45:45 +00:00
Nathan Rajlich
88da7463ce [build-utils] Remove Node v20 env var check (#10834)
It's safe to remove this env var check, because #10822 makes it explicit on which versions of Node are actually present in the build environment.
2023-11-15 22:04:36 +00:00
Nathan Rajlich
65dec5b7e7 [build-utils] Select Node.js version based on what's available in build-container (#10822)
Makes `getLatestNodeVersion()` and `getSupportedNodeVersion()` (and thus by extension - `getNodeVersion()`) be aware of the available Node.js versions when running inside the build-container. This is to address the situation with the new AL2023 build-container image which has different Node versions installed compared to the existing AL2 build image.

### Project Settings `20.x` with package.json `"engines": "18.x"`

If the Project Settings Node Version is set to `20.x`, but the package.json has `"engines": "18.x"`, then the build will fail like so, because Node 18 is not present on the AL2023 build image:

<img width="1044" alt="Screenshot 2023-11-09 at 1 25 41 PM" src="https://github.com/vercel/vercel/assets/71256/572c544b-6574-4eb1-98f7-787075a60000">

### Project Settings `18.x` with package.json `"engines": "20.x"`

If the Project Settings Node Version is set to `18.x`, but the package.json has `"engines": "20.x"`, then the build will fail like so, because Node 20 is not present on the AL2 build image:

<img width="1042" alt="Screenshot 2023-11-09 at 1 34 43 PM" src="https://github.com/vercel/vercel/assets/71256/c6a2d955-9453-4ef5-a99d-b49a6d9af766">

### Project Settings `18.x` with no package.json `"engines"`

If Project Settings Node Version is set to `18.x`, but the package.json has no "engines" (and thus wants "latest"), then the latest available Node version in the build-container, which would be Node 18.
2023-11-14 23:08:27 +00:00
Nathan Rajlich
0861dc8fbc [build-utils] Add experimental flag to allow Node.js v20 (#10802)
Similar to #8836, but now for Node.js v20.
2023-11-07 13:43:29 +00:00
Trek Glowacki
2f5b0aeeb1 [cli] Update bun detection and add tests for projects with both bunlock.b and yarn.lock files (#10583)
Updates package manager detection to account for two lock files. All other managers will only have the one lock file. Bun, however, may have both a `bun.lockb` _and_ a `yarn.lock` file. To ensure bun is properly detected, the presence of `bun.lockb` with `yarn.lock` must occur before `yarn.lock` so we don't mistake the presence of a `yarn.lock` to mean "Yarn".

This PR also adds a test for this situation in `fs-detectors`. The behavior is currently correct there, but was not tested initially. It is now to avoid future regressions.
2023-09-26 21:11:57 +00:00
Steven
45b73c7e86 [build-utils] Add zero config detection for bun package manager (#10486)
> [!IMPORTANT]  
> This PR will only support Bun as a package manager at build time. 
> Bun will **not** work at runtime with Serverless Functions or Edge
Functions at this time.

- Depends on https://github.com/vercel/api/pull/21869
- Fixes https://github.com/orgs/vercel/discussions/2021
- Closes https://github.com/vercel/vercel/pull/10244
- Related https://github.com/nodejs/corepack/issues/295
- Docs https://bun.sh/docs/install
2023-09-11 17:26:34 -04:00
Zack Tanner
d8bc570f60 [build-utils] add experimentalBypassFor field to Prerender (#10481)
This adds an experimental flag to `Prerender` outputs as a way to programmatically bypass the cache and hit the lambda directly, using a similar interface to `has`. 

(Note: I copied over `HasField` from `@vercel/router-utils` since it wasn't available for import in `build-utils`, but can add it as a dep if that's preferred)

The specific use-case being targeted here relates to https://github.com/vercel/next.js/pull/51534 -- a Next.js page marked static should still be able to initiate server actions.
2023-09-08 23:33:59 +00:00
Nabeel Sulieman
50e04dd858 Add optional experimentalStreamingLambda field for prerender (#10476)
This adds a new `experimentalStreamingLambda` field to Prerender
outputs, allowing references to an optional streaming lambda path.
2023-09-08 11:42:06 -07:00
Nathan Rajlich
8f152a5939 [build-utils] Fix Node 14.x tests (#10355) 2023-08-16 20:59:14 +00:00
Steven
0750517af9 [build-utils] Push back nodejs16.x discontinue date to 2024-02-06 (#10209)
The discontinue date for `nodejs16.x` needs to be pushed back until we can add support for `nodejs20.x`.

Currently `nodejs18.x` can cause problems with native packages that depend on a specific version of glibc so the only solution for that use case is to stay on `nodejs16.x` at this time.


### Related Issues
- https://github.com/orgs/vercel/discussions/3061
- https://github.com/orgs/vercel/discussions/2867
- https://github.com/orgs/vercel/discussions/2258
- https://github.com/orgs/vercel/discussions/2630
- https://github.com/orgs/vercel/discussions/2105
- https://github.com/orgs/vercel/discussions/2596
- https://github.com/orgs/vercel/discussions/2730
2023-07-13 22:47:03 +00:00
Sean Massa
71b9f3a94b Deprecate Node.js 14.x and 16.x with warning (#9976)
Node.js 14 and 16 are being deprecated. This PR will cause a warning when they are used today and an error after August 15.
2023-05-18 19:03:01 +00:00
Nathan Rajlich
954536e681 Use pnpm v8.3.1 (#9853)
Updates our usage of pnpm to version 8.3.1, and updates the lockfile to the newer version 6 format.
2023-04-25 03:53:42 +00:00
Sean Massa
cd09a38c19 [tests] skip recent flakey tests (#9613)
This test has been flakey on mac for a long time.
2023-03-07 17:21:53 +00:00
Steven
b60d3f657a [tests] Update CI to Node.js 16 (#9397)
In an effort to speed up CI, we should update the lowest common
denominator to Node.js 16

Note: In April, Node.js 14 will reach EOL so we can update tsconfig
targets and ship a major semver at that time.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-02-13 15:59:05 -05:00
JJ Kasper
e2105e47b5 [build-utils] Add passQuery field to Prerender (#9388) 2023-02-06 16:57:17 -08:00
Steven
dbea973546 [build-utils][cli] Add env vars for VERCEL_PROJECT_SETTINGS_ (#9332)
This PR adds a few new environment variables for project settings.

This allows frameworks targeting the [Build Output API](https://vercel.com/docs/build-output-api/v3) to read data that is normally only available in through the `config` object when developing a [Builder/Runtime](https://github.com/vercel/vercel/blob/main/DEVELOPING_A_RUNTIME.md).

This will also solve the problem of old Builders/Runtimes that never passed the `config` through to `getNodeVersion()`.

- Related to https://github.com/unjs/nitro/pull/879
2023-01-31 23:27:36 +00:00
Chris Barber
89a15681d5 [build-utils] Rewrite rename() to be more efficient (#9322)
Around 6 months ago, @styfle brought to my attention how `rename()` in build-utils used `reduce()` and could be written better. So, I rewrote it.

Before, the code would create a new `Files` object and copy the contents of the previous `Files` object. This caused heavy garbage collection and memory thrashing.

Instead, I created a single `Files` object, then add the files to it.

Results:

| # Files | Before | After |
|---|---|---|
| 1,000 | 75 ms | 1 ms |
| 10,000 | 10.6 s | 7 ms |
| 20,000 | 44.6 s | 16 ms |
| 30,000 | 105.5 s | 22 ms |
| 100,000 | Too long | 73 ms |
2023-01-27 18:21:59 +00:00
Ethan Arrowood
a008c9c7fe [build-utils] Support empty directory entries for glob() and download() (#9164)
Reopening #9103 since it was reverted.
2023-01-13 12:01:37 -08:00
Ethan Arrowood
9c768b98b7 [tests] Migrate from yarn to pnpm (#9198)
<picture data-single-emoji=":pnpm:" title=":pnpm:"><img class="emoji" src="https://single-emoji.vercel.app/api/emoji/eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..4mJzrO94AnSn0Pue.4apgaKtTUdQ-wxNyahjdJj28u8bbXreLoTA8AGqYjLta3MrsFvbo9DsQFth4CoIkBgXFhQ5_BVcKNfYbwLg4bKzyIvItKe4OFS8AzG7Kkicz2kUUZk0.nXyK_PvHzZFGA-MQB6XHfA" alt=":pnpm:" width="20" height="auto" align="absmiddle"></picture> 

yarn has become increasingly more difficult to use as the v1 we rely on no longer receives updates. pnpm is faster and is actively maintained. 

This PR migrates us to pnpm.
2023-01-11 23:35:13 +00:00
Nathan Rajlich
84f93d8af4 [build-utils] Support directory entries in Lambda#createZip() (#9201)
Adds support for empty directory entries in the Lambda `createZip()` function.
2023-01-11 10:21:42 +00:00
Sean Massa
3a68c73496 [build-utils] Revert "Support empty directory entries for glob() and download()" (#9157)
Reverts vercel/vercel#9103

We believe the original PR is the cause of errors like:

> Error: EISDIR: illegal operation on a directory, read
2023-01-03 17:29:27 -05:00
Nathan Rajlich
99e40272cf [build-utils] Support empty directory entries for glob() and download() (#9103)
There are some edge-case situations where a dependency or build process is expecting an empty directory to exist, and this expectation would fail currently because `glob()` does not return directory entries.

So update `glob()` to return entries for empty directories, which are also re-created properly when passed to the `download()` function.
2022-12-21 20:06:14 +00:00
Sean Massa
0bbf826213 [build-utils] make lambda optional in Prerender constructor (#8965)
It turns out that there is [a logic flow](https://github.com/vercel/api/pull/15237/files#diff-54171844caccedbadf06e6f6f408676d4cd200358b55b62ca6f9818e113aeabbL144) in the build container that will not populate `Prerender#lambda` right away. The type error was being ignored with `@ts-expect-error`.

The `Prerender` class needs to handle this case.

---

This will be used in https://github.com/vercel/api/pull/15237
2022-11-28 16:32:50 +00:00
Sean Massa
164d392f56 [build-utils][node][next][remix] add operationType to Lambda (#8887) 2022-11-23 15:50:34 -06:00
Nathan Rajlich
e200bf2ddc [build-utils] Remove Node 18 env var check (#8947)
Node 18 is the new default.
2022-11-18 19:23:25 +00:00
Steven
d42a8a6588 [build-utils] Experimental flag to allow nodejs18.x (#8836)
Add a new experimental flag to allow `nodejs18.x`
2022-11-02 10:56:14 -04:00
JJ Kasper
b388357c0b [build-utils] Fix check for initialHeaders on prerender (#8757)
### Related Issues

x-ref: https://github.com/vercel/vercel/pull/8743

### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [ ] The code changed/added as part of this PR has been covered with
tests
- [ ] All tests pass locally with `yarn test-unit`

#### Code Review

- [ ] This PR has a concise title and thorough description useful to a
reviewer
- [ ] Issue from task tracker has a link to this PR
2022-10-20 15:48:01 -07:00
Steven
244554ab1b [tests] Remove nodejs12.x tests (#8667)
Now that `nodejs12.x` has passed the sunset date, new deployments will fail so we need to update a few tests.

https://vercel.com/changelog/node-js-12-is-being-deprecated
2022-10-03 20:59:05 +00:00
Steven
6f767367e4 [build-utils] Adjust nodejs12.x discontinueDate to Monday (#8638)
The previous date was on a Saturday so lets move it to the following Monday to ensure support tickets are quickly answered.
2022-09-26 22:22:32 +00:00
Steven
e43b968fbe [build-utils] Retry with legacy peer deps on install failure (#8598)
In this PR, we try to detect when npm install fails due to invalid peer deps and retry with `--legacy-peer-deps`.

This is a follow up to PR #8550 that explains more.

Steps to reproduce the npm bug:

```sh
corepack enable npm
echo '{"packageManager":"npm@8.5.5","dependencies":{"swr":"1.3.0","react":"16.8.0"}}' > package.json
npm install --legacy-peer-deps
npm install # works fine now that a lockfile exists
echo '{"packageManager":"npm@8.6.0","dependencies":{"swr":"1.3.0","react":"16.8.0"}}' > package.json
npm install # fails with code ERESOLVE (Conflicting peer dependency)
```
2022-09-21 13:14:21 +00:00
Steven
cea2981512 [tests] Change some runNpmInstall() unit tests to mocks (#8581)
- Closes #8580
2022-09-19 21:30:32 +00:00
Steven
6cad10c899 [build-utils] Replace npm bin with custom implementation (#8483)
This PR removes `npm bin` in favor of a custom implementation since the command will be removed in npm 9.

- Related to https://github.com/npm/statusboard/issues/537
2022-08-30 01:23:34 +00:00
Steven
30fe76a0cf [build-utils] Push back nodejs12.x sunset date (#8355)
This PR pushes back the `nodejs12.x` discontinue date to give more projects a chance to upgrade
2022-08-08 20:46:04 +00:00
Steven
c11527e904 [build-utils] Fix symlink on download (#8288)
Some builders, such as `@vercel/next`, return both the symlinked directory and the resolved file.

When `vc build` iterates over the files to recreate them in `.vercel/output`, it fails with `EEXIST: file already exists` when creating the symlink because it first creates the file `node_modules/<symlink>/package.json` and then attempts to create the symlink `node_modules/<symlink>`.

This happened to work before `vc build` because yazl would accept the symlinked directory instead of the package.json file, so this PR is created to match that behavior.
2022-08-01 23:35:24 +00:00
Steven
1ee9a96a62 [build-utils] Fix package.json and lockfile detection (#8230)
This PR fixes a couple issues where `vercel build` was not correctly detecting the package.json files

```
Error: @vercel/node:test: ERROR: frontend/index.ts(1,12): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
```

It also fixes an issue where all deployments were incorrectly detecting the lock file because the lock file doesn't always live in the same directory as the package.json file. So we need to do 2 passes: one to find the nearest package.json and one to find the nearest lock file.
2022-07-25 16:29:24 +00:00
Sean Massa
2a45805b26 [tests] increase timeout for test that's failing on windows (#8221)
This test sometimes times out on Windows. When it succeeds, it takes ~6 seconds. When it fails, we don't know how long it would have taken, but the current timeout is 7 seconds. Let's try 10 seconds and see if that's better.
2022-07-22 08:52:28 +00:00
Steven
4f4a42813f [build-utils][node][python][ruby] Update error message for EOL runtimes (#8167)
This PR updates the error message when the runtime version detected is EOL
2022-07-15 15:38:38 -04:00
Steven
ee4d772ae9 [tests] Add retry to npm tests (#8133)
These tests fail occasionally on GH Actions due to flakey network IO, so this PR adds retry logic.

https://github.com/vercel/vercel/runs/7289659634?check_suite_focus=true#step:13:328
2022-07-11 21:39:10 +00:00
Steven
51fe09d5e9 [build-utils][fs-detectors][cli] MAJOR: move some of build-utils into new fs-detectors (#8054)
The `@vercel/build-utils` package was meant be shared functions necessary for writing a Vercel Builder (aka Runtime).

This package has since bloated into the catch-all package for anything that wasn't a Builder.

This PR removes the bloat in favor of a new package, `@vercel/fs-detectors`. It also removes the need for `@vercel/build-utils` to have a dependency on `@vercel/frameworks`.

- Related to #7951
2022-06-30 21:14:07 +00:00
Steven
b92aeac84d [build-utils] Fix warning for package.json engines (#7900)
This PR updates the way we handle warning for engines.node in `package.json`.

- should not warn when the engines version satisfies the project settings (previously it was an exact match)
- should warn when engines version is exact instead of range since it cannot be satisfied exactly
- should warn when engines version is greater than since it might introduce breaking changes for a future node.js version
2022-06-01 00:15:00 +00:00
Steven
54dfe747e2 [build-utils] Deprecate Node.js 12.x with warning (#7779)
Node.js 12 reached EOL April 2022 so its time to notify customers.

This PR will warn starting today and then error once the discontinue date is reached in a couple months.
2022-05-16 16:06:39 +00:00
Steven
3b9a9878bc [build-utils] Add Node.js 16.x (#7772)
Add support for Node.js 16

- Related to https://github.com/aws/aws-lambda-base-images/issues/14#issuecomment-1120864028
2022-05-09 10:13:11 -04:00
Steven
eab2e229dc [build-utils] Add warning for experimental Node.js (#7717) 2022-04-25 12:49:04 -04:00
Steven
57916bb712 [build-utils] Add env var ENABLE_EXPERIMENTAL_NODE16 (#7489)
This PR uses an environment variable since this feature is not available to all accounts yet.
2022-04-25 11:07:16 -04:00
Nathan Rajlich
d62461d952 [build-utils] Only allow runNpmInstall() to run once per package.json (#7671)
Adds a best-effort optimization to only run `npm install` once per
`pacakge.json` file. This will save a lot of time in the single-sandbox
build world (i.e. `vc build`).
2022-04-12 09:09:10 -07:00
Sean Massa
a82f117217 [build-utils] Preserve symlinks for FileRef and FileBlob types in download() (#7534)
Co-authored-by: Nathan Rajlich <n@n8.io>
2022-03-09 16:41:03 -06:00
Jared Palmer
6ccb4354f9 Add support for PNPM (#6834)
Add support for `pnpm` as well as new fixtures for `pnpm` with and without workspaces

#### Tests

- [x] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit && yarn test-integration-once` 

#### Code Review

- [x] This PR has a concise title and thorough description useful to a reviewer
- [x] Issue from task tracker has a link to this PR
2022-03-01 22:34:39 +00:00
Steven
783144e0d6 [test] Skip runPackageJsonScript() on windows and macOS (#7176)
This test is flaky on windows and macOS but its never actually run on those OS's so there is no need to test it there.
2021-12-10 18:37:49 -05:00
Nathan Rajlich
0533cfd566 [build-utils] Fix test name 2021-08-06 12:48:58 -07:00