Compare commits

..

5 Commits

Author SHA1 Message Date
Andy Bitz
a2c56425f4 Publish Stable
- @vercel/static-build@0.17.12
2020-11-10 00:43:05 +01:00
Andy Bitz
c759bfda9c Publish Canary
- @vercel/client@9.0.4-canary.3
 - @vercel/static-build@0.17.12-canary.0
2020-11-10 00:14:31 +01:00
Andy
57995001ac [static-build] Add directory for Serverless Functions (#5390)
* [@vercel/static-build] Add directory for Serverless Functions

* Update tests and only consider index.js files

* Import only once

* Only change for zeroConfig

* Update packages/now-static-build/src/utils/_shared.ts

Co-authored-by: Steven <steven@ceriously.com>

* Update packages/now-static-build/test/fixtures/62-function-output-directory-with-static/now.json

Co-authored-by: Steven <steven@ceriously.com>

* Update packages/now-static-build/test/fixtures/61-function-output-directory/now.json

Co-authored-by: Steven <steven@ceriously.com>

* Update build

* Fix type

* Remove line

* Add to .vercelignore

* Fix paths in test

* Move more files

* Remove special case for test

Co-authored-by: Steven <steven@ceriously.com>
2020-11-10 00:09:23 +01:00
Nathan Rajlich
e5553d8ec2 Publish Canary
- @vercel/build-utils@2.5.5-canary.2
 - vercel@20.1.3-canary.6
 - @vercel/client@9.0.4-canary.2
2020-11-09 15:02:17 -08:00
Nathan Rajlich
dcee5b16c7 [build-utils] Add installCommand to Config object (#5391) 2020-11-09 22:27:29 +00:00
27 changed files with 207 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/build-utils",
"version": "2.5.5-canary.1",
"version": "2.5.5-canary.2",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.js",

View File

@@ -24,6 +24,7 @@ interface Options {
projectSettings?: {
framework?: string | null;
devCommand?: string | null;
installCommand?: string | null;
buildCommand?: string | null;
outputDirectory?: string | null;
createdAt?: number;
@@ -450,6 +451,10 @@ function detectFrontBuilder(
config.devCommand = projectSettings.devCommand;
}
if (projectSettings.installCommand) {
config.installCommand = projectSettings.installCommand;
}
if (projectSettings.buildCommand) {
config.buildCommand = projectSettings.buildCommand;
}

View File

@@ -41,6 +41,7 @@ export interface Config {
import?: { [key: string]: string };
functions?: BuilderFunctions;
outputDirectory?: string;
installCommand?: string;
buildCommand?: string;
devCommand?: string;
framework?: string;

View File

@@ -1,6 +1,6 @@
{
"name": "vercel",
"version": "20.1.3-canary.5",
"version": "20.1.3-canary.6",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Vercel",
@@ -61,7 +61,7 @@
"node": ">= 10"
},
"dependencies": {
"@vercel/build-utils": "2.5.5-canary.1",
"@vercel/build-utils": "2.5.5-canary.2",
"@vercel/go": "1.1.6",
"@vercel/node": "1.8.4",
"@vercel/python": "1.2.3",

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/client",
"version": "9.0.4-canary.1",
"version": "9.0.4-canary.3",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"homepage": "https://vercel.com",
@@ -37,7 +37,7 @@
]
},
"dependencies": {
"@vercel/build-utils": "2.5.5-canary.1",
"@vercel/build-utils": "2.5.5-canary.2",
"@zeit/fetch": "5.2.0",
"async-retry": "1.2.3",
"async-sema": "3.0.0",

View File

@@ -136,6 +136,7 @@ export async function getVercelIgnore(
'__pycache__',
'venv',
'CVS',
'.vercel_build_output',
];
const cwds = Array.isArray(cwd) ? cwd : [cwd];

View File

@@ -3,3 +3,6 @@ dist/
# bypass all ignored files for the cache fixtures
# because they contain node_modules and package-lock.json files
!test/cache-fixtures/**
/src/bridge.ts
/src/launcher.ts

View File

@@ -1,8 +1,17 @@
#!/bin/bash
set -euo pipefail
# Copy shared dependencies
bridge_defs="$(dirname $(pwd))/now-node-bridge/src/bridge.ts"
launcher_defs="$(dirname $(pwd))/now-node/src/launcher.ts"
cp -v "$bridge_defs" src
cp -v "$launcher_defs" src
# Start fresh
rm -rf dist
tsc
# Build with `ncc`
ncc build src/index.ts -e @vercel/build-utils -e @now/build-utils -o dist

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/static-build",
"version": "0.17.11",
"version": "0.17.12",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://vercel.com/docs/build-step",
@@ -19,6 +19,7 @@
"prepublishOnly": "./build.sh"
},
"devDependencies": {
"@types/aws-lambda": "8.10.64",
"@types/cross-spawn": "6.0.0",
"@types/ms": "0.7.31",
"@types/node-fetch": "2.5.4",

View File

@@ -33,6 +33,7 @@ const {
NowBuildError,
} = buildUtils;
import { Route, Source } from '@vercel/routing-utils';
import { readBuildOutputDirectory } from './utils/_shared';
import * as GatsbyUtils from './utils/gatsby';
const sleep = (n: number) => new Promise(resolve => setTimeout(resolve, n));
@@ -489,7 +490,12 @@ export async function build({
}
}
validateDistDir(distPath);
const extraOutputs = await readBuildOutputDirectory({ workPath });
// No need to verify the dist dir if there are other output files.
if (!Object.keys(extraOutputs.output).length) {
validateDistDir(distPath);
}
if (framework) {
const frameworkRoutes = await getFrameworkRoutes(
@@ -514,6 +520,7 @@ export async function build({
debug(`Using ignore: ${JSON.stringify(ignore)}`);
}
output = await glob('**', { cwd: distPath, ignore }, mountpoint);
Object.assign(output, extraOutputs.output);
}
const watch = [path.join(mountpoint.replace(/^\.\/?/, ''), '**/*')];

View File

@@ -1,6 +1,10 @@
import { PackageJson } from '@vercel/build-utils';
import { constants, PathLike, promises as fs } from 'fs';
import * as path from 'path';
import { FileBlob, Files, Lambda, PackageJson } from '@vercel/build-utils';
import { makeNowLauncher } from '../launcher';
import buildUtils from '../build-utils';
import path from 'path';
const { createLambda, debug, getLatestNodeVersion, glob } = buildUtils;
export type DeepWriteable<T> = {
-readonly [P in keyof T]: DeepWriteable<T[P]>;
@@ -38,3 +42,74 @@ export async function writePackageJson(
JSON.stringify(packageJson, null, 2)
);
}
/**
* Reads the .vercel_build_output directory and returns and object
* that should be merged with the build outputs.
*
* At the moment only `functions/node` is supported.
*/
export async function readBuildOutputDirectory({
workPath,
}: {
workPath: string;
}) {
const output: { [key: string]: Lambda } = {};
const nodeFunctionPath = path.join(
workPath,
'.vercel_build_output',
'functions',
'node'
);
const nodeFunctionFiles = await glob('**/index.js', {
cwd: nodeFunctionPath,
});
const nodeBridgeData = await fs.readFile(path.join(__dirname, 'bridge.js'));
for (const fileName of Object.keys(nodeFunctionFiles)) {
const launcherFileName = '___now_launcher';
const bridgeFileName = '___now_bridge';
const launcherFiles: Files = {
[`${launcherFileName}.js`]: new FileBlob({
data: makeNowLauncher({
entrypointPath: `./index.js`,
bridgePath: `./${bridgeFileName}`,
helpersPath: '',
sourcemapSupportPath: '',
shouldAddHelpers: false,
shouldAddSourcemapSupport: false,
}),
}),
[`${bridgeFileName}.js`]: new FileBlob({
data: nodeBridgeData,
}),
};
const requiredFiles = await glob('**', {
cwd: path.join(nodeFunctionPath, path.dirname(fileName)),
});
const lambda = await createLambda({
files: {
...requiredFiles,
...launcherFiles,
},
handler: `${launcherFileName}.launcher`,
runtime: getLatestNodeVersion().runtime,
});
const parsed = path.parse(fileName);
const newPath = path.join(parsed.dir, parsed.name);
output[newPath] = lambda;
debug(
`Created Lambda "${newPath}" from "${path.join(
nodeFunctionPath,
fileName
)}".`
);
}
return { output };
}

View File

@@ -0,0 +1 @@
.vercel_build_output/functions/node

View File

@@ -0,0 +1,22 @@
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@vercel/static-build",
"config": { "zeroConfig": true }
}
],
"probes": [
{ "path": "/", "mustContain": "Hello from /index.js on /" },
{
"path": "/about",
"mustContain": "Hello from /about/index.js on /about - Milkshake"
},
{
"path": "/products/product",
"mustContain": "Hello from /products/product/index.js on /products/product"
},
{ "path": "/about/util", "status": 404 }
]
}

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"build": "mkdir -p .vercel_build_output/functions/node && cp -r src/* .vercel_build_output/functions/node"
}
}

