mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 12:57:46 +00:00
Compare commits
10 Commits
@vercel/st
...
@vercel/py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bf6295d7a | ||
|
|
a4001ce10b | ||
|
|
2df3432d88 | ||
|
|
bcfc19de12 | ||
|
|
04381c669b | ||
|
|
0c7b54edad | ||
|
|
6d42816395 | ||
|
|
6fe6d05a42 | ||
|
|
50a201f145 | ||
|
|
701a02ae9d |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/build-utils",
|
||||
"version": "4.0.1-canary.0",
|
||||
"version": "4.1.1-canary.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
|
||||
@@ -23,7 +23,7 @@ interface ErrorResponse {
|
||||
}
|
||||
|
||||
interface Options {
|
||||
tag?: 'canary' | 'latest' | string;
|
||||
tag?: string;
|
||||
functions?: BuilderFunctions;
|
||||
ignoreBuildScript?: boolean;
|
||||
projectSettings?: ProjectSettings;
|
||||
@@ -278,7 +278,7 @@ export async function detectBuilders(
|
||||
// and package.json can be served as static files
|
||||
frontendBuilder = {
|
||||
use: '@vercel/static',
|
||||
src: '!{api/**,package.json}',
|
||||
src: '!{api/**,package.json,middleware.[jt]s}',
|
||||
config: {
|
||||
zeroConfig: true,
|
||||
},
|
||||
@@ -355,7 +355,16 @@ function maybeGetApiBuilder(
|
||||
apiMatches: Builder[],
|
||||
options: Options
|
||||
) {
|
||||
if (!fileName.startsWith('api/')) {
|
||||
const middleware =
|
||||
fileName === 'middleware.js' || fileName === 'middleware.ts';
|
||||
|
||||
// Root-level Middleware file is handled by `@vercel/next`, so don't
|
||||
// schedule a separate Builder when "nextjs" framework is selected
|
||||
if (middleware && options.projectSettings?.framework === 'nextjs') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(fileName.startsWith('api/') || middleware)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -381,7 +390,7 @@ function maybeGetApiBuilder(
|
||||
|
||||
const { fnPattern, func } = getFunction(fileName, options);
|
||||
|
||||
const use = (func && func.runtime) || (match && match.use);
|
||||
const use = func?.runtime || match?.use;
|
||||
|
||||
if (!use) {
|
||||
return null;
|
||||
@@ -389,6 +398,10 @@ function maybeGetApiBuilder(
|
||||
|
||||
const config: Config = { zeroConfig: true };
|
||||
|
||||
if (middleware) {
|
||||
config.middleware = true;
|
||||
}
|
||||
|
||||
if (fnPattern && func) {
|
||||
config.functions = { [fnPattern]: func };
|
||||
|
||||
@@ -428,6 +441,7 @@ function getApiMatches() {
|
||||
const config = { zeroConfig: true };
|
||||
|
||||
return [
|
||||
{ src: 'middleware.[jt]s', use: `@vercel/node`, config },
|
||||
{ src: 'api/**/*.js', use: `@vercel/node`, config },
|
||||
{ src: 'api/**/*.mjs', use: `@vercel/node`, config },
|
||||
{ src: 'api/**/*.ts', use: `@vercel/node`, config },
|
||||
|
||||
60
packages/build-utils/src/get-project-paths.ts
Normal file
60
packages/build-utils/src/get-project-paths.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { detectFramework } from './detect-framework';
|
||||
import { DetectorFilesystem } from './detectors/filesystem';
|
||||
import frameworks from '@vercel/frameworks';
|
||||
|
||||
const MAX_DEPTH_TRAVERSE = 3;
|
||||
|
||||
export interface GetProjectPathsOptions {
|
||||
fs: DetectorFilesystem;
|
||||
path?: string;
|
||||
skipPaths?: string[];
|
||||
depth?: number;
|
||||
}
|
||||
|
||||
export type ProjectPath = string;
|
||||
|
||||
export const getProjectPaths = async ({
|
||||
fs,
|
||||
path,
|
||||
skipPaths,
|
||||
depth = MAX_DEPTH_TRAVERSE,
|
||||
}: GetProjectPathsOptions): Promise<ProjectPath[]> => {
|
||||
if (depth === 0) return [];
|
||||
|
||||
const allPaths: Array<ProjectPath> = [];
|
||||
const topPath: string = path ?? './';
|
||||
|
||||
if (path && skipPaths?.includes(path)) {
|
||||
return allPaths;
|
||||
}
|
||||
const framework = await detectFramework({
|
||||
fs: fs.chdir(topPath),
|
||||
frameworkList: frameworks,
|
||||
});
|
||||
|
||||
if (framework !== null) allPaths.push(topPath);
|
||||
|
||||
if (depth > 1) {
|
||||
const directoryContents = await fs.readdir(topPath);
|
||||
const childDirectories = directoryContents.filter(
|
||||
stat => stat.type === 'dir' && !skipPaths?.includes(stat.path)
|
||||
);
|
||||
|
||||
const paths = (
|
||||
await Promise.all(
|
||||
childDirectories.map(({ path }) => {
|
||||
return getProjectPaths({
|
||||
fs,
|
||||
path,
|
||||
depth: depth - 1,
|
||||
skipPaths,
|
||||
});
|
||||
})
|
||||
)
|
||||
).flat();
|
||||
|
||||
return [...paths, ...allPaths];
|
||||
}
|
||||
|
||||
return allPaths;
|
||||
};
|
||||
@@ -88,6 +88,7 @@ export {
|
||||
} from './detect-builders';
|
||||
export { detectFileSystemAPI } from './detect-file-system-api';
|
||||
export { detectFramework } from './detect-framework';
|
||||
export { getProjectPaths } from './get-project-paths';
|
||||
export { DetectorFilesystem } from './detectors/filesystem';
|
||||
export { readConfigFile } from './fs/read-config-file';
|
||||
export { normalizePath } from './fs/normalize-path';
|
||||
|
||||
@@ -428,6 +428,8 @@ export interface BuildResultV2Typical {
|
||||
export type BuildResultV2 = BuildResultV2Typical | BuildResultBuildOutput;
|
||||
|
||||
export interface BuildResultV3 {
|
||||
// TODO: use proper `Route` type from `routing-utils` (perhaps move types to a common package)
|
||||
routes?: any[];
|
||||
output: Lambda | EdgeFunction;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-three",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-three",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "a",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"debug": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "b",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cowsay": "^1.5.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "21-npm-workspaces",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-three",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-two",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-two",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/users.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
@@ -89,7 +89,7 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/[endpoint].js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
@@ -144,7 +144,7 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/endpoint.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
});
|
||||
|
||||
@@ -347,7 +347,7 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/index.ts');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
});
|
||||
|
||||
it('functions with nextjs', async () => {
|
||||
@@ -1010,7 +1010,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/users.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
|
||||
@@ -1032,7 +1032,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/[endpoint].js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
@@ -1258,7 +1258,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/endpoint.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
|
||||
expect(defaultRoutes!.length).toBe(2);
|
||||
@@ -1288,7 +1288,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/version.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
|
||||
expect(defaultRoutes!.length).toBe(2);
|
||||
@@ -1567,7 +1567,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/index.ts');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(errorRoutes!.length).toBe(1);
|
||||
expect((errorRoutes![0] as Source).status).toBe(404);
|
||||
});
|
||||
@@ -2228,6 +2228,55 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders).toBe(null);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
|
||||
it('no package.json + no build + root-level "middleware.js"', async () => {
|
||||
const files = ['middleware.js', 'index.html', 'web/middleware.js'];
|
||||
const { builders, errors } = await detectBuilders(files, null, {
|
||||
featHandleMiss,
|
||||
});
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('middleware.js');
|
||||
expect(builders![0].config?.middleware).toEqual(true);
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
|
||||
it('no package.json + no build + root-level "middleware.ts"', async () => {
|
||||
const files = ['middleware.ts', 'index.html', 'web/middleware.js'];
|
||||
const { builders, errors } = await detectBuilders(files, null, {
|
||||
featHandleMiss,
|
||||
});
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('middleware.ts');
|
||||
expect(builders![0].config?.middleware).toEqual(true);
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
|
||||
it('should not add middleware builder when "nextjs" framework is selected', async () => {
|
||||
const files = ['package.json', 'pages/index.ts', 'middleware.ts'];
|
||||
const projectSettings = {
|
||||
framework: 'nextjs',
|
||||
};
|
||||
const { builders } = await detectBuilders(files, null, {
|
||||
projectSettings,
|
||||
featHandleMiss,
|
||||
});
|
||||
expect(builders).toEqual([
|
||||
{
|
||||
use: '@vercel/next',
|
||||
src: 'package.json',
|
||||
config: {
|
||||
zeroConfig: true,
|
||||
framework: projectSettings.framework,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('Test `detectRoutes`', async () => {
|
||||
|
||||
70
packages/build-utils/test/unit.get-project-paths.test.ts
vendored
Normal file
70
packages/build-utils/test/unit.get-project-paths.test.ts
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import path from 'path';
|
||||
import { normalizePath } from '../src';
|
||||
import { getProjectPaths, ProjectPath } from '../src/get-project-paths';
|
||||
import { FixtureFilesystem } from './utils/fixture-filesystem';
|
||||
|
||||
describe.each<{
|
||||
fixturePath: string;
|
||||
resultPaths: ProjectPath[];
|
||||
skipPaths?: ProjectPath[];
|
||||
readdirCalls: number;
|
||||
}>([
|
||||
{
|
||||
fixturePath: '32-monorepo-highly-nested',
|
||||
resultPaths: [],
|
||||
readdirCalls: 2,
|
||||
},
|
||||
{
|
||||
fixturePath: '33-hybrid-monorepo',
|
||||
resultPaths: ['backend/app-three'],
|
||||
readdirCalls: 2,
|
||||
skipPaths: ['frontend'],
|
||||
},
|
||||
{
|
||||
fixturePath: '34-monorepo-no-workspaces',
|
||||
resultPaths: ['backend/app-three', 'frontend/app-one', 'frontend/app-two'],
|
||||
readdirCalls: 3,
|
||||
},
|
||||
{
|
||||
fixturePath: '35-no-monorepo',
|
||||
resultPaths: [],
|
||||
readdirCalls: 1,
|
||||
},
|
||||
{
|
||||
fixturePath: '36-monorepo-some-nested',
|
||||
resultPaths: ['frontend/app-two'],
|
||||
readdirCalls: 2,
|
||||
},
|
||||
{
|
||||
fixturePath: '37-project-depth-one-level',
|
||||
resultPaths: ['./'],
|
||||
readdirCalls: 1,
|
||||
},
|
||||
])(
|
||||
'`getProjectPaths()`',
|
||||
({ resultPaths, readdirCalls, fixturePath, skipPaths }) => {
|
||||
const testName =
|
||||
resultPaths.length > 0
|
||||
? `should detect ${resultPaths.join()} project${
|
||||
resultPaths.length > 1 ? 's' : ''
|
||||
} for ${fixturePath}`
|
||||
: `should not detect any path for ${fixturePath}`;
|
||||
|
||||
it(testName, async () => {
|
||||
const fixture = path.join(
|
||||
__dirname,
|
||||
'non-deployed-fixtures',
|
||||
fixturePath
|
||||
);
|
||||
const fs = new FixtureFilesystem(fixture);
|
||||
const mockReaddir = jest.fn().mockImplementation(fs.readdir);
|
||||
const mockHasPath = jest.fn().mockImplementation(fs.hasPath);
|
||||
fs.readdir = mockReaddir;
|
||||
fs.hasPath = mockHasPath;
|
||||
const actualPaths = await getProjectPaths({ fs, skipPaths });
|
||||
const normalizedPaths = actualPaths.map(path => normalizePath(path));
|
||||
expect(normalizedPaths).toEqual(resultPaths);
|
||||
expect(fs.readdir).toHaveBeenCalledTimes(readdirCalls);
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vercel",
|
||||
"version": "25.0.2-canary.0",
|
||||
"version": "25.1.1-canary.0",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Vercel",
|
||||
@@ -42,15 +42,15 @@
|
||||
"node": ">= 14"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "4.0.1-canary.0",
|
||||
"@vercel/go": "2.0.1-canary.0",
|
||||
"@vercel/next": "3.0.1-canary.0",
|
||||
"@vercel/node": "2.0.2-canary.0",
|
||||
"@vercel/python": "3.0.1-canary.0",
|
||||
"@vercel/redwood": "1.0.1-canary.0",
|
||||
"@vercel/remix": "1.0.1-canary.0",
|
||||
"@vercel/ruby": "1.3.9-canary.0",
|
||||
"@vercel/static-build": "1.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"@vercel/go": "2.0.2-canary.0",
|
||||
"@vercel/next": "3.0.2-canary.0",
|
||||
"@vercel/node": "2.1.1-canary.0",
|
||||
"@vercel/python": "3.0.2-canary.0",
|
||||
"@vercel/redwood": "1.0.2-canary.0",
|
||||
"@vercel/remix": "1.0.2-canary.0",
|
||||
"@vercel/ruby": "1.3.10-canary.0",
|
||||
"@vercel/static-build": "1.0.2-canary.0",
|
||||
"update-notifier": "5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -94,7 +94,7 @@
|
||||
"@types/which": "1.3.2",
|
||||
"@types/write-json-file": "2.2.1",
|
||||
"@types/yauzl-promise": "2.1.0",
|
||||
"@vercel/client": "12.0.1-canary.0",
|
||||
"@vercel/client": "12.0.2-canary.0",
|
||||
"@vercel/frameworks": "1.0.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@zeit/fun": "0.11.2",
|
||||
|
||||
@@ -101,6 +101,7 @@ export default async function main(client: Client): Promise<number> {
|
||||
const argv = getArgs(client.argv.slice(2), {
|
||||
'--cwd': String,
|
||||
'--prod': Boolean,
|
||||
'--yes': Boolean,
|
||||
});
|
||||
|
||||
if (argv['--help']) {
|
||||
@@ -114,42 +115,53 @@ export default async function main(client: Client): Promise<number> {
|
||||
}
|
||||
const cwd = process.cwd();
|
||||
|
||||
// Build `target` influences which environment variables will be used
|
||||
const target = argv['--prod'] ? 'production' : 'preview';
|
||||
const yes = Boolean(argv['--yes']);
|
||||
|
||||
// TODO: read project settings from the API, fall back to local `project.json` if that fails
|
||||
|
||||
// Read project settings, and pull them from Vercel if necessary
|
||||
let project = await readProjectSettings(join(cwd, VERCEL_DIR));
|
||||
const isTTY = process.stdin.isTTY;
|
||||
while (!project?.settings) {
|
||||
if (!isTTY) {
|
||||
client.output.print(
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull --yes'
|
||||
)} to retreive them.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
let confirmed = yes;
|
||||
if (!confirmed) {
|
||||
if (!isTTY) {
|
||||
client.output.print(
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull --yes'
|
||||
)} to retreive them.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const confirmed = await confirm(
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull'
|
||||
)} for retrieving them?`,
|
||||
true
|
||||
);
|
||||
confirmed = await confirm(
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull'
|
||||
)} for retrieving them?`,
|
||||
true
|
||||
);
|
||||
}
|
||||
if (!confirmed) {
|
||||
client.output.print(`Aborted. No Project Settings retrieved.\n`);
|
||||
return 0;
|
||||
}
|
||||
client.argv = [];
|
||||
const { argv: originalArgv } = client;
|
||||
client.argv = [
|
||||
...originalArgv.slice(0, 2),
|
||||
'pull',
|
||||
`--environment`,
|
||||
target,
|
||||
];
|
||||
const result = await pull(client);
|
||||
if (result !== 0) {
|
||||
return result;
|
||||
}
|
||||
client.argv = originalArgv;
|
||||
project = await readProjectSettings(join(cwd, VERCEL_DIR));
|
||||
}
|
||||
|
||||
// Build `target` influences which environment variables will be used
|
||||
const target = argv['--prod'] ? 'production' : 'preview';
|
||||
|
||||
// TODO: load env vars from the API, fall back to local files if that fails
|
||||
|
||||
const envPath = await checkExists([
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { resolve, join } from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import DevServer from '../../util/dev/server';
|
||||
import parseListen from '../../util/dev/parse-listen';
|
||||
@@ -12,6 +13,7 @@ import setupAndLink from '../../util/link/setup-and-link';
|
||||
import getSystemEnvValues from '../../util/env/get-system-env-values';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
import param from '../../util/output/param';
|
||||
import { OUTPUT_DIR } from '../../util/build/write-build-result';
|
||||
|
||||
type Options = {
|
||||
'--listen': string;
|
||||
@@ -104,6 +106,15 @@ export default async function dev(
|
||||
devCommand = process.env.VERCEL_DEV_COMMAND;
|
||||
}
|
||||
|
||||
// If there is no Development Command, we must delete the
|
||||
// v3 Build Output because it will incorrectly be detected by
|
||||
// @vercel/static-build in BuildOutputV3.getBuildOutputDirectory()
|
||||
if (!devCommand) {
|
||||
output.log(`Removing ${OUTPUT_DIR}`);
|
||||
const outputDir = join(cwd, OUTPUT_DIR);
|
||||
await fs.remove(outputDir);
|
||||
}
|
||||
|
||||
const devServer = new DevServer(cwd, {
|
||||
output,
|
||||
devCommand,
|
||||
|
||||
7
packages/cli/test/fixtures/unit/commands/build/middleware/.vercel/project.json
vendored
Normal file
7
packages/cli/test/fixtures/unit/commands/build/middleware/.vercel/project.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"orgId": ".",
|
||||
"projectId": ".",
|
||||
"settings": {
|
||||
"framework": null
|
||||
}
|
||||
}
|
||||
1
packages/cli/test/fixtures/unit/commands/build/middleware/index.html
vendored
Normal file
1
packages/cli/test/fixtures/unit/commands/build/middleware/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Vercel</h1>
|
||||
1
packages/cli/test/fixtures/unit/commands/build/middleware/middleware.js
vendored
Normal file
1
packages/cli/test/fixtures/unit/commands/build/middleware/middleware.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default req => new Response('middleware');
|
||||
4
packages/cli/test/fixtures/unit/commands/build/static-pull/.vercel/project.json
vendored
Normal file
4
packages/cli/test/fixtures/unit/commands/build/static-pull/.vercel/project.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"projectId": "vercel-pull-next",
|
||||
"orgId": "team_dummy"
|
||||
}
|
||||
1
packages/cli/test/fixtures/unit/commands/build/static-pull/index.html
vendored
Normal file
1
packages/cli/test/fixtures/unit/commands/build/static-pull/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Vercel</h1>
|
||||
@@ -1,8 +1,11 @@
|
||||
import ms from 'ms';
|
||||
import fs from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
import { client } from '../../mocks/client';
|
||||
import build from '../../../src/commands/build';
|
||||
import { client } from '../../mocks/client';
|
||||
import { defaultProject, useProject } from '../../mocks/project';
|
||||
import { useTeams } from '../../mocks/team';
|
||||
import { useUser } from '../../mocks/user';
|
||||
|
||||
jest.setTimeout(ms('1 minute'));
|
||||
|
||||
@@ -139,7 +142,7 @@ describe('build', () => {
|
||||
require: '@vercel/static',
|
||||
apiVersion: 2,
|
||||
use: '@vercel/static',
|
||||
src: '!{api/**,package.json}',
|
||||
src: '!{api/**,package.json,middleware.[jt]s}',
|
||||
config: {
|
||||
zeroConfig: true,
|
||||
},
|
||||
@@ -204,7 +207,7 @@ describe('build', () => {
|
||||
require: '@vercel/static',
|
||||
apiVersion: 2,
|
||||
use: '@vercel/static',
|
||||
src: '!{api/**,package.json}',
|
||||
src: '!{api/**,package.json,middleware.[jt]s}',
|
||||
config: {
|
||||
zeroConfig: true,
|
||||
},
|
||||
@@ -237,4 +240,135 @@ describe('build', () => {
|
||||
delete process.env.__VERCEL_BUILD_RUNNING;
|
||||
}
|
||||
});
|
||||
|
||||
it('should pull "preview" env vars by default', async () => {
|
||||
const cwd = fixture('static-pull');
|
||||
useUser();
|
||||
useTeams('team_dummy');
|
||||
useProject({
|
||||
...defaultProject,
|
||||
id: 'vercel-pull-next',
|
||||
name: 'vercel-pull-next',
|
||||
});
|
||||
const envFilePath = join(cwd, '.vercel', '.env.preview.local');
|
||||
const projectJsonPath = join(cwd, '.vercel', 'project.json');
|
||||
const originalProjectJson = await fs.readJSON(
|
||||
join(cwd, '.vercel/project.json')
|
||||
);
|
||||
try {
|
||||
process.chdir(cwd);
|
||||
client.setArgv('build', '--yes');
|
||||
const exitCode = await build(client);
|
||||
expect(exitCode).toEqual(0);
|
||||
|
||||
const previewEnv = await fs.readFile(envFilePath, 'utf8');
|
||||
const envFileHasPreviewEnv = previewEnv.includes(
|
||||
'REDIS_CONNECTION_STRING'
|
||||
);
|
||||
expect(envFileHasPreviewEnv).toBeTruthy();
|
||||
} finally {
|
||||
await fs.remove(envFilePath);
|
||||
await fs.writeJSON(projectJsonPath, originalProjectJson, { spaces: 2 });
|
||||
process.chdir(originalCwd);
|
||||
delete process.env.__VERCEL_BUILD_RUNNING;
|
||||
}
|
||||
});
|
||||
|
||||
it('should pull "production" env vars with `--prod`', async () => {
|
||||
const cwd = fixture('static-pull');
|
||||
useUser();
|
||||
useTeams('team_dummy');
|
||||
useProject({
|
||||
...defaultProject,
|
||||
id: 'vercel-pull-next',
|
||||
name: 'vercel-pull-next',
|
||||
});
|
||||
const envFilePath = join(cwd, '.vercel', '.env.production.local');
|
||||
const projectJsonPath = join(cwd, '.vercel', 'project.json');
|
||||
const originalProjectJson = await fs.readJSON(
|
||||
join(cwd, '.vercel/project.json')
|
||||
);
|
||||
try {
|
||||
process.chdir(cwd);
|
||||
client.setArgv('build', '--yes', '--prod');
|
||||
const exitCode = await build(client);
|
||||
expect(exitCode).toEqual(0);
|
||||
|
||||
const prodEnv = await fs.readFile(envFilePath, 'utf8');
|
||||
const envFileHasProductionEnv1 = prodEnv.includes(
|
||||
'REDIS_CONNECTION_STRING'
|
||||
);
|
||||
expect(envFileHasProductionEnv1).toBeTruthy();
|
||||
const envFileHasProductionEnv2 = prodEnv.includes(
|
||||
'SQL_CONNECTION_STRING'
|
||||
);
|
||||
expect(envFileHasProductionEnv2).toBeTruthy();
|
||||
} finally {
|
||||
await fs.remove(envFilePath);
|
||||
await fs.writeJSON(projectJsonPath, originalProjectJson, { spaces: 2 });
|
||||
process.chdir(originalCwd);
|
||||
delete process.env.__VERCEL_BUILD_RUNNING;
|
||||
}
|
||||
});
|
||||
|
||||
it('should build root-level `middleware.js` and exclude from static files', async () => {
|
||||
const cwd = fixture('middleware');
|
||||
const output = join(cwd, '.vercel/output');
|
||||
try {
|
||||
process.chdir(cwd);
|
||||
const exitCode = await build(client);
|
||||
expect(exitCode).toEqual(0);
|
||||
|
||||
// `builds.json` says that "@vercel/static" was run
|
||||
const builds = await fs.readJSON(join(output, 'builds.json'));
|
||||
expect(builds).toMatchObject({
|
||||
target: 'preview',
|
||||
builds: [
|
||||
{
|
||||
require: '@vercel/node',
|
||||
apiVersion: 3,
|
||||
use: '@vercel/node',
|
||||
src: 'middleware.js',
|
||||
config: {
|
||||
zeroConfig: true,
|
||||
middleware: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
require: '@vercel/static',
|
||||
apiVersion: 2,
|
||||
use: '@vercel/static',
|
||||
src: '!{api/**,package.json,middleware.[jt]s}',
|
||||
config: {
|
||||
zeroConfig: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// `config.json` includes the "middlewarePath" route
|
||||
const config = await fs.readJSON(join(output, 'config.json'));
|
||||
expect(config).toMatchObject({
|
||||
version: 3,
|
||||
routes: [
|
||||
{ src: '/.*', middlewarePath: 'middleware', continue: true },
|
||||
{ handle: 'filesystem' },
|
||||
{ src: '^/api(/.*)?$', status: 404 },
|
||||
{ handle: 'error' },
|
||||
{ status: 404, src: '^(?!/api).*$', dest: '/404.html' },
|
||||
],
|
||||
});
|
||||
|
||||
// "static" directory contains `index.html`, but *not* `middleware.js`
|
||||
const staticFiles = await fs.readdir(join(output, 'static'));
|
||||
expect(staticFiles.sort()).toEqual(['index.html']);
|
||||
|
||||
// "functions" directory contains `middleware.func`
|
||||
const functions = await fs.readdir(join(output, 'functions'));
|
||||
expect(functions.sort()).toEqual(['middleware.func']);
|
||||
} finally {
|
||||
process.chdir(originalCwd);
|
||||
delete process.env.__VERCEL_BUILD_RUNNING;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/client",
|
||||
"version": "12.0.1-canary.0",
|
||||
"version": "12.0.2-canary.0",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"homepage": "https://vercel.com",
|
||||
@@ -42,7 +42,7 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "4.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"@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.1-canary.0",
|
||||
"version": "2.0.2-canary.0",
|
||||
"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.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"async-retry": "1.3.1",
|
||||
"execa": "^1.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/next",
|
||||
"version": "3.0.1-canary.0",
|
||||
"version": "3.0.2-canary.0",
|
||||
"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.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"@vercel/nft": "0.19.1",
|
||||
"@vercel/routing-utils": "1.13.4",
|
||||
"async-sema": "3.0.1",
|
||||
|
||||
@@ -2,23 +2,6 @@ const KIB = 1024;
|
||||
const MIB = 1024 * KIB;
|
||||
|
||||
/**
|
||||
* The limit after compression. it has to be kibibyte instead of kilobyte
|
||||
* See https://github.com/cloudflare/wrangler/blob/8907b12add3d70ee21ac597b69cd66f6807571f4/src/wranglerjs/output.rs#L44
|
||||
* The maximum size of a *compressed* edge function.
|
||||
*/
|
||||
const EDGE_FUNCTION_SCRIPT_SIZE_LIMIT = MIB;
|
||||
|
||||
/**
|
||||
* This safety buffer must cover the size of our whole runtime layer compressed
|
||||
* plus some extra space to allow it to grow in the future. At the time of
|
||||
* writing this comment the compressed size size is ~7KiB so 20KiB should
|
||||
* be more than enough.
|
||||
*/
|
||||
const EDGE_FUNCTION_SCRIPT_SIZE_BUFFER = 20 * KIB;
|
||||
|
||||
/**
|
||||
* The max size we allow for compressed user code is the compressed script
|
||||
* limit minus the compressed safety buffer. We must check this limit after
|
||||
* compressing the user code.
|
||||
*/
|
||||
export const EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT =
|
||||
EDGE_FUNCTION_SCRIPT_SIZE_LIMIT - EDGE_FUNCTION_SCRIPT_SIZE_BUFFER;
|
||||
export const EDGE_FUNCTION_SIZE_LIMIT = MIB;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { readFile } from 'fs-extra';
|
||||
import { ConcatSource, Source } from 'webpack-sources';
|
||||
import { fileToSource, raw, sourcemapped } from '../sourcemapped';
|
||||
import { join } from 'path';
|
||||
import { EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT } from './constants';
|
||||
import { EDGE_FUNCTION_SIZE_LIMIT } from './constants';
|
||||
import zlib from 'zlib';
|
||||
import { promisify } from 'util';
|
||||
import bytes from 'pretty-bytes';
|
||||
@@ -74,11 +74,11 @@ function getWasmImportStatements(wasm: { name: string }[] = []) {
|
||||
|
||||
async function validateScript(content: string) {
|
||||
const gzipped = await gzip(content);
|
||||
if (gzipped.length > EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT) {
|
||||
if (gzipped.length > EDGE_FUNCTION_SIZE_LIMIT) {
|
||||
throw new Error(
|
||||
`Exceeds maximum edge function script size: ${bytes(
|
||||
gzipped.length
|
||||
)} / ${bytes(EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT)}`
|
||||
)} / ${bytes(EDGE_FUNCTION_SIZE_LIMIT)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import {
|
||||
getExportStatus,
|
||||
getFilesMapFromReasons,
|
||||
getImagesManifest,
|
||||
getMiddlewareManifest,
|
||||
getNextConfig,
|
||||
getPageLambdaGroups,
|
||||
getPrerenderManifest,
|
||||
@@ -77,6 +78,7 @@ import {
|
||||
updateRouteSrc,
|
||||
validateEntrypoint,
|
||||
} from './utils';
|
||||
import assert from 'assert';
|
||||
|
||||
export const version = 2;
|
||||
export const htmlContentType = 'text/html; charset=utf-8';
|
||||
@@ -1001,7 +1003,11 @@ export const build: BuildV2 = async ({
|
||||
buildId,
|
||||
'pages'
|
||||
);
|
||||
const pages = await glob('**/!(_middleware).js', pagesDir);
|
||||
const pages = await getServerlessPages({
|
||||
pagesDir,
|
||||
entryPath,
|
||||
outputDirectory,
|
||||
});
|
||||
const launcherPath = path.join(__dirname, 'legacy-launcher.js');
|
||||
const launcherData = await readFile(launcherPath, 'utf8');
|
||||
|
||||
@@ -1074,7 +1080,11 @@ export const build: BuildV2 = async ({
|
||||
'pages'
|
||||
);
|
||||
|
||||
const pages = await glob('**/!(_middleware).js', pagesDir);
|
||||
const pages = await getServerlessPages({
|
||||
pagesDir,
|
||||
entryPath,
|
||||
outputDirectory,
|
||||
});
|
||||
const isApiPage = (page: string) =>
|
||||
page
|
||||
.replace(/\\/g, '/')
|
||||
@@ -1284,6 +1294,7 @@ export const build: BuildV2 = async ({
|
||||
entryPath,
|
||||
baseDir,
|
||||
dataRoutes,
|
||||
buildId,
|
||||
escapedBuildId,
|
||||
outputDirectory,
|
||||
trailingSlashRedirects,
|
||||
@@ -2575,3 +2586,32 @@ export const prepareCache: PrepareCache = async ({
|
||||
debug('Cache file manifest produced');
|
||||
return cache;
|
||||
};
|
||||
|
||||
async function getServerlessPages(params: {
|
||||
pagesDir: string;
|
||||
entryPath: string;
|
||||
outputDirectory: string;
|
||||
}) {
|
||||
const [pages, middlewareManifest] = await Promise.all([
|
||||
glob('**/!(_middleware).js', params.pagesDir),
|
||||
getMiddlewareManifest(params.entryPath, params.outputDirectory),
|
||||
]);
|
||||
|
||||
// Edge Functions do not consider as Serverless Functions
|
||||
for (const edgeFunctionFile of Object.keys(
|
||||
middlewareManifest?.functions ?? {}
|
||||
)) {
|
||||
// `getStaticProps` are expecting `Prerender` output which is a Serverless function
|
||||
// and not an Edge Function. Therefore we only remove API endpoints for now, as they
|
||||
// don't have `getStaticProps`.
|
||||
//
|
||||
// Context: https://github.com/vercel/vercel/pull/7905#discussion_r890213165
|
||||
assert(
|
||||
edgeFunctionFile.startsWith('/api/'),
|
||||
`Only API endpoints are currently supported for Edge endpoints.`
|
||||
);
|
||||
delete pages[edgeFunctionFile.slice(1) + '.js'];
|
||||
}
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import prettyBytes from 'pretty-bytes';
|
||||
// related PR: https://github.com/vercel/next.js/pull/30046
|
||||
const CORRECT_NOT_FOUND_ROUTES_VERSION = 'v12.0.1';
|
||||
const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
|
||||
const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
|
||||
|
||||
export async function serverBuild({
|
||||
dynamicPages,
|
||||
@@ -65,6 +66,7 @@ export async function serverBuild({
|
||||
workPath,
|
||||
entryPath,
|
||||
nodeVersion,
|
||||
buildId,
|
||||
escapedBuildId,
|
||||
dynamicPrefix,
|
||||
entryDirectory,
|
||||
@@ -101,6 +103,7 @@ export async function serverBuild({
|
||||
privateOutputs: { files: Files; routes: Route[] };
|
||||
entryPath: string;
|
||||
dynamicPrefix: string;
|
||||
buildId: string;
|
||||
escapedBuildId: string;
|
||||
wildcardConfig: BuildResult['wildcard'];
|
||||
nodeVersion: NodeVersion;
|
||||
@@ -796,6 +799,10 @@ export async function serverBuild({
|
||||
isCorrectMiddlewareOrder,
|
||||
});
|
||||
|
||||
const isNextDataServerResolving =
|
||||
middleware.staticRoutes.length > 0 &&
|
||||
semver.gte(nextVersion, NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION);
|
||||
|
||||
const dynamicRoutes = await getDynamicRoutes(
|
||||
entryPath,
|
||||
entryDirectory,
|
||||
@@ -876,6 +883,53 @@ export async function serverBuild({
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeNextDataRoute = isNextDataServerResolving
|
||||
? [
|
||||
// strip _next/data prefix for resolving
|
||||
{
|
||||
src: `^${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
'/_next/data/',
|
||||
escapedBuildId,
|
||||
'/(.*).json'
|
||||
)}`,
|
||||
dest: `${path.join('/', entryDirectory, '/$1')}`,
|
||||
continue: true,
|
||||
override: true,
|
||||
has: [
|
||||
{
|
||||
type: 'header',
|
||||
key: 'x-nextjs-data',
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
: [];
|
||||
|
||||
const denormalizeNextDataRoute = isNextDataServerResolving
|
||||
? [
|
||||
{
|
||||
src: '/(.*)',
|
||||
has: [
|
||||
{
|
||||
type: 'header',
|
||||
key: 'x-nextjs-data',
|
||||
},
|
||||
],
|
||||
dest: `${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
'/_next/data/',
|
||||
buildId,
|
||||
'/$1.json'
|
||||
)}`,
|
||||
continue: true,
|
||||
override: true,
|
||||
},
|
||||
]
|
||||
: [];
|
||||
|
||||
return {
|
||||
wildcard: wildcardConfig,
|
||||
images:
|
||||
@@ -900,6 +954,15 @@ export async function serverBuild({
|
||||
...staticDirectoryFiles,
|
||||
...privateOutputs.files,
|
||||
...middleware.edgeFunctions,
|
||||
...(isNextDataServerResolving
|
||||
? {
|
||||
__next_data_catchall: new FileBlob({
|
||||
contentType: 'application/json',
|
||||
mode: 0o644,
|
||||
data: '{}',
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
routes: [
|
||||
/*
|
||||
@@ -919,6 +982,9 @@ export async function serverBuild({
|
||||
|
||||
...privateOutputs.routes,
|
||||
|
||||
// normalize _next/data URL before processing redirects
|
||||
...normalizeNextDataRoute,
|
||||
|
||||
...(i18n
|
||||
? [
|
||||
// Handle auto-adding current default locale to path based on
|
||||
@@ -1077,6 +1143,9 @@ export async function serverBuild({
|
||||
},
|
||||
]),
|
||||
|
||||
// we need to undo _next/data normalize before checking filesystem
|
||||
...denormalizeNextDataRoute,
|
||||
|
||||
// while middleware was in beta the order came right before
|
||||
// handle: 'filesystem' we maintain this for older versions
|
||||
// to prevent a local/deploy mismatch
|
||||
@@ -1098,13 +1167,20 @@ export async function serverBuild({
|
||||
]
|
||||
: []),
|
||||
|
||||
// No-op _next/data rewrite to trigger handle: 'rewrites' and then 404
|
||||
// if no match to prevent rewriting _next/data unexpectedly
|
||||
{
|
||||
src: path.join('/', entryDirectory, '_next/data/(.*)'),
|
||||
dest: path.join('/', entryDirectory, '_next/data/$1'),
|
||||
check: true,
|
||||
},
|
||||
// normalize _next/data URL before processing rewrites
|
||||
...normalizeNextDataRoute,
|
||||
|
||||
...(!isNextDataServerResolving
|
||||
? [
|
||||
// No-op _next/data rewrite to trigger handle: 'rewrites' and then 404
|
||||
// if no match to prevent rewriting _next/data unexpectedly
|
||||
{
|
||||
src: path.join('/', entryDirectory, '_next/data/(.*)'),
|
||||
dest: path.join('/', entryDirectory, '_next/data/$1'),
|
||||
check: true,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
||||
// These need to come before handle: miss or else they are grouped
|
||||
// with that routing section
|
||||
@@ -1163,21 +1239,45 @@ export async function serverBuild({
|
||||
// if there no rewrites
|
||||
{ handle: 'rewrite' },
|
||||
|
||||
// re-build /_next/data URL after resolving
|
||||
...denormalizeNextDataRoute,
|
||||
|
||||
// /_next/data routes for getServerProps/getStaticProps pages
|
||||
...dataRoutes,
|
||||
|
||||
// ensure we 404 for non-existent _next/data routes before
|
||||
// trying page dynamic routes
|
||||
{
|
||||
src: path.join('/', entryDirectory, '_next/data/(.*)'),
|
||||
dest: path.join('/', entryDirectory, '404'),
|
||||
status: 404,
|
||||
},
|
||||
...(!isNextDataServerResolving
|
||||
? [
|
||||
// ensure we 404 for non-existent _next/data routes before
|
||||
// trying page dynamic routes
|
||||
{
|
||||
src: path.join('/', entryDirectory, '_next/data/(.*)'),
|
||||
dest: path.join('/', entryDirectory, '404'),
|
||||
status: 404,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
||||
// Dynamic routes (must come after dataRoutes as dataRoutes are more
|
||||
// specific)
|
||||
...dynamicRoutes,
|
||||
|
||||
...(isNextDataServerResolving
|
||||
? [
|
||||
// add a catch-all data route so we don't 404 when getting
|
||||
// middleware effects
|
||||
{
|
||||
src: `^${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
'/_next/data/',
|
||||
escapedBuildId,
|
||||
'/(.*).json'
|
||||
)}`,
|
||||
dest: '__next_data_catchall',
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
||||
// routes to call after a file has been matched
|
||||
{ handle: 'hit' },
|
||||
// Before we handle static files we need to set proper caching headers
|
||||
|
||||
@@ -2124,12 +2124,11 @@ export {
|
||||
interface MiddlewareManifest {
|
||||
version: 1;
|
||||
sortedMiddleware: string[];
|
||||
middleware: {
|
||||
[page: string]: MiddlewareInfo;
|
||||
};
|
||||
middleware: { [page: string]: EdgeFunctionInfo };
|
||||
functions?: { [page: string]: EdgeFunctionInfo };
|
||||
}
|
||||
|
||||
interface MiddlewareInfo {
|
||||
interface EdgeFunctionInfo {
|
||||
env: string[];
|
||||
files: string[];
|
||||
name: string;
|
||||
@@ -2153,16 +2152,34 @@ export async function getMiddlewareBundle({
|
||||
entryPath,
|
||||
outputDirectory
|
||||
);
|
||||
const sortedFunctions = [
|
||||
...(!middlewareManifest
|
||||
? []
|
||||
: middlewareManifest.sortedMiddleware.map(key => ({
|
||||
key,
|
||||
edgeFunction: middlewareManifest?.middleware[key],
|
||||
type: 'middleware' as const,
|
||||
}))),
|
||||
|
||||
if (middlewareManifest && middlewareManifest?.sortedMiddleware.length > 0) {
|
||||
...Object.entries(middlewareManifest?.functions ?? {}).map(
|
||||
([key, edgeFunction]) => {
|
||||
return {
|
||||
key,
|
||||
edgeFunction,
|
||||
type: 'function' as const,
|
||||
};
|
||||
}
|
||||
),
|
||||
];
|
||||
|
||||
if (middlewareManifest && sortedFunctions.length > 0) {
|
||||
const workerConfigs = await Promise.all(
|
||||
middlewareManifest.sortedMiddleware.map(async key => {
|
||||
const middleware = middlewareManifest.middleware[key];
|
||||
sortedFunctions.map(async ({ key, edgeFunction, type }) => {
|
||||
try {
|
||||
const wrappedModuleSource = await getNextjsEdgeFunctionSource(
|
||||
middleware.files,
|
||||
edgeFunction.files,
|
||||
{
|
||||
name: middleware.name,
|
||||
name: edgeFunction.name,
|
||||
staticRoutes: routesManifest.staticRoutes,
|
||||
dynamicRoutes: routesManifest.dynamicRoutes.filter(
|
||||
r => !('isMiddleware' in r)
|
||||
@@ -2173,18 +2190,19 @@ export async function getMiddlewareBundle({
|
||||
},
|
||||
},
|
||||
path.resolve(entryPath, outputDirectory),
|
||||
middleware.wasm
|
||||
edgeFunction.wasm
|
||||
);
|
||||
|
||||
return {
|
||||
page: middlewareManifest.middleware[key].page,
|
||||
type,
|
||||
page: edgeFunction.page,
|
||||
edgeFunction: (() => {
|
||||
const { source, map } = wrappedModuleSource.sourceAndMap();
|
||||
const transformedMap = stringifySourceMap(
|
||||
transformSourceMap(map)
|
||||
);
|
||||
|
||||
const wasmFiles = (middleware.wasm ?? []).reduce(
|
||||
const wasmFiles = (edgeFunction.wasm ?? []).reduce(
|
||||
(acc: Files, { filePath, name }) => {
|
||||
const fullFilePath = path.join(
|
||||
entryPath,
|
||||
@@ -2203,7 +2221,7 @@ export async function getMiddlewareBundle({
|
||||
|
||||
return new EdgeFunction({
|
||||
deploymentTarget: 'v8-worker',
|
||||
name: middleware.name,
|
||||
name: edgeFunction.name,
|
||||
files: {
|
||||
'index.js': new FileBlob({
|
||||
data: source,
|
||||
@@ -2220,13 +2238,10 @@ export async function getMiddlewareBundle({
|
||||
...wasmFiles,
|
||||
},
|
||||
entrypoint: 'index.js',
|
||||
envVarsInUse: middleware.env,
|
||||
envVarsInUse: edgeFunction.env,
|
||||
});
|
||||
})(),
|
||||
routeSrc: getRouteSrc(
|
||||
middlewareManifest.middleware[key],
|
||||
routesManifest
|
||||
),
|
||||
routeSrc: getRouteSrc(edgeFunction, routesManifest),
|
||||
};
|
||||
} catch (e: any) {
|
||||
e.message = `Can't build edge function ${key}: ${e.message}`;
|
||||
@@ -2247,16 +2262,21 @@ export async function getMiddlewareBundle({
|
||||
|
||||
for (const worker of workerConfigs.values()) {
|
||||
const edgeFile = worker.edgeFunction.name;
|
||||
worker.edgeFunction.name = edgeFile.replace(/^pages\//, '');
|
||||
source.edgeFunctions[edgeFile] = worker.edgeFunction;
|
||||
const route: Source = {
|
||||
const shortPath = edgeFile.replace(/^pages\//, '');
|
||||
worker.edgeFunction.name = shortPath;
|
||||
source.edgeFunctions[shortPath] = worker.edgeFunction;
|
||||
const route: Route = {
|
||||
continue: true,
|
||||
middlewarePath: edgeFile,
|
||||
src: worker.routeSrc,
|
||||
};
|
||||
|
||||
if (isCorrectMiddlewareOrder) {
|
||||
route.override = true;
|
||||
if (worker.type === 'function') {
|
||||
route.dest = shortPath;
|
||||
} else {
|
||||
route.middlewarePath = shortPath;
|
||||
if (isCorrectMiddlewareOrder) {
|
||||
route.override = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
|
||||
@@ -2281,7 +2301,7 @@ export async function getMiddlewareBundle({
|
||||
* location. If the manifest can't be found it will resolve to
|
||||
* undefined.
|
||||
*/
|
||||
async function getMiddlewareManifest(
|
||||
export async function getMiddlewareManifest(
|
||||
entryPath: string,
|
||||
outputDirectory: string
|
||||
): Promise<MiddlewareManifest | undefined> {
|
||||
@@ -2313,7 +2333,7 @@ async function getMiddlewareManifest(
|
||||
* @returns A regexp string for the middleware route.
|
||||
*/
|
||||
function getRouteSrc(
|
||||
{ regexp, page }: MiddlewareInfo,
|
||||
{ regexp, page }: EdgeFunctionInfo,
|
||||
{ basePath = '', i18n }: RoutesManifest
|
||||
): string {
|
||||
if (page === '/') {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/node",
|
||||
"version": "2.0.2-canary.0",
|
||||
"version": "2.1.1-canary.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
||||
@@ -45,10 +45,10 @@
|
||||
"@types/etag": "1.8.0",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/test-listen": "1.1.0",
|
||||
"@vercel/build-utils": "4.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/nft": "0.19.1",
|
||||
"@vercel/static-config": "2.0.1-canary.0",
|
||||
"@vercel/static-config": "2.0.1",
|
||||
"content-type": "1.0.4",
|
||||
"cookie": "0.4.0",
|
||||
"etag": "1.8.1",
|
||||
|
||||
@@ -373,36 +373,60 @@ export const build: BuildV3 = async ({
|
||||
);
|
||||
debug(`Trace complete [${Date.now() - traceTime}ms]`);
|
||||
|
||||
const project = new Project();
|
||||
const staticConfig = getConfig(project, entrypointPath);
|
||||
|
||||
let routes: BuildResultV3['routes'];
|
||||
let output: BuildResultV3['output'] | undefined;
|
||||
|
||||
const handler = renameTStoJS(relative(baseDir, entrypointPath));
|
||||
const outputName = config.zeroConfig
|
||||
? handler.substring(0, handler.length - 3)
|
||||
: handler;
|
||||
|
||||
if (staticConfig?.runtime) {
|
||||
if (!ALLOWED_RUNTIMES.includes(staticConfig.runtime)) {
|
||||
throw new Error(
|
||||
`Unsupported "runtime" property in \`config\`: ${JSON.stringify(
|
||||
staticConfig.runtime
|
||||
)} (must be one of: ${JSON.stringify(ALLOWED_RUNTIMES)})`
|
||||
);
|
||||
}
|
||||
if (staticConfig.runtime === 'experimental-edge') {
|
||||
const name = config.zeroConfig
|
||||
? handler.substring(0, handler.length - 3)
|
||||
: handler;
|
||||
output = new EdgeFunction({
|
||||
entrypoint: handler,
|
||||
files: preparedFiles,
|
||||
// Will output an `EdgeFunction` for when `config.middleware = true`
|
||||
// (i.e. for root-level "middleware" file) or if source code contains:
|
||||
// `export const config = { runtime: 'experimental-edge' }`
|
||||
let isEdgeFunction = false;
|
||||
|
||||
// TODO: remove - these two properties should not be required
|
||||
name,
|
||||
deploymentTarget: 'v8-worker',
|
||||
});
|
||||
// Add a catch-all `route` for Middleware
|
||||
if (config.middleware === true) {
|
||||
routes = [
|
||||
{
|
||||
src: '/.*',
|
||||
middlewarePath: config.zeroConfig
|
||||
? outputName
|
||||
: relative(baseDir, entrypointPath),
|
||||
continue: true,
|
||||
},
|
||||
];
|
||||
|
||||
// Middleware is implicitly an Edge Function
|
||||
isEdgeFunction = true;
|
||||
}
|
||||
|
||||
if (!isEdgeFunction) {
|
||||
const project = new Project();
|
||||
const staticConfig = getConfig(project, entrypointPath);
|
||||
if (staticConfig?.runtime) {
|
||||
if (!ALLOWED_RUNTIMES.includes(staticConfig.runtime)) {
|
||||
throw new Error(
|
||||
`Unsupported "runtime" property in \`config\`: ${JSON.stringify(
|
||||
staticConfig.runtime
|
||||
)} (must be one of: ${JSON.stringify(ALLOWED_RUNTIMES)})`
|
||||
);
|
||||
}
|
||||
isEdgeFunction = staticConfig.runtime === 'experimental-edge';
|
||||
}
|
||||
}
|
||||
|
||||
if (!output) {
|
||||
if (isEdgeFunction) {
|
||||
output = new EdgeFunction({
|
||||
entrypoint: handler,
|
||||
files: preparedFiles,
|
||||
|
||||
// TODO: remove - these two properties should not be required
|
||||
name: outputName,
|
||||
deploymentTarget: 'v8-worker',
|
||||
});
|
||||
} else {
|
||||
// "nodejs" runtime is the default
|
||||
const shouldAddHelpers = !(
|
||||
config.helpers === false || process.env.NODEJS_HELPERS === '0'
|
||||
@@ -418,7 +442,7 @@ export const build: BuildV3 = async ({
|
||||
});
|
||||
}
|
||||
|
||||
return { output };
|
||||
return { routes, output };
|
||||
};
|
||||
|
||||
export const prepareCache: PrepareCache = ({ repoRootPath, workPath }) => {
|
||||
|
||||
7
packages/node/test/fixtures/62-edge-middleware/api/edge.js
vendored
Normal file
7
packages/node/test/fixtures/62-edge-middleware/api/edge.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export const config = {
|
||||
runtime: 'experimental-edge',
|
||||
};
|
||||
|
||||
export default req => {
|
||||
return new Response(`RANDOMNESS_PLACEHOLDER:edge`);
|
||||
};
|
||||
14
packages/node/test/fixtures/62-edge-middleware/middleware.ts
vendored
Normal file
14
packages/node/test/fixtures/62-edge-middleware/middleware.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
export default (req: Request) => {
|
||||
const url = new URL(req.url);
|
||||
const headers = new Headers({
|
||||
'x-got-middleware': 'true',
|
||||
});
|
||||
if (url.pathname === '/' || url.pathname.startsWith('/api/')) {
|
||||
// For `index.html` and `/api/edge.js`, pass through
|
||||
headers.set('x-middleware-next', '1');
|
||||
return new Response(null, { headers });
|
||||
} else {
|
||||
// For everything else, serve a custom response
|
||||
return new Response(`RANDOMNESS_PLACEHOLDER:middleware`, { headers });
|
||||
}
|
||||
};
|
||||
26
packages/node/test/fixtures/62-edge-middleware/vercel.json
vendored
Normal file
26
packages/node/test/fixtures/62-edge-middleware/vercel.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"builds": [
|
||||
{ "src": "api/**/*.js", "use": "@vercel/node" },
|
||||
{
|
||||
"src": "middleware.ts",
|
||||
"use": "@vercel/node",
|
||||
"config": { "middleware": true }
|
||||
}
|
||||
],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/api/edge.js",
|
||||
"mustContain": "RANDOMNESS_PLACEHOLDER:edge",
|
||||
"responseHeaders": {
|
||||
"x-got-middleware": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/non-exist",
|
||||
"mustContain": "RANDOMNESS_PLACEHOLDER:middleware",
|
||||
"responseHeaders": {
|
||||
"x-got-middleware": "true"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/python",
|
||||
"version": "3.0.1-canary.0",
|
||||
"version": "3.0.2-canary.0",
|
||||
"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.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"execa": "^1.0.0",
|
||||
"typescript": "4.3.4"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/redwood",
|
||||
"version": "1.0.1-canary.0",
|
||||
"version": "1.0.2-canary.0",
|
||||
"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.0.1-canary.0"
|
||||
"@vercel/build-utils": "4.1.1-canary.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/remix",
|
||||
"version": "1.0.1-canary.0",
|
||||
"version": "1.0.2-canary.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"homepage": "https://vercel.com/docs",
|
||||
@@ -27,7 +27,7 @@
|
||||
"devDependencies": {
|
||||
"@types/jest": "27.5.1",
|
||||
"@types/node": "*",
|
||||
"@vercel/build-utils": "4.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"typescript": "4.6.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@vercel/ruby",
|
||||
"author": "Nathan Cahill <nathan@nathancahill.com>",
|
||||
"version": "1.3.9-canary.0",
|
||||
"version": "1.3.10-canary.0",
|
||||
"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.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"@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.1-canary.0",
|
||||
"version": "1.0.2-canary.0",
|
||||
"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.0.1-canary.0",
|
||||
"@vercel/build-utils": "4.1.1-canary.0",
|
||||
"@vercel/frameworks": "1.0.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/routing-utils": "1.13.4",
|
||||
|
||||
@@ -50,6 +50,11 @@ export function createBuildOutput(
|
||||
else if (framework) buildCommandName = framework.name;
|
||||
else buildCommandName = 'the "build" script';
|
||||
|
||||
if (meta.isDev) {
|
||||
throw new Error(
|
||||
`Detected Build Output v3 from ${buildCommandName}, but it is not supported for \`vercel dev\`. Please set the Development Command in your Project Settings.`
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
`Detected Build Output v3 from ${buildCommandName}, but this Deployment is not using \`vercel build\`.\nPlease set the \`ENABLE_VC_BUILD=1\` environment variable.`
|
||||
);
|
||||
|
||||
32
packages/static-build/test/build.test.ts
vendored
32
packages/static-build/test/build.test.ts
vendored
@@ -17,6 +17,7 @@ describe('build()', () => {
|
||||
const buildResult = await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
repoRootPath: workPath,
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
@@ -46,6 +47,7 @@ describe('build()', () => {
|
||||
const buildResult = await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
repoRootPath: workPath,
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
@@ -76,6 +78,7 @@ describe('build()', () => {
|
||||
const buildResult = await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
repoRootPath: workPath,
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
@@ -105,6 +108,7 @@ describe('build()', () => {
|
||||
const buildResult = await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
repoRootPath: workPath,
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
@@ -132,6 +136,7 @@ describe('build()', () => {
|
||||
await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
repoRootPath: workPath,
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
@@ -145,5 +150,32 @@ describe('build()', () => {
|
||||
`Detected Build Output v3 from the "build" script, but this Deployment is not using \`vercel build\`.\nPlease set the \`ENABLE_VC_BUILD=1\` environment variable.`
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an Error when `vercel dev` is used with `@vercel/static-build`', async () => {
|
||||
let err;
|
||||
const workPath = path.join(
|
||||
__dirname,
|
||||
'build-fixtures',
|
||||
'09-build-output-v3'
|
||||
);
|
||||
try {
|
||||
await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
repoRootPath: workPath,
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
skipDownload: true,
|
||||
isDev: true,
|
||||
},
|
||||
});
|
||||
} catch (_err: any) {
|
||||
err = _err;
|
||||
}
|
||||
expect(err.message).toEqual(
|
||||
`Detected Build Output v3 from the "build" script, but it is not supported for \`vercel dev\`. Please set the Development Command in your Project Settings.`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/static-config",
|
||||
"version": "2.0.1-canary.0",
|
||||
"version": "2.0.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user