mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-24 11:49:13 +00:00
Compare commits
8 Commits
@now/pytho
...
@now/frame
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b88c158b9 | ||
|
|
ec3a38107a | ||
|
|
0c0f1c6eb5 | ||
|
|
ed296ef733 | ||
|
|
246f47ec95 | ||
|
|
9d95b99b72 | ||
|
|
3de8ae9d7e | ||
|
|
44f6e1904e |
@@ -12,6 +12,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"next\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`next build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "next dev --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"placeholder": "Next.js default"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -27,6 +38,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"gatsby\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`gatsby build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "gatsby develop --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "public"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -41,6 +63,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"hexo\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`hexo generate` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "hexo server --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "public"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -55,6 +88,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"@11ty\\/eleventy\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`npx @11ty/eleventy` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "npx @11ty/eleventy --serve --watch --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "_site"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -73,6 +117,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"@docusaurus\\/core\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`docusaurus-build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "docusaurus-start --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "build"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -88,6 +143,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"preact-cli\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`preact build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "preact watch --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "build"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -102,6 +168,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"ember-cli\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`ember build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "ember serve --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "dist"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -117,6 +194,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"@vue\\/cli-service\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`vue-cli-service build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "vue-cli-service serve --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "dist"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -130,6 +218,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"@scullyio\\/init\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`ng build && scully` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "ng serve --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "dist"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -145,6 +244,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"@angular\\/cli\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`ng build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "ng serve --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "dist"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -159,6 +269,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"polymer-cli\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`polymer build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "polymer serve --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "build"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -174,6 +295,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"sirv-cli\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`rollup -c` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "sirv public --single --dev --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "public"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -193,6 +325,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"react-dev-utils\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`react-scripts build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "react-scripts start"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "build"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -207,6 +350,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"gridsome\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`gridsome build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "gridsome develop -p $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "dist"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -222,6 +376,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"umi\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`umi build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "umi dev --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "dist"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -237,6 +402,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"sapper\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`sapper export` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "sapper dev --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "__sapper__/export"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -251,6 +427,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"saber\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`saber build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "saber --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "public"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -265,6 +452,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"@stencil\\/core\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`stencil build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "stencil build --dev --watch --serve --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "www"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -280,6 +478,17 @@
|
||||
"matchContent": "\"(dev)?(d|D)ependencies\":\\s*{[^}]*\"nuxt\":\\s*\".+?\"[^}]*}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`nuxt build` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "nuxt"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "dist"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -300,6 +509,17 @@
|
||||
"file": "config.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"value": "hugo"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "hugo server -D -w -p $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"placeholder": "`public` or `publishDir` from the `config` file"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -313,6 +533,17 @@
|
||||
"file": "_config.yml"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"value": "jekyll build"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "bundle exec jekyll serve --watch --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"placeholder": "`_site` or `destination` from `_config.yml`"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -326,6 +557,17 @@
|
||||
"file": "brunch-config.js"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"placeholder": "`brunch build --production` or `build` from `package.json`"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "brunch watch --server --port $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "public"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -339,6 +581,17 @@
|
||||
"file": "config.rb"
|
||||
}
|
||||
]
|
||||
},
|
||||
"settings": {
|
||||
"buildCommand": {
|
||||
"value": "bundle exec middleman build"
|
||||
},
|
||||
"devCommand": {
|
||||
"value": "bundle exec middleman server -p $PORT"
|
||||
},
|
||||
"outputDirectory": {
|
||||
"value": "build"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
10
packages/frameworks/index.d.ts
vendored
10
packages/frameworks/index.d.ts
vendored
@@ -3,6 +3,11 @@ export interface FrameworkDetectionItem {
|
||||
matchContent?: string;
|
||||
}
|
||||
|
||||
interface Setting {
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
export interface Framework {
|
||||
name: string;
|
||||
slug: string;
|
||||
@@ -13,4 +18,9 @@ export interface Framework {
|
||||
every?: FrameworkDetectionItem[];
|
||||
some?: FrameworkDetectionItem[];
|
||||
};
|
||||
settings?: {
|
||||
buildCommand?: Setting;
|
||||
devCommand?: Setting;
|
||||
outputDirectory?: Setting;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/frameworks",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"main": "frameworks.json",
|
||||
"license": "UNLICENSED"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/build-utils",
|
||||
"version": "1.3.0",
|
||||
"version": "1.3.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { parse as parsePath } from 'path';
|
||||
import { Route, isHandler } from '@now/routing-utils';
|
||||
import { Route, Source } from '@now/routing-utils';
|
||||
import { Builder } from './types';
|
||||
import { getIgnoreApiFilter, sortFiles } from './detect-builders';
|
||||
|
||||
@@ -41,20 +41,26 @@ function getSegmentName(segment: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
function createRouteFromPath(filePath: string): Route {
|
||||
function createRouteFromPath(
|
||||
filePath: string,
|
||||
featHandleMiss: boolean,
|
||||
cleanUrls: boolean
|
||||
): { route: Source; isDynamic: boolean } {
|
||||
const parts = filePath.split('/');
|
||||
|
||||
let counter = 1;
|
||||
const query: string[] = [];
|
||||
let isDynamic = false;
|
||||
|
||||
const srcParts = parts.map((segment, index): string => {
|
||||
const srcParts = parts.map((segment, i): string => {
|
||||
const name = getSegmentName(segment);
|
||||
const isLast = index === parts.length - 1;
|
||||
const isLast = i === parts.length - 1;
|
||||
|
||||
if (name !== null) {
|
||||
// We can't use `URLSearchParams` because `$` would get escaped
|
||||
query.push(`${name}=$${counter++}`);
|
||||
return `([^\\/]+)`;
|
||||
isDynamic = true;
|
||||
return `([^/]+)`;
|
||||
} else if (isLast) {
|
||||
const { name: fileName, ext } = parsePath(segment);
|
||||
const isIndex = fileName === 'index';
|
||||
@@ -63,27 +69,43 @@ function createRouteFromPath(filePath: string): Route {
|
||||
const names = [
|
||||
isIndex ? prefix : `${fileName}\\/`,
|
||||
prefix + escapeName(fileName),
|
||||
prefix + escapeName(fileName) + escapeName(ext),
|
||||
featHandleMiss && cleanUrls
|
||||
? ''
|
||||
: prefix + escapeName(fileName) + escapeName(ext),
|
||||
].filter(Boolean);
|
||||
|
||||
// Either filename with extension, filename without extension
|
||||
// or nothing when the filename is `index`
|
||||
// or nothing when the filename is `index`.
|
||||
// When `cleanUrls: true` then do *not* add the filename with extension.
|
||||
return `(${names.join('|')})${isIndex ? '?' : ''}`;
|
||||
}
|
||||
|
||||
return segment;
|
||||
});
|
||||
|
||||
const { name: fileName } = parsePath(filePath);
|
||||
const { name: fileName, ext } = parsePath(filePath);
|
||||
const isIndex = fileName === 'index';
|
||||
const queryString = `${query.length ? '?' : ''}${query.join('&')}`;
|
||||
|
||||
const src = isIndex
|
||||
? `^/${srcParts.slice(0, -1).join('/')}${srcParts.slice(-1)[0]}$`
|
||||
: `^/${srcParts.join('/')}$`;
|
||||
|
||||
const dest = `/${filePath}${query.length ? '?' : ''}${query.join('&')}`;
|
||||
|
||||
return { src, dest };
|
||||
let route: Source;
|
||||
if (featHandleMiss) {
|
||||
const extensionless = ext ? filePath.slice(0, -ext.length) : filePath;
|
||||
route = {
|
||||
src,
|
||||
dest: `/${extensionless}${queryString}`,
|
||||
check: true,
|
||||
};
|
||||
} else {
|
||||
route = {
|
||||
src,
|
||||
dest: `/${filePath}${queryString}`,
|
||||
};
|
||||
}
|
||||
return { route, isDynamic };
|
||||
}
|
||||
|
||||
// Check if the path partially matches and has the same
|
||||
@@ -193,18 +215,30 @@ function sortFilesBySegmentCount(fileA: string, fileB: string): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
interface ApiRoutesResult {
|
||||
defaultRoutes: Source[] | null;
|
||||
dynamicRoutes: Source[] | null;
|
||||
error: { [key: string]: string } | null;
|
||||
}
|
||||
|
||||
interface RoutesResult {
|
||||
defaultRoutes: Route[] | null;
|
||||
redirectRoutes: Route[] | null;
|
||||
error: { [key: string]: string } | null;
|
||||
}
|
||||
|
||||
async function detectApiRoutes(
|
||||
files: string[],
|
||||
builders: Builder[],
|
||||
featHandleMiss: boolean
|
||||
): Promise<RoutesResult> {
|
||||
featHandleMiss: boolean,
|
||||
cleanUrls: boolean
|
||||
): Promise<ApiRoutesResult> {
|
||||
if (!files || files.length === 0) {
|
||||
return { defaultRoutes: null, error: null };
|
||||
return {
|
||||
defaultRoutes: null,
|
||||
dynamicRoutes: null,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
// The deepest routes need to be
|
||||
@@ -214,7 +248,8 @@ async function detectApiRoutes(
|
||||
.sort(sortFiles)
|
||||
.sort(sortFilesBySegmentCount);
|
||||
|
||||
let defaultRoutes: Route[] = [];
|
||||
const defaultRoutes: Source[] = [];
|
||||
const dynamicRoutes: Source[] = [];
|
||||
|
||||
for (const file of sortedFiles) {
|
||||
// We only consider every file in the api directory
|
||||
@@ -231,6 +266,7 @@ async function detectApiRoutes(
|
||||
if (conflictingSegment) {
|
||||
return {
|
||||
defaultRoutes: null,
|
||||
dynamicRoutes: null,
|
||||
error: {
|
||||
code: 'conflicting_path_segment',
|
||||
message:
|
||||
@@ -252,6 +288,7 @@ async function detectApiRoutes(
|
||||
|
||||
return {
|
||||
defaultRoutes: null,
|
||||
dynamicRoutes: null,
|
||||
error: {
|
||||
code: 'conflicting_file_path',
|
||||
message:
|
||||
@@ -262,39 +299,14 @@ async function detectApiRoutes(
|
||||
};
|
||||
}
|
||||
|
||||
defaultRoutes.push(createRouteFromPath(file));
|
||||
}
|
||||
|
||||
// 404 Route to disable directory listing
|
||||
if (defaultRoutes.length > 0) {
|
||||
if (featHandleMiss) {
|
||||
defaultRoutes = [
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '/api/(.+)\\.\\w+',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
];
|
||||
} else if (
|
||||
defaultRoutes.some(
|
||||
route =>
|
||||
!isHandler(route) && route.dest && route.dest.startsWith('/api/')
|
||||
)
|
||||
) {
|
||||
defaultRoutes.push({
|
||||
status: 404,
|
||||
src: '/api(/.*)?$',
|
||||
});
|
||||
const out = createRouteFromPath(file, featHandleMiss, cleanUrls);
|
||||
if (out.isDynamic) {
|
||||
dynamicRoutes.push(out.route);
|
||||
}
|
||||
defaultRoutes.push(out.route);
|
||||
}
|
||||
|
||||
return { defaultRoutes, error: null };
|
||||
return { defaultRoutes, dynamicRoutes, error: null };
|
||||
}
|
||||
|
||||
function getPublicBuilder(builders: Builder[]): Builder | null {
|
||||
@@ -319,17 +331,81 @@ export function detectOutputDirectory(builders: Builder[]): string | null {
|
||||
export async function detectRoutes(
|
||||
files: string[],
|
||||
builders: Builder[],
|
||||
featHandleMiss = false
|
||||
featHandleMiss = false,
|
||||
cleanUrls = false,
|
||||
trailingSlash?: boolean
|
||||
): Promise<RoutesResult> {
|
||||
const routesResult = await detectApiRoutes(files, builders, featHandleMiss);
|
||||
const result = await detectApiRoutes(
|
||||
files,
|
||||
builders,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
const { dynamicRoutes, defaultRoutes: allRoutes, error } = result;
|
||||
if (error) {
|
||||
return { defaultRoutes: null, redirectRoutes: null, error };
|
||||
}
|
||||
const directory = detectOutputDirectory(builders);
|
||||
const defaultRoutes: Route[] = [];
|
||||
const redirectRoutes: Route[] = [];
|
||||
if (allRoutes && allRoutes.length > 0) {
|
||||
const hasApiRoutes = allRoutes.some(
|
||||
r => r.dest && r.dest.startsWith('/api/')
|
||||
);
|
||||
if (featHandleMiss) {
|
||||
defaultRoutes.push({ handle: 'miss' });
|
||||
if (cleanUrls) {
|
||||
const extensions = builders
|
||||
.map(b => parsePath(b.src).ext)
|
||||
.filter(Boolean);
|
||||
if (extensions.length > 0) {
|
||||
const exts = extensions.map(ext => ext.slice(1)).join('|');
|
||||
const group = `(?:\\.(?:${exts}))`;
|
||||
redirectRoutes.push({
|
||||
src: `^/(api(?:.+)?)/index${group}?/?$`,
|
||||
headers: { Location: trailingSlash ? '/$1/' : '/$1' },
|
||||
status: 308,
|
||||
});
|
||||
redirectRoutes.push({
|
||||
src: `^/api/(.+)${group}/?$`,
|
||||
headers: { Location: trailingSlash ? '/api/$1/' : '/api/$1' },
|
||||
status: 308,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
defaultRoutes.push({
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
});
|
||||
}
|
||||
if (dynamicRoutes) {
|
||||
defaultRoutes.push(...dynamicRoutes);
|
||||
}
|
||||
if (hasApiRoutes) {
|
||||
defaultRoutes.push({
|
||||
src: '^/api(/.*)?$',
|
||||
status: 404,
|
||||
continue: true,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
defaultRoutes.push(...allRoutes);
|
||||
if (hasApiRoutes) {
|
||||
defaultRoutes.push({
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (routesResult.defaultRoutes && directory && !featHandleMiss) {
|
||||
routesResult.defaultRoutes.push({
|
||||
if (!featHandleMiss && directory) {
|
||||
defaultRoutes.push({
|
||||
src: '/(.*)',
|
||||
dest: `/${directory}/$1`,
|
||||
});
|
||||
}
|
||||
|
||||
return routesResult;
|
||||
return { defaultRoutes, redirectRoutes, error };
|
||||
}
|
||||
|
||||
18
packages/now-build-utils/src/errors.ts
Normal file
18
packages/now-build-utils/src/errors.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* This error should be thrown from a Builder in
|
||||
* order to stop the build and print a message.
|
||||
* This is necessary to avoid printing a stack trace.
|
||||
*/
|
||||
export class NowBuildError extends Error {
|
||||
public code: string;
|
||||
|
||||
constructor({ message, code }: Props) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
message: string;
|
||||
code: string;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { intersects } from 'semver';
|
||||
import boxen from 'boxen';
|
||||
import { NodeVersion } from '../types';
|
||||
import { NowBuildError } from '../errors';
|
||||
import debug from '../debug';
|
||||
|
||||
const allOptions: NodeVersion[] = [
|
||||
@@ -15,6 +16,11 @@ const allOptions: NodeVersion[] = [
|
||||
];
|
||||
|
||||
const supportedOptions = allOptions.filter(o => !isDiscontinued(o));
|
||||
const pleaseUse =
|
||||
'Please use one of the following supported ranges in your `package.json`: ';
|
||||
const upstreamProvider =
|
||||
'This change is the result of a decision made by an upstream infrastructure provider (AWS).' +
|
||||
'\nRead more: https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html';
|
||||
|
||||
export function getOldestNodeVersion(): NodeVersion {
|
||||
return allOptions[allOptions.length - 1];
|
||||
@@ -26,77 +32,85 @@ export function getLatestNodeVersion(): NodeVersion {
|
||||
|
||||
export async function getSupportedNodeVersion(
|
||||
engineRange?: string,
|
||||
silent?: boolean
|
||||
isAuto?: boolean
|
||||
): Promise<NodeVersion> {
|
||||
let selection = getOldestNodeVersion();
|
||||
|
||||
if (!engineRange) {
|
||||
if (!silent) {
|
||||
debug(
|
||||
'Missing `engines` in `package.json`, using default range: ' +
|
||||
selection.range
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (engineRange) {
|
||||
const found = allOptions.some(o => {
|
||||
// the array is already in order so return the first
|
||||
// match which will be the newest version of node
|
||||
selection = o;
|
||||
return intersects(o.range, engineRange);
|
||||
});
|
||||
const discontinued = isDiscontinued(selection);
|
||||
if (found && !discontinued) {
|
||||
if (!silent) {
|
||||
debug(
|
||||
'Found `engines` in `package.json`, selecting range: ' +
|
||||
selection.range
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
'Found `engines` in `package.json` with an unsupported Node.js version range: ' +
|
||||
engineRange +
|
||||
'\nPlease use one of the following supported ranges: ' +
|
||||
JSON.stringify(supportedOptions.map(o => o.range)) +
|
||||
(discontinued
|
||||
? '\nThis change is the result of a decision made by an upstream infrastructure provider (AWS).' +
|
||||
'\nRead more: https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html'
|
||||
: '')
|
||||
);
|
||||
if (!found) {
|
||||
const intro =
|
||||
isAuto || !engineRange
|
||||
? 'This project is using an invalid version of Node.js and must be changed.'
|
||||
: 'Found `engines` in `package.json` with an invalid Node.js version range: ' +
|
||||
engineRange;
|
||||
throw new NowBuildError({
|
||||
code: 'NOW_BUILD_UTILS_NODE_VERSION_INVALID',
|
||||
message:
|
||||
intro +
|
||||
'\n' +
|
||||
pleaseUse +
|
||||
JSON.stringify(supportedOptions.map(o => o.range)),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const { range, discontinueDate } = selection;
|
||||
if (discontinueDate && !isDiscontinued(selection)) {
|
||||
const d = discontinueDate.toISOString().split('T')[0];
|
||||
if (isDiscontinued(selection)) {
|
||||
const intro =
|
||||
isAuto || !engineRange
|
||||
? 'This project is using a discontinued version of Node.js and must be upgraded.'
|
||||
: 'Found `engines` in `package.json` with a discontinued Node.js version range: ' +
|
||||
engineRange;
|
||||
throw new NowBuildError({
|
||||
code: 'NOW_BUILD_UTILS_NODE_VERSION_DISCONTINUED',
|
||||
message:
|
||||
intro +
|
||||
'\n' +
|
||||
pleaseUse +
|
||||
JSON.stringify(supportedOptions.map(o => o.range)) +
|
||||
'\n' +
|
||||
upstreamProvider,
|
||||
});
|
||||
}
|
||||
|
||||
debug(
|
||||
isAuto || !engineRange
|
||||
? 'Using default Node.js range: ' + selection.range
|
||||
: (engineRange ? 'Found' : 'Missing') +
|
||||
' `engines` in `package.json`, selecting range: ' +
|
||||
selection.range
|
||||
);
|
||||
|
||||
if (selection.discontinueDate) {
|
||||
const d = selection.discontinueDate.toISOString().split('T')[0];
|
||||
const validRanges = supportedOptions
|
||||
.filter(o => !o.discontinueDate)
|
||||
.map(o => o.range);
|
||||
const prevTerm = process.env.TERM;
|
||||
if (!prevTerm) {
|
||||
// workaround for https://github.com/sindresorhus/term-size/issues/13
|
||||
process.env.TERM = 'xterm';
|
||||
}
|
||||
console.warn(
|
||||
boxen(
|
||||
'NOTICE' +
|
||||
'\n' +
|
||||
`\nNode.js version ${range} has reached end-of-life.` +
|
||||
`\nNode.js version ${selection.range} has reached end-of-life.` +
|
||||
`\nAs a result, deployments created on or after ${d} will fail to build.` +
|
||||
'\nPlease use one of the following supported `engines` in `package.json`: ' +
|
||||
'\n' +
|
||||
pleaseUse +
|
||||
JSON.stringify(validRanges) +
|
||||
'\nThis change is the result of a decision made by an upstream infrastructure provider (AWS).' +
|
||||
'\nRead more: https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html',
|
||||
'\n' +
|
||||
upstreamProvider,
|
||||
{ padding: 1 }
|
||||
)
|
||||
);
|
||||
process.env.TERM = prevTerm;
|
||||
}
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
function isDiscontinued({ discontinueDate }: NodeVersion): boolean {
|
||||
const today = new Date();
|
||||
return discontinueDate !== undefined && discontinueDate <= today;
|
||||
const today = Date.now();
|
||||
return discontinueDate !== undefined && discontinueDate.getTime() <= today;
|
||||
}
|
||||
|
||||
@@ -144,20 +144,20 @@ export async function getNodeVersion(
|
||||
): Promise<NodeVersion> {
|
||||
const { packageJson } = await scanParentDirs(destPath, true);
|
||||
let range: string | undefined;
|
||||
let silent = false;
|
||||
let isAuto = false;
|
||||
if (packageJson && packageJson.engines && packageJson.engines.node) {
|
||||
range = packageJson.engines.node;
|
||||
} else if (minNodeVersion) {
|
||||
range = minNodeVersion;
|
||||
silent = true;
|
||||
isAuto = true;
|
||||
} else if (config && config.nodeVersion) {
|
||||
range = config.nodeVersion;
|
||||
silent = true;
|
||||
isAuto = true;
|
||||
} else if (config && config.zeroConfig) {
|
||||
range = '10.x';
|
||||
silent = true;
|
||||
isAuto = true;
|
||||
}
|
||||
return getSupportedNodeVersion(range, silent);
|
||||
return getSupportedNodeVersion(range, isAuto);
|
||||
}
|
||||
|
||||
async function scanParentDirs(destPath: string, readPackageJson = false) {
|
||||
|
||||
@@ -66,3 +66,4 @@ export { readConfigFile } from './fs/read-config-file';
|
||||
|
||||
export * from './schemas';
|
||||
export * from './types';
|
||||
export * from './errors';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Source, Route } from '@now/routing-utils';
|
||||
import { detectBuilders, detectRoutes } from '../src';
|
||||
|
||||
describe('Test `detectBuilders`', () => {
|
||||
@@ -892,7 +893,7 @@ it('Test `detectRoutes`', async () => {
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes } = await detectRoutes(files, builders!);
|
||||
expect((defaultRoutes![2] as any).status).toBe(404);
|
||||
expect((defaultRoutes![2] as any).src).toBe('/api(/.*)?$');
|
||||
expect((defaultRoutes![2] as any).src).toBe('^/api(/.*)?$');
|
||||
expect((defaultRoutes![3] as any).src).toBe('/(.*)');
|
||||
expect((defaultRoutes![3] as any).dest).toBe('/public/$1');
|
||||
expect(defaultRoutes!.length).toBe(4);
|
||||
@@ -908,7 +909,7 @@ it('Test `detectRoutes`', async () => {
|
||||
const { builders } = await detectBuilders(files, pkg);
|
||||
const { defaultRoutes } = await detectRoutes(files, builders!);
|
||||
expect((defaultRoutes![1] as any).status).toBe(404);
|
||||
expect((defaultRoutes![1] as any).src).toBe('/api(/.*)?$');
|
||||
expect((defaultRoutes![1] as any).src).toBe('^/api(/.*)?$');
|
||||
expect(defaultRoutes!.length).toBe(2);
|
||||
}
|
||||
|
||||
@@ -946,7 +947,7 @@ it('Test `detectRoutes`', async () => {
|
||||
|
||||
expect(defaultRoutes!.length).toBe(3);
|
||||
expect((defaultRoutes![0] as any).src).toBe(
|
||||
'^/api/([^\\/]+)(\\/|\\/index|\\/index\\.js)?$'
|
||||
'^/api/([^/]+)(\\/|\\/index|\\/index\\.js)?$'
|
||||
);
|
||||
expect((defaultRoutes![0] as any).dest).toBe(
|
||||
'/api/[date]/index.js?date=$1'
|
||||
@@ -993,20 +994,6 @@ it('Test `detectRoutes`', async () => {
|
||||
it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
const featHandleMiss = true;
|
||||
|
||||
const expectedRoutes = [
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '/api/(.+)\\.\\w+',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
];
|
||||
|
||||
{
|
||||
const files = ['api/user.go', 'api/team.js', 'api/package.json'];
|
||||
|
||||
@@ -1016,7 +1003,19 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
builders!,
|
||||
featHandleMiss
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual(expectedRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1065,7 +1064,29 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
builders!,
|
||||
featHandleMiss
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual(expectedRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)/([^/]+)$',
|
||||
dest: '/api/[endpoint]/[id]?endpoint=$1&id=$2',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1081,7 +1102,29 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
builders!,
|
||||
featHandleMiss
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual(expectedRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)/([^/]+)$',
|
||||
dest: '/api/[endpoint]/[id]?endpoint=$1&id=$2',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1103,7 +1146,24 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
builders!,
|
||||
featHandleMiss
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual(expectedRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1127,7 +1187,19 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
builders!,
|
||||
featHandleMiss
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual(expectedRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1139,7 +1211,24 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
builders!,
|
||||
featHandleMiss
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual(expectedRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)(\\/|\\/index|\\/index\\.js)?$',
|
||||
dest: '/api/[date]/index?date=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1157,7 +1246,16 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
builders!,
|
||||
featHandleMiss
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual(expectedRoutes);
|
||||
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{ status: 404, src: '^/api(/.*)?$', continue: true },
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1171,6 +1269,611 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
builders!,
|
||||
featHandleMiss
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual(expectedRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/(.+)\\.\\w+$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
{ status: 404, src: '^/api(/.*)?$', continue: true },
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async () => {
|
||||
const featHandleMiss = true;
|
||||
const cleanUrls = true;
|
||||
const testHeaders = (redirectRoutes: Route[] | null) => {
|
||||
if (!redirectRoutes || redirectRoutes.length === 0) {
|
||||
throw new Error('Expected one redirect but found none');
|
||||
}
|
||||
expect(redirectRoutes).toBeDefined();
|
||||
expect(redirectRoutes.length).toBe(2);
|
||||
};
|
||||
|
||||
{
|
||||
const files = ['api/user.go', 'api/team.js', 'api/package.json'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
|
||||
// expected redirect should match inputs
|
||||
const getLocation = createReplaceLocation(redirectRoutes);
|
||||
|
||||
expect(getLocation('/api/index')).toBe('/api');
|
||||
expect(getLocation('/api/index.js')).toBe('/api');
|
||||
expect(getLocation('/api/user.js')).toBe('/api/user');
|
||||
expect(getLocation('/api/user.prod.js')).toBe('/api/user.prod');
|
||||
expect(getLocation('/api/user/index.js')).toBe('/api/user');
|
||||
|
||||
expect(getLocation('/api/index.go')).toBe('/api');
|
||||
expect(getLocation('/api/user.go')).toBe('/api/user');
|
||||
expect(getLocation('/api/user.prod.go')).toBe('/api/user.prod');
|
||||
expect(getLocation('/api/user/index.go')).toBe('/api/user');
|
||||
|
||||
expect(getLocation('/api/index.cpp')).toBe(null);
|
||||
expect(getLocation('/api/user.cpp')).toBe(null);
|
||||
expect(getLocation('/api/user.prod.cpp')).toBe(null);
|
||||
expect(getLocation('/api/user/index.cpp')).toBe(null);
|
||||
|
||||
expect(getLocation('/api/user')).toBe(null);
|
||||
expect(getLocation('/api/user/get')).toBe(null);
|
||||
expect(getLocation('/apiindex')).toBe(null);
|
||||
expect(getLocation('/api-index')).toBe(null);
|
||||
expect(getLocation('/apiuserindex')).toBe(null);
|
||||
expect(getLocation('/apiuser-index')).toBe(null);
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/user.go', 'api/user.js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { error } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
expect(error!.code).toBe('conflicting_file_path');
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/[user].go', 'api/[team]/[id].js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { error } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
expect(error!.code).toBe('conflicting_file_path');
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/[team]/[team].js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { error } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
expect(error!.code).toBe('conflicting_path_segment');
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/date/index.js', 'api/date/index.go'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, error } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
expect(defaultRoutes).toBe(null);
|
||||
expect(error!.code).toBe('conflicting_file_path');
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/[endpoint].js', 'api/[endpoint]/[id].js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/([^/]+)/([^/]+)$',
|
||||
dest: '/api/[endpoint]/[id]?endpoint=$1&id=$2',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = [
|
||||
'public/index.html',
|
||||
'api/[endpoint].js',
|
||||
'api/[endpoint]/[id].js',
|
||||
];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/([^/]+)/([^/]+)$',
|
||||
dest: '/api/[endpoint]/[id]?endpoint=$1&id=$2',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const pkg = {
|
||||
scripts: {
|
||||
build: 'next build',
|
||||
},
|
||||
framework: {
|
||||
slug: 'next',
|
||||
version: '9.0.0',
|
||||
},
|
||||
};
|
||||
|
||||
const files = ['public/index.html', 'api/[endpoint].js'];
|
||||
|
||||
const { builders } = await detectBuilders(files, pkg);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['public/index.html'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
expect(defaultRoutes).toStrictEqual([]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/date/index.js', 'api/date.js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/date.js', 'api/[date]/index.js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/([^/]+)(\\/|\\/index)?$',
|
||||
dest: '/api/[date]/index?date=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = [
|
||||
'api/index.ts',
|
||||
'api/index.d.ts',
|
||||
'api/users/index.ts',
|
||||
'api/users/index.d.ts',
|
||||
'api/food.ts',
|
||||
'api/ts/gold.ts',
|
||||
];
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{ status: 404, src: '^/api(/.*)?$', continue: true },
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
// use a custom runtime
|
||||
const functions = { 'api/user.php': { runtime: 'now-php@0.0.5' } };
|
||||
const files = ['api/user.php'];
|
||||
|
||||
const { builders } = await detectBuilders(files, null, { functions });
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{ status: 404, src: '^/api(/.*)?$', continue: true },
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingSlash=true`', async () => {
|
||||
const featHandleMiss = true;
|
||||
const cleanUrls = true;
|
||||
const trailingSlash = true;
|
||||
const testHeaders = (redirectRoutes: Route[] | null) => {
|
||||
if (!redirectRoutes || redirectRoutes.length === 0) {
|
||||
throw new Error('Expected one redirect but found none');
|
||||
}
|
||||
expect(redirectRoutes).toBeDefined();
|
||||
expect(redirectRoutes.length).toBe(2);
|
||||
};
|
||||
|
||||
{
|
||||
const files = ['api/user.go', 'api/team.js', 'api/package.json'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls,
|
||||
trailingSlash
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
|
||||
// expected redirect should match inputs
|
||||
const getLocation = createReplaceLocation(redirectRoutes);
|
||||
|
||||
expect(getLocation('/api/index')).toBe('/api/');
|
||||
expect(getLocation('/api/index.js')).toBe('/api/');
|
||||
expect(getLocation('/api/user.js')).toBe('/api/user/');
|
||||
expect(getLocation('/api/user.prod.js')).toBe('/api/user.prod/');
|
||||
expect(getLocation('/api/user/index.js')).toBe('/api/user/');
|
||||
|
||||
expect(getLocation('/api/index.go')).toBe('/api/');
|
||||
expect(getLocation('/api/user.go')).toBe('/api/user/');
|
||||
expect(getLocation('/api/user.prod.go')).toBe('/api/user.prod/');
|
||||
expect(getLocation('/api/user/index.go')).toBe('/api/user/');
|
||||
|
||||
expect(getLocation('/api/index.cpp')).toBe(null);
|
||||
expect(getLocation('/api/user.cpp')).toBe(null);
|
||||
expect(getLocation('/api/user.prod.cpp')).toBe(null);
|
||||
expect(getLocation('/api/user/index.cpp')).toBe(null);
|
||||
|
||||
expect(getLocation('/api/user')).toBe(null);
|
||||
expect(getLocation('/api/user/get')).toBe(null);
|
||||
expect(getLocation('/apiindex')).toBe(null);
|
||||
expect(getLocation('/api.index')).toBe(null);
|
||||
expect(getLocation('/api.index.js')).toBe(null);
|
||||
expect(getLocation('/api-index')).toBe(null);
|
||||
expect(getLocation('/apiuser.index')).toBe(null);
|
||||
expect(getLocation('/apiuser-index')).toBe(null);
|
||||
expect(getLocation('/apiuser-index')).toBe(null);
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/[endpoint].js', 'api/[endpoint]/[id].js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls,
|
||||
trailingSlash
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/([^/]+)/([^/]+)$',
|
||||
dest: '/api/[endpoint]/[id]?endpoint=$1&id=$2',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = [
|
||||
'public/index.html',
|
||||
'api/[endpoint].js',
|
||||
'api/[endpoint]/[id].js',
|
||||
];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls,
|
||||
trailingSlash
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/([^/]+)/([^/]+)$',
|
||||
dest: '/api/[endpoint]/[id]?endpoint=$1&id=$2',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const pkg = {
|
||||
scripts: {
|
||||
build: 'next build',
|
||||
},
|
||||
framework: {
|
||||
slug: 'next',
|
||||
version: '9.0.0',
|
||||
},
|
||||
};
|
||||
|
||||
const files = ['public/index.html', 'api/[endpoint].js'];
|
||||
|
||||
const { builders } = await detectBuilders(files, pkg);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls,
|
||||
trailingSlash
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/([^/]+)$',
|
||||
dest: '/api/[endpoint]?endpoint=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/date/index.js', 'api/date.js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls,
|
||||
trailingSlash
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = ['api/date.js', 'api/[date]/index.js'];
|
||||
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls,
|
||||
trailingSlash
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
src: '^/api/([^/]+)(\\/|\\/index)?$',
|
||||
dest: '/api/[date]/index?date=$1',
|
||||
check: true,
|
||||
},
|
||||
{
|
||||
status: 404,
|
||||
src: '^/api(/.*)?$',
|
||||
continue: true,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
const files = [
|
||||
'api/index.ts',
|
||||
'api/index.d.ts',
|
||||
'api/users/index.ts',
|
||||
'api/users/index.d.ts',
|
||||
'api/food.ts',
|
||||
'api/ts/gold.ts',
|
||||
];
|
||||
const { builders } = await detectBuilders(files);
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls,
|
||||
trailingSlash
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{ status: 404, src: '^/api(/.*)?$', continue: true },
|
||||
]);
|
||||
}
|
||||
|
||||
{
|
||||
// use a custom runtime
|
||||
const functions = { 'api/user.php': { runtime: 'now-php@0.0.5' } };
|
||||
const files = ['api/user.php'];
|
||||
|
||||
const { builders } = await detectBuilders(files, null, { functions });
|
||||
const { defaultRoutes, redirectRoutes } = await detectRoutes(
|
||||
files,
|
||||
builders!,
|
||||
featHandleMiss,
|
||||
cleanUrls,
|
||||
trailingSlash
|
||||
);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{ status: 404, src: '^/api(/.*)?$', continue: true },
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Create a function that will replace matched redirects
|
||||
* similar to how it works with `now-proxy` in production.
|
||||
*/
|
||||
function createReplaceLocation(redirectRoutes: Route[] | null) {
|
||||
const redirectSources = (redirectRoutes || []) as Source[];
|
||||
return (filePath: string): string | null => {
|
||||
for (const r of redirectSources) {
|
||||
const m = new RegExp(r.src).exec(filePath);
|
||||
console.log({ filePath, r, m });
|
||||
if (m && r.headers) {
|
||||
const match = m[1] || '';
|
||||
return r.headers['Location'].replace('$1', match);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
45
packages/now-build-utils/test/unit.test.js
vendored
45
packages/now-build-utils/test/unit.test.js
vendored
@@ -47,12 +47,31 @@ it('should create zip files with symlinks properly', async () => {
|
||||
});
|
||||
|
||||
it('should only match supported node versions', async () => {
|
||||
expect(await getSupportedNodeVersion('10.x')).toHaveProperty('major', 10);
|
||||
expect(await getSupportedNodeVersion('12.x')).toHaveProperty('major', 12);
|
||||
expect(getSupportedNodeVersion('8.11.x')).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('6.x')).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('999.x')).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('foo')).rejects.toThrow();
|
||||
expect(await getSupportedNodeVersion('10.x', false)).toHaveProperty(
|
||||
'major',
|
||||
10
|
||||
);
|
||||
expect(await getSupportedNodeVersion('12.x', false)).toHaveProperty(
|
||||
'major',
|
||||
12
|
||||
);
|
||||
expect(getSupportedNodeVersion('8.11.x', false)).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('6.x', false)).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('999.x', false)).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('foo', false)).rejects.toThrow();
|
||||
|
||||
expect(await getSupportedNodeVersion('10.x', true)).toHaveProperty(
|
||||
'major',
|
||||
10
|
||||
);
|
||||
expect(await getSupportedNodeVersion('12.x', true)).toHaveProperty(
|
||||
'major',
|
||||
12
|
||||
);
|
||||
expect(getSupportedNodeVersion('8.11.x', true)).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('6.x', true)).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('999.x', true)).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('foo', true)).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('should match all semver ranges', async () => {
|
||||
@@ -89,6 +108,20 @@ it('should get latest node version', async () => {
|
||||
expect(await getLatestNodeVersion()).toHaveProperty('major', 12);
|
||||
});
|
||||
|
||||
it('should throw for discontinued versions', async () => {
|
||||
// Mock a future date so that Node 8 becomes discontinued
|
||||
const realDateNow = Date.now.bind(global.Date);
|
||||
global.Date.now = () => new Date('2020-02-14').getTime();
|
||||
|
||||
expect(getSupportedNodeVersion('', false)).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('8.10.x', false)).rejects.toThrow();
|
||||
|
||||
expect(getSupportedNodeVersion('', true)).rejects.toThrow();
|
||||
expect(getSupportedNodeVersion('8.10.x', true)).rejects.toThrow();
|
||||
|
||||
global.Date.now = realDateNow;
|
||||
});
|
||||
|
||||
it('should support require by path for legacy builders', () => {
|
||||
const index = require('@now/build-utils');
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "now",
|
||||
"version": "16.7.2-canary.1",
|
||||
"version": "16.7.2-canary.2",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Now",
|
||||
|
||||
@@ -544,10 +544,11 @@ export default class DevServer {
|
||||
}
|
||||
|
||||
if (builders) {
|
||||
const { defaultRoutes, error: routesError } = await detectRoutes(
|
||||
files,
|
||||
builders
|
||||
);
|
||||
const {
|
||||
defaultRoutes,
|
||||
redirectRoutes,
|
||||
error: routesError,
|
||||
} = await detectRoutes(files, builders);
|
||||
|
||||
config.builds = config.builds || [];
|
||||
config.builds.push(...builders);
|
||||
@@ -556,8 +557,12 @@ export default class DevServer {
|
||||
this.output.error(routesError.message);
|
||||
await this.exit();
|
||||
} else {
|
||||
config.routes = config.routes || [];
|
||||
config.routes.push(...(defaultRoutes as RouteConfig[]));
|
||||
const routes: RouteConfig[] = [];
|
||||
const { routes: nowConfigRoutes } = config;
|
||||
routes.push(...(redirectRoutes || []));
|
||||
routes.push(...(nowConfigRoutes || []));
|
||||
routes.push(...(defaultRoutes || []));
|
||||
config.routes = routes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/next",
|
||||
"version": "2.3.5",
|
||||
"version": "2.3.6",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/next-js",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/node",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/node-js",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { relative, basename, resolve, dirname } from 'path';
|
||||
import _ts from 'typescript';
|
||||
import { NowBuildError } from '@now/build-utils';
|
||||
|
||||
/*
|
||||
* Fork of TS-Node - https://github.com/TypeStrong/ts-node
|
||||
@@ -180,8 +181,8 @@ export function register(opts: Options = {}): Register {
|
||||
};
|
||||
|
||||
function createTSError(diagnostics: ReadonlyArray<_ts.Diagnostic>) {
|
||||
const diagnosticText = formatDiagnostics(diagnostics, diagnosticHost);
|
||||
return new Error(diagnosticText);
|
||||
const message = formatDiagnostics(diagnostics, diagnosticHost);
|
||||
return new NowBuildError({ code: 'NOW_NODE_TYPESCRIPT_ERROR', message });
|
||||
}
|
||||
|
||||
function reportTSError(
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
}
|
||||
],
|
||||
"probes": [
|
||||
{ "path": "/empty", "mustContain": "RANDOMNESS_PLACEHOLDER:8" },
|
||||
{ "path": "/empty", "mustContain": "RANDOMNESS_PLACEHOLDER:12" },
|
||||
{ "path": "/exact", "mustContain": "RANDOMNESS_PLACEHOLDER:10" },
|
||||
{ "path": "/greater", "mustContain": "RANDOMNESS_PLACEHOLDER:12" },
|
||||
{ "path": "/major", "mustContain": "RANDOMNESS_PLACEHOLDER:10" },
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/static-build",
|
||||
"version": "0.14.1",
|
||||
"version": "0.14.2",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/static-builds",
|
||||
|
||||
@@ -162,7 +162,13 @@ function getPkg(entrypoint: string, workPath: string) {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
function getFramework(config: Config | null, pkg?: PackageJson | null) {
|
||||
function getFramework(
|
||||
config: Config | null,
|
||||
pkg?: PackageJson | null
|
||||
): Framework | undefined {
|
||||
if (!config || !config.zeroConfig) {
|
||||
return;
|
||||
}
|
||||
const { framework: configFramework = null } = config || {};
|
||||
|
||||
if (configFramework) {
|
||||
|
||||
11
packages/now-static-build/test/fixtures/04a-correct-dist-dir/now.json
vendored
Normal file
11
packages/now-static-build/test/fixtures/04a-correct-dist-dir/now.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@now/static-build",
|
||||
"config": { "distDir": "out" }
|
||||
}
|
||||
],
|
||||
"probes": [{ "path": "/", "mustContain": "output:RANDOMNESS_PLACEHOLDER" }]
|
||||
}
|
||||
9
packages/now-static-build/test/fixtures/04a-correct-dist-dir/package.json
vendored
Normal file
9
packages/now-static-build/test/fixtures/04a-correct-dist-dir/package.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"now-build": "mkdir out && echo 'output:RANDOMNESS_PLACEHOLDER' > out/index.txt"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vue/cli-service": "3.11.0"
|
||||
}
|
||||
}
|
||||
1
packages/now-static-build/test/fixtures/04a-correct-dist-dir/public/index.txt
vendored
Normal file
1
packages/now-static-build/test/fixtures/04a-correct-dist-dir/public/index.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Should not use this file
|
||||
2
packages/now-static-build/test/unit.test.js
vendored
2
packages/now-static-build/test/unit.test.js
vendored
@@ -4,6 +4,7 @@ const path = require('path');
|
||||
describe('prepareCache', () => {
|
||||
test('should cache node_modules', async () => {
|
||||
const files = await prepareCache({
|
||||
config: { zeroConfig: true },
|
||||
workPath: path.resolve(__dirname, './cache-fixtures/default'),
|
||||
entrypoint: 'index.js',
|
||||
});
|
||||
@@ -14,6 +15,7 @@ describe('prepareCache', () => {
|
||||
|
||||
test('should cache node_modules and `.cache` folder for gatsby deployments', async () => {
|
||||
const files = await prepareCache({
|
||||
config: { zeroConfig: true },
|
||||
workPath: path.resolve(__dirname, './cache-fixtures/gatsby'),
|
||||
entrypoint: 'package.json',
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const assert = require('assert');
|
||||
const { createHash } = require('crypto');
|
||||
const { homedir } = require('os');
|
||||
const path = require('path');
|
||||
const fetch = require('./fetch-retry.js');
|
||||
|
||||
@@ -28,7 +27,7 @@ async function nowDeploy (bodies, randomness) {
|
||||
RANDOMNESS_BUILD_ENV_VAR: randomness,
|
||||
},
|
||||
},
|
||||
name: 'test',
|
||||
name: 'test2020',
|
||||
files,
|
||||
builds: nowJson.builds,
|
||||
routes: nowJson.routes || [],
|
||||
@@ -133,20 +132,12 @@ async function fetchWithAuth (url, opts = {}) {
|
||||
if (!opts.headers) opts.headers = {};
|
||||
|
||||
if (!opts.headers.Authorization) {
|
||||
const { NOW_TOKEN, CIRCLECI } = process.env;
|
||||
currentCount += 1;
|
||||
if (!token || currentCount === MAX_COUNT) {
|
||||
currentCount = 0;
|
||||
if (NOW_TOKEN) {
|
||||
token = NOW_TOKEN;
|
||||
} else if (CIRCLECI) {
|
||||
token = await fetchTokenWithRetry(
|
||||
Buffer.from(str, 'base64').toString()
|
||||
);
|
||||
} else {
|
||||
const authJsonPath = path.join(homedir(), '.now/auth.json');
|
||||
token = require(authJsonPath).token;
|
||||
}
|
||||
token = await fetchTokenWithRetry(
|
||||
Buffer.from(str, 'base64').toString()
|
||||
);
|
||||
}
|
||||
|
||||
opts.headers.Authorization = `Bearer ${token}`;
|
||||
|
||||
12
yarn.lock
12
yarn.lock
@@ -2341,9 +2341,9 @@ ansi-styles@^4.0.0:
|
||||
color-convert "^2.0.1"
|
||||
|
||||
ansi-styles@^4.1.0:
|
||||
version "4.2.0"
|
||||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.0.tgz#5681f0dcf7ae5880a7841d8831c4724ed9cc0172"
|
||||
integrity sha512-7kFQgnEaMdRtwf6uSfUnVr9gSGC7faurn+J/Mv90/W+iTtN0405/nLdopfMWwchyxhbGYl6TC4Sccn9TUkGAgg==
|
||||
version "4.2.1"
|
||||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359"
|
||||
integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==
|
||||
dependencies:
|
||||
"@types/color-name" "^1.1.1"
|
||||
color-convert "^2.0.1"
|
||||
@@ -10418,9 +10418,9 @@ term-size@^1.2.0:
|
||||
execa "^0.7.0"
|
||||
|
||||
term-size@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/term-size/-/term-size-2.1.0.tgz#3aec444c07a7cf936e157c1dc224b590c3c7eef2"
|
||||
integrity sha512-I42EWhJ+2aeNQawGx1VtpO0DFI9YcfuvAMNIdKyf/6sRbHJ4P+ZQ/zIT87tE+ln1ymAGcCJds4dolfSAS0AcNg==
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/term-size/-/term-size-2.1.1.tgz#f81ec25854af91a480d2f9d0c77ffcb26594ed1a"
|
||||
integrity sha512-UqvQSch04R+69g4RDhrslmGvGL3ucDRX/U+snYW0Mab4uCAyKSndUksaoqlJ81QKSpRnIsuOYQCbC2ZWx2896A==
|
||||
|
||||
test-exclude@^5.1.0, test-exclude@^5.2.3:
|
||||
version "5.2.3"
|
||||
|
||||
Reference in New Issue
Block a user