Compare commits

..

7 Commits

Author SHA1 Message Date
Steven
053c185481 Publish Stable
- vercel@28.4.6
 - @vercel/client@12.2.11
 - @vercel/next@3.2.2
2022-10-03 10:07:07 -04:00
JJ Kasper
8805b586ea [next] Allow revalidating ISR 404 path itself (#8663)
### Related Issues

Fixes: https://vercel.slack.com/archives/C03S8ED1DKM/p1664521958768189

### 📋 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-02 13:09:24 +00:00
Chris Barber
681070ffa0 [tests] Adding test for next builder OS path separator for serverless file refs (#8661)
Here's the test for https://github.com/vercel/vercel/pull/8657.

#### 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`

#### 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-09-30 18:29:39 +00:00
Chris Barber
362b17d60a [next] Use OS path separator to match serverless file references (#8657)
When running `vc build` for a Next.js app, the Next builder will execute the server build which performs several steps. One of the steps is to trace each serverless function for any referenced files, then the raw list of files is scrubbed and filtered. The filtering uses OS specific file path comparisons to see if a file is of interest. Since it's comparing OS specific paths, we need to use OS specific path separators.

During testing on Windows, the traced serverless functions file list was always empty.

### 📋 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
- [x] 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-09-30 15:25:33 +00:00
JJ Kasper
c7c9b1a791 [next] Update RSC header in has routes (#8651)
### Related Issues

x-ref: https://github.com/vercel/next.js/pull/40979

### 📋 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-09-28 13:24:01 -07:00
Nathan Rajlich
c42f309463 [cli] Print upload progress in increments of 25% when non-TTY (#8650)
When running `vc deploy` in a non-TTY context (i.e. CI), limit the number of progress updates to 25% increments (for a total of 5).

```
Uploading [--------------------] (0.0B/71.9MB)
Uploading [=====---------------] (18.0MB/71.9MB)
Uploading [==========----------] (36.0MB/71.9MB)
Uploading [===============-----] (54.0MB/71.9MB)
Uploading [====================] (71.9MB/71.9MB)
```

This avoids spamming the user logs with many progress updates.
2022-09-28 19:33:33 +00:00
Sean Massa
a0ead28369 [tests] replace spinner messages with normal output during tests (#8634)
Convert spinner output to simple prints during test runs. This makes it easier to write tests against the output of commands.
2022-09-28 17:52:40 +00:00
18 changed files with 276 additions and 68 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "vercel",
"version": "28.4.5",
"version": "28.4.6",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Vercel",
@@ -44,7 +44,7 @@
"@vercel/build-utils": "5.5.3",
"@vercel/go": "2.2.11",
"@vercel/hydrogen": "0.0.24",
"@vercel/next": "3.2.1",
"@vercel/next": "3.2.2",
"@vercel/node": "2.5.21",
"@vercel/python": "3.1.20",
"@vercel/redwood": "1.0.29",
@@ -95,7 +95,7 @@
"@types/which": "1.3.2",
"@types/write-json-file": "2.2.1",
"@types/yauzl-promise": "2.1.0",
"@vercel/client": "12.2.10",
"@vercel/client": "12.2.11",
"@vercel/frameworks": "1.1.6",
"@vercel/fs-detectors": "3.4.1",
"@vercel/fun": "1.0.4",

View File

@@ -115,29 +115,39 @@ export default async function processDeployment({
.reduce((a: number, b: number) => a + b, 0);
const totalSizeHuman = bytes.format(missingSize, { decimalPlaces: 1 });
uploads.forEach((e: any) =>
e.on('progress', () => {
const uploadedBytes = uploads.reduce((acc: number, e: any) => {
return acc + e.bytesUploaded;
}, 0);
// When stderr is not a TTY then we only want to
// print upload progress in 25% increments
let nextStep = 0;
const stepSize = now._client.stderr.isTTY ? 0 : 0.25;
const bar = progress(uploadedBytes, missingSize);
if (!bar || uploadedBytes === missingSize) {
output.spinner(deployingSpinnerVal, 0);
} else {
const uploadedHuman = bytes.format(uploadedBytes, {
decimalPlaces: 1,
fixedDecimals: true,
});
const updateProgress = () => {
const uploadedBytes = uploads.reduce((acc: number, e: any) => {
return acc + e.bytesUploaded;
}, 0);
const bar = progress(uploadedBytes, missingSize);
if (!bar) {
output.spinner(deployingSpinnerVal, 0);
} else {
const uploadedHuman = bytes.format(uploadedBytes, {
decimalPlaces: 1,
fixedDecimals: true,
});
const percent = uploadedBytes / missingSize;
if (percent >= nextStep) {
output.spinner(
`Uploading ${chalk.reset(
`[${bar}] (${uploadedHuman}/${totalSizeHuman})`
)}`,
0
);
nextStep += stepSize;
}
})
);
}
};
uploads.forEach((e: any) => e.on('progress', updateProgress));
updateProgress();
}
if (event.type === 'file-uploaded') {

View File

@@ -4,6 +4,8 @@ import wait, { StopSpinner } from './wait';
import type { WritableTTY } from '../../types';
import { errorToString } from '../is-error';
const IS_TEST = process.env.NODE_ENV === 'test';
export interface OutputOptions {
debug?: boolean;
}
@@ -108,12 +110,15 @@ export class Output {
};
spinner = (message: string, delay: number = 300): void => {
this.spinnerMessage = message;
if (this.debugEnabled) {
this.debug(`Spinner invoked (${message}) with a ${delay}ms delay`);
return;
}
if (this.stream.isTTY) {
if (IS_TEST || !this.stream.isTTY) {
this.print(`${message}\n`);
} else {
this.spinnerMessage = message;
if (this._spinner) {
this._spinner.text = message;
} else {
@@ -125,8 +130,6 @@ export class Output {
delay
);
}
} else {
this.print(`${message}\n`);
}
};

View File

@@ -1,4 +1,7 @@
import bytes from 'bytes';
import fs from 'fs-extra';
import { join } from 'path';
import { randomBytes } from 'crypto';
import { fileNameSymbol } from '@vercel/client';
import { client } from '../../mocks/client';
import deploy from '../../../src/commands/deploy';
@@ -199,4 +202,119 @@ describe('deploy', () => {
process.chdir(originalCwd);
}
});
it('should upload missing files', async () => {
const cwd = setupFixture('commands/deploy/archive');
const originalCwd = process.cwd();
// Add random 1mb file
await fs.writeFile(join(cwd, 'data'), randomBytes(bytes('1mb')));
try {
process.chdir(cwd);
const user = useUser();
useTeams('team_dummy');
useProject({
...defaultProject,
name: 'archive',
id: 'archive',
});
let body: any;
let fileUploaded = false;
client.scenario.post(`/v13/deployments`, (req, res) => {
if (fileUploaded) {
body = req.body;
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
});
} else {
const sha = req.body.files[0].sha;
res.status(400).json({
error: {
code: 'missing_files',
message: 'Missing files',
missing: [sha],
},
});
}
});
client.scenario.post('/v2/files', (req, res) => {
// Wait for file to be finished uploading
req.on('data', () => {
// Noop
});
req.on('end', () => {
fileUploaded = true;
res.end();
});
});
client.scenario.get(`/v13/deployments/dpl_archive_test`, (req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
});
client.scenario.get(
`/v10/now/deployments/dpl_archive_test`,
(req, res) => {
res.json({
creator: {
uid: user.id,
username: user.username,
},
id: 'dpl_archive_test',
readyState: 'READY',
aliasAssigned: true,
alias: [],
});
}
);
// When stderr is not a TTY we expect 5 progress lines to be printed
client.stderr.isTTY = false;
client.setArgv('deploy', '--archive=tgz');
const uploadingLines: string[] = [];
client.stderr.on('data', data => {
if (data.startsWith('Uploading [')) {
uploadingLines.push(data);
}
});
client.stderr.resume();
const exitCode = await deploy(client);
expect(exitCode).toEqual(0);
expect(body?.files?.length).toEqual(1);
expect(body?.files?.[0].file).toEqual('.vercel/source.tgz');
expect(uploadingLines.length).toEqual(5);
expect(
uploadingLines[0].startsWith('Uploading [--------------------]')
).toEqual(true);
expect(
uploadingLines[1].startsWith('Uploading [=====---------------]')
).toEqual(true);
expect(
uploadingLines[2].startsWith('Uploading [==========----------]')
).toEqual(true);
expect(
uploadingLines[3].startsWith('Uploading [===============-----]')
).toEqual(true);
expect(
uploadingLines[4].startsWith('Uploading [====================]')
).toEqual(true);
} finally {
process.chdir(originalCwd);
}
});
});

View File

@@ -38,11 +38,11 @@ describe('list', () => {
await list(client);
const output = await readOutputStream(client, 4);
const output = await readOutputStream(client, 6);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseSpacedTableRow(output.split('\n')[3]);
const data: string[] = parseSpacedTableRow(output.split('\n')[4]);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[2]);
const header: string[] = parseSpacedTableRow(output.split('\n')[5]);
const data: string[] = parseSpacedTableRow(output.split('\n')[6]);
data.shift();
expect(org).toEqual(team[0].slug);
@@ -81,11 +81,11 @@ describe('list', () => {
client.setArgv('-S', user.username);
await list(client);
const output = await readOutputStream(client, 4);
const output = await readOutputStream(client, 6);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseSpacedTableRow(output.split('\n')[3]);
const data: string[] = parseSpacedTableRow(output.split('\n')[4]);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[2]);
const header: string[] = parseSpacedTableRow(output.split('\n')[5]);
const data: string[] = parseSpacedTableRow(output.split('\n')[6]);
data.shift();
expect(org).toEqual(user.username);
@@ -116,11 +116,11 @@ describe('list', () => {
client.setArgv(deployment.name);
await list(client);
const output = await readOutputStream(client, 4);
const output = await readOutputStream(client, 6);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseSpacedTableRow(output.split('\n')[3]);
const data: string[] = parseSpacedTableRow(output.split('\n')[4]);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[2]);
const header: string[] = parseSpacedTableRow(output.split('\n')[5]);
const data: string[] = parseSpacedTableRow(output.split('\n')[6]);
data.shift();
expect(org).toEqual(teamSlug || team[0].slug);

View File

@@ -22,10 +22,10 @@ describe('project', () => {
client.setArgv('project', 'ls');
await projects(client);
const output = await readOutputStream(client, 2);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseSpacedTableRow(output.split('\n')[2]);
const data: string[] = parseSpacedTableRow(output.split('\n')[3]);
const output = await readOutputStream(client, 3);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[1]);
const header: string[] = parseSpacedTableRow(output.split('\n')[3]);
const data: string[] = parseSpacedTableRow(output.split('\n')[4]);
data.pop();
expect(org).toEqual(user.username);
@@ -47,10 +47,10 @@ describe('project', () => {
client.setArgv('project', 'ls');
await projects(client);
const output = await readOutputStream(client, 2);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[0]);
const header: string[] = parseSpacedTableRow(output.split('\n')[2]);
const data: string[] = parseSpacedTableRow(output.split('\n')[3]);
const output = await readOutputStream(client, 3);
const { org } = pluckIdentifiersFromDeploymentList(output.split('\n')[1]);
const header: string[] = parseSpacedTableRow(output.split('\n')[3]);
const data: string[] = parseSpacedTableRow(output.split('\n')[4]);
data.pop();
expect(org).toEqual(user.username);

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/client",
"version": "12.2.10",
"version": "12.2.11",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"homepage": "https://vercel.com",

View File

@@ -1,4 +1,5 @@
import { Agent } from 'https';
import http from 'http';
import https from 'https';
import { Readable } from 'stream';
import { EventEmitter } from 'events';
import retry from 'async-retry';
@@ -78,7 +79,9 @@ export async function* upload(
debug('Building an upload list...');
const semaphore = new Sema(50, { capacity: 50 });
const agent = new Agent({ keepAlive: true });
const agent = apiUrl?.startsWith('https://')
? new https.Agent({ keepAlive: true })
: new http.Agent({ keepAlive: true });
shas.forEach((sha, index) => {
const uploadProgress = uploads[index];

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/next",
"version": "3.2.1",
"version": "3.2.2",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",

View File

@@ -633,7 +633,7 @@ export async function serverBuild({
const curPagesDir = isAppPath && appDir ? appDir : pagesDir;
const pageDir = path.dirname(path.join(curPagesDir, originalPagePath));
const normalizedBaseDir = `${baseDir}${
baseDir.endsWith('/') ? '' : '/'
baseDir.endsWith(path.sep) ? '' : path.sep
}`;
files.forEach((file: string) => {
const absolutePath = path.join(pageDir, file);
@@ -1134,7 +1134,7 @@ export async function serverBuild({
if (appPathRoutesManifest) {
// create .rsc variant for app lambdas and edge functions
// to match prerenders so we can route the same when the
// __flight__ header is present
// __rsc__ header is present
const edgeFunctions = middleware.edgeFunctions;
for (let route of Object.values(appPathRoutesManifest)) {
@@ -1343,6 +1343,12 @@ export async function serverBuild({
.join('|')})?[/]?404/?`,
status: 404,
continue: true,
missing: [
{
type: 'header',
key: 'x-prerender-revalidate',
},
],
},
]
: [
@@ -1350,6 +1356,12 @@ export async function serverBuild({
src: path.posix.join('/', entryDirectory, '404/?'),
status: 404,
continue: true,
missing: [
{
type: 'header',
key: 'x-prerender-revalidate',
},
],
},
]),
@@ -1393,7 +1405,7 @@ export async function serverBuild({
has: [
{
type: 'header',
key: '__flight__',
key: '__rsc__',
},
],
dest: path.posix.join('/', entryDirectory, '/$1.rsc'),

View File

@@ -1698,7 +1698,6 @@ export const onPrerenderRoute =
const {
appDir,
pagesDir,
hasPages404,
static404Page,
entryDirectory,
prerenderManifest,
@@ -1896,11 +1895,9 @@ export const onPrerenderRoute =
});
}
// If revalidate isn't enabled we force the /404 route to be static
// to match next start behavior otherwise getStaticProps would be
// recalled for each 404 URL path since Prerender is cached based
// on the URL path
if (!canUsePreviewMode || (hasPages404 && routeKey === '/404')) {
// if preview mode/On-Demand ISR can't be leveraged
// we can output pure static outputs instead of prerenders
if (!canUsePreviewMode) {
htmlFsRef.contentType = htmlContentType;
prerenders[outputPathPage] = htmlFsRef;
prerenders[outputPathData] = jsonFsRef;

View File

@@ -15,7 +15,7 @@
"path": "/dashboard",
"status": 200,
"headers": {
"__flight__": "1"
"__rsc__": "1"
},
"mustContain": "M1:{",
"mustNotContain": "<html"

View File

@@ -1,7 +1,7 @@
/* eslint-env jest */
const path = require('path');
const cheerio = require('cheerio');
const { deployAndTest, check, waitFor } = require('../../utils');
const { deployAndTest, check } = require('../../utils');
const fetch = require('../../../../../test/lib/deployment/fetch-retry');
async function checkForChange(url, initialValue, getNewValue) {
@@ -141,4 +141,30 @@ describe(`${__dirname.split(path.sep).pop()}`, () => {
expect(preRevalidateRandom).toBeDefined();
expect(preRevalidateRandomData).toBeDefined();
});
it('should revalidate 404 page itself correctly', async () => {
const initial404 = await fetch(`${ctx.deploymentUrl}/404`);
const initial404Html = await initial404.text();
const initial404Props = JSON.parse(
cheerio.load(initial404Html)('#props').text()
);
expect(initial404.status).toBe(404);
expect(initial404Props.is404).toBe(true);
const revalidateRes = await fetch(
`${ctx.deploymentUrl}/api/revalidate?urlPath=/404`
);
expect(revalidateRes.status).toBe(200);
expect(await revalidateRes.json()).toEqual({ revalidated: true });
await check(async () => {
const res = await fetch(`${ctx.deploymentUrl}/404`);
const resHtml = await res.text();
const resProps = JSON.parse(cheerio.load(resHtml)('#props').text());
expect(res.status).toBe(404);
expect(resProps.is404).toBe(true);
expect(resProps.time).not.toEqual(initial404Props.time);
return 'success';
}, 'success');
});
});

View File

@@ -1,3 +1,18 @@
export default function Page() {
return <p>custom 404</p>;
export default function Page(props) {
return (
<>
<p>custom 404</p>
<p id="props">{JSON.stringify(props)}</p>
</>
);
}
export function getStaticProps() {
console.log('pages/404 getStaticProps');
return {
props: {
is404: true,
time: Date.now(),
},
};
}

View File

@@ -36,7 +36,10 @@ it('should build with app-dir correctly', async () => {
);
});
it('should build with app-dir in edg runtime correctly', async () => {
// TODO: re-enable after edge build failure is fixed in Next.js
// Disabled Oct, 1st 2022
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should build with app-dir in edge runtime correctly', async () => {
const { buildResult } = await runBuildLambda(
path.join(__dirname, '../fixtures/00-app-dir-edge')
);
@@ -315,9 +318,9 @@ it('Should build the gip-gsp-404 example', async () => {
expect(routes[handleErrorIdx + 1].dest).toBe('/404');
expect(routes[handleErrorIdx + 1].headers).toBe(undefined);
expect(output['404']).toBeDefined();
expect(output['404'].type).toBe('FileFsRef');
expect(output['404'].type).toBe('Prerender');
expect(output['_next/data/testing-build-id/404.json']).toBeDefined();
expect(output['_next/data/testing-build-id/404.json'].type).toBe('FileFsRef');
expect(output['_next/data/testing-build-id/404.json'].type).toBe('Prerender');
const filePaths = Object.keys(output);
const serverlessError = filePaths.some(filePath => filePath.match(/_error/));
const hasUnderScoreAppStaticFile = filePaths.some(filePath =>

View File

@@ -0,0 +1,3 @@
{
"foo": "bar"
}

View File

@@ -1,7 +1,7 @@
const fs = require('fs-extra');
const ms = require('ms');
const path = require('path');
const { build } = require('../../../../src');
const { build } = require('../../../../dist');
const { FileFsRef } = require('@vercel/build-utils');
jest.setTimeout(ms('6m'));
@@ -12,6 +12,7 @@ describe(`${__dirname.split(path.sep).pop()}`, () => {
'index.test.js',
'next.config.js',
'package.json',
'data/strings.json',
'pages/foo/bar/index.js',
'pages/foo/index.js',
'pages/index.js',
@@ -38,9 +39,15 @@ describe(`${__dirname.split(path.sep).pop()}`, () => {
for (const page of pages) {
expect(output).toHaveProperty(page);
expect(path.resolve(output[page].fsPath)).toEqual(
path.join(pagesDir, `${page}.html`)
);
if (page === 'index') {
const { files, type } = output[page];
expect(type).toEqual('Lambda');
expect(files).toHaveProperty([path.join('data', 'strings.json')]);
} else {
expect(path.resolve(output[page].fsPath)).toEqual(
path.join(pagesDir, `${page}.html`)
);
}
}
for (const route of routes) {

View File

@@ -1,7 +1,18 @@
export default function Page() {
import fs from 'fs';
import path from 'path';
export default function Page({ foo }) {
return (
<>
<p>hello from pages</p>
<p>hello from pages {foo}</p>
</>
);
}
export async function getServerSideProps() {
const dataFile = path.join(process.cwd(), 'data', 'strings.json');
const strings = JSON.parse(fs.readFileSync(dataFile));
return {
props: strings,
};
}