Compare commits

...

8 Commits

Author SHA1 Message Date
Steven
d8a5da6a3e Publish
- @now/bash@0.2.0
 - @now/build-utils@0.5.0
 - @now/cgi@0.1.0
 - @now/go@0.4.0
 - @now/html-minifier@1.1.0
 - @now/lambda@0.5.0
 - @now/md@0.5.0
 - @now/mdx-deck@0.5.0
 - @now/next@0.2.0
 - @now/node-bridge@1.1.0
 - @now/node-server@0.6.0
 - @now/node@0.6.0
 - @now/optipng@0.5.0
 - @now/php-bridge@0.5.0
 - @now/php@0.5.0
 - @now/python@0.1.0
 - @now/rust@0.2.0
 - @now/static-build@0.5.0
 - @now/wordpress@0.5.0
2019-04-25 09:19:19 -04:00
Leo Lamprecht
48f7b72bb2 Added missing workPath type property (#426) 2019-04-25 15:05:41 +02:00
Nathan Rajlich
8e2d5de446 [now-static-build] Add now-dev package.json script (#418)
* [static-build] Add `now-dev` package.json script

This will cause `now dev` to run the `now-dev` script as defined in the
`package.json` file.

`now dev` sets the `$PORT` env variable for use in the `now-dev` script,
which is expected to launch a file watching server (for example `hugo
dev`) on the specified `$PORT`. `now dev` wait for this port to be bound
before returning the `build()` function with the generated assets.

The `watch` array is just "watch everything in the
`path.dirname(entrypoint)`" so any file changed within that directory
will trigger a "re-sync" of the source files that `now dev` is working
with, which the user spawned static build watcher should pick up on and
return the updated assets.

* Use `routes` instead of globbing the output dir

Proxy passing to the development server is a cleaner approach, since it
removes the race condition about the builder not having knowledge of
when a dev watcher server rebuilds, so it's not possible to know how
long to wait to return outputs upon another call to `build()`.

* Make `watch` be an array

Co-Authored-By: TooTallNate <n@n8.io>

* Fix `promise-timeout` require()

* Inherit from `process.env` for `yarn run`

Otherwise ENOENT happens because there is no `PATH` env var set

* Only validate dist dir in production builds

* Fix `routes` and `watch` output

* Remove dev logging, add better timeout error message

* Populate `routes` upon rebuild

* Pass `meta` to the `download()` function

* Revert version change in `package.json`

* Save devport sooner
2019-04-25 08:41:38 -04:00
Steven
2b3efb06be Revert "[now-node] Add initial Builder v2 API (#424)" (#425)
This reverts commit dc3f112d4f.
2019-04-24 22:16:37 -04:00
Connor Davis
13e57bf68f [now/next] Set env variable directly 2019-04-24 16:57:00 -05:00
Nathan Rajlich
dc3f112d4f [now-node] Add initial Builder v2 API (#424)
This is a less complete version of #400, since it's still a WIP.
2019-04-24 14:46:02 -07:00
Connor Davis
da1c423033 Publish
- @now/next@0.2.0-canary.45
2019-04-24 14:57:51 -05:00
Connor Davis
5e1d58f0e8 Set target env variable (#423) 2019-04-25 04:16:08 +09:00
23 changed files with 140 additions and 44 deletions

View File

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

View File

@@ -1,6 +1,6 @@
{
"name": "@now/build-utils",
"version": "0.4.41-canary.8",
"version": "0.5.0",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.js",

View File

@@ -1,4 +1,4 @@
import FileRef from "./file-ref";
import FileRef from './file-ref';
import FileFsRef from './file-fs-ref';
export interface File {
@@ -9,11 +9,11 @@ export interface File {
}
export interface Files {
[filePath: string]: File
[filePath: string]: File;
}
export interface Config {
[key: string]: string
[key: string]: string;
}
export interface Meta {
@@ -29,7 +29,7 @@ export interface AnalyzeOptions {
*/
files: {
[filePath: string]: FileRef;
}
};
/**
* Name of entrypoint file for this particular build job. Value
@@ -52,7 +52,6 @@ export interface AnalyzeOptions {
config: Config;
}
export interface BuildOptions {
/**
* All source files of the project
@@ -138,9 +137,15 @@ export interface ShouldServeOptions {
* All source files of the project
*/
files: {
[path: string]: FileFsRef
[path: string]: FileFsRef;
};
/**
* A writable temporary directory where you are encouraged to perform your
* build process. This directory will be populated with the restored cache.
*/
workPath: string;
/**
* An arbitrary object passed by the user in the build definition defined
* in `now.json`.

View File

@@ -1,6 +1,6 @@
{
"name": "@now/cgi",
"version": "0.0.16-canary.0",
"version": "0.1.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/go",
"version": "0.3.1-canary.3",
"version": "0.4.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/html-minifier",
"version": "1.0.8-canary.1",
"version": "1.1.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/lambda",
"version": "0.4.10-canary.1",
"version": "0.5.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/md",
"version": "0.4.10-canary.2",
"version": "0.5.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/mdx-deck",
"version": "0.4.19-canary.2",
"version": "0.5.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/next",
"version": "0.2.0-canary.44",
"version": "0.2.0",
"license": "MIT",
"main": "./dist/index",
"scripts": {
@@ -14,7 +14,7 @@
"directory": "packages/now-next"
},
"dependencies": {
"@now/node-bridge": "^1.0.2-canary.2",
"@now/node-bridge": "^1.1.0",
"fs-extra": "^7.0.0",
"get-port": "^5.0.0",
"resolve-from": "^5.0.0",

View File

@@ -171,6 +171,8 @@ export const build = async ({
);
}
process.env.__NEXT_BUILDER_EXPERIMENTAL_TARGET = 'serverless';
if (meta.isDev) {
// eslint-disable-next-line no-underscore-dangle
process.env.__NEXT_BUILDER_EXPERIMENTAL_DEBUG = 'true';

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node-bridge",
"version": "1.0.2-canary.2",
"version": "1.1.0",
"license": "MIT",
"main": "./index.js",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node-server",
"version": "0.5.4-canary.5",
"version": "0.6.0",
"license": "MIT",
"repository": {
"type": "git",
@@ -8,7 +8,7 @@
"directory": "packages/now-node-server"
},
"dependencies": {
"@now/node-bridge": "^1.0.2-canary.2",
"@now/node-bridge": "^1.1.0",
"@zeit/ncc": "0.18.1",
"fs-extra": "7.0.1"
},

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node",
"version": "0.5.4-canary.6",
"version": "0.6.0",
"license": "MIT",
"main": "./dist/index",
"repository": {
@@ -9,7 +9,7 @@
"directory": "packages/now-node"
},
"dependencies": {
"@now/node-bridge": "^1.0.2-canary.2",
"@now/node-bridge": "^1.1.0",
"@zeit/ncc": "0.18.1",
"fs-extra": "7.0.1"
},

View File

@@ -1,6 +1,6 @@
{
"name": "@now/optipng",
"version": "0.4.9-canary.1",
"version": "0.5.0",
"license": "MIT",
"main": "./dist/index",
"files": [

View File

@@ -1,6 +1,6 @@
{
"name": "@now/php-bridge",
"version": "0.4.16-canary.0",
"version": "0.5.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/php",
"version": "0.4.17-canary.1",
"version": "0.5.0",
"license": "MIT",
"repository": {
"type": "git",
@@ -8,7 +8,7 @@
"directory": "packages/now-php"
},
"dependencies": {
"@now/php-bridge": "^0.4.16-canary.0"
"@now/php-bridge": "^0.5.0"
},
"scripts": {
"test": "jest"

View File

@@ -1,6 +1,6 @@
{
"name": "@now/python",
"version": "0.1.0-canary.2",
"version": "0.1.0",
"main": "index.js",
"license": "MIT",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@now/rust",
"version": "0.1.2-canary.2",
"version": "0.2.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,5 +1,9 @@
const path = require('path');
const { existsSync } = require('fs');
const getPort = require('get-port');
const { promisify } = require('util');
const { timeout } = require('promise-timeout');
const { existsSync, readFileSync } = require('fs');
const waitForPort = promisify(require('wait-for-port'));
const {
glob,
download,
@@ -17,12 +21,16 @@ function validateDistDir(distDir) {
}
}
exports.version = 2;
const nowDevScriptPorts = new Map();
exports.build = async ({
files, entrypoint, workPath, config,
files, entrypoint, workPath, config, meta = {},
}) => {
console.log('downloading user files...');
await download(files, workPath);
console.log('running user scripts...');
await download(files, workPath, meta);
const mountpoint = path.dirname(entrypoint);
const entrypointFsDirname = path.join(workPath, mountpoint);
const distPath = path.join(
@@ -31,13 +39,79 @@ exports.build = async ({
(config && config.distDir) || 'dist',
);
if (path.basename(entrypoint) === 'package.json') {
const entrypointName = path.basename(entrypoint);
if (entrypointName === 'package.json') {
await runNpmInstall(entrypointFsDirname, ['--prefer-offline']);
if (await runPackageJsonScript(entrypointFsDirname, 'now-build')) {
const pkgPath = path.join(workPath, entrypoint);
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
let output = {};
const routes = [];
if (meta.isDev && pkg.scripts && pkg.scripts['now-dev']) {
let devPort = nowDevScriptPorts.get(entrypoint);
if (typeof devPort === 'number') {
console.log('`now-dev` server already running for %j', entrypoint);
} else {
// Run the `now-dev` script out-of-bounds, since it is assumed that
// it will launch a dev server that never "completes"
devPort = await getPort();
nowDevScriptPorts.set(entrypoint, devPort);
const opts = {
env: { ...process.env, PORT: String(devPort) },
};
const promise = runPackageJsonScript(
entrypointFsDirname,
'now-dev',
opts,
);
promise.then(
() => {
nowDevScriptPorts.delete(entrypoint);
},
(err) => {
console.log('`now-dev` script error:', err);
nowDevScriptPorts.delete(entrypoint);
},
);
// Now wait for the server to have listened on `$PORT`, after which we
// will ProxyPass any requests to that development server that come in
// for this builder.
try {
await timeout(waitForPort('localhost', devPort), 60 * 1000);
} catch (err) {
throw new Error(
`Failed to detect a server running on port ${devPort}`,
);
}
console.log('Detected dev server for %j', entrypoint);
}
let srcBase = mountpoint.replace(/^\.\/?/, '');
if (srcBase.length > 0) {
srcBase = `/${srcBase}`;
}
routes.push({
src: `${srcBase}/(.*)`,
dest: `http://localhost:${devPort}${srcBase}/$1`,
});
} else {
// Run the `now-build` script and wait for completion to collect the build
// outputs
console.log('running user "now-build" script from `package.json`...');
if (!(await runPackageJsonScript(entrypointFsDirname, 'now-build'))) {
throw new Error(
`An error running "now-build" script in "${entrypoint}"`,
);
}
validateDistDir(distPath);
return glob('**', distPath, mountpoint);
output = await glob('**', distPath, mountpoint);
}
throw new Error(`An error running "now-build" script in "${entrypoint}"`);
const watch = [path.join(mountpoint.replace(/^\.\/?/, ''), '**/*')];
return { routes, watch, output };
}
if (path.extname(entrypoint) === '.sh') {

View File

@@ -1,6 +1,6 @@
{
"name": "@now/static-build",
"version": "0.4.19-canary.2",
"version": "0.5.0",
"license": "MIT",
"repository": {
"type": "git",
@@ -9,5 +9,10 @@
},
"scripts": {
"test": "jest"
},
"dependencies": {
"get-port": "5.0.0",
"promise-timeout": "1.3.0",
"wait-for-port": "0.0.2"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@now/wordpress",
"version": "0.4.16-canary.0",
"version": "0.5.0",
"license": "MIT",
"repository": {
"type": "git",
@@ -8,7 +8,7 @@
"directory": "packages/now-wordpress"
},
"dependencies": {
"@now/php-bridge": "^0.4.16-canary.0",
"@now/php-bridge": "^0.5.0",
"node-fetch": "2.3.0",
"yauzl": "2.10.0"
},

View File

@@ -3789,18 +3789,18 @@ get-pkg-repo@^1.0.0:
parse-github-repo-url "^1.3.0"
through2 "^2.0.0"
get-port@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc"
integrity sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw=
get-port@^5.0.0:
get-port@5.0.0, get-port@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.0.0.tgz#aa22b6b86fd926dd7884de3e23332c9f70c031a6"
integrity sha512-imzMU0FjsZqNa6BqOjbbW6w5BivHIuQKopjpPqcnx0AVHJQKCxK1O+Ab3OrVXhrekqfVMjwA9ZYu062R+KcIsQ==
dependencies:
type-fest "^0.3.0"
get-port@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc"
integrity sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw=
get-proxy@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/get-proxy/-/get-proxy-1.1.0.tgz#894854491bc591b0f147d7ae570f5c678b7256eb"
@@ -7967,6 +7967,11 @@ promise-retry@^1.1.1:
err-code "^1.0.0"
retry "^0.10.0"
promise-timeout@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/promise-timeout/-/promise-timeout-1.3.0.tgz#d1c78dd50a607d5f0a5207410252a3a0914e1014"
integrity sha512-5yANTE0tmi5++POym6OgtFmwfDvOXABD9oj/jLQr5GPEyuNEb7jH4wbbANJceJid49jwhi1RddxnhnEAb/doqg==
prompts@^0.1.9:
version "0.1.14"
resolved "https://registry.yarnpkg.com/prompts/-/prompts-0.1.14.tgz#a8e15c612c5c9ec8f8111847df3337c9cbd443b2"
@@ -9944,6 +9949,11 @@ w3c-hr-time@^1.0.1:
dependencies:
browser-process-hrtime "^0.1.2"
wait-for-port@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/wait-for-port/-/wait-for-port-0.0.2.tgz#bb5ff253436b9933ab9d65c00d584dc68c4d531a"
integrity sha1-u1/yU0NrmTOrnWXADVhNxoxNUxo=
walker@^1.0.7, walker@~1.0.5:
version "1.0.7"
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb"