mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 04:22:13 +00:00
Compare commits
30 Commits
vercel@24.
...
@vercel/py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c20218e05 | ||
|
|
02a0004719 | ||
|
|
123bffb776 | ||
|
|
074535f27c | ||
|
|
05243fb6e9 | ||
|
|
097725580c | ||
|
|
4b09c89e7d | ||
|
|
3a1eede63b | ||
|
|
9cee0dd5d7 | ||
|
|
b801c6e593 | ||
|
|
505050b923 | ||
|
|
15c7ad241a | ||
|
|
ec57654b5b | ||
|
|
3b9a9878bc | ||
|
|
70b7db1a15 | ||
|
|
41d6666139 | ||
|
|
2857219f89 | ||
|
|
246c2a0f5d | ||
|
|
d91bca7d6b | ||
|
|
be54fce67b | ||
|
|
7753bb8d89 | ||
|
|
ce17ac5c35 | ||
|
|
8006fc32b8 | ||
|
|
8038a90db1 | ||
|
|
f88c862e9d | ||
|
|
9170820371 | ||
|
|
c881546e0e | ||
|
|
fa21db98e4 | ||
|
|
8eabbfc666 | ||
|
|
6783f7afc9 |
20
examples/astro/.gitignore
vendored
Normal file
20
examples/astro/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# build output
|
||||
dist/
|
||||
.output/
|
||||
|
||||
# dependencies
|
||||
node_modules/
|
||||
|
||||
# logs
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
|
||||
# environment variables
|
||||
.env
|
||||
.env.production
|
||||
|
||||
# macOS-specific files
|
||||
.DS_Store
|
||||
2
examples/astro/.npmrc
Normal file
2
examples/astro/.npmrc
Normal file
@@ -0,0 +1,2 @@
|
||||
# Expose Astro dependencies for `pnpm` users
|
||||
shamefully-hoist=true
|
||||
1
examples/astro/.vercelignore
Normal file
1
examples/astro/.vercelignore
Normal file
@@ -0,0 +1 @@
|
||||
README.md
|
||||
42
examples/astro/README.md
Normal file
42
examples/astro/README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Welcome to [Astro](https://astro.build)
|
||||
|
||||
[](https://stackblitz.com/github/withastro/astro/tree/latest/examples/starter)
|
||||
|
||||
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun!
|
||||
|
||||
## 🚀 Project Structure
|
||||
|
||||
Inside of your Astro project, you'll see the following folders and files:
|
||||
|
||||
```
|
||||
/
|
||||
├── public/
|
||||
│ └── favicon.ico
|
||||
├── src/
|
||||
│ ├── components/
|
||||
│ │ └── Layout.astro
|
||||
│ └── pages/
|
||||
│ └── index.astro
|
||||
└── package.json
|
||||
```
|
||||
|
||||
Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.
|
||||
|
||||
There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components or layouts.
|
||||
|
||||
Any static assets, like images, can be placed in the `public/` directory.
|
||||
|
||||
## 🧞 Commands
|
||||
|
||||
All commands are run from the root of the project, from a terminal:
|
||||
|
||||
| Command | Action |
|
||||
| :---------------- | :------------------------------------------- |
|
||||
| `npm install` | Installs dependencies |
|
||||
| `npm run dev` | Starts local dev server at `localhost:3000` |
|
||||
| `npm run build` | Build your production site to `./dist/` |
|
||||
| `npm run preview` | Preview your build locally, before deploying |
|
||||
|
||||
## 👀 Want to learn more?
|
||||
|
||||
Feel free to check [our documentation](https://github.com/withastro/astro) or jump into our [Discord server](https://astro.build/chat).
|
||||
4
examples/astro/astro.config.mjs
Normal file
4
examples/astro/astro.config.mjs
Normal file
@@ -0,0 +1,4 @@
|
||||
import { defineConfig } from 'astro/config';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({});
|
||||
14
examples/astro/package.json
Normal file
14
examples/astro/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@example/basics",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "astro dev",
|
||||
"start": "astro dev",
|
||||
"build": "astro build",
|
||||
"preview": "astro preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"astro": "^1.0.0-beta.20"
|
||||
}
|
||||
}
|
||||
BIN
examples/astro/public/favicon.ico
Normal file
BIN
examples/astro/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
55
examples/astro/src/components/Layout.astro
Normal file
55
examples/astro/src/components/Layout.astro
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
export interface Props {
|
||||
title: string;
|
||||
}
|
||||
|
||||
const { title } = Astro.props as Props;
|
||||
---
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<title>{title}</title>
|
||||
</head>
|
||||
<body>
|
||||
<slot />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--font-size-base: clamp(1rem, 0.34vw + 0.91rem, 1.19rem);
|
||||
--font-size-lg: clamp(1.2rem, 0.7vw + 1.2rem, 1.5rem);
|
||||
--font-size-xl: clamp(2.44rem, 2.38vw + 1.85rem, 3.75rem);
|
||||
|
||||
--color-text: hsl(12, 5%, 4%);
|
||||
--color-bg: hsl(10, 21%, 95%);
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: system-ui, sans-serif;
|
||||
font-size: var(--font-size-base);
|
||||
color: var(--color-text);
|
||||
background-color: var(--color-bg);
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:global(h1) {
|
||||
font-size: var(--font-size-xl);
|
||||
}
|
||||
|
||||
:global(h2) {
|
||||
font-size: var(--font-size-lg);
|
||||
}
|
||||
|
||||
:global(code) {
|
||||
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
|
||||
Bitstream Vera Sans Mono, Courier New, monospace;
|
||||
}
|
||||
</style>
|
||||
174
examples/astro/src/pages/index.astro
Normal file
174
examples/astro/src/pages/index.astro
Normal file
@@ -0,0 +1,174 @@
|
||||
---
|
||||
import Layout from '../components/Layout.astro';
|
||||
---
|
||||
|
||||
<Layout title="Welcome to Astro.">
|
||||
<main>
|
||||
<h1>Welcome to <span class="text-gradient">Astro</span></h1>
|
||||
<p class="instructions"><strong>Your first mission:</strong> tweak this message to try our hot module reloading. Check the <code>src/pages</code> directory!</p>
|
||||
<ul role="list" class="link-card-grid">
|
||||
<li class="link-card">
|
||||
<a href="https://astro.build/integrations/">
|
||||
<h2>Integrations <span>→</span></h2>
|
||||
<p>Add component frameworks, Tailwind, Partytown, and more!</p>
|
||||
</a>
|
||||
</li>
|
||||
<li class="link-card">
|
||||
<a href="https://astro.build/themes/">
|
||||
<h2>Themes <span>→</span></h2>
|
||||
<p>Explore a galaxy of community-built starters.</p>
|
||||
</a>
|
||||
</li>
|
||||
<li class="link-card">
|
||||
<a href="https://docs.astro.build/">
|
||||
<h2>Docs <span>→</span></h2>
|
||||
<p>Learn our complete feature set and explore the API.</p>
|
||||
</a>
|
||||
</li>
|
||||
<li class="link-card">
|
||||
<a href="https://astro.build/chat/">
|
||||
<h2>Chat <span>→</span></h2>
|
||||
<p>
|
||||
Ask, contribute, and have fun on our community Discord
|
||||
<svg
|
||||
class="heart"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 512 512"
|
||||
width="16"
|
||||
height="16"
|
||||
fill="currentColor"
|
||||
>
|
||||
<title>heart</title>
|
||||
<path d="M256 448l-30.164-27.211C118.718 322.442 48 258.61 48 179.095 48 114.221 97.918 64 162.4 64c36.399 0 70.717 16.742 93.6 43.947C278.882 80.742 313.199 64 349.6 64 414.082 64 464 114.221 464 179.095c0 79.516-70.719 143.348-177.836 241.694L256 448z" />
|
||||
</svg>
|
||||
</p>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</main>
|
||||
</Layout>
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--color-border: hsl(17, 24%, 90%);
|
||||
--astro-gradient: linear-gradient(0deg,#4F39FA, #DA62C4);
|
||||
--link-gradient: linear-gradient(45deg, #4F39FA, #DA62C4 30%, var(--color-border) 60%);
|
||||
--night-sky-gradient: linear-gradient(0deg, #392362 -33%, #431f69 10%, #30216b 50%, #1f1638 100%);
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
transition: color 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
h2 span {
|
||||
display: inline-block;
|
||||
transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 0.875em;
|
||||
border: 0.1em solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
padding: 0.15em 0.25em;
|
||||
}
|
||||
|
||||
main {
|
||||
margin: auto;
|
||||
padding: 1em;
|
||||
max-width: 60ch;
|
||||
}
|
||||
|
||||
.text-gradient {
|
||||
font-weight: 900;
|
||||
background-image: var(--astro-gradient);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-size: 100% 200%;
|
||||
background-position-y: 100%;
|
||||
border-radius: 0.4rem;
|
||||
animation: pulse 4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
background-position-y: 0%;
|
||||
}
|
||||
50% {
|
||||
background-position-y: 80%;
|
||||
}
|
||||
}
|
||||
|
||||
.instructions {
|
||||
line-height: 1.8;
|
||||
margin-bottom: 2rem;
|
||||
background-image: var(--night-sky-gradient);
|
||||
padding: 1.5rem;
|
||||
border-radius: 0.4rem;
|
||||
color: var(--color-bg);
|
||||
}
|
||||
|
||||
.link-card-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
|
||||
gap: 1rem;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.link-card {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
padding: 0.15rem;
|
||||
background-image: var(--link-gradient);
|
||||
background-size: 400%;
|
||||
border-radius: 0.5rem;
|
||||
background-position: 100%;
|
||||
transition: background-position 0.6s cubic-bezier(0.22, 1, 0.36, 1);
|
||||
}
|
||||
|
||||
.link-card > a {
|
||||
width: 100%;
|
||||
text-decoration: none;
|
||||
line-height: 1.4;
|
||||
padding: 1em 1.3em;
|
||||
border-radius: 0.35rem;
|
||||
color: var(--text-color);
|
||||
background-color: white;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.link-card:is(:hover, :focus-within) {
|
||||
background-position: 0;
|
||||
}
|
||||
|
||||
.link-card:is(:hover, :focus-within) h2 {
|
||||
color: #4F39FA;
|
||||
}
|
||||
|
||||
.link-card:is(:hover, :focus-within) h2 span {
|
||||
transform: translateX(2px);
|
||||
}
|
||||
|
||||
.heart {
|
||||
display: inline-block;
|
||||
color: #DA62C4;
|
||||
animation: heartbeat 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes heartbeat {
|
||||
0%,
|
||||
50%,
|
||||
100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
5% {
|
||||
transform: scale(1.125);
|
||||
}
|
||||
10% {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
15% {
|
||||
transform: scale(1.25);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
15
examples/astro/tsconfig.json
Normal file
15
examples/astro/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Enable top-level await, and other modern ESM features.
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
// Enable node-style module resolution, for things like npm package imports.
|
||||
"moduleResolution": "node",
|
||||
// Enable JSON imports.
|
||||
"resolveJsonModule": true,
|
||||
// Enable stricter transpilation for better output.
|
||||
"isolatedModules": true,
|
||||
// Add type definitions for our Vite runtime.
|
||||
"types": ["vite/client"]
|
||||
}
|
||||
}
|
||||
3457
examples/astro/yarn.lock
Normal file
3457
examples/astro/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -48,6 +48,6 @@
|
||||
"qunit-dom": "^0.8.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": "8.* || >= 10.*"
|
||||
"node": "14.x"
|
||||
}
|
||||
}
|
||||
|
||||
2
examples/remix/package-lock.json
generated
2
examples/remix/package-lock.json
generated
@@ -21,7 +21,7 @@
|
||||
"typescript": "^4.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
"node": "14.x"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"typescript": "^4.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
"node": "14.x"
|
||||
},
|
||||
"sideEffects": false
|
||||
}
|
||||
}
|
||||
|
||||
1
examples/solidstart/.gitignore
vendored
1
examples/solidstart/.gitignore
vendored
@@ -2,6 +2,7 @@ dist
|
||||
worker
|
||||
.solid
|
||||
.vercel
|
||||
.output
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
@@ -15,6 +15,6 @@
|
||||
"vite": "^2.7.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
"node": "14.x"
|
||||
}
|
||||
}
|
||||
|
||||
7
examples/solidstart/vercel.json
Normal file
7
examples/solidstart/vercel.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"build": {
|
||||
"env": {
|
||||
"ENABLE_FILE_SYSTEM_API": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/build-utils",
|
||||
"version": "2.16.0",
|
||||
"version": "3.0.1-canary.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
@@ -30,7 +30,7 @@
|
||||
"@types/node-fetch": "^2.1.6",
|
||||
"@types/semver": "6.0.0",
|
||||
"@types/yazl": "2.4.2",
|
||||
"@vercel/frameworks": "0.8.0",
|
||||
"@vercel/frameworks": "0.9.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"aggregate-error": "3.0.1",
|
||||
"async-retry": "1.2.3",
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
export interface Stat {
|
||||
name: string;
|
||||
path: string;
|
||||
type: 'file' | 'dir';
|
||||
}
|
||||
/**
|
||||
* `DetectorFilesystem` is an abstract class that represents a virtual filesystem
|
||||
* to perform read-only operations on in order to detect which framework is being
|
||||
@@ -27,15 +32,19 @@ export abstract class DetectorFilesystem {
|
||||
protected abstract _hasPath(name: string): Promise<boolean>;
|
||||
protected abstract _readFile(name: string): Promise<Buffer>;
|
||||
protected abstract _isFile(name: string): Promise<boolean>;
|
||||
protected abstract _readdir(name: string): Promise<Stat[]>;
|
||||
protected abstract _chdir(name: string): DetectorFilesystem;
|
||||
|
||||
private pathCache: Map<string, Promise<boolean>>;
|
||||
private fileCache: Map<string, Promise<boolean>>;
|
||||
private readFileCache: Map<string, Promise<Buffer>>;
|
||||
private readdirCache: Map<string, Promise<Stat[]>>;
|
||||
|
||||
constructor() {
|
||||
this.pathCache = new Map();
|
||||
this.fileCache = new Map();
|
||||
this.readFileCache = new Map();
|
||||
this.readdirCache = new Map();
|
||||
}
|
||||
|
||||
public hasPath = async (path: string): Promise<boolean> => {
|
||||
@@ -64,4 +73,23 @@ export abstract class DetectorFilesystem {
|
||||
}
|
||||
return p;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a list of Stat objects from the current working directory.
|
||||
*/
|
||||
public readdir = async (name: string): Promise<Stat[]> => {
|
||||
let p = this.readdirCache.get(name);
|
||||
if (!p) {
|
||||
p = this._readdir(name);
|
||||
this.readdirCache.set(name, p);
|
||||
}
|
||||
return p;
|
||||
};
|
||||
|
||||
/**
|
||||
* Changes the current directory to the specified path and returns a new instance of DetectorFilesystem.
|
||||
*/
|
||||
public chdir = (name: string): DetectorFilesystem => {
|
||||
return this._chdir(name);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { NowBuildError } from '../errors';
|
||||
import debug from '../debug';
|
||||
|
||||
const allOptions = [
|
||||
{ major: 16, range: '16.x', runtime: 'nodejs16.x' },
|
||||
{ major: 14, range: '14.x', runtime: 'nodejs14.x' },
|
||||
{ major: 12, range: '12.x', runtime: 'nodejs12.x' },
|
||||
{
|
||||
|
||||
@@ -222,12 +222,6 @@ export async function getNodeVersion(
|
||||
const latest = getLatestNodeVersion();
|
||||
return { ...latest, runtime: 'nodejs' };
|
||||
}
|
||||
if (process.env.ENABLE_EXPERIMENTAL_NODE16 === '1') {
|
||||
console.warn(
|
||||
'Warning: Using experimental Node.js 16.x due to ENABLE_EXPERIMENTAL_NODE16=1'
|
||||
);
|
||||
return { major: 16, range: '16.x', runtime: 'nodejs16.x' };
|
||||
}
|
||||
const { packageJson } = await scanParentDirs(destPath, true);
|
||||
let { nodeVersion } = config;
|
||||
let isAuto = true;
|
||||
@@ -285,15 +279,17 @@ export async function scanParentDirs(
|
||||
),
|
||||
]);
|
||||
|
||||
if (packageLockJson && !hasYarnLock && !pnpmLockYaml) {
|
||||
cliType = 'npm';
|
||||
lockfileVersion = packageLockJson.lockfileVersion;
|
||||
}
|
||||
|
||||
if (!packageLockJson && !hasYarnLock && pnpmLockYaml) {
|
||||
// Priority order is Yarn > pnpm > npm
|
||||
// - find highest priority lock file and use that
|
||||
if (hasYarnLock) {
|
||||
cliType = 'yarn';
|
||||
} else if (pnpmLockYaml) {
|
||||
cliType = 'pnpm';
|
||||
// just ensure that it is read as a number and not a string
|
||||
lockfileVersion = Number(pnpmLockYaml.lockfileVersion);
|
||||
} else if (packageLockJson) {
|
||||
cliType = 'npm';
|
||||
lockfileVersion = packageLockJson.lockfileVersion;
|
||||
}
|
||||
|
||||
// Only stop iterating if a lockfile was found, because it's possible
|
||||
@@ -440,6 +436,12 @@ export function getEnvForPackageManager({
|
||||
newEnv.PATH = `/node16/bin-npm7:${env.PATH}`;
|
||||
console.log('Detected `package-lock.json` generated by npm 7...');
|
||||
}
|
||||
} else if (cliType === 'pnpm') {
|
||||
if (typeof lockfileVersion === 'number' && lockfileVersion === 5.4) {
|
||||
// Ensure that pnpm 7 is at the beginning of the `$PATH`
|
||||
newEnv.PATH = `/pnpm7/node_modules/.bin:${env.PATH}`;
|
||||
console.log('Detected `pnpm-lock.yaml` generated by pnpm 7...');
|
||||
}
|
||||
} else {
|
||||
// Yarn v2 PnP mode may be activated, so force "node-modules" linker style
|
||||
if (!env.YARN_NODE_LINKER) {
|
||||
|
||||
@@ -33,7 +33,6 @@ import {
|
||||
getDiscontinuedNodeVersions,
|
||||
} from './fs/node-version';
|
||||
import streamToBuffer from './fs/stream-to-buffer';
|
||||
import shouldServe from './should-serve';
|
||||
import debug from './debug';
|
||||
import getIgnoreFilter from './get-ignore-filter';
|
||||
import { getPlatformEnv } from './get-platform-env';
|
||||
@@ -73,7 +72,6 @@ export {
|
||||
getSpawnOptions,
|
||||
getPlatformEnv,
|
||||
streamToBuffer,
|
||||
shouldServe,
|
||||
debug,
|
||||
isSymbolicLink,
|
||||
getLambdaOptionsFromFunction,
|
||||
@@ -94,6 +92,7 @@ export { DetectorFilesystem } from './detectors/filesystem';
|
||||
export { readConfigFile } from './fs/read-config-file';
|
||||
export { normalizePath } from './fs/normalize-path';
|
||||
|
||||
export * from './should-serve';
|
||||
export * from './schemas';
|
||||
export * from './types';
|
||||
export * from './errors';
|
||||
@@ -116,3 +115,5 @@ export const isOfficialRuntime = (desired: string, name?: string): boolean => {
|
||||
export const isStaticRuntime = (name?: string): boolean => {
|
||||
return isOfficialRuntime('static', name);
|
||||
};
|
||||
|
||||
export { workspaceManagers } from './workspaces/workspace-managers';
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { parse } from 'path';
|
||||
import { ShouldServeOptions } from './types';
|
||||
import FileFsRef from './file-fs-ref';
|
||||
import type FileFsRef from './file-fs-ref';
|
||||
import type { ShouldServe } from './types';
|
||||
|
||||
export default function shouldServe({
|
||||
export const shouldServe: ShouldServe = ({
|
||||
entrypoint,
|
||||
files,
|
||||
requestPath,
|
||||
}: ShouldServeOptions): boolean {
|
||||
}) => {
|
||||
requestPath = requestPath.replace(/\/$/, ''); // sanitize trailing '/'
|
||||
entrypoint = entrypoint.replace(/\\/, '/'); // windows compatibility
|
||||
|
||||
@@ -20,7 +20,7 @@ export default function shouldServe({
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
function hasProp(obj: { [path: string]: FileFsRef }, key: string): boolean {
|
||||
return Object.hasOwnProperty.call(obj, key);
|
||||
|
||||
@@ -345,6 +345,7 @@ export interface BuilderV3 {
|
||||
version: 3;
|
||||
build: BuildV3;
|
||||
prepareCache?: PrepareCache;
|
||||
shouldServe?: ShouldServe;
|
||||
startDevServer?: StartDevServer;
|
||||
}
|
||||
|
||||
@@ -401,6 +402,9 @@ export interface BuildResultV3 {
|
||||
export type BuildV2 = (options: BuildOptions) => Promise<BuildResultV2>;
|
||||
export type BuildV3 = (options: BuildOptions) => Promise<BuildResultV3>;
|
||||
export type PrepareCache = (options: PrepareCacheOptions) => Promise<Files>;
|
||||
export type ShouldServe = (
|
||||
options: ShouldServeOptions
|
||||
) => boolean | Promise<boolean>;
|
||||
export type StartDevServer = (
|
||||
options: StartDevServerOptions
|
||||
) => Promise<StartDevServerResult>;
|
||||
|
||||
129
packages/build-utils/src/workspaces/workspace-managers.ts
Normal file
129
packages/build-utils/src/workspaces/workspace-managers.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
import type { Framework } from '@vercel/frameworks';
|
||||
|
||||
/**
|
||||
* The supported list of workspace managers.
|
||||
*
|
||||
* This list is designed to work with the @see {@link detectFramework} function.
|
||||
*
|
||||
* @example
|
||||
* import { workspaceManagers as frameworkList } from '@vercel/build-utils/workspaces'
|
||||
* import { detectFramework } from '@vercel/build-utils'
|
||||
*
|
||||
* const fs = new GitDetectorFilesystem(...)
|
||||
* detectFramwork({ fs, frameworkList }) // returns the 'slug' field if detected, otherwise null
|
||||
*
|
||||
* @todo Will be used by the detect-eligible-projects API endpoint for a given git url.
|
||||
*/
|
||||
export const workspaceManagers: Array<Framework> = [
|
||||
{
|
||||
name: 'Yarn',
|
||||
slug: 'yarn',
|
||||
detectors: {
|
||||
every: [
|
||||
{
|
||||
path: 'package.json',
|
||||
matchContent:
|
||||
'"workspaces":\\s*(?:\\[[^\\]]*]|{[^}]*"packages":[^}]*})',
|
||||
},
|
||||
{
|
||||
path: 'yarn.lock',
|
||||
},
|
||||
],
|
||||
},
|
||||
// unused props - needed for typescript
|
||||
description: '',
|
||||
logo: '',
|
||||
settings: {
|
||||
buildCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
devCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
installCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
outputDirectory: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
},
|
||||
getOutputDirName: () => Promise.resolve(''),
|
||||
},
|
||||
{
|
||||
name: 'pnpm',
|
||||
slug: 'pnpm',
|
||||
detectors: {
|
||||
every: [
|
||||
{
|
||||
path: 'pnpm-workspace.yaml',
|
||||
},
|
||||
],
|
||||
},
|
||||
// unused props - needed for typescript
|
||||
description: '',
|
||||
logo: '',
|
||||
settings: {
|
||||
buildCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
devCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
installCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
outputDirectory: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
},
|
||||
getOutputDirName: () => Promise.resolve(''),
|
||||
},
|
||||
{
|
||||
name: 'npm',
|
||||
slug: 'npm',
|
||||
detectors: {
|
||||
every: [
|
||||
{
|
||||
path: 'package.json',
|
||||
matchContent:
|
||||
'"workspaces":\\s*(?:\\[[^\\]]*]|{[^}]*"packages":[^}]*})',
|
||||
},
|
||||
{
|
||||
path: 'package-lock.json',
|
||||
},
|
||||
],
|
||||
},
|
||||
// unused props - needed for typescript
|
||||
description: '',
|
||||
logo: '',
|
||||
settings: {
|
||||
buildCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
devCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
installCommand: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
outputDirectory: {
|
||||
value: '',
|
||||
placeholder: '',
|
||||
},
|
||||
},
|
||||
getOutputDirName: () => Promise.resolve(''),
|
||||
},
|
||||
];
|
||||
|
||||
export default workspaceManagers;
|
||||
7789
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/package-lock.json
generated
vendored
Normal file
7789
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/package-lock.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
14
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/package.json
vendored
Normal file
14
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/package.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"private": "true",
|
||||
"name": "25-multiple-lock-files-yarn",
|
||||
"workspaces": [
|
||||
"a",
|
||||
"b"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "mkdir -p public && (printf \"yarn version: \" && yarn -v) > public/index.txt"
|
||||
},
|
||||
"dependencies": {
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
}
|
||||
19
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/pnpm-lock.yaml
generated
vendored
Normal file
19
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/pnpm-lock.yaml
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
lockfileVersion: 5.3
|
||||
|
||||
specifiers:
|
||||
once: ^1.4.0
|
||||
|
||||
dependencies:
|
||||
once: 1.4.0
|
||||
|
||||
packages:
|
||||
|
||||
/once/1.4.0:
|
||||
resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=}
|
||||
dependencies:
|
||||
wrappy: 1.0.2
|
||||
dev: false
|
||||
|
||||
/wrappy/1.0.2:
|
||||
resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=}
|
||||
dev: false
|
||||
11
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/vercel.json
vendored
Normal file
11
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/vercel.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/static-build" }],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/",
|
||||
"mustContain": "yarn version: 1",
|
||||
"logMustContain": "yarn run build"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/yarn.lock
vendored
Normal file
15
packages/build-utils/test/fixtures/25-multiple-lock-files-yarn/yarn.lock
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
once@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
|
||||
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
|
||||
dependencies:
|
||||
wrappy "1"
|
||||
|
||||
wrappy@1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
|
||||
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
||||
44
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/package-lock.json
generated
vendored
Normal file
44
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/package-lock.json
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "26-multiple-lock-files-pnpm",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "26-multiple-lock-files-pnpm",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"dependencies": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"node_modules/wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
}
|
||||
}
|
||||
}
|
||||
14
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/package.json
vendored
Normal file
14
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/package.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"private": "true",
|
||||
"name": "26-multiple-lock-files-pnpm",
|
||||
"workspaces": [
|
||||
"a",
|
||||
"b"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "mkdir -p public && (printf \"pnpm version: \" && pnpm -v) > public/index.txt"
|
||||
},
|
||||
"dependencies": {
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
}
|
||||
19
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/pnpm-lock.yaml
generated
vendored
Normal file
19
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/pnpm-lock.yaml
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
lockfileVersion: 5.3
|
||||
|
||||
specifiers:
|
||||
once: ^1.4.0
|
||||
|
||||
dependencies:
|
||||
once: 1.4.0
|
||||
|
||||
packages:
|
||||
|
||||
/once/1.4.0:
|
||||
resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=}
|
||||
dependencies:
|
||||
wrappy: 1.0.2
|
||||
dev: false
|
||||
|
||||
/wrappy/1.0.2:
|
||||
resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=}
|
||||
dev: false
|
||||
3
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/pnpm-workspace.yaml
vendored
Normal file
3
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/pnpm-workspace.yaml
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
packages:
|
||||
- 'a'
|
||||
- 'b'
|
||||
11
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/vercel.json
vendored
Normal file
11
packages/build-utils/test/fixtures/26-multiple-lock-files-pnpm/vercel.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/static-build" }],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/",
|
||||
"mustContain": "pnpm version: 6",
|
||||
"logMustContain": "pnpm run build"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
packages/build-utils/test/fixtures/27-yarn-workspaces/a/package.json
vendored
Normal file
15
packages/build-utils/test/fixtures/27-yarn-workspaces/a/package.json
vendored
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
15
packages/build-utils/test/fixtures/27-yarn-workspaces/b/package.json
vendored
Normal file
15
packages/build-utils/test/fixtures/27-yarn-workspaces/b/package.json
vendored
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
9
packages/build-utils/test/fixtures/27-yarn-workspaces/package.json
vendored
Normal file
9
packages/build-utils/test/fixtures/27-yarn-workspaces/package.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "21-npm-workspaces",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
}
|
||||
232
packages/build-utils/test/fixtures/27-yarn-workspaces/yarn.lock
vendored
Normal file
232
packages/build-utils/test/fixtures/27-yarn-workspaces/yarn.lock
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
ansi-regex@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.1.tgz#123d6479e92ad45ad897d4054e3c7ca7db4944e1"
|
||||
integrity sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==
|
||||
|
||||
ansi-regex@^5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
|
||||
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
|
||||
|
||||
ansi-styles@^4.0.0:
|
||||
version "4.3.0"
|
||||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937"
|
||||
integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==
|
||||
dependencies:
|
||||
color-convert "^2.0.1"
|
||||
|
||||
camelcase@^5.0.0:
|
||||
version "5.3.1"
|
||||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
|
||||
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
|
||||
|
||||
cliui@^6.0.0:
|
||||
version "6.0.0"
|
||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1"
|
||||
integrity sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==
|
||||
dependencies:
|
||||
string-width "^4.2.0"
|
||||
strip-ansi "^6.0.0"
|
||||
wrap-ansi "^6.2.0"
|
||||
|
||||
color-convert@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
|
||||
integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==
|
||||
dependencies:
|
||||
color-name "~1.1.4"
|
||||
|
||||
color-name@~1.1.4:
|
||||
version "1.1.4"
|
||||
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
|
||||
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
|
||||
|
||||
cowsay@^1.5.0:
|
||||
version "1.5.0"
|
||||
resolved "https://registry.yarnpkg.com/cowsay/-/cowsay-1.5.0.tgz#4a2a453b8b59383c7d7a50e44d765c5de0bf615f"
|
||||
integrity sha512-8Ipzr54Z8zROr/62C8f0PdhQcDusS05gKTS87xxdji8VbWefWly0k8BwGK7+VqamOrkv3eGsCkPtvlHzrhWsCA==
|
||||
dependencies:
|
||||
get-stdin "8.0.0"
|
||||
string-width "~2.1.1"
|
||||
strip-final-newline "2.0.0"
|
||||
yargs "15.4.1"
|
||||
|
||||
debug@^4.3.2:
|
||||
version "4.3.4"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
|
||||
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
|
||||
dependencies:
|
||||
ms "2.1.2"
|
||||
|
||||
decamelize@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
|
||||
integrity sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=
|
||||
|
||||
emoji-regex@^8.0.0:
|
||||
version "8.0.0"
|
||||
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
|
||||
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
|
||||
|
||||
find-up@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19"
|
||||
integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==
|
||||
dependencies:
|
||||
locate-path "^5.0.0"
|
||||
path-exists "^4.0.0"
|
||||
|
||||
get-caller-file@^2.0.1:
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
|
||||
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
|
||||
|
||||
get-stdin@8.0.0:
|
||||
version "8.0.0"
|
||||
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-8.0.0.tgz#cbad6a73feb75f6eeb22ba9e01f89aa28aa97a53"
|
||||
integrity sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==
|
||||
|
||||
is-fullwidth-code-point@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
|
||||
integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=
|
||||
|
||||
is-fullwidth-code-point@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d"
|
||||
integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==
|
||||
|
||||
locate-path@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0"
|
||||
integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==
|
||||
dependencies:
|
||||
p-locate "^4.1.0"
|
||||
|
||||
ms@2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
|
||||
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
|
||||
|
||||
p-limit@^2.2.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1"
|
||||
integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==
|
||||
dependencies:
|
||||
p-try "^2.0.0"
|
||||
|
||||
p-locate@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07"
|
||||
integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==
|
||||
dependencies:
|
||||
p-limit "^2.2.0"
|
||||
|
||||
p-try@^2.0.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
|
||||
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==
|
||||
|
||||
path-exists@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
|
||||
integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==
|
||||
|
||||
require-directory@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
|
||||
integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I=
|
||||
|
||||
require-main-filename@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
|
||||
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
|
||||
|
||||
set-blocking@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
|
||||
integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc=
|
||||
|
||||
string-width@^4.1.0, string-width@^4.2.0:
|
||||
version "4.2.3"
|
||||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
|
||||
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
|
||||
dependencies:
|
||||
emoji-regex "^8.0.0"
|
||||
is-fullwidth-code-point "^3.0.0"
|
||||
strip-ansi "^6.0.1"
|
||||
|
||||
string-width@~2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
|
||||
integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==
|
||||
dependencies:
|
||||
is-fullwidth-code-point "^2.0.0"
|
||||
strip-ansi "^4.0.0"
|
||||
|
||||
strip-ansi@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
|
||||
integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8=
|
||||
dependencies:
|
||||
ansi-regex "^3.0.0"
|
||||
|
||||
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
|
||||
version "6.0.1"
|
||||
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
|
||||
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
|
||||
dependencies:
|
||||
ansi-regex "^5.0.1"
|
||||
|
||||
strip-final-newline@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
|
||||
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==
|
||||
|
||||
which-module@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
|
||||
integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=
|
||||
|
||||
wrap-ansi@^6.2.0:
|
||||
version "6.2.0"
|
||||
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53"
|
||||
integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==
|
||||
dependencies:
|
||||
ansi-styles "^4.0.0"
|
||||
string-width "^4.1.0"
|
||||
strip-ansi "^6.0.0"
|
||||
|
||||
y18n@^4.0.0:
|
||||
version "4.0.3"
|
||||
resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.3.tgz#b5f259c82cd6e336921efd7bfd8bf560de9eeedf"
|
||||
integrity sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==
|
||||
|
||||
yargs-parser@^18.1.2:
|
||||
version "18.1.3"
|
||||
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0"
|
||||
integrity sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==
|
||||
dependencies:
|
||||
camelcase "^5.0.0"
|
||||
decamelize "^1.2.0"
|
||||
|
||||
yargs@15.4.1:
|
||||
version "15.4.1"
|
||||
resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8"
|
||||
integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==
|
||||
dependencies:
|
||||
cliui "^6.0.0"
|
||||
decamelize "^1.2.0"
|
||||
find-up "^4.1.0"
|
||||
get-caller-file "^2.0.1"
|
||||
require-directory "^2.1.1"
|
||||
require-main-filename "^2.0.0"
|
||||
set-blocking "^2.0.0"
|
||||
string-width "^4.2.0"
|
||||
which-module "^2.0.0"
|
||||
y18n "^4.0.0"
|
||||
yargs-parser "^18.1.2"
|
||||
9
packages/build-utils/test/fixtures/28-pnpm-7/package.json
vendored
Normal file
9
packages/build-utils/test/fixtures/28-pnpm-7/package.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"private": "true",
|
||||
"scripts": {
|
||||
"build": "mkdir -p public && (printf \"pnpm version: \" && pnpm -v) > public/index.txt"
|
||||
},
|
||||
"dependencies": {
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
}
|
||||
19
packages/build-utils/test/fixtures/28-pnpm-7/pnpm-lock.yaml
generated
vendored
Normal file
19
packages/build-utils/test/fixtures/28-pnpm-7/pnpm-lock.yaml
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
lockfileVersion: 5.4
|
||||
|
||||
specifiers:
|
||||
once: ^1.4.0
|
||||
|
||||
dependencies:
|
||||
once: 1.4.0
|
||||
|
||||
packages:
|
||||
|
||||
/once/1.4.0:
|
||||
resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=}
|
||||
dependencies:
|
||||
wrappy: 1.0.2
|
||||
dev: false
|
||||
|
||||
/wrappy/1.0.2:
|
||||
resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=}
|
||||
dev: false
|
||||
10
packages/build-utils/test/fixtures/28-pnpm-7/vercel.json
vendored
Normal file
10
packages/build-utils/test/fixtures/28-pnpm-7/vercel.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [{ "src": "package.json", "use": "@vercel/static-build" }],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/",
|
||||
"mustContain": "pnpm version: 7"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -32,6 +32,7 @@ const skipFixtures: string[] = [
|
||||
'08-zero-config-middleman',
|
||||
'21-npm-workspaces',
|
||||
'23-pnpm-workspaces',
|
||||
'27-yarn-workspaces',
|
||||
];
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
|
||||
31
packages/build-utils/test/unit.detect-workspace-managers.test.ts
vendored
Normal file
31
packages/build-utils/test/unit.detect-workspace-managers.test.ts
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import path from 'path';
|
||||
import { detectFramework } from '../src/detect-framework';
|
||||
import workspaceManagers from '../src/workspaces/workspace-managers';
|
||||
import { FixtureFilesystem } from './utils/fixture-filesystem';
|
||||
|
||||
describe('workspace-managers', () => {
|
||||
describe.each([
|
||||
['npm', '21-npm-workspaces'],
|
||||
['pnpm', '23-pnpm-workspaces'],
|
||||
['yarn', '27-yarn-workspaces'],
|
||||
['yarn', '25-multiple-lock-files-yarn'],
|
||||
['pnpm', '26-multiple-lock-files-pnpm'],
|
||||
[null, '22-pnpm'],
|
||||
])('with detectFramework', (frameworkSlug, fixturePath) => {
|
||||
const testName = frameworkSlug
|
||||
? `should detect a ${frameworkSlug} workspace for ${fixturePath}`
|
||||
: `should not detect framework for ${fixturePath}`;
|
||||
|
||||
it(testName, async () => {
|
||||
const fixture = path.join(__dirname, 'fixtures', fixturePath);
|
||||
const fs = new FixtureFilesystem(fixture);
|
||||
|
||||
const result = await detectFramework({
|
||||
fs,
|
||||
frameworkList: workspaceManagers,
|
||||
});
|
||||
|
||||
expect(result).toBe(frameworkSlug);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,21 +1,32 @@
|
||||
import path from 'path';
|
||||
import frameworkList from '@vercel/frameworks';
|
||||
import { detectFramework, DetectorFilesystem } from '../src';
|
||||
import { Stat } from '../src/detectors/filesystem';
|
||||
|
||||
const posixPath = path.posix;
|
||||
|
||||
class VirtualFilesystem extends DetectorFilesystem {
|
||||
private files: Map<string, Buffer>;
|
||||
private cwd: string;
|
||||
|
||||
constructor(files: { [key: string]: string | Buffer }) {
|
||||
constructor(files: { [key: string]: string | Buffer }, cwd = '') {
|
||||
super();
|
||||
this.files = new Map();
|
||||
this.cwd = cwd;
|
||||
Object.entries(files).map(([key, value]) => {
|
||||
const buffer = typeof value === 'string' ? Buffer.from(value) : value;
|
||||
this.files.set(key, buffer);
|
||||
});
|
||||
}
|
||||
|
||||
async _hasPath(path: string): Promise<boolean> {
|
||||
private _normalizePath(rawPath: string): string {
|
||||
return posixPath.normalize(rawPath);
|
||||
}
|
||||
|
||||
async _hasPath(name: string): Promise<boolean> {
|
||||
const basePath = this._normalizePath(posixPath.join(this.cwd, name));
|
||||
for (const file of this.files.keys()) {
|
||||
if (file.startsWith(path)) {
|
||||
if (file.startsWith(basePath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -24,11 +35,13 @@ class VirtualFilesystem extends DetectorFilesystem {
|
||||
}
|
||||
|
||||
async _isFile(name: string): Promise<boolean> {
|
||||
return this.files.has(name);
|
||||
const basePath = this._normalizePath(posixPath.join(this.cwd, name));
|
||||
return this.files.has(basePath);
|
||||
}
|
||||
|
||||
async _readFile(name: string): Promise<Buffer> {
|
||||
const file = this.files.get(name);
|
||||
const basePath = this._normalizePath(posixPath.join(this.cwd, name));
|
||||
const file = this.files.get(basePath);
|
||||
|
||||
if (file === undefined) {
|
||||
throw new Error('File does not exist');
|
||||
@@ -40,115 +53,291 @@ class VirtualFilesystem extends DetectorFilesystem {
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* An example of how to implement readdir for a virtual filesystem.
|
||||
*/
|
||||
async _readdir(name = '/'): Promise<Stat[]> {
|
||||
return (
|
||||
[...this.files.keys()]
|
||||
.map(filepath => {
|
||||
const basePath = this._normalizePath(
|
||||
posixPath.join(this.cwd, name === '/' ? '' : name)
|
||||
);
|
||||
const fileDirectoryName = posixPath.dirname(filepath);
|
||||
|
||||
if (fileDirectoryName === basePath) {
|
||||
return {
|
||||
name: posixPath.basename(filepath),
|
||||
path: filepath.replace(
|
||||
this.cwd === '' ? this.cwd : `${this.cwd}/`,
|
||||
''
|
||||
),
|
||||
type: 'file',
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
(basePath === '.' && fileDirectoryName !== '.') ||
|
||||
fileDirectoryName.startsWith(basePath)
|
||||
) {
|
||||
let subDirectoryName = fileDirectoryName.replace(
|
||||
basePath === '.' ? '' : `${basePath}/`,
|
||||
''
|
||||
);
|
||||
|
||||
if (subDirectoryName.includes('/')) {
|
||||
subDirectoryName = subDirectoryName.split('/')[0];
|
||||
}
|
||||
|
||||
return {
|
||||
name: subDirectoryName,
|
||||
path:
|
||||
name === '/'
|
||||
? subDirectoryName
|
||||
: this._normalizePath(posixPath.join(name, subDirectoryName)),
|
||||
type: 'dir',
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
})
|
||||
// remove nulls
|
||||
.filter((stat): stat is Stat => stat !== null)
|
||||
// remove duplicates
|
||||
.filter(
|
||||
(stat, index, self) =>
|
||||
index ===
|
||||
self.findIndex(s => s.name === stat.name && s.path === stat.path)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* An example of how to implement chdir for a virtual filesystem.
|
||||
*/
|
||||
_chdir(name: string): DetectorFilesystem {
|
||||
const basePath = this._normalizePath(posixPath.join(this.cwd, name));
|
||||
const files = Object.fromEntries(
|
||||
[...this.files.keys()].map(key => [key, this.files.get(key) ?? ''])
|
||||
);
|
||||
|
||||
return new VirtualFilesystem(files, basePath);
|
||||
}
|
||||
}
|
||||
|
||||
describe('#detectFramework', () => {
|
||||
it('Do not detect anything', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'README.md': '# hi',
|
||||
'api/cheese.js': 'export default (req, res) => res.end("cheese");',
|
||||
});
|
||||
describe('DetectorFilesystem', () => {
|
||||
it('should return the directory contents relative to the cwd', async () => {
|
||||
const files = {
|
||||
'package.json': '{}',
|
||||
'packages/app1/package.json': '{}',
|
||||
'packages/app2/package.json': '{}',
|
||||
};
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe(null);
|
||||
const fs = new VirtualFilesystem(files);
|
||||
|
||||
expect(await fs.readdir('/')).toEqual([
|
||||
{ name: 'package.json', path: 'package.json', type: 'file' },
|
||||
{ name: 'packages', path: 'packages', type: 'dir' },
|
||||
]);
|
||||
|
||||
expect(await fs.readdir('packages')).toEqual([
|
||||
{ name: 'app1', path: 'packages/app1', type: 'dir' },
|
||||
{ name: 'app2', path: 'packages/app2', type: 'dir' },
|
||||
]);
|
||||
|
||||
expect(await fs.readdir('./packages')).toEqual([
|
||||
{ name: 'app1', path: 'packages/app1', type: 'dir' },
|
||||
{ name: 'app2', path: 'packages/app2', type: 'dir' },
|
||||
]);
|
||||
|
||||
expect(await fs.readdir('packages/app1')).toEqual([
|
||||
{
|
||||
name: 'package.json',
|
||||
path: 'packages/app1/package.json',
|
||||
type: 'file',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('Detect Next.js', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'package.json': JSON.stringify({
|
||||
dependencies: {
|
||||
next: '9.0.0',
|
||||
},
|
||||
}),
|
||||
it('should be able to change directories', async () => {
|
||||
const nextPackageJson = JSON.stringify({
|
||||
dependencies: {
|
||||
next: '9.0.0',
|
||||
},
|
||||
});
|
||||
const gatsbyPackageJson = JSON.stringify({
|
||||
dependencies: {
|
||||
gatsby: '1.0.0',
|
||||
},
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('nextjs');
|
||||
const files = {
|
||||
'package.json': '{}',
|
||||
'packages/app1/package.json': nextPackageJson,
|
||||
'packages/app2/package.json': gatsbyPackageJson,
|
||||
};
|
||||
|
||||
const fs = new VirtualFilesystem(files);
|
||||
const packagesFs = fs.chdir('packages');
|
||||
|
||||
expect(await packagesFs.readdir('/')).toEqual([
|
||||
{ name: 'app1', path: 'app1', type: 'dir' },
|
||||
{ name: 'app2', path: 'app2', type: 'dir' },
|
||||
]);
|
||||
|
||||
expect(await packagesFs.hasPath('app1')).toBe(true);
|
||||
expect(await packagesFs.hasPath('app3')).toBe(false);
|
||||
expect(await packagesFs.isFile('app1')).toBe(false);
|
||||
expect(await packagesFs.isFile('app2')).toBe(false);
|
||||
expect(await packagesFs.isFile('app1/package.json')).toBe(true);
|
||||
expect(await packagesFs.isFile('app2/package.json')).toBe(true);
|
||||
expect(
|
||||
await (await packagesFs.readFile('app1/package.json')).toString()
|
||||
).toEqual(nextPackageJson);
|
||||
expect(
|
||||
await (await packagesFs.readFile('app2/package.json')).toString()
|
||||
).toEqual(gatsbyPackageJson);
|
||||
|
||||
expect(await detectFramework({ fs: packagesFs, frameworkList })).toBe(null);
|
||||
|
||||
const nextAppFs = packagesFs.chdir('app1');
|
||||
|
||||
expect(await nextAppFs.readdir('/')).toEqual([
|
||||
{ name: 'package.json', path: 'package.json', type: 'file' },
|
||||
]);
|
||||
|
||||
expect(await (await nextAppFs.readFile('package.json')).toString()).toEqual(
|
||||
nextPackageJson
|
||||
);
|
||||
|
||||
expect(await detectFramework({ fs: nextAppFs, frameworkList })).toBe(
|
||||
'nextjs'
|
||||
);
|
||||
|
||||
const gatsbyAppFs = packagesFs.chdir('./app2');
|
||||
|
||||
expect(await gatsbyAppFs.readdir('/')).toEqual([
|
||||
{ name: 'package.json', path: 'package.json', type: 'file' },
|
||||
]);
|
||||
|
||||
expect(
|
||||
await (await gatsbyAppFs.readFile('package.json')).toString()
|
||||
).toEqual(gatsbyPackageJson);
|
||||
|
||||
expect(await detectFramework({ fs: gatsbyAppFs, frameworkList })).toBe(
|
||||
'gatsby'
|
||||
);
|
||||
});
|
||||
|
||||
it('Detect Nuxt.js', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'package.json': JSON.stringify({
|
||||
dependencies: {
|
||||
nuxt: '1.0.0',
|
||||
},
|
||||
}),
|
||||
describe('#detectFramework', () => {
|
||||
it('Do not detect anything', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'README.md': '# hi',
|
||||
'api/cheese.js': 'export default (req, res) => res.end("cheese");',
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe(null);
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('nuxtjs');
|
||||
});
|
||||
it('Detect Next.js', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'package.json': JSON.stringify({
|
||||
dependencies: {
|
||||
next: '9.0.0',
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
it('Detect Gatsby', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'package.json': JSON.stringify({
|
||||
dependencies: {
|
||||
gatsby: '1.0.0',
|
||||
},
|
||||
}),
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('nextjs');
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('gatsby');
|
||||
});
|
||||
it('Detect Nuxt.js', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'package.json': JSON.stringify({
|
||||
dependencies: {
|
||||
nuxt: '1.0.0',
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
it('Detect Hugo #1', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.yaml': 'baseURL: http://example.org/',
|
||||
'content/post.md': '# hello world',
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('nuxtjs');
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
||||
});
|
||||
it('Detect Gatsby', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'package.json': JSON.stringify({
|
||||
dependencies: {
|
||||
gatsby: '1.0.0',
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
it('Detect Hugo #2', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.json': '{ "baseURL": "http://example.org/" }',
|
||||
'content/post.md': '# hello world',
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('gatsby');
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
||||
});
|
||||
it('Detect Hugo #1', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.yaml': 'baseURL: http://example.org/',
|
||||
'content/post.md': '# hello world',
|
||||
});
|
||||
|
||||
it('Detect Hugo #3', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.toml': 'baseURL = "http://example.org/"',
|
||||
'content/post.md': '# hello world',
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
||||
});
|
||||
it('Detect Hugo #2', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.json': '{ "baseURL": "http://example.org/" }',
|
||||
'content/post.md': '# hello world',
|
||||
});
|
||||
|
||||
it('Detect Jekyll', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'_config.yml': 'config',
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('jekyll');
|
||||
});
|
||||
it('Detect Hugo #3', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.toml': 'baseURL = "http://example.org/"',
|
||||
'content/post.md': '# hello world',
|
||||
});
|
||||
|
||||
it('Detect Middleman', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.rb': 'config',
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('middleman');
|
||||
});
|
||||
it('Detect Jekyll', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'_config.yml': 'config',
|
||||
});
|
||||
|
||||
it('Detect Scully', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'package.json': JSON.stringify({
|
||||
dependencies: {
|
||||
'@angular/cli': 'latest',
|
||||
'@scullyio/init': 'latest',
|
||||
},
|
||||
}),
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('jekyll');
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('scully');
|
||||
});
|
||||
it('Detect Middleman', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.rb': 'config',
|
||||
});
|
||||
|
||||
it('Detect Zola', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.toml': 'base_url = "/"',
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('middleman');
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('zola');
|
||||
it('Detect Scully', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'package.json': JSON.stringify({
|
||||
dependencies: {
|
||||
'@angular/cli': 'latest',
|
||||
'@scullyio/init': 'latest',
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('scully');
|
||||
});
|
||||
|
||||
it('Detect Zola', async () => {
|
||||
const fs = new VirtualFilesystem({
|
||||
'config.toml': 'base_url = "/"',
|
||||
});
|
||||
|
||||
expect(await detectFramework({ fs, frameworkList })).toBe('zola');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import assert from 'assert';
|
||||
import { getEnvForPackageManager, NodeVersion } from '../src';
|
||||
import { CliType } from '../src/fs/run-user-scripts';
|
||||
import { getEnvForPackageManager } from '../src';
|
||||
|
||||
describe('Test `getEnvForPackageManager()`', () => {
|
||||
const cases = [
|
||||
const cases: Array<{
|
||||
name: string;
|
||||
args: Parameters<typeof getEnvForPackageManager>[0];
|
||||
want: unknown;
|
||||
}> = [
|
||||
{
|
||||
name: 'should do nothing to env for npm < 6 and node < 16',
|
||||
args: {
|
||||
cliType: 'npm' as CliType,
|
||||
nodeVersion: {
|
||||
major: 14,
|
||||
} as NodeVersion,
|
||||
cliType: 'npm',
|
||||
nodeVersion: { major: 14, range: '14.x', runtime: 'nodejs14.x' },
|
||||
lockfileVersion: 1,
|
||||
env: {
|
||||
FOO: 'bar',
|
||||
@@ -23,10 +24,8 @@ describe('Test `getEnvForPackageManager()`', () => {
|
||||
{
|
||||
name: 'should set path if npm 7+ is detected and node < 16',
|
||||
args: {
|
||||
cliType: 'npm' as CliType,
|
||||
nodeVersion: {
|
||||
major: 14,
|
||||
} as NodeVersion,
|
||||
cliType: 'npm',
|
||||
nodeVersion: { major: 14, range: '14.x', runtime: 'nodejs14.x' },
|
||||
lockfileVersion: 2,
|
||||
env: {
|
||||
FOO: 'bar',
|
||||
@@ -41,10 +40,8 @@ describe('Test `getEnvForPackageManager()`', () => {
|
||||
{
|
||||
name: 'should not set path if node is 16 and npm 7+ is detected',
|
||||
args: {
|
||||
cliType: 'npm' as CliType,
|
||||
nodeVersion: {
|
||||
major: 16,
|
||||
} as NodeVersion,
|
||||
cliType: 'npm',
|
||||
nodeVersion: { major: 16, range: '16.x', runtime: 'nodejs16.x' },
|
||||
lockfileVersion: 2,
|
||||
env: {
|
||||
FOO: 'bar',
|
||||
@@ -59,10 +56,8 @@ describe('Test `getEnvForPackageManager()`', () => {
|
||||
{
|
||||
name: 'should set YARN_NODE_LINKER w/yarn if it is not already defined',
|
||||
args: {
|
||||
cliType: 'yarn' as CliType,
|
||||
nodeVersion: {
|
||||
major: 16,
|
||||
} as NodeVersion,
|
||||
cliType: 'yarn',
|
||||
nodeVersion: { major: 16, range: '16.x', runtime: 'nodejs16.x' },
|
||||
lockfileVersion: 2,
|
||||
env: {
|
||||
FOO: 'bar',
|
||||
@@ -76,10 +71,8 @@ describe('Test `getEnvForPackageManager()`', () => {
|
||||
{
|
||||
name: 'should not set YARN_NODE_LINKER if it already exists',
|
||||
args: {
|
||||
cliType: 'yarn' as CliType,
|
||||
nodeVersion: {
|
||||
major: 16,
|
||||
} as NodeVersion,
|
||||
cliType: 'yarn',
|
||||
nodeVersion: { major: 16, range: '16.x', runtime: 'nodejs16.x' },
|
||||
lockfileVersion: 2,
|
||||
env: {
|
||||
FOO: 'bar',
|
||||
@@ -91,6 +84,36 @@ describe('Test `getEnvForPackageManager()`', () => {
|
||||
YARN_NODE_LINKER: 'exists',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'should set path if pnpm 7+ is detected',
|
||||
args: {
|
||||
cliType: 'pnpm',
|
||||
nodeVersion: { major: 16, range: '16.x', runtime: 'nodejs16.x' },
|
||||
lockfileVersion: 5.4,
|
||||
env: {
|
||||
FOO: 'bar',
|
||||
PATH: 'foo',
|
||||
},
|
||||
},
|
||||
want: {
|
||||
FOO: 'bar',
|
||||
PATH: '/pnpm7/node_modules/.bin:foo',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'should not set path if pnpm 6 is detected',
|
||||
args: {
|
||||
cliType: 'pnpm',
|
||||
nodeVersion: { major: 14, range: '14.x', runtime: 'nodejs14.x' },
|
||||
lockfileVersion: 5.3,
|
||||
env: {
|
||||
FOO: 'bar',
|
||||
},
|
||||
},
|
||||
want: {
|
||||
FOO: 'bar',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
for (const { name, want, args } of cases) {
|
||||
|
||||
40
packages/build-utils/test/unit.test.ts
vendored
40
packages/build-utils/test/unit.test.ts
vendored
@@ -176,9 +176,13 @@ it('should only match supported node versions, otherwise throw an error', async
|
||||
'major',
|
||||
14
|
||||
);
|
||||
expect(await getSupportedNodeVersion('16.x', false)).toHaveProperty(
|
||||
'major',
|
||||
16
|
||||
);
|
||||
|
||||
const autoMessage =
|
||||
'Please set Node.js Version to 14.x in your Project Settings to use Node.js 14.';
|
||||
'Please set Node.js Version to 16.x in your Project Settings to use Node.js 16.';
|
||||
await expectBuilderError(
|
||||
getSupportedNodeVersion('8.11.x', true),
|
||||
autoMessage
|
||||
@@ -196,9 +200,13 @@ it('should only match supported node versions, otherwise throw an error', async
|
||||
'major',
|
||||
14
|
||||
);
|
||||
expect(await getSupportedNodeVersion('16.x', true)).toHaveProperty(
|
||||
'major',
|
||||
16
|
||||
);
|
||||
|
||||
const foundMessage =
|
||||
'Please set "engines": { "node": "14.x" } in your `package.json` file to use Node.js 14.';
|
||||
'Please set "engines": { "node": "16.x" } in your `package.json` file to use Node.js 16.';
|
||||
await expectBuilderError(
|
||||
getSupportedNodeVersion('8.11.x', false),
|
||||
foundMessage
|
||||
@@ -219,8 +227,8 @@ it('should match all semver ranges', async () => {
|
||||
// See https://docs.npmjs.com/files/package.json#engines
|
||||
expect(await getSupportedNodeVersion('12.0.0')).toHaveProperty('major', 12);
|
||||
expect(await getSupportedNodeVersion('12.x')).toHaveProperty('major', 12);
|
||||
expect(await getSupportedNodeVersion('>=10')).toHaveProperty('major', 14);
|
||||
expect(await getSupportedNodeVersion('>=10.3.0')).toHaveProperty('major', 14);
|
||||
expect(await getSupportedNodeVersion('>=10')).toHaveProperty('major', 16);
|
||||
expect(await getSupportedNodeVersion('>=10.3.0')).toHaveProperty('major', 16);
|
||||
expect(await getSupportedNodeVersion('11.5.0 - 12.5.0')).toHaveProperty(
|
||||
'major',
|
||||
12
|
||||
@@ -231,6 +239,10 @@ it('should match all semver ranges', async () => {
|
||||
);
|
||||
expect(await getSupportedNodeVersion('~12.5.0')).toHaveProperty('major', 12);
|
||||
expect(await getSupportedNodeVersion('^12.5.0')).toHaveProperty('major', 12);
|
||||
expect(await getSupportedNodeVersion('12.5.0 - 14.5.0')).toHaveProperty(
|
||||
'major',
|
||||
14
|
||||
);
|
||||
});
|
||||
|
||||
it('should ignore node version in vercel dev getNodeVersion()', async () => {
|
||||
@@ -246,8 +258,8 @@ it('should ignore node version in vercel dev getNodeVersion()', async () => {
|
||||
|
||||
it('should select project setting from config when no package.json is found', async () => {
|
||||
expect(
|
||||
await getNodeVersion('/tmp', undefined, { nodeVersion: '14.x' }, {})
|
||||
).toHaveProperty('range', '14.x');
|
||||
await getNodeVersion('/tmp', undefined, { nodeVersion: '16.x' }, {})
|
||||
).toHaveProperty('range', '16.x');
|
||||
expect(warningMessages).toStrictEqual([]);
|
||||
});
|
||||
|
||||
@@ -277,18 +289,8 @@ it('should not warn when package.json engines matches project setting from confi
|
||||
expect(warningMessages).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it('should select nodejs16.x with ENABLE_EXPERIMENTAL_NODE16', async () => {
|
||||
process.env.ENABLE_EXPERIMENTAL_NODE16 = '1';
|
||||
const result = await getNodeVersion('/tmp', undefined, {}, {});
|
||||
delete process.env.ENABLE_EXPERIMENTAL_NODE16;
|
||||
expect(result).toEqual({ major: 16, range: '16.x', runtime: 'nodejs16.x' });
|
||||
expect(warningMessages).toStrictEqual([
|
||||
'Warning: Using experimental Node.js 16.x due to ENABLE_EXPERIMENTAL_NODE16=1',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should get latest node version', async () => {
|
||||
expect(getLatestNodeVersion()).toHaveProperty('major', 14);
|
||||
expect(getLatestNodeVersion()).toHaveProperty('major', 16);
|
||||
});
|
||||
|
||||
it('should throw for discontinued versions', async () => {
|
||||
@@ -323,8 +325,8 @@ it('should warn for deprecated versions, soon to be discontinued', async () => {
|
||||
10
|
||||
);
|
||||
expect(warningMessages).toStrictEqual([
|
||||
'Error: Node.js version 10.x is deprecated. Deployments created on or after 2021-04-20 will fail to build. Please set "engines": { "node": "14.x" } in your `package.json` file to use Node.js 14. This change is the result of a decision made by an upstream infrastructure provider (AWS).',
|
||||
'Error: Node.js version 10.x is deprecated. Deployments created on or after 2021-04-20 will fail to build. Please set Node.js Version to 14.x in your Project Settings to use Node.js 14. This change is the result of a decision made by an upstream infrastructure provider (AWS).',
|
||||
'Error: Node.js version 10.x is deprecated. Deployments created on or after 2021-04-20 will fail to build. Please set "engines": { "node": "16.x" } in your `package.json` file to use Node.js 16. This change is the result of a decision made by an upstream infrastructure provider (AWS).',
|
||||
'Error: Node.js version 10.x is deprecated. Deployments created on or after 2021-04-20 will fail to build. Please set Node.js Version to 16.x in your Project Settings to use Node.js 16. This change is the result of a decision made by an upstream infrastructure provider (AWS).',
|
||||
]);
|
||||
|
||||
global.Date.now = realDateNow;
|
||||
|
||||
51
packages/build-utils/test/utils/fixture-filesystem.ts
Normal file
51
packages/build-utils/test/utils/fixture-filesystem.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { promises } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { DetectorFilesystem } from '../../src';
|
||||
import { Stat } from '../../src/detectors/filesystem';
|
||||
|
||||
const { stat, readFile, readdir } = promises;
|
||||
|
||||
export class FixtureFilesystem extends DetectorFilesystem {
|
||||
private rootPath: string;
|
||||
|
||||
constructor(fixturePath: string) {
|
||||
super();
|
||||
|
||||
this.rootPath = fixturePath;
|
||||
}
|
||||
|
||||
async _hasPath(name: string): Promise<boolean> {
|
||||
try {
|
||||
const filePath = path.join(this.rootPath, name);
|
||||
await stat(filePath);
|
||||
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async _readFile(name: string): Promise<Buffer> {
|
||||
const filePath = path.join(this.rootPath, name);
|
||||
return readFile(filePath);
|
||||
}
|
||||
async _isFile(name: string): Promise<boolean> {
|
||||
const filePath = path.join(this.rootPath, name);
|
||||
return (await stat(filePath)).isFile();
|
||||
}
|
||||
|
||||
async _readdir(name: string): Promise<Stat[]> {
|
||||
const dirPath = path.join(this.rootPath, name);
|
||||
const files = await readdir(dirPath, { withFileTypes: true });
|
||||
|
||||
return files.map(file => ({
|
||||
name: file.name,
|
||||
type: file.isFile() ? 'file' : 'dir',
|
||||
path: path.join(name, file.name),
|
||||
}));
|
||||
}
|
||||
|
||||
_chdir(name: string): DetectorFilesystem {
|
||||
return new FixtureFilesystem(path.join(this.rootPath, name));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vercel",
|
||||
"version": "24.2.0",
|
||||
"version": "24.2.2-canary.1",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Vercel",
|
||||
@@ -43,11 +43,11 @@
|
||||
"node": ">= 12"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.16.0",
|
||||
"@vercel/go": "1.4.0",
|
||||
"@vercel/node": "1.15.0",
|
||||
"@vercel/python": "2.3.0",
|
||||
"@vercel/ruby": "1.3.3",
|
||||
"@vercel/build-utils": "3.0.1-canary.1",
|
||||
"@vercel/go": "1.4.2-canary.0",
|
||||
"@vercel/node": "1.15.2-canary.0",
|
||||
"@vercel/python": "2.3.2-canary.0",
|
||||
"@vercel/ruby": "1.3.5-canary.0",
|
||||
"update-notifier": "4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -90,9 +90,8 @@
|
||||
"@types/update-notifier": "5.1.0",
|
||||
"@types/which": "1.3.2",
|
||||
"@types/write-json-file": "2.2.1",
|
||||
"@vercel/client": "11.0.0",
|
||||
"@vercel/fetch-retry": "5.0.3",
|
||||
"@vercel/frameworks": "0.8.0",
|
||||
"@vercel/client": "11.0.2-canary.0",
|
||||
"@vercel/frameworks": "0.9.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@zeit/fun": "0.11.2",
|
||||
"@zeit/source-map-support": "0.6.2",
|
||||
|
||||
@@ -61,6 +61,8 @@ import { getPreferredPreviewURL } from '../../util/deploy/get-preferred-preview-
|
||||
import { Output } from '../../util/output';
|
||||
import { help } from './args';
|
||||
import { getDeploymentChecks } from '../../util/deploy/get-deployment-checks';
|
||||
import parseTarget from '../../util/deploy/parse-target';
|
||||
import getPrebuiltJson from '../../util/deploy/get-prebuilt-json';
|
||||
|
||||
export default async (client: Client) => {
|
||||
const { output } = client;
|
||||
@@ -155,7 +157,7 @@ export default async (client: Client) => {
|
||||
}
|
||||
}
|
||||
|
||||
const { log, debug, error, warn, isTTY } = output;
|
||||
const { log, debug, error, prettyError, isTTY } = output;
|
||||
|
||||
const quiet = !isTTY;
|
||||
|
||||
@@ -181,6 +183,12 @@ export default async (client: Client) => {
|
||||
);
|
||||
}
|
||||
|
||||
// build `target`
|
||||
const target = parseTarget(output, argv['--target'], argv['--prod']);
|
||||
if (typeof target === 'number') {
|
||||
return target;
|
||||
}
|
||||
|
||||
// build `--prebuilt`
|
||||
if (argv['--prebuilt']) {
|
||||
const prebuiltExists = await fs.pathExists(join(path, '.vercel/output'));
|
||||
@@ -194,6 +202,25 @@ export default async (client: Client) => {
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const prebuiltBuild = await getPrebuiltJson(path);
|
||||
const assumedTarget = target || 'preview';
|
||||
if (prebuiltBuild?.target && prebuiltBuild.target !== assumedTarget) {
|
||||
let specifyTarget = '';
|
||||
if (prebuiltBuild.target === 'production') {
|
||||
specifyTarget = ` --prod`;
|
||||
}
|
||||
|
||||
prettyError({
|
||||
message: `The ${param(
|
||||
'--prebuilt'
|
||||
)} option was used with the target environment "${assumedTarget}", but the prebuilt output found in ".vercel/output" was built with target environment "${
|
||||
prebuiltBuild.target
|
||||
}". Please run ${getCommandName(`--prebuilt${specifyTarget}`)}.`,
|
||||
link: 'https://vercel.link/prebuilt-environment-mismatch',
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve `project` and `org` from .vercel
|
||||
@@ -418,33 +445,6 @@ export default async (client: Client) => {
|
||||
.filter(Boolean);
|
||||
const regions = regionFlag.length > 0 ? regionFlag : localConfig.regions;
|
||||
|
||||
// build `target`
|
||||
let target;
|
||||
if (argv['--target']) {
|
||||
const deprecatedTarget = argv['--target'];
|
||||
|
||||
if (!['staging', 'production'].includes(deprecatedTarget)) {
|
||||
error(
|
||||
`The specified ${param('--target')} ${code(
|
||||
deprecatedTarget
|
||||
)} is not valid`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (deprecatedTarget === 'production') {
|
||||
warn(
|
||||
'We recommend using the much shorter `--prod` option instead of `--target production` (deprecated)'
|
||||
);
|
||||
}
|
||||
|
||||
output.debug(`Setting target to ${deprecatedTarget}`);
|
||||
target = deprecatedTarget;
|
||||
} else if (argv['--prod']) {
|
||||
output.debug('Setting target to production');
|
||||
target = 'production';
|
||||
}
|
||||
|
||||
const currentTeam = org?.type === 'team' ? org.id : undefined;
|
||||
const now = new Now({
|
||||
client,
|
||||
|
||||
@@ -10,6 +10,8 @@ import { ProjectSettings } from '../../types';
|
||||
import getDecryptedEnvRecords from '../../util/get-decrypted-env-records';
|
||||
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';
|
||||
|
||||
type Options = {
|
||||
'--listen': string;
|
||||
@@ -46,6 +48,13 @@ export default async function dev(
|
||||
}
|
||||
|
||||
if (link.status === 'error') {
|
||||
if (link.reason === 'HEADLESS') {
|
||||
client.output.error(
|
||||
`Command ${getCommandName(
|
||||
'dev'
|
||||
)} requires confirmation. Use option ${param('--confirm')} to confirm.`
|
||||
);
|
||||
}
|
||||
return link.exitCode;
|
||||
}
|
||||
|
||||
@@ -82,7 +91,7 @@ export default async function dev(
|
||||
}
|
||||
|
||||
[{ envs: projectEnvs }, { systemEnvValues }] = await Promise.all([
|
||||
getDecryptedEnvRecords(output, client, project.id),
|
||||
getDecryptedEnvRecords(output, client, project.id, 'vercel-cli:dev'),
|
||||
project.autoExposeSystemEnvs
|
||||
? getSystemEnvValues(output, client, project.id)
|
||||
: { systemEnvValues: [] },
|
||||
|
||||
7
packages/cli/src/commands/env/add.ts
vendored
7
packages/cli/src/commands/env/add.ts
vendored
@@ -79,7 +79,12 @@ export default async function add(
|
||||
}
|
||||
}
|
||||
|
||||
const { envs } = await getEnvRecords(output, client, project.id);
|
||||
const { envs } = await getEnvRecords(
|
||||
output,
|
||||
client,
|
||||
project.id,
|
||||
'vercel-cli:env:add'
|
||||
);
|
||||
const existing = new Set(
|
||||
envs.filter(r => r.key === envName).map(r => r.target)
|
||||
);
|
||||
|
||||
3
packages/cli/src/commands/env/index.ts
vendored
3
packages/cli/src/commands/env/index.ts
vendored
@@ -147,7 +147,8 @@ export default async function main(client: Client) {
|
||||
argv,
|
||||
args,
|
||||
output,
|
||||
cwd
|
||||
cwd,
|
||||
'vercel-cli:env:pull'
|
||||
);
|
||||
default:
|
||||
output.error(getInvalidSubcommand(COMMAND_CONFIG));
|
||||
|
||||
14
packages/cli/src/commands/env/ls.ts
vendored
14
packages/cli/src/commands/env/ls.ts
vendored
@@ -48,10 +48,16 @@ export default async function ls(
|
||||
|
||||
const lsStamp = stamp();
|
||||
|
||||
const { envs } = await getEnvRecords(output, client, project.id, {
|
||||
target: envTarget,
|
||||
gitBranch: envGitBranch,
|
||||
});
|
||||
const { envs } = await getEnvRecords(
|
||||
output,
|
||||
client,
|
||||
project.id,
|
||||
'vercel-cli:env:ls',
|
||||
{
|
||||
target: envTarget,
|
||||
gitBranch: envGitBranch,
|
||||
}
|
||||
);
|
||||
|
||||
if (envs.length === 0) {
|
||||
output.log(
|
||||
|
||||
6
packages/cli/src/commands/env/pull.ts
vendored
6
packages/cli/src/commands/env/pull.ts
vendored
@@ -13,6 +13,7 @@ import { Output } from '../../util/output';
|
||||
import param from '../../util/output/param';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
import { EnvRecordsSource } from '../../util/env/get-env-records';
|
||||
|
||||
const CONTENTS_PREFIX = '# Created by Vercel CLI\n';
|
||||
|
||||
@@ -49,7 +50,8 @@ export default async function pull(
|
||||
opts: Partial<Options>,
|
||||
args: string[],
|
||||
output: Output,
|
||||
cwd: string
|
||||
cwd: string,
|
||||
source: Extract<EnvRecordsSource, 'vercel-cli:env:pull' | 'vercel-cli:pull'>
|
||||
) {
|
||||
if (args.length > 1) {
|
||||
output.error(
|
||||
@@ -90,7 +92,7 @@ export default async function pull(
|
||||
output.spinner('Downloading');
|
||||
|
||||
const [{ envs: projectEnvs }, { systemEnvValues }] = await Promise.all([
|
||||
getDecryptedEnvRecords(output, client, project.id, environment),
|
||||
getDecryptedEnvRecords(output, client, project.id, source, environment),
|
||||
project.autoExposeSystemEnvs
|
||||
? getSystemEnvValues(output, client, project.id)
|
||||
: { systemEnvValues: [] },
|
||||
|
||||
14
packages/cli/src/commands/env/rm.ts
vendored
14
packages/cli/src/commands/env/rm.ts
vendored
@@ -67,10 +67,16 @@ export default async function rm(
|
||||
return 1;
|
||||
}
|
||||
|
||||
const result = await getEnvRecords(output, client, project.id, {
|
||||
target: envTarget,
|
||||
gitBranch: envGitBranch,
|
||||
});
|
||||
const result = await getEnvRecords(
|
||||
output,
|
||||
client,
|
||||
project.id,
|
||||
'vercel-cli:env:rm',
|
||||
{
|
||||
target: envTarget,
|
||||
gitBranch: envGitBranch,
|
||||
}
|
||||
);
|
||||
|
||||
let envs = result.envs.filter(env => env.key === envName);
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import getArgs from '../../util/get-args';
|
||||
import logo from '../../util/output/logo';
|
||||
import { getPkgName } from '../../util/pkg-name';
|
||||
import setupAndLink from '../../util/link/setup-and-link';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
import param from '../../util/output/param';
|
||||
|
||||
const help = () => {
|
||||
console.log(`
|
||||
@@ -67,6 +69,13 @@ export default async function main(client: Client) {
|
||||
});
|
||||
|
||||
if (link.status === 'error') {
|
||||
if (link.reason === 'HEADLESS') {
|
||||
client.output.error(
|
||||
`Command ${getCommandName(
|
||||
'link'
|
||||
)} requires confirmation. Use option ${param('--confirm')} to confirm.`
|
||||
);
|
||||
}
|
||||
return link.exitCode;
|
||||
} else if (link.status === 'not_linked') {
|
||||
// User aborted project linking questions
|
||||
|
||||
@@ -15,7 +15,8 @@ import {
|
||||
} from '../util/projects/link';
|
||||
import { writeProjectSettings } from '../util/projects/project-settings';
|
||||
import envPull from './env/pull';
|
||||
|
||||
import { getCommandName } from '../util/pkg-name';
|
||||
import param from '../util/output/param';
|
||||
import type { Project, Org } from '../types';
|
||||
import {
|
||||
isValidEnvTarget,
|
||||
@@ -102,6 +103,13 @@ async function ensureLink(
|
||||
}
|
||||
|
||||
if (link.status === 'error') {
|
||||
if (link.reason === 'HEADLESS') {
|
||||
client.output.error(
|
||||
`Command ${getCommandName(
|
||||
'pull'
|
||||
)} requires confirmation. Use option ${param('--yes')} to confirm.`
|
||||
);
|
||||
}
|
||||
return link.exitCode;
|
||||
}
|
||||
|
||||
@@ -123,7 +131,8 @@ async function pullAllEnvFiles(
|
||||
argv,
|
||||
[join('.vercel', environmentFile)],
|
||||
client.output,
|
||||
cwd
|
||||
cwd,
|
||||
'vercel-cli:pull'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,12 @@ let debug: (s: string) => void = () => {};
|
||||
let apiUrl = 'https://api.vercel.com';
|
||||
|
||||
const main = async () => {
|
||||
const { isTTY } = process.stdout;
|
||||
let { isTTY } = process.stdout;
|
||||
if (process.env.FORCE_TTY === '1') {
|
||||
isTTY = true;
|
||||
process.stdout.isTTY = true;
|
||||
process.stdin.isTTY = true;
|
||||
}
|
||||
|
||||
let argv;
|
||||
|
||||
|
||||
@@ -277,7 +277,17 @@ export interface PaginationOptions {
|
||||
export type ProjectLinkResult =
|
||||
| { status: 'linked'; org: Org; project: Project }
|
||||
| { status: 'not_linked'; org: null; project: null }
|
||||
| { status: 'error'; exitCode: number };
|
||||
| {
|
||||
status: 'error';
|
||||
exitCode: number;
|
||||
reason?:
|
||||
| 'HEADLESS'
|
||||
| 'NOT_AUTHORIZED'
|
||||
| 'TEAM_DELETED'
|
||||
| 'PATH_IS_FILE'
|
||||
| 'INVALID_ROOT_DIRECTORY'
|
||||
| 'MISSING_PROJECT_SETTINGS';
|
||||
};
|
||||
|
||||
export interface Token {
|
||||
id: string;
|
||||
|
||||
12
packages/cli/src/util/deploy/get-prebuilt-json.ts
Normal file
12
packages/cli/src/util/deploy/get-prebuilt-json.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import fs from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
|
||||
export default async function getPrebuiltJson(directory: string) {
|
||||
try {
|
||||
return await fs.readJSON(join(directory, '.vercel/output/builds.json'));
|
||||
} catch (error) {
|
||||
// ignoring error
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
41
packages/cli/src/util/deploy/parse-target.ts
Normal file
41
packages/cli/src/util/deploy/parse-target.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Output } from '../../util/output';
|
||||
import param from '../../util/output/param';
|
||||
import code from '../../util/output/code';
|
||||
|
||||
/**
|
||||
* Parses the environment target from the `--target` and `--prod` flags.
|
||||
*/
|
||||
export default function parseTarget(
|
||||
output: Output,
|
||||
targetArg?: string,
|
||||
prodArg?: boolean
|
||||
): string | number | undefined {
|
||||
if (targetArg) {
|
||||
const deprecatedTarget = targetArg;
|
||||
|
||||
if (!['staging', 'production'].includes(deprecatedTarget)) {
|
||||
output.error(
|
||||
`The specified ${param('--target')} ${code(
|
||||
deprecatedTarget
|
||||
)} is not valid`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (deprecatedTarget === 'production') {
|
||||
output.warn(
|
||||
'We recommend using the much shorter `--prod` option instead of `--target production` (deprecated)'
|
||||
);
|
||||
}
|
||||
|
||||
output.debug(`Setting target to ${deprecatedTarget}`);
|
||||
return deprecatedTarget;
|
||||
}
|
||||
|
||||
if (prodArg) {
|
||||
output.debug('Setting target to production');
|
||||
return 'production';
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
13
packages/cli/src/util/env/get-env-records.ts
vendored
13
packages/cli/src/util/env/get-env-records.ts
vendored
@@ -3,10 +3,20 @@ import Client from '../client';
|
||||
import { ProjectEnvVariable, ProjectEnvTarget } from '../../types';
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
/** The CLI command that was used that needs the environment variables. */
|
||||
export type EnvRecordsSource =
|
||||
| 'vercel-cli:env:ls'
|
||||
| 'vercel-cli:env:add'
|
||||
| 'vercel-cli:env:rm'
|
||||
| 'vercel-cli:env:pull'
|
||||
| 'vercel-cli:dev'
|
||||
| 'vercel-cli:pull';
|
||||
|
||||
export default async function getEnvRecords(
|
||||
output: Output,
|
||||
client: Client,
|
||||
projectId: string,
|
||||
source: EnvRecordsSource,
|
||||
{
|
||||
target,
|
||||
gitBranch,
|
||||
@@ -31,6 +41,9 @@ export default async function getEnvRecords(
|
||||
if (decrypt) {
|
||||
query.set('decrypt', decrypt.toString());
|
||||
}
|
||||
if (source) {
|
||||
query.set('source', source);
|
||||
}
|
||||
|
||||
const url = `/v8/projects/${projectId}/env?${query}`;
|
||||
|
||||
|
||||
@@ -6,15 +6,16 @@ import {
|
||||
ProjectEnvVariable,
|
||||
Secret,
|
||||
} from '../types';
|
||||
import getEnvRecords from './env/get-env-records';
|
||||
import getEnvRecords, { EnvRecordsSource } from './env/get-env-records';
|
||||
|
||||
export default async function getDecryptedEnvRecords(
|
||||
output: Output,
|
||||
client: Client,
|
||||
projectId: string,
|
||||
source: EnvRecordsSource,
|
||||
target?: ProjectEnvTarget
|
||||
): Promise<{ envs: ProjectEnvVariable[] }> {
|
||||
const { envs } = await getEnvRecords(output, client, projectId, {
|
||||
const { envs } = await getEnvRecords(output, client, projectId, source, {
|
||||
target: target || ProjectEnvTarget.Development,
|
||||
decrypt: true,
|
||||
});
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
getLinkedProject,
|
||||
linkFolderToProject,
|
||||
getVercelDirectory,
|
||||
VERCEL_DIR_README,
|
||||
VERCEL_DIR_PROJECT,
|
||||
} from '../projects/link';
|
||||
import createProject from '../projects/create-project';
|
||||
import updateProject from '../projects/update-project';
|
||||
@@ -49,7 +51,7 @@ export default async function setupAndLink(
|
||||
const isFile = !isDirectory(path);
|
||||
if (isFile) {
|
||||
output.error(`Expected directory but found file: ${path}`);
|
||||
return { status: 'error', exitCode: 1 };
|
||||
return { status: 'error', exitCode: 1, reason: 'PATH_IS_FILE' };
|
||||
}
|
||||
const link = await getLinkedProject(client, path);
|
||||
const isTTY = process.stdout.isTTY;
|
||||
@@ -65,7 +67,12 @@ export default async function setupAndLink(
|
||||
|
||||
if (forceDelete) {
|
||||
const vercelDir = getVercelDirectory(path);
|
||||
remove(vercelDir);
|
||||
remove(join(vercelDir, VERCEL_DIR_README));
|
||||
remove(join(vercelDir, VERCEL_DIR_PROJECT));
|
||||
}
|
||||
|
||||
if (!isTTY && !autoConfirm) {
|
||||
return { status: 'error', exitCode: 1, reason: 'HEADLESS' };
|
||||
}
|
||||
|
||||
const shouldStartSetup =
|
||||
@@ -87,9 +94,14 @@ export default async function setupAndLink(
|
||||
autoConfirm
|
||||
);
|
||||
} catch (err) {
|
||||
if (err.code === 'NOT_AUTHORIZED' || err.code === 'TEAM_DELETED') {
|
||||
if (err.code === 'NOT_AUTHORIZED') {
|
||||
output.prettyError(err);
|
||||
return { status: 'error', exitCode: 1 };
|
||||
return { status: 'error', exitCode: 1, reason: 'NOT_AUTHORIZED' };
|
||||
}
|
||||
|
||||
if (err.code === 'TEAM_DELETED') {
|
||||
output.prettyError(err);
|
||||
return { status: 'error', exitCode: 1, reason: 'TEAM_DELETED' };
|
||||
}
|
||||
|
||||
throw err;
|
||||
@@ -135,7 +147,7 @@ export default async function setupAndLink(
|
||||
rootDirectory &&
|
||||
!(await validateRootDirectory(output, path, sourcePath, ''))
|
||||
) {
|
||||
return { status: 'error', exitCode: 1 };
|
||||
return { status: 'error', exitCode: 1, reason: 'INVALID_ROOT_DIRECTORY' };
|
||||
}
|
||||
|
||||
config.currentTeam = org.type === 'team' ? org.id : undefined;
|
||||
@@ -191,7 +203,11 @@ export default async function setupAndLink(
|
||||
if (debug) {
|
||||
console.log(deployment);
|
||||
}
|
||||
return { status: 'error', exitCode: 1 };
|
||||
return {
|
||||
status: 'error',
|
||||
exitCode: 1,
|
||||
reason: 'MISSING_PROJECT_SETTINGS',
|
||||
};
|
||||
}
|
||||
|
||||
const { projectSettings, framework } = deployment;
|
||||
|
||||
@@ -2,6 +2,10 @@ import { join } from 'path';
|
||||
import { fileNameSymbol } from '@vercel/client';
|
||||
import { client } from '../mocks/client';
|
||||
import deploy from '../../src/commands/deploy';
|
||||
import { setupFixture } from '../helpers/setup-fixture';
|
||||
import { defaultProject, useProject } from '../mocks/project';
|
||||
import { useTeams } from '../mocks/team';
|
||||
import { useUser } from '../mocks/user';
|
||||
|
||||
describe('deploy', () => {
|
||||
it('should reject deploying a single file', async () => {
|
||||
@@ -40,6 +44,50 @@ describe('deploy', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject deploying a directory that was built with a different target environment when `--prebuilt --prod` is used on "preview" output', async () => {
|
||||
const cwd = setupFixture('build-output-api-preview');
|
||||
|
||||
useUser();
|
||||
useTeams('team_dummy');
|
||||
useProject({
|
||||
...defaultProject,
|
||||
id: 'build-output-api-preview',
|
||||
name: 'build-output-api-preview',
|
||||
});
|
||||
|
||||
client.setArgv('deploy', cwd, '--prebuilt', '--prod');
|
||||
const exitCode = await deploy(client);
|
||||
expect(exitCode).toEqual(1);
|
||||
expect(client.outputBuffer).toEqual(
|
||||
'Error! The "--prebuilt" option was used with the target environment "production",' +
|
||||
' but the prebuilt output found in ".vercel/output" was built with target environment "preview".' +
|
||||
' Please run `vercel --prebuilt`.\n' +
|
||||
'Learn More: https://vercel.link/prebuilt-environment-mismatch\n'
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject deploying a directory that was built with a different target environment when `--prebuilt` is used on "production" output', async () => {
|
||||
const cwd = setupFixture('build-output-api-production');
|
||||
|
||||
useUser();
|
||||
useTeams('team_dummy');
|
||||
useProject({
|
||||
...defaultProject,
|
||||
id: 'build-output-api-preview',
|
||||
name: 'build-output-api-preview',
|
||||
});
|
||||
|
||||
client.setArgv('deploy', cwd, '--prebuilt');
|
||||
const exitCode = await deploy(client);
|
||||
expect(exitCode).toEqual(1);
|
||||
expect(client.outputBuffer).toEqual(
|
||||
'Error! The "--prebuilt" option was used with the target environment "preview",' +
|
||||
' but the prebuilt output found in ".vercel/output" was built with target environment "production".' +
|
||||
' Please run `vercel --prebuilt --prod`.\n' +
|
||||
'Learn More: https://vercel.link/prebuilt-environment-mismatch\n'
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject deploying "version: 1"', async () => {
|
||||
client.setArgv('deploy');
|
||||
client.localConfig = {
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('pull', () => {
|
||||
id: 'vercel-pull-next',
|
||||
name: 'vercel-pull-next',
|
||||
});
|
||||
client.setArgv('pull', '--yes', cwd);
|
||||
client.setArgv('pull', cwd);
|
||||
const exitCode = await pull(client);
|
||||
expect(exitCode, client.outputBuffer).toEqual(0);
|
||||
|
||||
@@ -28,6 +28,40 @@ describe('pull', () => {
|
||||
expect(devFileHasDevEnv).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should fail with message to pull without a link and without --env', async () => {
|
||||
try {
|
||||
process.stdout.isTTY = undefined;
|
||||
|
||||
const cwd = setupFixture('vercel-pull-unlinked');
|
||||
useUser();
|
||||
useTeams('team_dummy');
|
||||
|
||||
client.setArgv('pull', cwd);
|
||||
const exitCode = await pull(client);
|
||||
expect(exitCode, client.outputBuffer).toEqual(1);
|
||||
|
||||
expect(client.outputBuffer).toMatch(
|
||||
/Command `vercel pull` requires confirmation. Use option "--yes" to confirm./gm
|
||||
);
|
||||
} finally {
|
||||
process.stdout.isTTY = true;
|
||||
}
|
||||
});
|
||||
|
||||
it('should fail without message to pull without a link and with --env', async () => {
|
||||
const cwd = setupFixture('vercel-pull-next');
|
||||
useUser();
|
||||
useTeams('team_dummy');
|
||||
|
||||
client.setArgv('pull', cwd, '--yes');
|
||||
const exitCode = await pull(client);
|
||||
expect(exitCode, client.outputBuffer).toEqual(1);
|
||||
|
||||
expect(client.outputBuffer).not.toMatch(
|
||||
/Command `vercel pull` requires confirmation. Use option "--yes" to confirm./gm
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle pulling with env vars (headless mode)', async () => {
|
||||
try {
|
||||
process.env.VERCEL_PROJECT_ID = 'vercel-pull-next';
|
||||
@@ -73,7 +107,7 @@ describe('pull', () => {
|
||||
id: 'vercel-pull-next',
|
||||
name: 'vercel-pull-next',
|
||||
});
|
||||
client.setArgv('pull', '--yes', '--environment=preview', cwd);
|
||||
client.setArgv('pull', '--environment=preview', cwd);
|
||||
const exitCode = await pull(client);
|
||||
expect(exitCode).toEqual(0);
|
||||
|
||||
@@ -95,7 +129,7 @@ describe('pull', () => {
|
||||
id: 'vercel-pull-next',
|
||||
name: 'vercel-pull-next',
|
||||
});
|
||||
client.setArgv('pull', '--yes', '--environment=production', cwd);
|
||||
client.setArgv('pull', '--environment=production', cwd);
|
||||
const exitCode = await pull(client);
|
||||
expect(exitCode).toEqual(0);
|
||||
|
||||
|
||||
3
packages/cli/test/fixtures/unit/build-output-api-preview/.vercel/output/builds.json
vendored
Normal file
3
packages/cli/test/fixtures/unit/build-output-api-preview/.vercel/output/builds.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"target": "preview"
|
||||
}
|
||||
3
packages/cli/test/fixtures/unit/build-output-api-production/.vercel/output/builds.json
vendored
Normal file
3
packages/cli/test/fixtures/unit/build-output-api-production/.vercel/output/builds.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"target": "production"
|
||||
}
|
||||
2
packages/cli/test/fixtures/unit/vercel-pull-unlinked/.gitignore
vendored
Normal file
2
packages/cli/test/fixtures/unit/vercel-pull-unlinked/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.next
|
||||
yarn.lock
|
||||
12
packages/cli/test/fixtures/unit/vercel-pull-unlinked/package.json
vendored
Normal file
12
packages/cli/test/fixtures/unit/vercel-pull-unlinked/package.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "next build",
|
||||
"dev": "next",
|
||||
"now-build": "next build"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "^8.0.0",
|
||||
"react": "^16.7.0",
|
||||
"react-dom": "^16.7.0"
|
||||
}
|
||||
}
|
||||
11
packages/cli/test/fixtures/unit/vercel-pull-unlinked/pages/index.js
vendored
Normal file
11
packages/cli/test/fixtures/unit/vercel-pull-unlinked/pages/index.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { withRouter } from 'next/router';
|
||||
|
||||
function Index({ router }) {
|
||||
const data = {
|
||||
pathname: router.pathname,
|
||||
query: router.query,
|
||||
};
|
||||
return <div>{JSON.stringify(data)}</div>;
|
||||
}
|
||||
|
||||
export default withRouter(Index);
|
||||
1
packages/cli/test/fixtures/unit/vercel-pull-unlinked/static/robots.txt
vendored
Normal file
1
packages/cli/test/fixtures/unit/vercel-pull-unlinked/static/robots.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
User-Agent: *
|
||||
10
packages/cli/test/fixtures/unit/vercel-pull-unlinked/vercel.json
vendored
Normal file
10
packages/cli/test/fixtures/unit/vercel-pull-unlinked/vercel.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 2,
|
||||
"name": "vercel-pull-next",
|
||||
"routes": [
|
||||
{
|
||||
"src": "/(.*)",
|
||||
"dest": "/index?route-param=b"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -179,6 +179,19 @@ module.exports = async function prepare(session, binaryPath) {
|
||||
'list/README.md':
|
||||
'readme contents for deploy-default-with-conflicting-sub-directory',
|
||||
},
|
||||
'deploy-default-with-prebuilt-preview': {
|
||||
'vercel.json': JSON.stringify({ version: 2 }),
|
||||
'.vercel/output/builds.json': JSON.stringify({ target: 'preview' }),
|
||||
'.vercel/output/config.json': JSON.stringify({ version: 3 }),
|
||||
'.vercel/output/static/README.md':
|
||||
'readme contents for deploy-default-with-prebuilt-preview',
|
||||
},
|
||||
'build-output-api-raw': {
|
||||
'vercel.json': JSON.stringify({ version: 2 }),
|
||||
'.vercel/output/config.json': JSON.stringify({ version: 3 }),
|
||||
'.vercel/output/static/README.md':
|
||||
'readme contents for build-output-api-raw',
|
||||
},
|
||||
'local-config-v2': {
|
||||
[`main-${session}.html`]: '<h1>hello main</h1>',
|
||||
[`test-${session}.html`]: '<h1>hello test</h1>',
|
||||
|
||||
197
packages/cli/test/integration.js
vendored
197
packages/cli/test/integration.js
vendored
@@ -7,10 +7,9 @@ import { Readable } from 'stream';
|
||||
import { homedir } from 'os';
|
||||
import _execa from 'execa';
|
||||
import XDGAppPaths from 'xdg-app-paths';
|
||||
import nodeFetch from 'node-fetch';
|
||||
import fetch from 'node-fetch';
|
||||
import tmp from 'tmp-promise';
|
||||
import retry from 'async-retry';
|
||||
import createFetchRetry from '@vercel/fetch-retry';
|
||||
import fs, {
|
||||
writeFile,
|
||||
readFile,
|
||||
@@ -25,8 +24,6 @@ import pkg from '../package';
|
||||
import prepareFixtures from './helpers/prepare';
|
||||
import { fetchTokenWithRetry } from '../../../test/lib/deployment/now-deploy';
|
||||
|
||||
const fetch = createFetchRetry(nodeFetch);
|
||||
|
||||
// log command when running `execa`
|
||||
function execa(file, args, options) {
|
||||
console.log(`$ vercel ${args.join(' ')}`);
|
||||
@@ -497,6 +494,56 @@ test('default command should work with --cwd option', async t => {
|
||||
);
|
||||
});
|
||||
|
||||
test('should allow deploying a directory that was built with a target environment of "preview" and `--prebuilt` is used without specifying a target', async t => {
|
||||
const projectDir = fixture('deploy-default-with-prebuilt-preview');
|
||||
|
||||
await vcLink(t, projectDir);
|
||||
|
||||
const { exitCode, stderr, stdout } = await execa(
|
||||
binaryPath,
|
||||
[
|
||||
// omit the default "deploy" command
|
||||
'--prebuilt',
|
||||
...defaultArgs,
|
||||
],
|
||||
{
|
||||
cwd: projectDir,
|
||||
}
|
||||
);
|
||||
|
||||
t.is(exitCode, 0, formatOutput({ stderr, stdout }));
|
||||
|
||||
const url = stdout;
|
||||
const deploymentResult = await fetch(`${url}/README.md`);
|
||||
const body = await deploymentResult.text();
|
||||
t.deepEqual(body, 'readme contents for deploy-default-with-prebuilt-preview');
|
||||
});
|
||||
|
||||
test('should allow deploying a directory that was prebuilt, but has no builds.json', async t => {
|
||||
const projectDir = fixture('build-output-api-raw');
|
||||
|
||||
await vcLink(t, projectDir);
|
||||
|
||||
const { exitCode, stderr, stdout } = await execa(
|
||||
binaryPath,
|
||||
[
|
||||
// omit the default "deploy" command
|
||||
'--prebuilt',
|
||||
...defaultArgs,
|
||||
],
|
||||
{
|
||||
cwd: projectDir,
|
||||
}
|
||||
);
|
||||
|
||||
t.is(exitCode, 0, formatOutput({ stderr, stdout }));
|
||||
|
||||
const url = stdout;
|
||||
const deploymentResult = await fetch(`${url}/README.md`);
|
||||
const body = await deploymentResult.text();
|
||||
t.deepEqual(body, 'readme contents for build-output-api-raw');
|
||||
});
|
||||
|
||||
test('deploy using only now.json with `redirects` defined', async t => {
|
||||
const target = fixture('redirects-v2');
|
||||
|
||||
@@ -797,15 +844,10 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
|
||||
|
||||
const contents = fs.readFileSync(path.join(target, '.env'), 'utf8');
|
||||
t.regex(contents, /^# Created by Vercel CLI\n/);
|
||||
|
||||
const lines = new Set(contents.split('\n'));
|
||||
t.true(lines.has('MY_NEW_ENV_VAR="my plaintext value"'), 'MY_NEW_ENV_VAR');
|
||||
t.true(lines.has('MY_STDIN_VAR="{"expect":"quotes"}"'), 'MY_STDIN_VAR');
|
||||
t.true(
|
||||
lines.has('MY_DECRYPTABLE_SECRET_ENV="decryptable value"'),
|
||||
'MY_DECRYPTABLE_SECRET_ENV'
|
||||
);
|
||||
t.false(lines.has('MY_PREVIEW'), 'MY_PREVIEW');
|
||||
t.regex(contents, /MY_NEW_ENV_VAR="my plaintext value"/);
|
||||
t.regex(contents, /MY_STDIN_VAR="{"expect":"quotes"}"/);
|
||||
t.regex(contents, /MY_DECRYPTABLE_SECRET_ENV="decryptable value"/);
|
||||
t.notRegex(contents, /MY_PREVIEW/);
|
||||
}
|
||||
|
||||
async function vcEnvPullOverwrite() {
|
||||
@@ -1090,29 +1132,48 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
|
||||
t.is(exitCode, 0, formatOutput({ stderr, stdout }));
|
||||
}
|
||||
|
||||
await vcLink();
|
||||
await vcEnvLsIsEmpty();
|
||||
await vcEnvAddWithPrompts();
|
||||
await vcEnvAddFromStdin();
|
||||
await vcEnvAddFromStdinPreview();
|
||||
await vcEnvAddFromStdinPreviewWithBranch();
|
||||
await vcEnvLsIncludesVar();
|
||||
await createEnvWithDecryptableSecret();
|
||||
await vcEnvPull();
|
||||
await vcEnvPullOverwrite();
|
||||
await vcEnvPullConfirm();
|
||||
await vcDeployWithVar();
|
||||
await vcDevWithEnv();
|
||||
fs.unlinkSync(path.join(target, '.env'));
|
||||
await vcDevAndFetchCloudVars();
|
||||
await enableAutoExposeSystemEnvs();
|
||||
await vcEnvPullFetchSystemVars();
|
||||
fs.unlinkSync(path.join(target, '.env'));
|
||||
await vcDevAndFetchSystemVars();
|
||||
await vcEnvRemove();
|
||||
await vcEnvRemoveWithArgs();
|
||||
await vcEnvRemoveWithNameOnly();
|
||||
await vcEnvLsIsEmpty();
|
||||
function vcEnvRemoveByName(name) {
|
||||
return execa(binaryPath, ['env', 'rm', name, '-y', ...defaultArgs], {
|
||||
reject: false,
|
||||
cwd: target,
|
||||
});
|
||||
}
|
||||
|
||||
async function vcEnvRemoveAll() {
|
||||
await vcEnvRemoveByName('MY_PREVIEW');
|
||||
await vcEnvRemoveByName('MY_STDIN_VAR');
|
||||
await vcEnvRemoveByName('MY_DECRYPTABLE_SECRET_ENV');
|
||||
await vcEnvRemoveByName('MY_NEW_ENV_VAR');
|
||||
}
|
||||
|
||||
try {
|
||||
await vcEnvRemoveAll();
|
||||
await vcLink();
|
||||
await vcEnvLsIsEmpty();
|
||||
await vcEnvAddWithPrompts();
|
||||
await vcEnvAddFromStdin();
|
||||
await vcEnvAddFromStdinPreview();
|
||||
await vcEnvAddFromStdinPreviewWithBranch();
|
||||
await vcEnvLsIncludesVar();
|
||||
await createEnvWithDecryptableSecret();
|
||||
await vcEnvPull();
|
||||
await vcEnvPullOverwrite();
|
||||
await vcEnvPullConfirm();
|
||||
await vcDeployWithVar();
|
||||
await vcDevWithEnv();
|
||||
fs.unlinkSync(path.join(target, '.env'));
|
||||
await vcDevAndFetchCloudVars();
|
||||
await enableAutoExposeSystemEnvs();
|
||||
await vcEnvPullFetchSystemVars();
|
||||
fs.unlinkSync(path.join(target, '.env'));
|
||||
await vcDevAndFetchSystemVars();
|
||||
await vcEnvRemove();
|
||||
await vcEnvRemoveWithArgs();
|
||||
await vcEnvRemoveWithNameOnly();
|
||||
await vcEnvLsIsEmpty();
|
||||
} finally {
|
||||
await vcEnvRemoveAll();
|
||||
}
|
||||
});
|
||||
|
||||
test('[vc projects] should create a project successfully', async t => {
|
||||
@@ -1450,6 +1511,9 @@ test('try to purchase a domain', async t => {
|
||||
{
|
||||
reject: false,
|
||||
input: stream,
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -2361,6 +2425,9 @@ test('[vercel dev] fails when development commad calls vercel dev recursively',
|
||||
const dev = execa(binaryPath, ['dev', ...defaultArgs], {
|
||||
cwd: dir,
|
||||
reject: false,
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
});
|
||||
|
||||
await setupProject(dev, projectName, {
|
||||
@@ -2766,6 +2833,9 @@ test('change user', async t => {
|
||||
|
||||
await execute(['login', email, '--api', loginApiUrl, '--debug'], {
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
});
|
||||
|
||||
const auth = await fs.readJSON(getConfigAuthPath());
|
||||
@@ -2895,7 +2965,11 @@ test('should prefill "project name" prompt with folder name', async t => {
|
||||
const directory = path.join(src, '../', projectName);
|
||||
await copy(src, directory);
|
||||
|
||||
const now = execa(binaryPath, [directory, ...defaultArgs]);
|
||||
const now = execa(binaryPath, [directory, ...defaultArgs], {
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
});
|
||||
|
||||
await waitForPrompt(now, chunk => /Set up and deploy [^?]+\?/.test(chunk));
|
||||
now.stdin.write('yes\n');
|
||||
@@ -2938,12 +3012,15 @@ test('should prefill "project name" prompt with --name', async t => {
|
||||
// remove previously linked project if it exists
|
||||
await remove(path.join(directory, '.vercel'));
|
||||
|
||||
const now = execa(binaryPath, [
|
||||
directory,
|
||||
'--name',
|
||||
projectName,
|
||||
...defaultArgs,
|
||||
]);
|
||||
const now = execa(
|
||||
binaryPath,
|
||||
[directory, '--name', projectName, ...defaultArgs],
|
||||
{
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
let isDeprecated = false;
|
||||
|
||||
@@ -3002,7 +3079,11 @@ test('should prefill "project name" prompt with now.json `name`', async t => {
|
||||
})
|
||||
);
|
||||
|
||||
const now = execa(binaryPath, [directory, ...defaultArgs]);
|
||||
const now = execa(binaryPath, [directory, ...defaultArgs], {
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
});
|
||||
|
||||
let isDeprecated = false;
|
||||
|
||||
@@ -3423,7 +3504,12 @@ test('[vc link] should show prompts to set up project', async t => {
|
||||
// remove previously linked project if it exists
|
||||
await remove(path.join(dir, '.vercel'));
|
||||
|
||||
const vc = execa(binaryPath, ['link', ...defaultArgs], { cwd: dir });
|
||||
const vc = execa(binaryPath, ['link', ...defaultArgs], {
|
||||
cwd: dir,
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
});
|
||||
|
||||
await setupProject(vc, projectName, {
|
||||
buildCommand: `mkdir -p o && echo '<h1>custom hello</h1>' > o/index.html`,
|
||||
@@ -3496,7 +3582,13 @@ test('[vc link] should not duplicate paths in .gitignore', async t => {
|
||||
const { exitCode, stderr, stdout } = await execa(
|
||||
binaryPath,
|
||||
['link', '--confirm', ...defaultArgs],
|
||||
{ cwd: dir, reject: false }
|
||||
{
|
||||
cwd: dir,
|
||||
reject: false,
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// Ensure the exit code is right
|
||||
@@ -3522,6 +3614,9 @@ test('[vc dev] should show prompts to set up project', async t => {
|
||||
|
||||
const dev = execa(binaryPath, ['dev', '--listen', port, ...defaultArgs], {
|
||||
cwd: dir,
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
});
|
||||
|
||||
await setupProject(dev, projectName, {
|
||||
@@ -3566,7 +3661,12 @@ test('[vc link] should show project prompts but not framework when `builds` defi
|
||||
// remove previously linked project if it exists
|
||||
await remove(path.join(dir, '.vercel'));
|
||||
|
||||
const vc = execa(binaryPath, ['link', ...defaultArgs], { cwd: dir });
|
||||
const vc = execa(binaryPath, ['link', ...defaultArgs], {
|
||||
cwd: dir,
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
});
|
||||
|
||||
await waitForPrompt(vc, chunk => /Set up [^?]+\?/.test(chunk));
|
||||
vc.stdin.write('yes\n');
|
||||
@@ -3625,6 +3725,9 @@ test('[vc dev] should send the platform proxy request headers to frontend dev se
|
||||
|
||||
const dev = execa(binaryPath, ['dev', '--listen', port, ...defaultArgs], {
|
||||
cwd: dir,
|
||||
env: {
|
||||
FORCE_TTY: '1',
|
||||
},
|
||||
});
|
||||
|
||||
await setupProject(dev, projectName, {
|
||||
|
||||
55
packages/cli/test/util/deploy/parse-target.test.ts
Normal file
55
packages/cli/test/util/deploy/parse-target.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import parseTarget from '../../../src/util/deploy/parse-target';
|
||||
import { Output } from '../../../src/util/output';
|
||||
|
||||
describe('parseTarget', () => {
|
||||
let output: Output;
|
||||
|
||||
beforeEach(() => {
|
||||
output = new Output();
|
||||
output.warn = jest.fn();
|
||||
output.error = jest.fn();
|
||||
});
|
||||
|
||||
it('defaults to `undefined`', () => {
|
||||
let result = parseTarget(output);
|
||||
expect(result).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('fails when given invalid target', () => {
|
||||
const result = parseTarget(output, 'not-a-real-environment');
|
||||
expect(result).toEqual(1);
|
||||
|
||||
const errorMock = (output.error as jest.Mock<any, any>).mock;
|
||||
expect(errorMock.calls[0][0]).toMatch(
|
||||
/not-a-real-environment.+is not valid/g
|
||||
);
|
||||
});
|
||||
|
||||
it('parses "production" target', () => {
|
||||
let result = parseTarget(output, 'production');
|
||||
expect(result).toEqual('production');
|
||||
expect(output.warn).toHaveBeenCalledWith(
|
||||
'We recommend using the much shorter `--prod` option instead of `--target production` (deprecated)'
|
||||
);
|
||||
});
|
||||
|
||||
it('parses "staging" target', () => {
|
||||
let result = parseTarget(output, 'staging');
|
||||
expect(result).toEqual('staging');
|
||||
});
|
||||
|
||||
it('prefers target over production argument', () => {
|
||||
let result = parseTarget(output, 'staging', true);
|
||||
expect(result).toEqual('staging');
|
||||
});
|
||||
|
||||
it('parses production argument when `true`', () => {
|
||||
let result = parseTarget(output, undefined, true);
|
||||
expect(result).toEqual('production');
|
||||
});
|
||||
|
||||
it('parses production argument when `false`', () => {
|
||||
let result = parseTarget(output, undefined, false);
|
||||
expect(result).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
@@ -126,6 +126,12 @@ describe('DevServer', () => {
|
||||
it(
|
||||
'should maintain query when builder defines routes',
|
||||
testFixture('now-dev-next', async server => {
|
||||
if (process.platform === 'darwin') {
|
||||
// this test very often fails on Mac OS only due to timeouts
|
||||
console.log('Skipping test on macOS');
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await fetch(`${server.address}/something?url-param=a`);
|
||||
validateResponseHeaders(res);
|
||||
|
||||
@@ -171,6 +177,12 @@ describe('DevServer', () => {
|
||||
it(
|
||||
'should support default builds and routes',
|
||||
testFixture('now-dev-default-builds-and-routes', async server => {
|
||||
if (process.platform === 'darwin') {
|
||||
// this test very often fails on Mac OS only due to timeouts
|
||||
console.log('Skipping test on macOS');
|
||||
return;
|
||||
}
|
||||
|
||||
let podId: string;
|
||||
|
||||
let res = await fetch(`${server.address}/`);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/client",
|
||||
"version": "11.0.0",
|
||||
"version": "11.0.2-canary.0",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"homepage": "https://vercel.com",
|
||||
@@ -41,7 +41,7 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.16.0",
|
||||
"@vercel/build-utils": "3.0.1-canary.1",
|
||||
"@zeit/fetch": "5.2.0",
|
||||
"async-retry": "1.2.3",
|
||||
"async-sema": "3.0.0",
|
||||
|
||||
15
packages/frameworks/logos/astro-dark.svg
Normal file
15
packages/frameworks/logos/astro-dark.svg
Normal file
@@ -0,0 +1,15 @@
|
||||
<svg width="1281" height="1280" viewBox="0 0 1281 1280" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M815.931 94.6439C825.65 106.709 830.606 122.99 840.519 155.553L1057.06 866.901C976.999 825.368 889.964 795.413 798.174 779.252L657.182 302.798C654.875 295.002 647.715 289.654 639.585 289.654C631.434 289.654 624.26 295.03 621.972 302.853L482.688 779.011C390.471 795.1 303.038 825.109 222.634 866.793L440.24 155.388L440.24 155.388C450.183 122.882 455.154 106.629 464.874 94.5853C473.455 83.9531 484.616 75.6958 497.293 70.6002C511.652 64.8284 528.649 64.8284 562.642 64.8284H718.067C752.104 64.8284 769.123 64.8284 783.496 70.6123C796.184 75.7184 807.352 83.9923 815.931 94.6439Z" fill="url(#paint0_linear_709_106)"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M841.843 900.754C806.146 931.279 734.895 952.097 652.822 952.097C552.089 952.097 467.659 920.737 445.256 878.561C437.247 902.732 435.45 930.396 435.45 948.068C435.45 948.068 430.173 1034.84 490.528 1095.2C490.528 1063.86 515.934 1038.46 547.273 1038.46C600.989 1038.46 600.929 1085.32 600.88 1123.34C600.878 1124.48 600.877 1125.61 600.877 1126.73C600.877 1184.44 636.147 1233.91 686.308 1254.77C678.816 1239.36 674.613 1222.05 674.613 1203.77C674.613 1148.73 706.926 1128.23 744.48 1104.41L744.481 1104.41C774.361 1085.46 807.56 1064.41 830.44 1022.17C842.379 1000.13 849.158 974.893 849.158 948.068C849.158 931.573 846.594 915.676 841.843 900.754Z" fill="#FF5D01"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M841.843 900.754C806.146 931.279 734.895 952.097 652.822 952.097C552.089 952.097 467.659 920.737 445.256 878.561C437.247 902.732 435.45 930.396 435.45 948.068C435.45 948.068 430.173 1034.84 490.528 1095.2C490.528 1063.86 515.934 1038.46 547.273 1038.46C600.989 1038.46 600.929 1085.32 600.88 1123.34C600.878 1124.48 600.877 1125.61 600.877 1126.73C600.877 1184.44 636.147 1233.91 686.308 1254.77C678.816 1239.36 674.613 1222.05 674.613 1203.77C674.613 1148.73 706.926 1128.23 744.48 1104.41L744.481 1104.41C774.361 1085.46 807.56 1064.41 830.44 1022.17C842.379 1000.13 849.158 974.893 849.158 948.068C849.158 931.573 846.594 915.676 841.843 900.754Z" fill="url(#paint1_linear_709_106)"/>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_709_106" x1="883.889" y1="27.1132" x2="639.848" y2="866.902" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="white"/>
|
||||
<stop offset="1" stop-color="#F9FAFB"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="paint1_linear_709_106" x1="1002.57" y1="652.45" x2="791.219" y2="1094.91" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#FF1639"/>
|
||||
<stop offset="1" stop-color="#FF1639" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
15
packages/frameworks/logos/astro.svg
Normal file
15
packages/frameworks/logos/astro.svg
Normal file
@@ -0,0 +1,15 @@
|
||||
<svg width="1280" height="1280" viewBox="0 0 1280 1280" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M815.039 94.6439C824.758 106.709 829.714 122.99 839.626 155.553L1056.17 866.901C976.107 825.368 889.072 795.413 797.281 779.252L656.29 302.798C653.983 295.002 646.822 289.654 638.693 289.654C630.542 289.654 623.368 295.03 621.08 302.853L481.795 779.011C389.579 795.1 302.146 825.109 221.741 866.793L439.347 155.388L439.348 155.388C449.291 122.882 454.262 106.629 463.982 94.5853C472.562 83.9531 483.723 75.6958 496.4 70.6002C510.76 64.8284 527.756 64.8284 561.749 64.8284H717.174C751.212 64.8284 768.23 64.8284 782.603 70.6123C795.292 75.7184 806.459 83.9923 815.039 94.6439Z" fill="url(#paint0_linear_709_110)"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M840.951 900.754C805.253 931.279 734.002 952.097 651.929 952.097C551.197 952.097 466.767 920.737 444.363 878.561C436.354 902.732 434.558 930.396 434.558 948.068C434.558 948.068 429.281 1034.84 489.636 1095.2C489.636 1063.86 515.042 1038.46 546.381 1038.46C600.097 1038.46 600.036 1085.32 599.987 1123.34C599.986 1124.48 599.984 1125.61 599.984 1126.73C599.984 1184.44 635.255 1233.91 685.416 1254.77C677.924 1239.36 673.721 1222.05 673.721 1203.77C673.721 1148.73 706.034 1128.23 743.588 1104.41L743.588 1104.41C773.469 1085.46 806.668 1064.41 829.548 1022.17C841.486 1000.13 848.265 974.893 848.265 948.068C848.265 931.573 845.702 915.676 840.951 900.754Z" fill="#FF5D01"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M840.951 900.754C805.253 931.279 734.002 952.097 651.929 952.097C551.197 952.097 466.767 920.737 444.363 878.561C436.354 902.732 434.558 930.396 434.558 948.068C434.558 948.068 429.281 1034.84 489.636 1095.2C489.636 1063.86 515.042 1038.46 546.381 1038.46C600.097 1038.46 600.036 1085.32 599.987 1123.34C599.986 1124.48 599.984 1125.61 599.984 1126.73C599.984 1184.44 635.255 1233.91 685.416 1254.77C677.924 1239.36 673.721 1222.05 673.721 1203.77C673.721 1148.73 706.034 1128.23 743.588 1104.41L743.588 1104.41C773.469 1085.46 806.668 1064.41 829.548 1022.17C841.486 1000.13 848.265 974.893 848.265 948.068C848.265 931.573 845.702 915.676 840.951 900.754Z" fill="url(#paint1_linear_709_110)"/>
|
||||
<defs>
|
||||
<linearGradient id="paint0_linear_709_110" x1="882.997" y1="27.1132" x2="638.955" y2="866.902" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#000014"/>
|
||||
<stop offset="1" stop-color="#150426"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="paint1_linear_709_110" x1="1001.68" y1="652.45" x2="790.326" y2="1094.91" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="#FF1639"/>
|
||||
<stop offset="1" stop-color="#FF1639" stop-opacity="0"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/frameworks",
|
||||
"version": "0.8.0",
|
||||
"version": "0.9.0",
|
||||
"main": "./dist/frameworks.js",
|
||||
"types": "./dist/frameworks.d.ts",
|
||||
"files": [
|
||||
|
||||
@@ -60,7 +60,8 @@ export const frameworks = [
|
||||
slug: 'nextjs',
|
||||
demo: 'https://nextjs-template.vercel.app',
|
||||
logo: 'https://raw.githubusercontent.com/vercel/vercel/main/packages/frameworks/logos/next.svg',
|
||||
darkModeLogo: 'https://raw.githubusercontent.com/vercel/vercel/main/packages/frameworks/logos/next-dark.svg',
|
||||
darkModeLogo:
|
||||
'https://raw.githubusercontent.com/vercel/vercel/main/packages/frameworks/logos/next-dark.svg',
|
||||
screenshot:
|
||||
'https://assets.vercel.com/image/upload/v1647366075/front/import/nextjs.png',
|
||||
tagline:
|
||||
@@ -204,9 +205,7 @@ export const frameworks = [
|
||||
detectors: {
|
||||
every: [
|
||||
{
|
||||
path: 'package.json',
|
||||
matchContent:
|
||||
'"(dev)?(d|D)ependencies":\\s*{[^}]*"remix":\\s*".+?"[^}]*}',
|
||||
path: 'remix.config.js',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -262,6 +261,73 @@ export const frameworks = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Astro',
|
||||
slug: 'astro',
|
||||
demo: 'https://astro-template.vercel.app',
|
||||
logo: 'https://raw.githubusercontent.com/vercel/vercel/main/packages/frameworks/logos/astro.svg',
|
||||
darkModeLogo:
|
||||
'https://raw.githubusercontent.com/vercel/vercel/main/packages/frameworks/logos/astro-dark.svg',
|
||||
tagline:
|
||||
'Astro is a new kind of static site builder for the modern web. Powerful developer experience meets lightweight output.',
|
||||
description: 'An Astro site, using the basics starter kit.',
|
||||
website: 'https://astro.build',
|
||||
envPrefix: 'PUBLIC_',
|
||||
detectors: {
|
||||
every: [
|
||||
{
|
||||
path: 'package.json',
|
||||
matchContent:
|
||||
'"(dev)?(d|D)ependencies":\\s*{[^}]*"astro":\\s*".+?"[^}]*}',
|
||||
},
|
||||
],
|
||||
},
|
||||
settings: {
|
||||
installCommand: {
|
||||
placeholder: '`yarn install` or `npm install`',
|
||||
},
|
||||
buildCommand: {
|
||||
value: 'astro build',
|
||||
placeholder: '`npm run build` or `astro build`',
|
||||
},
|
||||
devCommand: {
|
||||
value: 'astro dev --port $PORT',
|
||||
placeholder: 'astro dev',
|
||||
},
|
||||
outputDirectory: {
|
||||
value: 'dist',
|
||||
},
|
||||
},
|
||||
dependency: 'astro',
|
||||
getFsOutputDir: async () => 'dist',
|
||||
getOutputDirName: async () => 'dist',
|
||||
defaultRoutes: [
|
||||
{
|
||||
src: '^/dist/(.*)$',
|
||||
headers: { 'cache-control': 'public, max-age=31536000, immutable' },
|
||||
continue: true,
|
||||
},
|
||||
{
|
||||
handle: 'filesystem',
|
||||
},
|
||||
{
|
||||
src: '/(.*)',
|
||||
dest: '/index.html',
|
||||
},
|
||||
],
|
||||
defaultHeaders: [
|
||||
{
|
||||
source: '^/dist/(.*)$',
|
||||
regex: '^/dist/(.*)$',
|
||||
headers: [
|
||||
{
|
||||
key: 'cache-control',
|
||||
value: 'public, max-age=31536000, immutable',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Hexo',
|
||||
slug: 'hexo',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/go",
|
||||
"version": "1.4.0",
|
||||
"version": "1.4.2-canary.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
|
||||
@@ -24,7 +24,7 @@
|
||||
"@types/fs-extra": "^5.0.5",
|
||||
"@types/node-fetch": "^2.3.0",
|
||||
"@types/tar": "^4.0.0",
|
||||
"@vercel/build-utils": "2.16.0",
|
||||
"@vercel/build-utils": "3.0.1-canary.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"async-retry": "1.3.1",
|
||||
"execa": "^1.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/node",
|
||||
"version": "1.15.0",
|
||||
"version": "1.15.2-canary.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
||||
@@ -12,12 +12,22 @@
|
||||
"scripts": {
|
||||
"build": "node build",
|
||||
"test-integration-once": "jest --env node --verbose --runInBand --bail test/integration.test.js",
|
||||
"test-unit": "jest --env node --verbose --bail test/prepare-cache.test.js",
|
||||
"test-unit": "jest --env node --verbose --bail test/prepare-cache.test.ts",
|
||||
"prepublishOnly": "node build"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
"testEnvironment": "node",
|
||||
"globals": {
|
||||
"ts-jest": {
|
||||
"diagnostics": true,
|
||||
"isolatedModules": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "*",
|
||||
"@vercel/node-bridge": "2.2.1",
|
||||
@@ -32,8 +42,9 @@
|
||||
"@types/content-type": "1.1.3",
|
||||
"@types/cookie": "0.3.3",
|
||||
"@types/etag": "1.8.0",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/test-listen": "1.1.0",
|
||||
"@vercel/build-utils": "2.16.0",
|
||||
"@vercel/build-utils": "3.0.1-canary.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/nft": "0.18.1",
|
||||
"content-type": "1.0.4",
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
const path = require('path');
|
||||
const { prepareCache } = require('../dist');
|
||||
import path from 'path';
|
||||
import assert from 'assert';
|
||||
import { prepareCache } from '../src';
|
||||
|
||||
describe('prepareCache()', () => {
|
||||
test('should cache **/node_modules/**', async () => {
|
||||
test('should cache `**/node_modules/**`', async () => {
|
||||
const files = await prepareCache({
|
||||
files: {},
|
||||
entrypoint: '.',
|
||||
config: {},
|
||||
workPath: path.resolve(__dirname, './cache-fixtures/'),
|
||||
repoRootPath: path.resolve(__dirname, './cache-fixtures/'),
|
||||
});
|
||||
|
||||
@@ -14,14 +19,17 @@ describe('prepareCache()', () => {
|
||||
|
||||
test('should ignore root modules', async () => {
|
||||
const files = await prepareCache({
|
||||
files: {},
|
||||
entrypoint: '.',
|
||||
config: {},
|
||||
workPath: path.resolve(__dirname, './cache-fixtures/foo/'),
|
||||
});
|
||||
|
||||
expect(files['node_modules/file']).toBeDefined();
|
||||
const file = files['node_modules/file'];
|
||||
expect(file).toBeDefined();
|
||||
assert(file.type === 'FileFsRef');
|
||||
expect(
|
||||
files['node_modules/file'].fsPath.includes(
|
||||
'cache-fixtures/foo/node_modules/file'
|
||||
)
|
||||
file.fsPath.includes('cache-fixtures/foo/node_modules/file')
|
||||
).toBeTruthy();
|
||||
expect(files['index.js']).toBeUndefined();
|
||||
});
|
||||
4
packages/node/test/tsconfig.json
vendored
Normal file
4
packages/node/test/tsconfig.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"include": ["*.test.ts"]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/python",
|
||||
"version": "2.3.0",
|
||||
"version": "2.3.2-canary.0",
|
||||
"main": "./dist/index.js",
|
||||
"license": "MIT",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
|
||||
@@ -22,7 +22,7 @@
|
||||
"devDependencies": {
|
||||
"@types/execa": "^0.9.0",
|
||||
"@types/jest": "27.4.1",
|
||||
"@vercel/build-utils": "2.16.0",
|
||||
"@vercel/build-utils": "3.0.1-canary.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"execa": "^1.0.0",
|
||||
"typescript": "4.3.4"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/redwood",
|
||||
"version": "0.8.0",
|
||||
"version": "0.8.2-canary.0",
|
||||
"main": "./dist/index.js",
|
||||
"license": "MIT",
|
||||
"homepage": "https://vercel.com/docs",
|
||||
@@ -27,6 +27,6 @@
|
||||
"@types/aws-lambda": "8.10.19",
|
||||
"@types/node": "*",
|
||||
"@types/semver": "6.0.0",
|
||||
"@vercel/build-utils": "2.16.0"
|
||||
"@vercel/build-utils": "3.0.1-canary.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@vercel/ruby",
|
||||
"author": "Nathan Cahill <nathan@nathancahill.com>",
|
||||
"version": "1.3.3",
|
||||
"version": "1.3.5-canary.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/ruby",
|
||||
@@ -22,7 +22,7 @@
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "8.0.0",
|
||||
"@types/semver": "6.0.0",
|
||||
"@vercel/build-utils": "2.16.0",
|
||||
"@vercel/build-utils": "3.0.1-canary.1",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"execa": "2.0.4",
|
||||
"fs-extra": "^7.0.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/static-build",
|
||||
"version": "0.24.0",
|
||||
"version": "0.24.2-canary.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/build-step",
|
||||
@@ -31,14 +31,16 @@
|
||||
"devDependencies": {
|
||||
"@types/aws-lambda": "8.10.64",
|
||||
"@types/cross-spawn": "6.0.0",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/ms": "0.7.31",
|
||||
"@types/node-fetch": "2.5.4",
|
||||
"@types/promise-timeout": "1.3.0",
|
||||
"@vercel/build-utils": "2.16.0",
|
||||
"@vercel/frameworks": "0.8.0",
|
||||
"@vercel/build-utils": "3.0.1-canary.1",
|
||||
"@vercel/frameworks": "0.9.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/routing-utils": "1.13.2",
|
||||
"fs-extra": "10.0.0",
|
||||
"get-port": "5.0.0",
|
||||
"is-port-reachable": "2.0.1",
|
||||
"ms": "2.1.2",
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
} from '@vercel/build-utils';
|
||||
import type { Route, Source } from '@vercel/routing-utils';
|
||||
import * as BuildOutputV1 from './utils/build-output-v1';
|
||||
import * as BuildOutputV2 from './utils/build-output-v2';
|
||||
import * as BuildOutputV3 from './utils/build-output-v3';
|
||||
import * as GatsbyUtils from './utils/gatsby';
|
||||
import * as NuxtUtils from './utils/nuxt';
|
||||
@@ -261,6 +262,37 @@ async function fetchBinary(url: string, framework: string, version: string) {
|
||||
});
|
||||
}
|
||||
|
||||
async function getUpdatedDistPath(
|
||||
framework: Framework | undefined,
|
||||
outputDirPrefix: string,
|
||||
entrypointDir: string,
|
||||
distPath: string,
|
||||
config: Config
|
||||
): Promise<string | undefined> {
|
||||
if (framework) {
|
||||
const outputDirName = config.outputDirectory
|
||||
? config.outputDirectory
|
||||
: await framework.getOutputDirName(outputDirPrefix);
|
||||
|
||||
return path.join(outputDirPrefix, outputDirName);
|
||||
}
|
||||
|
||||
if (!config || !config.distDir) {
|
||||
// Select either `dist` or `public` as directory
|
||||
const publicPath = path.join(entrypointDir, 'public');
|
||||
|
||||
if (
|
||||
!existsSync(distPath) &&
|
||||
existsSync(publicPath) &&
|
||||
statSync(publicPath).isDirectory()
|
||||
) {
|
||||
return publicPath;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export const build: BuildV2 = async ({
|
||||
files,
|
||||
entrypoint,
|
||||
@@ -622,48 +654,36 @@ export const build: BuildV2 = async ({
|
||||
}
|
||||
|
||||
const outputDirPrefix = path.join(workPath, path.dirname(entrypoint));
|
||||
distPath =
|
||||
(await getUpdatedDistPath(
|
||||
framework,
|
||||
outputDirPrefix,
|
||||
entrypointDir,
|
||||
distPath,
|
||||
config
|
||||
)) || distPath;
|
||||
|
||||
// If the Build Command or Framework output files according to the
|
||||
// Build Output v3 API, then stop processing here in `static-build`
|
||||
// since the output is already in its final form.
|
||||
const buildOutputPath = await BuildOutputV3.getBuildOutputDirectory(
|
||||
const buildOutputPathV3 = await BuildOutputV3.getBuildOutputDirectory(
|
||||
outputDirPrefix
|
||||
);
|
||||
|
||||
if (buildOutputPath) {
|
||||
if (buildOutputPathV3) {
|
||||
// Ensure that `vercel build` is being used for this Deployment
|
||||
if (!meta.cliVersion) {
|
||||
let buildCommandName: string;
|
||||
if (buildCommand) buildCommandName = `"${buildCommand}"`;
|
||||
else if (framework) buildCommandName = framework.name;
|
||||
else buildCommandName = 'the "build" script';
|
||||
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.`
|
||||
);
|
||||
}
|
||||
return {
|
||||
buildOutputVersion: 3,
|
||||
buildOutputPath,
|
||||
};
|
||||
return BuildOutputV3.createBuildOutput(
|
||||
meta,
|
||||
buildCommand,
|
||||
buildOutputPathV3,
|
||||
framework
|
||||
);
|
||||
}
|
||||
|
||||
if (framework) {
|
||||
const outputDirName = config.outputDirectory
|
||||
? config.outputDirectory
|
||||
: await framework.getOutputDirName(outputDirPrefix);
|
||||
|
||||
distPath = path.join(outputDirPrefix, outputDirName);
|
||||
} else if (!config || !config.distDir) {
|
||||
// Select either `dist` or `public` as directory
|
||||
const publicPath = path.join(entrypointDir, 'public');
|
||||
|
||||
if (
|
||||
!existsSync(distPath) &&
|
||||
existsSync(publicPath) &&
|
||||
statSync(publicPath).isDirectory()
|
||||
) {
|
||||
distPath = publicPath;
|
||||
}
|
||||
const buildOutputPathV2 = await BuildOutputV2.getBuildOutputDirectory(
|
||||
outputDirPrefix
|
||||
);
|
||||
if (buildOutputPathV2) {
|
||||
return await BuildOutputV2.createBuildOutput(workPath);
|
||||
}
|
||||
|
||||
const extraOutputs = await BuildOutputV1.readBuildOutputDirectory({
|
||||
|
||||
170
packages/static-build/src/utils/build-output-v2.ts
Normal file
170
packages/static-build/src/utils/build-output-v2.ts
Normal file
@@ -0,0 +1,170 @@
|
||||
import path from 'path';
|
||||
import { pathExists, readJson, appendFile } from 'fs-extra';
|
||||
import { Route } from '@vercel/routing-utils';
|
||||
import {
|
||||
Files,
|
||||
FileFsRef,
|
||||
debug,
|
||||
glob,
|
||||
EdgeFunction,
|
||||
BuildResultV2,
|
||||
} from '@vercel/build-utils';
|
||||
import { isObjectEmpty } from './_shared';
|
||||
|
||||
const BUILD_OUTPUT_DIR = '.output';
|
||||
const BRIDGE_MIDDLEWARE_V2_TO_V3 = `
|
||||
|
||||
|
||||
// appended to convert v2 middleware to v3 middleware
|
||||
export default async (request) => {
|
||||
const { response } = await _ENTRIES['middleware_pages/_middleware'].default({ request });
|
||||
return response;
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* Returns the path to the Build Output API v2 directory when the
|
||||
* `config.json` file was created by the framework / build script,
|
||||
* or `undefined` if the framework did not create the v3 output.
|
||||
*/
|
||||
export async function getBuildOutputDirectory(
|
||||
workingDir: string
|
||||
): Promise<string | undefined> {
|
||||
const outputDir = path.join(workingDir, BUILD_OUTPUT_DIR);
|
||||
const outputPathExists = await pathExists(outputDir);
|
||||
if (outputPathExists) {
|
||||
return outputDir;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the BUILD_OUTPUT_DIR directory and returns and object
|
||||
* that should be merged with the build outputs.
|
||||
*/
|
||||
export async function readBuildOutputDirectory({
|
||||
workPath,
|
||||
}: {
|
||||
workPath: string;
|
||||
}) {
|
||||
// Functions are not supported, but are used to support Middleware
|
||||
const functions: Record<string, EdgeFunction> = {};
|
||||
|
||||
// Routes are not supported, but are used to support Middleware
|
||||
const routes: Array<Route> = [];
|
||||
|
||||
const middleware = await getMiddleware(workPath);
|
||||
if (middleware) {
|
||||
routes.push(middleware.route);
|
||||
|
||||
functions['middleware'] = new EdgeFunction({
|
||||
deploymentTarget: 'v8-worker',
|
||||
entrypoint: '_middleware.js',
|
||||
files: {
|
||||
'_middleware.js': middleware.file,
|
||||
},
|
||||
name: 'middleware',
|
||||
});
|
||||
}
|
||||
|
||||
const staticFiles = await readStaticFiles({ workPath });
|
||||
|
||||
const outputs = {
|
||||
staticFiles: isObjectEmpty(staticFiles) ? null : staticFiles,
|
||||
functions: isObjectEmpty(functions) ? null : functions,
|
||||
routes: routes.length ? routes : null,
|
||||
};
|
||||
|
||||
if (outputs.functions) {
|
||||
debug(`Detected Serverless Functions in "${BUILD_OUTPUT_DIR}"`);
|
||||
}
|
||||
|
||||
if (outputs.staticFiles) {
|
||||
debug(`Detected Static Assets in "${BUILD_OUTPUT_DIR}"`);
|
||||
}
|
||||
|
||||
if (outputs.routes) {
|
||||
debug(`Detected Routes Configuration in "${BUILD_OUTPUT_DIR}"`);
|
||||
}
|
||||
|
||||
return outputs;
|
||||
}
|
||||
|
||||
async function getMiddleware(
|
||||
workPath: string
|
||||
): Promise<{ route: Route; file: FileFsRef } | undefined> {
|
||||
const manifestPath = path.join(
|
||||
workPath,
|
||||
BUILD_OUTPUT_DIR,
|
||||
'functions-manifest.json'
|
||||
);
|
||||
|
||||
try {
|
||||
const manifest = await readJson(manifestPath);
|
||||
if (manifest.pages['_middleware.js'].runtime !== 'web') {
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') throw error;
|
||||
return;
|
||||
}
|
||||
|
||||
const middlewareRelativePath = path.join(
|
||||
BUILD_OUTPUT_DIR,
|
||||
'server/pages/_middleware.js'
|
||||
);
|
||||
|
||||
const middlewareAbsoluatePath = path.join(workPath, middlewareRelativePath);
|
||||
await appendFile(middlewareAbsoluatePath, BRIDGE_MIDDLEWARE_V2_TO_V3);
|
||||
|
||||
const route = {
|
||||
src: '/(.*)',
|
||||
middlewarePath: 'middleware',
|
||||
continue: true,
|
||||
};
|
||||
|
||||
return {
|
||||
route,
|
||||
file: new FileFsRef({
|
||||
fsPath: middlewareRelativePath,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
async function readStaticFiles({
|
||||
workPath,
|
||||
}: {
|
||||
workPath: string;
|
||||
}): Promise<Files> {
|
||||
const staticFilePath = path.join(workPath, BUILD_OUTPUT_DIR, 'static');
|
||||
const staticFiles = await glob('**', {
|
||||
cwd: staticFilePath,
|
||||
});
|
||||
|
||||
return staticFiles;
|
||||
}
|
||||
|
||||
export async function createBuildOutput(
|
||||
workPath: string
|
||||
): Promise<BuildResultV2> {
|
||||
let output: Files = {};
|
||||
const routes: Route[] = [];
|
||||
|
||||
const extraOutputs = await readBuildOutputDirectory({
|
||||
workPath,
|
||||
});
|
||||
|
||||
if (extraOutputs.routes) {
|
||||
routes.push(...extraOutputs.routes);
|
||||
}
|
||||
|
||||
if (extraOutputs.staticFiles) {
|
||||
output = Object.assign(
|
||||
{},
|
||||
extraOutputs.staticFiles,
|
||||
extraOutputs.functions
|
||||
);
|
||||
}
|
||||
|
||||
return { routes, output };
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import { join } from 'path';
|
||||
import { promises as fs } from 'fs';
|
||||
import { BuildResultV2, Meta } from '../../../build-utils/dist';
|
||||
import { Framework } from '../../../frameworks/dist/types';
|
||||
|
||||
const BUILD_OUTPUT_DIR = '.vercel/output';
|
||||
|
||||
/**
|
||||
* Returns the path to the Build Output v3 directory when the
|
||||
* Returns the path to the Build Output API v3 directory when the
|
||||
* `config.json` file was created by the framework / build script,
|
||||
* or `undefined` if the framework did not create the v3 output.
|
||||
*/
|
||||
@@ -34,3 +36,27 @@ export async function readConfig(
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function createBuildOutput(
|
||||
meta: Meta,
|
||||
buildCommand: string | null,
|
||||
buildOutputPath: string,
|
||||
framework?: Framework
|
||||
): BuildResultV2 {
|
||||
if (!meta.cliVersion) {
|
||||
let buildCommandName: string;
|
||||
|
||||
if (buildCommand) buildCommandName = `"${buildCommand}"`;
|
||||
else if (framework) buildCommandName = framework.name;
|
||||
else buildCommandName = 'the "build" script';
|
||||
|
||||
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.`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
buildOutputVersion: 3,
|
||||
buildOutputPath,
|
||||
};
|
||||
}
|
||||
|
||||
1
packages/static-build/test/build-fixtures/09-build-output-v3/.gitignore
vendored
Normal file
1
packages/static-build/test/build-fixtures/09-build-output-v3/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
yarn.lock
|
||||
@@ -3,5 +3,5 @@ fs.mkdirSync('.vercel/output/static', { recursive: true });
|
||||
fs.writeFileSync('.vercel/output/config.json', '{}');
|
||||
fs.writeFileSync(
|
||||
'.vercel/output/static/index.html',
|
||||
'<h1>Build Output API</h1>'
|
||||
'<h1>Build Output API v3</h1>'
|
||||
);
|
||||
|
||||
1
packages/static-build/test/build-fixtures/10-build-output-v2/.gitignore
vendored
Normal file
1
packages/static-build/test/build-fixtures/10-build-output-v2/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
yarn.lock
|
||||
60
packages/static-build/test/build-fixtures/10-build-output-v2/build.js
Executable file
60
packages/static-build/test/build-fixtures/10-build-output-v2/build.js
Executable file
@@ -0,0 +1,60 @@
|
||||
const fs = require('fs');
|
||||
|
||||
fs.mkdirSync('.output/static', { recursive: true });
|
||||
fs.mkdirSync('.output/server/pages/api', { recursive: true });
|
||||
|
||||
fs.writeFileSync(
|
||||
'.output/functions-manifest.json',
|
||||
JSON.stringify(
|
||||
{
|
||||
version: 1,
|
||||
pages: {
|
||||
'_middleware.js': {
|
||||
runtime: 'web',
|
||||
env: [],
|
||||
files: ['server/pages/_middleware.js'],
|
||||
name: 'pages/_middleware',
|
||||
page: '/',
|
||||
regexp: '^/.*$',
|
||||
sortingIndex: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
|
||||
fs.writeFileSync('.output/static/index.html', '<h1>Build Output API v2</h1>');
|
||||
|
||||
fs.writeFileSync('.output/server/pages/about.html', '<h1>Some Site</h1>');
|
||||
|
||||
fs.writeFileSync(
|
||||
'.output/server/pages/api/user.js',
|
||||
`export default function handler(request, response) {
|
||||
response.status(200).json({
|
||||
body: 'some user info'
|
||||
});
|
||||
}`
|
||||
);
|
||||
|
||||
fs.writeFileSync(
|
||||
'.output/server/pages/_middleware.js',
|
||||
`
|
||||
const getResult = (body, options) => ({
|
||||
promise: Promise.resolve(),
|
||||
waitUntil: Promise.resolve(),
|
||||
response: new Response(body, options),
|
||||
});
|
||||
|
||||
_ENTRIES = typeof _ENTRIES === 'undefined' ? {} : _ENTRIES;
|
||||
|
||||
_ENTRIES['middleware_pages/_middleware'] = {
|
||||
default: async function ({ request }) {
|
||||
|
||||
return getResult('hi from the edge', {});
|
||||
|
||||
},
|
||||
};
|
||||
`
|
||||
);
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "10-build-output-v2",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "node build.js"
|
||||
}
|
||||
}
|
||||
108
packages/static-build/test/build.test.ts
vendored
108
packages/static-build/test/build.test.ts
vendored
@@ -1,54 +1,88 @@
|
||||
import path from 'path';
|
||||
import { remove } from 'fs-extra';
|
||||
import { build } from '../src';
|
||||
|
||||
describe('build()', () => {
|
||||
it('should detect Builder Output v3', async () => {
|
||||
const workPath = path.join(
|
||||
__dirname,
|
||||
'build-fixtures',
|
||||
'09-build-output-v3'
|
||||
);
|
||||
const buildResult = await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
skipDownload: true,
|
||||
cliVersion: '0.0.0',
|
||||
},
|
||||
describe('Build Output API v2', () => {
|
||||
it('should detect the output format', async () => {
|
||||
const workPath = path.join(
|
||||
__dirname,
|
||||
'build-fixtures',
|
||||
'10-build-output-v2'
|
||||
);
|
||||
|
||||
try {
|
||||
const buildResult = await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
skipDownload: true,
|
||||
cliVersion: '0.0.0',
|
||||
},
|
||||
});
|
||||
if ('buildOutputVersion' in buildResult) {
|
||||
throw new Error('Unexpected `buildOutputVersion` in build result');
|
||||
}
|
||||
|
||||
expect(buildResult.output['index.html']).toBeTruthy();
|
||||
expect(buildResult.output['middleware']).toBeTruthy();
|
||||
} finally {
|
||||
remove(path.join(workPath, '.output'));
|
||||
}
|
||||
});
|
||||
if ('output' in buildResult) {
|
||||
throw new Error('Unexpected `output` in build result');
|
||||
}
|
||||
expect(buildResult.buildOutputVersion).toEqual(3);
|
||||
expect(buildResult.buildOutputPath).toEqual(
|
||||
path.join(workPath, '.vercel/output')
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an Error with Builder Output v3 without `vercel build`', async () => {
|
||||
let err;
|
||||
const workPath = path.join(
|
||||
__dirname,
|
||||
'build-fixtures',
|
||||
'09-build-output-v3'
|
||||
);
|
||||
try {
|
||||
await build({
|
||||
describe('Build Output API v3', () => {
|
||||
it('should detect the output format', async () => {
|
||||
const workPath = path.join(
|
||||
__dirname,
|
||||
'build-fixtures',
|
||||
'09-build-output-v3'
|
||||
);
|
||||
const buildResult = await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
skipDownload: true,
|
||||
cliVersion: '0.0.0',
|
||||
},
|
||||
});
|
||||
} catch (_err: any) {
|
||||
err = _err;
|
||||
}
|
||||
expect(err.message).toEqual(
|
||||
`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.`
|
||||
);
|
||||
if ('output' in buildResult) {
|
||||
throw new Error('Unexpected `output` in build result');
|
||||
}
|
||||
expect(buildResult.buildOutputVersion).toEqual(3);
|
||||
expect(buildResult.buildOutputPath).toEqual(
|
||||
path.join(workPath, '.vercel/output')
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw an Error without `vercel build`', async () => {
|
||||
let err;
|
||||
const workPath = path.join(
|
||||
__dirname,
|
||||
'build-fixtures',
|
||||
'09-build-output-v3'
|
||||
);
|
||||
try {
|
||||
await build({
|
||||
files: {},
|
||||
entrypoint: 'package.json',
|
||||
workPath,
|
||||
config: {},
|
||||
meta: {
|
||||
skipDownload: true,
|
||||
},
|
||||
});
|
||||
} catch (_err: any) {
|
||||
err = _err;
|
||||
}
|
||||
expect(err.message).toEqual(
|
||||
`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.`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user