Compare commits

...

56 Commits

Author SHA1 Message Date
Igor Klopov
9a93713158 Publish
- @now/build-utils@0.4.30
 - @now/cgi@0.0.13
 - @now/go@0.2.10
 - @now/html-minifier@1.0.6
 - @now/lambda@0.4.7
 - @now/md@0.4.7
 - @now/mdx-deck@0.4.16
 - @now/next@0.0.80
 - @now/node-bridge@0.1.9
 - @now/node-server@0.4.24
 - @now/node@0.4.26
 - @now/optipng@0.4.7
 - @now/php@0.4.11
 - @now/python@0.0.40
 - @now/static-build@0.4.15
2018-11-26 04:16:16 +03:00
Igor Klopov
3392ef5636 [now-php] compile launcher binary 2018-11-26 03:48:52 +03:00
Igor Klopov
9236e2b584 Publish
- @now/build-utils@0.4.30-canary.6
 - @now/node-server@0.4.24-canary.8
 - @now/node@0.4.26-canary.8
 - @now/php@0.4.11-canary.7
 - @now/static-build@0.4.15-canary.7
2018-11-26 02:44:14 +03:00
Igor Klopov
ffc4686ab9 now/node-server: take assets from ncc into zip 2018-11-25 22:28:58 +03:00
Igor Klopov
1ff4b6bb4b now/node: take assets from ncc into zip 2018-11-25 22:15:07 +03:00
Igor Klopov
0e7d8c3ff1 node-server and node: bump ncc, yet without assets 2018-11-25 21:18:08 +03:00
Igor Klopov
86885b8c38 yarn/npm test for build-utils 2018-11-25 20:48:29 +03:00
Igor Klopov
8563f2b8b5 remove confusing now-build script not found from logs 2018-11-25 17:58:31 +03:00
Igor Klopov
c36938bd95 Tests for now/build-utils (#74)
* rearrange testDeployment arguments

* added tests for build-utils

* print what page failed probe check

* make opposing package be always at least canary
2018-11-25 05:16:17 +03:00
Igor Klopov
957ab6c4e3 Publish
- @now/cgi@0.0.13-canary.6
 - @now/go@0.2.10-canary.6
 - @now/node-server@0.4.24-canary.7
 - @now/node@0.4.26-canary.7
 - @now/php@0.4.11-canary.6
 - @now/static-build@0.4.15-canary.6
2018-11-24 02:35:01 +03:00
Nathan Rajlich
069e9b4052 [circle-ci] set GOPATH to ~/go (#72)
Attempting to fix this error:

```
> @now/cgi@0.0.13-canary.3 prepublish /home/circleci/repo/packages/now-cgi
> ./build.sh

main.go:14:2: cannot find package "github.com/aws/aws-lambda-go/events" in any of:
	/usr/lib/go/src/pkg/github.com/aws/aws-lambda-go/events (from $GOROOT)
	($GOPATH not set)
main.go:15:2: cannot find package "github.com/aws/aws-lambda-go/lambda" in any of:
	/usr/lib/go/src/pkg/github.com/aws/aws-lambda-go/lambda (from $GOROOT)
	($GOPATH not set)
```
2018-11-23 22:13:13 +01:00
Igor Klopov
0b06704be6 More tests 2 (#71)
* rename to let cowsays be together

* test for script.sh for static-build

* make env-vars 03 across builders

* 03-env-vars test for static-build
2018-11-23 17:44:07 +03:00
Igor Klopov
cf5a49e699 Node-server bundle=false (#70)
* copy node-server/index.js from node/index.js

* no need to promisify fs if we have fs-extra

* few renames to clarify what for they are

* node-server: config.bundle = false

* builder code fixes and tests

* fix maxLambdaSize back
2018-11-23 04:51:09 +03:00
Matheus Fernandes
b671b23d8d [now-go] Fix typo when setting the Host value (#66)
* `req.Host` -> `internalReq.Host`

* Add comments
2018-11-22 14:50:31 -08:00
Igor Klopov
fa44c23225 env vars test for now/php (#68) 2018-11-22 21:40:13 +03:00
Igor Klopov
ba9da3cec5 collect test fixtures via readdir 2018-11-22 17:27:17 +03:00
Igor Klopov
0909aaf2b3 Test env vars (#65)
* move 02-others to 10-others

* add 02-env-vars for node-server

* added 02-env-vars for now/node
2018-11-22 15:14:35 +03:00
Nathan Rajlich
e276342a6f [now-cgi] add HTTPS and SERVER_SOFTWARE env vars 2018-11-21 15:51:44 -08:00
Igor Klopov
f6e1bdf0a1 simple test for now/php 2018-11-22 02:29:50 +03:00
Igor Klopov
2c2189b661 add npmignore to prevent publishing 'test' directory 2018-11-22 01:43:29 +03:00
Igor Klopov
61522e2bc7 show deploymentUrl if state is ERROR. othw not clear from ci logs 2018-11-21 23:01:51 +03:00
Igor Klopov
a20f3a5920 test for static-build with 300 generated files 2018-11-21 22:40:23 +03:00
Igor Klopov
a5e58c2a8d bump to ncc 0.1.6 and enable apollo test 2018-11-21 22:26:41 +03:00
Igor Klopov
a58451548f simple tests for now/static-build 2018-11-21 19:11:52 +03:00
Igor Klopov
8e846c50b5 Pack testing 3 (#58)
* produce builder targz in jest.beforeAll

* improve fetchDeploymentUrl

* wait for deployment to become READY
2018-11-21 05:30:22 +03:00
Igor Klopov
7613dcf68b Pack testing 2 (#57)
* include new pack testing into 'yarn test'

* take now auth token from env var

* mkdirp(authJsonPath)
2018-11-21 00:21:03 +03:00
Nathan Rajlich
bea499cad3 [@now/php] remove unnecessary log line upon cold start (#44) 2018-11-20 11:46:28 -08:00
Igor Klopov
0f20a0dbbf [wip] Pack testing (#51)
* test.js packs and deploys static targz

* test.js deploys a fixture using the targz

* randomness, RANDOMNESS_PLACEHOLDER to prevent stale data

* test.js tests if randomness is present

* make test-deployment.js shared

* remove package.json.name

* nowDeploy: pass routes from now.json

* make apollo test work

* simplify test logs

* same page content that does not match a test. for inspection

* added cowsay to node-server

* distinguish mustContain values to prevent them intersect

* separate step packAndDeploy

* test for process.env.NODE_ENV replacement

* fetchBuilderUrl to wait for targz is deployed
2018-11-20 21:13:38 +03:00
Igor Klopov
1ea30588a3 Publish
- @now/node-server@0.4.24-canary.6
 - @now/node@0.4.26-canary.6
2018-11-20 19:20:22 +03:00
Igor Klopov
a3b670675a [node] bump zeit/ncc 2018-11-20 19:16:57 +03:00
Tim Neutkens
c4374fe5a8 Publish
- @now/next@0.0.80-canary.0
2018-11-20 00:05:45 +01:00
Tim Neutkens
c3983ba1c2 @now/next Use next build --lambdas to bundle node_modules (#54) 2018-11-19 17:00:47 -06:00
Tim Neutkens
ae1be4b243 @now/next Add maxLambdaSize 2018-11-19 12:15:31 +01:00
Tim Neutkens
b4b1131619 Publish
- @now/next@0.0.79-canary.7
2018-11-19 02:06:09 +01:00
Tim Neutkens
5fd923a7e7 Add stable publish script 2018-11-19 01:57:54 +01:00
Tim Neutkens
f4e95eb59c Publish
- @now/next@0.0.79-canary.7
2018-11-19 01:36:53 +01:00
Tim Neutkens
a6cdaccd34 @now/next add integration test for custom dependencies 2018-11-19 01:35:22 +01:00
Tim Neutkens
4f5fe8eba8 @now/next Fix normalizePackageJson types 2018-11-19 01:06:14 +01:00
Tim Neutkens
7239013989 Don’t run build on tags, only branches 2018-11-19 00:44:15 +01:00
Tim Neutkens
75000ee334 Publish
- @now/next@0.0.79-canary.6
2018-11-19 00:40:04 +01:00
Tim Neutkens
5319610d59 @now/next add normalized package.json logging 2018-11-19 00:39:37 +01:00
Tim Neutkens
6df0d69afa Add passing test for real world package.json 2018-11-19 00:28:48 +01:00
Tim Neutkens
65b191f6b9 Publish
- @now/build-utils@0.4.30-canary.5
 - @now/cgi@0.0.13-canary.5
 - @now/go@0.2.10-canary.5
 - @now/html-minifier@1.0.6-canary.5
 - @now/lambda@0.4.7-canary.5
 - @now/md@0.4.7-canary.5
 - @now/mdx-deck@0.4.16-canary.5
 - @now/next@0.0.79-canary.5
 - @now/node-bridge@0.1.9-canary.5
 - @now/node-server@0.4.24-canary.5
 - @now/node@0.4.26-canary.5
 - @now/optipng@0.4.7-canary.5
 - @now/php@0.4.11-canary.5
 - @now/python@0.0.40-canary.5
 - @now/static-build@0.4.15-canary.5
2018-11-18 17:04:46 +01:00
Tim Neutkens
115f62bbba Set gopath temporarily 2018-11-18 17:02:23 +01:00
Tim Neutkens
cdf6a98a18 Publish
- @now/build-utils@0.4.30-canary.4
 - @now/cgi@0.0.13-canary.4
 - @now/go@0.2.10-canary.4
 - @now/html-minifier@1.0.6-canary.4
 - @now/lambda@0.4.7-canary.4
 - @now/md@0.4.7-canary.4
 - @now/mdx-deck@0.4.16-canary.4
 - @now/next@0.0.79-canary.4
 - @now/node-bridge@0.1.9-canary.4
 - @now/node-server@0.4.24-canary.4
 - @now/node@0.4.26-canary.4
 - @now/optipng@0.4.7-canary.4
 - @now/php@0.4.11-canary.4
 - @now/python@0.0.40-canary.4
 - @now/static-build@0.4.15-canary.4
2018-11-18 16:50:10 +01:00
Tim Neutkens
bb75dfd993 Manually get dependencies 2018-11-18 16:48:57 +01:00
Tim Neutkens
b63062cfc5 Publish
- @now/build-utils@0.4.30-canary.3
 - @now/cgi@0.0.13-canary.3
 - @now/go@0.2.10-canary.3
 - @now/html-minifier@1.0.6-canary.3
 - @now/lambda@0.4.7-canary.3
 - @now/md@0.4.7-canary.3
 - @now/mdx-deck@0.4.16-canary.3
 - @now/next@0.0.79-canary.3
 - @now/node-bridge@0.1.9-canary.3
 - @now/node-server@0.4.24-canary.3
 - @now/node@0.4.26-canary.3
 - @now/optipng@0.4.7-canary.3
 - @now/php@0.4.11-canary.3
 - @now/python@0.0.40-canary.3
 - @now/static-build@0.4.15-canary.3
2018-11-18 16:23:55 +01:00
Tim Neutkens
5ad6dabd96 Use if/else so that build will fail when lerna fails 2018-11-18 16:23:10 +01:00
Tim Neutkens
30060bee07 Publish
- @now/build-utils@0.4.30-canary.2
 - @now/cgi@0.0.13-canary.2
 - @now/go@0.2.10-canary.2
 - @now/html-minifier@1.0.6-canary.2
 - @now/lambda@0.4.7-canary.2
 - @now/md@0.4.7-canary.2
 - @now/mdx-deck@0.4.16-canary.2
 - @now/next@0.0.79-canary.2
 - @now/node-bridge@0.1.9-canary.2
 - @now/node-server@0.4.24-canary.2
 - @now/node@0.4.26-canary.2
 - @now/optipng@0.4.7-canary.2
 - @now/php@0.4.11-canary.2
 - @now/python@0.0.40-canary.2
 - @now/static-build@0.4.15-canary.2
2018-11-18 16:14:10 +01:00
Tim Neutkens
dd48a1c6d3 Fall back to showing did not publish 2018-11-18 16:11:46 +01:00
Tim Neutkens
24d45736f1 If describe fails force null 2018-11-18 16:06:36 +01:00
Tim Neutkens
d839fdbe81 Only run on exact tag matches 2018-11-18 15:59:03 +01:00
Tim Neutkens
cfdcd2f8d0 Make git describe not fail on no tag 2018-11-18 15:53:20 +01:00
Tim Neutkens
b3cac2b372 Manually match tags and publish 2018-11-18 15:46:22 +01:00
Tim Neutkens
9d27d69656 Publish
- @now/build-utils@0.4.30-canary.1
 - @now/cgi@0.0.13-canary.1
 - @now/go@0.2.10-canary.1
 - @now/html-minifier@1.0.6-canary.1
 - @now/lambda@0.4.7-canary.1
 - @now/md@0.4.7-canary.1
 - @now/mdx-deck@0.4.16-canary.1
 - @now/next@0.0.79-canary.1
 - @now/node-bridge@0.1.9-canary.1
 - @now/node-server@0.4.24-canary.1
 - @now/node@0.4.26-canary.1
 - @now/optipng@0.4.7-canary.1
 - @now/php@0.4.11-canary.1
 - @now/python@0.0.40-canary.1
 - @now/static-build@0.4.15-canary.1
2018-11-18 14:55:52 +01:00
Tim Neutkens
04197b250c Run build for tags 2018-11-18 14:52:57 +01:00
103 changed files with 2297 additions and 176 deletions

View File

@@ -4,6 +4,8 @@ jobs:
docker:
- image: circleci/node:10
working_directory: ~/repo
environment:
GOPATH: $HOME/go
steps:
- checkout
- run:
@@ -24,64 +26,17 @@ jobs:
- run:
name: Tests
command: yarn test
publish-stable:
docker:
- image: circleci/node:10
working_directory: ~/repo
steps:
- checkout
- run:
name: Updating apt-get list
command: sudo apt-get update
name: Potentially save npm token
command: "([[ ! -z $NPM_TOKEN ]] && echo \"//registry.npmjs.org/:_authToken=$NPM_TOKEN\" >> ~/.npmrc) || echo \"Did not write npm token\""
- run:
name: Installing the latest version of Go
command: sudo apt-get install golang-go
- run: yarn install
- run: yarn bootstrap
name: Potentially publish canary release
command: "if ls ~/.npmrc >/dev/null 2>&1 && [[ $(git describe --exact-match 2> /dev/null || :) =~ -canary ]]; then yarn run lerna publish from-git --npm-tag canary --yes; else echo \"Did not publish\"; fi"
- run:
name: Saving Authentication Information
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Publishing to Stable Channel
command: yarn run lerna publish from-git --yes
publish-canary:
docker:
- image: circleci/node:10
working_directory: ~/repo
steps:
- checkout
- run:
name: Updating apt-get list
command: sudo apt-get update
- run:
name: Installing the latest version of Go
command: sudo apt-get install golang-go
- run: yarn install
- run: yarn bootstrap
- run:
name: Saving Authentication Information
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Publishing to Stable Channel
command: yarn run lerna publish from-git --npm-tag canary --yes
name: Potentially publish stable release
command: "if ls ~/.npmrc >/dev/null 2>&1 && [[ ! $(git describe --exact-match 2> /dev/null || :) =~ -canary ]]; then yarn run lerna publish from-git --yes; else echo \"Did not publish\"; fi"
workflows:
version: 2
build-and-deploy:
jobs:
- build
- publish-stable:
requires:
- build
filters:
tags:
only: /.*\d+\.\d+\.\d+$/
branches:
ignore: /.*/
- publish-canary:
requires:
- build
filters:
tags:
only: /.*-canary.*$/
branches:
ignore: /.*/

View File

@@ -1,5 +1,4 @@
module.exports = {
testEnvironment: 'node',
rootDir: 'test',
collectCoverageFrom: ['packages/**/*.{js,jsx}', '!**/node_modules/**'],
};

View File

@@ -34,8 +34,11 @@
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-import": "^2.14.0",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"jest": "^23.6.0",
"lint-staged": "^8.0.4",
"node-fetch": "^2.3.0",
"pre-commit": "^1.2.2",
"prettier": "^1.15.2",
"typescript": "^3.1.6"

View File

@@ -0,0 +1 @@
/test

View File

@@ -1,3 +1,4 @@
const assert = require('assert');
const fs = require('fs-extra');
const path = require('path');
const { spawn } = require('child_process');
@@ -13,22 +14,34 @@ function spawnAsync(command, args, cwd) {
}
async function runShellScript(fsPath) {
assert(path.isAbsolute(fsPath));
const destPath = path.dirname(fsPath);
await spawnAsync(`./${path.basename(fsPath)}`, [], destPath);
return true;
}
async function shouldUseNpm(destPath) {
async function scanParentDirs(destPath, scriptName) {
assert(path.isAbsolute(destPath));
let hasScript = false;
let hasPackageLockJson = false;
let currentDestPath = destPath;
// eslint-disable-next-line no-constant-condition
while (true) {
const packageJsonPath = path.join(currentDestPath, 'package.json');
// eslint-disable-next-line no-await-in-loop
if (await fs.exists(path.join(currentDestPath, 'package.json'))) {
if (await fs.exists(packageJsonPath)) {
// eslint-disable-next-line no-await-in-loop
if (await fs.exists(path.join(currentDestPath, 'package-lock.json'))) {
return true;
}
return false;
const packageJson = JSON.parse(await fs.readFile(packageJsonPath));
hasScript = Boolean(
packageJson.scripts && packageJson.scripts[scriptName],
);
// eslint-disable-next-line no-await-in-loop
hasPackageLockJson = await fs.exists(
path.join(currentDestPath, 'package-lock.json'),
);
break;
}
const newDestPath = path.dirname(currentDestPath);
@@ -36,13 +49,17 @@ async function shouldUseNpm(destPath) {
currentDestPath = newDestPath;
}
return false;
return { hasScript, hasPackageLockJson };
}
async function runNpmInstall(destPath, args = []) {
assert(path.isAbsolute(destPath));
let commandArgs = args;
console.log(`installing to ${destPath}`);
if (await shouldUseNpm(destPath)) {
const { hasPackageLockJson } = await scanParentDirs(destPath);
if (hasPackageLockJson) {
commandArgs = args.filter(a => a !== '--prefer-offline');
await spawnAsync('npm', ['install'].concat(commandArgs), destPath);
await spawnAsync('npm', ['cache', 'clean', '--force'], destPath);
@@ -53,21 +70,19 @@ async function runNpmInstall(destPath, args = []) {
}
async function runPackageJsonScript(destPath, scriptName) {
try {
if (await shouldUseNpm(destPath)) {
console.log(`running "npm run ${scriptName}"`);
await spawnAsync('npm', ['run', scriptName], destPath);
} else {
console.log(`running "yarn run ${scriptName}"`);
await spawnAsync(
'yarn',
['--cwd', destPath, 'run', scriptName],
destPath,
);
}
} catch (error) {
console.log(error.message);
return false;
assert(path.isAbsolute(destPath));
const { hasScript, hasPackageLockJson } = await scanParentDirs(
destPath,
scriptName,
);
if (!hasScript) return false;
if (hasPackageLockJson) {
console.log(`running "npm run ${scriptName}"`);
await spawnAsync('npm', ['run', scriptName], destPath);
} else {
console.log(`running "yarn run ${scriptName}"`);
await spawnAsync('yarn', ['--cwd', destPath, 'run', scriptName], destPath);
}
return true;

View File

@@ -1,6 +1,6 @@
{
"name": "@now/build-utils",
"version": "0.4.30-canary.0",
"version": "0.4.30",
"dependencies": {
"async-retry": "1.2.3",
"async-sema": "2.1.4",
@@ -11,5 +11,8 @@
"multistream": "2.1.1",
"node-fetch": "2.2.0",
"yazl": "2.4.3"
},
"scripts": {
"test": "jest"
}
}

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "with-npm/index.js", "use": "@now/node" },
{ "src": "with-yarn/index.js", "use": "@now/node" }
],
"probes": [
{ "path": "/with-npm", "mustContain": "npm:RANDOMNESS_PLACEHOLDER" },
{ "path": "/with-yarn", "mustContain": "yarn:RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');
const execpath = path.basename(process.env.npm_execpath);
console.log('execpath', execpath);
if (execpath === 'npm-cli.js') {
fs.writeFileSync(
'index.js',
'module.exports = (_, resp) => resp.end("npm:RANDOMNESS_PLACEHOLDER");',
);
} else {
throw new Error('npm is expected');
}

View File

@@ -0,0 +1,3 @@
{
"lockfileVersion": 1
}

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"now-build": "node must-be-npm.js"
}
}

View File

@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');
const execpath = path.basename(process.env.npm_execpath);
console.log('execpath', execpath);
if (execpath === 'yarn.js' || execpath === 'yarn') {
fs.writeFileSync(
'index.js',
'module.exports = (_, resp) => resp.end("yarn:RANDOMNESS_PLACEHOLDER");',
);
} else {
throw new Error('yarn is expected');
}

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"now-build": "node must-be-yarn.js"
}
}

View File

@@ -0,0 +1,53 @@
/* global beforeAll, expect, it, jest */
const fs = require('fs');
const path = require('path');
const {
packAndDeploy,
testDeployment,
} = require('../../../test/lib/deployment/test-deployment.js');
jest.setTimeout(2 * 60 * 1000);
let buildUtilsUrl;
beforeAll(async () => {
const buildUtilsPath = path.resolve(__dirname, '..');
buildUtilsUrl = await packAndDeploy(buildUtilsPath);
console.log('buildUtilsUrl', buildUtilsUrl);
});
// own fixtures
const fixturesPath = path.resolve(__dirname, 'fixtures');
// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath)) {
// eslint-disable-next-line no-loop-func
it(`should build ${fixture}`, async () => {
await expect(
testDeployment({ buildUtilsUrl }, path.join(fixturesPath, fixture)),
).resolves.toBe(undefined);
});
}
// few foreign tests
const buildersToTestWith = ['now-node-server', 'now-static-build'];
// eslint-disable-next-line no-restricted-syntax
for (const builder of buildersToTestWith) {
const fixturesPath2 = path.resolve(
__dirname,
`../../${builder}/test/fixtures`,
);
// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath2)) {
// eslint-disable-next-line no-loop-func
it(`should build ${builder}/${fixture}`, async () => {
await expect(
testDeployment({ buildUtilsUrl }, path.join(fixturesPath2, fixture)),
).resolves.toBe(undefined);
});
}
}

View File

@@ -1,4 +1,7 @@
#!/usr/bin/env bash
export GOOS=linux
export GOARCH=amd64
export GOPATH=$HOME/go
go get github.com/aws/aws-lambda-go/events
go get github.com/aws/aws-lambda-go/lambda
go build -o handler main.go

View File

@@ -70,7 +70,7 @@ func (h *CgiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Path: h.Script,
Root: "/" + h.Script,
Dir: h.Dir,
Env: []string{"SERVER_PORT=443"},
Env: []string{"SERVER_PORT=443", "HTTPS=on", "SERVER_SOFTWARE=@now/cgi"},
}
cgih.ServeHTTP(w, r)
}

View File

@@ -1,6 +1,6 @@
{
"name": "@now/cgi",
"version": "0.0.13-canary.0",
"version": "0.0.13",
"scripts": {
"test": "best -I test/*.js",
"prepublish": "./build.sh"

View File

@@ -91,7 +91,10 @@ func main() {
for k, v := range req.Headers {
internalReq.Header.Add(k, v)
if strings.ToLower(k) == "host" {
req.Host = v
// we need to set `Host` in the request
// because Go likes to ignore the `Host` header
// see https://github.com/golang/go/issues/7682
internalReq.Host = v
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@now/go",
"version": "0.2.10-canary.0",
"version": "0.2.10",
"scripts": {
"test": "best -I test/*.js",
"prepublish": "./build.sh"

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
{
"name": "@now/md",
"version": "0.4.7-canary.0",
"version": "0.4.7",
"dependencies": {
"rehype-document": "^2.2.0",
"rehype-format": "^2.3.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/mdx-deck",
"version": "0.4.16-canary.0",
"version": "0.4.16",
"peerDependencies": {
"@now/build-utils": ">=0.0.1"
}

View File

@@ -66,6 +66,10 @@ async function writeNpmRc(workPath, token) {
);
}
exports.config = {
maxLambdaSize: '5mb',
};
/**
* @param {BuildParamsType} buildParams
* @returns {Promise<Files>}
@@ -90,7 +94,10 @@ exports.build = async ({ files, workPath, entrypoint }) => {
let downloadedFiles = await download(filesWithoutStaticDirectory, workPath);
console.log('normalizing package.json');
const packageJson = normalizePackageJson(readPackageJson(downloadedFiles));
const packageJson = normalizePackageJson(
await readPackageJson(downloadedFiles),
);
console.log('normalized package.json result: ', packageJson);
await writePackageJson(workPath, packageJson);
if (process.env.NPM_AUTH_TOKEN) {

View File

@@ -1,6 +1,6 @@
{
"name": "@now/next",
"version": "0.0.79-canary.0",
"version": "0.0.80",
"dependencies": {
"@now/node-bridge": "0.1.4",
"execa": "^1.0.0",

View File

@@ -113,29 +113,45 @@ function excludeStaticDirectory(files) {
/**
* Enforce specific package.json configuration for smallest possible lambda
* @param {Object} defaultPackageJson
* @param {{dependencies?: any, devDependencies?: any, scripts?: any}} defaultPackageJson
*/
function normalizePackageJson(defaultPackageJson = {}) {
const dependencies = {};
const devDependencies = {
...defaultPackageJson.dependencies,
...defaultPackageJson.devDependencies,
};
if (devDependencies.react) {
dependencies.react = devDependencies.react;
delete devDependencies.react;
}
if (devDependencies['react-dom']) {
dependencies['react-dom'] = devDependencies['react-dom'];
delete devDependencies['react-dom'];
}
return {
...defaultPackageJson,
dependencies: {
// react and react-dom can be overwritten
react: 'latest',
'react-dom': 'latest',
...defaultPackageJson.dependencies,
...dependencies, // override react if user provided it
// next-server is forced to canary
'next-server': 'canary',
next: undefined,
},
devDependencies: {
...defaultPackageJson.devDependencies,
...devDependencies,
// next is forced to canary
next: 'canary',
// next-server is a dependency here
'next-server': undefined,
},
scripts: {
...defaultPackageJson.scripts,
'now-build': 'next build',
'now-build': 'next build --lambdas',
},
};
}

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node-bridge",
"version": "0.1.9-canary.0",
"version": "0.1.9",
"peerDependencies": {
"@now/build-utils": ">=0.0.1"
}

View File

@@ -0,0 +1 @@
/test

View File

@@ -5,31 +5,41 @@ const FileFsRef = require('@now/build-utils/file-fs-ref.js');
const fs = require('fs-extra');
const glob = require('@now/build-utils/fs/glob.js');
const path = require('path');
const { promisify } = require('util');
const rename = require('@now/build-utils/fs/rename.js');
const {
runNpmInstall,
runPackageJsonScript,
} = require('@now/build-utils/fs/run-user-scripts.js');
const fsp = {
readFile: promisify(fs.readFile),
};
/** @typedef { import('@now/build-utils/file-ref') } FileRef */
/** @typedef {{[filePath: string]: FileRef}} Files */
async function commonForTwo({
files, entrypoint, workPath, cachePath,
}) {
const xPath = workPath || cachePath;
const preferOfflineArgument = workPath ? ['--prefer-offline'] : [];
/**
* @typedef {Object} BuildParamsType
* @property {Files} files - Files object
* @property {string} entrypoint - Entrypoint specified for the builder
* @property {Object} config - User-passed config from now.json
* @property {string} workPath - Working directory for this build
*/
const xUserPath = path.join(xPath, 'user');
const xNccPath = path.join(xPath, 'ncc');
/**
* @param {BuildParamsType} buildParams
* @param {Object} [options]
* @param {string[]} [options.npmArguments]
*/
async function downloadInstallAndBundle(
{ files, entrypoint, workPath },
{ npmArguments = [] } = {},
) {
const userPath = path.join(workPath, 'user');
const nccPath = path.join(workPath, 'ncc');
console.log('downloading user files...');
const filesOnDisk = await download(files, xUserPath);
const downloadedFiles = await download(files, userPath);
console.log('running npm install for user...');
const entrypointFsDirname = path.join(xUserPath, path.dirname(entrypoint));
await runNpmInstall(entrypointFsDirname, preferOfflineArgument);
const entrypointFsDirname = path.join(userPath, path.dirname(entrypoint));
await runNpmInstall(entrypointFsDirname, npmArguments);
console.log('writing ncc package.json...');
await download(
@@ -37,48 +47,77 @@ async function commonForTwo({
'package.json': new FileBlob({
data: JSON.stringify({
dependencies: {
'@zeit/ncc': '0.1.4-webpack',
'@zeit/ncc': '0.1.12',
},
}),
}),
},
xNccPath,
nccPath,
);
console.log('running npm install for ncc...');
await runNpmInstall(xNccPath, preferOfflineArgument);
return [filesOnDisk, xNccPath, entrypointFsDirname];
await runNpmInstall(nccPath, npmArguments);
return [downloadedFiles, userPath, nccPath, entrypointFsDirname];
}
async function compile(workNccPath, input) {
async function compile(workNccPath, downloadedFiles, entrypoint) {
const input = downloadedFiles[entrypoint].fsPath;
const ncc = require(path.join(workNccPath, 'node_modules/@zeit/ncc'));
return ncc(input);
const { code, assets } = await ncc(input);
const preparedFiles = {};
const blob = new FileBlob({ data: code });
// move all user code to 'user' subdirectory
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] });
preparedFiles[
path.join('user', path.dirname(entrypoint), assetName)
] = blob2;
}
return preparedFiles;
}
exports.config = {
maxLambdaSize: '15mb',
};
exports.build = async ({ files, entrypoint, workPath }) => {
const [filesOnDisk, workNccPath, entrypointFsDirname] = await commonForTwo({
files,
entrypoint,
workPath,
});
/**
* @param {BuildParamsType} buildParams
* @returns {Promise<Files>}
*/
exports.build = async ({
files, entrypoint, config, workPath,
}) => {
const [
downloadedFiles,
workUserPath,
workNccPath,
entrypointFsDirname,
] = await downloadInstallAndBundle(
{ files, entrypoint, workPath },
{ npmArguments: ['--prefer-offline'] },
);
console.log('running user script...');
await runPackageJsonScript(entrypointFsDirname, 'now-build');
console.log('compiling entrypoint with ncc...');
const data = await compile(workNccPath, filesOnDisk[entrypoint].fsPath);
const blob = new FileBlob({ data });
console.log('preparing lambda files...');
// move all user code to 'user' subdirectory
const compiledFiles = { [path.join('user', entrypoint)]: blob };
const launcherPath = path.join(__dirname, 'launcher.js');
let launcherData = await fsp.readFile(launcherPath, 'utf8');
let preparedFiles;
if (config && config.bundle === false) {
// move all user code to 'user' subdirectory
preparedFiles = await glob('**', workUserPath);
preparedFiles = rename(preparedFiles, name => path.join('user', name));
} else {
console.log('compiling entrypoint with ncc...');
preparedFiles = await compile(workNccPath, downloadedFiles, entrypoint);
}
const launcherPath = path.join(__dirname, 'launcher.js');
let launcherData = await fs.readFile(launcherPath, 'utf8');
launcherData = launcherData.replace(
'// PLACEHOLDER',
[
@@ -93,7 +132,7 @@ exports.build = async ({ files, entrypoint, workPath }) => {
};
const lambda = await createLambda({
files: { ...compiledFiles, ...launcherFiles },
files: { ...preparedFiles, ...launcherFiles },
handler: 'launcher.launcher',
runtime: 'nodejs8.10',
});
@@ -105,7 +144,7 @@ exports.prepareCache = async ({
files, entrypoint, workPath, cachePath,
}) => {
await fs.remove(workPath);
await commonForTwo({ files, entrypoint, cachePath });
await downloadInstallAndBundle({ files, entrypoint, workPath: cachePath });
return {
...(await glob('user/node_modules/**', cachePath)),

View File

@@ -1,11 +1,14 @@
{
"name": "@now/node-server",
"version": "0.4.24-canary.0",
"version": "0.4.24",
"dependencies": {
"@now/node-bridge": "^0.1.9-canary.0",
"@now/node-bridge": "^0.1.9",
"fs-extra": "7.0.1"
},
"peerDependencies": {
"@now/build-utils": ">=0.0.1"
},
"scripts": {
"test": "jest"
}
}

View File

@@ -0,0 +1,11 @@
const cowsay = require('cowsay/build/cowsay.umd.js').say;
const http = require('http');
// test that process.env is not replaced by webpack
process.env.NODE_ENV = 'development';
const server = http.createServer((req, resp) => {
resp.end(cowsay({ text: 'cow:RANDOMNESS_PLACEHOLDER' }));
});
server.listen();

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "index.js", "use": "@now/node-server" },
{ "src": "subdirectory/index.js", "use": "@now/node-server" }
],
"probes": [
{ "path": "/", "mustContain": "cow:RANDOMNESS_PLACEHOLDER" },
{ "path": "/subdirectory", "mustContain": "yoda:RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"cowsay": "^1.3.1"
}
}

View File

@@ -0,0 +1,11 @@
const yodasay = require('yodasay/build/yodasay.umd.js').say;
const http = require('http');
// test that process.env is not replaced by webpack
process.env.NODE_ENV = 'development';
const server = http.createServer((req, resp) => {
resp.end(yodasay({ text: 'yoda:RANDOMNESS_PLACEHOLDER' }));
});
server.listen();

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"yodasay": "^1.1.6"
}
}

View File

@@ -0,0 +1,10 @@
const assert = require('assert');
const http = require('http');
const server = http.createServer((req, resp) => {
assert(!process.env.RANDOMNESS_BUILD_ENV_VAR);
assert(process.env.RANDOMNESS_ENV_VAR);
resp.end('BUILD_TIME_PLACEHOLDER:build-env');
});
server.listen();

View File

@@ -0,0 +1,12 @@
const assert = require('assert');
const fs = require('fs');
assert(process.env.RANDOMNESS_BUILD_ENV_VAR);
assert(!process.env.RANDOMNESS_ENV_VAR);
fs.writeFileSync(
'index.js',
fs
.readFileSync('index.js', 'utf8')
.replace('BUILD_TIME_PLACEHOLDER', process.env.RANDOMNESS_BUILD_ENV_VAR),
);

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"now-build": "node now-build.js"
}
}

View File

@@ -0,0 +1,10 @@
const assert = require('assert');
const http = require('http');
const server = http.createServer((req, resp) => {
assert(!process.env.RANDOMNESS_BUILD_ENV_VAR);
assert(process.env.RANDOMNESS_ENV_VAR);
resp.end(`${process.env.RANDOMNESS_ENV_VAR}:env`);
});
server.listen();

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "build-env/index.js", "use": "@now/node-server" },
{ "src": "env/index.js", "use": "@now/node-server" }
],
"probes": [
{ "path": "/build-env", "mustContain": "RANDOMNESS_PLACEHOLDER:build-env" },
{ "path": "/env", "mustContain": "RANDOMNESS_PLACEHOLDER:env" }
]
}

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "with-bundle/index.js", "use": "@now/node-server" },
{ "src": "without-bundle/index.js", "use": "@now/node-server", "config": { "bundle": false } }
],
"probes": [
{ "path": "/with-bundle", "mustContain": "RANDOMNESS_PLACEHOLDER" },
{ "path": "/without-bundle", "mustContain": "RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,8 @@
const http = require('http');
const isBundled = require('./is-bundled.js');
const server = http.createServer((req, resp) => {
resp.end(isBundled() ? 'RANDOMNESS_PLACEHOLDER' : '');
});
server.listen();

View File

@@ -0,0 +1,3 @@
const path = require('path');
module.exports = () => path.basename(__filename) === 'index.js';

View File

@@ -0,0 +1,8 @@
const http = require('http');
const isBundled = require('./is-bundled.js');
const server = http.createServer((req, resp) => {
resp.end(isBundled() ? '' : 'RANDOMNESS_PLACEHOLDER');
});
server.listen();

View File

@@ -0,0 +1,3 @@
const path = require('path');
module.exports = () => path.basename(__filename) === 'index.js';

View File

@@ -0,0 +1,24 @@
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
const typeDefs = gql`
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'apollo:RANDOMNESS_PLACEHOLDER',
},
};
const server = new ApolloServer({ typeDefs, resolvers, introspection: true });
const app = express();
server.applyMiddleware({ app });
app.get('/', (req, resp) => {
resp.redirect('/graphql');
});
app.listen({ port: 4000 });

View File

@@ -0,0 +1,7 @@
{
"dependencies": {
"apollo-server-express": "^2.2.2",
"express": "^4.16.4",
"graphql": "^14.0.2"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
{
"version": 2,
"builds": [
{ "src": "apollo/index.js", "use": "@now/node-server" }
],
"routes": [
{ "src": "/.*", "dest": "apollo/index.js" }
],
"probes": [
{ "path": "/graphql", "method": "POST", "body": { "query": "{hello}" }, "mustContain": "apollo:RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,29 @@
/* global beforeAll, expect, it, jest */
const fs = require('fs');
const path = require('path');
const {
packAndDeploy,
testDeployment,
} = require('../../../test/lib/deployment/test-deployment.js');
jest.setTimeout(2 * 60 * 1000);
let builderUrl;
beforeAll(async () => {
const builderPath = path.resolve(__dirname, '..');
builderUrl = await packAndDeploy(builderPath);
console.log('builderUrl', builderUrl);
});
const fixturesPath = path.resolve(__dirname, 'fixtures');
// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath)) {
// eslint-disable-next-line no-loop-func
it(`should build ${fixture}`, async () => {
await expect(
testDeployment({ builderUrl }, path.join(fixturesPath, fixture)),
).resolves.toBe(undefined);
});
}

View File

@@ -0,0 +1 @@
/test

View File

@@ -2,18 +2,14 @@ const { createLambda } = require('@now/build-utils/lambda.js');
const download = require('@now/build-utils/fs/download.js');
const FileBlob = require('@now/build-utils/file-blob.js');
const FileFsRef = require('@now/build-utils/file-fs-ref.js');
const fsExtra = require('fs-extra');
const fs = require('fs');
const fs = require('fs-extra');
const glob = require('@now/build-utils/fs/glob.js');
const path = require('path');
const { promisify } = require('util');
const {
runNpmInstall,
runPackageJsonScript,
} = require('@now/build-utils/fs/run-user-scripts.js');
const readFile = promisify(fs.readFile);
/** @typedef { import('@now/build-utils/file-ref') } FileRef */
/** @typedef {{[filePath: string]: FileRef}} Files */
@@ -37,7 +33,7 @@ async function downloadInstallAndBundle(
const nccPath = path.join(workPath, 'ncc');
console.log('downloading user files...');
const filesOnDisk = await download(files, userPath);
const downloadedFiles = await download(files, userPath);
console.log('running npm install for user...');
const entrypointFsDirname = path.join(userPath, path.dirname(entrypoint));
@@ -49,7 +45,7 @@ async function downloadInstallAndBundle(
'package.json': new FileBlob({
data: JSON.stringify({
dependencies: {
'@zeit/ncc': '0.1.4-webpack',
'@zeit/ncc': '0.1.12',
},
}),
}),
@@ -59,12 +55,27 @@ async function downloadInstallAndBundle(
console.log('running npm install for ncc...');
await runNpmInstall(nccPath, npmArguments);
return [filesOnDisk, nccPath, entrypointFsDirname];
return [downloadedFiles, nccPath, entrypointFsDirname];
}
async function compile(workNccPath, input) {
async function compile(workNccPath, downloadedFiles, entrypoint) {
const input = downloadedFiles[entrypoint].fsPath;
const ncc = require(path.join(workNccPath, 'node_modules/@zeit/ncc'));
return ncc(input);
const { code, assets } = await ncc(input);
const preparedFiles = {};
const blob = new FileBlob({ data: code });
// move all user code to 'user' subdirectory
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] });
preparedFiles[
path.join('user', path.dirname(entrypoint), assetName)
] = blob2;
}
return preparedFiles;
}
exports.config = {
@@ -77,7 +88,7 @@ exports.config = {
*/
exports.build = async ({ files, entrypoint, workPath }) => {
const [
filesOnDisk,
downloadedFiles,
workNccPath,
entrypointFsDirname,
] = await downloadInstallAndBundle(
@@ -89,14 +100,9 @@ exports.build = async ({ files, entrypoint, workPath }) => {
await runPackageJsonScript(entrypointFsDirname, 'now-build');
console.log('compiling entrypoint with ncc...');
const data = await compile(workNccPath, filesOnDisk[entrypoint].fsPath);
const blob = new FileBlob({ data });
console.log('preparing lambda files...');
// move all user code to 'user' subdirectory
const compiledFiles = { [path.join('user', entrypoint)]: blob };
const preparedFiles = await compile(workNccPath, downloadedFiles, entrypoint);
const launcherPath = path.join(__dirname, 'launcher.js');
let launcherData = await readFile(launcherPath, 'utf8');
let launcherData = await fs.readFile(launcherPath, 'utf8');
launcherData = launcherData.replace(
'// PLACEHOLDER',
@@ -112,7 +118,7 @@ exports.build = async ({ files, entrypoint, workPath }) => {
};
const lambda = await createLambda({
files: { ...compiledFiles, ...launcherFiles },
files: { ...preparedFiles, ...launcherFiles },
handler: 'launcher.launcher',
runtime: 'nodejs8.10',
});
@@ -123,7 +129,7 @@ exports.build = async ({ files, entrypoint, workPath }) => {
exports.prepareCache = async ({
files, entrypoint, workPath, cachePath,
}) => {
await fsExtra.remove(workPath);
await fs.remove(workPath);
await downloadInstallAndBundle({ files, entrypoint, workPath: cachePath });
return {

View File

@@ -1,11 +1,14 @@
{
"name": "@now/node",
"version": "0.4.26-canary.0",
"version": "0.4.26",
"dependencies": {
"@now/node-bridge": "^0.1.9-canary.0",
"@now/node-bridge": "^0.1.9",
"fs-extra": "7.0.1"
},
"peerDependencies": {
"@now/build-utils": ">=0.0.1"
},
"scripts": {
"test": "jest"
}
}

View File

@@ -0,0 +1,8 @@
const cowsay = require('cowsay/build/cowsay.umd.js').say;
// test that process.env is not replaced by webpack
process.env.NODE_ENV = 'development';
module.exports = (req, resp) => {
resp.end(cowsay({ text: 'cow:RANDOMNESS_PLACEHOLDER' }));
};

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "index.js", "use": "@now/node" },
{ "src": "subdirectory/index.js", "use": "@now/node" }
],
"probes": [
{ "path": "/", "mustContain": "cow:RANDOMNESS_PLACEHOLDER" },
{ "path": "/subdirectory", "mustContain": "yoda:RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"cowsay": "^1.3.1"
}
}

View File

@@ -0,0 +1,8 @@
const yodasay = require('yodasay/build/yodasay.umd.js').say;
// test that process.env is not replaced by webpack
process.env.NODE_ENV = 'development';
module.exports = (req, resp) => {
resp.end(yodasay({ text: 'yoda:RANDOMNESS_PLACEHOLDER' }));
};

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"yodasay": "^1.1.6"
}
}

View File

@@ -0,0 +1,7 @@
const assert = require('assert');
module.exports = (req, resp) => {
assert(!process.env.RANDOMNESS_BUILD_ENV_VAR);
assert(process.env.RANDOMNESS_ENV_VAR);
resp.end('BUILD_TIME_PLACEHOLDER:build-env');
};

View File

@@ -0,0 +1,12 @@
const assert = require('assert');
const fs = require('fs');
assert(process.env.RANDOMNESS_BUILD_ENV_VAR);
assert(!process.env.RANDOMNESS_ENV_VAR);
fs.writeFileSync(
'index.js',
fs
.readFileSync('index.js', 'utf8')
.replace('BUILD_TIME_PLACEHOLDER', process.env.RANDOMNESS_BUILD_ENV_VAR),
);

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"now-build": "node now-build.js"
}
}

View File

@@ -0,0 +1,7 @@
const assert = require('assert');
module.exports = (req, resp) => {
assert(!process.env.RANDOMNESS_BUILD_ENV_VAR);
assert(process.env.RANDOMNESS_ENV_VAR);
resp.end(`${process.env.RANDOMNESS_ENV_VAR}:env`);
};

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "build-env/index.js", "use": "@now/node" },
{ "src": "env/index.js", "use": "@now/node" }
],
"probes": [
{ "path": "/build-env", "mustContain": "RANDOMNESS_PLACEHOLDER:build-env" },
{ "path": "/env", "mustContain": "RANDOMNESS_PLACEHOLDER:env" }
]
}

View File

@@ -0,0 +1,29 @@
/* global beforeAll, expect, it, jest */
const fs = require('fs');
const path = require('path');
const {
packAndDeploy,
testDeployment,
} = require('../../../test/lib/deployment/test-deployment.js');
jest.setTimeout(2 * 60 * 1000);
let builderUrl;
beforeAll(async () => {
const builderPath = path.resolve(__dirname, '..');
builderUrl = await packAndDeploy(builderPath);
console.log('builderUrl', builderUrl);
});
const fixturesPath = path.resolve(__dirname, 'fixtures');
// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath)) {
// eslint-disable-next-line no-loop-func
it(`should build ${fixture}`, async () => {
await expect(
testDeployment({ builderUrl }, path.join(fixturesPath, fixture)),
).resolves.toBe(undefined);
});
}

View File

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

View File

@@ -1 +1,2 @@
/launcher
/test

Binary file not shown.

View File

@@ -5,7 +5,6 @@ import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"os"
"path"
@@ -100,6 +99,5 @@ func main() {
ex, _ := os.Executable()
phpScript = os.Getenv("NOW_PHP_SCRIPT")
phpScriptFull = path.Join(filepath.Dir(ex), phpScript)
fmt.Printf("phpScriptFull %s\n", phpScriptFull)
lambda.Start(handler)
}

View File

@@ -1,7 +1,10 @@
{
"name": "@now/php",
"version": "0.4.11-canary.0",
"version": "0.4.11",
"peerDependencies": {
"@now/build-utils": ">=0.0.1"
},
"scripts": {
"test": "jest"
}
}

View File

@@ -0,0 +1,3 @@
<?php
print "cow:RANDOMNESS_PLACEHOLDER";
?>

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "index.php", "use": "@now/php" },
{ "src": "subdirectory/index.php", "use": "@now/php" }
],
"probes": [
{ "path": "/", "mustContain": "cow:RANDOMNESS_PLACEHOLDER" },
{ "path": "/subdirectory", "mustContain": "yoda:RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,3 @@
<?php
print "yoda:RANDOMNESS_PLACEHOLDER";
?>

View File

@@ -0,0 +1,3 @@
<?php
print $_ENV["RANDOMNESS_ENV_VAR"] . ":env";
?>

View File

@@ -0,0 +1,9 @@
{
"version": 2,
"builds": [
{ "src": "env/index.php", "use": "@now/php" }
],
"probes": [
{ "path": "/env", "mustContain": "RANDOMNESS_PLACEHOLDER:env" }
]
}

View File

@@ -0,0 +1,29 @@
/* global beforeAll, expect, it, jest */
const fs = require('fs');
const path = require('path');
const {
packAndDeploy,
testDeployment,
} = require('../../../test/lib/deployment/test-deployment.js');
jest.setTimeout(2 * 60 * 1000);
let builderUrl;
beforeAll(async () => {
const builderPath = path.resolve(__dirname, '..');
builderUrl = await packAndDeploy(builderPath);
console.log('builderUrl', builderUrl);
});
const fixturesPath = path.resolve(__dirname, 'fixtures');
// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath)) {
// eslint-disable-next-line no-loop-func
it(`should build ${fixture}`, async () => {
await expect(
testDeployment({ builderUrl }, path.join(fixturesPath, fixture)),
).resolves.toBe(undefined);
});
}

View File

@@ -1,6 +1,6 @@
{
"name": "@now/python",
"version": "0.0.40-canary.0",
"version": "0.0.40",
"main": "index.js",
"license": "MIT",
"dependencies": {

View File

@@ -0,0 +1 @@
/test

View File

@@ -34,5 +34,5 @@ exports.build = async ({
return glob('**', distPath, mountpoint);
}
return {};
throw new Error('Proper build script must be specified as entrypoint');
};

View File

@@ -1,7 +1,10 @@
{
"name": "@now/static-build",
"version": "0.4.15-canary.0",
"version": "0.4.15",
"peerDependencies": {
"@now/build-utils": ">=0.0.1"
},
"scripts": {
"test": "jest"
}
}

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "package.json", "use": "@now/static-build" },
{ "src": "subdirectory/package.json", "use": "@now/static-build" }
],
"probes": [
{ "path": "/", "mustContain": "cow:RANDOMNESS_PLACEHOLDER" },
{ "path": "/subdirectory", "mustContain": "yoda:RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,8 @@
{
"dependencies": {
"cowsay": "^1.3.1"
},
"scripts": {
"now-build": "mkdir dist && cowsay cow:RANDOMNESS_PLACEHOLDER > dist/index.txt"
}
}

View File

@@ -0,0 +1,8 @@
{
"dependencies": {
"yodasay": "^1.1.6"
},
"scripts": {
"now-build": "mkdir dist && yodasay yoda:RANDOMNESS_PLACEHOLDER > dist/index.txt"
}
}

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "some-build.sh", "use": "@now/static-build" },
{ "src": "subdirectory/some-build.sh", "use": "@now/static-build" }
],
"probes": [
{ "path": "/", "mustContain": "cow:RANDOMNESS_PLACEHOLDER" },
{ "path": "/subdirectory", "mustContain": "yoda:RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"cowsay": "^1.3.1"
}
}

View File

@@ -0,0 +1,3 @@
yarn install
mkdir dist
./node_modules/.bin/cowsay cow:RANDOMNESS_PLACEHOLDER > dist/index.txt

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"yodasay": "^1.1.6"
}
}

View File

@@ -0,0 +1,3 @@
yarn install
mkdir dist
./node_modules/.bin/yodasay yoda:RANDOMNESS_PLACEHOLDER > dist/index.txt

View File

@@ -0,0 +1,10 @@
const assert = require('assert');
const fs = require('fs');
assert(process.env.RANDOMNESS_BUILD_ENV_VAR);
assert(!process.env.RANDOMNESS_ENV_VAR);
fs.writeFileSync(
'dist/index.html',
`${process.env.RANDOMNESS_BUILD_ENV_VAR}:build-env`,
);

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"now-build": "mkdir dist && node now-build.js"
}
}

View File

@@ -0,0 +1,9 @@
{
"version": 2,
"builds": [
{ "src": "build-env/package.json", "use": "@now/static-build" }
],
"probes": [
{ "path": "/build-env", "mustContain": "RANDOMNESS_PLACEHOLDER:build-env" }
]
}

View File

@@ -0,0 +1,7 @@
const fs = require('fs');
const path = require('path');
for (let i = 100; i < 400; i += 1) {
const file = path.join(__dirname, `dist/${i}.html`);
fs.writeFileSync(file, `<h1>Number ${i}:RANDOMNESS_PLACEHOLDER</h1>`);
}

View File

@@ -0,0 +1,11 @@
{
"version": 2,
"builds": [
{ "src": "package.json", "use": "@now/static-build" }
],
"probes": [
{ "path": "/100.html", "mustContain": "100:RANDOMNESS_PLACEHOLDER" },
{ "path": "/242.html", "mustContain": "242:RANDOMNESS_PLACEHOLDER" },
{ "path": "/399.html", "mustContain": "399:RANDOMNESS_PLACEHOLDER" }
]
}

View File

@@ -0,0 +1,5 @@
{
"scripts": {
"now-build": "mkdir dist && node build.js"
}
}

View File

@@ -0,0 +1,29 @@
/* global beforeAll, expect, it, jest */
const fs = require('fs');
const path = require('path');
const {
packAndDeploy,
testDeployment,
} = require('../../../test/lib/deployment/test-deployment.js');
jest.setTimeout(2 * 60 * 1000);
let builderUrl;
beforeAll(async () => {
const builderPath = path.resolve(__dirname, '..');
builderUrl = await packAndDeploy(builderPath);
console.log('builderUrl', builderUrl);
});
const fixturesPath = path.resolve(__dirname, 'fixtures');
// eslint-disable-next-line no-restricted-syntax
for (const fixture of fs.readdirSync(fixturesPath)) {
// eslint-disable-next-line no-loop-func
it(`should build ${fixture}`, async () => {
await expect(
testDeployment({ builderUrl }, path.join(fixturesPath, fixture)),
).resolves.toBe(undefined);
});
}

View File

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

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"isomorphic-unfetch": "latest"
}
}

View File

@@ -0,0 +1,6 @@
import fetch from 'isomorphic-unfetch';
// Fake fetch
fetch('https://example.com');
export default () => 'test';

View File

@@ -3,20 +3,40 @@ const path = require('path');
const runBuildLambda = require('../../lib/run-build-lambda');
const TWO_MINUTES = 120000;
const FOUR_MINUTES = 240000;
it('Should build the standard example', async () => {
const { buildResult } = await runBuildLambda(path.join(__dirname, 'standard'));
expect(buildResult.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();
}, TWO_MINUTES);
it(
'Should build the standard example',
async () => {
const { buildResult } = await runBuildLambda(
path.join(__dirname, 'standard'),
);
expect(buildResult.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();
},
TWO_MINUTES,
);
it(
'Should build the custom dependency test',
async () => {
const { buildResult } = await runBuildLambda(
path.join(__dirname, 'custom-dependency'),
);
expect(buildResult.index).toBeDefined();
},
FOUR_MINUTES,
);
it('Should throw when package.json or next.config.js is not the "src"', async () => {
try {
await runBuildLambda(path.join(__dirname, 'no-package-json-and-next-config'));
await runBuildLambda(
path.join(__dirname, 'no-package-json-and-next-config'),
);
} catch (err) {
expect(err.message).toMatch(/package\.json/);
}

View File

@@ -0,0 +1,30 @@
{
"overrides": [
{
"files": ["**"],
"rules": {
"array-bracket-spacing": [
"error",
"always"
],
"arrow-body-style": "off",
"arrow-parens": [
"error",
"always"
],
"comma-dangle": "off",
"import/no-extraneous-dependencies": "off",
"no-await-in-loop": "off",
"no-param-reassign": "off",
"no-restricted-syntax": "off",
"no-return-await": "off",
"no-use-before-define": "off",
"space-before-function-paren": [
"error",
"always"
]
}
}
]
}

Some files were not shown because too many files have changed in this diff Show More