View File

@@ -0,0 +1,5 @@
const { getAbout } = require('./util');
module.exports = async function (req, res) {
return res.end(`Hello from /about/index.js on ${req.url} - ${getAbout()}`);
};

View File

@@ -0,0 +1,5 @@
module.exports = {
getAbout() {
return 'Milkshake';
},
};

View File

@@ -0,0 +1,3 @@
module.exports = async function (req, res) {
return res.end(`Hello from /index.js on ${req.url}`);
};

View File

@@ -0,0 +1,3 @@
module.exports = async function (req, res) {
return res.end(`Hello from /products/product/index.js on ${req.url}`);
};

View File

@@ -0,0 +1 @@
.vercel_build_output/functions/node

View File

@@ -0,0 +1,23 @@
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@vercel/static-build",
"config": { "zeroConfig": true }
}
],
"probes": [
{ "path": "/static.txt", "mustContain": "Hello from a static file." },
{ "path": "/", "mustContain": "Hello from /index.js on /" },
{
"path": "/about",
"mustContain": "Hello from /about/index.js on /about - Milkshake"
},
{
"path": "/products/product",
"mustContain": "Hello from /products/product/index.js on /products/product"
},
{ "path": "/about/util", "status": 404 }
]
}

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"build": "mkdir -p public && echo 'Hello from a static file.' > public/static.txt && mkdir -p .vercel_build_output/functions/node && cp -r src/* .vercel_build_output/functions/node"
}
}

