Compare commits

...

21 Commits

Author SHA1 Message Date
Igor Klopov
77d445af71 Publish
- @now/bash@0.1.1
 - @now/build-utils@0.4.32
 - @now/cgi@0.0.15
 - @now/go@0.2.12
 - @now/html-minifier@1.0.7
 - @now/lambda@0.4.9
 - @now/md@0.4.9
 - @now/mdx-deck@0.4.18
 - @now/next@0.0.84
 - @now/node-bridge@0.1.10
 - @now/node-server@0.4.26
 - @now/node@0.4.28
 - @now/optipng@0.4.8
 - @now/php-bridge@0.4.13
 - @now/php@0.4.13
 - @now/static-build@0.4.17
 - @now/wordpress@0.4.14
2019-01-20 01:14:09 +03:00
Igor Klopov
79251ad180 [lerna] trying to set the order of package to publish 2019-01-20 00:01:16 +03:00
Igor Klopov
a215dc9103 [node-server] update tests for latest ncc 2019-01-19 23:23:44 +03:00
Nathan Rajlich
ea7d8f0f6c Update @zeit/ncc to v0.11.0 (#172) 2019-01-19 19:30:20 +03:00
Igor Klopov
2232efc984 fix misleading 'running npm install' messages in logs 2019-01-15 00:54:24 +03:00
Igor Klopov
b64ce0f3c0 [now-node] fix test for content-length 2019-01-14 03:27:15 +03:00
Igor Klopov
74233d50ad now/node: bump ncc 2019-01-12 05:20:37 +03:00
Nathan Rajlich
8aebec9fc3 Publish
- @now/bash@0.1.0
2019-01-10 12:27:59 -08:00
Igor Klopov
54584b7763 [tests] support NOW_TOKEN env var 2019-01-09 20:44:20 +03:00
Igor Klopov
d163fcbd71 [now-node-server] test for default content-type 2019-01-09 20:16:58 +03:00
Tim Neutkens
04c2996c76 [now-next] Add test for monorepo 2019-01-09 15:07:54 +01:00
Igor Klopov
2b69b898ed Publish
- @now/build-utils@0.4.32-canary.6
 - @now/node-bridge@0.1.10-canary.2
 - @now/node-server@0.4.26-canary.7
 - @now/node@0.4.28-canary.6
2019-01-08 01:42:13 +03:00
Igor Klopov
846aa11d6a now/node-bridge: postpone rejecting, let express print the error 2019-01-08 01:22:01 +03:00
Nathan Rajlich
a314a74479 Publish
- @now/bash@0.0.4-canary.2
2019-01-04 18:34:29 -08:00
Nathan Rajlich
40f029a72c [now-bash] Pipe response to jq stdin and use long options
Otherwise `jq` errors out with "arguments too long" when the response
body base64 is too large.

The long options are just for maintainability.
2019-01-04 18:33:56 -08:00
Nathan Rajlich
493d8a778f [now-bash] Update static-binaries to v1.0.0 2019-01-04 18:33:56 -08:00
Nathan Rajlich
cb5dcb658f [now-bash] Remove final build tree output
It's not necessary and can be too noisey if the lambda has a lot of files.
2019-01-04 18:33:56 -08:00
Nathan Rajlich
d77287d07b [now-bash] Add .editorconfig file 2019-01-04 18:33:56 -08:00
Igor Klopov
61d66bd957 Publish
- @now/build-utils@0.4.32-canary.5
 - @now/next@0.0.84-canary.0
2019-01-03 16:52:48 +03:00
Igor Klopov
ae73df9e3c build-utils: account google cloud functions 2019-01-03 16:29:55 +03:00
Tim Neutkens
cb09ae5bbf Publish
- @now/next@0.0.83
2019-01-03 11:56:29 +01:00
44 changed files with 186 additions and 70 deletions

View File

@@ -2,7 +2,24 @@
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
"packages/*"
"packages/now-build-utils",
"packages/now-node-bridge",
"packages/now-php-bridge",
"packages/now-bash",
"packages/now-cgi",
"packages/now-go",
"packages/now-html-minifier",
"packages/now-lambda",
"packages/now-md",
"packages/now-mdx-deck",
"packages/now-next",
"packages/now-node",
"packages/now-node-server",
"packages/now-optipng",
"packages/now-php",
"packages/now-python",
"packages/now-static-build",
"packages/now-wordpress"
],
"command": {
"publish": {

View File

@@ -0,0 +1,32 @@
root = true
[*]
indent_style = tab
indent_size = 4
tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{*.json,*.json.example,*.gyp,*.yml}]
indent_style = space
indent_size = 2
[*.py]
indent_style = space
indent_size = 4
[*.md]
trim_trailing_whitespace = false
# Ideal settings - some plugins might support these.
[*.js]
quote_type = single
[{*.c,*.cc,*.h,*.hh,*.cpp,*.hpp,*.m,*.mm,*.mpp,*.js,*.java,*.go,*.rs,*.php,*.ng,*.jsx,*.ts,*.d,*.cs,*.swift}]
curly_bracket_next_line = false
spaces_around_operators = true
spaces_around_brackets = outside
# close enough to 1TB
indent_brace_style = K&R

View File

@@ -38,12 +38,3 @@ if ! declare -f handler > /dev/null; then
echo "ERROR: A \`handler\` function must be defined in \"$ENTRYPOINT\"!" >&2
exit 1
fi
# Show a tree of the final lambda build
show_tree() {
import "static-binaries@0.0.6"
static_binaries tree
echo "Final lambda file tree:"
tree -a .
}
IMPORT_DEBUG= IMPORT_CACHE="$(mktemp -d)" show_tree

View File

@@ -1,6 +1,6 @@
{
"name": "@now/bash",
"version": "0.0.4-canary.1",
"version": "0.1.1",
"description": "Now 2.0 builder for HTTP endpoints written in Bash",
"main": "index.js",
"author": "Nathan Rajlich <nate@zeit.co>",

View File

@@ -1,4 +1,4 @@
import "static-binaries@0.0.6"
import "static-binaries@1.0.0"
static_binaries jq
# These get reset upon each request
@@ -35,7 +35,7 @@ _lambda_runtime_next() {
# Get an event
local event
event="$(mktemp)"
_lambda_runtime_api invocation/next -D "$headers" | jq -r '.body' > "$event"
_lambda_runtime_api invocation/next -D "$headers" | jq --raw-output --monochrome-output '.body' > "$event"
local request_id
request_id="$(grep -Fi Lambda-Runtime-Aws-Request-Id "$headers" | tr -d '[:space:]' | cut -d: -f2)"
@@ -61,28 +61,25 @@ _lambda_runtime_next() {
if [ "$exit_code" -eq 0 ]; then
# Send the response
local response
response="$(jq -cnMr \
jq --raw-input --raw-output --compact-output --slurp --monochrome-output \
--arg statusCode "$(cat "$_STATUS_CODE")" \
--argjson headers "$(cat "$_HEADERS")" \
--arg body "$(base64 --wrap=0 < "$body")" \
'{statusCode:$statusCode|tonumber, headers:$headers, encoding:"base64", body:$body}')"
'{statusCode:$statusCode|tonumber, headers:$headers, encoding:"base64", body:.|@base64}' < "$body" \
| _lambda_runtime_api "invocation/$request_id/response" -X POST -d @- > /dev/null
rm -f "$body" "$_HEADERS"
_lambda_runtime_api "invocation/$request_id/response" -X POST -d "$response" > /dev/null
else
echo "\`handler\` function return code: $exit_code"
local error='{"exitCode":'"$exit_code"'}'
_lambda_runtime_api "invocation/$request_id/error" -X POST -d "$error" > /dev/null
_lambda_runtime_api "invocation/$request_id/error" -X POST -d @- > /dev/null <<< '{"exitCode":'"$exit_code"'}'
fi
}
_lambda_runtime_body() {
if [ "$(jq -r '.body | type' < "$1")" = "string" ]; then
if [ "$(jq -r '.encoding' < "$1")" = "base64" ]; then
jq -r '.body' < "$1" | base64 -d
if [ "$(jq --raw-output '.body | type' < "$1")" = "string" ]; then
if [ "$(jq --raw-output '.encoding' < "$1")" = "base64" ]; then
jq --raw-output '.body' < "$1" | base64 -d
else
# assume plain-text body
jq -r '.body' < "$1"
jq --raw-output '.body' < "$1"
fi
fi
}

View File

@@ -56,7 +56,7 @@ class FileRef {
const resp = await fetch(url);
if (!resp.ok) {
const error = new BailableError(
`${resp.status} ${resp.statusText}`,
`download: ${resp.status} ${resp.statusText} for ${url}`,
);
if (resp.status === 403) error.bail = true;
throw error;

View File

@@ -1,8 +1,8 @@
const path = require('path');
const fs = require('fs-extra');
const dev = !process.env.AWS_EXECUTION_ENV;
const TMP_PATH = dev ? path.join(process.cwd(), 'tmp') : '/tmp';
const prod = process.env.AWS_EXECUTION_ENV || process.env.X_GOOGLE_CODE_LOCATION;
const TMP_PATH = prod ? '/tmp' : path.join(__dirname, 'tmp');
module.exports = async function getWritableDirectory() {
const name = Math.floor(Math.random() * 0x7fffffff).toString(16);

View File

@@ -3,6 +3,9 @@ const fs = require('fs-extra');
const path = require('path');
const { spawn } = require('child_process');
const prod = process.env.AWS_EXECUTION_ENV
|| process.env.X_GOOGLE_CODE_LOCATION;
function spawnAsync(command, args, cwd) {
return new Promise((resolve, reject) => {
const child = spawn(command, args, { stdio: 'inherit', cwd });
@@ -52,7 +55,7 @@ async function scanParentDirs(destPath, scriptName) {
return { hasScript, hasPackageLockJson };
}
async function runNpmInstall(destPath, args = []) {
async function installDependencies(destPath, args = []) {
assert(path.isAbsolute(destPath));
let commandArgs = args;
@@ -63,7 +66,7 @@ async function runNpmInstall(destPath, args = []) {
commandArgs = args.filter(a => a !== '--prefer-offline');
await spawnAsync('npm', ['install'].concat(commandArgs), destPath);
await spawnAsync('npm', ['cache', 'clean', '--force'], destPath);
} else if (process.env.AWS_EXECUTION_ENV) {
} else if (prod) {
console.log('using memory-fs for yarn cache');
await spawnAsync(
'node',
@@ -99,6 +102,7 @@ async function runPackageJsonScript(destPath, scriptName) {
module.exports = {
runShellScript,
runNpmInstall,
installDependencies,
runNpmInstall: installDependencies,
runPackageJsonScript,
};

View File

@@ -1,6 +1,6 @@
{
"name": "@now/build-utils",
"version": "0.4.32-canary.4",
"version": "0.4.32",
"license": "MIT",
"dependencies": {
"async-retry": "1.2.3",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/cgi",
"version": "0.0.15-canary.0",
"version": "0.0.15",
"license": "MIT",
"scripts": {
"test": "best -I test/*.js",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/go",
"version": "0.2.12-canary.0",
"version": "0.2.12",
"license": "MIT",
"scripts": {
"test": "best -I test/*.js",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/html-minifier",
"version": "1.0.7-canary.0",
"version": "1.0.7",
"license": "MIT",
"dependencies": {
"html-minifier": "3.5.21"

View File

@@ -1,6 +1,6 @@
{
"name": "@now/lambda",
"version": "0.4.9-canary.0",
"version": "0.4.9",
"license": "MIT",
"peerDependencies": {
"@now/build-utils": ">=0.0.1"

View File

@@ -1,6 +1,6 @@
{
"name": "@now/md",
"version": "0.4.9-canary.0",
"version": "0.4.9",
"license": "MIT",
"dependencies": {
"rehype-document": "^2.2.0",

View File

@@ -15,7 +15,7 @@ exports.build = async ({ files, entrypoint, workPath }) => {
const packageJson = { dependencies: { 'mdx-deck': '1.7.15' } };
const packageJsonPath = path.join(workPath, 'package.json');
await writeFile(packageJsonPath, JSON.stringify(packageJson));
console.log('running npm install...');
console.log('installing dependencies...');
process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = '1'; // TODO opts argument for runNpmInstall
await runNpmInstall(path.dirname(packageJsonPath), [
'--prod',

View File

@@ -1,6 +1,6 @@
{
"name": "@now/mdx-deck",
"version": "0.4.18-canary.1",
"version": "0.4.18",
"license": "MIT",
"peerDependencies": {
"@now/build-utils": ">=0.0.1"

View File

@@ -168,7 +168,7 @@ exports.build = async ({ files, workPath, entrypoint }) => {
await writeNpmRc(workPath, process.env.NPM_AUTH_TOKEN);
}
console.log('running npm install...');
console.log('installing dependencies...');
await runNpmInstall(workPath, ['--prefer-offline']);
console.log('running user script...');
await runPackageJsonScript(workPath, 'now-build');

View File

@@ -1,6 +1,6 @@
{
"name": "@now/next",
"version": "0.0.83-canary.0",
"version": "0.0.84",
"license": "MIT",
"dependencies": {
"@now/node-bridge": "0.1.4",

View File

@@ -91,7 +91,14 @@ class Bridge {
});
});
req.on('error', reject);
req.on('error', (error) => {
setTimeout(() => {
// this lets express print the true error of why the connection was closed.
// it is probably 'Cannot set headers after they are sent to the client'
reject(error);
}, 2);
});
if (body) req.write(body);
req.end();
});

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node-bridge",
"version": "0.1.10-canary.1",
"version": "0.1.10",
"license": "MIT",
"peerDependencies": {
"@now/build-utils": ">=0.0.1"

View File

@@ -37,7 +37,7 @@ async function downloadInstallAndBundle(
console.log('downloading user files...');
const downloadedFiles = await download(files, userPath);
console.log('running npm install for user...');
console.log('installing dependencies for user\'s code...');
const entrypointFsDirname = path.join(userPath, path.dirname(entrypoint));
await runNpmInstall(entrypointFsDirname, npmArguments);
@@ -47,7 +47,7 @@ async function downloadInstallAndBundle(
'package.json': new FileBlob({
data: JSON.stringify({
dependencies: {
'@zeit/ncc': '0.6.0',
'@zeit/ncc': '0.11.0',
},
}),
}),
@@ -55,7 +55,7 @@ async function downloadInstallAndBundle(
nccPath,
);
console.log('running npm install for ncc...');
console.log('installing dependencies for ncc...');
await runNpmInstall(nccPath, npmArguments);
return [downloadedFiles, userPath, nccPath, entrypointFsDirname];
}
@@ -71,7 +71,8 @@ async function compile(workNccPath, downloadedFiles, entrypoint) {
preparedFiles[path.join('user', entrypoint)] = blob;
// eslint-disable-next-line no-restricted-syntax
for (const assetName of Object.keys(assets)) {
const blob2 = new FileBlob({ data: assets[assetName] });
const { source: data, permissions: mode } = assets[assetName];
const blob2 = new FileBlob({ data, mode });
preparedFiles[
path.join('user', path.dirname(entrypoint), assetName)
] = blob2;

View File

@@ -1,9 +1,9 @@
{
"name": "@now/node-server",
"version": "0.4.26-canary.6",
"version": "0.4.26",
"license": "MIT",
"dependencies": {
"@now/node-bridge": "^0.1.10-canary.1",
"@now/node-bridge": "^0.1.10",
"fs-extra": "7.0.1"
},
"peerDependencies": {

View File

@@ -0,0 +1,7 @@
const http = require('http');
const server = http.createServer((req, resp) => {
resp.end('RANDOMNESS_PLACEHOLDER');
});
server.listen();

View File

@@ -0,0 +1,6 @@
{
"version": 2,
"builds": [
{ "src": "index.js", "use": "@now/node-server" }
]
}

View File

@@ -0,0 +1,7 @@
const assert = require('assert');
module.exports = async ({ deploymentUrl, fetch, randomness }) => {
const resp = await fetch(`https://${deploymentUrl}/`);
assert.equal(resp.headers.get('content-type'), null);
assert.equal(await resp.text(), randomness);
};

View File

@@ -2,7 +2,7 @@ const http = require('http');
const isBundled = require('./is-bundled.js');
const server = http.createServer((req, resp) => {
resp.end(isBundled() ? 'RANDOMNESS_PLACEHOLDER:with-bundle' : '');
resp.end(isBundled() ? 'RANDOMNESS_PLACEHOLDER:with-bundle' : 'WITHOUT-BUNDLE-THAT-IS-WRONG');
});
server.listen();

View File

@@ -1,3 +1,4 @@
const path = require('path');
module.exports = () => path.basename(__filename) === 'index.js';
// eslint-disable-next-line no-eval
module.exports = () => path.basename(eval('__filename')) === 'index.js';

View File

@@ -2,7 +2,7 @@ const http = require('http');
const isBundled = require('./is-bundled.js');
const server = http.createServer((req, resp) => {
resp.end(isBundled() ? '' : 'RANDOMNESS_PLACEHOLDER:without-bundle');
resp.end(isBundled() ? 'WITH-BUNDLE-THAT-IS-WRONG' : 'RANDOMNESS_PLACEHOLDER:without-bundle');
});
server.listen();

View File

@@ -1,3 +1,4 @@
const path = require('path');
module.exports = () => path.basename(__filename) === 'index.js';
// eslint-disable-next-line no-eval
module.exports = () => path.basename(eval('__filename')) === 'index.js';

View File

@@ -35,7 +35,7 @@ async function downloadInstallAndBundle(
console.log('downloading user files...');
const downloadedFiles = await download(files, userPath);
console.log('running npm install for user...');
console.log('installing dependencies for user\'s code...');
const entrypointFsDirname = path.join(userPath, path.dirname(entrypoint));
await runNpmInstall(entrypointFsDirname, npmArguments);
@@ -45,7 +45,7 @@ async function downloadInstallAndBundle(
'package.json': new FileBlob({
data: JSON.stringify({
dependencies: {
'@zeit/ncc': '0.6.0',
'@zeit/ncc': '0.11.0',
},
}),
}),
@@ -53,7 +53,7 @@ async function downloadInstallAndBundle(
nccPath,
);
console.log('running npm install for ncc...');
console.log('installing dependencies for ncc...');
await runNpmInstall(nccPath, npmArguments);
return [downloadedFiles, nccPath, entrypointFsDirname];
}
@@ -69,7 +69,8 @@ async function compile(workNccPath, downloadedFiles, entrypoint) {
preparedFiles[path.join('user', entrypoint)] = blob;
// eslint-disable-next-line no-restricted-syntax
for (const assetName of Object.keys(assets)) {
const blob2 = new FileBlob({ data: assets[assetName] });
const { source: data, permissions: mode } = assets[assetName];
const blob2 = new FileBlob({ data, mode });
preparedFiles[
path.join('user', path.dirname(entrypoint), assetName)
] = blob2;

View File

@@ -1,9 +1,9 @@
{
"name": "@now/node",
"version": "0.4.28-canary.5",
"version": "0.4.28",
"license": "MIT",
"dependencies": {
"@now/node-bridge": "^0.1.10-canary.1",
"@now/node-bridge": "^0.1.10",
"fs-extra": "7.0.1"
},
"peerDependencies": {

View File

@@ -4,21 +4,24 @@ async function test1({ deploymentUrl, fetch, randomness }) {
const bodyMustBe = `${randomness}:content-length`;
const resp = await fetch(`https://${deploymentUrl}/test1.js`);
assert.equal(resp.status, 401);
assert.equal(resp.headers.get('content-length'), bodyMustBe.length);
assert.equal(await resp.text(), bodyMustBe);
assert.equal(resp.headers.get('content-length'), bodyMustBe.length);
}
async function test2({ deploymentUrl, fetch }) {
const bodyMustBe = '';
const resp = await fetch(`https://${deploymentUrl}/test2.js`);
assert.equal(resp.status, 502);
assert.equal(resp.status, 401);
assert.equal(await resp.text(), bodyMustBe);
assert.equal(resp.headers.get('content-length'), bodyMustBe.length);
}
async function test3({ deploymentUrl, fetch, randomness }) {
const bodyMustBe = `${randomness}:content-length`;
const resp = await fetch(`https://${deploymentUrl}/test3.js`);
assert.equal(resp.status, 401);
assert.equal(resp.headers.get('content-length'), null);
assert.equal(await resp.text(), bodyMustBe);
assert.equal(resp.headers.get('content-length'), null);
}
module.exports = async ({ deploymentUrl, fetch, randomness }) => {

View File

@@ -1,4 +1,4 @@
module.exports = (_, resp) => {
resp.writeHead(401, { 'content-length': 2 });
resp.end(`${process.env.RANDOMNESS_ENV_VAR}:content-length`);
resp.end();
};

View File

@@ -1,6 +1,6 @@
{
"name": "@now/optipng",
"version": "0.4.8-canary.0",
"version": "0.4.8",
"license": "MIT",
"dependencies": {
"multipipe": "2.0.3",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/php-bridge",
"version": "0.4.13-canary.1",
"version": "0.4.13",
"license": "MIT",
"dependencies": {
"fastcgi-client": "0.0.1"

View File

@@ -1,9 +1,9 @@
{
"name": "@now/php",
"version": "0.4.13-canary.2",
"version": "0.4.13",
"license": "MIT",
"dependencies": {
"@now/php-bridge": "^0.4.13-canary.1"
"@now/php-bridge": "^0.4.13"
},
"peerDependencies": {
"@now/build-utils": ">=0.0.1"

View File

@@ -1,6 +1,6 @@
{
"name": "@now/static-build",
"version": "0.4.17-canary.0",
"version": "0.4.17",
"license": "MIT",
"peerDependencies": {
"@now/build-utils": ">=0.0.1"

View File

@@ -1,9 +1,9 @@
{
"name": "@now/wordpress",
"version": "0.4.14-canary.1",
"version": "0.4.14",
"license": "MIT",
"dependencies": {
"@now/php-bridge": "^0.4.13-canary.1",
"@now/php-bridge": "^0.4.13",
"node-fetch": "2.3.0",
"yauzl": "2.10.0"
},

View File

@@ -20,6 +20,22 @@ it(
FOUR_MINUTES,
);
it(
'Should build the monorepo example',
async () => {
const { buildResult } = await runBuildLambda(
path.join(__dirname, 'monorepo'),
);
expect(buildResult['www/index']).toBeDefined();
const filePaths = Object.keys(buildResult);
const hasUnderScoreAppStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_app\.js$/));
const hasUnderScoreErrorStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_error\.js$/));
expect(hasUnderScoreAppStaticFile).toBeTruthy();
expect(hasUnderScoreErrorStaticFile).toBeTruthy();
},
FOUR_MINUTES,
);
it(
'Should build the legacy standard example',
async () => {

View File

@@ -0,0 +1,6 @@
{
"version": 2,
"builds": [
{ "src": "www/package.json", "use": "@now/next" }
]
}

View File

@@ -0,0 +1,3 @@
module.exports = {
target: 'serverless',
};

View File

@@ -0,0 +1,11 @@
{
"name": "monorepo",
"dependencies": {
"next": "^8.0.0-canary.2",
"react": "^16.7.0",
"react-dom": "^16.7.0"
},
"scripts": {
"now-build": "next build"
}
}

View File

@@ -0,0 +1 @@
export default () => 'Index page';

View File

@@ -114,7 +114,11 @@ async function fetchWithAuth (url, opts = {}) {
if (!opts.headers.Authorization) {
if (!token) {
const { NOW_TOKEN_FACTORY_URL } = process.env;
const { NOW_TOKEN, NOW_TOKEN_FACTORY_URL } = process.env;
if (NOW_TOKEN) {
token = NOW_TOKEN;
} else
if (NOW_TOKEN_FACTORY_URL) {
const resp = await fetch(NOW_TOKEN_FACTORY_URL);
token = (await resp.json()).token;