Skip to content

Commit

Permalink
Merge branch 'canary' into increase-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 authored Oct 5, 2020
2 parents dd4a2c6 + 100a1d3 commit 55e0c38
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 61 deletions.
9 changes: 9 additions & 0 deletions .github/actions/next-stats-action/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path')
const fs = require('fs-extra')
const exec = require('./util/exec')
const logger = require('./util/logger')
const runConfigs = require('./run')
Expand Down Expand Up @@ -25,6 +27,13 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {

;(async () => {
try {
if (await fs.pathExists(path.join(__dirname, '../SKIP_NEXT_STATS.txt'))) {
console.log(
'SKIP_NEXT_STATS.txt file present, exiting stats generation..'
)
process.exit(0)
}

const { stdout: gitName } = await exec(
'git config user.name && git config user.email'
)
Expand Down
4 changes: 3 additions & 1 deletion .github/actions/next-stats-action/src/prepare/action-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ module.exports = function actionInfo() {
isLocal: LOCAL_STATS,
commitId: null,
issueId: ISSUE_ID,
isRelease: releaseTypes.has(GITHUB_ACTION),
isRelease:
GITHUB_REPOSITORY === 'vercel/next.js' &&
(GITHUB_REF || '').includes('canary'),
}

// get comment
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,14 @@ jobs:
key: ${{ github.sha }}

- run: ./publish-release.sh

prStats:
name: Release Stats
runs-on: ubuntu-latest
needs: [publishRelease]
steps:
- uses: actions/checkout@v2
- run: ./release-stats.sh
- uses: ./.github/actions/next-stats-action
env:
PR_STATS_COMMENT_TOKEN: ${{ secrets.PR_STATS_COMMENT_TOKEN }}
13 changes: 0 additions & 13 deletions .github/workflows/release_stats.yml

This file was deleted.

2 changes: 2 additions & 0 deletions docs/api-reference/next.config.js/exportPathMap.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ description: Customize the pages that will be exported as HTML files when using
</ul>
</details>

`exportPathMap` allows you to specify a mapping of request paths to page destinations, to be used during export.

Let's start with an example, to create a custom `exportPathMap` for an app with the following pages:

- `pages/index.js`
Expand Down
2 changes: 2 additions & 0 deletions docs/api-reference/next.config.js/rewrites.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Rewrites allow you to map an incoming request path to a different destination pa

Rewrites are only available on the Node.js environment and do not affect client-side routing.

Rewrites are not able to override public files or routes in the pages directory as these have higher priority than rewrites. For example, if you have `pages/index.js` you are not able to rewrite `/` to another location unless you rename the `pages/index.js` file.

To use rewrites you can use the `rewrites` key in `next.config.js`:

```js
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/built-in-css-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ In production, all CSS files will be automatically concatenated into a single mi

### Import styles from `node_modules`

Importing a CSS file from `node_modules` is permitted in anywhere your application.
Since Next.js **9.5.4**, importing a CSS file from `node_modules` is permitted anywhere in your application.

For global stylesheets, like `bootstrap` or `nprogress`, you should import the file inside `pages/_app.js`.
For example:
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/static-file-serving.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function MyImage() {
export default MyImage
```

This folder is also useful for `robots.txt`, Google Site Verification, and any other static files (including `.html`)!
This folder is also useful for `robots.txt`, `favicon.ico`, Google Site Verification, and any other static files (including `.html`)!

> **Note**: Don't name the `public` directory anything else. The name cannot be changed and is the only directory used to serve static assets.
Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You're now ready to start converting files from `.js` to `.tsx` and leveraging t

> A file named `next-env.d.ts` will be created in the root of your project. This file ensures Next.js types are picked up by the TypeScript compiler. **You cannot remove it**, however, you can edit it (but you don't need to).
> Next.js `strict` mode is turned off by default. When you feel comfortable with TypeScript, it's recommended to turn it on in your `tsconfig.json`.
> TypeScript `strict` mode is turned off by default. When you feel comfortable with TypeScript, it's recommended to turn it on in your `tsconfig.json`.
By default, Next.js will do type checking as part of `next build`. We recommend using code editor type checking during development.

Expand Down
19 changes: 19 additions & 0 deletions errors/export-no-custom-routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# `next export` No Custom Routes

#### Why This Error Occurred

In your `next.config.js` `rewrites`, `redirects`, or `headers` were defined while `next export` was being run outside of a platform that supports them.

These configs do not apply when exporting your Next.js application manually.

#### Possible Ways to Fix It

Disable the `rewrites`, `redirects`, and `headers` from your `next.config.js` when using `next export` to deploy your application or deploy your application using [a method](https://nextjs.org/docs/deployment#vercel-recommended) that supports these configs.

### Useful Links

- [Deployment Documentation](https://nextjs.org/docs/deployment#vercel-recommended)
- [`next export` Documentation](https://nextjs.org/docs/advanced-features/static-html-export)
- [Rewrites Documentation](https://nextjs.org/docs/api-reference/next.config.js/rewrites)
- [Redirects Documentation](https://nextjs.org/docs/api-reference/next.config.js/redirects)
- [Headers Documentation](https://nextjs.org/docs/api-reference/next.config.js/headers)
2 changes: 1 addition & 1 deletion examples/amp-first/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Things you need to do after installing the boilerplate:
```

- **amp-list & amp-mustache:** mustache templates conflict with JSX and it's template literals need to be escaped. A simple approach is to escape them via back ticks: `` src={`{{imageUrl}}`} ``.
- **amp-script:** you can use [amp-script](https://amp.dev/documentation/components/amp-script/) to add custom JavaScript to your AMP pages. The boilerplate includes a helper [`components/amp/AmpScript.js`](components/amp/AmpScript.js) to simplify using amp-script. The helper also supports embedding inline scripts. Good to know: Next.js uses [AMP Optimizer](https://github.com/ampproject/amp-toolbox/tree/master/packages/optimizer) under the hood, which automatically adds the needed script hashes for [inline amp-scripts](https://amp.dev/documentation/components/amp-script/#load-javascript-from-a-local-element).
- **amp-script:** you can use [amp-script](https://amp.dev/documentation/components/amp-script/) to add custom JavaScript to your AMP pages. The boilerplate includes a helper [`components/amp/AmpScript.js`](components/amp/AmpScript.js) to simplify using `amp-script`. The helper also supports embedding inline scripts. Good to know: Next.js uses [AMP Optimizer](https://github.com/ampproject/amp-toolbox/tree/master/packages/optimizer) under the hood, which automatically adds the needed script hashes for [inline amp-scripts](https://amp.dev/documentation/components/amp-script/#load-javascript-from-a-local-element).

## Deployment

Expand Down
2 changes: 1 addition & 1 deletion examples/api-routes-rest/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API routes with REST

Next.js ships with [API routes](https://github.com/vercel/next.js#api-routes), which provide an easy solution to build your own `API`. This example shows how it can be used to create your [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) api.
Next.js ships with [API routes](https://github.com/vercel/next.js#api-routes), which provide an easy solution to build your own `API`. This example shows how it can be used to create your [REST](https://en.wikipedia.org/wiki/Representational_state_transfer) `API`.

## Deploy your own

Expand Down
6 changes: 3 additions & 3 deletions examples/blog-starter-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

This is the existing [blog-starter](https://github.com/vercel/next.js/tree/canary/examples/blog-starter) plus TypeScript.

This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using markdown files as the data source.
This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using Markdown files as the data source.

The blog posts are stored in `/_posts` as markdown files with front matter support. Adding a new markdown file in there will create a new blog post.
The blog posts are stored in `/_posts` as Markdown files with front matter support. Adding a new Markdown file in there will create a new blog post.

To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page.
To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the Markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page.

## How to use

Expand Down
6 changes: 3 additions & 3 deletions examples/blog-starter/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# A statically generated blog example using Next.js and Markdown

This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using markdown files as the data source.
This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using Markdown files as the data source.

The blog posts are stored in `/_posts` as markdown files with front matter support. Adding a new markdown file in there will create a new blog post.
The blog posts are stored in `/_posts` as Markdown files with front matter support. Adding a new Markdown file in there will create a new blog post.

To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page.
To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) and [`remark-html`](https://github.com/remarkjs/remark-html) to convert the Markdown files into an HTML string, and then send it down as a prop to the page. The metadata of every post is handled by [`gray-matter`](https://github.com/jonschlinkert/gray-matter) and also sent in props to the page.

## Demo

Expand Down
4 changes: 3 additions & 1 deletion examples/with-mux-video/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ This example uses Mux Video, an API-first platform for video. The example featur

## Demo

### [https://with-mux-video.now.sh/](https://with-mux-video.now.sh/)
### [https://with-mux-video.vercel.app/](https://with-mux-video.vercel.app/)

### This project was used to create [stream.new](https://stream.new/)

## Deploy your own

Expand Down
4 changes: 2 additions & 2 deletions examples/with-mux-video/components/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { MUX_HOME_PAGE_URL } from '../constants'
export default function Layout({
title,
description,
metaTitle,
metaTitle = 'Mux + Next.js',
metaDescription,
image,
image = 'https://with-mux-video.vercel.app/mux-nextjs-og-image.png',
children,
loadTwitterWidget,
}) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions examples/with-storybook/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["next/babel"],
"plugins": []
}
1 change: 0 additions & 1 deletion examples/with-storybook/components/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
export default function Home() {
return <div>Hello World</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ const nextServerlessLoader: loader.Loader = function () {
(!value || (
Array.isArray(value) &&
value.length === 1 &&
value[0] === 'index'
${
''
// fallback optional catch-all SSG pages have
// [[...paramName]] for the root path on Vercel
}
(value[0] === 'index' || value[0] === \`[[...\${key}]]\`)
))
) {
value = undefined
Expand Down
16 changes: 16 additions & 0 deletions packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ export default async function exportApp(
)
}

const customRoutesDetected = ['rewrites', 'redirects', 'headers'].filter(
(config) => typeof nextConfig[config] === 'function'
)

if (
!process.env.NOW_BUILDER &&
!options.buildExport &&
customRoutesDetected.length > 0
) {
Log.warn(
`rewrites, redirects, and headers are not applied when exporting your application, detected (${customRoutesDetected.join(
', '
)}). See more info here: https://err.sh/next.js/export-no-custom-routes`
)
}

const buildId = readFileSync(join(distDir, BUILD_ID_FILE), 'utf8')
const pagesManifest =
!options.pages &&
Expand Down
28 changes: 0 additions & 28 deletions packages/next/next-server/server/api-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,34 +162,6 @@ function parseJson(str: string): object {
}
}

/**
* Parsing query arguments from request `url` string
* @param url of request
* @returns Object with key name of query argument and its value
*/
export function getQueryParser({ url }: IncomingMessage) {
return function parseQuery(): NextApiRequestQuery {
const { URL } = require('url')
// we provide a placeholder base url because we only want searchParams
const params = new URL(url, 'https://n').searchParams

const query: { [key: string]: string | string[] } = {}
for (const [key, value] of params) {
if (query[key]) {
if (Array.isArray(query[key])) {
;(query[key] as string[]).push(value)
} else {
query[key] = [query[key], value]
}
} else {
query[key] = value
}
}

return query
}
}

/**
* Parse cookies from `req` header
* @param req request object
Expand Down
18 changes: 18 additions & 0 deletions release-stats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

git describe --exact-match

if [[ ! $? -eq 0 ]];then
echo "Nothing to publish, exiting.."
touch .github/actions/next-stats-action/SKIP_NEXT_STATS.txt
exit 0;
fi

if [[ -z "$NPM_TOKEN" ]];then
echo "No NPM_TOKEN, exiting.."
exit 0;
fi

echo "Publish occurred, running release stats..."
echo "Waiting 30 seconds to allow publish to finalize"
sleep 30
74 changes: 71 additions & 3 deletions test/integration/custom-routes/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
waitFor,
normalizeRegEx,
initNextServerScript,
nextExport,
} from 'next-test-utils'

jest.setTimeout(1000 * 60 * 2)
Expand All @@ -31,6 +32,7 @@ let nextConfigContent
let externalServerPort
let externalServer
let stdout = ''
let stderr = ''
let buildId
let appPort
let app
Expand Down Expand Up @@ -1119,16 +1121,82 @@ describe('Custom routes', () => {

describe('server mode', () => {
beforeAll(async () => {
const { stdout: buildStdout } = await nextBuild(appDir, ['-d'], {
stdout: true,
})
const { stdout: buildStdout, stderr: buildStderr } = await nextBuild(
appDir,
['-d'],
{
stdout: true,
stderr: true,
}
)
stdout = buildStdout
stderr = buildStderr
appPort = await findPort()
app = await nextStart(appDir, appPort)
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
})
afterAll(() => killApp(app))
runTests()

it('should not show warning for custom routes when not next export', async () => {
expect(stderr).not.toContain(
`rewrites, redirects, and headers are not applied when exporting your application detected`
)
})
})

describe('export', () => {
let exportStderr = ''
let exportVercelStderr = ''

beforeAll(async () => {
const { stdout: buildStdout, stderr: buildStderr } = await nextBuild(
appDir,
['-d'],
{
stdout: true,
stderr: true,
}
)
const exportResult = await nextExport(
appDir,
{ outdir: join(appDir, 'out') },
{ stderr: true }
)
const exportVercelResult = await nextExport(
appDir,
{ outdir: join(appDir, 'out') },
{
stderr: true,
env: {
NOW_BUILDER: '1',
},
}
)

stdout = buildStdout
stderr = buildStderr
exportStderr = exportResult.stderr
exportVercelStderr = exportVercelResult.stderr
})

it('should not show warning for custom routes when not next export', async () => {
expect(stderr).not.toContain(
`rewrites, redirects, and headers are not applied when exporting your application detected`
)
})

it('should not show warning for custom routes when next export on Vercel', async () => {
expect(exportVercelStderr).not.toContain(
`rewrites, redirects, and headers are not applied when exporting your application detected`
)
})

it('should show warning for custom routes with next export', async () => {
expect(exportStderr).toContain(
`rewrites, redirects, and headers are not applied when exporting your application, detected (rewrites, redirects, headers)`
)
})
})

describe('serverless mode', () => {
Expand Down

0 comments on commit 55e0c38

Please sign in to comment.