View File

@@ -0,0 +1,5 @@
const { getAbout } = require('./util');
module.exports = async function (req, res) {
return res.end(`Hello from /about/index.js on ${req.url} - ${getAbout()}`);
};

View File

@@ -0,0 +1,5 @@
module.exports = {
getAbout() {
return 'Milkshake';
},
};

View File

@@ -0,0 +1,3 @@
module.exports = async function (req, res) {
return res.end(`Hello from /index.js on ${req.url}`);
};

View File

@@ -0,0 +1,3 @@
module.exports = async function (req, res) {
return res.end(`Hello from /products/product/index.js on ${req.url}`);
};

View File

@@ -15,7 +15,6 @@
"strict": true,
"target": "esnext"
},
"exclude": [
"test/fixtures"
]
"include": ["src/**/*"],
"exclude": ["test/fixtures"]
}

View File

@@ -1607,6 +1607,11 @@
resolved "https://registry.yarnpkg.com/@types/aws-lambda/-/aws-lambda-8.10.19.tgz#913a8016a4599d262960d97cb11faf7e963ec0e1"
integrity sha512-dEhQow/1awGGIf/unEpb97vsTtnQ3qRPAhSmZZcXKzs4nOVbIuWo5LCCzOYdSIkGkkoFXVvc8pBaSVKRYIFUBA==
"@types/aws-lambda@8.10.64":
version "8.10.64"
resolved "https://registry.yarnpkg.com/@types/aws-lambda/-/aws-lambda-8.10.64.tgz#4bdcb725aef96bef0cb1decf19c7efff1df22fe7"
integrity sha512-LRKk2UQCSi7BsO5TlfSI8cTNpOGz+MH6+RXEWtuZmxJficQgxwEYJDiKVirzgyiHce0L0F4CqCVvKTwblAeOUw==
"@types/babel__core@^7.1.0":
version "7.1.8"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.8.tgz#057f725aca3641f49fc11c7a87a9de5ec588a5d7"