Skip to content

Commit

Permalink
Merge branch 'canary' of github.com:vercel/next.js into azukaru-image…
Browse files Browse the repository at this point in the history
…-component

# Conflicts:
#	packages/next/client/image.tsx
  • Loading branch information
timneutkens committed Oct 17, 2020
2 parents 959c419 + b37835a commit 946ef4b
Show file tree
Hide file tree
Showing 78 changed files with 2,182 additions and 221 deletions.
15 changes: 15 additions & 0 deletions errors/install-sharp.md
@@ -0,0 +1,15 @@
# Install `sharp` to Use Built-In Image Optimization

#### Why This Error Occurred

Using Next.js' built-in Image Optimization requires that you bring your own version of `sharp`.

#### Possible Ways to Fix It

Please install the `sharp` package in your project.

```bash
npm i sharp
# or
yarn add sharp
```
2 changes: 1 addition & 1 deletion examples/with-expo-typescript/next.config.js
@@ -1,5 +1,5 @@
// @generated: @expo/next-adapter@2.1.9
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/guides/using-nextjs.md#withexpo
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/guides/using-nextjs.md

const { withExpo } = require('@expo/next-adapter')

Expand Down
2 changes: 1 addition & 1 deletion examples/with-expo/next.config.js
@@ -1,5 +1,5 @@
// @generated: @expo/next-adapter@2.1.5
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/guides/using-nextjs.md#withexpo
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/guides/using-nextjs.md

const { withExpo } = require('@expo/next-adapter')

Expand Down
50 changes: 29 additions & 21 deletions examples/with-mongodb/util/mongodb.js
@@ -1,37 +1,45 @@
import { MongoClient } from 'mongodb'

let uri = process.env.MONGODB_URI
let dbName = process.env.MONGODB_DB
const { MONGODB_URI, MONGODB_DB } = process.env

let cachedClient = null
let cachedDb = null

