mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 12:57:46 +00:00
Compare commits
8 Commits
vercel-plu
...
vercel-plu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b865ff753 | ||
|
|
4fd0734c48 | ||
|
|
f815421acb | ||
|
|
5da926fee1 | ||
|
|
3559531e4c | ||
|
|
449a3b3648 | ||
|
|
7bd338618c | ||
|
|
9048a6f584 |
10
examples/remix/.gitignore
vendored
10
examples/remix/.gitignore
vendored
@@ -1,8 +1,8 @@
|
||||
node_modules
|
||||
|
||||
/.cache
|
||||
/.vercel
|
||||
/.output
|
||||
.cache
|
||||
.vercel
|
||||
.output
|
||||
|
||||
/public/build
|
||||
/api/build
|
||||
public/build
|
||||
api/build
|
||||
|
||||
@@ -2,56 +2,33 @@
|
||||
|
||||
- [Remix Docs](https://remix.run/docs)
|
||||
|
||||
## Vercel Setup
|
||||
## Deployment
|
||||
|
||||
First you'll need the [Vercel CLI](https://vercel.com/docs/cli):
|
||||
After having run the `create-remix` command and selected "Vercel" as a deployment target, you only need to [import your Git repository](https://vercel.com/new) into Vercel, and it will be deployed.
|
||||
|
||||
If you'd like to avoid using a Git repository, you can also deploy the directory by running [Vercel CLI](https://vercel.com/cli):
|
||||
|
||||
```sh
|
||||
npm i -g vercel
|
||||
vercel
|
||||
```
|
||||
|
||||
Before you can run the app in development, you need to link this project to a new Vercel project on your account.
|
||||
|
||||
**It is important that you use a new project. If you try to link this project to an existing project (like a Next.js site) you will have problems.**
|
||||
|
||||
```sh
|
||||
$ vercel link
|
||||
```
|
||||
|
||||
Follow the prompts, and when it's done you should be able to get started.
|
||||
It is generally recommended to use a Git repository, because future commits will then automatically be deployed by Vercel, through its [Git Integration](https://vercel.com/docs/concepts/git).
|
||||
|
||||
## Development
|
||||
|
||||
You will be running two processes during development when using Vercel as your server.
|
||||
|
||||
- Your Vercel server in one
|
||||
- The Remix development server in another
|
||||
To run your Remix app locally, make sure your project's local dependencies are installed:
|
||||
|
||||
```sh
|
||||
# in one tab
|
||||
$ vercel dev
|
||||
npm install
|
||||
```
|
||||
|
||||
# in another
|
||||
$ npm run dev
|
||||
Afterwards, start the Remix development server like so:
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Open up [http://localhost:3000](http://localhost:3000) and you should be ready to go!
|
||||
|
||||
If you'd rather run everything in a single tab, you can look at [concurrently](https://npm.im/concurrently) or similar tools to run both processes in one tab.
|
||||
|
||||
## Deploying
|
||||
|
||||
```sh
|
||||
$ npm run build
|
||||
# preview deployment
|
||||
$ vercel
|
||||
|
||||
# production deployment
|
||||
$ vercel --prod
|
||||
```
|
||||
|
||||
### GitHub Automatic Deployments
|
||||
|
||||
For some reason the GitHub integration doesn't deploy the public folder. We're working with Vercel to figure this out.
|
||||
|
||||
For now, [you can set up a GitHub action with this config](https://gist.github.com/mcansh/91f8effda798b41bb373351fad217070) from our friend [@mcansh](https://github.com/mcansh).
|
||||
If you're used to using the `vercel dev` command provided by [Vercel CLI](https://vercel.com/cli) instead, you can also use that, but it's not needed.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
Link,
|
||||
Links,
|
||||
@@ -7,23 +6,14 @@ import {
|
||||
Outlet,
|
||||
Scripts,
|
||||
ScrollRestoration,
|
||||
useCatch,
|
||||
useLocation
|
||||
useCatch
|
||||
} from "remix";
|
||||
import type { LinksFunction } from "remix";
|
||||
|
||||
import deleteMeRemixStyles from "~/styles/demos/remix.css";
|
||||
import globalStylesUrl from "~/styles/global.css";
|
||||
import darkStylesUrl from "~/styles/dark.css";
|
||||
|
||||
/**
|
||||
* The `links` export is a function that returns an array of objects that map to
|
||||
* the attributes for an HTML `<link>` element. These will load `<link>` tags on
|
||||
* every route in the app, but individual routes can include their own links
|
||||
* that are automatically unloaded when a user navigates away from the route.
|
||||
*
|
||||
* https://remix.run/api/app#links
|
||||
*/
|
||||
// https://remix.run/api/app#links
|
||||
export let links: LinksFunction = () => {
|
||||
return [
|
||||
{ rel: "stylesheet", href: globalStylesUrl },
|
||||
@@ -31,16 +21,12 @@ export let links: LinksFunction = () => {
|
||||
rel: "stylesheet",
|
||||
href: darkStylesUrl,
|
||||
media: "(prefers-color-scheme: dark)"
|
||||
},
|
||||
{ rel: "stylesheet", href: deleteMeRemixStyles }
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* The root module's default export is a component that renders the current
|
||||
* route via the `<Outlet />` component. Think of this as the global layout
|
||||
* component for your app.
|
||||
*/
|
||||
// https://remix.run/api/conventions#default-export
|
||||
// https://remix.run/api/conventions#route-filenames
|
||||
export default function App() {
|
||||
return (
|
||||
<Document>
|
||||
@@ -51,68 +37,27 @@ export default function App() {
|
||||
);
|
||||
}
|
||||
|
||||
function Document({
|
||||
children,
|
||||
title
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
title?: string;
|
||||
}) {
|
||||
// https://remix.run/docs/en/v1/api/conventions#errorboundary
|
||||
export function ErrorBoundary({ error }: { error: Error }) {
|
||||
console.error(error);
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
{title ? <title>{title}</title> : null}
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<RouteChangeAnnouncement />
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
{process.env.NODE_ENV === "development" && <LiveReload />}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
function Layout({ children }: React.PropsWithChildren<{}>) {
|
||||
return (
|
||||
<div className="remix-app">
|
||||
<header className="remix-app__header">
|
||||
<div className="container remix-app__header-content">
|
||||
<Link to="/" title="Remix" className="remix-app__header-home-link">
|
||||
<RemixLogo />
|
||||
</Link>
|
||||
<nav aria-label="Main navigation" className="remix-app__header-nav">
|
||||
<ul>
|
||||
<li>
|
||||
<Link to="/">Home</Link>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://remix.run/docs">Remix Docs</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/remix-run/remix">GitHub</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
<div className="remix-app__main">
|
||||
<div className="container remix-app__main-content">{children}</div>
|
||||
</div>
|
||||
<footer className="remix-app__footer">
|
||||
<div className="container remix-app__footer-content">
|
||||
<p>© You!</p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
<Document title="Error!">
|
||||
<Layout>
|
||||
<div>
|
||||
<h1>There was an error</h1>
|
||||
<p>{error.message}</p>
|
||||
<hr />
|
||||
<p>
|
||||
Hey, developer, you should replace this with what you want your
|
||||
users to see.
|
||||
</p>
|
||||
</div>
|
||||
</Layout>
|
||||
</Document>
|
||||
);
|
||||
}
|
||||
|
||||
// https://remix.run/docs/en/v1/api/conventions#catchboundary
|
||||
export function CatchBoundary() {
|
||||
let caught = useCatch();
|
||||
|
||||
@@ -148,26 +93,68 @@ export function CatchBoundary() {
|
||||
);
|
||||
}
|
||||
|
||||
export function ErrorBoundary({ error }: { error: Error }) {
|
||||
console.error(error);
|
||||
function Document({
|
||||
children,
|
||||
title
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
title?: string;
|
||||
}) {
|
||||
return (
|
||||
<Document title="Error!">
|
||||
<Layout>
|
||||
<div>
|
||||
<h1>There was an error</h1>
|
||||
<p>{error.message}</p>
|
||||
<hr />
|
||||
<p>
|
||||
Hey, developer, you should replace this with what you want your
|
||||
users to see.
|
||||
</p>
|
||||
</div>
|
||||
</Layout>
|
||||
</Document>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
{title ? <title>{title}</title> : null}
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
{process.env.NODE_ENV === "development" && <LiveReload />}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
function RemixLogo(props: React.ComponentPropsWithoutRef<"svg">) {
|
||||
function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="remix-app">
|
||||
<header className="remix-app__header">
|
||||
<div className="container remix-app__header-content">
|
||||
<Link to="/" title="Remix" className="remix-app__header-home-link">
|
||||
<RemixLogo />
|
||||
</Link>
|
||||
<nav aria-label="Main navigation" className="remix-app__header-nav">
|
||||
<ul>
|
||||
<li>
|
||||
<Link to="/">Home</Link>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://remix.run/docs">Remix Docs</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/remix-run/remix">GitHub</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
<div className="remix-app__main">
|
||||
<div className="container remix-app__main-content">{children}</div>
|
||||
</div>
|
||||
<footer className="remix-app__footer">
|
||||
<div className="container remix-app__footer-content">
|
||||
<p>© You!</p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RemixLogo() {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 659 165"
|
||||
@@ -179,7 +166,6 @@ function RemixLogo(props: React.ComponentPropsWithoutRef<"svg">) {
|
||||
width="106"
|
||||
height="30"
|
||||
fill="currentColor"
|
||||
{...props}
|
||||
>
|
||||
<title id="remix-run-logo-title">Remix Logo</title>
|
||||
<path d="M0 161V136H45.5416C53.1486 136 54.8003 141.638 54.8003 145V161H0Z M133.85 124.16C135.3 142.762 135.3 151.482 135.3 161H92.2283C92.2283 158.927 92.2653 157.03 92.3028 155.107C92.4195 149.128 92.5411 142.894 91.5717 130.304C90.2905 111.872 82.3473 107.776 67.7419 107.776H54.8021H0V74.24H69.7918C88.2407 74.24 97.4651 68.632 97.4651 53.784C97.4651 40.728 88.2407 32.816 69.7918 32.816H0V0H77.4788C119.245 0 140 19.712 140 51.2C140 74.752 125.395 90.112 105.665 92.672C122.32 96 132.057 105.472 133.85 124.16Z" />
|
||||
@@ -190,58 +176,3 @@ function RemixLogo(props: React.ComponentPropsWithoutRef<"svg">) {
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an alert for screen reader users when the route changes.
|
||||
*/
|
||||
const RouteChangeAnnouncement = React.memo(() => {
|
||||
let [hydrated, setHydrated] = React.useState(false);
|
||||
let [innerHtml, setInnerHtml] = React.useState("");
|
||||
let location = useLocation();
|
||||
|
||||
React.useEffect(() => {
|
||||
setHydrated(true);
|
||||
}, []);
|
||||
|
||||
let firstRenderRef = React.useRef(true);
|
||||
React.useEffect(() => {
|
||||
// Skip the first render because we don't want an announcement on the
|
||||
// initial page load.
|
||||
if (firstRenderRef.current) {
|
||||
firstRenderRef.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
let pageTitle = location.pathname === "/" ? "Home page" : document.title;
|
||||
setInnerHtml(`Navigated to ${pageTitle}`);
|
||||
}, [location.pathname]);
|
||||
|
||||
// Render nothing on the server. The live region provides no value unless
|
||||
// scripts are loaded and the browser takes over normal routing.
|
||||
if (!hydrated) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-live="assertive"
|
||||
aria-atomic
|
||||
id="route-change-region"
|
||||
style={{
|
||||
border: "0",
|
||||
clipPath: "inset(100%)",
|
||||
clip: "rect(0 0 0 0)",
|
||||
height: "1px",
|
||||
margin: "-1px",
|
||||
overflow: "hidden",
|
||||
padding: "0",
|
||||
position: "absolute",
|
||||
width: "1px",
|
||||
whiteSpace: "nowrap",
|
||||
wordWrap: "normal"
|
||||
}}
|
||||
>
|
||||
{innerHtml}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -96,3 +96,121 @@ input:where([type="search"]) {
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.remix-app {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
min-height: calc(100vh - env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.remix-app > * {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.remix-app__header {
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.remix-app__header-content {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.remix-app__header-home-link {
|
||||
width: 106px;
|
||||
height: 30px;
|
||||
color: var(--color-foreground);
|
||||
}
|
||||
|
||||
.remix-app__header-nav ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.5em;
|
||||
}
|
||||
|
||||
.remix-app__header-nav li {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.remix-app__main {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
|
||||
.remix-app__footer {
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.remix-app__footer-content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.remix__page {
|
||||
--gap: 1rem;
|
||||
--space: 2rem;
|
||||
display: grid;
|
||||
grid-auto-rows: min-content;
|
||||
gap: var(--gap);
|
||||
padding-top: var(--space);
|
||||
padding-bottom: var(--space);
|
||||
}
|
||||
|
||||
@media print, screen and (min-width: 640px) {
|
||||
.remix__page {
|
||||
--gap: 2rem;
|
||||
grid-auto-rows: unset;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1024px) {
|
||||
.remix__page {
|
||||
--gap: 4rem;
|
||||
}
|
||||
}
|
||||
|
||||
.remix__page > main > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.remix__page > main > :last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.remix__page > aside {
|
||||
margin: 0;
|
||||
padding: 1.5ch 2ch;
|
||||
border: solid 1px var(--color-border);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.remix__page > aside > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.remix__page > aside > :last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.remix__form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.remix__form > * {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,15 @@
|
||||
"postinstall": "remix setup node"
|
||||
},
|
||||
"dependencies": {
|
||||
"@remix-run/react": "^1.0.4",
|
||||
"@remix-run/react": "^1.0.5",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"remix": "^1.0.4",
|
||||
"@remix-run/vercel": "^1.0.4"
|
||||
"remix": "^1.0.5",
|
||||
"@remix-run/serve": "^1.0.5",
|
||||
"@remix-run/vercel": "^1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@remix-run/dev": "^1.0.4",
|
||||
"@remix-run/dev": "^1.0.5",
|
||||
"@types/react": "^17.0.24",
|
||||
"@types/react-dom": "^17.0.9",
|
||||
"typescript": "^4.1.2"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"build": {
|
||||
"env": {
|
||||
"ENABLE_FILE_SYSTEM_API": "1"
|
||||
}
|
||||
"build": {
|
||||
"env": {
|
||||
"ENABLE_FILE_SYSTEM_API": "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/build-utils",
|
||||
"version": "2.12.3-canary.22",
|
||||
"version": "2.12.3-canary.25",
|
||||
"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.1",
|
||||
"@vercel/frameworks": "0.5.1-canary.13",
|
||||
"@vercel/frameworks": "0.5.1-canary.15",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"aggregate-error": "3.0.1",
|
||||
"async-retry": "1.2.3",
|
||||
|
||||
@@ -2,7 +2,6 @@ import fs from 'fs-extra';
|
||||
import { join, dirname, relative } from 'path';
|
||||
import glob from './fs/glob';
|
||||
import { normalizePath } from './fs/normalize-path';
|
||||
import { detectBuilders } from './detect-builders';
|
||||
import { FILES_SYMBOL, getLambdaOptionsFromFunction, Lambda } from './lambda';
|
||||
import type FileBlob from './file-blob';
|
||||
import type { BuilderFunctions, BuildOptions, Files } from './types';
|
||||
@@ -25,8 +24,6 @@ export function convertRuntimeToPlugin(
|
||||
vercelConfig: {
|
||||
functions?: BuilderFunctions;
|
||||
regions?: string[];
|
||||
trailingSlash?: boolean;
|
||||
cleanUrls?: boolean;
|
||||
};
|
||||
workPath: string;
|
||||
}) {
|
||||
@@ -35,7 +32,7 @@ export function convertRuntimeToPlugin(
|
||||
delete files['vercel.json']; // Builders/Runtimes didn't have vercel.json
|
||||
const entrypoints = await glob(`api/**/*${ext}`, opts);
|
||||
const pages: { [key: string]: any } = {};
|
||||
const { functions = {}, cleanUrls, trailingSlash } = vercelConfig;
|
||||
const { functions = {} } = vercelConfig;
|
||||
const traceDir = join(workPath, '.output', 'runtime-traced-files');
|
||||
await fs.ensureDir(traceDir);
|
||||
|
||||
@@ -64,7 +61,7 @@ export function convertRuntimeToPlugin(
|
||||
maxDuration: output.maxDuration,
|
||||
environment: output.environment,
|
||||
allowQuery: output.allowQuery,
|
||||
regions: output.regions,
|
||||
//regions: output.regions,
|
||||
};
|
||||
|
||||
// @ts-ignore This symbol is a private API
|
||||
@@ -112,61 +109,6 @@ export function convertRuntimeToPlugin(
|
||||
}
|
||||
|
||||
await updateFunctionsManifest({ vercelConfig, workPath, pages });
|
||||
|
||||
const {
|
||||
warnings,
|
||||
errors,
|
||||
//defaultRoutes,
|
||||
redirectRoutes,
|
||||
//rewriteRoutes,
|
||||
dynamicRoutesWithKeys,
|
||||
// errorRoutes, already handled by pages404
|
||||
} = await detectBuilders(Object.keys(files), null, {
|
||||
tag: 'latest',
|
||||
functions: functions,
|
||||
projectSettings: undefined,
|
||||
featHandleMiss: true,
|
||||
cleanUrls,
|
||||
trailingSlash,
|
||||
});
|
||||
|
||||
if (errors) {
|
||||
throw new Error(errors[0].message);
|
||||
}
|
||||
|
||||
if (warnings) {
|
||||
warnings.forEach(warning => console.warn(warning.message, warning.link));
|
||||
}
|
||||
|
||||
const redirects = redirectRoutes
|
||||
?.filter(r => r.src && 'headers' in r)
|
||||
?.map(r => ({
|
||||
source: r.src || '',
|
||||
destination:
|
||||
'headers' in r && r.headers?.Location ? r.headers.Location : '',
|
||||
statusCode: 'status' in r && r.status ? r.status : 307,
|
||||
regex: r.src || '',
|
||||
}));
|
||||
|
||||
const dynamicRoutes = dynamicRoutesWithKeys?.map(r => {
|
||||
const keys = Object.keys(r.routeKeys);
|
||||
return {
|
||||
page: '/' + r.fileName.slice(0, -ext.length),
|
||||
regex: r.regex,
|
||||
routeKeys: r.routeKeys,
|
||||
namedRegex: r.regex
|
||||
.split('([^/]+)')
|
||||
.map((str, i) => str + (keys[i] ? `(?<${keys[i]}>[^/]+)` : ''))
|
||||
.join(''),
|
||||
};
|
||||
});
|
||||
|
||||
await updateRoutesManifest({
|
||||
workPath,
|
||||
redirects,
|
||||
rewrites: [],
|
||||
dynamicRoutes,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,6 @@ interface ErrorResponse {
|
||||
link?: string;
|
||||
}
|
||||
|
||||
interface DynamicRoutesWithKeys {
|
||||
fileName: string;
|
||||
regex: string;
|
||||
routeKeys: { [key: string]: string };
|
||||
}
|
||||
|
||||
interface Options {
|
||||
tag?: 'canary' | 'latest' | string;
|
||||
functions?: BuilderFunctions;
|
||||
@@ -102,7 +96,7 @@ export async function detectBuilders(
|
||||
redirectRoutes: Route[] | null;
|
||||
rewriteRoutes: Route[] | null;
|
||||
errorRoutes: Route[] | null;
|
||||
dynamicRoutesWithKeys: DynamicRoutesWithKeys[] | null;
|
||||
limitedRoutes: LimitedRoutes | null;
|
||||
}> {
|
||||
const errors: ErrorResponse[] = [];
|
||||
const warnings: ErrorResponse[] = [];
|
||||
@@ -121,7 +115,7 @@ export async function detectBuilders(
|
||||
redirectRoutes: null,
|
||||
rewriteRoutes: null,
|
||||
errorRoutes: null,
|
||||
dynamicRoutesWithKeys: null,
|
||||
limitedRoutes: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -165,14 +159,13 @@ export async function detectBuilders(
|
||||
|
||||
const apiRoutes: Source[] = [];
|
||||
const dynamicRoutes: Source[] = [];
|
||||
const dynamicRoutesWithKeys: DynamicRoutesWithKeys[] = [];
|
||||
|
||||
// API
|
||||
for (const fileName of sortedFiles) {
|
||||
const apiBuilder = maybeGetApiBuilder(fileName, apiMatches, options);
|
||||
|
||||
if (apiBuilder) {
|
||||
const { routeError, apiRoute, isDynamic, routeKeys } = getApiRoute(
|
||||
const { routeError, apiRoute, isDynamic } = getApiRoute(
|
||||
fileName,
|
||||
apiSortedFiles,
|
||||
options,
|
||||
@@ -188,7 +181,7 @@ export async function detectBuilders(
|
||||
redirectRoutes: null,
|
||||
rewriteRoutes: null,
|
||||
errorRoutes: null,
|
||||
dynamicRoutesWithKeys: null,
|
||||
limitedRoutes: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -196,11 +189,6 @@ export async function detectBuilders(
|
||||
apiRoutes.push(apiRoute);
|
||||
if (isDynamic) {
|
||||
dynamicRoutes.push(apiRoute);
|
||||
dynamicRoutesWithKeys.push({
|
||||
fileName,
|
||||
regex: apiRoute.src,
|
||||
routeKeys,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +260,7 @@ export async function detectBuilders(
|
||||
defaultRoutes: null,
|
||||
rewriteRoutes: null,
|
||||
errorRoutes: null,
|
||||
dynamicRoutesWithKeys: null,
|
||||
limitedRoutes: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -315,7 +303,7 @@ export async function detectBuilders(
|
||||
defaultRoutes: null,
|
||||
rewriteRoutes: null,
|
||||
errorRoutes: null,
|
||||
dynamicRoutesWithKeys: null,
|
||||
limitedRoutes: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -343,6 +331,7 @@ export async function detectBuilders(
|
||||
}
|
||||
|
||||
const routesResult = getRouteResult(
|
||||
pkg,
|
||||
apiRoutes,
|
||||
dynamicRoutes,
|
||||
usedOutputDirectory,
|
||||
@@ -359,7 +348,7 @@ export async function detectBuilders(
|
||||
defaultRoutes: routesResult.defaultRoutes,
|
||||
rewriteRoutes: routesResult.rewriteRoutes,
|
||||
errorRoutes: routesResult.errorRoutes,
|
||||
dynamicRoutesWithKeys,
|
||||
limitedRoutes: routesResult.limitedRoutes,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -693,7 +682,6 @@ function getApiRoute(
|
||||
): {
|
||||
apiRoute: Source | null;
|
||||
isDynamic: boolean;
|
||||
routeKeys: { [key: string]: string };
|
||||
routeError: ErrorResponse | null;
|
||||
} {
|
||||
const conflictingSegment = getConflictingSegment(fileName);
|
||||
@@ -702,7 +690,6 @@ function getApiRoute(
|
||||
return {
|
||||
apiRoute: null,
|
||||
isDynamic: false,
|
||||
routeKeys: {},
|
||||
routeError: {
|
||||
code: 'conflicting_path_segment',
|
||||
message:
|
||||
@@ -723,7 +710,6 @@ function getApiRoute(
|
||||
return {
|
||||
apiRoute: null,
|
||||
isDynamic: false,
|
||||
routeKeys: {},
|
||||
routeError: {
|
||||
code: 'conflicting_file_path',
|
||||
message:
|
||||
@@ -743,7 +729,6 @@ function getApiRoute(
|
||||
return {
|
||||
apiRoute: out.route,
|
||||
isDynamic: out.isDynamic,
|
||||
routeKeys: out.routeKeys,
|
||||
routeError: null,
|
||||
};
|
||||
}
|
||||
@@ -889,12 +874,11 @@ function createRouteFromPath(
|
||||
filePath: string,
|
||||
featHandleMiss: boolean,
|
||||
cleanUrls: boolean
|
||||
): { route: Source; isDynamic: boolean; routeKeys: { [key: string]: string } } {
|
||||
): { route: Source; isDynamic: boolean } {
|
||||
const parts = filePath.split('/');
|
||||
|
||||
let counter = 1;
|
||||
const query: string[] = [];
|
||||
const routeKeys: { [key: string]: string } = {};
|
||||
let isDynamic = false;
|
||||
|
||||
const srcParts = parts.map((segment, i): string => {
|
||||
@@ -904,7 +888,6 @@ function createRouteFromPath(
|
||||
if (name !== null) {
|
||||
// We can't use `URLSearchParams` because `$` would get escaped
|
||||
query.push(`${name}=$${counter++}`);
|
||||
routeKeys[name] = name;
|
||||
isDynamic = true;
|
||||
return `([^/]+)`;
|
||||
} else if (isLast) {
|
||||
@@ -953,10 +936,17 @@ function createRouteFromPath(
|
||||
};
|
||||
}
|
||||
|
||||
return { route, isDynamic, routeKeys };
|
||||
return { route, isDynamic };
|
||||
}
|
||||
|
||||
interface LimitedRoutes {
|
||||
defaultRoutes: Route[];
|
||||
redirectRoutes: Route[];
|
||||
rewriteRoutes: Route[];
|
||||
}
|
||||
|
||||
function getRouteResult(
|
||||
pkg: PackageJson | undefined | null,
|
||||
apiRoutes: Source[],
|
||||
dynamicRoutes: Source[],
|
||||
outputDirectory: string,
|
||||
@@ -968,11 +958,18 @@ function getRouteResult(
|
||||
redirectRoutes: Route[];
|
||||
rewriteRoutes: Route[];
|
||||
errorRoutes: Route[];
|
||||
limitedRoutes: LimitedRoutes;
|
||||
} {
|
||||
const deps = Object.assign({}, pkg?.dependencies, pkg?.devDependencies);
|
||||
const defaultRoutes: Route[] = [];
|
||||
const redirectRoutes: Route[] = [];
|
||||
const rewriteRoutes: Route[] = [];
|
||||
const errorRoutes: Route[] = [];
|
||||
const limitedRoutes: LimitedRoutes = {
|
||||
defaultRoutes: [],
|
||||
redirectRoutes: [],
|
||||
rewriteRoutes: [],
|
||||
};
|
||||
const framework = frontendBuilder?.config?.framework || '';
|
||||
const isNextjs =
|
||||
framework === 'nextjs' || isOfficialRuntime('next', frontendBuilder?.use);
|
||||
@@ -980,14 +977,43 @@ function getRouteResult(
|
||||
|
||||
if (apiRoutes && apiRoutes.length > 0) {
|
||||
if (options.featHandleMiss) {
|
||||
// Exclude extension names if the corresponding plugin is not found in package.json
|
||||
// detectBuilders({ignoreRoutesForBuilders: ['@vercel/python']})
|
||||
// return a copy of routes.
|
||||
// We should exclud errorRoutes and
|
||||
const extSet = detectApiExtensions(apiBuilders);
|
||||
const withTag = options.tag ? `@${options.tag}` : '';
|
||||
const extSetLimited = detectApiExtensions(
|
||||
apiBuilders.filter(b => {
|
||||
if (
|
||||
b.use === `@vercel/python${withTag}` &&
|
||||
!('vercel-plugin-python' in deps)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
b.use === `@vercel/go${withTag}` &&
|
||||
!('vercel-plugin-go' in deps)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
b.use === `@vercel/ruby${withTag}` &&
|
||||
!('vercel-plugin-ruby' in deps)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
);
|
||||
|
||||
if (extSet.size > 0) {
|
||||
const exts = Array.from(extSet)
|
||||
const extGroup = `(?:\\.(?:${Array.from(extSet)
|
||||
.map(ext => ext.slice(1))
|
||||
.join('|');
|
||||
|
||||
const extGroup = `(?:\\.(?:${exts}))`;
|
||||
.join('|')}))`;
|
||||
const extGroupLimited = `(?:\\.(?:${Array.from(extSetLimited)
|
||||
.map(ext => ext.slice(1))
|
||||
.join('|')}))`;
|
||||
|
||||
if (options.cleanUrls) {
|
||||
redirectRoutes.push({
|
||||
@@ -1003,6 +1029,20 @@ function getRouteResult(
|
||||
},
|
||||
status: 308,
|
||||
});
|
||||
|
||||
limitedRoutes.redirectRoutes.push({
|
||||
src: `^/(api(?:.+)?)/index${extGroupLimited}?/?$`,
|
||||
headers: { Location: options.trailingSlash ? '/$1/' : '/$1' },
|
||||
status: 308,
|
||||
});
|
||||
|
||||
limitedRoutes.redirectRoutes.push({
|
||||
src: `^/api/(.+)${extGroupLimited}/?$`,
|
||||
headers: {
|
||||
Location: options.trailingSlash ? '/api/$1/' : '/api/$1',
|
||||
},
|
||||
status: 308,
|
||||
});
|
||||
} else {
|
||||
defaultRoutes.push({ handle: 'miss' });
|
||||
defaultRoutes.push({
|
||||
@@ -1010,10 +1050,18 @@ function getRouteResult(
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
});
|
||||
|
||||
limitedRoutes.defaultRoutes.push({ handle: 'miss' });
|
||||
limitedRoutes.defaultRoutes.push({
|
||||
src: `^/api/(.+)${extGroupLimited}$`,
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
rewriteRoutes.push(...dynamicRoutes);
|
||||
limitedRoutes.rewriteRoutes.push(...dynamicRoutes);
|
||||
|
||||
if (typeof ignoreRuntimes === 'undefined') {
|
||||
// This route is only necessary to hide the directory listing
|
||||
@@ -1064,6 +1112,7 @@ function getRouteResult(
|
||||
redirectRoutes,
|
||||
rewriteRoutes,
|
||||
errorRoutes,
|
||||
limitedRoutes,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2385,13 +2385,10 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
{
|
||||
const files = ['api/user.go', 'api/team.js', 'api/package.json'];
|
||||
|
||||
const { defaultRoutes, rewriteRoutes, errorRoutes } = await detectBuilders(
|
||||
files,
|
||||
null,
|
||||
{
|
||||
const { defaultRoutes, rewriteRoutes, errorRoutes, limitedRoutes } =
|
||||
await detectBuilders(files, null, {
|
||||
featHandleMiss,
|
||||
}
|
||||
);
|
||||
});
|
||||
expect(defaultRoutes).toStrictEqual([
|
||||
{ handle: 'miss' },
|
||||
{
|
||||
@@ -2414,6 +2411,22 @@ it('Test `detectRoutes` with `featHandleMiss=true`', async () => {
|
||||
},
|
||||
]);
|
||||
|
||||
// Limited routes should have js but not go since the go plugin is not installed
|
||||
expect(limitedRoutes).toStrictEqual({
|
||||
redirectRoutes: [],
|
||||
rewriteRoutes: [],
|
||||
defaultRoutes: [
|
||||
{
|
||||
handle: 'miss',
|
||||
},
|
||||
{
|
||||
src: '^/api/(.+)(?:\\.(?:js))$',
|
||||
dest: '/api/$1',
|
||||
check: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const pattern = new RegExp(errorRoutes![0].src!);
|
||||
|
||||
[
|
||||
@@ -2816,8 +2829,13 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
|
||||
{
|
||||
const files = ['api/user.go', 'api/team.js', 'api/package.json'];
|
||||
|
||||
const { defaultRoutes, redirectRoutes, rewriteRoutes, errorRoutes } =
|
||||
await detectBuilders(files, null, options);
|
||||
const {
|
||||
defaultRoutes,
|
||||
redirectRoutes,
|
||||
rewriteRoutes,
|
||||
errorRoutes,
|
||||
limitedRoutes,
|
||||
} = await detectBuilders(files, null, options);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([]);
|
||||
expect(rewriteRoutes).toStrictEqual([
|
||||
@@ -2834,6 +2852,28 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`', async ()
|
||||
},
|
||||
]);
|
||||
|
||||
// Limited routes should have js but not go since the go plugin is not installed
|
||||
expect(limitedRoutes).toStrictEqual({
|
||||
redirectRoutes: [
|
||||
{
|
||||
src: '^/(api(?:.+)?)/index(?:\\.(?:js))?/?$',
|
||||
headers: {
|
||||
Location: '/$1',
|
||||
},
|
||||
status: 308,
|
||||
},
|
||||
{
|
||||
src: '^/api/(.+)(?:\\.(?:js))/?$',
|
||||
headers: {
|
||||
Location: '/api/$1',
|
||||
},
|
||||
status: 308,
|
||||
},
|
||||
],
|
||||
rewriteRoutes: [],
|
||||
defaultRoutes: [],
|
||||
});
|
||||
|
||||
// expected redirect should match inputs
|
||||
const getLocation = createReplaceLocation(redirectRoutes);
|
||||
|
||||
@@ -3077,7 +3117,7 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
|
||||
{
|
||||
const files = ['api/user.go', 'api/team.js', 'api/package.json'];
|
||||
|
||||
const { defaultRoutes, redirectRoutes, rewriteRoutes } =
|
||||
const { defaultRoutes, redirectRoutes, rewriteRoutes, limitedRoutes } =
|
||||
await detectBuilders(files, null, options);
|
||||
testHeaders(redirectRoutes);
|
||||
expect(defaultRoutes).toStrictEqual([]);
|
||||
@@ -3088,6 +3128,28 @@ it('Test `detectRoutes` with `featHandleMiss=true`, `cleanUrls=true`, `trailingS
|
||||
},
|
||||
]);
|
||||
|
||||
// Limited routes should have js but not go since the go plugin is not installed
|
||||
expect(limitedRoutes).toStrictEqual({
|
||||
redirectRoutes: [
|
||||
{
|
||||
src: '^/(api(?:.+)?)/index(?:\\.(?:js))?/?$',
|
||||
headers: {
|
||||
Location: '/$1/',
|
||||
},
|
||||
status: 308,
|
||||
},
|
||||
{
|
||||
src: '^/api/(.+)(?:\\.(?:js))/?$',
|
||||
headers: {
|
||||
Location: '/api/$1/',
|
||||
},
|
||||
status: 308,
|
||||
},
|
||||
],
|
||||
rewriteRoutes: [],
|
||||
defaultRoutes: [],
|
||||
});
|
||||
|
||||
// expected redirect should match inputs
|
||||
const getLocation = createReplaceLocation(redirectRoutes);
|
||||
|
||||
|
||||
@@ -31,37 +31,6 @@ describe('convert-runtime-to-plugin', () => {
|
||||
await fs.remove(join(pythonApiWorkpath, '.output'));
|
||||
});
|
||||
|
||||
it('should error with invalid functions prop', async () => {
|
||||
const workPath = invalidFuncWorkpath;
|
||||
const lambdaOptions = {
|
||||
handler: 'index.handler',
|
||||
runtime: 'nodejs14.x',
|
||||
memory: 512,
|
||||
maxDuration: 5,
|
||||
environment: {},
|
||||
regions: ['sfo1'],
|
||||
};
|
||||
|
||||
const buildRuntime = async (opts: BuildOptions) => {
|
||||
const lambda = await createLambda({
|
||||
files: opts.files,
|
||||
...lambdaOptions,
|
||||
});
|
||||
return { output: lambda };
|
||||
};
|
||||
|
||||
const lambdaFiles = await fsToJson(workPath);
|
||||
const vercelConfig = JSON.parse(lambdaFiles['vercel.json']);
|
||||
delete lambdaFiles['vercel.json'];
|
||||
const build = await convertRuntimeToPlugin(buildRuntime, '.js');
|
||||
|
||||
expect(build({ vercelConfig, workPath })).rejects.toThrow(
|
||||
new Error(
|
||||
'The pattern "api/doesnt-exist.rb" defined in `functions` doesn\'t match any Serverless Functions inside the `api` directory.'
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('should create correct fileystem for python', async () => {
|
||||
const workPath = pythonApiWorkpath;
|
||||
const lambdaOptions = {
|
||||
@@ -70,7 +39,6 @@ describe('convert-runtime-to-plugin', () => {
|
||||
memory: 512,
|
||||
maxDuration: 5,
|
||||
environment: {},
|
||||
regions: ['sfo1'],
|
||||
};
|
||||
|
||||
const buildRuntime = async (opts: BuildOptions) => {
|
||||
@@ -91,7 +59,6 @@ describe('convert-runtime-to-plugin', () => {
|
||||
const output = await fsToJson(join(workPath, '.output'));
|
||||
expect(output).toMatchObject({
|
||||
'functions-manifest.json': expect.stringContaining('{'),
|
||||
'routes-manifest.json': expect.stringContaining('{'),
|
||||
'runtime-traced-files': lambdaFiles,
|
||||
server: {
|
||||
pages: {
|
||||
@@ -119,37 +86,6 @@ describe('convert-runtime-to-plugin', () => {
|
||||
},
|
||||
});
|
||||
|
||||
const routesManifest = JSON.parse(output['routes-manifest.json']);
|
||||
expect(routesManifest).toMatchObject({
|
||||
version: 3,
|
||||
pages404: true,
|
||||
redirects: [],
|
||||
rewrites: [
|
||||
/* TODO: `handle: miss`
|
||||
{
|
||||
source: "^/api/(.+)(?:\\.(?:py))$",
|
||||
destination: "/api/db/[id]?id=$1",
|
||||
regex: "^/api/(.+)(?:\\.(?:py))$"
|
||||
}
|
||||
*/
|
||||
],
|
||||
dynamicRoutes: [
|
||||
{
|
||||
page: '/api/project/[aid]/[bid]/index',
|
||||
regex: '^/api/project/([^/]+)/([^/]+)(/|/index|/index\\.py)?$',
|
||||
routeKeys: { aid: 'aid', bid: 'bid' },
|
||||
namedRegex:
|
||||
'^/api/project/(?<aid>[^/]+)/(?<bid>[^/]+)(/|/index|/index\\.py)?$',
|
||||
},
|
||||
{
|
||||
page: '/api/db/[id]',
|
||||
regex: '^/api/db/([^/]+)$',
|
||||
routeKeys: { id: 'id' },
|
||||
namedRegex: '^/api/db/(?<id>[^/]+)$',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const indexJson = JSON.parse(output.server.pages.api['index.py.nft.json']);
|
||||
expect(indexJson).toMatchObject({
|
||||
version: 1,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vercel",
|
||||
"version": "23.1.3-canary.40",
|
||||
"version": "23.1.3-canary.43",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Vercel",
|
||||
@@ -43,14 +43,14 @@
|
||||
"node": ">= 12"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.12.3-canary.22",
|
||||
"@vercel/build-utils": "2.12.3-canary.25",
|
||||
"@vercel/go": "1.2.4-canary.4",
|
||||
"@vercel/node": "1.12.2-canary.7",
|
||||
"@vercel/python": "2.1.2-canary.0",
|
||||
"@vercel/ruby": "1.2.8-canary.4",
|
||||
"update-notifier": "4.1.0",
|
||||
"vercel-plugin-middleware": "0.0.0-canary.7",
|
||||
"vercel-plugin-node": "1.12.2-canary.13"
|
||||
"vercel-plugin-node": "1.12.2-canary.16"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@next/env": "11.1.2",
|
||||
@@ -90,7 +90,7 @@
|
||||
"@types/update-notifier": "5.1.0",
|
||||
"@types/which": "1.3.2",
|
||||
"@types/write-json-file": "2.2.1",
|
||||
"@vercel/frameworks": "0.5.1-canary.13",
|
||||
"@vercel/frameworks": "0.5.1-canary.15",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/nft": "0.17.0",
|
||||
"@zeit/fun": "0.11.2",
|
||||
|
||||
@@ -14,7 +14,7 @@ import { assert } from 'console';
|
||||
import { createHash } from 'crypto';
|
||||
import fs from 'fs-extra';
|
||||
import ogGlob from 'glob';
|
||||
import { isAbsolute, join, parse, relative, resolve } from 'path';
|
||||
import { dirname, isAbsolute, join, parse, relative, resolve } from 'path';
|
||||
import pluralize from 'pluralize';
|
||||
import Client from '../util/client';
|
||||
import { VercelConfig } from '../util/dev/types';
|
||||
@@ -136,9 +136,11 @@ export default async function main(client: Client) {
|
||||
});
|
||||
|
||||
// Set process.env with loaded environment variables
|
||||
await processEnv(loadedEnvFiles);
|
||||
processEnv(loadedEnvFiles);
|
||||
|
||||
const spawnOpts = {
|
||||
const spawnOpts: {
|
||||
env: Record<string, string | undefined>;
|
||||
} = {
|
||||
env: { ...combinedEnv, VERCEL: '1' },
|
||||
};
|
||||
|
||||
@@ -284,6 +286,18 @@ export default async function main(client: Client) {
|
||||
// Clean the output directory
|
||||
fs.removeSync(join(cwd, OUTPUT_DIR));
|
||||
|
||||
if (framework && process.env.VERCEL_URL && 'envPrefix' in framework) {
|
||||
for (const key of Object.keys(process.env)) {
|
||||
if (key.startsWith('VERCEL_')) {
|
||||
const newKey = `${framework.envPrefix}${key}`;
|
||||
// Set `process.env` and `spawnOpts.env` to make sure the variables are
|
||||
// available to the `build` step and the CLI Plugins.
|
||||
process.env[newKey] = process.env[newKey] || process.env[key];
|
||||
spawnOpts.env[newKey] = process.env[newKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Yarn v2 PnP mode may be activated, so force
|
||||
// "node-modules" linker style
|
||||
const env = {
|
||||
@@ -315,22 +329,42 @@ export default async function main(client: Client) {
|
||||
cwd,
|
||||
});
|
||||
}
|
||||
// don't trust framework detection here because they might be switching to next on a branch
|
||||
const isNextJs = fs.existsSync(join(cwd, '.next'));
|
||||
|
||||
if (!fs.existsSync(join(cwd, OUTPUT_DIR))) {
|
||||
let outputDir = join(OUTPUT_DIR, 'static');
|
||||
let distDir = await framework.getFsOutputDir(cwd);
|
||||
if (isNextJs) {
|
||||
outputDir = OUTPUT_DIR;
|
||||
let dotNextDir: string | null = null;
|
||||
|
||||
// If a custom `outputDirectory` was set, we'll need to verify
|
||||
// if it's `.next` output, or just static output.
|
||||
const userOutputDirectory = project.settings.outputDirectory;
|
||||
|
||||
if (typeof userOutputDirectory === 'string') {
|
||||
if (fs.existsSync(join(cwd, userOutputDirectory, 'BUILD_ID'))) {
|
||||
dotNextDir = join(cwd, userOutputDirectory);
|
||||
client.output.debug(
|
||||
`Consider ${param(userOutputDirectory)} as ${param('.next')} output.`
|
||||
);
|
||||
}
|
||||
} else if (fs.existsSync(join(cwd, '.next'))) {
|
||||
dotNextDir = join(cwd, '.next');
|
||||
client.output.debug(`Found ${param('.next')} directory.`);
|
||||
}
|
||||
const copyStamp = stamp();
|
||||
|
||||
// We cannot rely on the `framework` alone, as it might be a static export,
|
||||
// and the current build might use a differnt project that's not in the settings.
|
||||
const isNextOutput = Boolean(dotNextDir);
|
||||
const outputDir = isNextOutput ? OUTPUT_DIR : join(OUTPUT_DIR, 'static');
|
||||
const distDir =
|
||||
dotNextDir ||
|
||||
userOutputDirectory ||
|
||||
(await framework.getFsOutputDir(cwd));
|
||||
|
||||
await fs.ensureDir(join(cwd, outputDir));
|
||||
const relativeDistDir = relative(cwd, distDir);
|
||||
|
||||
const copyStamp = stamp();
|
||||
client.output.spinner(
|
||||
`Copying files from ${param(distDir)} to ${param(outputDir)}`
|
||||
);
|
||||
const files = await glob(join(relativeDistDir, '**'), {
|
||||
const files = await glob(join(relative(cwd, distDir), '**'), {
|
||||
ignore: [
|
||||
'node_modules/**',
|
||||
'.vercel/**',
|
||||
@@ -378,6 +412,7 @@ export default async function main(client: Client) {
|
||||
`Generating build manifest: ${param(buildManifestPath)}`
|
||||
);
|
||||
const buildManifest = {
|
||||
version: 1,
|
||||
cache: framework.cachePattern ? [framework.cachePattern] : [],
|
||||
};
|
||||
await fs.writeJSON(buildManifestPath, buildManifest, { spaces: 2 });
|
||||
@@ -405,7 +440,7 @@ export default async function main(client: Client) {
|
||||
}
|
||||
|
||||
// Special Next.js processing.
|
||||
if (isNextJs) {
|
||||
if (isNextOutput) {
|
||||
// The contents of `.output/static` should be placed inside of `.output/static/_next/static`
|
||||
const tempStatic = '___static';
|
||||
await fs.rename(
|
||||
@@ -456,10 +491,12 @@ export default async function main(client: Client) {
|
||||
// `public`, then`static`). We can't read both at the same time because that would mean we'd
|
||||
// read public for old Next.js versions that don't support it, which might be breaking (and
|
||||
// we don't want to make vercel build specific framework versions).
|
||||
const nextSrcDirectory = dirname(distDir);
|
||||
|
||||
const publicFiles = await glob('public/**', {
|
||||
nodir: true,
|
||||
dot: true,
|
||||
cwd,
|
||||
cwd: nextSrcDirectory,
|
||||
absolute: true,
|
||||
});
|
||||
if (publicFiles.length > 0) {
|
||||
@@ -468,7 +505,11 @@ export default async function main(client: Client) {
|
||||
smartCopy(
|
||||
client,
|
||||
f,
|
||||
f.replace('public', join(OUTPUT_DIR, 'static'))
|
||||
join(
|
||||
OUTPUT_DIR,
|
||||
'static',
|
||||
relative(join(dirname(distDir), 'public'), f)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -476,7 +517,7 @@ export default async function main(client: Client) {
|
||||
const staticFiles = await glob('static/**', {
|
||||
nodir: true,
|
||||
dot: true,
|
||||
cwd,
|
||||
cwd: nextSrcDirectory,
|
||||
absolute: true,
|
||||
});
|
||||
await Promise.all(
|
||||
@@ -484,7 +525,12 @@ export default async function main(client: Client) {
|
||||
smartCopy(
|
||||
client,
|
||||
f,
|
||||
f.replace('static', join(OUTPUT_DIR, 'static', 'static'))
|
||||
join(
|
||||
OUTPUT_DIR,
|
||||
'static',
|
||||
'static',
|
||||
relative(join(dirname(distDir), 'static'), f)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -503,6 +549,7 @@ export default async function main(client: Client) {
|
||||
const nftFiles = await glob(join(OUTPUT_DIR, '**', '*.nft.json'), {
|
||||
nodir: true,
|
||||
dot: true,
|
||||
ignore: ['cache/**'],
|
||||
cwd,
|
||||
absolute: true,
|
||||
});
|
||||
@@ -539,6 +586,7 @@ export default async function main(client: Client) {
|
||||
baseDir,
|
||||
outputDir: OUTPUT_DIR,
|
||||
nftFileName: f.replace(ext, '.js.nft.json'),
|
||||
distDir,
|
||||
nft: {
|
||||
version: 1,
|
||||
files: Array.from(fileList).map(fileListEntry =>
|
||||
@@ -556,10 +604,12 @@ export default async function main(client: Client) {
|
||||
outputDir: OUTPUT_DIR,
|
||||
nftFileName: f,
|
||||
nft: json,
|
||||
distDir,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
client.output.debug(`Resolve ${param('required-server-files.json')}.`);
|
||||
const requiredServerFilesPath = join(
|
||||
OUTPUT_DIR,
|
||||
'required-server-files.json'
|
||||
@@ -571,11 +621,14 @@ export default async function main(client: Client) {
|
||||
...requiredServerFilesJson,
|
||||
appDir: '.',
|
||||
files: requiredServerFilesJson.files.map((i: string) => {
|
||||
const absolutePath = join(cwd, i.replace('.next', '.output'));
|
||||
const originalPath = join(dirname(distDir), i);
|
||||
const relPath = join(OUTPUT_DIR, relative(distDir, originalPath));
|
||||
|
||||
const absolutePath = join(cwd, relPath);
|
||||
const output = relative(baseDir, absolutePath);
|
||||
|
||||
return {
|
||||
input: i.replace('.next', '.output'),
|
||||
input: relPath,
|
||||
output,
|
||||
};
|
||||
}),
|
||||
@@ -758,24 +811,37 @@ async function resolveNftToOutput({
|
||||
baseDir,
|
||||
outputDir,
|
||||
nftFileName,
|
||||
distDir,
|
||||
nft,
|
||||
}: {
|
||||
client: Client;
|
||||
baseDir: string;
|
||||
outputDir: string;
|
||||
nftFileName: string;
|
||||
distDir: string;
|
||||
nft: NftFile;
|
||||
}) {
|
||||
client.output.debug(`Processing and resolving ${nftFileName}`);
|
||||
await fs.ensureDir(join(outputDir, 'inputs'));
|
||||
const newFilesList: NftFile['files'] = [];
|
||||
|
||||
// If `distDir` is a subdirectory, then the input has to be resolved to where the `.output` directory will be.
|
||||
const relNftFileName = relative(outputDir, nftFileName);
|
||||
const origNftFilename = join(distDir, relNftFileName);
|
||||
|
||||
if (relNftFileName.startsWith('cache/')) {
|
||||
// No need to process the `cache/` directory.
|
||||
// Paths in it might also not be relative to `cache` itself.
|
||||
return;
|
||||
}
|
||||
|
||||
for (let fileEntity of nft.files) {
|
||||
const relativeInput: string =
|
||||
const relativeInput =
|
||||
typeof fileEntity === 'string' ? fileEntity : fileEntity.input;
|
||||
const fullInput = resolve(join(parse(nftFileName).dir, relativeInput));
|
||||
const fullInput = resolve(join(parse(origNftFilename).dir, relativeInput));
|
||||
|
||||
// if the resolved path is NOT in the .output directory we move in it there
|
||||
if (!fullInput.includes(outputDir)) {
|
||||
if (!fullInput.includes(distDir)) {
|
||||
const { ext } = parse(fullInput);
|
||||
const raw = await fs.readFile(fullInput);
|
||||
const newFilePath = join(outputDir, 'inputs', hash(raw) + ext);
|
||||
|
||||
@@ -8,6 +8,7 @@ export type ProjectLinkAndSettings = ProjectLink & {
|
||||
buildCommand: Project['buildCommand'];
|
||||
devCommand: Project['devCommand'];
|
||||
outputDirectory: Project['outputDirectory'];
|
||||
directoryListing: Project['directoryListing'];
|
||||
rootDirectory: Project['rootDirectory'];
|
||||
framework: Project['framework'];
|
||||
};
|
||||
@@ -29,6 +30,7 @@ export async function writeProjectSettings(
|
||||
settings: {
|
||||
buildCommand: project.buildCommand,
|
||||
devCommand: project.devCommand,
|
||||
outputDirectory: project.outputDirectory,
|
||||
directoryListing: project.directoryListing,
|
||||
rootDirectory: project.rootDirectory,
|
||||
framework: project.framework,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/client",
|
||||
"version": "10.2.3-canary.23",
|
||||
"version": "10.2.3-canary.26",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"homepage": "https://vercel.com",
|
||||
@@ -40,7 +40,7 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.12.3-canary.22",
|
||||
"@vercel/build-utils": "2.12.3-canary.25",
|
||||
"@zeit/fetch": "5.2.0",
|
||||
"async-retry": "1.2.3",
|
||||
"async-sema": "3.0.0",
|
||||
|
||||
6
packages/frameworks/logos/remix-no-shadow.svg
Normal file
6
packages/frameworks/logos/remix-no-shadow.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg viewBox="0 0 800 800" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M700 0H100C44.772 0 0 44.772 0 100v600c0 55.228 44.772 100 100 100h600c55.228 0 100-44.772 100-100V100C800 44.772 755.228 0 700 0Z" fill="#212121"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M587.947 527.768c4.254 54.65 4.254 80.268 4.254 108.232H465.756c0-6.091.109-11.663.219-17.313.342-17.564.699-35.88-2.147-72.868-3.761-54.152-27.08-66.185-69.957-66.185H195v-98.525h204.889c54.16 0 81.241-16.476 81.241-60.098 0-38.357-27.081-61.601-81.241-61.601H195V163h227.456C545.069 163 606 220.912 606 313.42c0 69.193-42.877 114.319-100.799 121.84 48.895 9.777 77.48 37.605 82.746 92.508Z" fill="#fff"/>
|
||||
<path d="M195 636v-73.447h133.697c22.332 0 27.181 16.563 27.181 26.441V636H195Z" fill="#fff"/>
|
||||
<path d="M194.5 636v.5h161.878v-47.506c0-5.006-1.226-11.734-5.315-17.224-4.108-5.515-11.059-9.717-22.366-9.717H194.5V636Z" stroke="#fff" stroke-opacity=".8"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 958 B |
@@ -1,25 +0,0 @@
|
||||
<svg width="800" height="800" viewBox="0 0 800 800" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="800" height="800" fill="#212121"/>
|
||||
<g filter="url(#filter0_dd_126_53)">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M587.947 527.768C592.201 582.418 592.201 608.036 592.201 636H465.756C465.756 629.909 465.865 624.337 465.975 618.687C466.317 601.123 466.674 582.807 463.828 545.819C460.067 491.667 436.748 479.634 393.871 479.634H355.883H195V381.109H399.889C454.049 381.109 481.13 364.633 481.13 321.011C481.13 282.654 454.049 259.41 399.889 259.41H195V163H422.456C545.069 163 606 220.912 606 313.42C606 382.613 563.123 427.739 505.201 435.26C554.096 445.037 582.681 472.865 587.947 527.768Z" fill="#E8F2FF"/>
|
||||
<path d="M195 636V562.553H328.697C351.029 562.553 355.878 579.116 355.878 588.994V636H195Z" fill="#E8F2FF"/>
|
||||
</g>
|
||||
<defs>
|
||||
<filter id="filter0_dd_126_53" x="131" y="99" width="539" height="601" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
|
||||
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
|
||||
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
|
||||
<feOffset/>
|
||||
<feGaussianBlur stdDeviation="28"/>
|
||||
<feComposite in2="hardAlpha" operator="out"/>
|
||||
<feColorMatrix type="matrix" values="0 0 0 0 0.223529 0 0 0 0 0.572549 0 0 0 0 1 0 0 0 1 0"/>
|
||||
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_126_53"/>
|
||||
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
|
||||
<feOffset/>
|
||||
<feGaussianBlur stdDeviation="32"/>
|
||||
<feComposite in2="hardAlpha" operator="out"/>
|
||||
<feColorMatrix type="matrix" values="0 0 0 0 0.223529 0 0 0 0 0.572549 0 0 0 0 1 0 0 0 0.9 0"/>
|
||||
<feBlend mode="normal" in2="effect1_dropShadow_126_53" result="effect2_dropShadow_126_53"/>
|
||||
<feBlend mode="normal" in="SourceGraphic" in2="effect2_dropShadow_126_53" result="shape"/>
|
||||
</filter>
|
||||
</defs>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/frameworks",
|
||||
"version": "0.5.1-canary.13",
|
||||
"version": "0.5.1-canary.15",
|
||||
"main": "./dist/frameworks.js",
|
||||
"types": "./dist/frameworks.d.ts",
|
||||
"files": [
|
||||
|
||||
@@ -195,7 +195,7 @@ export const frameworks = [
|
||||
name: 'Remix',
|
||||
slug: 'remix',
|
||||
demo: 'https://remix.examples.vercel.com',
|
||||
logo: 'https://raw.githubusercontent.com/vercel/vercel/main/packages/frameworks/logos/remix.svg',
|
||||
logo: 'https://raw.githubusercontent.com/vercel/vercel/main/packages/frameworks/logos/remix-no-shadow.svg',
|
||||
tagline: 'Build Better Websites',
|
||||
description: 'A new Remix app — the result of running `npx create-remix`.',
|
||||
website: 'https://remix.run',
|
||||
@@ -251,8 +251,8 @@ export const frameworks = [
|
||||
],
|
||||
defaultHeaders: [
|
||||
{
|
||||
source: '^/build/(.*)$',
|
||||
regex: '^/build/(.*)$',
|
||||
source: '/build/(.*)',
|
||||
regex: '/build/(.*)',
|
||||
headers: [
|
||||
{ key: 'cache-control', value: 'public, max-age=31536000, immutable' },
|
||||
],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "vercel-plugin-go",
|
||||
"version": "1.0.0-canary.7",
|
||||
"version": "1.0.0-canary.10",
|
||||
"main": "dist/index.js",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
@@ -17,7 +17,7 @@
|
||||
"prepublishOnly": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.12.3-canary.22",
|
||||
"@vercel/build-utils": "2.12.3-canary.25",
|
||||
"@vercel/go": "1.2.4-canary.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vercel-plugin-node",
|
||||
"version": "1.12.2-canary.13",
|
||||
"version": "1.12.2-canary.16",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
||||
@@ -34,7 +34,7 @@
|
||||
"@types/node-fetch": "2",
|
||||
"@types/test-listen": "1.1.0",
|
||||
"@types/yazl": "2.4.2",
|
||||
"@vercel/build-utils": "2.12.3-canary.22",
|
||||
"@vercel/build-utils": "2.12.3-canary.25",
|
||||
"@vercel/fun": "1.0.3",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@vercel/nft": "0.14.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "vercel-plugin-python",
|
||||
"version": "1.0.0-canary.8",
|
||||
"version": "1.0.0-canary.11",
|
||||
"main": "dist/index.js",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
@@ -17,7 +17,7 @@
|
||||
"prepublishOnly": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.12.3-canary.22",
|
||||
"@vercel/build-utils": "2.12.3-canary.25",
|
||||
"@vercel/python": "2.1.2-canary.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": false,
|
||||
"name": "vercel-plugin-ruby",
|
||||
"version": "1.0.0-canary.6",
|
||||
"version": "1.0.0-canary.9",
|
||||
"main": "dist/index.js",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
@@ -17,7 +17,7 @@
|
||||
"prepublishOnly": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.12.3-canary.22",
|
||||
"@vercel/build-utils": "2.12.3-canary.25",
|
||||
"@vercel/ruby": "1.2.8-canary.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user