mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 12:57:46 +00:00
Compare commits
6 Commits
vercel@25.
...
@vercel/py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
547e88228e | ||
|
|
9bfb5dd535 | ||
|
|
81ea84fae8 | ||
|
|
fa8bf07be4 | ||
|
|
cc9dce73ad | ||
|
|
bba7cbd411 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/build-utils",
|
||||
"version": "4.2.0",
|
||||
"version": "4.2.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
|
||||
@@ -61,6 +61,13 @@ export interface SpawnOptionsExtended extends SpawnOptions {
|
||||
* Pretty formatted command that is being spawned for logging purposes.
|
||||
*/
|
||||
prettyCommand?: string;
|
||||
|
||||
/**
|
||||
* Returns instead of throwing an error when the process exits with a
|
||||
* non-0 exit code. When relevant, the returned object will include
|
||||
* the error code, stdout and stderr.
|
||||
*/
|
||||
ignoreNon0Exit?: boolean;
|
||||
}
|
||||
|
||||
export function spawnAsync(
|
||||
@@ -79,7 +86,7 @@ export function spawnAsync(
|
||||
|
||||
child.on('error', reject);
|
||||
child.on('close', (code, signal) => {
|
||||
if (code === 0) {
|
||||
if (code === 0 || opts.ignoreNon0Exit) {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
@@ -123,24 +130,24 @@ export function execAsync(
|
||||
|
||||
child.on('error', reject);
|
||||
child.on('close', (code, signal) => {
|
||||
if (code !== 0) {
|
||||
const cmd = opts.prettyCommand
|
||||
? `Command "${opts.prettyCommand}"`
|
||||
: 'Command';
|
||||
|
||||
return reject(
|
||||
new NowBuildError({
|
||||
code: `BUILD_UTILS_EXEC_${code || signal}`,
|
||||
message: `${cmd} exited with ${code || signal}`,
|
||||
})
|
||||
);
|
||||
if (code === 0 || opts.ignoreNon0Exit) {
|
||||
return resolve({
|
||||
code,
|
||||
stdout: Buffer.concat(stdoutList).toString(),
|
||||
stderr: Buffer.concat(stderrList).toString(),
|
||||
});
|
||||
}
|
||||
|
||||
return resolve({
|
||||
code,
|
||||
stdout: Buffer.concat(stdoutList).toString(),
|
||||
stderr: Buffer.concat(stderrList).toString(),
|
||||
});
|
||||
const cmd = opts.prettyCommand
|
||||
? `Command "${opts.prettyCommand}"`
|
||||
: 'Command';
|
||||
|
||||
return reject(
|
||||
new NowBuildError({
|
||||
code: `BUILD_UTILS_EXEC_${code || signal}`,
|
||||
message: `${cmd} exited with ${code || signal}`,
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -166,9 +173,30 @@ export async function execCommand(command: string, options: SpawnOptions = {}) {
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function getNodeBinPath({ cwd }: { cwd: string }) {
|
||||
const { stdout } = await execAsync('npm', ['bin'], { cwd });
|
||||
return stdout.trim();
|
||||
export async function getNodeBinPath({
|
||||
cwd,
|
||||
}: {
|
||||
cwd: string;
|
||||
}): Promise<string | undefined> {
|
||||
const { code, stdout, stderr } = await execAsync('npm', ['bin'], {
|
||||
cwd,
|
||||
prettyCommand: 'npm bin',
|
||||
|
||||
// in some rare cases, we saw `npm bin` exit with a non-0 code, but still
|
||||
// output the right bin path, so we ignore the exit code
|
||||
ignoreNon0Exit: true,
|
||||
});
|
||||
|
||||
const nodeBinPath = stdout.trim();
|
||||
|
||||
if (path.isAbsolute(nodeBinPath)) {
|
||||
return nodeBinPath;
|
||||
}
|
||||
|
||||
throw new NowBuildError({
|
||||
code: `BUILD_UTILS_GET_NODE_BIN_PATH`,
|
||||
message: `Running \`npm bin\` failed to return a valid bin path (code=${code}, stdout=${stdout}, stderr=${stderr})`,
|
||||
});
|
||||
}
|
||||
|
||||
async function chmodPlusX(fsPath: string) {
|
||||
|
||||
29
packages/build-utils/test/unit.exec-async.test.ts
vendored
Normal file
29
packages/build-utils/test/unit.exec-async.test.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { execAsync, NowBuildError } from '../src';
|
||||
|
||||
it('should execute a command', async () => {
|
||||
const { code, stdout, stderr } = await execAsync('echo', ['hello']);
|
||||
|
||||
expect(code).toBe(0);
|
||||
expect(stdout).toContain('hello');
|
||||
expect(stderr).toBe('');
|
||||
});
|
||||
|
||||
it('should throw if the command exits with non-0 code', async () => {
|
||||
await expect(execAsync('find', ['unknown-file'])).rejects.toBeInstanceOf(
|
||||
NowBuildError
|
||||
);
|
||||
});
|
||||
|
||||
it('should return if the command exits with non-0 code and ignoreNon0Exit=true', async () => {
|
||||
const { code, stdout, stderr } = await execAsync('find', ['unknown-file'], {
|
||||
ignoreNon0Exit: true,
|
||||
});
|
||||
|
||||
expect(code).toBe(process.platform === 'win32' ? 2 : 1);
|
||||
expect(stdout).toBe('');
|
||||
expect(stderr).toContain(
|
||||
process.platform === 'win32'
|
||||
? 'Parameter format not correct'
|
||||
: 'No such file or directory'
|
||||
);
|
||||
});
|
||||
21
packages/build-utils/test/unit.spawn-async.test.ts
vendored
Normal file
21
packages/build-utils/test/unit.spawn-async.test.ts
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { spawnAsync, NowBuildError } from '../src';
|
||||
|
||||
it('should execute a command', async () => {
|
||||
// should resolve (it doesn't return anything, so it resolves with "undefined")
|
||||
await expect(spawnAsync('echo', ['hello'])).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it('should throw if the command exits with non-0 code', async () => {
|
||||
await expect(spawnAsync('find', ['unknown-file'])).rejects.toBeInstanceOf(
|
||||
NowBuildError
|
||||
);
|
||||
});
|
||||
|
||||
it('should return if the command exits with non-0 code and ignoreNon0Exit=true', async () => {
|
||||
// should resolve (it doesn't return anything, so it resolves with "undefined")
|
||||
await expect(
|
||||
spawnAsync('find', ['unknown-file'], {
|
||||
ignoreNon0Exit: true,
|
||||
})
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vercel",
|
||||
"version": "25.2.2",
|
||||
"version": "25.2.3",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Vercel",
|
||||
@@ -42,15 +42,15 @@
|
||||
"node": ">= 14"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/go": "2.0.2",
|
||||
"@vercel/next": "3.1.1",
|
||||
"@vercel/node": "2.3.2",
|
||||
"@vercel/python": "3.0.2",
|
||||
"@vercel/redwood": "1.0.3",
|
||||
"@vercel/remix": "1.0.3",
|
||||
"@vercel/ruby": "1.3.10",
|
||||
"@vercel/static-build": "1.0.2",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"@vercel/go": "2.0.3",
|
||||
"@vercel/next": "3.1.2",
|
||||
"@vercel/node": "2.3.3",
|
||||
"@vercel/python": "3.0.3",
|
||||
"@vercel/redwood": "1.0.4",
|
||||
"@vercel/remix": "1.0.4",
|
||||
"@vercel/ruby": "1.3.11",
|
||||
"@vercel/static-build": "1.0.3",
|
||||
"update-notifier": "5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -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.0.2",
|
||||
"@vercel/client": "12.0.3",
|
||||
"@vercel/frameworks": "1.0.2",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@zeit/fun": "0.11.2",
|
||||
|
||||
@@ -10,7 +10,6 @@ import confirm from '../../util/input/confirm';
|
||||
import findAliasByAliasOrId from '../../util/alias/find-alias-by-alias-or-id';
|
||||
|
||||
import { Alias } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import { isValidName } from '../../util/is-valid-name';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
|
||||
@@ -71,7 +70,7 @@ export default async function rm(
|
||||
}
|
||||
|
||||
const removeStamp = stamp();
|
||||
if (!opts['--yes'] && !(await confirmAliasRemove(output, alias))) {
|
||||
if (!opts['--yes'] && !(await confirmAliasRemove(client, alias))) {
|
||||
output.log('Aborted');
|
||||
return 0;
|
||||
}
|
||||
@@ -85,7 +84,7 @@ export default async function rm(
|
||||
return 0;
|
||||
}
|
||||
|
||||
async function confirmAliasRemove(output: Output, alias: Alias) {
|
||||
async function confirmAliasRemove(client: Client, alias: Alias) {
|
||||
const srcUrl = alias.deployment
|
||||
? chalk.underline(alias.deployment.url)
|
||||
: null;
|
||||
@@ -104,7 +103,7 @@ async function confirmAliasRemove(output: Output, alias: Alias) {
|
||||
}
|
||||
);
|
||||
|
||||
output.log(`The following alias will be removed permanently`);
|
||||
output.print(` ${tbl}\n`);
|
||||
return confirm(chalk.red('Are you sure?'), false);
|
||||
client.output.log(`The following alias will be removed permanently`);
|
||||
client.output.print(` ${tbl}\n`);
|
||||
return confirm(client, chalk.red('Are you sure?'), false);
|
||||
}
|
||||
|
||||
@@ -187,6 +187,7 @@ export default async client => {
|
||||
if (cardId) {
|
||||
const label = `Are you sure that you to set this card as the default?`;
|
||||
const confirmation = await promptBool(label, {
|
||||
...client,
|
||||
trailing: '\n',
|
||||
});
|
||||
|
||||
@@ -262,7 +263,7 @@ export default async client => {
|
||||
// typed `vercel billing rm <some-id>`) is valid
|
||||
if (cardId) {
|
||||
const label = `Are you sure that you want to remove this card?`;
|
||||
const confirmation = await promptBool(label);
|
||||
const confirmation = await promptBool(label, client);
|
||||
if (!confirmation) {
|
||||
console.log('Aborted');
|
||||
break;
|
||||
|
||||
@@ -140,6 +140,7 @@ export default async function main(client: Client): Promise<number> {
|
||||
}
|
||||
|
||||
confirmed = await confirm(
|
||||
client,
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull'
|
||||
)} for retrieving them?`,
|
||||
|
||||
@@ -165,7 +165,7 @@ export default async (client: Client) => {
|
||||
const quiet = !isTTY;
|
||||
|
||||
// check paths
|
||||
const pathValidation = await validatePaths(output, paths);
|
||||
const pathValidation = await validatePaths(client, paths);
|
||||
|
||||
if (!pathValidation.valid) {
|
||||
return pathValidation.exitCode;
|
||||
@@ -243,6 +243,7 @@ export default async (client: Client) => {
|
||||
const shouldStartSetup =
|
||||
autoConfirm ||
|
||||
(await confirm(
|
||||
client,
|
||||
`Set up and deploy ${chalk.cyan(`“${toHumanPath(path)}”`)}?`,
|
||||
true
|
||||
));
|
||||
@@ -287,7 +288,7 @@ export default async (client: Client) => {
|
||||
|
||||
if (typeof projectOrNewProjectName === 'string') {
|
||||
newProjectName = projectOrNewProjectName;
|
||||
rootDirectory = await inputRootDirectory(path, output, autoConfirm);
|
||||
rootDirectory = await inputRootDirectory(client, path, autoConfirm);
|
||||
} else {
|
||||
project = projectOrNewProjectName;
|
||||
rootDirectory = project.rootDirectory;
|
||||
@@ -521,7 +522,7 @@ export default async (client: Client) => {
|
||||
}
|
||||
|
||||
const settings = await editProjectSettings(
|
||||
output,
|
||||
client,
|
||||
projectSettings,
|
||||
framework,
|
||||
false,
|
||||
|
||||
@@ -46,7 +46,7 @@ export default async function add(
|
||||
|
||||
const addStamp = stamp();
|
||||
const { domain, data: argData } = parsedParams;
|
||||
const data = await getDNSData(output, argData);
|
||||
const data = await getDNSData(client, argData);
|
||||
if (!data) {
|
||||
output.log(`Aborted`);
|
||||
return 1;
|
||||
|
||||
@@ -87,7 +87,8 @@ export default async function buy(
|
||||
!(await promptBool(
|
||||
`Buy now for ${chalk.bold(`$${price}`)} (${`${period}yr${
|
||||
period > 1 ? 's' : ''
|
||||
}`})?`
|
||||
}`})?`,
|
||||
client
|
||||
))
|
||||
) {
|
||||
return 0;
|
||||
@@ -99,7 +100,7 @@ export default async function buy(
|
||||
: `Auto renew every ${renewalPrice.period} years for ${chalk.bold(
|
||||
`$${price}`
|
||||
)}?`,
|
||||
{ defaultValue: true }
|
||||
{ ...client, defaultValue: true }
|
||||
);
|
||||
|
||||
let buyResult;
|
||||
|
||||
@@ -77,7 +77,8 @@ export default async function move(
|
||||
!(await promptBool(
|
||||
`Are you sure you want to move ${param(domainName)} to ${param(
|
||||
destination
|
||||
)}?`
|
||||
)}?`,
|
||||
client
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
@@ -95,7 +96,8 @@ export default async function move(
|
||||
);
|
||||
if (
|
||||
!(await promptBool(
|
||||
`Are you sure you want to move ${param(domainName)}?`
|
||||
`Are you sure you want to move ${param(domainName)}?`,
|
||||
client
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
|
||||
@@ -92,7 +92,10 @@ export default async function rm(
|
||||
const skipConfirmation = opts['--yes'] || false;
|
||||
if (
|
||||
!skipConfirmation &&
|
||||
!(await promptBool(`Are you sure you want to remove ${param(domainName)}?`))
|
||||
!(await promptBool(
|
||||
`Are you sure you want to remove ${param(domainName)}?`,
|
||||
client
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
return 0;
|
||||
@@ -230,7 +233,7 @@ async function removeDomain(
|
||||
|
||||
if (
|
||||
!skipConfirmation &&
|
||||
!(await promptBool(`Remove conflicts associated with domain?`))
|
||||
!(await promptBool(`Remove conflicts associated with domain?`, client))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
return 0;
|
||||
|
||||
@@ -81,7 +81,8 @@ export default async function transferIn(
|
||||
const shouldTransfer = await promptBool(
|
||||
transferPolicy === 'no-change'
|
||||
? `Transfer now for ${chalk.bold(`$${price}`)}?`
|
||||
: `Transfer now with 1yr renewal for ${chalk.bold(`$${price}`)}?`
|
||||
: `Transfer now with 1yr renewal for ${chalk.bold(`$${price}`)}?`,
|
||||
client
|
||||
);
|
||||
if (!shouldTransfer) {
|
||||
return 0;
|
||||
|
||||
2
packages/cli/src/commands/env/add.ts
vendored
2
packages/cli/src/commands/env/add.ts
vendored
@@ -31,7 +31,7 @@ export default async function add(
|
||||
// improve the way we show inquirer prompts
|
||||
require('../../util/input/patch-inquirer');
|
||||
|
||||
const stdInput = await readStandardInput();
|
||||
const stdInput = await readStandardInput(client.stdin);
|
||||
let [envName, envTargetArg, envGitBranch] = args;
|
||||
|
||||
if (args.length > 3) {
|
||||
|
||||
1
packages/cli/src/commands/env/pull.ts
vendored
1
packages/cli/src/commands/env/pull.ts
vendored
@@ -74,6 +74,7 @@ export default async function pull(
|
||||
exists &&
|
||||
!skipConfirmation &&
|
||||
!(await confirm(
|
||||
client,
|
||||
`Found existing file ${param(filename)}. Do you want to overwrite?`,
|
||||
false
|
||||
))
|
||||
|
||||
1
packages/cli/src/commands/env/rm.ts
vendored
1
packages/cli/src/commands/env/rm.ts
vendored
@@ -104,6 +104,7 @@ export default async function rm(
|
||||
if (
|
||||
!skipConfirmation &&
|
||||
!(await confirm(
|
||||
client,
|
||||
`Removing Environment Variable ${param(env.key)} from ${formatEnvTarget(
|
||||
env
|
||||
)} in Project ${chalk.bold(project.name)}. Are you sure?`,
|
||||
|
||||
@@ -65,7 +65,7 @@ export default async function init(
|
||||
return extractExample(client, name, dir, force, 'v1');
|
||||
}
|
||||
|
||||
const found = await guess(exampleList, name);
|
||||
const found = await guess(client, exampleList, name);
|
||||
|
||||
if (typeof found === 'string') {
|
||||
return extractExample(client, found, dir, force);
|
||||
@@ -194,7 +194,7 @@ function prepareFolder(cwd: string, folder: string, force?: boolean) {
|
||||
/**
|
||||
* Guess which example user try to init
|
||||
*/
|
||||
async function guess(exampleList: string[], name: string) {
|
||||
async function guess(client: Client, exampleList: string[], name: string) {
|
||||
const GuessError = new Error(
|
||||
`No example found for ${chalk.bold(name)}, run ${getCommandName(
|
||||
`init`
|
||||
@@ -208,7 +208,7 @@ async function guess(exampleList: string[], name: string) {
|
||||
const found = didYouMean(name, exampleList, 0.7);
|
||||
|
||||
if (typeof found === 'string') {
|
||||
if (await promptBool(`Did you mean ${chalk.bold(found)}?`)) {
|
||||
if (await promptBool(`Did you mean ${chalk.bold(found)}?`, client)) {
|
||||
return found;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -387,6 +387,8 @@ const main = async () => {
|
||||
// Shared API `Client` instance for all sub-commands to utilize
|
||||
client = new Client({
|
||||
apiUrl,
|
||||
stdin: process.stdin,
|
||||
stdout: process.stdout,
|
||||
output,
|
||||
config,
|
||||
authConfig,
|
||||
|
||||
@@ -385,8 +385,14 @@ export async function* findDirs(
|
||||
}
|
||||
for (const path of paths) {
|
||||
const abs = join(dir, path);
|
||||
const s = await fs.stat(abs);
|
||||
if (s.isDirectory()) {
|
||||
let stat: fs.Stats;
|
||||
try {
|
||||
stat = await fs.lstat(abs);
|
||||
} catch (err: any) {
|
||||
if (err.code === 'ENOENT') continue;
|
||||
throw err;
|
||||
}
|
||||
if (stat.isDirectory()) {
|
||||
if (path === name) {
|
||||
yield relative(root, abs);
|
||||
} else {
|
||||
|
||||
@@ -32,6 +32,8 @@ export interface ClientOptions {
|
||||
argv: string[];
|
||||
apiUrl: string;
|
||||
authConfig: AuthConfig;
|
||||
stdin: NodeJS.ReadStream;
|
||||
stdout: NodeJS.WriteStream;
|
||||
output: Output;
|
||||
config: GlobalConfig;
|
||||
localConfig?: VercelConfig;
|
||||
@@ -45,6 +47,8 @@ export default class Client extends EventEmitter {
|
||||
argv: string[];
|
||||
apiUrl: string;
|
||||
authConfig: AuthConfig;
|
||||
stdin: NodeJS.ReadStream;
|
||||
stdout: NodeJS.WriteStream;
|
||||
output: Output;
|
||||
config: GlobalConfig;
|
||||
localConfig?: VercelConfig;
|
||||
@@ -55,6 +59,8 @@ export default class Client extends EventEmitter {
|
||||
this.argv = opts.argv;
|
||||
this.apiUrl = opts.apiUrl;
|
||||
this.authConfig = opts.authConfig;
|
||||
this.stdin = opts.stdin;
|
||||
this.stdout = opts.stdout;
|
||||
this.output = opts.output;
|
||||
this.config = opts.config;
|
||||
this.localConfig = opts.localConfig;
|
||||
|
||||
@@ -329,6 +329,8 @@ export default class DevServer {
|
||||
): Promise<void> {
|
||||
const name = relative(this.cwd, fsPath);
|
||||
try {
|
||||
await this.getVercelConfig();
|
||||
|
||||
this.files[name] = await FileFsRef.fromFsPath({ fsPath });
|
||||
const extensionless = this.getExtensionlessFile(name);
|
||||
if (extensionless) {
|
||||
|
||||
@@ -2,26 +2,29 @@ import chalk from 'chalk';
|
||||
import { DNSRecordData } from '../../types';
|
||||
import textInput from '../input/text';
|
||||
import promptBool from '../input/prompt-bool';
|
||||
import { Output } from '../output';
|
||||
import Client from '../client';
|
||||
|
||||
const RECORD_TYPES = ['A', 'AAAA', 'ALIAS', 'CAA', 'CNAME', 'MX', 'SRV', 'TXT'];
|
||||
|
||||
export default async function getDNSData(
|
||||
output: Output,
|
||||
client: Client,
|
||||
data: null | DNSRecordData
|
||||
): Promise<DNSRecordData | null> {
|
||||
if (data) {
|
||||
return data;
|
||||
}
|
||||
const { output } = client;
|
||||
|
||||
try {
|
||||
// first ask for type, branch from there
|
||||
const possibleTypes = new Set(RECORD_TYPES);
|
||||
const type = (await textInput({
|
||||
label: `- Record type (${RECORD_TYPES.join(', ')}): `,
|
||||
validateValue: (v: string) =>
|
||||
Boolean(v && possibleTypes.has(v.trim().toUpperCase()))
|
||||
}))
|
||||
const type = (
|
||||
await textInput({
|
||||
label: `- Record type (${RECORD_TYPES.join(', ')}): `,
|
||||
validateValue: (v: string) =>
|
||||
Boolean(v && possibleTypes.has(v.trim().toUpperCase())),
|
||||
})
|
||||
)
|
||||
.trim()
|
||||
.toUpperCase();
|
||||
|
||||
@@ -39,7 +42,7 @@ export default async function getDNSData(
|
||||
target
|
||||
)}.`
|
||||
);
|
||||
return (await verifyData())
|
||||
return (await verifyData(client))
|
||||
? {
|
||||
name,
|
||||
type,
|
||||
@@ -47,8 +50,8 @@ export default async function getDNSData(
|
||||
priority,
|
||||
weight,
|
||||
port,
|
||||
target
|
||||
}
|
||||
target,
|
||||
},
|
||||
}
|
||||
: null;
|
||||
}
|
||||
@@ -61,23 +64,23 @@ export default async function getDNSData(
|
||||
`${mxPriority}`
|
||||
)} ${chalk.cyan(value)}`
|
||||
);
|
||||
return (await verifyData())
|
||||
return (await verifyData(client))
|
||||
? {
|
||||
name,
|
||||
type,
|
||||
value,
|
||||
mxPriority
|
||||
mxPriority,
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
const value = await getTrimmedString(`- ${type} value: `);
|
||||
output.log(`${chalk.cyan(name)} ${chalk.bold(type)} ${chalk.cyan(value)}`);
|
||||
return (await verifyData())
|
||||
return (await verifyData(client))
|
||||
? {
|
||||
name,
|
||||
type,
|
||||
value
|
||||
value,
|
||||
}
|
||||
: null;
|
||||
} catch (error) {
|
||||
@@ -85,13 +88,13 @@ export default async function getDNSData(
|
||||
}
|
||||
}
|
||||
|
||||
async function verifyData() {
|
||||
return promptBool('Is this correct?');
|
||||
async function verifyData(client: Client) {
|
||||
return promptBool('Is this correct?', client);
|
||||
}
|
||||
|
||||
async function getRecordName(type: string) {
|
||||
const input = await textInput({
|
||||
label: `- ${type} name: `
|
||||
label: `- ${type} name: `,
|
||||
});
|
||||
return input === '@' ? '' : input;
|
||||
}
|
||||
@@ -100,14 +103,14 @@ async function getNumber(label: string) {
|
||||
return Number(
|
||||
await textInput({
|
||||
label,
|
||||
validateValue: v => Boolean(v && Number(v))
|
||||
validateValue: v => Boolean(v && Number(v)),
|
||||
})
|
||||
);
|
||||
}
|
||||
async function getTrimmedString(label: string) {
|
||||
const res = await textInput({
|
||||
label,
|
||||
validateValue: v => Boolean(v && v.trim().length > 0)
|
||||
validateValue: v => Boolean(v && v.trim().length > 0),
|
||||
});
|
||||
return res.trim();
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ export default async function purchaseDomainIfAvailable(
|
||||
!(await promptBool(
|
||||
`Buy ${chalk.underline(domain)} for ${chalk.bold(
|
||||
`$${price}`
|
||||
)} (${plural('yr', period, true)})?`
|
||||
)} (${plural('yr', period, true)})?`,
|
||||
client
|
||||
))
|
||||
) {
|
||||
output.print(eraseLines(1));
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
import inquirer from 'inquirer';
|
||||
import Client from '../client';
|
||||
|
||||
export default async function confirm(
|
||||
client: Client,
|
||||
message: string,
|
||||
preferred: boolean
|
||||
): Promise<boolean> {
|
||||
require('./patch-inquirer');
|
||||
|
||||
const answers = await inquirer.prompt({
|
||||
const prompt = inquirer.createPromptModule({
|
||||
input: client.stdin,
|
||||
output: client.stdout,
|
||||
});
|
||||
|
||||
const answers = await prompt({
|
||||
type: 'confirm',
|
||||
name: 'value',
|
||||
message,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import inquirer from 'inquirer';
|
||||
import confirm from './confirm';
|
||||
import chalk from 'chalk';
|
||||
import { Output } from '../output';
|
||||
import frameworkList, { Framework } from '@vercel/frameworks';
|
||||
import Client from '../client';
|
||||
import { isSettingValue } from '../is-setting-value';
|
||||
import { ProjectSettings } from '../../types';
|
||||
|
||||
@@ -22,12 +22,14 @@ const settingKeys = Object.keys(settingMap).sort() as unknown as readonly [
|
||||
export type PartialProjectSettings = Pick<ProjectSettings, ConfigKeys>;
|
||||
|
||||
export default async function editProjectSettings(
|
||||
output: Output,
|
||||
client: Client,
|
||||
projectSettings: PartialProjectSettings | null,
|
||||
framework: Framework | null,
|
||||
autoConfirm: boolean,
|
||||
localConfigurationOverrides: PartialProjectSettings | null
|
||||
): Promise<ProjectSettings> {
|
||||
const { output } = client;
|
||||
|
||||
// Create initial settings object defaulting everything to `null` and assigning what may exist in `projectSettings`
|
||||
const settings: ProjectSettings = Object.assign(
|
||||
{
|
||||
@@ -118,7 +120,7 @@ export default async function editProjectSettings(
|
||||
// Prompt the user if they want to modify any settings not defined by local configuration.
|
||||
if (
|
||||
autoConfirm ||
|
||||
!(await confirm('Want to modify these settings?', false))
|
||||
!(await confirm(client, 'Want to modify these settings?', false))
|
||||
) {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -47,11 +47,16 @@ export default async function inputProject(
|
||||
|
||||
if (!detectedProject) {
|
||||
// did not auto-detect a project to link
|
||||
shouldLinkProject = await confirm(`Link to existing project?`, false);
|
||||
shouldLinkProject = await confirm(
|
||||
client,
|
||||
`Link to existing project?`,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
// auto-detected a project to link
|
||||
if (
|
||||
await confirm(
|
||||
client,
|
||||
`Found project ${chalk.cyan(
|
||||
`“${org.slug}/${detectedProject.name}”`
|
||||
)}. Link to it?`,
|
||||
@@ -63,6 +68,7 @@ export default async function inputProject(
|
||||
|
||||
// user doesn't want to link the auto-detected project
|
||||
shouldLinkProject = await confirm(
|
||||
client,
|
||||
`Link to different existing project?`,
|
||||
true
|
||||
);
|
||||
@@ -73,7 +79,11 @@ export default async function inputProject(
|
||||
let project: Project | ProjectNotFound | null = null;
|
||||
|
||||
while (!project || project instanceof ProjectNotFound) {
|
||||
const answers = await inquirer.prompt({
|
||||
const prompt = inquirer.createPromptModule({
|
||||
input: client.stdin,
|
||||
output: client.stdout,
|
||||
});
|
||||
const answers = await prompt({
|
||||
type: 'input',
|
||||
name: 'existingProjectName',
|
||||
message: `What’s the name of your existing project?`,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import path from 'path';
|
||||
import chalk from 'chalk';
|
||||
import inquirer from 'inquirer';
|
||||
import { Output } from '../output';
|
||||
import { validateRootDirectory } from '../validate-paths';
|
||||
import Client from '../client';
|
||||
|
||||
export async function inputRootDirectory(
|
||||
client: Client,
|
||||
cwd: string,
|
||||
output: Output,
|
||||
autoConfirm = false
|
||||
) {
|
||||
if (autoConfirm) {
|
||||
@@ -15,7 +15,11 @@ export async function inputRootDirectory(
|
||||
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const { rootDirectory } = await inquirer.prompt({
|
||||
const prompt = inquirer.createPromptModule({
|
||||
input: client.stdin,
|
||||
output: client.stdout,
|
||||
});
|
||||
const { rootDirectory } = await prompt({
|
||||
type: 'input',
|
||||
name: 'rootDirectory',
|
||||
message: `In which directory is your code located?`,
|
||||
@@ -38,7 +42,7 @@ export async function inputRootDirectory(
|
||||
|
||||
if (
|
||||
(await validateRootDirectory(
|
||||
output,
|
||||
client.output,
|
||||
cwd,
|
||||
fullPath,
|
||||
'Please choose a different one.'
|
||||
|
||||
@@ -5,21 +5,21 @@ type Options = {
|
||||
defaultValue?: boolean;
|
||||
noChar?: string;
|
||||
resolveChars?: Set<string>;
|
||||
stdin?: NodeJS.ReadStream;
|
||||
stdout?: NodeJS.WriteStream;
|
||||
stdin: NodeJS.ReadStream;
|
||||
stdout: NodeJS.WriteStream;
|
||||
trailing?: string;
|
||||
yesChar?: string;
|
||||
};
|
||||
|
||||
export default async function promptBool(label: string, options: Options = {}) {
|
||||
export default async function promptBool(label: string, options: Options) {
|
||||
const {
|
||||
stdin,
|
||||
stdout,
|
||||
defaultValue = false,
|
||||
abortSequences = new Set(['\u0003']),
|
||||
resolveChars = new Set(['\r']),
|
||||
yesChar = 'y',
|
||||
noChar = 'n',
|
||||
stdin = process.stdin,
|
||||
stdout = process.stdout,
|
||||
trailing = '',
|
||||
} = options;
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
export default async function readStandardInput(): Promise<string> {
|
||||
export default async function readStandardInput(
|
||||
stdin: NodeJS.ReadStream
|
||||
): Promise<string> {
|
||||
return new Promise<string>(resolve => {
|
||||
setTimeout(() => resolve(''), 500);
|
||||
|
||||
if (process.stdin.isTTY) {
|
||||
if (stdin.isTTY) {
|
||||
// found tty so we know there is nothing piped to stdin
|
||||
resolve('');
|
||||
} else {
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.once('data', resolve);
|
||||
stdin.setEncoding('utf8');
|
||||
stdin.once('data', resolve);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ export default async function setupAndLink(
|
||||
const shouldStartSetup =
|
||||
autoConfirm ||
|
||||
(await confirm(
|
||||
client,
|
||||
`${setupMsg} ${chalk.cyan(`“${toHumanPath(path)}”`)}?`,
|
||||
true
|
||||
));
|
||||
@@ -120,7 +121,7 @@ export default async function setupAndLink(
|
||||
|
||||
if (typeof projectOrNewProjectName === 'string') {
|
||||
newProjectName = projectOrNewProjectName;
|
||||
rootDirectory = await inputRootDirectory(path, output, autoConfirm);
|
||||
rootDirectory = await inputRootDirectory(client, path, autoConfirm);
|
||||
} else {
|
||||
const project = projectOrNewProjectName;
|
||||
|
||||
@@ -224,7 +225,7 @@ export default async function setupAndLink(
|
||||
const { projectSettings, framework } = deployment;
|
||||
|
||||
settings = await editProjectSettings(
|
||||
output,
|
||||
client,
|
||||
projectSettings,
|
||||
framework,
|
||||
autoConfirm,
|
||||
|
||||
@@ -14,7 +14,7 @@ export default async function reauthenticate(
|
||||
client.output.log(
|
||||
`You must re-authenticate with SAML to use ${bold(error.scope)} scope.`
|
||||
);
|
||||
if (await confirm(`Log in with SAML?`, true)) {
|
||||
if (await confirm(client, `Log in with SAML?`, true)) {
|
||||
return doSamlLogin(client, error.teamId);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -5,6 +5,7 @@ import chalk from 'chalk';
|
||||
import { homedir } from 'os';
|
||||
import confirm from './input/confirm';
|
||||
import toHumanPath from './humanize-path';
|
||||
import Client from './client';
|
||||
|
||||
const stat = promisify(lstatRaw);
|
||||
|
||||
@@ -51,9 +52,11 @@ export async function validateRootDirectory(
|
||||
}
|
||||
|
||||
export default async function validatePaths(
|
||||
output: Output,
|
||||
client: Client,
|
||||
paths: string[]
|
||||
): Promise<{ valid: true; path: string } | { valid: false; exitCode: number }> {
|
||||
const { output } = client;
|
||||
|
||||
// can't deploy more than 1 path
|
||||
if (paths.length > 1) {
|
||||
output.print(`${chalk.red('Error!')} Can't deploy more than one path.\n`);
|
||||
@@ -85,6 +88,7 @@ export default async function validatePaths(
|
||||
// ask confirmation if the directory is home
|
||||
if (path === homedir()) {
|
||||
const shouldDeployHomeDirectory = await confirm(
|
||||
client,
|
||||
`You are deploying your home directory. Do you want to continue?`,
|
||||
false
|
||||
);
|
||||
|
||||
3
packages/cli/test/dev/fixtures/no-api/vercel.json
Normal file
3
packages/cli/test/dev/fixtures/no-api/vercel.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"version": 2
|
||||
}
|
||||
@@ -1,7 +1,17 @@
|
||||
// eslint-disable-next-line
|
||||
import path from 'path';
|
||||
import { join } from 'path';
|
||||
import ms from 'ms';
|
||||
import fs, { mkdirp } from 'fs-extra';
|
||||
|
||||
const { exec, fixture, testFixture, testFixtureStdio } = require('./utils.js');
|
||||
const {
|
||||
exec,
|
||||
fetch,
|
||||
fixture,
|
||||
sleep,
|
||||
testFixture,
|
||||
testFixtureStdio,
|
||||
validateResponseHeaders,
|
||||
} = require('./utils.js');
|
||||
|
||||
test('[vercel dev] validate redirects', async () => {
|
||||
const directory = fixture('invalid-redirects');
|
||||
@@ -334,3 +344,44 @@ test(
|
||||
await testPath(200, '/', /A simple deployment with the Vercel API!/m);
|
||||
})
|
||||
);
|
||||
|
||||
test(
|
||||
'[vercel dev] add a `api/fn.ts` when `api` does not exist at startup`',
|
||||
testFixtureStdio('no-api', async (_testPath: any, port: any) => {
|
||||
const directory = fixture('no-api');
|
||||
const apiDir = join(directory, 'api');
|
||||
|
||||
try {
|
||||
{
|
||||
const response = await fetch(`http://localhost:${port}/api/new-file`);
|
||||
validateResponseHeaders(response);
|
||||
expect(response.status).toBe(404);
|
||||
}
|
||||
|
||||
const fileContents = `
|
||||
export const config = {
|
||||
runtime: 'experimental-edge'
|
||||
}
|
||||
|
||||
export default async function edge(request, event) {
|
||||
return new Response('from new file');
|
||||
}
|
||||
`;
|
||||
|
||||
await mkdirp(apiDir);
|
||||
await fs.writeFile(join(apiDir, 'new-file.js'), fileContents);
|
||||
|
||||
// Wait until file events have been processed
|
||||
await sleep(ms('1s'));
|
||||
|
||||
{
|
||||
const response = await fetch(`http://localhost:${port}/api/new-file`);
|
||||
validateResponseHeaders(response);
|
||||
const body = await response.text();
|
||||
expect(body.trim()).toBe('from new file');
|
||||
}
|
||||
} finally {
|
||||
await fs.remove(apiDir);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import chalk from 'chalk';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createServer, Server } from 'http';
|
||||
import express, { Express, Router } from 'express';
|
||||
import listen from 'async-listen';
|
||||
@@ -23,10 +24,13 @@ export class MockClient extends Client {
|
||||
// Gets populated in `startMockServer()`
|
||||
apiUrl: '',
|
||||
authConfig: {},
|
||||
stdin: new PassThrough(),
|
||||
stdout: new PassThrough(),
|
||||
output: new Output(),
|
||||
config: {},
|
||||
localConfig: {},
|
||||
});
|
||||
|
||||
this.mockOutput = jest.fn();
|
||||
|
||||
this.app = express();
|
||||
@@ -53,6 +57,12 @@ export class MockClient extends Client {
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.stdin = new PassThrough();
|
||||
this.stdin.isTTY = true;
|
||||
|
||||
this.stdout = new PassThrough();
|
||||
this.stdout.isTTY = true;
|
||||
|
||||
this.output = new Output();
|
||||
this.mockOutput = jest.fn();
|
||||
this.output.print = s => {
|
||||
|
||||
25
packages/cli/test/unit/mock.test.ts
Normal file
25
packages/cli/test/unit/mock.test.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import confirm from '../../src/util/input/confirm';
|
||||
import { client } from '../mocks/client';
|
||||
|
||||
describe('MockClient', () => {
|
||||
it('should mock `confirm()`', async () => {
|
||||
// true
|
||||
let confirmedPromise = confirm(client, 'Do the thing?', false);
|
||||
|
||||
client.stdin.write('yes\n');
|
||||
|
||||
client.stdout.setEncoding('utf8');
|
||||
client.stdout.on('data', d => console.log({ d }));
|
||||
|
||||
let confirmed = await confirmedPromise;
|
||||
expect(confirmed).toEqual(true);
|
||||
|
||||
// false
|
||||
confirmedPromise = confirm(client, 'Do the thing?', false);
|
||||
|
||||
client.stdin.write('no\n');
|
||||
|
||||
confirmed = await confirmedPromise;
|
||||
expect(confirmed).toEqual(false);
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,6 @@
|
||||
import { Framework, frameworks } from '@vercel/frameworks';
|
||||
import editProjectSettings from '../../../../src/util/input/edit-project-settings';
|
||||
import { Output } from '../../../../src/util/output';
|
||||
|
||||
let output: Output;
|
||||
|
||||
beforeEach(() => {
|
||||
output = new Output();
|
||||
output.print = jest.fn();
|
||||
});
|
||||
import { client } from '../../../mocks/client';
|
||||
|
||||
const otherFramework = frameworks.find(
|
||||
fwk => fwk.name === 'Other'
|
||||
@@ -20,7 +13,7 @@ describe('editProjectSettings', () => {
|
||||
describe('with no settings, "Other" framework, and no overrides provided', () => {
|
||||
test('should default all settings to `null` and print user default framework settings', async () => {
|
||||
const settings = await editProjectSettings(
|
||||
output,
|
||||
client,
|
||||
null,
|
||||
otherFramework,
|
||||
true,
|
||||
@@ -34,22 +27,14 @@ describe('editProjectSettings', () => {
|
||||
installCommand: null,
|
||||
outputDirectory: null,
|
||||
});
|
||||
expect((output.print as jest.Mock).mock.calls.length).toBe(5);
|
||||
expect((output.print as jest.Mock).mock.calls[0][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls.length).toBe(5);
|
||||
expect(client.mockOutput.mock.calls[0][0]).toMatch(
|
||||
/No framework detected. Default Project Settings:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[1][0]).toMatch(
|
||||
/Build Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[2][0]).toMatch(
|
||||
/Development Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[3][0]).toMatch(
|
||||
/Install Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[4][0]).toMatch(
|
||||
/Output Directory/
|
||||
);
|
||||
expect(client.mockOutput.mock.calls[1][0]).toMatch(/Build Command/);
|
||||
expect(client.mockOutput.mock.calls[2][0]).toMatch(/Development Command/);
|
||||
expect(client.mockOutput.mock.calls[3][0]).toMatch(/Install Command/);
|
||||
expect(client.mockOutput.mock.calls[4][0]).toMatch(/Output Directory/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -63,29 +48,21 @@ describe('editProjectSettings', () => {
|
||||
outputDirectory: 'OUTPUT_DIRECTORY',
|
||||
};
|
||||
const settings = await editProjectSettings(
|
||||
output,
|
||||
client,
|
||||
projectSettings,
|
||||
otherFramework,
|
||||
true,
|
||||
null
|
||||
);
|
||||
expect(settings).toStrictEqual({ ...projectSettings, framework: null });
|
||||
expect((output.print as jest.Mock).mock.calls.length).toBe(5);
|
||||
expect((output.print as jest.Mock).mock.calls[0][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls.length).toBe(5);
|
||||
expect(client.mockOutput.mock.calls[0][0]).toMatch(
|
||||
/No framework detected. Default Project Settings:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[1][0]).toMatch(
|
||||
/Build Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[2][0]).toMatch(
|
||||
/Development Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[3][0]).toMatch(
|
||||
/Install Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[4][0]).toMatch(
|
||||
/Output Directory/
|
||||
);
|
||||
expect(client.mockOutput.mock.calls[1][0]).toMatch(/Build Command/);
|
||||
expect(client.mockOutput.mock.calls[2][0]).toMatch(/Development Command/);
|
||||
expect(client.mockOutput.mock.calls[3][0]).toMatch(/Install Command/);
|
||||
expect(client.mockOutput.mock.calls[4][0]).toMatch(/Output Directory/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -99,28 +76,20 @@ describe('editProjectSettings', () => {
|
||||
outputDirectory: 'OUTPUT_DIRECTORY',
|
||||
};
|
||||
const settings = await editProjectSettings(
|
||||
output,
|
||||
client,
|
||||
projectSettings,
|
||||
nextJSFramework,
|
||||
true,
|
||||
null
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls.length).toBe(5);
|
||||
expect((output.print as jest.Mock).mock.calls[0][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls.length).toBe(5);
|
||||
expect(client.mockOutput.mock.calls[0][0]).toMatch(
|
||||
/Auto-detected Project Settings/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[1][0]).toMatch(
|
||||
/Build Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[2][0]).toMatch(
|
||||
/Development Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[3][0]).toMatch(
|
||||
/Install Command/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[4][0]).toMatch(
|
||||
/Output Directory/
|
||||
);
|
||||
expect(client.mockOutput.mock.calls[1][0]).toMatch(/Build Command/);
|
||||
expect(client.mockOutput.mock.calls[2][0]).toMatch(/Development Command/);
|
||||
expect(client.mockOutput.mock.calls[3][0]).toMatch(/Install Command/);
|
||||
expect(client.mockOutput.mock.calls[4][0]).toMatch(/Output Directory/);
|
||||
expect(settings).toStrictEqual({
|
||||
...projectSettings,
|
||||
framework: nextJSFramework.slug,
|
||||
@@ -146,38 +115,28 @@ describe('editProjectSettings', () => {
|
||||
outputDirectory: 'OUTPUT_DIRECTORY',
|
||||
};
|
||||
const settings = await editProjectSettings(
|
||||
output,
|
||||
client,
|
||||
projectSettings,
|
||||
nextJSFramework,
|
||||
true,
|
||||
overrides
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls.length).toBe(9);
|
||||
expect((output.print as jest.Mock).mock.calls[0][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls.length).toBe(9);
|
||||
expect(client.mockOutput.mock.calls[0][0]).toMatch(
|
||||
/Local settings detected in vercel.json:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[1][0]).toMatch(
|
||||
/Build Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[2][0]).toMatch(
|
||||
/Ignore Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[3][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[1][0]).toMatch(/Build Command:/);
|
||||
expect(client.mockOutput.mock.calls[2][0]).toMatch(/Ignore Command:/);
|
||||
expect(client.mockOutput.mock.calls[3][0]).toMatch(
|
||||
/Development Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[4][0]).toMatch(
|
||||
/Framework:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[5][0]).toMatch(
|
||||
/Install Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[6][0]).toMatch(
|
||||
/Output Directory:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[7][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[4][0]).toMatch(/Framework:/);
|
||||
expect(client.mockOutput.mock.calls[5][0]).toMatch(/Install Command:/);
|
||||
expect(client.mockOutput.mock.calls[6][0]).toMatch(/Output Directory:/);
|
||||
expect(client.mockOutput.mock.calls[7][0]).toMatch(
|
||||
/Merging default Project Settings for Svelte. Previously listed overrides are prioritized./
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[8][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[8][0]).toMatch(
|
||||
/Auto-detected Project Settings/
|
||||
);
|
||||
|
||||
@@ -196,38 +155,28 @@ describe('editProjectSettings', () => {
|
||||
outputDirectory: 'OUTPUT_DIRECTORY',
|
||||
};
|
||||
const settings = await editProjectSettings(
|
||||
output,
|
||||
client,
|
||||
null,
|
||||
nextJSFramework,
|
||||
true,
|
||||
overrides
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls.length).toBe(9);
|
||||
expect((output.print as jest.Mock).mock.calls[0][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls.length).toBe(9);
|
||||
expect(client.mockOutput.mock.calls[0][0]).toMatch(
|
||||
/Local settings detected in vercel.json:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[1][0]).toMatch(
|
||||
/Build Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[2][0]).toMatch(
|
||||
/Ignore Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[3][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[1][0]).toMatch(/Build Command:/);
|
||||
expect(client.mockOutput.mock.calls[2][0]).toMatch(/Ignore Command:/);
|
||||
expect(client.mockOutput.mock.calls[3][0]).toMatch(
|
||||
/Development Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[4][0]).toMatch(
|
||||
/Framework:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[5][0]).toMatch(
|
||||
/Install Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[6][0]).toMatch(
|
||||
/Output Directory:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[7][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[4][0]).toMatch(/Framework:/);
|
||||
expect(client.mockOutput.mock.calls[5][0]).toMatch(/Install Command:/);
|
||||
expect(client.mockOutput.mock.calls[6][0]).toMatch(/Output Directory:/);
|
||||
expect(client.mockOutput.mock.calls[7][0]).toMatch(
|
||||
/Merging default Project Settings for Svelte. Previously listed overrides are prioritized./
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[8][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[8][0]).toMatch(
|
||||
/Auto-detected Project Settings/
|
||||
);
|
||||
expect(settings).toStrictEqual(overrides);
|
||||
@@ -245,38 +194,28 @@ describe('editProjectSettings', () => {
|
||||
outputDirectory: 'OUTPUT_DIRECTORY',
|
||||
};
|
||||
const settings = await editProjectSettings(
|
||||
output,
|
||||
client,
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
overrides
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls.length).toBe(9);
|
||||
expect((output.print as jest.Mock).mock.calls[0][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls.length).toBe(9);
|
||||
expect(client.mockOutput.mock.calls[0][0]).toMatch(
|
||||
/Local settings detected in vercel.json:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[1][0]).toMatch(
|
||||
/Build Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[2][0]).toMatch(
|
||||
/Ignore Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[3][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[1][0]).toMatch(/Build Command:/);
|
||||
expect(client.mockOutput.mock.calls[2][0]).toMatch(/Ignore Command:/);
|
||||
expect(client.mockOutput.mock.calls[3][0]).toMatch(
|
||||
/Development Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[4][0]).toMatch(
|
||||
/Framework:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[5][0]).toMatch(
|
||||
/Install Command:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[6][0]).toMatch(
|
||||
/Output Directory:/
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[7][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[4][0]).toMatch(/Framework:/);
|
||||
expect(client.mockOutput.mock.calls[5][0]).toMatch(/Install Command:/);
|
||||
expect(client.mockOutput.mock.calls[6][0]).toMatch(/Output Directory:/);
|
||||
expect(client.mockOutput.mock.calls[7][0]).toMatch(
|
||||
/Merging default Project Settings for Svelte. Previously listed overrides are prioritized./
|
||||
);
|
||||
expect((output.print as jest.Mock).mock.calls[8][0]).toMatch(
|
||||
expect(client.mockOutput.mock.calls[8][0]).toMatch(
|
||||
/Auto-detected Project Settings/
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/client",
|
||||
"version": "12.0.2",
|
||||
"version": "12.0.3",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"homepage": "https://vercel.com",
|
||||
@@ -42,7 +42,7 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"@zeit/fetch": "5.2.0",
|
||||
"async-retry": "1.2.3",
|
||||
"async-sema": "3.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/go",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.3",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
|
||||
@@ -25,7 +25,7 @@
|
||||
"@types/fs-extra": "^5.0.5",
|
||||
"@types/node-fetch": "^2.3.0",
|
||||
"@types/tar": "^4.0.0",
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"async-retry": "1.3.1",
|
||||
"execa": "^1.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/next",
|
||||
"version": "3.1.1",
|
||||
"version": "3.1.2",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
|
||||
@@ -45,7 +45,7 @@
|
||||
"@types/semver": "6.0.0",
|
||||
"@types/text-table": "0.2.1",
|
||||
"@types/webpack-sources": "3.2.0",
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"@vercel/nft": "0.20.1",
|
||||
"@vercel/routing-utils": "1.13.5",
|
||||
"async-sema": "3.0.1",
|
||||
|
||||
@@ -1520,35 +1520,35 @@ export const build: BuildV2 = async ({
|
||||
const pageLambdaGroups: Array<LambdaGroup> = [];
|
||||
|
||||
if (isSharedLambdas) {
|
||||
const initialPageLambdaGroups = await getPageLambdaGroups(
|
||||
const initialPageLambdaGroups = await getPageLambdaGroups({
|
||||
entryPath,
|
||||
config,
|
||||
nonApiPages,
|
||||
new Set(),
|
||||
pages: nonApiPages,
|
||||
prerenderRoutes: new Set(),
|
||||
pageTraces,
|
||||
compressedPages,
|
||||
tracedPseudoLayer?.pseudoLayer || {},
|
||||
0,
|
||||
0,
|
||||
tracedPseudoLayer: tracedPseudoLayer?.pseudoLayer || {},
|
||||
initialPseudoLayer: { pseudoLayer: {}, pseudoLayerBytes: 0 },
|
||||
initialPseudoLayerUncompressed: 0,
|
||||
lambdaCompressedByteLimit,
|
||||
// internal pages are already referenced in traces for serverless
|
||||
// like builds
|
||||
[]
|
||||
);
|
||||
internalPages: [],
|
||||
});
|
||||
|
||||
const initialApiLambdaGroups = await getPageLambdaGroups(
|
||||
const initialApiLambdaGroups = await getPageLambdaGroups({
|
||||
entryPath,
|
||||
config,
|
||||
apiPages,
|
||||
new Set(),
|
||||
pages: apiPages,
|
||||
prerenderRoutes: new Set(),
|
||||
pageTraces,
|
||||
compressedPages,
|
||||
tracedPseudoLayer?.pseudoLayer || {},
|
||||
0,
|
||||
0,
|
||||
tracedPseudoLayer: tracedPseudoLayer?.pseudoLayer || {},
|
||||
initialPseudoLayer: { pseudoLayer: {}, pseudoLayerBytes: 0 },
|
||||
initialPseudoLayerUncompressed: 0,
|
||||
lambdaCompressedByteLimit,
|
||||
[]
|
||||
);
|
||||
internalPages: [],
|
||||
});
|
||||
|
||||
debug(
|
||||
JSON.stringify(
|
||||
|
||||
@@ -425,11 +425,8 @@ export async function serverBuild({
|
||||
const uncompressedInitialSize = Object.keys(
|
||||
initialPseudoLayer.pseudoLayer
|
||||
).reduce((prev, cur) => {
|
||||
return (
|
||||
prev +
|
||||
(initialPseudoLayer.pseudoLayer[cur] as PseudoFile)
|
||||
.uncompressedSize || 0
|
||||
);
|
||||
const file = initialPseudoLayer.pseudoLayer[cur] as PseudoFile;
|
||||
return prev + file.uncompressedSize || 0;
|
||||
}, 0);
|
||||
|
||||
debug(
|
||||
@@ -611,43 +608,36 @@ export async function serverBuild({
|
||||
}, {})
|
||||
);
|
||||
|
||||
const initialPseudoLayerSize = Object.keys(
|
||||
initialPseudoLayer.pseudoLayer
|
||||
).reduce((prev, cur) => {
|
||||
const file = initialPseudoLayer.pseudoLayer[cur] as PseudoFile;
|
||||
return prev + file.uncompressedSize || 0;
|
||||
}, 0);
|
||||
|
||||
const pageExtensions = requiredServerFilesManifest.config?.pageExtensions;
|
||||
|
||||
const pageLambdaGroups = await getPageLambdaGroups(
|
||||
requiredServerFilesManifest.appDir || entryPath,
|
||||
const pageLambdaGroups = await getPageLambdaGroups({
|
||||
entryPath: requiredServerFilesManifest.appDir || entryPath,
|
||||
config,
|
||||
nonApiPages,
|
||||
pages: nonApiPages,
|
||||
prerenderRoutes,
|
||||
pageTraces,
|
||||
compressedPages,
|
||||
tracedPseudoLayer.pseudoLayer,
|
||||
initialPseudoLayer.pseudoLayerBytes,
|
||||
initialPseudoLayerSize,
|
||||
tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
|
||||
initialPseudoLayer,
|
||||
lambdaCompressedByteLimit,
|
||||
initialPseudoLayerUncompressed: uncompressedInitialSize,
|
||||
internalPages,
|
||||
pageExtensions,
|
||||
});
|
||||
|
||||
const apiLambdaGroups = await getPageLambdaGroups({
|
||||
entryPath: requiredServerFilesManifest.appDir || entryPath,
|
||||
config,
|
||||
pages: apiPages,
|
||||
prerenderRoutes,
|
||||
pageTraces,
|
||||
compressedPages,
|
||||
tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
|
||||
initialPseudoLayer,
|
||||
initialPseudoLayerUncompressed: uncompressedInitialSize,
|
||||
lambdaCompressedByteLimit,
|
||||
internalPages,
|
||||
pageExtensions
|
||||
);
|
||||
|
||||
const apiLambdaGroups = await getPageLambdaGroups(
|
||||
requiredServerFilesManifest.appDir || entryPath,
|
||||
config,
|
||||
apiPages,
|
||||
prerenderRoutes,
|
||||
pageTraces,
|
||||
compressedPages,
|
||||
tracedPseudoLayer.pseudoLayer,
|
||||
initialPseudoLayer.pseudoLayerBytes,
|
||||
initialPseudoLayerSize,
|
||||
lambdaCompressedByteLimit,
|
||||
internalPages
|
||||
);
|
||||
});
|
||||
|
||||
debug(
|
||||
JSON.stringify(
|
||||
@@ -682,7 +672,6 @@ export async function serverBuild({
|
||||
const lambda = await createLambdaFromPseudoLayers({
|
||||
files: launcherFiles,
|
||||
layers: [
|
||||
initialPseudoLayer.pseudoLayer,
|
||||
group.pseudoLayer,
|
||||
[...group.pages, ...internalPages].reduce((prev, page) => {
|
||||
const pageFileName = path.normalize(
|
||||
|
||||
@@ -1275,26 +1275,39 @@ export const MAX_UNCOMPRESSED_LAMBDA_SIZE = 250 * 1000 * 1000; // 250MB
|
||||
const LAMBDA_RESERVED_UNCOMPRESSED_SIZE = 2.5 * 1000 * 1000; // 2.5MB
|
||||
const LAMBDA_RESERVED_COMPRESSED_SIZE = 250 * 1000; // 250KB
|
||||
|
||||
export async function getPageLambdaGroups(
|
||||
entryPath: string,
|
||||
config: Config,
|
||||
pages: string[],
|
||||
prerenderRoutes: Set<string>,
|
||||
export async function getPageLambdaGroups({
|
||||
entryPath,
|
||||
config,
|
||||
pages,
|
||||
prerenderRoutes,
|
||||
pageTraces,
|
||||
compressedPages,
|
||||
tracedPseudoLayer,
|
||||
initialPseudoLayer,
|
||||
initialPseudoLayerUncompressed,
|
||||
lambdaCompressedByteLimit,
|
||||
internalPages,
|
||||
pageExtensions,
|
||||
}: {
|
||||
entryPath: string;
|
||||
config: Config;
|
||||
pages: string[];
|
||||
prerenderRoutes: Set<string>;
|
||||
pageTraces: {
|
||||
[page: string]: {
|
||||
[key: string]: FileFsRef;
|
||||
};
|
||||
},
|
||||
};
|
||||
compressedPages: {
|
||||
[page: string]: PseudoFile;
|
||||
},
|
||||
tracedPseudoLayer: PseudoLayer,
|
||||
initialPseudoLayerSize: number,
|
||||
initialPseudoLayerUncompressedSize: number,
|
||||
lambdaCompressedByteLimit: number,
|
||||
internalPages: string[],
|
||||
pageExtensions?: string[]
|
||||
) {
|
||||
};
|
||||
tracedPseudoLayer: PseudoLayer;
|
||||
initialPseudoLayer: PseudoLayerResult;
|
||||
initialPseudoLayerUncompressed: number;
|
||||
lambdaCompressedByteLimit: number;
|
||||
internalPages: string[];
|
||||
pageExtensions?: string[];
|
||||
}) {
|
||||
const groups: Array<LambdaGroup> = [];
|
||||
|
||||
for (const page of pages) {
|
||||
@@ -1341,10 +1354,10 @@ export async function getPageLambdaGroups(
|
||||
}
|
||||
|
||||
const underUncompressedLimit =
|
||||
newTracedFilesUncompressedSize + initialPseudoLayerUncompressedSize <
|
||||
newTracedFilesUncompressedSize <
|
||||
MAX_UNCOMPRESSED_LAMBDA_SIZE - LAMBDA_RESERVED_UNCOMPRESSED_SIZE;
|
||||
const underCompressedLimit =
|
||||
newTracedFilesSize + initialPseudoLayerSize <
|
||||
newTracedFilesSize <
|
||||
lambdaCompressedByteLimit - LAMBDA_RESERVED_COMPRESSED_SIZE;
|
||||
|
||||
return underUncompressedLimit && underCompressedLimit;
|
||||
@@ -1359,9 +1372,9 @@ export async function getPageLambdaGroups(
|
||||
pages: [page],
|
||||
...opts,
|
||||
isPrerenders: isPrerenderRoute,
|
||||
pseudoLayerBytes: 0,
|
||||
pseudoLayerUncompressedBytes: 0,
|
||||
pseudoLayer: {},
|
||||
pseudoLayerBytes: initialPseudoLayer.pseudoLayerBytes,
|
||||
pseudoLayerUncompressedBytes: initialPseudoLayerUncompressed,
|
||||
pseudoLayer: Object.assign({}, initialPseudoLayer.pseudoLayer),
|
||||
};
|
||||
groups.push(newGroup);
|
||||
matchingGroup = newGroup;
|
||||
|
||||
@@ -105,6 +105,21 @@ it('should build using server build', async () => {
|
||||
log.includes('WARNING: Unable to find source file for page')
|
||||
)
|
||||
).toBeFalsy();
|
||||
|
||||
const lambdas = new Set();
|
||||
let totalLambdas = 0;
|
||||
|
||||
for (const item of Object.values(output)) {
|
||||
if (item.type === 'Lambda') {
|
||||
totalLambdas += 1;
|
||||
lambdas.add(item);
|
||||
} else if (item.type === 'Prerender') {
|
||||
lambdas.add(item.lambda);
|
||||
totalLambdas += 1;
|
||||
}
|
||||
}
|
||||
expect(lambdas.size).toBe(5);
|
||||
expect(lambdas.size).toBeLessThan(totalLambdas);
|
||||
});
|
||||
|
||||
it('should build custom error lambda correctly', async () => {
|
||||
@@ -715,7 +730,7 @@ it('Should provide lambda info when limit is hit (server build)', async () => {
|
||||
console.log = origLog;
|
||||
|
||||
expect(logs).toContain(
|
||||
'Max serverless function size was exceeded for 1 function'
|
||||
'Max serverless function size was exceeded for 2 functions'
|
||||
);
|
||||
expect(logs).toContain(
|
||||
'Max serverless function size of 50 MB compressed or 250 MB uncompressed reached'
|
||||
@@ -802,3 +817,99 @@ it('Should provide lambda info when limit is hit for internal pages (server buil
|
||||
expect(logs).toMatch(/public\/big-image-1\.jpg/);
|
||||
expect(logs).toMatch(/public\/big-image-2\.jpg/);
|
||||
});
|
||||
|
||||
it('Should provide lambda info when limit is hit (uncompressed)', async () => {
|
||||
let logs = '';
|
||||
|
||||
const origLog = console.log;
|
||||
|
||||
console.log = function (...args) {
|
||||
logs += args.join(' ');
|
||||
origLog(...args);
|
||||
};
|
||||
|
||||
try {
|
||||
await runBuildLambda(
|
||||
path.join(__dirname, 'test-limit-exceeded-404-static-files')
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
console.log = origLog;
|
||||
|
||||
expect(logs).toContain(
|
||||
'Max serverless function size was exceeded for 1 function'
|
||||
);
|
||||
expect(logs).toContain(
|
||||
'Max serverless function size of 50 MB compressed or 250 MB uncompressed reached'
|
||||
);
|
||||
expect(logs).toContain(`Serverless Function's page: api/hello.js`);
|
||||
expect(logs).toMatch(
|
||||
/Large Dependencies.*?Uncompressed size.*?Compressed size/
|
||||
);
|
||||
expect(logs).toMatch(/data\.txt/);
|
||||
expect(logs).toMatch(/\.next\/server\/pages/);
|
||||
});
|
||||
|
||||
it('Should de-dupe correctly when limit is close (uncompressed)', async () => {
|
||||
const origLog = console.log;
|
||||
const origError = console.error;
|
||||
const caughtLogs = [];
|
||||
|
||||
console.log = function (...args) {
|
||||
caughtLogs.push(args.join(' '));
|
||||
origLog.apply(this, args);
|
||||
};
|
||||
console.error = function (...args) {
|
||||
caughtLogs.push(args.join(' '));
|
||||
origError.apply(this, args);
|
||||
};
|
||||
|
||||
const {
|
||||
buildResult: { output },
|
||||
} = await runBuildLambda(
|
||||
path.join(__dirname, 'test-limit-large-uncompressed-files')
|
||||
);
|
||||
|
||||
console.log = origLog;
|
||||
console.error = origError;
|
||||
|
||||
expect(output['index']).toBeDefined();
|
||||
expect(output['another']).toBeDefined();
|
||||
expect(output['api/hello']).toBeDefined();
|
||||
expect(output['api/hello-1']).toBeDefined();
|
||||
expect(output['api/hello-2']).toBeDefined();
|
||||
expect(output['api/hello-3']).toBeDefined();
|
||||
expect(output['api/hello-4']).toBeDefined();
|
||||
expect(output['_app']).not.toBeDefined();
|
||||
expect(output['_error']).not.toBeDefined();
|
||||
expect(output['_document']).not.toBeDefined();
|
||||
|
||||
expect(output['index'] === output['another']).toBe(true);
|
||||
expect(output['index'] !== output['api/hello']).toBe(true);
|
||||
expect(output['api/hello'] === output['api/hello-1']).toBe(true);
|
||||
expect(output['api/hello'] === output['api/hello-2']).toBe(true);
|
||||
expect(output['api/hello'] === output['api/hello-3']).toBe(true);
|
||||
expect(output['api/hello'] === output['api/hello-4']).toBe(true);
|
||||
|
||||
expect(
|
||||
caughtLogs.some(log =>
|
||||
log.includes('WARNING: Unable to find source file for page')
|
||||
)
|
||||
).toBeFalsy();
|
||||
|
||||
const lambdas = new Set();
|
||||
let totalLambdas = 0;
|
||||
|
||||
for (const item of Object.values(output)) {
|
||||
if (item.type === 'Lambda') {
|
||||
totalLambdas += 1;
|
||||
lambdas.add(item);
|
||||
} else if (item.type === 'Prerender') {
|
||||
lambdas.add(item.lambda);
|
||||
totalLambdas += 1;
|
||||
}
|
||||
}
|
||||
expect(lambdas.size).toBe(2);
|
||||
expect(lambdas.size).toBeLessThan(totalLambdas);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
|
||||
const locales = ['en'];
|
||||
let charStart = 97;
|
||||
let charEnd = 105;
|
||||
|
||||
// generate 81 random locales under en
|
||||
for (let i = charStart; i <= charEnd; i++) {
|
||||
const firstChar = String.fromCharCode(i);
|
||||
|
||||
for (let j = charStart; j <= charEnd; j++) {
|
||||
const secondChar = String.fromCharCode(j);
|
||||
locales.push(`en-${firstChar}${secondChar}`);
|
||||
}
|
||||
}
|
||||
|
||||
assert(
|
||||
locales.length === 82,
|
||||
`unexpected locale count, expected 82, received ${locales.length}`
|
||||
);
|
||||
|
||||
// generate 100MB text file which will be traced in `/api/hello`
|
||||
// which when combined with the 404 HTML files will push us over the 250MB
|
||||
// uncompressed limit
|
||||
fs.writeFileSync('data.txt', new Array(100 * 1000 * 1000).fill('a').join());
|
||||
|
||||
module.exports = {
|
||||
i18n: {
|
||||
locales,
|
||||
defaultLocale: 'en',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "test-limit",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"build": "next build"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
export default function Page(props) {
|
||||
return (
|
||||
<>
|
||||
<p>404 | Page Not Found</p>
|
||||
<p>{JSON.stringify(props)}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function getStaticProps({ locale }) {
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
// 1MB string which is duplicated in HTML totalling 2MB
|
||||
// this will be generated for each locale as well
|
||||
largeData: new Array(1 * 1000 * 1000).fill('a').join(''),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/* eslint-disable */
|
||||
import React from 'react';
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
try {
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
fs.readdirSync(path.join(process.cwd(), 'public'));
|
||||
fs.readdirSync(path.join(process.cwd(), 'node_modules/chrome-aws-lambda'));
|
||||
fs.readdirSync(path.join(process.cwd(), 'node_modules/firebase'));
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
export default function MyApp({ Component, pageProps }) {
|
||||
return React.createElement(Component, pageProps);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
try {
|
||||
fs.readFileSync(path.join(process.cwd(), 'data.txt'));
|
||||
} catch (_) {
|
||||
/**/
|
||||
}
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.end('hello');
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Home() {
|
||||
return 'index page';
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@vercel/next"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const fs = require('fs');
|
||||
|
||||
// generate 200MB file which will be traced in `/api/hello`
|
||||
fs.writeFileSync('data.txt', Buffer.alloc(200 * 1024 * 1024));
|
||||
|
||||
module.exports = {};
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "test-limit",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"build": "next build"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/* eslint-disable */
|
||||
import React from 'react';
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
try {
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
fs.readdirSync(path.join(process.cwd(), 'public'));
|
||||
fs.readdirSync(path.join(process.cwd(), 'node_modules/chrome-aws-lambda'));
|
||||
fs.readdirSync(path.join(process.cwd(), 'node_modules/firebase'));
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
export default function MyApp({ Component, pageProps }) {
|
||||
return React.createElement(Component, pageProps);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export default function Home() {
|
||||
return 'another page';
|
||||
}
|
||||
|
||||
export function getServerSideProps() {
|
||||
require('fs').readFileSync(require('path').join(process.cwd(), 'data.txt'));
|
||||
return {
|
||||
props: {},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
try {
|
||||
fs.readFileSync(path.join(process.cwd(), 'data.txt'));
|
||||
} catch (_) {
|
||||
/**/
|
||||
}
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.end('hello');
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
try {
|
||||
fs.readFileSync(path.join(process.cwd(), 'data.txt'));
|
||||
} catch (_) {
|
||||
/**/
|
||||
}
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.end('hello');
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
try {
|
||||
fs.readFileSync(path.join(process.cwd(), 'data.txt'));
|
||||
} catch (_) {
|
||||
/**/
|
||||
}
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.end('hello');
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
try {
|
||||
fs.readFileSync(path.join(process.cwd(), 'data.txt'));
|
||||
} catch (_) {
|
||||
/**/
|
||||
}
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.end('hello');
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
try {
|
||||
fs.readFileSync(path.join(process.cwd(), 'data.txt'));
|
||||
} catch (_) {
|
||||
/**/
|
||||
}
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.end('hello');
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export default function Home() {
|
||||
return 'index page';
|
||||
}
|
||||
|
||||
export function getServerSideProps() {
|
||||
require('fs').readFileSync(require('path').join(process.cwd(), 'data.txt'));
|
||||
return {
|
||||
props: {},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@vercel/next"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/node",
|
||||
"version": "2.3.2",
|
||||
"version": "2.3.3",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
||||
@@ -31,7 +31,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "*",
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"@vercel/node-bridge": "3.0.0",
|
||||
"@vercel/static-config": "2.0.1",
|
||||
"edge-runtime": "1.0.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/python",
|
||||
"version": "3.0.2",
|
||||
"version": "3.0.3",
|
||||
"main": "./dist/index.js",
|
||||
"license": "MIT",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
|
||||
@@ -23,7 +23,7 @@
|
||||
"devDependencies": {
|
||||
"@types/execa": "^0.9.0",
|
||||
"@types/jest": "27.4.1",
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"execa": "^1.0.0",
|
||||
"typescript": "4.3.4"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/redwood",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"main": "./dist/index.js",
|
||||
"license": "MIT",
|
||||
"homepage": "https://vercel.com/docs",
|
||||
@@ -28,6 +28,6 @@
|
||||
"@types/aws-lambda": "8.10.19",
|
||||
"@types/node": "*",
|
||||
"@types/semver": "6.0.0",
|
||||
"@vercel/build-utils": "4.2.0"
|
||||
"@vercel/build-utils": "4.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/remix",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"homepage": "https://vercel.com/docs",
|
||||
@@ -26,7 +26,7 @@
|
||||
"devDependencies": {
|
||||
"@types/jest": "27.5.1",
|
||||
"@types/node": "*",
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"typescript": "4.6.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@vercel/ruby",
|
||||
"author": "Nathan Cahill <nathan@nathancahill.com>",
|
||||
"version": "1.3.10",
|
||||
"version": "1.3.11",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/ruby",
|
||||
@@ -23,7 +23,7 @@
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "8.0.0",
|
||||
"@types/semver": "6.0.0",
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"execa": "2.0.4",
|
||||
"fs-extra": "^7.0.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/static-build",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/build-step",
|
||||
@@ -37,7 +37,7 @@
|
||||
"@types/ms": "0.7.31",
|
||||
"@types/node-fetch": "2.5.4",
|
||||
"@types/promise-timeout": "1.3.0",
|
||||
"@vercel/build-utils": "4.2.0",
|
||||
"@vercel/build-utils": "4.2.1",
|
||||
"@vercel/frameworks": "1.0.2",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/routing-utils": "1.13.5",
|
||||
|
||||
Reference in New Issue
Block a user