Skip to content

Commit

Permalink
Merge branch 'canary' into turbopack-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Dec 19, 2022
2 parents fd2138b + e45bbbe commit b7f741b
Show file tree
Hide file tree
Showing 53 changed files with 2,839 additions and 3,327 deletions.
13 changes: 11 additions & 2 deletions .eslintrc.json
@@ -1,7 +1,7 @@
{
"root": true,
"parser": "@babel/eslint-parser",
"plugins": ["react", "react-hooks", "jest", "import"],
"plugins": ["react", "react-hooks", "jest", "import", "jsdoc"],
"env": {
"browser": true,
"commonjs": true,
Expand Down Expand Up @@ -96,7 +96,16 @@
"@typescript-eslint/no-useless-constructor": "warn",
"@typescript-eslint/prefer-literal-enum-member": "error",
"@typescript-eslint/prefer-namespace-keyword": "error"
}
},
"overrides": [
{
"files": ["packages/**"],
"rules": {
"jsdoc/no-types": "error",
"jsdoc/no-undefined-types": "error"
}
}
]
},
{
"files": [
Expand Down
9 changes: 5 additions & 4 deletions docs/deployment.md
Expand Up @@ -107,20 +107,21 @@ The following services support Next.js `v12+`. Below, you’ll find examples or
### Static Only

The following services support deploying Next.js using [`next export`](/docs/advanced-features/static-html-export.md).
The following services only support deploying Next.js using [`next export`](/docs/advanced-features/static-html-export.md).

- [Cloudflare Pages](https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/)
- [Firebase](https://github.com/vercel/next.js/tree/canary/examples/with-firebase-hosting)
- [GitHub Pages](https://github.com/vercel/next.js/tree/canary/examples/github-pages)

You can also manually deploy the [`next export`](/docs/advanced-features/static-html-export.md) output to any static hosting provider, often through your CI/CD pipeline like GitHub Actions, Jenkins, AWS CodeBuild, Circle CI, Azure Pipelines, and more.

### Serverless

- [AWS Amplify](https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplify-support.html)
- [AWS Serverless](https://github.com/serverless-nextjs/serverless-next.js)
- [Azure Static Web Apps](https://learn.microsoft.com/en-us/azure/static-web-apps/nextjs)
- [Terraform](https://github.com/milliHQ/terraform-aws-next-js)
- [Cloudflare Pages](https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/)
- [Firebase](https://firebase.google.com/docs/hosting/nextjs)
- [Netlify](https://docs.netlify.com/integrations/frameworks/next-js)
- [Terraform](https://github.com/milliHQ/terraform-aws-next-js)

> **Note:** Not all serverless providers implement the [Next.js Build API](/docs/deployment.md#nextjs-build-api) from `next start`. Please check with the provider to see what features are supported.
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -137,6 +137,7 @@
"eslint-plugin-jest": "24.3.5",
"eslint-plugin-react": "7.23.2",
"eslint-plugin-react-hooks": "4.5.0",
"eslint-plugin-jsdoc": "39.6.4",
"event-stream": "4.0.1",
"execa": "2.0.3",
"expect-type": "0.14.2",
Expand Down
21 changes: 7 additions & 14 deletions packages/next/build/webpack/config/blocks/css/index.ts
Expand Up @@ -28,10 +28,6 @@ const regexSassModules = /\.module\.(scss|sass)$/

/**
* Mark a rule as removable if built-in CSS support is disabled
*
* @param {webpack.RuleSetRule} r the rule to mark
*
* @returns {webpack.RuleSetRule} the marked rule
*/
function markRemovable(r: webpack.RuleSetRule): webpack.RuleSetRule {
Object.defineProperty(r, Symbol.for('__next_css_remove'), {
Expand Down Expand Up @@ -83,15 +79,11 @@ export async function lazyPostCSS(
/**
* Returns the vendor prefix extracted from an input string.
*
* @param {string} prop String with or without vendor prefix.
*
* @return {string} vendor prefix or empty string
*
* @example
* postcss.vendor.prefix('-moz-tab-size') //=> '-moz-'
* postcss.vendor.prefix('tab-size') //=> ''
*/
prefix: function prefix(prop: any) {
prefix: function prefix(prop: string): string {
const match = prop.match(/^(-\w+-)/)

if (match) {
Expand All @@ -104,14 +96,15 @@ export async function lazyPostCSS(
/**
* Returns the input string stripped of its vendor prefix.
*
* @param {string} prop String with or without vendor prefix.
*
* @return {string} String name without vendor prefixes.
*
* @example
* postcss.vendor.unprefixed('-moz-tab-size') //=> 'tab-size'
*/
unprefixed: function unprefixed(prop: any) {
unprefixed: function unprefixed(
/**
* String with or without vendor prefix.
*/
prop: string
): string {
return prop.replace(/^-\w+-/, '')
},
}
Expand Down
73 changes: 45 additions & 28 deletions packages/next/cli/next-dev.ts
Expand Up @@ -8,40 +8,64 @@ import { startedDevelopmentServer } from '../build/output'
import { cliCommand } from '../lib/commands'
import isError from '../lib/is-error'
import { getProjectDir } from '../lib/get-project-dir'
import { CONFIG_FILES } from '../shared/lib/constants'
import { CONFIG_FILES, PHASE_DEVELOPMENT_SERVER } from '../shared/lib/constants'
import path from 'path'
import type { NextConfig } from '../types'
import type { NextConfigComplete } from '../server/config-shared'
import { traceGlobals } from '../trace/shared'
import cluster from 'cluster'
import { Telemetry } from '../telemetry/storage'
import loadConfig from '../server/config'
import { findPagesDir } from '../lib/find-pages-dir'

let isTurboSession = false
let sessionStopHandled = false
let sessionStarted = Date.now()
let dir: string

const handleSessionStop = async () => {
if (sessionStopHandled) return
sessionStopHandled = true

const { eventCliSession } =
require('../telemetry/events/session-stopped') as typeof import('../telemetry/events/session-stopped')
const telemetry = traceGlobals.get('telemetry') as InstanceType<
typeof import('../telemetry/storage').Telemetry
>
if (!telemetry) {
process.exit(0)
}
try {
const { eventCliSession } =
require('../telemetry/events/session-stopped') as typeof import('../telemetry/events/session-stopped')

telemetry.record(
eventCliSession({
cliCommand: 'dev',
turboFlag: isTurboSession,
durationMilliseconds: Date.now() - sessionStarted,
pagesDir: !!traceGlobals.get('pagesDir'),
appDir: !!traceGlobals.get('appDir'),
})
)
await telemetry.flush()
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, dir)

let telemetry =
(traceGlobals.get('telemetry') as InstanceType<
typeof import('../telemetry/storage').Telemetry
>) ||
new Telemetry({
distDir: path.join(dir, config.distDir),
})

let appDir: boolean = !!traceGlobals.get('pagesDir')
let pagesDir: boolean = !!traceGlobals.get('appDir')

if (
typeof traceGlobals.get('pagesDir') === 'undefined' ||
typeof traceGlobals.get('appDir') === 'undefined'
) {
const pagesResult = await findPagesDir(dir, !!config.experimental.appDir)
appDir = !!pagesResult.appDir
pagesDir = !!pagesResult.pagesDir
}

telemetry.record(
eventCliSession({
cliCommand: 'dev',
turboFlag: isTurboSession,
durationMilliseconds: Date.now() - sessionStarted,
pagesDir,
appDir,
})
)
await telemetry.flush()
} catch (err) {
console.error(err)
}
process.exit(0)
}

Expand Down Expand Up @@ -95,7 +119,7 @@ const nextDev: cliCommand = async (argv) => {
process.exit(0)
}

const dir = getProjectDir(args._[0])
dir = getProjectDir(args._[0])

// Check if pages dir exists and warn if not
if (!existsSync(dir)) {
Expand Down Expand Up @@ -147,10 +171,6 @@ const nextDev: cliCommand = async (argv) => {
require('../build/webpack-config') as typeof import('../build/webpack-config')
const { defaultConfig } =
require('../server/config-shared') as typeof import('../server/config-shared')
const { default: loadConfig } =
require('../server/config') as typeof import('../server/config')
const { PHASE_DEVELOPMENT_SERVER } =
require('../shared/lib/constants') as typeof import('../shared/lib/constants')
const chalk =
require('next/dist/compiled/chalk') as typeof import('next/dist/compiled/chalk')
const { interopDefault } =
Expand Down Expand Up @@ -353,11 +373,8 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
require('../build/swc') as typeof import('../build/swc')
const { eventCliSession } =
require('../telemetry/events/version') as typeof import('../telemetry/events/version')
const { findPagesDir } =
require('../lib/find-pages-dir') as typeof import('../lib/find-pages-dir')
const { setGlobal } = require('../trace') as typeof import('../trace')
const { Telemetry } =
require('../telemetry/storage') as typeof import('../telemetry/storage')
require('../telemetry/storage') as typeof import('../telemetry/storage')
const findUp =
require('next/dist/compiled/find-up') as typeof import('next/dist/compiled/find-up')

Expand Down
8 changes: 4 additions & 4 deletions packages/next/client/page-loader.ts
Expand Up @@ -145,10 +145,10 @@ export default class PageLoader {
)
}

/**
* @param {string} route - the route (file-system path)
*/
_isSsg(route: string): Promise<boolean> {
_isSsg(
/** the route (file-system path) */
route: string
): Promise<boolean> {
return this.promisedSsgManifest.then((manifest) => manifest.has(route))
}

Expand Down
17 changes: 11 additions & 6 deletions packages/next/lib/eslint/writeOutputFile.ts
Expand Up @@ -5,10 +5,12 @@ import isError from '../../lib/is-error'

/**
* Check if a given file path is a directory or not.
* @param {string} filePath The path to a file to check.
* @returns {Promise<boolean>} `true` if the path is a directory.
* Returns `true` if the path is a directory.
*/
async function isDirectory(filePath: string): Promise<boolean> {
async function isDirectory(
/** The path to a file to check. */
filePath: string
): Promise<boolean> {
try {
return (await fs.stat(filePath)).isDirectory()
} catch (error) {
Expand All @@ -23,10 +25,13 @@ async function isDirectory(filePath: string): Promise<boolean> {
}
/**
* Create a file with eslint output data
* @param {string} outputFile The name file that needs to be created
* @param {string} outputData The data that needs to be inserted into the file
*/
export async function writeOutputFile(outputFile: string, outputData: string) {
export async function writeOutputFile(
/** The name file that needs to be created */
outputFile: string,
/** The data that needs to be inserted into the file */
outputData: string
): Promise<void> {
const filePath = path.resolve(process.cwd(), outputFile)

if (await isDirectory(filePath)) {
Expand Down
7 changes: 3 additions & 4 deletions packages/next/lib/recursive-delete.ts
Expand Up @@ -35,14 +35,13 @@ const unlinkPath = async (p: string, isDir = false, t = 1): Promise<void> => {

/**
* Recursively delete directory contents
* @param {string} dir Directory to delete the contents of
* @param {RegExp} [exclude] Exclude based on relative file path
* @param {string} [previousPath] Ensures that parameter dir exists, this is not passed recursively
* @returns Promise void
*/
export async function recursiveDelete(
/** Directory to delete the contents of */
dir: string,
/** Exclude based on relative file path */
exclude?: RegExp,
/** Ensures that parameter dir exists, this is not passed recursively */
previousPath: string = ''
): Promise<void> {
let result
Expand Down
11 changes: 6 additions & 5 deletions packages/next/lib/recursive-readdir.ts
Expand Up @@ -3,17 +3,18 @@ import { join } from 'path'

/**
* Recursively read directory
* @param {string} dir Directory to read
* @param {RegExp} filter Filter for the file name, only the name part is considered, not the full path
* @param {string[]=[]} arr This doesn't have to be provided, it's used for the recursion
* @param {string=dir`} rootDir Used to replace the initial path, only the relative path is left, it's faster than path.relative.
* @returns Promise array holding all relative paths
* Returns array holding all relative paths
*/
export async function recursiveReadDir(
/** Directory to read */
dir: string,
/** Filter for the file name, only the name part is considered, not the full path */
filter: RegExp,
/** Filter for the file name, only the name part is considered, not the full path */
ignore?: RegExp,
/** This doesn't have to be provided, it's used for the recursion */
arr: string[] = [],
/** Used to replace the initial path, only the relative path is left, it's faster than path.relative. */
rootDir: string = dir
): Promise<string[]> {
const result = await promises.readdir(dir, { withFileTypes: true })
Expand Down
1 change: 1 addition & 0 deletions packages/next/lib/server-external-packages.ts
Expand Up @@ -9,6 +9,7 @@ export const EXTERNAL_PACKAGES = [
'express',
'firebase-admin',
'jest',
'lodash',
'mongodb',
'next-mdx-remote',
'next-seo',
Expand Down
10 changes: 6 additions & 4 deletions packages/next/server/dev/next-dev-server.ts
Expand Up @@ -732,6 +732,12 @@ export default class DevServer extends Server {
}

const telemetry = new Telemetry({ distDir: this.distDir })

// This is required by the tracing subsystem.
setGlobal('appDir', this.appDir)
setGlobal('pagesDir', this.pagesDir)
setGlobal('telemetry', telemetry)

const isSrcDir = relative(
this.dir,
this.pagesDir || this.appDir || ''
Expand All @@ -748,10 +754,6 @@ export default class DevServer extends Server {
appDir: !!this.appDir,
})
)
// This is required by the tracing subsystem.
setGlobal('appDir', this.appDir)
setGlobal('pagesDir', this.pagesDir)
setGlobal('telemetry', telemetry)

process.on('unhandledRejection', (reason) => {
this.logErrorWithOriginalStack(reason, 'unhandledRejection').catch(
Expand Down
7 changes: 4 additions & 3 deletions packages/next/server/lib/recursive-readdir-sync.ts
Expand Up @@ -3,13 +3,14 @@ import { join } from 'path'

/**
* Recursively read directory
* @param {string[]=[]} arr This doesn't have to be provided, it's used for the recursion
* @param {string=dir`} rootDir Used to replace the initial path, only the relative path is left, it's faster than path.relative.
* @returns Array holding all relative paths
* Returns array holding all relative paths
*/
export function recursiveReadDirSync(
/** The directory to read */
dir: string,
/** This doesn't have to be provided, it's used for the recursion */
arr: string[] = [],
/** Used to replace the initial path, only the relative path is left, it's faster than path.relative. */
rootDir = dir
): string[] {
const result = fs.readdirSync(dir)
Expand Down

0 comments on commit b7f741b

Please sign in to comment.