mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 12:57:46 +00:00
Compare commits
65 Commits
@now/pytho
...
@now/pytho
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89172a6e89 | ||
|
|
e8f1dbaa46 | ||
|
|
16b5b6fdf3 | ||
|
|
3bab29ff76 | ||
|
|
d675d2e668 | ||
|
|
2dda88e676 | ||
|
|
5a0090eb1f | ||
|
|
d438b4ec4e | ||
|
|
f8810fd7e6 | ||
|
|
a642cfea96 | ||
|
|
2daa20a9f2 | ||
|
|
4d5c0c40f0 | ||
|
|
29051681df | ||
|
|
96d5e81538 | ||
|
|
9ba9dd6949 | ||
|
|
b362d57270 | ||
|
|
4ff95e1718 | ||
|
|
ef02bedd4d | ||
|
|
ed68a09c3e | ||
|
|
ac7ae5fc5d | ||
|
|
9727b1f020 | ||
|
|
2dc454f15f | ||
|
|
4463af5c7a | ||
|
|
c00fb37cf6 | ||
|
|
4deb426f9c | ||
|
|
008b04413a | ||
|
|
f177ba46e9 | ||
|
|
c030fce589 | ||
|
|
50a5150bb5 | ||
|
|
0578ccf47e | ||
|
|
e32cd36ded | ||
|
|
6ac0ab121c | ||
|
|
05db2e6a73 | ||
|
|
0b89d30d6c | ||
|
|
8a021c9417 | ||
|
|
f218771382 | ||
|
|
17309291ed | ||
|
|
86300577ae | ||
|
|
f9594e0d61 | ||
|
|
20fd4b2e12 | ||
|
|
718e4d0e0c | ||
|
|
dc3584cd08 | ||
|
|
b41788b241 | ||
|
|
af9a2f9792 | ||
|
|
f8b8e760de | ||
|
|
93d6ec8024 | ||
|
|
7ed6b84056 | ||
|
|
31da488365 | ||
|
|
8eaf05f782 | ||
|
|
9311e90f27 | ||
|
|
c0de970de2 | ||
|
|
465ac2093d | ||
|
|
19ab0e8698 | ||
|
|
02fa98e5e3 | ||
|
|
4aef9d48b0 | ||
|
|
bd2d05344e | ||
|
|
edc7696623 | ||
|
|
e2f91094bc | ||
|
|
38dba57378 | ||
|
|
be6a6ba1d7 | ||
|
|
31fb5d9ec8 | ||
|
|
6c8f946a48 | ||
|
|
d59e1b9789 | ||
|
|
2852d3fbc3 | ||
|
|
d0292eb751 |
7
.github/CODEOWNERS
vendored
Normal file
7
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Documentation
|
||||
# https://help.github.com/en/articles/about-code-owners
|
||||
|
||||
* @styfle
|
||||
/packages/now-node @styfle @tootallnate
|
||||
/packages/now-next @styfle @dav-is
|
||||
/packages/now-go @styfle @sophearak
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,6 @@
|
||||
node_modules
|
||||
tmp
|
||||
target/
|
||||
.next
|
||||
.next
|
||||
coverage
|
||||
*.tgz
|
||||
|
||||
38
errors/now-static-build-failed-to-detect-a-server.md
Normal file
38
errors/now-static-build-failed-to-detect-a-server.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# `@now/static-build` Failed to detect a server running
|
||||
|
||||
#### Why This Warning Occurred
|
||||
|
||||
When running `now dev`, the `@now/static-build` builder proxies relevant HTTP
|
||||
requests to the server that is created by the `now-dev` script in the
|
||||
`package.json` file.
|
||||
|
||||
In order for `now dev` to know which port the server is running on, the builder
|
||||
is provided a `$PORT` environment variable that the server *must* bind to. The
|
||||
error "Failed to detect a server running on port" is printed if the builder fails
|
||||
to detect a server listening on that specific port within five minutes.
|
||||
|
||||
#### Possible Ways to Fix It
|
||||
|
||||
Please ensure that your `now-dev` script binds the spawned development server on
|
||||
the provided `$PORT` that the builder expects the server to bind to.
|
||||
|
||||
For example, if you are using Gatsby, your `now-dev` script must use the `-p`
|
||||
(port) option to bind to the `$PORT` specified from the builder:
|
||||
|
||||
```
|
||||
{
|
||||
...
|
||||
"scripts": {
|
||||
...
|
||||
"now-dev": "gatsby develop -p $PORT"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Consult your static builder program's `--help` or documentation to figure out what
|
||||
the command line flag to bind to a specific port is (in many cases, it is one of:
|
||||
`-p` / `-P` / `--port`).
|
||||
|
||||
### Useful Links
|
||||
|
||||
- [`@now/static-build` Local Development Documentation](https://zeit.co/docs/v2/deployments/official-builders/static-build-now-static-build#local-development)
|
||||
@@ -1,5 +1,37 @@
|
||||
const childProcess = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
const command = 'git diff HEAD~1 --name-only';
|
||||
const diff = childProcess.execSync(command).toString();
|
||||
|
||||
const changed = diff
|
||||
.split('\n')
|
||||
.filter(item => Boolean(item) && item.includes('packages/'))
|
||||
.map(item => path.relative('packages', item).split('/')[0]);
|
||||
|
||||
const matches = [];
|
||||
|
||||
if (changed.length > 0) {
|
||||
console.log('The following packages have changed:');
|
||||
|
||||
changed.map((item) => {
|
||||
matches.push(item);
|
||||
console.log(item);
|
||||
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
matches.push('now-node');
|
||||
console.log(`No packages changed, defaulting to ${matches[0]}`);
|
||||
}
|
||||
|
||||
const testMatch = Array.from(new Set(matches)).map(
|
||||
item => `**/${item}/**/?(*.)+(spec|test).[jt]s?(x)`,
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
testEnvironment: 'node',
|
||||
testMatch,
|
||||
collectCoverageFrom: [
|
||||
'packages/(!test)/**/*.{js,jsx}',
|
||||
'!**/node_modules/**',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/bash",
|
||||
"version": "0.2.1-canary.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.5",
|
||||
"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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,11 +4,11 @@ import { File, Files, Meta } from '../types';
|
||||
import { remove, mkdirp, readlink, symlink } from 'fs-extra';
|
||||
|
||||
export interface DownloadedFiles {
|
||||
[filePath: string]: FileFsRef
|
||||
[filePath: string]: FileFsRef;
|
||||
}
|
||||
|
||||
const S_IFMT = 61440; /* 0170000 type of file */
|
||||
const S_IFLNK = 40960; /* 0120000 symbolic link */
|
||||
const S_IFMT = 61440; /* 0170000 type of file */
|
||||
const S_IFLNK = 40960; /* 0120000 symbolic link */
|
||||
|
||||
export function isSymbolicLink(mode: number): boolean {
|
||||
return (mode & S_IFMT) === S_IFLNK;
|
||||
@@ -17,9 +17,9 @@ export function isSymbolicLink(mode: number): boolean {
|
||||
async function downloadFile(file: File, fsPath: string): Promise<FileFsRef> {
|
||||
const { mode } = file;
|
||||
if (mode && isSymbolicLink(mode) && file.type === 'FileFsRef') {
|
||||
const [ target ] = await Promise.all([
|
||||
const [target] = await Promise.all([
|
||||
readlink((file as FileFsRef).fsPath),
|
||||
mkdirp(path.dirname(fsPath))
|
||||
mkdirp(path.dirname(fsPath)),
|
||||
]);
|
||||
await symlink(target, fsPath);
|
||||
return FileFsRef.fromFsPath({ mode, fsPath });
|
||||
@@ -34,12 +34,25 @@ async function removeFile(basePath: string, fileMatched: string) {
|
||||
await remove(file);
|
||||
}
|
||||
|
||||
export default async function download(files: Files, basePath: string, meta?: Meta): Promise<DownloadedFiles> {
|
||||
export default async function download(
|
||||
files: Files,
|
||||
basePath: string,
|
||||
meta?: Meta
|
||||
): Promise<DownloadedFiles> {
|
||||
const { isDev = false, filesChanged = null, filesRemoved = null } =
|
||||
meta || {};
|
||||
|
||||
if (isDev) {
|
||||
// In `now dev`, the `download()` function is a no-op because
|
||||
// the `basePath` matches the `cwd` of the dev server, so the
|
||||
// source files are already available.
|
||||
return files as DownloadedFiles;
|
||||
}
|
||||
|
||||
const files2: DownloadedFiles = {};
|
||||
const { filesChanged = null, filesRemoved = null } = meta || {};
|
||||
|
||||
await Promise.all(
|
||||
Object.keys(files).map(async (name) => {
|
||||
Object.keys(files).map(async name => {
|
||||
// If the file does not exist anymore, remove it.
|
||||
if (Array.isArray(filesRemoved) && filesRemoved.includes(name)) {
|
||||
await removeFile(basePath, name);
|
||||
@@ -55,7 +68,7 @@ export default async function download(files: Files, basePath: string, meta?: Me
|
||||
const fsPath = path.join(basePath, name);
|
||||
|
||||
files2[name] = await downloadFile(file, fsPath);
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
return files2;
|
||||
|
||||
@@ -8,12 +8,16 @@ import FileFsRef from '../file-fs-ref';
|
||||
type GlobOptions = vanillaGlob_.IOptions;
|
||||
|
||||
interface FsFiles {
|
||||
[filePath: string]: FileFsRef
|
||||
[filePath: string]: FileFsRef;
|
||||
}
|
||||
|
||||
const vanillaGlob = promisify(vanillaGlob_);
|
||||
|
||||
export default async function glob(pattern: string, opts: GlobOptions | string, mountpoint?: string): Promise<FsFiles> {
|
||||
export default async function glob(
|
||||
pattern: string,
|
||||
opts: GlobOptions | string,
|
||||
mountpoint?: string
|
||||
): Promise<FsFiles> {
|
||||
let options: GlobOptions;
|
||||
if (typeof opts === 'string') {
|
||||
options = { cwd: opts };
|
||||
@@ -23,7 +27,7 @@ export default async function glob(pattern: string, opts: GlobOptions | string,
|
||||
|
||||
if (!options.cwd) {
|
||||
throw new Error(
|
||||
'Second argument (basePath) must be specified for names of resulting files',
|
||||
'Second argument (basePath) must be specified for names of resulting files'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -41,11 +45,11 @@ export default async function glob(pattern: string, opts: GlobOptions | string,
|
||||
const files = await vanillaGlob(pattern, options);
|
||||
|
||||
for (const relativePath of files) {
|
||||
const fsPath = path.join(options.cwd!, relativePath);
|
||||
const fsPath = path.join(options.cwd!, relativePath).replace(/\\/g, '/');
|
||||
let stat: Stats = options.statCache![fsPath] as Stats;
|
||||
assert(
|
||||
stat,
|
||||
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`,
|
||||
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
|
||||
);
|
||||
if (stat.isFile()) {
|
||||
const isSymlink = options.symlinks![fsPath];
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,13 @@ const { shouldServe } = require('@now/build-utils'); // eslint-disable-line impo
|
||||
|
||||
exports.analyze = ({ files, entrypoint }) => files[entrypoint].digest;
|
||||
|
||||
exports.build = async ({ files, entrypoint }) => {
|
||||
exports.build = async ({
|
||||
workPath, files, entrypoint, meta,
|
||||
}) => {
|
||||
console.log('downloading files...');
|
||||
const srcDir = await getWritableDirectory();
|
||||
const outDir = await getWritableDirectory();
|
||||
|
||||
await download(files, srcDir);
|
||||
await download(files, workPath, meta);
|
||||
|
||||
const handlerPath = path.join(__dirname, 'handler');
|
||||
await copyFile(handlerPath, path.join(outDir, 'handler'));
|
||||
@@ -24,7 +25,7 @@ exports.build = async ({ files, entrypoint }) => {
|
||||
|
||||
// For now only the entrypoint file is copied into the lambda
|
||||
await copyFile(
|
||||
path.join(srcDir, entrypoint),
|
||||
path.join(workPath, entrypoint),
|
||||
path.join(outDir, entrypoint),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/cgi",
|
||||
"version": "0.1.1-canary.0",
|
||||
"version": "0.1.4",
|
||||
"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,33 @@ 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, or default `Go` path exists
|
||||
// asssume that user have `Go` installed
|
||||
if (isUserGo || process.env.GOPATH !== undefined) {
|
||||
const { stdout } = await execa('go', ['version']);
|
||||
|
||||
// if we found GOPATH in ENV, use it
|
||||
if (process.env.GOPATH !== undefined) {
|
||||
return createGo(dir, platform, arch);
|
||||
if (parseInt(stdout.split('.')[1]) >= 11) {
|
||||
return createGo(dir, platform, arch);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Your current ${stdout} doesn't support Go Modules. Please update.`
|
||||
);
|
||||
} 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,5 +1,7 @@
|
||||
import { join, sep, dirname } from 'path';
|
||||
import { readFile, writeFile, pathExists, move } from 'fs-extra';
|
||||
import { join, sep, dirname, basename } from 'path';
|
||||
import { readFile, writeFile, pathExists, move, copy } from 'fs-extra';
|
||||
import { homedir } from 'os';
|
||||
import execa from 'execa';
|
||||
|
||||
import {
|
||||
glob,
|
||||
@@ -14,6 +16,7 @@ import {
|
||||
import { createGo, getAnalyzedEntrypoint } from './go-helpers';
|
||||
|
||||
interface Analyzed {
|
||||
found?: boolean;
|
||||
packageName: string;
|
||||
functionName: string;
|
||||
watch: string[];
|
||||
@@ -28,6 +31,18 @@ interface BuildParamsType extends BuildOptions {
|
||||
meta: BuildParamsMeta;
|
||||
}
|
||||
|
||||
// Initialize private git repo for Go Modules
|
||||
async function initPrivateGit(credentials: string) {
|
||||
await execa('git', [
|
||||
'config',
|
||||
'--global',
|
||||
'credential.helper',
|
||||
`store --file ${join(homedir(), '.git-credentials')}`,
|
||||
]);
|
||||
|
||||
await writeFile(join(homedir(), '.git-credentials'), credentials);
|
||||
}
|
||||
|
||||
export const version = 2;
|
||||
|
||||
export const config = {
|
||||
@@ -38,8 +53,14 @@ export async function build({
|
||||
files,
|
||||
entrypoint,
|
||||
config,
|
||||
workPath,
|
||||
meta = {} as BuildParamsMeta,
|
||||
}: BuildParamsType) {
|
||||
if (process.env.GIT_CREDENTIALS && !meta.isDev) {
|
||||
console.log('Initialize Git credentials...');
|
||||
await initPrivateGit(process.env.GIT_CREDENTIALS);
|
||||
}
|
||||
|
||||
console.log('Downloading user files...');
|
||||
const entrypointArr = entrypoint.split(sep);
|
||||
|
||||
@@ -48,26 +69,12 @@ export async function build({
|
||||
getWriteableDirectory(),
|
||||
]);
|
||||
|
||||
if (meta.isDev) {
|
||||
const devGoPath = `dev${entrypointArr[entrypointArr.length - 1]}`;
|
||||
const goPathArr = goPath.split(sep);
|
||||
goPathArr.pop();
|
||||
goPathArr.push(devGoPath);
|
||||
goPath = goPathArr.join(sep);
|
||||
}
|
||||
|
||||
const srcPath = join(goPath, 'src', 'lambda');
|
||||
const downloadedFiles = await download(files, srcPath);
|
||||
const input = dirname(downloadedFiles[entrypoint].fsPath);
|
||||
var includedFiles: Files = {};
|
||||
|
||||
if (config && config.includeFiles) {
|
||||
for (const pattern of config.includeFiles) {
|
||||
const files = await glob(pattern, input);
|
||||
for (const assetName of Object.keys(files)) {
|
||||
includedFiles[assetName] = files[assetName];
|
||||
}
|
||||
}
|
||||
let downloadedFiles;
|
||||
if (meta.isDev) {
|
||||
downloadedFiles = await download(files, workPath, meta);
|
||||
} else {
|
||||
downloadedFiles = await download(files, srcPath);
|
||||
}
|
||||
|
||||
console.log(`Parsing AST for "${entrypoint}"`);
|
||||
@@ -81,24 +88,79 @@ export async function build({
|
||||
|
||||
if (!analyzed) {
|
||||
const err = new Error(
|
||||
`Could not find an exported function in "${entrypoint}"`
|
||||
`Could not find an exported function in "${entrypoint}"
|
||||
Learn more: https://zeit.co/docs/v2/deployments/official-builders/go-now-go/#entrypoint
|
||||
`
|
||||
);
|
||||
console.log(err.message);
|
||||
throw err;
|
||||
}
|
||||
|
||||
const entrypointDirnameDev = dirname(downloadedFiles[entrypoint].fsPath);
|
||||
const parsedAnalyzed = JSON.parse(analyzed) as Analyzed;
|
||||
|
||||
if (meta.isDev) {
|
||||
const base = dirname(downloadedFiles['now.json'].fsPath);
|
||||
const destNow = join(
|
||||
base,
|
||||
'.now',
|
||||
'cache',
|
||||
basename(entrypoint, '.go'),
|
||||
'src',
|
||||
'lambda'
|
||||
);
|
||||
const goMod = await pathExists(join(entrypointDirnameDev, 'go.mod'));
|
||||
|
||||
// this will ensure Go rebuilt fast
|
||||
goPath = join(base, '.now', 'cache', basename(entrypoint, '.go'));
|
||||
|
||||
for (const file of parsedAnalyzed.watch) {
|
||||
if (entrypointArr.length > 0) {
|
||||
await copy(
|
||||
join(base, dirname(entrypoint), file),
|
||||
join(destNow, dirname(entrypoint), file)
|
||||
);
|
||||
|
||||
if (goMod) {
|
||||
await copy(
|
||||
join(entrypointDirnameDev, 'go.mod'),
|
||||
join(destNow, dirname(entrypoint), 'go.mod')
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await copy(join(base, file), join(destNow, file));
|
||||
|
||||
if (goMod) {
|
||||
await copy(
|
||||
join(entrypointDirnameDev, 'go.mod'),
|
||||
join(destNow, 'go.mod')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
downloadedFiles = await glob('**', destNow);
|
||||
}
|
||||
|
||||
const entrypointDirname = dirname(downloadedFiles[entrypoint].fsPath);
|
||||
const input = entrypointDirname;
|
||||
var includedFiles: Files = {};
|
||||
|
||||
if (config && config.includeFiles) {
|
||||
for (const pattern of config.includeFiles) {
|
||||
const files = await glob(pattern, input);
|
||||
for (const assetName of Object.keys(files)) {
|
||||
includedFiles[assetName] = files[assetName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handlerFunctionName = parsedAnalyzed.functionName;
|
||||
console.log(
|
||||
`Found exported function "${handlerFunctionName}" in "${entrypoint}"`
|
||||
);
|
||||
|
||||
// we need `main.go` in the same dir as the entrypoint,
|
||||
// otherwise `go build` will refuse to build
|
||||
const entrypointDirname = dirname(downloadedFiles[entrypoint].fsPath);
|
||||
|
||||
// check if package name other than main
|
||||
// using `go.mod` way building the handler
|
||||
const packageName = parsedAnalyzed.packageName;
|
||||
const isGoModExist = await pathExists(join(entrypointDirname, 'go.mod'));
|
||||
if (packageName !== 'main') {
|
||||
@@ -225,6 +287,9 @@ export async function build({
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// legacy mode
|
||||
// we need `main.go` in the same dir as the entrypoint,
|
||||
// otherwise `go build` will refuse to build
|
||||
const go = await createGo(
|
||||
goPath,
|
||||
process.platform,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/go",
|
||||
"version": "0.4.3-canary.0",
|
||||
"version": "0.5.0",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
22
packages/now-go/test/fixtures/09-exported-function/index.go
vendored
Normal file
22
packages/now-go/test/fixtures/09-exported-function/index.go
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
package function
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Person struct
|
||||
type Person struct {
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
// NewPerson struct method
|
||||
func NewPerson(name string, age int) *Person {
|
||||
return &Person{name: name, age: age}
|
||||
}
|
||||
|
||||
// H func
|
||||
func H(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "RANDOMNESS_PLACEHOLDER")
|
||||
}
|
||||
9
packages/now-go/test/fixtures/09-exported-function/now.json
vendored
Normal file
9
packages/now-go/test/fixtures/09-exported-function/now.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{ "src": "index.go", "use": "@now/go" }
|
||||
],
|
||||
"probes": [
|
||||
{ "path": "/", "mustContain": "RANDOMNESS_PLACEHOLDER" }
|
||||
]
|
||||
}
|
||||
@@ -10,9 +10,22 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ignoredFoldersRegex []*regexp.Regexp
|
||||
|
||||
func init() {
|
||||
ignoredFolders := []string{"vendor", "testdata", ".now"}
|
||||
|
||||
// Build the regex that matches if a path contains the respective ignored folder
|
||||
// The pattern will look like: (.*/)?vendor/.*, which matches every path that contains a vendor folder
|
||||
for _, folder := range ignoredFolders {
|
||||
ignoredFoldersRegex = append(ignoredFoldersRegex, regexp.MustCompile("(.*/)?"+folder+"/.*"))
|
||||
}
|
||||
}
|
||||
|
||||
type analyze struct {
|
||||
PackageName string `json:"packageName"`
|
||||
FuncName string `json:"functionName"`
|
||||
@@ -40,8 +53,9 @@ func visit(files *[]string) filepath.WalkFunc {
|
||||
}
|
||||
|
||||
// we don't need Dirs, or test files
|
||||
// we only want `.go` files
|
||||
if info.IsDir() || itf || filepath.Ext(path) != ".go" {
|
||||
// we only want `.go` files. Further, we ignore
|
||||
// every file that is in one of the ignored folders.
|
||||
if info.IsDir() || itf || filepath.Ext(path) != ".go" || isInIgnoredFolder(path) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -50,6 +64,19 @@ func visit(files *[]string) filepath.WalkFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// isInIgnoredFolder checks if the given path is in one of the ignored folders.
|
||||
func isInIgnoredFolder(path string) bool {
|
||||
// Make sure the regex works for Windows paths
|
||||
path = filepath.ToSlash(path)
|
||||
|
||||
for _, pattern := range ignoredFoldersRegex {
|
||||
if pattern.MatchString(path) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// return unique file
|
||||
func unique(files []string) []string {
|
||||
encountered := map[string]bool{}
|
||||
@@ -138,24 +165,32 @@ func main() {
|
||||
}
|
||||
|
||||
parsed := parse(fileName)
|
||||
offset := parsed.Pos()
|
||||
reqRep := "*http.Request http.ResponseWriter"
|
||||
|
||||
for _, decl := range parsed.Decls {
|
||||
fn, ok := decl.(*ast.FuncDecl)
|
||||
if !ok {
|
||||
// this declaraction is not a function
|
||||
// this declaration is not a function
|
||||
// so we're not interested
|
||||
continue
|
||||
}
|
||||
if fn.Name.IsExported() == true {
|
||||
// we found the first exported function
|
||||
// we're done!
|
||||
analyzed := analyze{
|
||||
PackageName: parsed.Name.Name,
|
||||
FuncName: fn.Name.Name,
|
||||
Watch: unique(relatedFiles),
|
||||
// find a valid `net/http` handler function
|
||||
for _, param := range fn.Type.Params.List {
|
||||
if strings.Contains(reqRep, string(rf[param.Type.Pos()-offset:param.Type.End()-offset])) {
|
||||
// we found the first exported function with `net/http`
|
||||
// we're done!
|
||||
analyzed := analyze{
|
||||
PackageName: parsed.Name.Name,
|
||||
FuncName: fn.Name.Name,
|
||||
Watch: unique(relatedFiles),
|
||||
}
|
||||
analyzedJSON, _ := json.Marshal(analyzed)
|
||||
fmt.Print(string(analyzedJSON))
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
json, _ := json.Marshal(analyzed)
|
||||
fmt.Print(string(json))
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/html-minifier",
|
||||
"version": "1.1.1-canary.0",
|
||||
"version": "1.1.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/lambda",
|
||||
"version": "0.5.1-canary.0",
|
||||
"version": "0.5.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/md",
|
||||
"version": "0.5.1-canary.0",
|
||||
"version": "0.5.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -8,9 +8,11 @@ const { runNpmInstall } = require('@now/build-utils/fs/run-user-scripts.js'); //
|
||||
|
||||
const writeFile = promisify(fs.writeFile);
|
||||
|
||||
exports.build = async ({ files, entrypoint, workPath }) => {
|
||||
exports.build = async ({
|
||||
files, entrypoint, workPath, meta,
|
||||
}) => {
|
||||
console.log('downloading user files...');
|
||||
const downloadedFiles = await download(files, workPath);
|
||||
const downloadedFiles = await download(files, workPath, meta);
|
||||
console.log('writing package.json...');
|
||||
const packageJson = { dependencies: { 'mdx-deck': '1.7.15' } };
|
||||
const packageJsonPath = path.join(workPath, 'package.json');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/mdx-deck",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.4",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/next",
|
||||
"version": "0.2.1-canary.0",
|
||||
"version": "0.4.0",
|
||||
"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.3",
|
||||
"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,19 +25,23 @@ import {
|
||||
|
||||
import nextLegacyVersions from './legacy-versions';
|
||||
import {
|
||||
EnvConfig,
|
||||
excludeFiles,
|
||||
getNextConfig,
|
||||
getPathsInside,
|
||||
getRoutes,
|
||||
includeOnlyEntryDirectory,
|
||||
normalizePackageJson,
|
||||
onlyStaticDirectory,
|
||||
filesFromDirectory,
|
||||
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: [],
|
||||
});
|
||||
@@ -146,14 +155,13 @@ export const build = async ({
|
||||
entrypoint,
|
||||
meta = {} as BuildParamsMeta,
|
||||
}: BuildParamsType): Promise<{
|
||||
routes?: any[];
|
||||
routes?: { src: string; dest: string }[];
|
||||
output: Files;
|
||||
watch?: string[];
|
||||
childProcesses: ChildProcess[];
|
||||
}> => {
|
||||
validateEntrypoint(entrypoint);
|
||||
|
||||
const routes: any[] = [];
|
||||
const entryDirectory = path.dirname(entrypoint);
|
||||
const entryPath = path.join(workPath, entryDirectory);
|
||||
const dotNext = path.join(entryPath, '.next');
|
||||
@@ -181,7 +189,17 @@ export const build = async ({
|
||||
if (!urls[entrypoint]) {
|
||||
console.log(`${name} Installing dependencies...`);
|
||||
await runNpmInstall(entryPath, ['--prefer-offline']);
|
||||
const { forked, getUrl } = startDevServer(entryPath);
|
||||
|
||||
if (!process.env.NODE_ENV) {
|
||||
process.env.NODE_ENV = 'development';
|
||||
}
|
||||
|
||||
// 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(
|
||||
@@ -270,7 +288,9 @@ export const build = async ({
|
||||
await unlinkFile(path.join(entryPath, '.npmrc'));
|
||||
}
|
||||
|
||||
const routes: { src: string; dest: string }[] = [];
|
||||
const lambdas: { [key: string]: Lambda } = {};
|
||||
const staticPages: { [key: string]: FileFsRef } = {};
|
||||
|
||||
if (isLegacy) {
|
||||
const filesAfterBuild = await glob('**', entryPath);
|
||||
@@ -362,10 +382,21 @@ export const build = async ({
|
||||
fsPath: path.join(__dirname, 'launcher.js'),
|
||||
}),
|
||||
};
|
||||
const pages = await glob(
|
||||
'**/*.js',
|
||||
path.join(entryPath, '.next', 'serverless', 'pages')
|
||||
);
|
||||
const pagesDir = path.join(entryPath, '.next', 'serverless', 'pages');
|
||||
|
||||
const pages = await glob('**/*.js', pagesDir);
|
||||
const staticPageFiles = await glob('**/*.html', pagesDir);
|
||||
|
||||
Object.keys(staticPageFiles).forEach((page: string) => {
|
||||
const staticRoute = path.join(entryDirectory, page);
|
||||
staticPages[staticRoute] = staticPageFiles[page];
|
||||
|
||||
const pathname = page.replace(/\.html$/, '');
|
||||
routes.push({
|
||||
src: `^${path.join('/', entryDirectory, pathname)}$`,
|
||||
dest: path.join('/', staticRoute),
|
||||
});
|
||||
});
|
||||
|
||||
const pageKeys = Object.keys(pages);
|
||||
|
||||
@@ -433,14 +464,32 @@ export const build = async ({
|
||||
{}
|
||||
);
|
||||
|
||||
const staticDirectoryFiles = onlyStaticDirectory(
|
||||
includeOnlyEntryDirectory(files, entryDirectory),
|
||||
entryDirectory
|
||||
const entryDirectoryFiles = includeOnlyEntryDirectory(files, entryDirectory);
|
||||
const staticDirectoryFiles = filesFromDirectory(
|
||||
entryDirectoryFiles,
|
||||
path.join(entryDirectory, 'static')
|
||||
);
|
||||
const publicDirectoryFiles = filesFromDirectory(
|
||||
entryDirectoryFiles,
|
||||
path.join(entryDirectory, 'public')
|
||||
);
|
||||
const publicFiles = Object.keys(publicDirectoryFiles).reduce(
|
||||
(mappedFiles, file) => ({
|
||||
...mappedFiles,
|
||||
[file.replace(/public[/\\]+/, '')]: publicDirectoryFiles[file],
|
||||
}),
|
||||
{}
|
||||
);
|
||||
|
||||
return {
|
||||
output: { ...lambdas, ...staticFiles, ...staticDirectoryFiles },
|
||||
routes: [],
|
||||
output: {
|
||||
...publicFiles,
|
||||
...lambdas,
|
||||
...staticPages,
|
||||
...staticFiles,
|
||||
...staticDirectoryFiles,
|
||||
},
|
||||
routes,
|
||||
watch: [],
|
||||
childProcesses: [],
|
||||
};
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
if (!process.env.NODE_ENV) {
|
||||
process.env.NODE_ENV = process.env.NOW_REGION === 'dev1' ? 'development' : 'production';
|
||||
process.env.NODE_ENV =
|
||||
process.env.NOW_REGION === 'dev1' ? 'development' : 'production';
|
||||
}
|
||||
|
||||
const { Server } = require('http');
|
||||
const { Bridge } = require('./now__bridge');
|
||||
const page = require('./page');
|
||||
|
||||
const server = new Server(page.render);
|
||||
// page.render is for React rendering
|
||||
// page.default is for /api rendering
|
||||
// page is for module.exports in /api
|
||||
const server = new Server(page.render || page.default || page);
|
||||
const bridge = new Bridge(server);
|
||||
bridge.listen();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -63,11 +73,11 @@ function excludeLockFiles(files: Files): Files {
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the static directory from files
|
||||
* Include only the files from a selected directory
|
||||
*/
|
||||
function onlyStaticDirectory(files: Files, entryDir: string): Files {
|
||||
function filesFromDirectory(files: Files, dir: string): Files {
|
||||
function matcher(filePath: string) {
|
||||
return !filePath.startsWith(path.join(entryDir, 'static'));
|
||||
return !filePath.startsWith(dir.replace(/\\/g, '/'));
|
||||
}
|
||||
|
||||
return excludeFiles(files, matcher);
|
||||
@@ -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,15 +188,16 @@ 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`,
|
||||
},
|
||||
];
|
||||
const filePaths = Object.keys(filesInside);
|
||||
|
||||
for (const file of Object.keys(filesInside)) {
|
||||
for (const file of filePaths) {
|
||||
const relativePath = path.relative(entryDirectory, file);
|
||||
const isPage = pathIsInside('pages', relativePath);
|
||||
|
||||
@@ -192,7 +215,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,23 +223,57 @@ function getRoutes(entryDirectory: string, pathsInside: string[], files: Files,
|
||||
|
||||
routes.push({
|
||||
src: `${prefix}${resolvedIndex}`,
|
||||
dest: `${url}/${resolvedIndex}`
|
||||
dest: `${url}/${resolvedIndex}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add public folder routes
|
||||
for (const file of filePaths) {
|
||||
const relativePath = path.relative(entryDirectory, file);
|
||||
const isPublic = pathIsInside('public', relativePath);
|
||||
|
||||
if (!isPublic) continue;
|
||||
|
||||
const fileName = path.relative('public', relativePath);
|
||||
const route = {
|
||||
src: `${prefix}${fileName}`,
|
||||
dest: `${url}/${fileName}`,
|
||||
};
|
||||
|
||||
// Only add the route if a page is not already using it
|
||||
if (!routes.some(r => r.src === route.src)) {
|
||||
routes.push(route);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
includeOnlyEntryDirectory,
|
||||
excludeLockFiles,
|
||||
normalizePackageJson,
|
||||
onlyStaticDirectory,
|
||||
filesFromDirectory,
|
||||
getNextConfig,
|
||||
getPathsInside,
|
||||
getRoutes,
|
||||
stringMap,
|
||||
syncEnvVars,
|
||||
};
|
||||
|
||||
@@ -28,6 +28,7 @@ it(
|
||||
} = await runBuildLambda(path.join(__dirname, 'monorepo'));
|
||||
expect(output['www/index']).toBeDefined();
|
||||
expect(output['www/static/test.txt']).toBeDefined();
|
||||
expect(output['www/data.txt']).toBeDefined();
|
||||
const filePaths = Object.keys(output);
|
||||
const hasUnderScoreAppStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_app\.js$/));
|
||||
const hasUnderScoreErrorStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_error\.js$/));
|
||||
@@ -96,3 +97,14 @@ it(
|
||||
},
|
||||
FOUR_MINUTES,
|
||||
);
|
||||
|
||||
it(
|
||||
'Should build the public-files test',
|
||||
async () => {
|
||||
const {
|
||||
buildResult: { output },
|
||||
} = await runBuildLambda(path.join(__dirname, 'public-files'));
|
||||
expect(output['robots.txt']).toBeDefined();
|
||||
},
|
||||
FOUR_MINUTES,
|
||||
);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
data
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
target: 'serverless',
|
||||
};
|
||||
6
packages/now-next/test/integration/public-files/now.json
Normal file
6
packages/now-next/test/integration/public-files/now.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{"src": "next.config.js", "use": "@now/next"}
|
||||
]
|
||||
}
|
||||
10
packages/now-next/test/integration/public-files/package.json
Normal file
10
packages/now-next/test/integration/public-files/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"scripts": {
|
||||
"now-build": "next build"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "8",
|
||||
"react": "16",
|
||||
"react-dom": "16"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export default () => 'Index page';
|
||||
@@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow: /
|
||||
@@ -2,7 +2,7 @@
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const { build } = require('@now/next');
|
||||
const { FileBlob } = require('@now/build-utils');
|
||||
const { download, FileBlob } = require('@now/build-utils');
|
||||
|
||||
jest.setTimeout(45000);
|
||||
|
||||
@@ -22,6 +22,15 @@ describe('build meta dev', () => {
|
||||
export default () => 'Index page'
|
||||
`,
|
||||
}),
|
||||
// This file should be omitted because `pages/index.js` will use the same route
|
||||
'public/index': new FileBlob({
|
||||
mode: 0o777,
|
||||
data: 'text',
|
||||
}),
|
||||
'public/data.txt': new FileBlob({
|
||||
mode: 0o777,
|
||||
data: 'data',
|
||||
}),
|
||||
'package.json': new FileBlob({
|
||||
mode: 0o777,
|
||||
data: `
|
||||
@@ -46,24 +55,12 @@ describe('build meta dev', () => {
|
||||
.slice(3),
|
||||
);
|
||||
console.log('workPath directory: ', workPath);
|
||||
/*
|
||||
it('should have builder v2 response isDev=false', async () => {
|
||||
const meta = { isDev: false, requestPath: null };
|
||||
const { output, routes, watch } = await build({
|
||||
files,
|
||||
workPath,
|
||||
entrypoint,
|
||||
meta,
|
||||
});
|
||||
//console.log('output: ', Object.keys(output));
|
||||
expect(Object.keys(output).length).toBe(7);
|
||||
expect(output.index.type).toBe('Lambda');
|
||||
expect(routes.length).toBe(0);
|
||||
expect(watch.length).toBe(0);
|
||||
});
|
||||
*/
|
||||
|
||||
it('should have builder v2 response isDev=true', async () => {
|
||||
// Since `download()` is a no-op when `isDev=true`, the assumption is that the
|
||||
// source files are already present, so manually download them here first.
|
||||
await download(files, workPath);
|
||||
|
||||
const meta = { isDev: true, requestPath: null };
|
||||
const {
|
||||
output, routes, watch, childProcesses,
|
||||
@@ -83,8 +80,15 @@ describe('build meta dev', () => {
|
||||
{ src: '/static/(.*)', dest: 'http://localhost:5000/static/$1' },
|
||||
{ src: '/index', dest: 'http://localhost:5000/index' },
|
||||
{ src: '/', dest: 'http://localhost:5000/' },
|
||||
{ src: '/data.txt', dest: 'http://localhost:5000/data.txt' },
|
||||
]);
|
||||
expect(watch).toEqual([
|
||||
'next.config.js',
|
||||
'pages/index.js',
|
||||
'public/index',
|
||||
'public/data.txt',
|
||||
'package.json',
|
||||
]);
|
||||
expect(watch).toEqual(['next.config.js', 'pages/index.js', 'package.json']);
|
||||
childProcesses.forEach(cp => cp.kill());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/node-bridge",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.3",
|
||||
"license": "MIT",
|
||||
"main": "./index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { AddressInfo } from 'net';
|
||||
import { APIGatewayProxyEvent } from 'aws-lambda';
|
||||
import { APIGatewayProxyEvent, Context } from 'aws-lambda';
|
||||
import {
|
||||
Server,
|
||||
IncomingHttpHeaders,
|
||||
OutgoingHttpHeaders,
|
||||
request
|
||||
request,
|
||||
} from 'http';
|
||||
|
||||
interface NowProxyEvent {
|
||||
@@ -133,25 +133,25 @@ export class Bridge {
|
||||
|
||||
return this.server.listen({
|
||||
host: '127.0.0.1',
|
||||
port: 0
|
||||
port: 0,
|
||||
});
|
||||
}
|
||||
|
||||
async launcher(
|
||||
event: NowProxyEvent | APIGatewayProxyEvent
|
||||
event: NowProxyEvent | APIGatewayProxyEvent,
|
||||
context: Context
|
||||
): Promise<NowProxyResponse> {
|
||||
context.callbackWaitsForEmptyEventLoop = false;
|
||||
const { port } = await this.listening;
|
||||
|
||||
const { isApiGateway, method, path, headers, body } = normalizeEvent(
|
||||
event
|
||||
);
|
||||
const { isApiGateway, method, path, headers, body } = normalizeEvent(event);
|
||||
|
||||
const opts = {
|
||||
hostname: '127.0.0.1',
|
||||
port,
|
||||
path,
|
||||
method,
|
||||
headers
|
||||
headers,
|
||||
};
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
@@ -175,7 +175,7 @@ export class Bridge {
|
||||
statusCode: response.statusCode || 200,
|
||||
headers: response.headers,
|
||||
body: bodyBuffer.toString('base64'),
|
||||
encoding: 'base64'
|
||||
encoding: 'base64',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,56 +16,70 @@ test('port binding', async () => {
|
||||
});
|
||||
|
||||
test('`APIGatewayProxyEvent` normalizing', async () => {
|
||||
const server = new Server((req, res) => res.end(
|
||||
JSON.stringify({
|
||||
method: req.method,
|
||||
path: req.url,
|
||||
headers: req.headers,
|
||||
}),
|
||||
));
|
||||
const server = new Server((req, res) =>
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
method: req.method,
|
||||
path: req.url,
|
||||
headers: req.headers,
|
||||
})
|
||||
)
|
||||
);
|
||||
const bridge = new Bridge(server);
|
||||
bridge.listen();
|
||||
const result = await bridge.launcher({
|
||||
httpMethod: 'GET',
|
||||
headers: { foo: 'bar' },
|
||||
path: '/apigateway',
|
||||
body: null,
|
||||
});
|
||||
const context = {};
|
||||
const result = await bridge.launcher(
|
||||
{
|
||||
httpMethod: 'GET',
|
||||
headers: { foo: 'bar' },
|
||||
path: '/apigateway',
|
||||
body: null,
|
||||
},
|
||||
context
|
||||
);
|
||||
assert.equal(result.encoding, 'base64');
|
||||
assert.equal(result.statusCode, 200);
|
||||
const body = JSON.parse(Buffer.from(result.body, 'base64').toString());
|
||||
assert.equal(body.method, 'GET');
|
||||
assert.equal(body.path, '/apigateway');
|
||||
assert.equal(body.headers.foo, 'bar');
|
||||
assert.equal(context.callbackWaitsForEmptyEventLoop, false);
|
||||
|
||||
server.close();
|
||||
});
|
||||
|
||||
test('`NowProxyEvent` normalizing', async () => {
|
||||
const server = new Server((req, res) => res.end(
|
||||
JSON.stringify({
|
||||
method: req.method,
|
||||
path: req.url,
|
||||
headers: req.headers,
|
||||
}),
|
||||
));
|
||||
const server = new Server((req, res) =>
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
method: req.method,
|
||||
path: req.url,
|
||||
headers: req.headers,
|
||||
})
|
||||
)
|
||||
);
|
||||
const bridge = new Bridge(server);
|
||||
bridge.listen();
|
||||
const result = await bridge.launcher({
|
||||
Action: 'Invoke',
|
||||
body: JSON.stringify({
|
||||
method: 'POST',
|
||||
headers: { foo: 'baz' },
|
||||
path: '/nowproxy',
|
||||
body: 'body=1',
|
||||
}),
|
||||
});
|
||||
const context = { callbackWaitsForEmptyEventLoop: true };
|
||||
const result = await bridge.launcher(
|
||||
{
|
||||
Action: 'Invoke',
|
||||
body: JSON.stringify({
|
||||
method: 'POST',
|
||||
headers: { foo: 'baz' },
|
||||
path: '/nowproxy',
|
||||
body: 'body=1',
|
||||
}),
|
||||
},
|
||||
context
|
||||
);
|
||||
assert.equal(result.encoding, 'base64');
|
||||
assert.equal(result.statusCode, 200);
|
||||
const body = JSON.parse(Buffer.from(result.body, 'base64').toString());
|
||||
assert.equal(body.method, 'POST');
|
||||
assert.equal(body.path, '/nowproxy');
|
||||
assert.equal(body.headers.foo, 'baz');
|
||||
assert.equal(context.callbackWaitsForEmptyEventLoop, false);
|
||||
|
||||
server.close();
|
||||
});
|
||||
|
||||
@@ -28,11 +28,13 @@ const { shouldServe } = require('@now/build-utils'); // eslint-disable-line impo
|
||||
* @param {string[]} [options.npmArguments]
|
||||
*/
|
||||
async function downloadInstallAndBundle(
|
||||
{ files, entrypoint, workPath },
|
||||
{
|
||||
files, entrypoint, workPath, meta,
|
||||
},
|
||||
{ npmArguments = [] } = {},
|
||||
) {
|
||||
console.log('downloading user files...');
|
||||
const downloadedFiles = await download(files, workPath);
|
||||
const downloadedFiles = await download(files, workPath, meta);
|
||||
|
||||
console.log("installing dependencies for user's code...");
|
||||
const entrypointFsDirname = path.join(workPath, path.dirname(entrypoint));
|
||||
@@ -99,10 +101,12 @@ exports.config = {
|
||||
* @returns {Promise<Files>}
|
||||
*/
|
||||
exports.build = async ({
|
||||
files, entrypoint, config, workPath,
|
||||
files, entrypoint, config, workPath, meta,
|
||||
}) => {
|
||||
const [downloadedFiles, entrypointFsDirname] = await downloadInstallAndBundle(
|
||||
{ files, entrypoint, workPath },
|
||||
{
|
||||
files, entrypoint, workPath, meta,
|
||||
},
|
||||
{ npmArguments: ['--prefer-offline'] },
|
||||
);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/node-server",
|
||||
"version": "0.6.1-canary.2",
|
||||
"version": "0.7.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -8,8 +8,8 @@
|
||||
"directory": "packages/now-node-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@now/node-bridge": "^1.1.0",
|
||||
"@zeit/ncc": "0.18.2",
|
||||
"@now/node-bridge": "^1.1.3",
|
||||
"@zeit/ncc": "0.18.5",
|
||||
"fs-extra": "7.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/node",
|
||||
"version": "0.6.1-canary.2",
|
||||
"version": "0.7.3",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"repository": {
|
||||
@@ -9,8 +9,8 @@
|
||||
"directory": "packages/now-node"
|
||||
},
|
||||
"dependencies": {
|
||||
"@now/node-bridge": "^1.1.0",
|
||||
"@zeit/ncc": "0.18.2",
|
||||
"@now/node-bridge": "^1.1.3",
|
||||
"@zeit/ncc": "0.18.5",
|
||||
"fs-extra": "7.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
FileBlob,
|
||||
FileFsRef,
|
||||
Files,
|
||||
Meta,
|
||||
createLambda,
|
||||
runNpmInstall,
|
||||
runPackageJsonScript,
|
||||
@@ -22,6 +23,7 @@ interface DownloadOptions {
|
||||
files: Files;
|
||||
entrypoint: string;
|
||||
workPath: string;
|
||||
meta?: Meta;
|
||||
npmArguments?: string[];
|
||||
}
|
||||
|
||||
@@ -29,10 +31,11 @@ async function downloadInstallAndBundle({
|
||||
files,
|
||||
entrypoint,
|
||||
workPath,
|
||||
meta,
|
||||
npmArguments = [],
|
||||
}: DownloadOptions) {
|
||||
console.log('downloading user files...');
|
||||
const downloadedFiles = await download(files, workPath);
|
||||
const downloadedFiles = await download(files, workPath, meta);
|
||||
|
||||
console.log("installing dependencies for user's code...");
|
||||
const entrypointFsDirname = join(workPath, dirname(entrypoint));
|
||||
@@ -110,6 +113,7 @@ export async function build({
|
||||
entrypoint,
|
||||
workPath,
|
||||
config,
|
||||
meta,
|
||||
}: BuildOptions) {
|
||||
const {
|
||||
entrypointPath,
|
||||
@@ -118,6 +122,7 @@ export async function build({
|
||||
files,
|
||||
entrypoint,
|
||||
workPath,
|
||||
meta,
|
||||
npmArguments: ['--prefer-offline'],
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/optipng",
|
||||
"version": "0.5.1-canary.0",
|
||||
"version": "0.6.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"files": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/php-bridge",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.2",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -13,11 +13,10 @@ exports.config = {
|
||||
};
|
||||
|
||||
exports.build = async ({
|
||||
files, entrypoint, workPath, config,
|
||||
files, entrypoint, workPath, config, meta,
|
||||
}) => {
|
||||
// Download all files to workPath
|
||||
const fileDir = path.join(workPath, 'userfiles');
|
||||
const downloadedFiles = await download(files, fileDir);
|
||||
const downloadedFiles = await download(files, workPath, meta);
|
||||
|
||||
let includedFiles = {};
|
||||
if (config && config.includeFiles) {
|
||||
@@ -25,7 +24,7 @@ exports.build = async ({
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const pattern of config.includeFiles) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const matchedFiles = await glob(pattern, fileDir);
|
||||
const matchedFiles = await glob(pattern, workPath);
|
||||
Object.assign(includedFiles, matchedFiles);
|
||||
}
|
||||
// explicit and always include the entrypoint
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/php",
|
||||
"version": "0.5.1-canary.0",
|
||||
"version": "0.5.4",
|
||||
"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,4 +1,4 @@
|
||||
import { join, dirname } from 'path';
|
||||
import { join, dirname, basename } from 'path';
|
||||
import execa from 'execa';
|
||||
import fs from 'fs';
|
||||
import { promisify } from 'util';
|
||||
@@ -73,7 +73,16 @@ export const build = async ({
|
||||
meta = {},
|
||||
}: BuildOptions) => {
|
||||
console.log('downloading files...');
|
||||
const downloadedFiles = await download(originalFiles, workPath);
|
||||
let downloadedFiles = await download(originalFiles, workPath, meta);
|
||||
|
||||
if (meta.isDev) {
|
||||
const base = dirname(downloadedFiles['now.json'].fsPath);
|
||||
const destNow = join(base, '.now', 'cache', basename(entrypoint, '.py'));
|
||||
await download(downloadedFiles, destNow);
|
||||
downloadedFiles = await glob('**', destNow);
|
||||
workPath = destNow;
|
||||
}
|
||||
|
||||
const foundLockFile = 'Pipfile.lock' in downloadedFiles;
|
||||
const pyUserBase = await getWriteableDirectory();
|
||||
process.env.PYTHONUSERBASE = pyUserBase;
|
||||
|
||||
@@ -22,6 +22,7 @@ _now_imported, _now_is_legacy = _now_get_import()
|
||||
if _now_is_legacy:
|
||||
print('using HTTP Handler')
|
||||
from http.server import HTTPServer
|
||||
from urllib.parse import unquote
|
||||
import requests
|
||||
import _thread
|
||||
server = HTTPServer(('', 0), _now_imported)
|
||||
@@ -30,7 +31,7 @@ if _now_is_legacy:
|
||||
_thread.start_new_thread(server.handle_request, ())
|
||||
|
||||
payload = json.loads(event['body'])
|
||||
path = payload['path']
|
||||
path = unquote(payload['path'])
|
||||
headers = payload['headers']
|
||||
method = payload['method']
|
||||
encoding = payload.get('encoding')
|
||||
@@ -53,10 +54,7 @@ if _now_is_legacy:
|
||||
else:
|
||||
print('using Web Server Gateway Interface (WSGI)')
|
||||
import sys
|
||||
try:
|
||||
from urllib.parse import urlparse
|
||||
except ImportError:
|
||||
from urlparse import urlparse
|
||||
from urllib.parse import urlparse, unquote
|
||||
from werkzeug._compat import BytesIO
|
||||
from werkzeug._compat import string_types
|
||||
from werkzeug._compat import to_bytes
|
||||
@@ -75,13 +73,14 @@ else:
|
||||
if isinstance(body, string_types):
|
||||
body = to_bytes(body, charset='utf-8')
|
||||
|
||||
urlinfo = urlparse(payload['path'])
|
||||
path = unquote(payload['path'])
|
||||
query = urlparse(path).query
|
||||
|
||||
environ = {
|
||||
'CONTENT_LENGTH': str(len(body)),
|
||||
'CONTENT_TYPE': headers.get('content-type', ''),
|
||||
'PATH_INFO': payload['path'],
|
||||
'QUERY_STRING': urlinfo.query,
|
||||
'PATH_INFO': path,
|
||||
'QUERY_STRING': query,
|
||||
'REMOTE_ADDR': headers.get(
|
||||
'x-forwarded-for', headers.get(
|
||||
'x-real-ip', payload.get(
|
||||
@@ -102,7 +101,7 @@ else:
|
||||
}
|
||||
|
||||
for key, value in environ.items():
|
||||
if isinstance(value, string_types):
|
||||
if isinstance(value, string_types) and key != 'QUERY_STRING':
|
||||
environ[key] = wsgi_encoding_dance(value)
|
||||
|
||||
for key, value in headers.items():
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/python",
|
||||
"version": "0.1.1-canary.2",
|
||||
"version": "0.2.4",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
7
packages/now-python/test/fixtures/09-url-params/custom.py
vendored
Normal file
7
packages/now-python/test/fixtures/09-url-params/custom.py
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
from flask import Flask, Response, __version__
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/', defaults={'path': ''})
|
||||
@app.route('/<path:path>')
|
||||
def catch_all(path):
|
||||
return Response("path=%s" %(path), mimetype='text/html')
|
||||
7
packages/now-python/test/fixtures/09-url-params/index.py
vendored
Normal file
7
packages/now-python/test/fixtures/09-url-params/index.py
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
from flask import Flask, Response, __version__
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/', defaults={'path': ''})
|
||||
@app.route('/<path:path>')
|
||||
def catch_all(path):
|
||||
return Response("path=%s" %(path), mimetype='text/html')
|
||||
13
packages/now-python/test/fixtures/09-url-params/now.json
vendored
Normal file
13
packages/now-python/test/fixtures/09-url-params/now.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{ "src": "*.py", "use": "@now/python" }
|
||||
],
|
||||
"routes": [
|
||||
{ "src": "/another", "dest": "custom.py" }
|
||||
],
|
||||
"probes": [
|
||||
{ "path": "/?hello=/", "mustContain": "path=?hello=/" },
|
||||
{ "path": "/another?hello=/", "mustContain": "path=another?hello=/" }
|
||||
]
|
||||
}
|
||||
1
packages/now-python/test/fixtures/09-url-params/requirements.txt
vendored
Normal file
1
packages/now-python/test/fixtures/09-url-params/requirements.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Flask==1.0.2
|
||||
8
packages/now-python/test/fixtures/10-url-params-http-handler/custom.py
vendored
Normal file
8
packages/now-python/test/fixtures/10-url-params-http-handler/custom.py
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
|
||||
class handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(str("path=").encode()+self.path.encode())
|
||||
return
|
||||
8
packages/now-python/test/fixtures/10-url-params-http-handler/index.py
vendored
Normal file
8
packages/now-python/test/fixtures/10-url-params-http-handler/index.py
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
|
||||
class handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(str("path=").encode()+self.path.encode())
|
||||
return
|
||||
13
packages/now-python/test/fixtures/10-url-params-http-handler/now.json
vendored
Normal file
13
packages/now-python/test/fixtures/10-url-params-http-handler/now.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{ "src": "*.py", "use": "@now/python" }
|
||||
],
|
||||
"routes": [
|
||||
{ "src": "/another", "dest": "custom.py" }
|
||||
],
|
||||
"probes": [
|
||||
{ "path": "/?hello=/", "mustContain": "path=/?hello=/" },
|
||||
{ "path": "/another?hello=/", "mustContain": "path=/another?hello=/" }
|
||||
]
|
||||
}
|
||||
@@ -254,10 +254,10 @@ async function buildSingleFile({
|
||||
|
||||
exports.build = async (m) => {
|
||||
const {
|
||||
files, entrypoint, workPath, config,
|
||||
files, entrypoint, workPath, config, meta,
|
||||
} = m;
|
||||
console.log('downloading files');
|
||||
const downloadedFiles = await download(files, workPath);
|
||||
const downloadedFiles = await download(files, workPath, meta);
|
||||
const entryPath = downloadedFiles[entrypoint].fsPath;
|
||||
|
||||
await installRust();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/rust",
|
||||
"version": "0.2.1-canary.0",
|
||||
"version": "0.2.4",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -88,7 +88,7 @@ exports.build = async ({
|
||||
);
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`Failed to detect a server running on port ${devPort}`,
|
||||
`Failed to detect a server running on port ${devPort}.\nDetails: https://err.sh/zeit/now-builders/now-static-build-failed-to-detect-a-server`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ exports.build = async ({
|
||||
}
|
||||
routes.push({
|
||||
src: `${srcBase}/(.*)`,
|
||||
dest: `http://localhost:${devPort}${srcBase}/$1`,
|
||||
dest: `http://localhost:${devPort}/$1`,
|
||||
});
|
||||
} else {
|
||||
if (meta.isDev) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/static-build",
|
||||
"version": "0.5.3-canary.1",
|
||||
"version": "0.5.7",
|
||||
"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"
|
||||
},
|
||||
|
||||
@@ -28,11 +28,27 @@ async function runBuildLambda(inputPath) {
|
||||
entrypoint,
|
||||
config: build.config,
|
||||
});
|
||||
console.log(analyzeResult);
|
||||
|
||||
const workPath = await getWritableDirectory();
|
||||
const buildResult = await wrapper.build({
|
||||
files: inputFiles, entrypoint, config: build.config, workPath,
|
||||
files: inputFiles,
|
||||
entrypoint,
|
||||
config: build.config,
|
||||
workPath,
|
||||
});
|
||||
const { output } = buildResult;
|
||||
|
||||
// Windows support
|
||||
if (output) {
|
||||
buildResult.output = Object.keys(output).reduce(
|
||||
(result, path) => ({
|
||||
...result,
|
||||
[path.replace(/\\/g, '/')]: output[path],
|
||||
}),
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
analyzeResult,
|
||||
buildResult,
|
||||
|
||||
@@ -1135,10 +1135,10 @@
|
||||
globby "8.0.0"
|
||||
signal-exit "3.0.2"
|
||||
|
||||
"@zeit/ncc@0.18.2":
|
||||
version "0.18.2"
|
||||
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.18.2.tgz#b5f721ec1d23bfe531f3568633689ddab7c05638"
|
||||
integrity sha512-liiuVTcxLaOIGQDftpZ2qhSS/vdEbuvmi2tkBWMfIwIyeKd/sh/jw+l8yONT3/unx/sSmfMTDnwfwUlY+saKiw==
|
||||
"@zeit/ncc@0.18.5":
|
||||
version "0.18.5"
|
||||
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.18.5.tgz#5687df6c32f1a2e2486aa110b3454ccebda4fb9c"
|
||||
integrity sha512-F+SbvEAh8rchiRXqQbmD1UmbePY7dCOKTbvfFtbVbK2xMH/tyri5YKfNxXKK7eL9EWkkbqB3NTVQO6nokApeBA==
|
||||
|
||||
JSONStream@^1.0.4, JSONStream@^1.3.4:
|
||||
version "1.3.5"
|
||||
|
||||
Reference in New Issue
Block a user