mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-23 18:59:59 +00:00
Compare commits
13 Commits
@now/node@
...
@now/pytho
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71c297de32 | ||
|
|
9569c1babc | ||
|
|
16a573ec6e | ||
|
|
79a6c8e1d2 | ||
|
|
e7f62d194b | ||
|
|
3c4306662e | ||
|
|
2ed4e7e9a2 | ||
|
|
d7a65cc835 | ||
|
|
0eb5dac904 | ||
|
|
9ad63f9ed2 | ||
|
|
4ad4765034 | ||
|
|
162f06e4a6 | ||
|
|
4b5b573a1e |
@@ -7,6 +7,7 @@
|
|||||||
/packages/now-build-utils/src/fs/*.js
|
/packages/now-build-utils/src/fs/*.js
|
||||||
/packages/now-node/dist/*
|
/packages/now-node/dist/*
|
||||||
/packages/now-next/dist/*
|
/packages/now-next/dist/*
|
||||||
|
/packages/now-next/test/fixtures/**
|
||||||
/packages/now-node-bridge/*
|
/packages/now-node-bridge/*
|
||||||
/packages/now-python/dist/*
|
/packages/now-python/dist/*
|
||||||
/packages/now-go/*
|
/packages/now-go/*
|
||||||
|
|||||||
40
PUBLISHING.md
Normal file
40
PUBLISHING.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Publishing to npm
|
||||||
|
|
||||||
|
Always publish to the Canary Channel as soon as a PR is merged into the `canary` branch.
|
||||||
|
|
||||||
|
```
|
||||||
|
yarn publish-canary
|
||||||
|
```
|
||||||
|
|
||||||
|
Publish the Stable Channel weekly.
|
||||||
|
|
||||||
|
- Cherry pick each commit from `canary` to `master` branch
|
||||||
|
- Verify that you are _in-sync_ with canary (with the exception of the `version` line in `package.json`)
|
||||||
|
- Deploy the modified Builders
|
||||||
|
|
||||||
|
```
|
||||||
|
# View differences excluding "Publish" commits
|
||||||
|
git checkout canary && git pull
|
||||||
|
git log --pretty=format:"$ad- %s [%an]" | grep -v Publish > ~/Desktop/canary.txt
|
||||||
|
git checkout master && git pull
|
||||||
|
git log --pretty=format:"$ad- %s [%an]" | grep -v Publish > ~/Desktop/master.txt
|
||||||
|
diff ~/Desktop/canary.txt ~/Desktop/master.txt
|
||||||
|
|
||||||
|
# Cherry pick all PRs from canary into master ...
|
||||||
|
git cherry-pick <PR501_COMMIT_SHA>
|
||||||
|
git cherry-pick <PR502_COMMIT_SHA>
|
||||||
|
git cherry-pick <PR503_COMMIT_SHA>
|
||||||
|
git cherry-pick <PR504_COMMIT_SHA>
|
||||||
|
|
||||||
|
# Verify the only difference is "version" in package.json
|
||||||
|
git diff origin/canary
|
||||||
|
|
||||||
|
# Ship it
|
||||||
|
yarn publish-stable
|
||||||
|
```
|
||||||
|
|
||||||
|
After running this publish step, GitHub Actions will take care of publishing the modified Builder packages to npm.
|
||||||
|
|
||||||
|
If for some reason GitHub Actions fails to publish the npm package, you may do so
|
||||||
|
manually by running `npm publish` from the package directory. Make sure to
|
||||||
|
use `npm publish --tag canary` if you are publishing a canary release!
|
||||||
60
README.md
60
README.md
@@ -2,64 +2,18 @@
|
|||||||
|
|
||||||
This is a monorepo containing the [Official Builders](https://zeit.co/docs/v2/advanced/builders) provided by the ZEIT team.
|
This is a monorepo containing the [Official Builders](https://zeit.co/docs/v2/advanced/builders) provided by the ZEIT team.
|
||||||
|
|
||||||
## Channels
|
## Versioning and advanced usage
|
||||||
|
|
||||||
There are two Channels:
|
See [VERSIONING.md](VERSIONING.md).
|
||||||
|
|
||||||
| Channel | Git Branch | npm dist-tag | use example |
|
## Publishing to npm
|
||||||
| ------- | ------------------------------------------------------------- | ------------ | ------------------ |
|
|
||||||
| Canary | [canary](https://github.com/zeit/now-builders/commits/canary) | `@canary` | `@now/node@canary` |
|
|
||||||
| Stable | [master](https://github.com/zeit/now-builders/commits/master) | `@latest` | `@now/node@latest` |
|
|
||||||
|
|
||||||
All PRs should be submitted to the `canary` branch.
|
See [PUBLISHING.md](PUBLISHING.md).
|
||||||
|
|
||||||
Once a PR is merged into the `canary` branch, it should be published to npm immediately using the Canary Channel.
|
## Contributing
|
||||||
|
|
||||||
### Publishing to npm
|
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
|
|
||||||
For the Canary Channel, publish the modified Builders to npm with the following:
|
|
||||||
|
|
||||||
```
|
|
||||||
yarn publish-canary
|
|
||||||
```
|
|
||||||
|
|
||||||
For the Stable Channel, you must do the following:
|
|
||||||
|
|
||||||
- Cherry pick each commit from canary to master
|
|
||||||
- Verify that you are _in-sync_ with canary (with the exception of the `version` line in `package.json`)
|
|
||||||
- Deploy the modified Builders
|
|
||||||
|
|
||||||
```
|
|
||||||
# View differences excluding "Publish" commits
|
|
||||||
git checkout canary && git pull
|
|
||||||
git log --pretty=format:"$ad- %s [%an]" | grep -v Publish > ~/Desktop/canary.txt
|
|
||||||
git checkout master && git pull
|
|
||||||
git log --pretty=format:"$ad- %s [%an]" | grep -v Publish > ~/Desktop/master.txt
|
|
||||||
diff ~/Desktop/canary.txt ~/Desktop/master.txt
|
|
||||||
|
|
||||||
# Cherry pick all PRs from canary into master ...
|
|
||||||
git cherry-pick <PR501_COMMIT_SHA>
|
|
||||||
git cherry-pick <PR502_COMMIT_SHA>
|
|
||||||
git cherry-pick <PR503_COMMIT_SHA>
|
|
||||||
git cherry-pick <PR504_COMMIT_SHA>
|
|
||||||
|
|
||||||
# Verify the only difference is "version" in package.json
|
|
||||||
git diff origin/canary
|
|
||||||
|
|
||||||
# Ship it
|
|
||||||
yarn publish-stable
|
|
||||||
```
|
|
||||||
|
|
||||||
After running this publish step, GitHub Actions will take care of publishing the modified Builder packages to npm.
|
|
||||||
|
|
||||||
If for some reason GitHub Actions fails to publish the npm package, you may do so
|
|
||||||
manually by running `npm publish` from the package directory. Make sure to
|
|
||||||
use `npm publish --tag canary` if you are publishing a canary release!
|
|
||||||
|
|
||||||
### Contributing
|
|
||||||
|
|
||||||
See the [Contribution guidelines for this project](CONTRIBUTING.md), it also contains guidance on interpreting tests failures.
|
|
||||||
|
|
||||||
### Creating Your Own Builder
|
### Creating Your Own Builder
|
||||||
|
|
||||||
To create your own Builder, see [the Builder's Developer Reference](DEVELOPING_A_BUILDER.md).
|
See [DEVELOPING_A_BUILDER.md](DEVELOPING_A_BUILDER.md).
|
||||||
|
|||||||
25
VERSIONING.md
Normal file
25
VERSIONING.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Versioning
|
||||||
|
|
||||||
|
Builders are released to two different channels.
|
||||||
|
|
||||||
|
## Channels
|
||||||
|
|
||||||
|
| Channel | Git Branch | npm dist-tag | use example |
|
||||||
|
| ------- | ------------------------------------------------------------- | ------------ | ------------------ |
|
||||||
|
| Canary | [canary](https://github.com/zeit/now-builders/commits/canary) | `@canary` | `@now/node@canary` |
|
||||||
|
| Stable | [master](https://github.com/zeit/now-builders/commits/master) | `@latest` | `@now/node@latest` |
|
||||||
|
|
||||||
|
All PRs are submitted to the `canary` branch. Once a PR is merged into the `canary` branch, it should be published to npm immediately using the Canary Channel.
|
||||||
|
|
||||||
|
## Version Selection
|
||||||
|
|
||||||
|
Since Builders are published to [npmjs.com](https://npmjs.com), this makes versioning works the same for Builders as it does for any npm package. The `use` statement in [now.json](https://zeit.co/docs/v2/advanced/configuration#builds) has a similar syntax to `npm install`.
|
||||||
|
|
||||||
|
The following are valid examples [@now/node](https://www.npmjs.com/package/@now/node?activeTab=versions):
|
||||||
|
|
||||||
|
- `@now/node`
|
||||||
|
- `@now/node@0.7.3`
|
||||||
|
- `@now/node@canary`
|
||||||
|
- `@now/node@0.7.2-canary.2`
|
||||||
|
|
||||||
|
We always recommend using the latest version by leaving off the dist-tag suffix, `@now/node` for example.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/build-utils",
|
"name": "@now/build-utils",
|
||||||
"version": "0.9.11",
|
"version": "0.9.12",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.js",
|
"types": "./dist/index.d.js",
|
||||||
|
|||||||
@@ -58,19 +58,30 @@ function createRouteFromPath(filePath: string): Route {
|
|||||||
} else if (isLast) {
|
} else if (isLast) {
|
||||||
const { name: fileName, ext } = parsePath(segment);
|
const { name: fileName, ext } = parsePath(segment);
|
||||||
const isIndex = fileName === 'index';
|
const isIndex = fileName === 'index';
|
||||||
|
const prefix = isIndex ? '\\/' : '';
|
||||||
|
|
||||||
|
const names = [
|
||||||
|
prefix,
|
||||||
|
prefix + escapeName(fileName),
|
||||||
|
prefix + escapeName(fileName) + escapeName(ext),
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
// Either filename with extension, filename without extension
|
// Either filename with extension, filename without extension
|
||||||
// or nothing when the filename is `index`
|
// or nothing when the filename is `index`
|
||||||
return `(${escapeName(fileName)}|${escapeName(fileName)}${escapeName(
|
return `(${names.join('|')})${isIndex ? '?' : ''}`;
|
||||||
ext
|
|
||||||
)})${isIndex ? '?' : ''}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return segment;
|
return segment;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const src = `^/${srcParts.join('/')}$`;
|
const { name: fileName } = parsePath(filePath);
|
||||||
|
const isIndex = fileName === 'index';
|
||||||
|
|
||||||
|
const src = isIndex
|
||||||
|
? `^/${srcParts.slice(0, -1).join('/')}${srcParts.slice(-1)[0]}$`
|
||||||
|
: `^/${srcParts.join('/')}$`;
|
||||||
|
|
||||||
const dest = `/${filePath}${query.length ? '?' : ''}${query.join('&')}`;
|
const dest = `/${filePath}${query.length ? '?' : ''}${query.join('&')}`;
|
||||||
|
|
||||||
return { src, dest };
|
return { src, dest };
|
||||||
|
|||||||
1
packages/now-build-utils/test/fixtures/01-zero-config-api/.gitignore
vendored
Normal file
1
packages/now-build-utils/test/fixtures/01-zero-config-api/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
now.json
|
||||||
3
packages/now-build-utils/test/fixtures/01-zero-config-api/api/[endpoint].js
vendored
Normal file
3
packages/now-build-utils/test/fixtures/01-zero-config-api/api/[endpoint].js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res) => {
|
||||||
|
res.end(req.query.endpoint);
|
||||||
|
};
|
||||||
3
packages/now-build-utils/test/fixtures/01-zero-config-api/api/[endpoint]/[id].js
vendored
Normal file
3
packages/now-build-utils/test/fixtures/01-zero-config-api/api/[endpoint]/[id].js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res) => {
|
||||||
|
res.end(`${req.query.endpoint}/${req.query.id}`);
|
||||||
|
};
|
||||||
5
packages/now-build-utils/test/fixtures/01-zero-config-api/package.json
vendored
Normal file
5
packages/now-build-utils/test/fixtures/01-zero-config-api/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"build": "mkdir -p public && echo 'hello from index.txt' > public/index.txt"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
packages/now-build-utils/test/fixtures/02-zero-config-api/.gitignore
vendored
Normal file
1
packages/now-build-utils/test/fixtures/02-zero-config-api/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
now.json
|
||||||
3
packages/now-build-utils/test/fixtures/02-zero-config-api/api/date.js
vendored
Normal file
3
packages/now-build-utils/test/fixtures/02-zero-config-api/api/date.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res) => {
|
||||||
|
res.end('hello from api/date.js');
|
||||||
|
};
|
||||||
3
packages/now-build-utils/test/fixtures/02-zero-config-api/api/date/index.js
vendored
Normal file
3
packages/now-build-utils/test/fixtures/02-zero-config-api/api/date/index.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res) => {
|
||||||
|
res.end('hello from api/date/index.js');
|
||||||
|
};
|
||||||
3
packages/now-build-utils/test/fixtures/02-zero-config-api/api/index.js
vendored
Normal file
3
packages/now-build-utils/test/fixtures/02-zero-config-api/api/index.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = (req, res) => {
|
||||||
|
res.end('hello from api/index.js');
|
||||||
|
};
|
||||||
5
packages/now-build-utils/test/fixtures/02-zero-config-api/package.json
vendored
Normal file
5
packages/now-build-utils/test/fixtures/02-zero-config-api/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"build": "mkdir -p public && echo 'hello from index.txt' > public/index.txt"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,21 +4,21 @@ const fs = require('fs-extra');
|
|||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
const execa = require('execa');
|
const execa = require('execa');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const { createZip } = require('../dist/lambda');
|
||||||
const {
|
const {
|
||||||
glob, download, detectBuilders, detectRoutes,
|
glob, download, detectBuilders, detectRoutes,
|
||||||
} = require('../');
|
} = require('../');
|
||||||
const { createZip } = require('../dist/lambda');
|
|
||||||
const {
|
const {
|
||||||
getSupportedNodeVersion,
|
getSupportedNodeVersion,
|
||||||
defaultSelection,
|
defaultSelection,
|
||||||
} = require('../dist/fs/node-version');
|
} = require('../dist/fs/node-version');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
packAndDeploy,
|
packAndDeploy,
|
||||||
testDeployment,
|
testDeployment,
|
||||||
} = require('../../../test/lib/deployment/test-deployment.js');
|
} = require('../../../test/lib/deployment/test-deployment');
|
||||||
|
|
||||||
jest.setTimeout(4 * 60 * 1000);
|
jest.setTimeout(4 * 60 * 1000);
|
||||||
|
|
||||||
const builderUrl = '@canary';
|
const builderUrl = '@canary';
|
||||||
let buildUtilsUrl;
|
let buildUtilsUrl;
|
||||||
|
|
||||||
@@ -152,6 +152,11 @@ const fixturesPath = path.resolve(__dirname, 'fixtures');
|
|||||||
|
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
for (const fixture of fs.readdirSync(fixturesPath)) {
|
for (const fixture of fs.readdirSync(fixturesPath)) {
|
||||||
|
if (fixture.includes('zero-config')) {
|
||||||
|
// Those have separate tests
|
||||||
|
continue; // eslint-disable-line no-continue
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-loop-func
|
// eslint-disable-next-line no-loop-func
|
||||||
it(`should build ${fixture}`, async () => {
|
it(`should build ${fixture}`, async () => {
|
||||||
await expect(
|
await expect(
|
||||||
@@ -548,7 +553,9 @@ it('Test `detectRoutes`', async () => {
|
|||||||
const { defaultRoutes } = await detectRoutes(files, builders);
|
const { defaultRoutes } = await detectRoutes(files, builders);
|
||||||
|
|
||||||
expect(defaultRoutes.length).toBe(3);
|
expect(defaultRoutes.length).toBe(3);
|
||||||
expect(defaultRoutes[0].src).toBe('^/api/date/(index|index\\.js)?$');
|
expect(defaultRoutes[0].src).toBe(
|
||||||
|
'^/api/date(\\/|\\/index|\\/index\\.js)?$',
|
||||||
|
);
|
||||||
expect(defaultRoutes[0].dest).toBe('/api/date/index.js');
|
expect(defaultRoutes[0].dest).toBe('/api/date/index.js');
|
||||||
expect(defaultRoutes[1].src).toBe('^/api/(date|date\\.js)$');
|
expect(defaultRoutes[1].src).toBe('^/api/(date|date\\.js)$');
|
||||||
expect(defaultRoutes[1].dest).toBe('/api/date.js');
|
expect(defaultRoutes[1].dest).toBe('/api/date.js');
|
||||||
@@ -561,7 +568,9 @@ it('Test `detectRoutes`', async () => {
|
|||||||
const { defaultRoutes } = await detectRoutes(files, builders);
|
const { defaultRoutes } = await detectRoutes(files, builders);
|
||||||
|
|
||||||
expect(defaultRoutes.length).toBe(3);
|
expect(defaultRoutes.length).toBe(3);
|
||||||
expect(defaultRoutes[0].src).toBe('^/api/([^\\/]+)/(index|index\\.js)?$');
|
expect(defaultRoutes[0].src).toBe(
|
||||||
|
'^/api/([^\\/]+)(\\/|\\/index|\\/index\\.js)?$',
|
||||||
|
);
|
||||||
expect(defaultRoutes[0].dest).toBe('/api/[date]/index.js?date=$1');
|
expect(defaultRoutes[0].dest).toBe('/api/[date]/index.js?date=$1');
|
||||||
expect(defaultRoutes[1].src).toBe('^/api/(date|date\\.js)$');
|
expect(defaultRoutes[1].src).toBe('^/api/(date|date\\.js)$');
|
||||||
expect(defaultRoutes[1].dest).toBe('/api/date.js');
|
expect(defaultRoutes[1].dest).toBe('/api/date.js');
|
||||||
@@ -587,3 +596,146 @@ it('Test `detectRoutes`', async () => {
|
|||||||
expect(defaultRoutes.length).toBe(5);
|
expect(defaultRoutes.length).toBe(5);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Test `detectBuilders` and `detectRoutes`', async () => {
|
||||||
|
const fixture = path.join(__dirname, 'fixtures', '01-zero-config-api');
|
||||||
|
const pkg = await fs.readJSON(path.join(fixture, 'package.json'));
|
||||||
|
const fileList = await glob('**', fixture);
|
||||||
|
const files = Object.keys(fileList);
|
||||||
|
|
||||||
|
const probes = [
|
||||||
|
{
|
||||||
|
path: '/api/my-endpoint',
|
||||||
|
mustContain: 'my-endpoint',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/other-endpoint',
|
||||||
|
mustContain: 'other-endpoint',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/team/zeit',
|
||||||
|
mustContain: 'team/zeit',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/user/myself',
|
||||||
|
mustContain: 'user/myself',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/not-okay/',
|
||||||
|
status: 404,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api',
|
||||||
|
status: 404,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/',
|
||||||
|
status: 404,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
mustContain: 'hello from index.txt',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const { builders } = await detectBuilders(files, pkg);
|
||||||
|
const { defaultRoutes } = await detectRoutes(files, builders);
|
||||||
|
|
||||||
|
const nowConfig = { builds: builders, routes: defaultRoutes, probes };
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(fixture, 'now.json'),
|
||||||
|
JSON.stringify(nowConfig, null, 2),
|
||||||
|
);
|
||||||
|
|
||||||
|
const deployment = await testDeployment(
|
||||||
|
{ builderUrl, buildUtilsUrl },
|
||||||
|
fixture,
|
||||||
|
);
|
||||||
|
expect(deployment).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test `detectBuilders` and `detectRoutes` with `index` files', async () => {
|
||||||
|
const fixture = path.join(__dirname, 'fixtures', '02-zero-config-api');
|
||||||
|
const pkg = await fs.readJSON(path.join(fixture, 'package.json'));
|
||||||
|
const fileList = await glob('**', fixture);
|
||||||
|
const files = Object.keys(fileList);
|
||||||
|
|
||||||
|
const probes = [
|
||||||
|
{
|
||||||
|
path: '/api/not-okay',
|
||||||
|
status: 404,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api',
|
||||||
|
mustContain: 'hello from api/index.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/',
|
||||||
|
mustContain: 'hello from api/index.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/index',
|
||||||
|
mustContain: 'hello from api/index.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/index.js',
|
||||||
|
mustContain: 'hello from api/index.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/date.js',
|
||||||
|
mustContain: 'hello from api/date.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Someone might expect this to be `date.js`,
|
||||||
|
// but I doubt that there is any case were both
|
||||||
|
// `date/index.js` and `date.js` exists,
|
||||||
|
// so it is not special cased
|
||||||
|
path: '/api/date',
|
||||||
|
mustContain: 'hello from api/date/index.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/date/',
|
||||||
|
mustContain: 'hello from api/date/index.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/date/index',
|
||||||
|
mustContain: 'hello from api/date/index.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/api/date/index.js',
|
||||||
|
mustContain: 'hello from api/date/index.js',
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
mustContain: 'hello from index.txt',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const { builders } = await detectBuilders(files, pkg);
|
||||||
|
const { defaultRoutes } = await detectRoutes(files, builders);
|
||||||
|
|
||||||
|
const nowConfig = { builds: builders, routes: defaultRoutes, probes };
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(fixture, 'now.json'),
|
||||||
|
JSON.stringify(nowConfig, null, 2),
|
||||||
|
);
|
||||||
|
|
||||||
|
const deployment = await testDeployment(
|
||||||
|
{ builderUrl, buildUtilsUrl },
|
||||||
|
fixture,
|
||||||
|
);
|
||||||
|
expect(deployment).toBeDefined();
|
||||||
|
});
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ Learn more: https://github.com/golang/go/wiki/Modules
|
|||||||
if (!analyzed) {
|
if (!analyzed) {
|
||||||
const err = new Error(
|
const err = new Error(
|
||||||
`Could not find an exported function in "${entrypoint}"
|
`Could not find an exported function in "${entrypoint}"
|
||||||
Learn more: https://zeit.co/docs/v2/deployments/official-builders/go-now-go/#entrypoint
|
Learn more: https://zeit.co/docs/v2/advanced/builders/#go
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
console.log(err.message);
|
console.log(err.message);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/go",
|
"name": "@now/go",
|
||||||
"version": "0.5.9",
|
"version": "0.5.10",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/go-now-go",
|
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/go-now-go",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/next",
|
"name": "@now/next",
|
||||||
"version": "0.5.10",
|
"version": "0.6.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/next-js-now-next",
|
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/next-js-now-next",
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
"@types/next-server": "8.0.0",
|
"@types/next-server": "8.0.0",
|
||||||
"@types/resolve-from": "5.0.1",
|
"@types/resolve-from": "5.0.1",
|
||||||
"@types/semver": "6.0.0",
|
"@types/semver": "6.0.0",
|
||||||
"@zeit/node-file-trace": "0.2.7",
|
"@zeit/node-file-trace": "0.2.9",
|
||||||
"fs-extra": "7.0.0",
|
"fs-extra": "7.0.0",
|
||||||
"get-port": "5.0.0",
|
"get-port": "5.0.0",
|
||||||
"resolve-from": "5.0.0",
|
"resolve-from": "5.0.0",
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import path from 'path';
|
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
import path from 'path';
|
||||||
|
import semver from 'semver';
|
||||||
|
|
||||||
function getCustomData(importName: string) {
|
import { ExperimentalTraceVersion } from './utils';
|
||||||
|
|
||||||
|
function getCustomData(importName: string, target: string) {
|
||||||
return `
|
return `
|
||||||
module.exports = function(...args) {
|
module.exports = function(...args) {
|
||||||
let original = require('./${importName}');
|
let original = require('./${importName}');
|
||||||
|
|
||||||
const finalConfig = {};
|
const finalConfig = {};
|
||||||
const target = { target: 'serverless' };
|
const target = { target: '${target}' };
|
||||||
|
|
||||||
if (typeof original === 'function' && original.constructor.name === 'AsyncFunction') {
|
if (typeof original === 'function' && original.constructor.name === 'AsyncFunction') {
|
||||||
// AsyncFunctions will become promises
|
// AsyncFunctions will become promises
|
||||||
@@ -37,14 +40,29 @@ function getDefaultData() {
|
|||||||
return `module.exports = { target: 'serverless' };`;
|
return `module.exports = { target: 'serverless' };`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function createServerlessConfig(workPath: string) {
|
export default async function createServerlessConfig(
|
||||||
|
workPath: string,
|
||||||
|
nextVersion: string | undefined
|
||||||
|
) {
|
||||||
|
let target = 'serverless';
|
||||||
|
if (nextVersion) {
|
||||||
|
try {
|
||||||
|
if (
|
||||||
|
nextVersion.includes('canary') &&
|
||||||
|
semver.satisfies(nextVersion, `>=${ExperimentalTraceVersion}`)
|
||||||
|
) {
|
||||||
|
target = 'experimental-serverless-trace';
|
||||||
|
}
|
||||||
|
} catch (_ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
const configPath = path.join(workPath, 'next.config.js');
|
const configPath = path.join(workPath, 'next.config.js');
|
||||||
const backupConfigName = `next.config.original.${Date.now()}.js`;
|
const backupConfigName = `next.config.original.${Date.now()}.js`;
|
||||||
const backupConfigPath = path.join(workPath, backupConfigName);
|
const backupConfigPath = path.join(workPath, backupConfigName);
|
||||||
|
|
||||||
if (fs.existsSync(configPath)) {
|
if (fs.existsSync(configPath)) {
|
||||||
await fs.rename(configPath, backupConfigPath);
|
await fs.rename(configPath, backupConfigPath);
|
||||||
await fs.writeFile(configPath, getCustomData(backupConfigName));
|
await fs.writeFile(configPath, getCustomData(backupConfigName, target));
|
||||||
} else {
|
} else {
|
||||||
await fs.writeFile(configPath, getDefaultData());
|
await fs.writeFile(configPath, getDefaultData());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,12 @@ import {
|
|||||||
} from 'fs-extra';
|
} from 'fs-extra';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import resolveFrom from 'resolve-from';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BuildOptions,
|
BuildOptions,
|
||||||
|
Config,
|
||||||
createLambda,
|
createLambda,
|
||||||
download,
|
download,
|
||||||
FileBlob,
|
FileBlob,
|
||||||
@@ -21,16 +23,18 @@ import {
|
|||||||
glob,
|
glob,
|
||||||
Lambda,
|
Lambda,
|
||||||
PrepareCacheOptions,
|
PrepareCacheOptions,
|
||||||
|
Route,
|
||||||
runNpmInstall,
|
runNpmInstall,
|
||||||
runPackageJsonScript,
|
runPackageJsonScript,
|
||||||
Route,
|
|
||||||
} from '@now/build-utils';
|
} from '@now/build-utils';
|
||||||
|
import nodeFileTrace from '@zeit/node-file-trace';
|
||||||
|
|
||||||
import createServerlessConfig from './create-serverless-config';
|
import createServerlessConfig from './create-serverless-config';
|
||||||
import nextLegacyVersions from './legacy-versions';
|
import nextLegacyVersions from './legacy-versions';
|
||||||
import {
|
import {
|
||||||
EnvConfig,
|
EnvConfig,
|
||||||
excludeFiles,
|
excludeFiles,
|
||||||
|
ExperimentalTraceVersion,
|
||||||
filesFromDirectory,
|
filesFromDirectory,
|
||||||
getDynamicRoutes,
|
getDynamicRoutes,
|
||||||
getNextConfig,
|
getNextConfig,
|
||||||
@@ -156,7 +160,7 @@ export const build = async ({
|
|||||||
files,
|
files,
|
||||||
workPath,
|
workPath,
|
||||||
entrypoint,
|
entrypoint,
|
||||||
config,
|
config = {} as Config,
|
||||||
meta = {} as BuildParamsMeta,
|
meta = {} as BuildParamsMeta,
|
||||||
}: BuildParamsType): Promise<{
|
}: BuildParamsType): Promise<{
|
||||||
routes: Route[];
|
routes: Route[];
|
||||||
@@ -176,10 +180,6 @@ export const build = async ({
|
|||||||
const pkg = await readPackageJson(entryPath);
|
const pkg = await readPackageJson(entryPath);
|
||||||
const nextVersion = getNextVersion(pkg);
|
const nextVersion = getNextVersion(pkg);
|
||||||
|
|
||||||
if (!meta.isDev) {
|
|
||||||
await createServerlessConfig(workPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodeVersion = await getNodeVersion(entryPath, undefined, config);
|
const nodeVersion = await getNodeVersion(entryPath, undefined, config);
|
||||||
const spawnOpts = getSpawnOptions(meta, nodeVersion);
|
const spawnOpts = getSpawnOptions(meta, nodeVersion);
|
||||||
|
|
||||||
@@ -284,6 +284,20 @@ export const build = async ({
|
|||||||
console.log('installing dependencies...');
|
console.log('installing dependencies...');
|
||||||
await runNpmInstall(entryPath, ['--prefer-offline'], spawnOpts);
|
await runNpmInstall(entryPath, ['--prefer-offline'], spawnOpts);
|
||||||
|
|
||||||
|
let realNextVersion: string | undefined;
|
||||||
|
try {
|
||||||
|
realNextVersion = require(resolveFrom(entryPath, 'next/package.json'))
|
||||||
|
.version;
|
||||||
|
|
||||||
|
console.log(`detected Next.js version: ${realNextVersion}`);
|
||||||
|
} catch (_ignored) {
|
||||||
|
console.warn(`could not identify real Next.js version, that's OK!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLegacy) {
|
||||||
|
await createServerlessConfig(workPath, realNextVersion);
|
||||||
|
}
|
||||||
|
|
||||||
console.log('running user script...');
|
console.log('running user script...');
|
||||||
const memoryToConsume = Math.floor(os.totalmem() / 1024 ** 2) - 128;
|
const memoryToConsume = Math.floor(os.totalmem() / 1024 ** 2) - 128;
|
||||||
const env = { ...spawnOpts.env } as any;
|
const env = { ...spawnOpts.env } as any;
|
||||||
@@ -394,14 +408,6 @@ export const build = async ({
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log('preparing lambda files...');
|
console.log('preparing lambda files...');
|
||||||
const launcherFiles = {
|
|
||||||
'now__bridge.js': new FileFsRef({
|
|
||||||
fsPath: path.join(__dirname, 'now__bridge.js'),
|
|
||||||
}),
|
|
||||||
'now__launcher.js': new FileFsRef({
|
|
||||||
fsPath: path.join(__dirname, 'launcher.js'),
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
const pagesDir = path.join(entryPath, '.next', 'serverless', 'pages');
|
const pagesDir = path.join(entryPath, '.next', 'serverless', 'pages');
|
||||||
|
|
||||||
const pages = await glob('**/*.js', pagesDir);
|
const pages = await glob('**/*.js', pagesDir);
|
||||||
@@ -440,18 +446,77 @@ export const build = async ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// An optional assets folder that is placed alongside every page entrypoint
|
// Assume tracing to be safe, bail if we know we don't need it.
|
||||||
const assets = await glob(
|
let requiresTracing = true;
|
||||||
'assets/**',
|
try {
|
||||||
path.join(entryPath, '.next', 'serverless')
|
if (
|
||||||
);
|
realNextVersion &&
|
||||||
|
semver.satisfies(realNextVersion, `<${ExperimentalTraceVersion}`)
|
||||||
const assetKeys = Object.keys(assets);
|
) {
|
||||||
if (assetKeys.length > 0) {
|
if (config.debug) {
|
||||||
console.log('detected assets to be bundled with lambda:');
|
console.log(
|
||||||
assetKeys.forEach(assetFile => console.log(`\t${assetFile}`));
|
'Next.js version is too old for us to trace the required dependencies.\n' +
|
||||||
|
'Assuming Next.js has handled it!'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
requiresTracing = false;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (config.debug) {
|
||||||
|
console.log(
|
||||||
|
'Failed to check Next.js version for tracing compatibility: ' + err
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let assets:
|
||||||
|
| {
|
||||||
|
[filePath: string]: FileFsRef;
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
const tracedFiles: {
|
||||||
|
[filePath: string]: FileFsRef;
|
||||||
|
} = {};
|
||||||
|
if (requiresTracing) {
|
||||||
|
const tracingLabel = 'Tracing Next.js lambdas for external files ...';
|
||||||
|
console.time(tracingLabel);
|
||||||
|
|
||||||
|
const { fileList } = await nodeFileTrace(
|
||||||
|
Object.keys(pages).map(page => pages[page].fsPath),
|
||||||
|
{ base: workPath }
|
||||||
|
);
|
||||||
|
if (config.debug) {
|
||||||
|
console.log(`node-file-trace result for pages: ${fileList}`);
|
||||||
|
}
|
||||||
|
fileList.forEach(file => {
|
||||||
|
tracedFiles[file] = new FileFsRef({
|
||||||
|
fsPath: path.join(workPath, file),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
console.timeEnd(tracingLabel);
|
||||||
|
} else {
|
||||||
|
// An optional assets folder that is placed alongside every page
|
||||||
|
// entrypoint.
|
||||||
|
// This is a legacy feature that was needed before we began tracing
|
||||||
|
// lambdas.
|
||||||
|
assets = await glob(
|
||||||
|
'assets/**',
|
||||||
|
path.join(entryPath, '.next', 'serverless')
|
||||||
|
);
|
||||||
|
|
||||||
|
const assetKeys = Object.keys(assets!);
|
||||||
|
if (assetKeys.length > 0) {
|
||||||
|
console.log('detected (legacy) assets to be bundled with lambda:');
|
||||||
|
assetKeys.forEach(assetFile => console.log(`\t${assetFile}`));
|
||||||
|
console.log(
|
||||||
|
'\nPlease upgrade to Next.js 9.1 to leverage modern asset handling.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const launcherPath = path.join(__dirname, 'templated-launcher.js');
|
||||||
|
const launcherData = await readFile(launcherPath, 'utf8');
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pageKeys.map(async page => {
|
pageKeys.map(async page => {
|
||||||
// These default pages don't have to be handled as they'd always 404
|
// These default pages don't have to be handled as they'd always 404
|
||||||
@@ -465,17 +530,34 @@ export const build = async ({
|
|||||||
dynamicPages.push(normalizePage(pathname));
|
dynamicPages.push(normalizePage(pathname));
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Creating lambda for page: "${page}"...`);
|
const label = `Creating lambda for page: "${page}"...`;
|
||||||
|
console.time(label);
|
||||||
|
|
||||||
|
const pageFileName = path.relative(workPath, pages[page].fsPath);
|
||||||
|
const launcher = launcherData.replace(
|
||||||
|
/__LAUNCHER_PAGE_PATH__/g,
|
||||||
|
JSON.stringify(
|
||||||
|
requiresTracing ? path.join('./', pageFileName) : './page'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
const launcherFiles = {
|
||||||
|
'now__bridge.js': new FileFsRef({
|
||||||
|
fsPath: path.join(__dirname, 'now__bridge.js'),
|
||||||
|
}),
|
||||||
|
'now__launcher.js': new FileBlob({ data: launcher }),
|
||||||
|
};
|
||||||
|
|
||||||
lambdas[path.join(entryDirectory, pathname)] = await createLambda({
|
lambdas[path.join(entryDirectory, pathname)] = await createLambda({
|
||||||
files: {
|
files: {
|
||||||
...launcherFiles,
|
...launcherFiles,
|
||||||
...assets,
|
...assets,
|
||||||
'page.js': pages[page],
|
...tracedFiles,
|
||||||
|
[requiresTracing ? pageFileName : 'page.js']: pages[page],
|
||||||
},
|
},
|
||||||
handler: 'now__launcher.launcher',
|
handler: 'now__launcher.launcher',
|
||||||
runtime: nodeVersion.runtime,
|
runtime: nodeVersion.runtime,
|
||||||
});
|
});
|
||||||
console.log(`Created lambda for page: "${page}"`);
|
console.timeEnd(label);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ if (!process.env.NODE_ENV) {
|
|||||||
|
|
||||||
import { Server } from 'http';
|
import { Server } from 'http';
|
||||||
import { Bridge } from './now__bridge';
|
import { Bridge } from './now__bridge';
|
||||||
const page = require('./page');
|
// @ts-ignore
|
||||||
|
const page = require(__LAUNCHER_PAGE_PATH__);
|
||||||
|
|
||||||
// page.render is for React rendering
|
// page.render is for React rendering
|
||||||
// page.default is for /api rendering
|
// page.default is for /api rendering
|
||||||
@@ -356,6 +356,8 @@ function syncEnvVars(base: EnvConfig, removeEnv: EnvConfig, addEnv: EnvConfig) {
|
|||||||
Object.assign(base, addEnv);
|
Object.assign(base, addEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ExperimentalTraceVersion = `9.0.4-canary.1`;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
excludeFiles,
|
excludeFiles,
|
||||||
validateEntrypoint,
|
validateEntrypoint,
|
||||||
|
|||||||
5
packages/now-next/test/fixtures/02-firebase/next.config.js
vendored
Normal file
5
packages/now-next/test/fixtures/02-firebase/next.config.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
generateBuildId() {
|
||||||
|
return 'testing-build-id';
|
||||||
|
},
|
||||||
|
};
|
||||||
8
packages/now-next/test/fixtures/02-firebase/now.json
vendored
Normal file
8
packages/now-next/test/fixtures/02-firebase/now.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [{ "src": "package.json", "use": "@now/next" }],
|
||||||
|
"probes": [
|
||||||
|
{ "path": "/nested/fb", "mustContain": "Hello Firebase: <!-- -->0" },
|
||||||
|
{ "path": "/nested/moar/fb", "mustContain": "Hello Firebase: <!-- -->0" }
|
||||||
|
]
|
||||||
|
}
|
||||||
8
packages/now-next/test/fixtures/02-firebase/package.json
vendored
Normal file
8
packages/now-next/test/fixtures/02-firebase/package.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"next": "canary",
|
||||||
|
"react": "^16.8.6",
|
||||||
|
"react-dom": "^16.8.6",
|
||||||
|
"firebase": "6.3.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
packages/now-next/test/fixtures/02-firebase/pages/nested/fb.js
vendored
Normal file
19
packages/now-next/test/fixtures/02-firebase/pages/nested/fb.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import firebase from 'firebase/app';
|
||||||
|
import 'firebase/firestore';
|
||||||
|
|
||||||
|
if (!firebase.apps.length) {
|
||||||
|
firebase.initializeApp({ projectId: 'noop' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = firebase.firestore();
|
||||||
|
|
||||||
|
const Comp = ({ results }) => {
|
||||||
|
return <div>Hello Firebase: {results}</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
Comp.getInitialProps = async () => {
|
||||||
|
const query = await store.collection('users').get();
|
||||||
|
return { results: query.size };
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Comp;
|
||||||
19
packages/now-next/test/fixtures/02-firebase/pages/nested/moar/fb.js
vendored
Normal file
19
packages/now-next/test/fixtures/02-firebase/pages/nested/moar/fb.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import firebase from 'firebase/app';
|
||||||
|
import 'firebase/firestore';
|
||||||
|
|
||||||
|
if (!firebase.apps.length) {
|
||||||
|
firebase.initializeApp({ projectId: 'noop' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = firebase.firestore();
|
||||||
|
|
||||||
|
const Comp = ({ results }) => {
|
||||||
|
return <div>Hello Firebase: {results}</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
Comp.getInitialProps = async () => {
|
||||||
|
const query = await store.collection('users').get();
|
||||||
|
return { results: query.size };
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Comp;
|
||||||
5
packages/now-next/test/fixtures/03-next-8/next.config.js
vendored
Normal file
5
packages/now-next/test/fixtures/03-next-8/next.config.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
generateBuildId() {
|
||||||
|
return 'testing-build-id';
|
||||||
|
},
|
||||||
|
};
|
||||||
8
packages/now-next/test/fixtures/03-next-8/now.json
vendored
Normal file
8
packages/now-next/test/fixtures/03-next-8/now.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [{ "src": "package.json", "use": "@now/next" }],
|
||||||
|
"probes": [
|
||||||
|
{ "path": "/hello1", "mustContain": "Hello World 1" },
|
||||||
|
{ "path": "/nested/hello2", "mustContain": "Hello World 2" }
|
||||||
|
]
|
||||||
|
}
|
||||||
7
packages/now-next/test/fixtures/03-next-8/package.json
vendored
Normal file
7
packages/now-next/test/fixtures/03-next-8/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"next": "8.x.x",
|
||||||
|
"react": "^16.8.6",
|
||||||
|
"react-dom": "^16.8.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
7
packages/now-next/test/fixtures/03-next-8/pages/hello1.js
vendored
Normal file
7
packages/now-next/test/fixtures/03-next-8/pages/hello1.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
function A({ data }) {
|
||||||
|
return <div>{data}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
A.getInitialProps = () => ({ data: 'Hello World 1' });
|
||||||
|
|
||||||
|
export default A;
|
||||||
7
packages/now-next/test/fixtures/03-next-8/pages/nested/hello2.js
vendored
Normal file
7
packages/now-next/test/fixtures/03-next-8/pages/nested/hello2.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
function B({ data }) {
|
||||||
|
return <div>{data}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
B.getInitialProps = () => ({ data: 'Hello World 2' });
|
||||||
|
|
||||||
|
export default B;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node",
|
"name": "@now/node",
|
||||||
"version": "0.12.5",
|
"version": "0.12.6",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/node-js-now-node",
|
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/node-js-now-node",
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
"@types/etag": "1.8.0",
|
"@types/etag": "1.8.0",
|
||||||
"@types/test-listen": "1.1.0",
|
"@types/test-listen": "1.1.0",
|
||||||
"@zeit/ncc": "0.20.4",
|
"@zeit/ncc": "0.20.4",
|
||||||
"@zeit/node-file-trace": "0.2.7",
|
"@zeit/node-file-trace": "0.2.9",
|
||||||
"content-type": "1.0.4",
|
"content-type": "1.0.4",
|
||||||
"cookie": "0.4.0",
|
"cookie": "0.4.0",
|
||||||
"etag": "1.8.1",
|
"etag": "1.8.1",
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ elif 'app' in __now_variables:
|
|||||||
}
|
}
|
||||||
|
|
||||||
for key, value in environ.items():
|
for key, value in environ.items():
|
||||||
if isinstance(value, string_types) and key != 'QUERY_STRING':
|
if isinstance(value, string_types):
|
||||||
environ[key] = wsgi_encoding_dance(value)
|
environ[key] = wsgi_encoding_dance(value)
|
||||||
|
|
||||||
for key, value in headers.items():
|
for key, value in headers.items():
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/python",
|
"name": "@now/python",
|
||||||
"version": "0.2.14",
|
"version": "0.2.15",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/python-now-python",
|
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/python-now-python",
|
||||||
|
|||||||
8
packages/now-python/test/fixtures/13-wsgi-url-params-encoding/custom.py
vendored
Normal file
8
packages/now-python/test/fixtures/13-wsgi-url-params-encoding/custom.py
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from flask import Flask, Response, request, __version__
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/', defaults={'path': ''})
|
||||||
|
@app.route('/<path:path>')
|
||||||
|
def catch_all(path):
|
||||||
|
qs = request.args.to_dict()
|
||||||
|
return Response("path: %s query: %s" %(path, qs), mimetype='text/html')
|
||||||
8
packages/now-python/test/fixtures/13-wsgi-url-params-encoding/index.py
vendored
Normal file
8
packages/now-python/test/fixtures/13-wsgi-url-params-encoding/index.py
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from flask import Flask, Response, request, __version__
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/', defaults={'path': ''})
|
||||||
|
@app.route('/<path:path>')
|
||||||
|
def catch_all(path):
|
||||||
|
qs = request.args.to_dict()
|
||||||
|
return Response("path: %s query: %s" %(path, qs), mimetype='text/html')
|
||||||
15
packages/now-python/test/fixtures/13-wsgi-url-params-encoding/now.json
vendored
Normal file
15
packages/now-python/test/fixtures/13-wsgi-url-params-encoding/now.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [{ "src": "*.py", "use": "@now/python" }],
|
||||||
|
"routes": [{ "src": "/%E6%82%A8%E5%A5%BD", "dest": "custom.py" }],
|
||||||
|
"probes": [
|
||||||
|
{
|
||||||
|
"path": "/?%E6%82%A8%E5%A5%BD=/",
|
||||||
|
"mustContain": "path: query: {'您好': '/'}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "/%E6%82%A8%E5%A5%BD?hello=/",
|
||||||
|
"mustContain": "path: 您好 query: {'hello': '/'}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
1
packages/now-python/test/fixtures/13-wsgi-url-params-encoding/requirements.txt
vendored
Normal file
1
packages/now-python/test/fixtures/13-wsgi-url-params-encoding/requirements.txt
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Flask==1.0.2
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/static-build",
|
"name": "@now/static-build",
|
||||||
"version": "0.9.6",
|
"version": "0.9.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/static-build-now-static-build",
|
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/static-build-now-static-build",
|
||||||
|
|||||||
@@ -65,23 +65,23 @@ export default [
|
|||||||
dependency: '@vue/cli-service',
|
dependency: '@vue/cli-service',
|
||||||
getOutputDirName: async () => 'dist',
|
getOutputDirName: async () => 'dist',
|
||||||
defaultRoutes: [
|
defaultRoutes: [
|
||||||
{
|
|
||||||
handle: 'filesystem',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
src: '^/js/(.*)',
|
src: '^/js/(.*)',
|
||||||
headers: { 'cache-control': 'max-age=31536000, immutable' },
|
headers: { 'cache-control': 'max-age=31536000, immutable' },
|
||||||
dest: '/js/$1',
|
continue: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
src: '^/css/(.*)',
|
src: '^/css/(.*)',
|
||||||
headers: { 'cache-control': 'max-age=31536000, immutable' },
|
headers: { 'cache-control': 'max-age=31536000, immutable' },
|
||||||
dest: '/css/$1',
|
continue: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
src: '^/img/(.*)',
|
src: '^/img/(.*)',
|
||||||
headers: { 'cache-control': 'max-age=31536000, immutable' },
|
headers: { 'cache-control': 'max-age=31536000, immutable' },
|
||||||
dest: '/img/$1',
|
continue: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
handle: 'filesystem',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
src: '/(.*)',
|
src: '/(.*)',
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
{
|
{
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"builds": [
|
"builds": [
|
||||||
{ "src": "package.json", "use": "@now/static-build", "config": { "zeroConfig": true } }
|
{
|
||||||
|
"src": "package.json",
|
||||||
|
"use": "@now/static-build",
|
||||||
|
"config": { "zeroConfig": true }
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"probes": [
|
"probes": [
|
||||||
{ "path": "/", "mustContain": "13-vue" },
|
{ "path": "/", "mustContain": "13-vue" },
|
||||||
|
{
|
||||||
|
"path": "/js/app.js",
|
||||||
|
"headers": { "cache-control": "max-age=31536000, immutable" },
|
||||||
|
"mustContain": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "/css/app.css",
|
||||||
|
"headers": { "cache-control": "max-age=31536000, immutable" },
|
||||||
|
"mustContain": "font-family"
|
||||||
|
},
|
||||||
{ "path": "/923h3223329ddas", "mustContain": "13-vue" }
|
{ "path": "/923h3223329ddas", "mustContain": "13-vue" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
5
packages/now-static-build/test/fixtures/13-vue/vue.config.js
vendored
Normal file
5
packages/now-static-build/test/fixtures/13-vue/vue.config.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
// This is necessary for our test probes
|
||||||
|
// so that the generated file names are deterministic.
|
||||||
|
filenameHashing: false,
|
||||||
|
};
|
||||||
@@ -90,6 +90,16 @@ async function testDeployment (
|
|||||||
const { text, resp } = await fetchDeploymentUrl(probeUrl, fetchOpts);
|
const { text, resp } = await fetchDeploymentUrl(probeUrl, fetchOpts);
|
||||||
console.log('finished testing', JSON.stringify(probe));
|
console.log('finished testing', JSON.stringify(probe));
|
||||||
|
|
||||||
|
if (probe.status) {
|
||||||
|
if (probe.status !== resp.status) {
|
||||||
|
throw new Error(
|
||||||
|
`Fetched page ${probeUrl} does not return the status ${
|
||||||
|
probe.status
|
||||||
|
} Instead it has ${resp.status}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (probe.mustContain) {
|
if (probe.mustContain) {
|
||||||
if (!text.includes(probe.mustContain)) {
|
if (!text.includes(probe.mustContain)) {
|
||||||
await fs.writeFile(path.join(__dirname, 'failed-page.txt'), text);
|
await fs.writeFile(path.join(__dirname, 'failed-page.txt'), text);
|
||||||
@@ -117,7 +127,7 @@ async function testDeployment (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else if (!probe.status) {
|
||||||
assert(false, 'probe must have a test condition');
|
assert(false, 'probe must have a test condition');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,14 +150,10 @@ async function nowDeployIndexTgz (file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fetchDeploymentUrl (url, opts) {
|
async function fetchDeploymentUrl (url, opts) {
|
||||||
for (let i = 0; i < 500; i += 1) {
|
for (let i = 0; i < 50; i += 1) {
|
||||||
const resp = await fetch(url, opts);
|
const resp = await fetch(url, opts);
|
||||||
const text = await resp.text();
|
const text = await resp.text();
|
||||||
if (
|
if (text && !text.includes('Join Free')) {
|
||||||
text
|
|
||||||
&& !text.includes('Join Free')
|
|
||||||
&& !text.includes('The page could not be found')
|
|
||||||
) {
|
|
||||||
return { resp, text };
|
return { resp, text };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1480,10 +1480,10 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.20.4.tgz#00f0a25a88cac3712af4ba66561d9e281c6f05c9"
|
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.20.4.tgz#00f0a25a88cac3712af4ba66561d9e281c6f05c9"
|
||||||
integrity sha512-fmq+F/QxPec+k/zvT7HiVpk7oiGFseS6brfT/AYqmCUp6QFRK7vZf2Ref46MImsg/g2W3g5X6SRvGRmOAvEfdA==
|
integrity sha512-fmq+F/QxPec+k/zvT7HiVpk7oiGFseS6brfT/AYqmCUp6QFRK7vZf2Ref46MImsg/g2W3g5X6SRvGRmOAvEfdA==
|
||||||
|
|
||||||
"@zeit/node-file-trace@0.2.7":
|
"@zeit/node-file-trace@0.2.9":
|
||||||
version "0.2.7"
|
version "0.2.9"
|
||||||
resolved "https://registry.yarnpkg.com/@zeit/node-file-trace/-/node-file-trace-0.2.7.tgz#af6efa0fd1753e70eff6f627581963c5f0a23b64"
|
resolved "https://registry.yarnpkg.com/@zeit/node-file-trace/-/node-file-trace-0.2.9.tgz#176aa55ae4800bfc847076b69b33df3bebc60201"
|
||||||
integrity sha512-4y8fLbe6heqlsAcu8M1LbwNHLx11P8LSsdh5aYoz2PL2yAo70t47qPY74njM1NuIHqdWInKDx4bGc8fOsn7AdA==
|
integrity sha512-OZU4HqNwlCEDIW67WTQnRjQ0ML7o9O8boPf1f9ffZbliKWRJrBPU+ydqvUtJeHICmY5Cjy9MQxwzo+q81G3uAA==
|
||||||
dependencies:
|
dependencies:
|
||||||
acorn "^6.1.1"
|
acorn "^6.1.1"
|
||||||
acorn-stage3 "^2.0.0"
|
acorn-stage3 "^2.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user