mirror of
https://github.com/LukeHagar/vercel.git
synced 2026-01-01 04:09:15 +00:00
Compare commits
14 Commits
@now/node@
...
@now/node-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2f91094bc | ||
|
|
38dba57378 | ||
|
|
be6a6ba1d7 | ||
|
|
31fb5d9ec8 | ||
|
|
6c8f946a48 | ||
|
|
d59e1b9789 | ||
|
|
2852d3fbc3 | ||
|
|
d0292eb751 | ||
|
|
17bbf69346 | ||
|
|
4fb4229c90 | ||
|
|
03b7586b50 | ||
|
|
a1427866ca | ||
|
|
5f787b8146 | ||
|
|
b03405a665 |
@@ -1,10 +1,13 @@
|
||||
const execa = require('execa');
|
||||
const { join } = require('path');
|
||||
const snakeCase = require('snake-case');
|
||||
const glob = require('@now/build-utils/fs/glob'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const download = require('@now/build-utils/fs/download'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { createLambda } = require('@now/build-utils/lambda'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const getWritableDirectory = require('@now/build-utils/fs/get-writable-directory'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const {
|
||||
glob,
|
||||
download,
|
||||
createLambda,
|
||||
getWriteableDirectory,
|
||||
shouldServe,
|
||||
} = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
exports.config = {
|
||||
maxLambdaSize: '10mb',
|
||||
@@ -15,7 +18,7 @@ exports.analyze = ({ files, entrypoint }) => files[entrypoint].digest;
|
||||
exports.build = async ({
|
||||
workPath, files, entrypoint, config,
|
||||
}) => {
|
||||
const srcDir = await getWritableDirectory();
|
||||
const srcDir = await getWriteableDirectory();
|
||||
|
||||
console.log('downloading files...');
|
||||
await download(files, srcDir);
|
||||
@@ -55,3 +58,5 @@ exports.build = async ({
|
||||
[entrypoint]: lambda,
|
||||
};
|
||||
};
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/bash",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.3",
|
||||
"description": "Now 2.0 builder for HTTP endpoints written in Bash",
|
||||
"main": "index.js",
|
||||
"author": "Nathan Rajlich <nate@zeit.co>",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/build-utils",
|
||||
"version": "0.5.2-canary.0",
|
||||
"version": "0.5.4",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
|
||||
@@ -8,7 +8,6 @@ import { File } from './types';
|
||||
interface FileRefOptions {
|
||||
mode?: number;
|
||||
digest: string;
|
||||
mutable?: boolean;
|
||||
}
|
||||
|
||||
const semaToDownloadFromS3 = new Sema(5);
|
||||
@@ -26,26 +25,29 @@ export default class FileRef implements File {
|
||||
public type: 'FileRef';
|
||||
public mode: number;
|
||||
public digest: string;
|
||||
public mutable: boolean;
|
||||
|
||||
constructor({ mode = 0o100644, digest, mutable = false }: FileRefOptions) {
|
||||
constructor({ mode = 0o100644, digest }: FileRefOptions) {
|
||||
assert(typeof mode === 'number');
|
||||
assert(typeof digest === 'string');
|
||||
assert(typeof mutable === 'boolean');
|
||||
this.type = 'FileRef';
|
||||
this.mode = mode;
|
||||
this.digest = digest;
|
||||
this.mutable = mutable;
|
||||
}
|
||||
|
||||
async toStreamAsync(): Promise<NodeJS.ReadableStream> {
|
||||
let url = '';
|
||||
// sha:24be087eef9fac01d61b30a725c1a10d7b45a256
|
||||
const digestParts = this.digest.split(':');
|
||||
if (digestParts[0] === 'sha') {
|
||||
url = this.mutable
|
||||
? `https://s3.amazonaws.com/now-files/${digestParts[1]}`
|
||||
: `https://dmmcy0pwk6bqi.cloudfront.net/${digestParts[1]}`;
|
||||
const [digestType, digestHash] = this.digest.split(':');
|
||||
if (digestType === 'sha') {
|
||||
// This CloudFront URL edge caches the `now-files` S3 bucket to prevent
|
||||
// overloading it
|
||||
// `https://now-files.s3.amazonaws.com/${digestHash}`
|
||||
url = `https://dmmcy0pwk6bqi.cloudfront.net/${digestHash}`;
|
||||
} else if (digestType === 'sha+ephemeral') {
|
||||
// This URL is currently only used for cache files that constantly
|
||||
// change. We shouldn't cache it on CloudFront because it'd always be a
|
||||
// MISS.
|
||||
url = `https://now-ephemeral-files.s3.amazonaws.com/${digestHash}`;
|
||||
} else {
|
||||
throw new Error('Expected digest to be sha');
|
||||
}
|
||||
@@ -58,14 +60,14 @@ export default class FileRef implements File {
|
||||
const resp = await fetch(url);
|
||||
if (!resp.ok) {
|
||||
const error = new BailableError(
|
||||
`download: ${resp.status} ${resp.statusText} for ${url}`,
|
||||
`download: ${resp.status} ${resp.statusText} for ${url}`
|
||||
);
|
||||
if (resp.status === 403) error.bail = true;
|
||||
throw error;
|
||||
}
|
||||
return resp.body;
|
||||
},
|
||||
{ factor: 1, retries: 3 },
|
||||
{ factor: 1, retries: 3 }
|
||||
);
|
||||
} finally {
|
||||
// console.timeEnd(`downloading ${url}`);
|
||||
@@ -77,15 +79,15 @@ export default class FileRef implements File {
|
||||
let flag = false;
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
return multiStream((cb) => {
|
||||
return multiStream(cb => {
|
||||
if (flag) return cb(null, null);
|
||||
flag = true;
|
||||
|
||||
this.toStreamAsync()
|
||||
.then((stream) => {
|
||||
.then(stream => {
|
||||
cb(null, stream);
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
cb(error, null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -116,7 +116,7 @@ export async function installDependencies(
|
||||
} else {
|
||||
await spawnAsync(
|
||||
'yarn',
|
||||
['--cwd', destPath].concat(commandArgs),
|
||||
['--ignore-engines', '--cwd', destPath].concat(commandArgs),
|
||||
destPath,
|
||||
opts as SpawnOptions
|
||||
);
|
||||
|
||||
9
packages/now-build-utils/test/fixtures/15-yarn-ignore-engines/index.js
vendored
Normal file
9
packages/now-build-utils/test/fixtures/15-yarn-ignore-engines/index.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
const scheduler = require('@google-cloud/scheduler');
|
||||
|
||||
module.exports = (_, res) => {
|
||||
if (scheduler) {
|
||||
res.end('found:RANDOMNESS_PLACEHOLDER');
|
||||
} else {
|
||||
res.end('nope:RANDOMNESS_PLACEHOLDER');
|
||||
}
|
||||
};
|
||||
10
packages/now-build-utils/test/fixtures/15-yarn-ignore-engines/now.json
vendored
Normal file
10
packages/now-build-utils/test/fixtures/15-yarn-ignore-engines/now.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{ "src": "index.js", "use": "@now/node", "config": { "maxLambdaSize": "15mb" } }
|
||||
],
|
||||
"probes": [
|
||||
{ "path": "/", "mustContain": "found:RANDOMNESS_PLACEHOLDER" }
|
||||
]
|
||||
}
|
||||
|
||||
8
packages/now-build-utils/test/fixtures/15-yarn-ignore-engines/package.json
vendored
Normal file
8
packages/now-build-utils/test/fixtures/15-yarn-ignore-engines/package.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "15-yarn-ignore-engines",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@google-cloud/scheduler": "0.3.0"
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ const glob = require('@now/build-utils/fs/glob'); // eslint-disable-line import/
|
||||
const download = require('@now/build-utils/fs/download'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { createLambda } = require('@now/build-utils/lambda'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const getWritableDirectory = require('@now/build-utils/fs/get-writable-directory'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { shouldServe } = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
exports.analyze = ({ files, entrypoint }) => files[entrypoint].digest;
|
||||
|
||||
@@ -40,3 +41,5 @@ exports.build = async ({ files, entrypoint }) => {
|
||||
[entrypoint]: lambda,
|
||||
};
|
||||
};
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/cgi",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -3,6 +3,7 @@ import execa from 'execa';
|
||||
import fetch from 'node-fetch';
|
||||
import { mkdirp, pathExists } from 'fs-extra';
|
||||
import { dirname, join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import Debug from 'debug';
|
||||
|
||||
const debug = Debug('@now/go:go-helpers');
|
||||
@@ -118,16 +119,25 @@ export async function downloadGo(
|
||||
platform = process.platform,
|
||||
arch = process.arch
|
||||
) {
|
||||
debug('Installing `go` v%s to %o for %s %s', version, dir, platform, arch);
|
||||
// Check default `Go` in user machine
|
||||
const isUserGo = await pathExists(join(homedir(), 'go'));
|
||||
|
||||
const url = getGoUrl(version, platform, arch);
|
||||
|
||||
// if we found GOPATH in ENV, use it
|
||||
if (process.env.GOPATH !== undefined) {
|
||||
// If we found GOPATH in ENV, or default `Go` path exists
|
||||
// asssume that user have `Go` installed
|
||||
if (isUserGo || process.env.GOPATH !== undefined) {
|
||||
return createGo(dir, platform, arch);
|
||||
} else {
|
||||
// Check `Go` bin in builder CWD
|
||||
const isGoExist = await pathExists(join(dir, 'bin'));
|
||||
if (!isGoExist) {
|
||||
debug(
|
||||
'Installing `go` v%s to %o for %s %s',
|
||||
version,
|
||||
dir,
|
||||
platform,
|
||||
arch
|
||||
);
|
||||
const url = getGoUrl(version, platform, arch);
|
||||
debug('Downloading `go` URL: %o', url);
|
||||
console.log('Downloading Go ...');
|
||||
const res = await fetch(url);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/go",
|
||||
"version": "0.4.3-canary.0",
|
||||
"version": "0.4.5",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const FileBlob = require('@now/build-utils/file-blob.js'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { FileBlob, shouldServe } = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { minify } = require('html-minifier');
|
||||
|
||||
const defaultOptions = {
|
||||
@@ -28,3 +28,5 @@ exports.build = async ({ files, entrypoint, config }) => {
|
||||
|
||||
return { [entrypoint]: result };
|
||||
};
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/html-minifier",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { Lambda } = require('@now/build-utils/lambda.js'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const streamToBuffer = require('@now/build-utils/fs/stream-to-buffer.js'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { shouldServe } = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
exports.build = async ({ files, entrypoint, config }) => {
|
||||
if (!files[entrypoint]) throw new Error('Entrypoint not found in files');
|
||||
@@ -10,3 +11,5 @@ exports.build = async ({ files, entrypoint, config }) => {
|
||||
const lambda = new Lambda({ zipBuffer, handler, runtime });
|
||||
return { [entrypoint]: lambda };
|
||||
};
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/lambda",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const FileBlob = require('@now/build-utils/file-blob.js'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { FileBlob, shouldServe } = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const unified = require('unified');
|
||||
const unifiedStream = require('unified-stream');
|
||||
const markdown = require('remark-parse');
|
||||
@@ -38,3 +38,5 @@ exports.build = async ({ files, entrypoint, config }) => {
|
||||
|
||||
return { [replacedEntrypoint]: result };
|
||||
};
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/md",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/mdx-deck",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/next",
|
||||
"version": "0.2.1-canary.0",
|
||||
"version": "0.3.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"scripts": {
|
||||
@@ -14,7 +14,7 @@
|
||||
"directory": "packages/now-next"
|
||||
},
|
||||
"dependencies": {
|
||||
"@now/node-bridge": "^1.1.0",
|
||||
"@now/node-bridge": "^1.1.2",
|
||||
"fs-extra": "^7.0.0",
|
||||
"get-port": "^5.0.0",
|
||||
"resolve-from": "^5.0.0",
|
||||
|
||||
@@ -2,6 +2,13 @@ import resolveFrom from 'resolve-from';
|
||||
import { parse } from 'url';
|
||||
import getPort from 'get-port';
|
||||
import { createServer } from 'http';
|
||||
import { syncEnvVars } from './utils';
|
||||
|
||||
process.on('unhandledRejection', err => {
|
||||
console.error('Exiting builder due to build error:');
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
async function main(cwd: string) {
|
||||
const next = require(resolveFrom(cwd, 'next'));
|
||||
@@ -17,6 +24,13 @@ async function main(cwd: string) {
|
||||
// Prepare for incoming requests
|
||||
await app.prepare();
|
||||
|
||||
// The runtime env vars are passed in to `argv[2]`
|
||||
// as a base64-encoded JSON string
|
||||
const runtimeEnv = JSON.parse(
|
||||
Buffer.from(process.argv[2], 'base64').toString()
|
||||
);
|
||||
syncEnvVars(process.env, process.env, runtimeEnv);
|
||||
|
||||
createServer((req, res) => {
|
||||
const parsedUrl = parse(req.url || '', true);
|
||||
handler(req, res, parsedUrl);
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
|
||||
import nextLegacyVersions from './legacy-versions';
|
||||
import {
|
||||
EnvConfig,
|
||||
excludeFiles,
|
||||
getNextConfig,
|
||||
getPathsInside,
|
||||
@@ -33,11 +34,14 @@ import {
|
||||
normalizePackageJson,
|
||||
onlyStaticDirectory,
|
||||
stringMap,
|
||||
syncEnvVars,
|
||||
validateEntrypoint,
|
||||
} from './utils';
|
||||
|
||||
interface BuildParamsMeta {
|
||||
isDev: boolean | undefined;
|
||||
env?: EnvConfig;
|
||||
buildEnv?: EnvConfig;
|
||||
}
|
||||
|
||||
interface BuildParamsType extends BuildOptions {
|
||||
@@ -119,10 +123,15 @@ function isLegacyNext(nextVersion: string) {
|
||||
const name = '[@now/next]';
|
||||
const urls: stringMap = {};
|
||||
|
||||
function startDevServer(entryPath: string) {
|
||||
function startDevServer(entryPath: string, runtimeEnv: EnvConfig) {
|
||||
// The runtime env vars are encoded and passed in as `argv[2]`, so that the
|
||||
// dev-server process can replace them onto `process.env` after the Next.js
|
||||
// "prepare" step
|
||||
const encodedEnv = Buffer.from(JSON.stringify(runtimeEnv)).toString('base64');
|
||||
|
||||
// `env` is omitted since that
|
||||
// makes it default to `process.env`
|
||||
const forked = fork(path.join(__dirname, 'dev-server.js'), [], {
|
||||
const forked = fork(path.join(__dirname, 'dev-server.js'), [encodedEnv], {
|
||||
cwd: entryPath,
|
||||
execArgv: [],
|
||||
});
|
||||
@@ -181,7 +190,13 @@ export const build = async ({
|
||||
if (!urls[entrypoint]) {
|
||||
console.log(`${name} Installing dependencies...`);
|
||||
await runNpmInstall(entryPath, ['--prefer-offline']);
|
||||
const { forked, getUrl } = startDevServer(entryPath);
|
||||
|
||||
// The runtime env vars consist of the base `process.env` vars, but with the
|
||||
// build env vars removed, and the runtime env vars mixed in afterwards
|
||||
const runtimeEnv: EnvConfig = Object.assign({}, process.env);
|
||||
syncEnvVars(runtimeEnv, meta.buildEnv || {}, meta.env || {});
|
||||
|
||||
const { forked, getUrl } = startDevServer(entryPath, runtimeEnv);
|
||||
urls[entrypoint] = await getUrl();
|
||||
childProcess = forked;
|
||||
console.log(
|
||||
|
||||
@@ -2,18 +2,22 @@ import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { Files } from '@now/build-utils';
|
||||
|
||||
type stringMap = {[key: string]: string};
|
||||
type stringMap = { [key: string]: string };
|
||||
|
||||
export interface EnvConfig {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if the entrypoint is allowed to be used
|
||||
*/
|
||||
function validateEntrypoint(entrypoint: string) {
|
||||
if (
|
||||
!/package\.json$/.exec(entrypoint)
|
||||
&& !/next\.config\.js$/.exec(entrypoint)
|
||||
!/package\.json$/.exec(entrypoint) &&
|
||||
!/next\.config\.js$/.exec(entrypoint)
|
||||
) {
|
||||
throw new Error(
|
||||
'Specified "src" for "@now/next" has to be "package.json" or "next.config.js"',
|
||||
'Specified "src" for "@now/next" has to be "package.json" or "next.config.js"'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +25,10 @@ function validateEntrypoint(entrypoint: string) {
|
||||
/**
|
||||
* Exclude certain files from the files object
|
||||
*/
|
||||
function excludeFiles(files: Files, matcher: (filePath: string) => boolean): Files {
|
||||
function excludeFiles(
|
||||
files: Files,
|
||||
matcher: (filePath: string) => boolean
|
||||
): Files {
|
||||
return Object.keys(files).reduce((newFiles, filePath) => {
|
||||
if (matcher(filePath)) {
|
||||
return newFiles;
|
||||
@@ -36,7 +43,10 @@ function excludeFiles(files: Files, matcher: (filePath: string) => boolean): Fil
|
||||
/**
|
||||
* Creates a new Files object holding only the entrypoint files
|
||||
*/
|
||||
function includeOnlyEntryDirectory(files: Files, entryDirectory: string): Files {
|
||||
function includeOnlyEntryDirectory(
|
||||
files: Files,
|
||||
entryDirectory: string
|
||||
): Files {
|
||||
if (entryDirectory === '.') {
|
||||
return files;
|
||||
}
|
||||
@@ -76,7 +86,13 @@ function onlyStaticDirectory(files: Files, entryDir: string): Files {
|
||||
/**
|
||||
* Enforce specific package.json configuration for smallest possible lambda
|
||||
*/
|
||||
function normalizePackageJson(defaultPackageJson: {dependencies?: stringMap, devDependencies?: stringMap, scripts?: stringMap} = {}) {
|
||||
function normalizePackageJson(
|
||||
defaultPackageJson: {
|
||||
dependencies?: stringMap;
|
||||
devDependencies?: stringMap;
|
||||
scripts?: stringMap;
|
||||
} = {}
|
||||
) {
|
||||
const dependencies: stringMap = {};
|
||||
const devDependencies: stringMap = {
|
||||
...defaultPackageJson.dependencies,
|
||||
@@ -112,7 +128,8 @@ function normalizePackageJson(defaultPackageJson: {dependencies?: stringMap, dev
|
||||
},
|
||||
scripts: {
|
||||
...defaultPackageJson.scripts,
|
||||
'now-build': 'NODE_OPTIONS=--max_old_space_size=3000 next build --lambdas',
|
||||
'now-build':
|
||||
'NODE_OPTIONS=--max_old_space_size=3000 next build --lambdas',
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -151,7 +168,12 @@ function getPathsInside(entryDirectory: string, files: Files) {
|
||||
return watch;
|
||||
}
|
||||
|
||||
function getRoutes(entryDirectory: string, pathsInside: string[], files: Files, url: string): any[] {
|
||||
function getRoutes(
|
||||
entryDirectory: string,
|
||||
pathsInside: string[],
|
||||
files: Files,
|
||||
url: string
|
||||
): any[] {
|
||||
const filesInside: Files = {};
|
||||
const prefix = entryDirectory === `.` ? `/` : `/${entryDirectory}/`;
|
||||
|
||||
@@ -166,12 +188,12 @@ function getRoutes(entryDirectory: string, pathsInside: string[], files: Files,
|
||||
const routes: any[] = [
|
||||
{
|
||||
src: `${prefix}_next/(.*)`,
|
||||
dest: `${url}/_next/$1`
|
||||
dest: `${url}/_next/$1`,
|
||||
},
|
||||
{
|
||||
src: `${prefix}static/(.*)`,
|
||||
dest: `${url}/static/$1`
|
||||
}
|
||||
dest: `${url}/static/$1`,
|
||||
},
|
||||
];
|
||||
|
||||
for (const file of Object.keys(filesInside)) {
|
||||
@@ -192,7 +214,7 @@ function getRoutes(entryDirectory: string, pathsInside: string[], files: Files,
|
||||
|
||||
routes.push({
|
||||
src: `${prefix}${pageName}`,
|
||||
dest: `${url}/${pageName}`
|
||||
dest: `${url}/${pageName}`,
|
||||
});
|
||||
|
||||
if (pageName.endsWith('index')) {
|
||||
@@ -200,7 +222,7 @@ function getRoutes(entryDirectory: string, pathsInside: string[], files: Files,
|
||||
|
||||
routes.push({
|
||||
src: `${prefix}${resolvedIndex}`,
|
||||
dest: `${url}/${resolvedIndex}`
|
||||
dest: `${url}/${resolvedIndex}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -208,6 +230,20 @@ function getRoutes(entryDirectory: string, pathsInside: string[], files: Files,
|
||||
return routes;
|
||||
}
|
||||
|
||||
function syncEnvVars(base: EnvConfig, removeEnv: EnvConfig, addEnv: EnvConfig) {
|
||||
// Remove any env vars from `removeEnv`
|
||||
// that are not present in the `addEnv`
|
||||
const addKeys = new Set(Object.keys(addEnv));
|
||||
for (const name of Object.keys(removeEnv)) {
|
||||
if (!addKeys.has(name)) {
|
||||
delete base[name];
|
||||
}
|
||||
}
|
||||
|
||||
// Add in the keys from `addEnv`
|
||||
Object.assign(base, addEnv);
|
||||
}
|
||||
|
||||
export {
|
||||
excludeFiles,
|
||||
validateEntrypoint,
|
||||
@@ -219,4 +255,5 @@ export {
|
||||
getPathsInside,
|
||||
getRoutes,
|
||||
stringMap,
|
||||
syncEnvVars,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/node-bridge",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.2",
|
||||
"license": "MIT",
|
||||
"main": "./index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -9,6 +9,7 @@ const {
|
||||
runNpmInstall,
|
||||
runPackageJsonScript,
|
||||
} = require('@now/build-utils/fs/run-user-scripts.js'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { shouldServe } = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
/** @typedef { import('@now/build-utils/file-ref') } FileRef */
|
||||
/** @typedef {{[filePath: string]: FileRef}} Files */
|
||||
@@ -49,8 +50,12 @@ async function compile(workPath, downloadedFiles, entrypoint, config) {
|
||||
});
|
||||
|
||||
if (config && config.includeFiles) {
|
||||
const includeFiles = typeof config.includeFiles === 'string'
|
||||
? [config.includeFiles]
|
||||
: config.includeFiles;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const pattern of config.includeFiles) {
|
||||
for (const pattern of includeFiles) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const files = await glob(pattern, inputDir);
|
||||
|
||||
@@ -145,3 +150,5 @@ exports.prepareCache = async ({ workPath }) => ({
|
||||
...(await glob('package-lock.json', workPath)),
|
||||
...(await glob('yarn.lock', workPath)),
|
||||
});
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/node-server",
|
||||
"version": "0.6.1-canary.0",
|
||||
"version": "0.7.1",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -8,7 +8,7 @@
|
||||
"directory": "packages/now-node-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@now/node-bridge": "^1.1.0",
|
||||
"@now/node-bridge": "^1.1.2",
|
||||
"@zeit/ncc": "0.18.2",
|
||||
"fs-extra": "7.0.1"
|
||||
},
|
||||
|
||||
5
packages/now-node-server/test/fixtures/11-include-files/accepts-string/index.js
vendored
Normal file
5
packages/now-node-server/test/fixtures/11-include-files/accepts-string/index.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
const express = require('express');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.listen();
|
||||
@@ -9,6 +9,13 @@
|
||||
"templates/**"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"src": "accepts-string/index.js",
|
||||
"use": "@now/node-server",
|
||||
"config": {
|
||||
"includeFiles": "templates/**"
|
||||
}
|
||||
}
|
||||
],
|
||||
"probes": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/node",
|
||||
"version": "0.6.1-canary.1",
|
||||
"version": "0.7.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"repository": {
|
||||
@@ -9,7 +9,7 @@
|
||||
"directory": "packages/now-node"
|
||||
},
|
||||
"dependencies": {
|
||||
"@now/node-bridge": "^1.1.0",
|
||||
"@now/node-bridge": "^1.1.2",
|
||||
"@zeit/ncc": "0.18.2",
|
||||
"fs-extra": "7.0.1"
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
runPackageJsonScript,
|
||||
PrepareCacheOptions,
|
||||
BuildOptions,
|
||||
shouldServe,
|
||||
} from '@now/build-utils';
|
||||
|
||||
interface CompilerConfig {
|
||||
@@ -157,3 +158,5 @@ export async function prepareCache({ workPath }: PrepareCacheOptions) {
|
||||
...(await glob('yarn.lock', workPath)),
|
||||
};
|
||||
}
|
||||
|
||||
export { shouldServe };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/optipng",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"files": [
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
// eslint-disable-line import/no-extraneous-dependencies
|
||||
import {
|
||||
import {
|
||||
FileBlob,
|
||||
BuildOptions,
|
||||
AnalyzeOptions
|
||||
} from '@now/build-utils'
|
||||
import OptiPng from 'optipng'
|
||||
import pipe from 'multipipe'
|
||||
AnalyzeOptions,
|
||||
shouldServe,
|
||||
} from '@now/build-utils';
|
||||
import OptiPng from 'optipng';
|
||||
import pipe from 'multipipe';
|
||||
|
||||
export function analyze({ files, entrypoint }: AnalyzeOptions) {
|
||||
export function analyze({ files, entrypoint }: AnalyzeOptions) {
|
||||
return files[entrypoint].digest;
|
||||
}
|
||||
|
||||
@@ -20,3 +21,5 @@ export async function build({ files, entrypoint }: BuildOptions) {
|
||||
const result = await FileBlob.fromStream({ stream });
|
||||
return { [entrypoint]: result };
|
||||
}
|
||||
|
||||
export { shouldServe };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/php-bridge",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.2",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
const {
|
||||
createLambda, rename, glob, download,
|
||||
createLambda,
|
||||
rename,
|
||||
glob,
|
||||
download,
|
||||
shouldServe,
|
||||
} = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const path = require('path');
|
||||
const { getFiles } = require('@now/php-bridge');
|
||||
@@ -52,3 +56,5 @@ exports.build = async ({
|
||||
|
||||
return { [entrypoint]: lambda };
|
||||
};
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/php",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -8,7 +8,7 @@
|
||||
"directory": "packages/now-php"
|
||||
},
|
||||
"dependencies": {
|
||||
"@now/php-bridge": "^0.5.0"
|
||||
"@now/php-bridge": "^0.5.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import execa from 'execa';
|
||||
|
||||
// downloads and installs `pip` (respecting
|
||||
// process.env.PYTHONUSERBASE), and returns
|
||||
// the absolute path to it
|
||||
export async function downloadAndInstallPip() {
|
||||
const { PYTHONUSERBASE } = process.env;
|
||||
if (!PYTHONUSERBASE) {
|
||||
// this is the directory in which `pip` will be
|
||||
// installed to. `--user` will assume `~` if this
|
||||
// is not set, and `~` is not writeable on AWS Lambda.
|
||||
// let's refuse to proceed
|
||||
throw new Error(
|
||||
'Could not install "pip": "PYTHONUSERBASE" env var is not set'
|
||||
);
|
||||
}
|
||||
|
||||
console.log('installing python...');
|
||||
try {
|
||||
await execa('uname', ['-a'], { stdio: 'inherit' });
|
||||
await execa('yum-config-manager', ['--enable', 'epel'], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
await execa(
|
||||
'yum',
|
||||
['install', '-y', 'https://centos6.iuscommunity.org/ius-release.rpm'],
|
||||
{ stdio: 'inherit' }
|
||||
);
|
||||
//await execa('yum', ['update'], { stdio: 'inherit' });
|
||||
await execa(
|
||||
'yum',
|
||||
[
|
||||
'install',
|
||||
'-y',
|
||||
'python36u',
|
||||
'python36u-libs',
|
||||
'python36u-devel',
|
||||
'python36u-pip',
|
||||
],
|
||||
{ stdio: 'inherit' }
|
||||
);
|
||||
} catch (err) {
|
||||
console.log('could not install python');
|
||||
throw err;
|
||||
}
|
||||
|
||||
return '/usr/bin/pip3.6';
|
||||
}
|
||||
@@ -9,9 +9,9 @@ import {
|
||||
download,
|
||||
glob,
|
||||
createLambda,
|
||||
shouldServe,
|
||||
BuildOptions,
|
||||
} from '@now/build-utils';
|
||||
import { downloadAndInstallPip } from './download-and-install-pip';
|
||||
|
||||
async function pipInstall(pipPath: string, workDir: string, ...args: string[]) {
|
||||
const target = '.';
|
||||
@@ -68,20 +68,16 @@ export const config = {
|
||||
|
||||
export const build = async ({
|
||||
workPath,
|
||||
files,
|
||||
files: originalFiles,
|
||||
entrypoint,
|
||||
meta = {},
|
||||
}: BuildOptions) => {
|
||||
console.log('downloading files...');
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
files = await download(files, workPath);
|
||||
|
||||
// this is where `pip` will be installed to
|
||||
// we need it to be under `/tmp`
|
||||
const downloadedFiles = await download(originalFiles, workPath);
|
||||
const foundLockFile = 'Pipfile.lock' in downloadedFiles;
|
||||
const pyUserBase = await getWriteableDirectory();
|
||||
process.env.PYTHONUSERBASE = pyUserBase;
|
||||
const pipPath = meta.isDev ? 'pip3' : await downloadAndInstallPip();
|
||||
const pipPath = 'pip3';
|
||||
|
||||
try {
|
||||
// See: https://stackoverflow.com/a/44728772/376773
|
||||
@@ -91,8 +87,10 @@ export const build = async ({
|
||||
//
|
||||
// distutils.errors.DistutilsOptionError: must supply either home
|
||||
// or prefix/exec-prefix -- not both
|
||||
const setupCfg = join(workPath, 'setup.cfg');
|
||||
await writeFile(setupCfg, '[install]\nprefix=\n');
|
||||
if (meta.isDev) {
|
||||
const setupCfg = join(workPath, 'setup.cfg');
|
||||
await writeFile(setupCfg, '[install]\nprefix=\n');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('failed to create "setup.cfg" file');
|
||||
throw err;
|
||||
@@ -101,10 +99,7 @@ export const build = async ({
|
||||
await pipInstall(pipPath, workPath, 'werkzeug');
|
||||
await pipInstall(pipPath, workPath, 'requests');
|
||||
|
||||
const entryDirectory = dirname(entrypoint);
|
||||
const requirementsTxt = join(entryDirectory, 'requirements.txt');
|
||||
|
||||
if (files['Pipfile.lock']) {
|
||||
if (foundLockFile) {
|
||||
console.log('found "Pipfile.lock"');
|
||||
|
||||
// Install pipenv.
|
||||
@@ -114,6 +109,8 @@ export const build = async ({
|
||||
}
|
||||
|
||||
const fsFiles = await glob('**', workPath);
|
||||
const entryDirectory = dirname(entrypoint);
|
||||
const requirementsTxt = join(entryDirectory, 'requirements.txt');
|
||||
|
||||
if (fsFiles[requirementsTxt]) {
|
||||
console.log('found local "requirements.txt"');
|
||||
@@ -159,3 +156,5 @@ export const build = async ({
|
||||
[entrypoint]: lambda,
|
||||
};
|
||||
};
|
||||
|
||||
export { shouldServe };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/python",
|
||||
"version": "0.1.1-canary.0",
|
||||
"version": "0.2.1",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
@@ -8,6 +8,7 @@ const glob = require('@now/build-utils/fs/glob.js'); // eslint-disable-line impo
|
||||
const { runShellScript } = require('@now/build-utils/fs/run-user-scripts.js'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const FileFsRef = require('@now/build-utils/file-fs-ref.js'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const FileRef = require('@now/build-utils/file-ref.js'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const { shouldServe } = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
|
||||
const installRust = require('./install-rust.js');
|
||||
|
||||
exports.config = {
|
||||
@@ -367,3 +368,5 @@ exports.getDefaultCache = ({ files, entrypoint }) => {
|
||||
});
|
||||
return { [targetFolderDir]: defaultCacheRef };
|
||||
};
|
||||
|
||||
exports.shouldServe = shouldServe;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/rust",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/static-build",
|
||||
"version": "0.5.3-canary.1",
|
||||
"version": "0.5.5",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/wordpress",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.2",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -8,7 +8,7 @@
|
||||
"directory": "packages/now-wordpress"
|
||||
},
|
||||
"dependencies": {
|
||||
"@now/php-bridge": "^0.5.0",
|
||||
"@now/php-bridge": "^0.5.2",
|
||||
"node-fetch": "2.3.0",
|
||||
"yauzl": "2.10.0"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user