if (!uri) {
if (!MONGODB_URI) {
throw new Error(
'Please define the MONGODB_URI environment variable inside .env.local'
)
}

if (!dbName) {
if (!MONGODB_DB) {
throw new Error(
'Please define the MONGODB_DB environment variable inside .env.local'
)
}

/**
* Global is used here to maintain a cached connection across hot reloads
* in development. This prevents connections growing exponentiatlly
* during API Route usage.
*/
let cached = global.mongo
if (!cached) cached = global.mongo = {}

export async function connectToDatabase() {
if (cachedClient && cachedDb) {
return { client: cachedClient, db: cachedDb }
if (cached.conn) return cached.conn
if (!cached.promise) {
const conn = {}
const opts = {
useNewUrlParser: true,
useUnifiedTopology: true,
}
cached.promise = MongoClient.connect(MONGODB_URI, opts)
.then((client) => {
conn.client = client
return client.db(MONGODB_DB)
})
.then((db) => {
conn.db = db
cached.conn = conn
})
}

const client = await MongoClient.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})

const db = await client.db(dbName)

cachedClient = client
cachedDb = db

return { client, db }
await cached.promise
return cached.conn
}
6 changes: 4 additions & 2 deletions examples/with-prisma/README.md
@@ -1,5 +1,7 @@
Prisma.io maintains it's own Next.Js examples

- [Javascript](https://github.com/prisma/prisma-examples/tree/master/javascript/rest-nextjs)
- [Typescript](https://github.com/prisma/prisma-examples/tree/master/typescript/rest-nextjs)
- [Typescript-GraphQL](https://github.com/prisma/prisma-examples/tree/master/typescript/graphql-nextjs)
- [Typescript: rest-api-routes-auth](https://github.com/prisma/prisma-examples/tree/latest/typescript/rest-nextjs-api-routes-auth)
- [Typescript: rest-api-routes](https://github.com/prisma/prisma-examples/tree/latest/typescript/rest-nextjs-api-routes)
- [Typescript: rest-api-express](https://github.com/prisma/prisma-examples/tree/latest/typescript/rest-nextjs-express)
- [Typescript: graphql](https://github.com/prisma/prisma-examples/tree/latest/typescript/graphql-nextjs)
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -17,5 +17,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.5.6-canary.0"
"version": "9.5.6-canary.4"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-google-analytics"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-sentry"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "9.5.6-canary.0",
"version": "9.5.6-canary.4",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
59 changes: 52 additions & 7 deletions packages/next/build/index.ts
Expand Up @@ -29,6 +29,7 @@ import {
CLIENT_STATIC_FILES_PATH,
EXPORT_DETAIL,
EXPORT_MARKER,
IMAGES_MANIFEST,
PAGES_MANIFEST,
PHASE_PRODUCTION_BUILD,
PRERENDER_MANIFEST,
Expand Down Expand Up @@ -96,6 +97,7 @@ export type PrerenderManifest = {
version: 2
routes: { [route: string]: SsgRoute }
dynamicRoutes: { [route: string]: DynamicSsgRoute }
notFoundRoutes: string[]
preview: __ApiPreviewProps
}

Expand Down Expand Up @@ -306,6 +308,15 @@ export default async function build(
dataRouteRegex: string
namedDataRouteRegex?: string
}>
i18n?: {
locales: string[]
defaultLocale: string[]
domains: Array<{
domain: string
defaultLocale: string
locales: string[]
}>
}
} = {
version: 3,
pages404: true,
Expand All @@ -325,6 +336,7 @@ export default async function build(
}
}),
dataRoutes: [],
i18n: config.experimental.i18n || undefined,
}

await promises.mkdir(distDir, { recursive: true })
Expand Down Expand Up @@ -703,6 +715,7 @@ export default async function build(

const finalPrerenderRoutes: { [route: string]: SsgRoute } = {}
const tbdPrerenderRoutes: string[] = []
let ssgNotFoundPaths: string[] = []

if (postCompileSpinner) postCompileSpinner.stopAndPersist()

Expand All @@ -720,6 +733,7 @@ export default async function build(
const exportConfig: any = {
...config,
initialPageRevalidationMap: {},
ssgNotFoundPaths: [] as string[],
// Default map will be the collection of automatic statically exported
// pages and incremental pages.
// n.b. we cannot handle this above in combinedPages because the dynamic
Expand Down Expand Up @@ -785,7 +799,7 @@ export default async function build(
const outputPath = `/${locale}${page === '/' ? '' : page}`

defaultMap[outputPath] = {
page: defaultMap[page].page,
page: defaultMap[page]?.page || page,
query: { __nextLocale: locale },
}

Expand All @@ -811,6 +825,7 @@ export default async function build(
const postBuildSpinner = createSpinner({
prefixText: `${Log.prefixes.info} Finalizing page optimization`,
})
ssgNotFoundPaths = exportConfig.ssgNotFoundPaths

// remove server bundles that were exported
for (const page of staticPages) {
Expand Down Expand Up @@ -864,11 +879,12 @@ export default async function build(
}

const { i18n } = config.experimental
const isNotFound = ssgNotFoundPaths.includes(page)

// for SSG files with i18n the non-prerendered variants are
// output with the locale prefixed so don't attempt moving
// without the prefix
if (!i18n || additionalSsgFile) {
if ((!i18n || additionalSsgFile) && !isNotFound) {
await promises.mkdir(path.dirname(dest), { recursive: true })
await promises.rename(orig, dest)
} else if (i18n && !isSsg) {
Expand All @@ -881,9 +897,14 @@ export default async function build(
if (additionalSsgFile) return

for (const locale of i18n.locales) {
const curPath = `/${locale}${page === '/' ? '' : page}`
const localeExt = page === '/' ? path.extname(file) : ''
const relativeDestNoPages = relativeDest.substr('pages/'.length)

if (isSsg && ssgNotFoundPaths.includes(curPath)) {
continue
}

const updatedRelativeDest = path.join(
'pages',
locale + localeExt,
Expand All @@ -903,9 +924,7 @@ export default async function build(
)

if (!isSsg) {
pagesManifest[
`/${locale}${page === '/' ? '' : page}`
] = updatedRelativeDest
pagesManifest[curPath] = updatedRelativeDest
}
await promises.mkdir(path.dirname(updatedDest), { recursive: true })
await promises.rename(updatedOrig, updatedDest)
Expand Down Expand Up @@ -941,21 +960,27 @@ export default async function build(
}

if (isSsg) {
const { i18n } = config.experimental

// For a non-dynamic SSG page, we must copy its data file from export.
if (!isDynamic) {
await moveExportedPage(page, page, file, true, 'json')

const revalidationMapPath = i18n
? `/${i18n.defaultLocale}${page}`
: page

finalPrerenderRoutes[page] = {
initialRevalidateSeconds:
exportConfig.initialPageRevalidationMap[page],
exportConfig.initialPageRevalidationMap[revalidationMapPath],
srcRoute: null,
dataRoute: path.posix.join('/_next/data', buildId, `${file}.json`),
}
// Set Page Revalidation Interval
const pageInfo = pageInfos.get(page)
if (pageInfo) {
pageInfo.initialRevalidateSeconds =
exportConfig.initialPageRevalidationMap[page]
exportConfig.initialPageRevalidationMap[revalidationMapPath]
pageInfos.set(page, pageInfo)
}
} else {
Expand Down Expand Up @@ -1056,6 +1081,7 @@ export default async function build(
version: 2,
routes: finalPrerenderRoutes,
dynamicRoutes: finalDynamicRoutes,
notFoundRoutes: ssgNotFoundPaths,
preview: previewProps,
}

Expand All @@ -1075,6 +1101,7 @@ export default async function build(
routes: {},
dynamicRoutes: {},
preview: previewProps,
notFoundRoutes: [],
}
await promises.writeFile(
path.join(distDir, PRERENDER_MANIFEST),
Expand All @@ -1083,6 +1110,15 @@ export default async function build(
)
}

await promises.writeFile(
path.join(distDir, IMAGES_MANIFEST),
JSON.stringify({
version: 1,
images: config.images,
}),
'utf8'
)

await promises.writeFile(
path.join(distDir, EXPORT_MARKER),
JSON.stringify({
Expand Down Expand Up @@ -1123,6 +1159,15 @@ export default async function build(
printCustomRoutes({ redirects, rewrites, headers })
}

if (config.experimental.analyticsId) {
console.log(
chalk.bold.green('Next.js Analytics') +
' is enabled for this production build. ' +
"You'll receive a Real Experience Score computed by all of your visitors."
)
console.log('')
}

if (tracer) {
const parsedResults = await tracer.profiler.stopProfiling()
await new Promise((resolve) => {
Expand Down

0 comments on commit 946ef4b

Please sign in to comment.