Skip to content

Commit

Permalink
Merge branch 'canary' into webpack/upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Nov 8, 2021
2 parents 5c1e47b + cfb8cc8 commit a30852c
Show file tree
Hide file tree
Showing 80 changed files with 780 additions and 309 deletions.
4 changes: 2 additions & 2 deletions examples/cms-strapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"remark": "12.0.0",
"remark-html": "11.0.2"
"remark": "^14.0.1",
"remark-html": "^15.0.0"
},
"devDependencies": {
"autoprefixer": "10.2.6",
Expand Down
15 changes: 15 additions & 0 deletions examples/with-supertokens/config/appInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const port = process.env.APP_PORT || 3000

const apiBasePath = '/api/auth/'

export const websiteDomain =
process.env.APP_URL ||
process.env.NEXT_PUBLIC_APP_URL ||
`http://localhost:${port}`

export const appInfo = {
appName: 'SuperTokens Demo App',
websiteDomain,
apiDomain: websiteDomain,
apiBasePath,
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import ThirdPartyEmailPasswordNode from 'supertokens-node/recipe/thirdpartyemailpassword'
import SessionNode from 'supertokens-node/recipe/session'

import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword'
import SessionReact from 'supertokens-auth-react/recipe/session'

const port = process.env.APP_PORT || 3000
const websiteDomain =
process.env.APP_URL ||
process.env.NEXT_PUBLIC_APP_URL ||
`http://localhost:${port}`
const apiBasePath = '/api/auth/'

let appInfo = {
appName: 'SuperTokens Demo App',
websiteDomain,
apiDomain: websiteDomain,
apiBasePath,
}
import { appInfo } from './appInfo'

export let backendConfig = () => {
return {
Expand Down Expand Up @@ -50,23 +34,3 @@ export let backendConfig = () => {
isInServerlessEnv: true,
}
}

export let frontendConfig = () => {
return {
appInfo,
recipeList: [
ThirdPartyEmailPasswordReact.init({
emailVerificationFeature: {
mode: 'REQUIRED',
},
signInAndUpFeature: {
providers: [
ThirdPartyEmailPasswordReact.Google.init(),
ThirdPartyEmailPasswordReact.Github.init(),
],
},
}),
SessionReact.init(),
],
}
}
23 changes: 23 additions & 0 deletions examples/with-supertokens/config/frontendConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ThirdPartyEmailPasswordReact from 'supertokens-auth-react/recipe/thirdpartyemailpassword'
import SessionReact from 'supertokens-auth-react/recipe/session'
import { appInfo } from './appInfo'

export let frontendConfig = () => {
return {
appInfo,
recipeList: [
ThirdPartyEmailPasswordReact.init({
emailVerificationFeature: {
mode: 'REQUIRED',
},
signInAndUpFeature: {
providers: [
ThirdPartyEmailPasswordReact.Google.init(),
ThirdPartyEmailPasswordReact.Github.init(),
],
},
}),
SessionReact.init(),
],
}
}
11 changes: 8 additions & 3 deletions examples/with-supertokens/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ import '../styles/globals.css'
import React from 'react'
import { useEffect } from 'react'
import SuperTokensReact from 'supertokens-auth-react'
import * as SuperTokensConfig from '../config/supertokensConfig'
import * as SuperTokensConfig from '../config/frontendConfig'
import Session from 'supertokens-auth-react/recipe/session'
import SuperTokensNode from 'supertokens-node'
import { redirectToAuth } from 'supertokens-auth-react/recipe/thirdpartyemailpassword'

async function initNode() {
const supertokensNode = await import('supertokens-node')
const { backendConfig } = await import('../config/backendConfig')
supertokensNode.init(backendConfig())
}

if (typeof window !== 'undefined') {
SuperTokensReact.init(SuperTokensConfig.frontendConfig())
} else {
SuperTokensNode.init(SuperTokensConfig.backendConfig())
initNode().catch(console.error)
}

function MyApp({ Component, pageProps }) {
Expand Down
4 changes: 2 additions & 2 deletions examples/with-supertokens/pages/api/auth/[[...path]].js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { superTokensNextWrapper } from 'supertokens-node/nextjs'
import supertokens from 'supertokens-node'
import { middleware } from 'supertokens-node/framework/express'
import * as SuperTokensConfig from '../../../config/supertokensConfig'
import { backendConfig } from '../../../config/backendConfig'

supertokens.init(SuperTokensConfig.backendConfig())
supertokens.init(backendConfig())

export default async function superTokens(req, res) {
await superTokensNextWrapper(
Expand Down
4 changes: 2 additions & 2 deletions examples/with-supertokens/pages/api/user.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { superTokensNextWrapper } from 'supertokens-node/nextjs'
import { verifySession } from 'supertokens-node/recipe/session/framework/express'
import supertokens from 'supertokens-node'
import * as SuperTokensConfig from '../../config/supertokensConfig'
import { backendConfig } from '../../config/backendConfig'

supertokens.init(SuperTokensConfig.backendConfig())
supertokens.init(backendConfig())

export default async function user(req, res) {
await superTokensNextWrapper(
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.0.3-canary.10"
"version": "12.0.3"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@
"pretty-ms": "7.0.0",
"random-seed": "0.3.0",
"react": "17.0.2",
"react-18": "npm:react@18.0.0-alpha-3c4c1c470-20211021",
"react-18": "npm:react@18.0.0-alpha-13455d26d-20211104",
"react-dom": "17.0.2",
"react-dom-18": "npm:react-dom@18.0.0-alpha-3c4c1c470-20211021",
"react-dom-18": "npm:react-dom@18.0.0-alpha-13455d26d-20211104",
"react-ssr-prepass": "1.0.8",
"release": "6.3.0",
"request-promise-core": "1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "12.0.3-canary.10",
"@next/eslint-plugin-next": "12.0.3",
"@rushstack/eslint-patch": "^1.0.6",
"@typescript-eslint/parser": "^4.20.0",
"eslint-import-resolver-node": "^0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.0.3-canary.10",
"version": "12.0.3",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
20 changes: 7 additions & 13 deletions packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pages-lo
import { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
import { LoadedEnvFiles } from '@next/env'
import { NextConfigComplete } from '../server/config-shared'
import { isFlightPage } from './utils'
import { isCustomErrorPage, isFlightPage, isReservedPage } from './utils'
import { ssrEntries } from './webpack/plugins/middleware-plugin'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { MIDDLEWARE_SSR_RUNTIME_WEBPACK } from '../shared/lib/constants'
Expand Down Expand Up @@ -65,7 +65,7 @@ export function createPagesMapping(
// we alias these in development and allow webpack to
// allow falling back to the correct source file so
// that HMR can work properly when a file is added/removed
const documentPage = `_document${hasServerComponents ? '.web' : ''}`
const documentPage = `_document${hasServerComponents ? '-web' : ''}`
if (isDev) {
pages['/_app'] = `${PAGES_DIR_ALIAS}/_app`
pages['/_error'] = `${PAGES_DIR_ALIAS}/_error`
Expand Down Expand Up @@ -136,7 +136,10 @@ export function createEntrypoints(
const serverBundlePath = posix.join('pages', bundleFile)

const isLikeServerless = isTargetLikeServerless(target)
const isReserved = isReservedPage(page)
const isCustomError = isCustomErrorPage(page)
const isFlight = isFlightPage(config, absolutePagePath)

const webServerRuntime = !!config.experimental.concurrentFeatures

if (page.match(MIDDLEWARE_ROUTE)) {
Expand All @@ -151,11 +154,7 @@ export function createEntrypoints(
return
}

if (
webServerRuntime &&
!(page === '/_app' || page === '/_error' || page === '/_document') &&
!isApiRoute
) {
if (webServerRuntime && !isReserved && !isCustomError && !isApiRoute) {
ssrEntries.set(clientBundlePath, { requireFlightManifest: isFlight })
serverWeb[serverBundlePath] = finalizeEntrypoint({
name: '[name].js',
Expand Down Expand Up @@ -184,12 +183,7 @@ export function createEntrypoints(
serverlessLoaderOptions
)}!`
} else if (isApiRoute || target === 'server') {
if (
!webServerRuntime ||
page === '/_document' ||
page === '/_app' ||
page === '/_error'
) {
if (!webServerRuntime || isReserved || isCustomError) {
server[serverBundlePath] = [absolutePagePath]
}
} else if (
Expand Down
20 changes: 13 additions & 7 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ import {
printTreeView,
getCssFilePaths,
getUnresolvedModuleFromError,
isReservedPage,
isCustomErrorPage,
} from './utils'
import getBaseWebpackConfig from './webpack-config'
import { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
Expand All @@ -102,8 +104,6 @@ import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'
import { MiddlewareManifest } from './webpack/plugins/middleware-plugin'
import type { webpack5 as webpack } from 'next/dist/compiled/webpack/webpack'

const RESERVED_PAGE = /^\/(_app|_error|_document|api(\/|$))/

export type SsgRoute = {
initialRevalidateSeconds: number | false
srcRoute: string | null
Expand Down Expand Up @@ -465,7 +465,7 @@ export default async function build(
(page) =>
!isDynamicRoute(page) &&
!page.match(MIDDLEWARE_ROUTE) &&
!page.match(RESERVED_PAGE)
!isReservedPage(page)
)
.map(pageToRoute),
dataRoutes: [],
Expand Down Expand Up @@ -916,7 +916,7 @@ export default async function build(

if (
!isMiddlewareRoute &&
!page.match(RESERVED_PAGE) &&
!isReservedPage(page) &&
!hasConcurrentFeatures
) {
try {
Expand Down Expand Up @@ -1029,7 +1029,8 @@ export default async function build(
isWebSsr:
hasConcurrentFeatures &&
!isMiddlewareRoute &&
!page.match(RESERVED_PAGE),
!isReservedPage(page) &&
!isCustomErrorPage(page),
isHybridAmp,
ssgPageRoutes,
initialRevalidateSeconds: false,
Expand Down Expand Up @@ -1318,7 +1319,9 @@ export default async function build(
// Since custom _app.js can wrap the 404 page we have to opt-out of static optimization if it has getInitialProps
// Only export the static 404 when there is no /_error present
const useStatic404 =
!customAppGetInitialProps && (!hasNonStaticErrorPage || hasPages404)
!hasConcurrentFeatures &&
!customAppGetInitialProps &&
(!hasNonStaticErrorPage || hasPages404)

if (invalidPages.size > 0) {
const err = new Error(
Expand Down Expand Up @@ -1383,7 +1386,10 @@ export default async function build(

const combinedPages = [...staticPages, ...ssgPages]

if (combinedPages.length > 0 || useStatic404 || useDefaultStatic500) {
if (
!hasConcurrentFeatures &&
(combinedPages.length > 0 || useStatic404 || useDefaultStatic500)
) {
const staticGenerationSpan = nextBuildSpan.traceChild('static-generation')
await staticGenerationSpan.traceAsyncFn(async () => {
detectConflictingPaths(
Expand Down
9 changes: 9 additions & 0 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { NextConfigComplete } from '../server/config-shared'
import isError from '../lib/is-error'

const { builtinModules } = require('module')
const RESERVED_PAGE = /^\/(_app|_error|_document|api(\/|$))/
const fileGzipStats: { [k: string]: Promise<number> | undefined } = {}
const fsStatGzip = (file: string) => {
const cached = fileGzipStats[file]
Expand Down Expand Up @@ -1144,3 +1145,11 @@ export function getUnresolvedModuleFromError(
const [, moduleName] = error.match(moduleErrorRegex) || []
return builtinModules.find((item: string) => item === moduleName)
}

export function isReservedPage(page: string) {
return RESERVED_PAGE.test(page)
}

export function isCustomErrorPage(page: string) {
return page === '/404' || page === '/500'
}

0 comments on commit a30852c

Please sign in to comment.