Compare commits

..

4 Commits

Author SHA1 Message Date
JJ Kasper
4f0f44e746 Publish Stable
- @now/next@2.3.3
2020-01-02 13:18:38 -06:00
JJ Kasper
0da98a7f5d Revert "[now-next] Implement handle: miss for custom-routes (#3456)" (#3488)
This reverts commit 40bbff9bee.
2020-01-02 13:15:16 -06:00
Steven
685989ae57 Publish Canary
- @now/build-utils@1.2.1-canary.6
 - @now/next@2.3.3-canary.0
 - @now/node@1.3.1-canary.1
 - @now/static-build@0.14.1-canary.7
2020-01-02 12:42:36 -05:00
Steven
6bc121e7b1 [now-build-utils] Add support for getLatestNodeVersion() and config.nodeVersion (#3483)
This PR does a few things:

1. Add functions `getLatestNodeVersion()` and `getOldestNodeVersion()` for use in api-project.
2. Add property `config.nodeVersion` which has precedence over default Node 8.

We want new projects to use the latest node version without setting any configuration but we don't want to break old projects. So during project creation, the value of `getLatestNodeVersion()` will be saved and then each deployment of that project will assign that value to `config.nodeVersion`. 

Implements [PRODUCT-837]

[PRODUCT-837]: https://zeit.atlassian.net/browse/PRODUCT-837
2020-01-02 17:34:31 +00:00
19 changed files with 66 additions and 104 deletions

View File

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

View File

@@ -16,17 +16,19 @@ const allOptions: NodeVersion[] = [
const supportedOptions = allOptions.filter(o => !isDiscontinued(o));
// This version should match Fargate's default in the PATH
// Today that is Node 8
export const defaultSelection = supportedOptions.find(
o => o.major === 8
) as NodeVersion;
export function getOldestNodeVersion(): NodeVersion {
return allOptions[allOptions.length - 1];
}
export function getLatestNodeVersion(): NodeVersion {
return allOptions[0];
}
export async function getSupportedNodeVersion(
engineRange?: string,
silent?: boolean
): Promise<NodeVersion> {
let selection = defaultSelection;
let selection = getOldestNodeVersion();
if (!engineRange) {
if (!silent) {

View File

@@ -150,8 +150,10 @@ export async function getNodeVersion(
} else if (minNodeVersion) {
range = minNodeVersion;
silent = true;
} else if (config && config.nodeVersion) {
range = config.nodeVersion;
silent = true;
} else if (config && config.zeroConfig) {
// Use latest node version zero config detected
range = '10.x';
silent = true;
}

View File

@@ -21,6 +21,7 @@ import {
getNodeVersion,
getSpawnOptions,
} from './fs/run-user-scripts';
import { getLatestNodeVersion } from './fs/node-version';
import streamToBuffer from './fs/stream-to-buffer';
import shouldServe from './should-serve';
import debug from './debug';
@@ -48,6 +49,7 @@ export {
runPipInstall,
runShellScript,
getNodeVersion,
getLatestNodeVersion,
getSpawnOptions,
streamToBuffer,
shouldServe,

View File

@@ -43,6 +43,7 @@ export interface Config {
buildCommand?: string;
devCommand?: string;
framework?: string;
nodeVersion?: string;
}
export interface Meta {

View File

@@ -3,10 +3,8 @@ const fs = require('fs-extra');
const assert = require('assert');
const { createZip } = require('../dist/lambda');
const { glob, spawnAsync, download } = require('../');
const {
getSupportedNodeVersion,
defaultSelection,
} = require('../dist/fs/node-version');
const { getSupportedNodeVersion } = require('../dist/fs/node-version');
const { getNodeVersion, getLatestNodeVersion } = require('../dist');
it('should re-create symlinks properly', async () => {
const files = await glob('**', path.join(__dirname, 'symlinks'));
@@ -50,14 +48,11 @@ it('should create zip files with symlinks properly', async () => {
it('should only match supported node versions', async () => {
expect(await getSupportedNodeVersion('10.x')).toHaveProperty('major', 10);
expect(await getSupportedNodeVersion('8.10.x')).toHaveProperty('major', 8);
expect(await getSupportedNodeVersion('12.x')).toHaveProperty('major', 12);
expect(getSupportedNodeVersion('8.11.x')).rejects.toThrow();
expect(getSupportedNodeVersion('6.x')).rejects.toThrow();
expect(getSupportedNodeVersion('999.x')).rejects.toThrow();
expect(getSupportedNodeVersion('foo')).rejects.toThrow();
expect(await getSupportedNodeVersion('')).toBe(defaultSelection);
expect(await getSupportedNodeVersion(null)).toBe(defaultSelection);
expect(await getSupportedNodeVersion(undefined)).toBe(defaultSelection);
});
it('should match all semver ranges', async () => {
@@ -78,6 +73,22 @@ it('should match all semver ranges', async () => {
expect(await getSupportedNodeVersion('^10.5.0')).toHaveProperty('major', 10);
});
it('should select correct node version in getNodeVersion()', async () => {
expect(
await getNodeVersion('/tmp', undefined, { nodeVersion: '12.x' })
).toHaveProperty('major', 12);
expect(
await getNodeVersion('/tmp', undefined, { nodeVersion: '10.x' })
).toHaveProperty('major', 10);
expect(
await getNodeVersion('/tmp', '10.x', { nodeVersion: '12.x' })
).toHaveProperty('major', 10);
});
it('should get latest node version', async () => {
expect(await getLatestNodeVersion()).toHaveProperty('major', 12);
});
it('should support require by path for legacy builders', () => {
const index = require('@now/build-utils');

View File

@@ -1,6 +1,6 @@
{
"name": "@now/next",
"version": "2.3.2",
"version": "2.3.3",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/next-js",

View File

@@ -450,11 +450,7 @@ export const build = async ({
const prerenders: { [key: string]: Prerender | FileFsRef } = {};
const staticPages: { [key: string]: FileFsRef } = {};
const dynamicPages: string[] = [];
const dynamicDataRoutes: Array<{
src: string;
dest: string;
check: true;
}> = [];
const dynamicDataRoutes: Array<{ src: string; dest: string }> = [];
const appMountPrefixNoTrailingSlash = path.posix
.join('/', entryDirectory)
@@ -880,7 +876,6 @@ export const build = async ({
src: dataRouteRegex.replace(/^\^/, `^${appMountPrefixNoTrailingSlash}`),
// Location of lambda in builder output
dest: path.posix.join(entryDirectory, dataRoute),
check: true,
});
});
}
@@ -948,28 +943,6 @@ export const build = async ({
routes: [
// redirects take the highest priority
...redirects,
// Next.js page lambdas, `static/` folder, reserved assets, and `public/`
// folder
{ handle: 'filesystem' },
...rewrites,
// Custom Next.js 404 page (TODO: do we want to remove this?)
...(isLegacy
? []
: [
{
src: path.join('/', entryDirectory, '.*'),
dest: path.join('/', entryDirectory, '_error'),
status: 404,
check: true,
},
]),
// Routes that are checked after each rewrite and no filesystem match
{ handle: 'miss' },
// Dynamic routes
...dynamicRoutes,
...dynamicDataRoutes,
// Routes that are checked after filesystem match
{ handle: 'hit' },
// Before we handle static files we need to set proper caching headers
{
// This ensures we only match known emitted-by-Next.js files and not
@@ -984,6 +957,24 @@ export const build = async ({
headers: { 'cache-control': 'public,max-age=31536000,immutable' },
continue: true,
},
{ src: path.join('/', entryDirectory, '_next(?!/data(?:/|$))(?:/.*)?') },
// Next.js page lambdas, `static/` folder, reserved assets, and `public/`
// folder
{ handle: 'filesystem' },
...rewrites,
// Dynamic routes
...dynamicRoutes,
...dynamicDataRoutes,
// Custom Next.js 404 page (TODO: do we want to remove this?)
...(isLegacy
? []
: [
{
src: path.join('/', entryDirectory, '.*'),
dest: path.join('/', entryDirectory, '_error'),
status: 404,
},
]),
],
watch: [],
childProcesses: [],

View File

@@ -353,7 +353,7 @@ export async function getDynamicRoutes(
dynamicPages: string[],
isDev?: boolean,
routesManifest?: RoutesManifest
): Promise<{ src: string; dest: string; check: true }[]> {
): Promise<{ src: string; dest: string }[]> {
if (!dynamicPages.length) {
return [];
}
@@ -367,7 +367,6 @@ export async function getDynamicRoutes(
return {
src: regex,
dest: !isDev ? path.join('/', entryDirectory, page) : page,
check: true,
};
}
);
@@ -424,7 +423,7 @@ export async function getDynamicRoutes(
matcher: getRouteRegex && getRouteRegex(pageName).re,
}));
const routes: { src: string; dest: string; check: true }[] = [];
const routes: { src: string; dest: string }[] = [];
pageMatchers.forEach(pageMatcher => {
// in `now dev` we don't need to prefix the destination
const dest = !isDev
@@ -435,7 +434,6 @@ export async function getDynamicRoutes(
routes.push({
src: pageMatcher.matcher.source,
dest,
check: true,
});
}
});

View File

@@ -1,6 +1,6 @@
{
"dependencies": {
"next": "9.1.7-canary.11",
"next": "^9.1.4-canary.1",
"react": "^16.8.6",
"react-dom": "^16.8.6"
}

View File

@@ -1,6 +1,6 @@
{
"dependencies": {
"next": "9.1.7-canary.11",
"next": "^9.1.4-canary.1",
"react": "^16.8.6",
"react-dom": "^16.8.6"
}

View File

@@ -1,19 +0,0 @@
module.exports = {
generateBuildId() {
return 'testing-build-id';
},
experimental: {
async rewrites() {
return [
{
source: '/blog/post-1',
destination: '/blog/post-2',
},
{
source: '/blog/post-2',
destination: '/404',
},
];
},
},
};

View File

@@ -1,10 +0,0 @@
{
"version": 2,
"builds": [{ "src": "package.json", "use": "@now/next" }],
"probes": [
{
"path": "/blog/post-1",
"mustContain": "post-2"
}
]
}

View File

@@ -1,7 +0,0 @@
{
"dependencies": {
"next": "9.1.7-canary.11",
"react": "^16.8.6",
"react-dom": "^16.8.6"
}
}

View File

@@ -1,11 +0,0 @@
import { useRouter } from 'next/router'
const Page = () => (
<>
<p>Post: {useRouter().query.post}</p>
</>
)
Page.getInitialProps = () => ({ hello: 'world' })
export default Page

View File

@@ -117,7 +117,6 @@ describe('build meta dev', () => {
{
src: '^/(nested\\/([^\\/]+?)(?:\\/)?)$',
dest: 'http://localhost:5000/$1',
check: true,
},
{ src: '/data.txt', dest: 'http://localhost:5000/data.txt' },
]);

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node",
"version": "1.3.1-canary.0",
"version": "1.3.1-canary.1",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/node-js",

View File

@@ -1,7 +1,10 @@
{
"engines": {
"node": "10.x"
},
"dependencies": {
"chrome-aws-lambda": "1.11.1",
"lighthouse": "4.3.1",
"puppeteer-core": "1.11.0"
"chrome-aws-lambda": "1.20.4",
"lighthouse": "5.6.0",
"puppeteer-core": "1.20.0"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@now/static-build",
"version": "0.14.1-canary.6",
"version": "0.14.1-canary.7",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/static-builds",