mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 04:22:13 +00:00
Compare commits
56 Commits
@now/pytho
...
@now/php@0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a93713158 | ||
|
|
3392ef5636 | ||
|
|
9236e2b584 | ||
|
|
ffc4686ab9 | ||
|
|
1ff4b6bb4b | ||
|
|
0e7d8c3ff1 | ||
|
|
86885b8c38 | ||
|
|
8563f2b8b5 | ||
|
|
c36938bd95 | ||
|
|
957ab6c4e3 | ||
|
|
069e9b4052 | ||
|
|
0b06704be6 | ||
|
|
cf5a49e699 | ||
|
|
b671b23d8d | ||
|
|
fa44c23225 | ||
|
|
ba9da3cec5 | ||
|
|
0909aaf2b3 | ||
|
|
e276342a6f | ||
|
|
f6e1bdf0a1 | ||
|
|
2c2189b661 | ||
|
|
61522e2bc7 | ||
|
|
a20f3a5920 | ||
|
|
a5e58c2a8d | ||
|
|
a58451548f | ||
|
|
8e846c50b5 | ||
|
|
7613dcf68b | ||
|
|
bea499cad3 | ||
|
|
0f20a0dbbf | ||
|
|
1ea30588a3 | ||
|
|
a3b670675a | ||
|
|
c4374fe5a8 | ||
|
|
c3983ba1c2 | ||
|
|
ae1be4b243 | ||
|
|
b4b1131619 | ||
|
|
5fd923a7e7 | ||
|
|
f4e95eb59c | ||
|
|
a6cdaccd34 | ||
|
|
4f5fe8eba8 | ||
|
|
7239013989 | ||
|
|
75000ee334 | ||
|
|
5319610d59 | ||
|
|
6df0d69afa | ||
|
|
65b191f6b9 | ||
|
|
115f62bbba | ||
|
|
cdf6a98a18 | ||
|
|
bb75dfd993 | ||
|
|
b63062cfc5 | ||
|
|
5ad6dabd96 | ||
|
|
30060bee07 | ||
|
|
dd48a1c6d3 | ||
|
|
24d45736f1 | ||
|
|
d839fdbe81 | ||
|
|
cfdcd2f8d0 | ||
|
|
b3cac2b372 | ||
|
|
9d27d69656 | ||
|
|
04197b250c |
@@ -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: /.*/
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
module.exports = {
|
||||
testEnvironment: 'node',
|
||||
rootDir: 'test',
|
||||
collectCoverageFrom: ['packages/**/*.{js,jsx}', '!**/node_modules/**'],
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
|
||||
1
packages/now-build-utils/.npmignore
Normal file
1
packages/now-build-utils/.npmignore
Normal file
@@ -0,0 +1 @@
|
||||
/test
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
11
packages/now-build-utils/test/fixtures/08-yarn-npm/now.json
vendored
Normal file
11
packages/now-build-utils/test/fixtures/08-yarn-npm/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
0
packages/now-build-utils/test/fixtures/08-yarn-npm/with-npm/index.js
vendored
Normal file
0
packages/now-build-utils/test/fixtures/08-yarn-npm/with-npm/index.js
vendored
Normal file
14
packages/now-build-utils/test/fixtures/08-yarn-npm/with-npm/must-be-npm.js
vendored
Normal file
14
packages/now-build-utils/test/fixtures/08-yarn-npm/with-npm/must-be-npm.js
vendored
Normal 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');
|
||||
}
|
||||
3
packages/now-build-utils/test/fixtures/08-yarn-npm/with-npm/package-lock.json
generated
vendored
Normal file
3
packages/now-build-utils/test/fixtures/08-yarn-npm/with-npm/package-lock.json
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
5
packages/now-build-utils/test/fixtures/08-yarn-npm/with-npm/package.json
vendored
Normal file
5
packages/now-build-utils/test/fixtures/08-yarn-npm/with-npm/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"scripts": {
|
||||
"now-build": "node must-be-npm.js"
|
||||
}
|
||||
}
|
||||
0
packages/now-build-utils/test/fixtures/08-yarn-npm/with-yarn/index.js
vendored
Normal file
0
packages/now-build-utils/test/fixtures/08-yarn-npm/with-yarn/index.js
vendored
Normal file
14
packages/now-build-utils/test/fixtures/08-yarn-npm/with-yarn/must-be-yarn.js
vendored
Normal file
14
packages/now-build-utils/test/fixtures/08-yarn-npm/with-yarn/must-be-yarn.js
vendored
Normal 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');
|
||||
}
|
||||
5
packages/now-build-utils/test/fixtures/08-yarn-npm/with-yarn/package.json
vendored
Normal file
5
packages/now-build-utils/test/fixtures/08-yarn-npm/with-yarn/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"scripts": {
|
||||
"now-build": "node must-be-yarn.js"
|
||||
}
|
||||
}
|
||||
53
packages/now-build-utils/test/test.js
Normal file
53
packages/now-build-utils/test/test.js
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/html-minifier",
|
||||
"version": "1.0.6-canary.0",
|
||||
"version": "1.0.6",
|
||||
"dependencies": {
|
||||
"html-minifier": "3.5.21"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/lambda",
|
||||
"version": "0.4.7-canary.0",
|
||||
"version": "0.4.7",
|
||||
"peerDependencies": {
|
||||
"@now/build-utils": ">=0.0.1"
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
1
packages/now-node-server/.npmignore
Normal file
1
packages/now-node-server/.npmignore
Normal file
@@ -0,0 +1 @@
|
||||
/test
|
||||
@@ -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)),
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
11
packages/now-node-server/test/fixtures/01-cowsay/index.js
vendored
Normal file
11
packages/now-node-server/test/fixtures/01-cowsay/index.js
vendored
Normal 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();
|
||||
11
packages/now-node-server/test/fixtures/01-cowsay/now.json
vendored
Normal file
11
packages/now-node-server/test/fixtures/01-cowsay/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
5
packages/now-node-server/test/fixtures/01-cowsay/package.json
vendored
Normal file
5
packages/now-node-server/test/fixtures/01-cowsay/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"cowsay": "^1.3.1"
|
||||
}
|
||||
}
|
||||
11
packages/now-node-server/test/fixtures/01-cowsay/subdirectory/index.js
vendored
Normal file
11
packages/now-node-server/test/fixtures/01-cowsay/subdirectory/index.js
vendored
Normal 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();
|
||||
5
packages/now-node-server/test/fixtures/01-cowsay/subdirectory/package.json
vendored
Normal file
5
packages/now-node-server/test/fixtures/01-cowsay/subdirectory/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"yodasay": "^1.1.6"
|
||||
}
|
||||
}
|
||||
10
packages/now-node-server/test/fixtures/03-env-vars/build-env/index.js
vendored
Normal file
10
packages/now-node-server/test/fixtures/03-env-vars/build-env/index.js
vendored
Normal 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();
|
||||
12
packages/now-node-server/test/fixtures/03-env-vars/build-env/now-build.js
vendored
Normal file
12
packages/now-node-server/test/fixtures/03-env-vars/build-env/now-build.js
vendored
Normal 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),
|
||||
);
|
||||
5
packages/now-node-server/test/fixtures/03-env-vars/build-env/package.json
vendored
Normal file
5
packages/now-node-server/test/fixtures/03-env-vars/build-env/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"scripts": {
|
||||
"now-build": "node now-build.js"
|
||||
}
|
||||
}
|
||||
10
packages/now-node-server/test/fixtures/03-env-vars/env/index.js
vendored
Normal file
10
packages/now-node-server/test/fixtures/03-env-vars/env/index.js
vendored
Normal 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();
|
||||
11
packages/now-node-server/test/fixtures/03-env-vars/now.json
vendored
Normal file
11
packages/now-node-server/test/fixtures/03-env-vars/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
11
packages/now-node-server/test/fixtures/09-no-bundle/now.json
vendored
Normal file
11
packages/now-node-server/test/fixtures/09-no-bundle/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
8
packages/now-node-server/test/fixtures/09-no-bundle/with-bundle/index.js
vendored
Normal file
8
packages/now-node-server/test/fixtures/09-no-bundle/with-bundle/index.js
vendored
Normal 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();
|
||||
3
packages/now-node-server/test/fixtures/09-no-bundle/with-bundle/is-bundled.js
vendored
Normal file
3
packages/now-node-server/test/fixtures/09-no-bundle/with-bundle/is-bundled.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = () => path.basename(__filename) === 'index.js';
|
||||
8
packages/now-node-server/test/fixtures/09-no-bundle/without-bundle/index.js
vendored
Normal file
8
packages/now-node-server/test/fixtures/09-no-bundle/without-bundle/index.js
vendored
Normal 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();
|
||||
3
packages/now-node-server/test/fixtures/09-no-bundle/without-bundle/is-bundled.js
vendored
Normal file
3
packages/now-node-server/test/fixtures/09-no-bundle/without-bundle/is-bundled.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = () => path.basename(__filename) === 'index.js';
|
||||
24
packages/now-node-server/test/fixtures/10-others/apollo/index.js
vendored
Normal file
24
packages/now-node-server/test/fixtures/10-others/apollo/index.js
vendored
Normal 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 });
|
||||
7
packages/now-node-server/test/fixtures/10-others/apollo/package.json
vendored
Normal file
7
packages/now-node-server/test/fixtures/10-others/apollo/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"apollo-server-express": "^2.2.2",
|
||||
"express": "^4.16.4",
|
||||
"graphql": "^14.0.2"
|
||||
}
|
||||
}
|
||||
1007
packages/now-node-server/test/fixtures/10-others/apollo/yarn.lock
vendored
Normal file
1007
packages/now-node-server/test/fixtures/10-others/apollo/yarn.lock
vendored
Normal file
File diff suppressed because it is too large
Load Diff
12
packages/now-node-server/test/fixtures/10-others/now.json
vendored
Normal file
12
packages/now-node-server/test/fixtures/10-others/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
29
packages/now-node-server/test/test.js
Normal file
29
packages/now-node-server/test/test.js
Normal 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);
|
||||
});
|
||||
}
|
||||
1
packages/now-node/.npmignore
Normal file
1
packages/now-node/.npmignore
Normal file
@@ -0,0 +1 @@
|
||||
/test
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
8
packages/now-node/test/fixtures/01-cowsay/index.js
vendored
Normal file
8
packages/now-node/test/fixtures/01-cowsay/index.js
vendored
Normal 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' }));
|
||||
};
|
||||
11
packages/now-node/test/fixtures/01-cowsay/now.json
vendored
Normal file
11
packages/now-node/test/fixtures/01-cowsay/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
5
packages/now-node/test/fixtures/01-cowsay/package.json
vendored
Normal file
5
packages/now-node/test/fixtures/01-cowsay/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"cowsay": "^1.3.1"
|
||||
}
|
||||
}
|
||||
8
packages/now-node/test/fixtures/01-cowsay/subdirectory/index.js
vendored
Normal file
8
packages/now-node/test/fixtures/01-cowsay/subdirectory/index.js
vendored
Normal 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' }));
|
||||
};
|
||||
5
packages/now-node/test/fixtures/01-cowsay/subdirectory/package.json
vendored
Normal file
5
packages/now-node/test/fixtures/01-cowsay/subdirectory/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"yodasay": "^1.1.6"
|
||||
}
|
||||
}
|
||||
7
packages/now-node/test/fixtures/03-env-vars/build-env/index.js
vendored
Normal file
7
packages/now-node/test/fixtures/03-env-vars/build-env/index.js
vendored
Normal 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');
|
||||
};
|
||||
12
packages/now-node/test/fixtures/03-env-vars/build-env/now-build.js
vendored
Normal file
12
packages/now-node/test/fixtures/03-env-vars/build-env/now-build.js
vendored
Normal 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),
|
||||
);
|
||||
5
packages/now-node/test/fixtures/03-env-vars/build-env/package.json
vendored
Normal file
5
packages/now-node/test/fixtures/03-env-vars/build-env/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"scripts": {
|
||||
"now-build": "node now-build.js"
|
||||
}
|
||||
}
|
||||
7
packages/now-node/test/fixtures/03-env-vars/env/index.js
vendored
Normal file
7
packages/now-node/test/fixtures/03-env-vars/env/index.js
vendored
Normal 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`);
|
||||
};
|
||||
11
packages/now-node/test/fixtures/03-env-vars/now.json
vendored
Normal file
11
packages/now-node/test/fixtures/03-env-vars/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
29
packages/now-node/test/test.js
Normal file
29
packages/now-node/test/test.js
Normal 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);
|
||||
});
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
/launcher
|
||||
/test
|
||||
|
||||
BIN
packages/now-php/dist/launcher
vendored
BIN
packages/now-php/dist/launcher
vendored
Binary file not shown.
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
3
packages/now-php/test/fixtures/01-cowsay/index.php
vendored
Normal file
3
packages/now-php/test/fixtures/01-cowsay/index.php
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
print "cow:RANDOMNESS_PLACEHOLDER";
|
||||
?>
|
||||
11
packages/now-php/test/fixtures/01-cowsay/now.json
vendored
Normal file
11
packages/now-php/test/fixtures/01-cowsay/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
3
packages/now-php/test/fixtures/01-cowsay/subdirectory/index.php
vendored
Normal file
3
packages/now-php/test/fixtures/01-cowsay/subdirectory/index.php
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
print "yoda:RANDOMNESS_PLACEHOLDER";
|
||||
?>
|
||||
3
packages/now-php/test/fixtures/03-env-vars/env/index.php
vendored
Normal file
3
packages/now-php/test/fixtures/03-env-vars/env/index.php
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
print $_ENV["RANDOMNESS_ENV_VAR"] . ":env";
|
||||
?>
|
||||
9
packages/now-php/test/fixtures/03-env-vars/now.json
vendored
Normal file
9
packages/now-php/test/fixtures/03-env-vars/now.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{ "src": "env/index.php", "use": "@now/php" }
|
||||
],
|
||||
"probes": [
|
||||
{ "path": "/env", "mustContain": "RANDOMNESS_PLACEHOLDER:env" }
|
||||
]
|
||||
}
|
||||
29
packages/now-php/test/test.js
Normal file
29
packages/now-php/test/test.js
Normal 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);
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@now/python",
|
||||
"version": "0.0.40-canary.0",
|
||||
"version": "0.0.40",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
1
packages/now-static-build/.npmignore
Normal file
1
packages/now-static-build/.npmignore
Normal file
@@ -0,0 +1 @@
|
||||
/test
|
||||
@@ -34,5 +34,5 @@ exports.build = async ({
|
||||
return glob('**', distPath, mountpoint);
|
||||
}
|
||||
|
||||
return {};
|
||||
throw new Error('Proper build script must be specified as entrypoint');
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
11
packages/now-static-build/test/fixtures/01-cowsay/now.json
vendored
Normal file
11
packages/now-static-build/test/fixtures/01-cowsay/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
8
packages/now-static-build/test/fixtures/01-cowsay/package.json
vendored
Normal file
8
packages/now-static-build/test/fixtures/01-cowsay/package.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"cowsay": "^1.3.1"
|
||||
},
|
||||
"scripts": {
|
||||
"now-build": "mkdir dist && cowsay cow:RANDOMNESS_PLACEHOLDER > dist/index.txt"
|
||||
}
|
||||
}
|
||||
8
packages/now-static-build/test/fixtures/01-cowsay/subdirectory/package.json
vendored
Normal file
8
packages/now-static-build/test/fixtures/01-cowsay/subdirectory/package.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"yodasay": "^1.1.6"
|
||||
},
|
||||
"scripts": {
|
||||
"now-build": "mkdir dist && yodasay yoda:RANDOMNESS_PLACEHOLDER > dist/index.txt"
|
||||
}
|
||||
}
|
||||
11
packages/now-static-build/test/fixtures/02-cowsay-sh/now.json
vendored
Normal file
11
packages/now-static-build/test/fixtures/02-cowsay-sh/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
5
packages/now-static-build/test/fixtures/02-cowsay-sh/package.json
vendored
Normal file
5
packages/now-static-build/test/fixtures/02-cowsay-sh/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"cowsay": "^1.3.1"
|
||||
}
|
||||
}
|
||||
3
packages/now-static-build/test/fixtures/02-cowsay-sh/some-build.sh
vendored
Normal file
3
packages/now-static-build/test/fixtures/02-cowsay-sh/some-build.sh
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
yarn install
|
||||
mkdir dist
|
||||
./node_modules/.bin/cowsay cow:RANDOMNESS_PLACEHOLDER > dist/index.txt
|
||||
5
packages/now-static-build/test/fixtures/02-cowsay-sh/subdirectory/package.json
vendored
Normal file
5
packages/now-static-build/test/fixtures/02-cowsay-sh/subdirectory/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"yodasay": "^1.1.6"
|
||||
}
|
||||
}
|
||||
3
packages/now-static-build/test/fixtures/02-cowsay-sh/subdirectory/some-build.sh
vendored
Normal file
3
packages/now-static-build/test/fixtures/02-cowsay-sh/subdirectory/some-build.sh
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
yarn install
|
||||
mkdir dist
|
||||
./node_modules/.bin/yodasay yoda:RANDOMNESS_PLACEHOLDER > dist/index.txt
|
||||
10
packages/now-static-build/test/fixtures/03-env-vars/build-env/now-build.js
vendored
Normal file
10
packages/now-static-build/test/fixtures/03-env-vars/build-env/now-build.js
vendored
Normal 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`,
|
||||
);
|
||||
5
packages/now-static-build/test/fixtures/03-env-vars/build-env/package.json
vendored
Normal file
5
packages/now-static-build/test/fixtures/03-env-vars/build-env/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"scripts": {
|
||||
"now-build": "mkdir dist && node now-build.js"
|
||||
}
|
||||
}
|
||||
9
packages/now-static-build/test/fixtures/03-env-vars/now.json
vendored
Normal file
9
packages/now-static-build/test/fixtures/03-env-vars/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
7
packages/now-static-build/test/fixtures/10-hundreds/build.js
vendored
Normal file
7
packages/now-static-build/test/fixtures/10-hundreds/build.js
vendored
Normal 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>`);
|
||||
}
|
||||
11
packages/now-static-build/test/fixtures/10-hundreds/now.json
vendored
Normal file
11
packages/now-static-build/test/fixtures/10-hundreds/now.json
vendored
Normal 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" }
|
||||
]
|
||||
}
|
||||
5
packages/now-static-build/test/fixtures/10-hundreds/package.json
vendored
Normal file
5
packages/now-static-build/test/fixtures/10-hundreds/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"scripts": {
|
||||
"now-build": "mkdir dist && node build.js"
|
||||
}
|
||||
}
|
||||
29
packages/now-static-build/test/test.js
Normal file
29
packages/now-static-build/test/test.js
Normal 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);
|
||||
});
|
||||
}
|
||||
6
test/integration/now-next/custom-dependency/now.json
Normal file
6
test/integration/now-next/custom-dependency/now.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{"src": "package.json", "use": "@now/next"}
|
||||
]
|
||||
}
|
||||
5
test/integration/now-next/custom-dependency/package.json
Normal file
5
test/integration/now-next/custom-dependency/package.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"isomorphic-unfetch": "latest"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import fetch from 'isomorphic-unfetch';
|
||||
|
||||
// Fake fetch
|
||||
fetch('https://example.com');
|
||||
|
||||
export default () => 'test';
|
||||
@@ -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/);
|
||||
}
|
||||
|
||||
30
test/lib/deployment/.eslintrc
Normal file
30
test/lib/deployment/.eslintrc
Normal 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
Reference in New Issue
Block a user