Commit 04993166 authored by Tim Neutkens's avatar Tim Neutkens Committed by Joe Haddad

Add check for now.json and custom server (#9346)

* Check if the user has a now.json

* Check for now.json

* Add check for custom server
parent c5faf73c
...@@ -6,7 +6,7 @@ import mkdirpOrig from 'mkdirp' ...@@ -6,7 +6,7 @@ import mkdirpOrig from 'mkdirp'
import nanoid from 'next/dist/compiled/nanoid/index.js' import nanoid from 'next/dist/compiled/nanoid/index.js'
import path from 'path' import path from 'path'
import { promisify } from 'util' import { promisify } from 'util'
import findUp from 'find-up'
import formatWebpackMessages from '../client/dev/error-overlay/format-webpack-messages' import formatWebpackMessages from '../client/dev/error-overlay/format-webpack-messages'
import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../lib/constants' import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../lib/constants'
import { findPagesDir } from '../lib/find-pages-dir' import { findPagesDir } from '../lib/find-pages-dir'
...@@ -125,6 +125,8 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -125,6 +125,8 @@ export default async function build(dir: string, conf = null): Promise<void> {
eventVersion({ eventVersion({
cliCommand: 'build', cliCommand: 'build',
isSrcDir: path.relative(dir, pagesDir!).startsWith('src'), isSrcDir: path.relative(dir, pagesDir!).startsWith('src'),
hasNowJson: !!(await findUp('now.json', { cwd: dir })),
isCustomServer: null,
}) })
), ),
eventNextPlugins(path.resolve(dir)).then(events => telemetry.record(events)) eventNextPlugins(path.resolve(dir)).then(events => telemetry.record(events))
......
#!/usr/bin/env node #!/usr/bin/env node
import { resolve, join } from 'path' import { resolve } from 'path'
import arg from 'next/dist/compiled/arg/index.js' import arg from 'next/dist/compiled/arg/index.js'
import { existsSync } from 'fs' import { existsSync } from 'fs'
import startServer from '../server/lib/start-server' import startServer from '../server/lib/start-server'
...@@ -57,7 +57,11 @@ const nextDev: cliCommand = argv => { ...@@ -57,7 +57,11 @@ const nextDev: cliCommand = argv => {
startedDevelopmentServer(appUrl) startedDevelopmentServer(appUrl)
startServer({ dir, dev: true }, port, args['--hostname']) startServer(
{ dir, dev: true, isNextDevCommand: true },
port,
args['--hostname']
)
.then(async app => { .then(async app => {
await app.prepare() await app.prepare()
}) })
......
...@@ -5,7 +5,7 @@ import mkdirpModule from 'mkdirp' ...@@ -5,7 +5,7 @@ import mkdirpModule from 'mkdirp'
import { cpus } from 'os' import { cpus } from 'os'
import { dirname, join, resolve, sep } from 'path' import { dirname, join, resolve, sep } from 'path'
import { promisify } from 'util' import { promisify } from 'util'
import findUp from 'find-up'
import { AmpPageStatus, formatAmpMessages } from '../build/output/index' import { AmpPageStatus, formatAmpMessages } from '../build/output/index'
import createSpinner from '../build/spinner' import createSpinner from '../build/spinner'
import { API_ROUTE } from '../lib/constants' import { API_ROUTE } from '../lib/constants'
...@@ -95,7 +95,14 @@ export default async function( ...@@ -95,7 +95,14 @@ export default async function(
const distDir = join(dir, nextConfig.distDir) const distDir = join(dir, nextConfig.distDir)
if (!options.buildExport) { if (!options.buildExport) {
const telemetry = new Telemetry({ distDir }) const telemetry = new Telemetry({ distDir })
telemetry.record(eventVersion({ cliCommand: 'export', isSrcDir: null })) telemetry.record(
eventVersion({
cliCommand: 'export',
isSrcDir: null,
hasNowJson: !!(await findUp('now.json', { cwd: dir })),
isCustomServer: null,
})
)
} }
const subFolders = nextConfig.exportTrailingSlash const subFolders = nextConfig.exportTrailingSlash
......
...@@ -6,7 +6,7 @@ import React from 'react' ...@@ -6,7 +6,7 @@ import React from 'react'
import { UrlWithParsedQuery } from 'url' import { UrlWithParsedQuery } from 'url'
import { promisify } from 'util' import { promisify } from 'util'
import Watchpack from 'watchpack' import Watchpack from 'watchpack'
import findUp from 'find-up'
import { ampValidation } from '../build/output/index' import { ampValidation } from '../build/output/index'
import * as Log from '../build/output/log' import * as Log from '../build/output/log'
import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../lib/constants' import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../lib/constants'
...@@ -41,8 +41,9 @@ export default class DevServer extends Server { ...@@ -41,8 +41,9 @@ export default class DevServer extends Server {
private setDevReady?: Function private setDevReady?: Function
private webpackWatcher?: Watchpack | null private webpackWatcher?: Watchpack | null
private hotReloader?: HotReloader private hotReloader?: HotReloader
private isCustomServer: boolean
constructor(options: ServerConstructor) { constructor(options: ServerConstructor & { isNextDevCommand?: boolean }) {
super({ ...options, dev: true }) super({ ...options, dev: true })
this.renderOpts.dev = true this.renderOpts.dev = true
;(this.renderOpts as any).ErrorDebug = ErrorDebug ;(this.renderOpts as any).ErrorDebug = ErrorDebug
...@@ -69,6 +70,7 @@ export default class DevServer extends Server { ...@@ -69,6 +70,7 @@ export default class DevServer extends Server {
`The static directory has been deprecated in favor of the public directory. https://err.sh/zeit/next.js/static-dir-deprecated` `The static directory has been deprecated in favor of the public directory. https://err.sh/zeit/next.js/static-dir-deprecated`
) )
} }
this.isCustomServer = !options.isNextDevCommand
this.pagesDir = findPagesDir(this.dir) this.pagesDir = findPagesDir(this.dir)
} }
...@@ -211,6 +213,8 @@ export default class DevServer extends Server { ...@@ -211,6 +213,8 @@ export default class DevServer extends Server {
eventVersion({ eventVersion({
cliCommand: 'dev', cliCommand: 'dev',
isSrcDir: relative(this.dir, this.pagesDir!).startsWith('src'), isSrcDir: relative(this.dir, this.pagesDir!).startsWith('src'),
hasNowJson: !!(await findUp('now.json', { cwd: this.dir })),
isCustomServer: this.isCustomServer,
}) })
) )
} }
......
...@@ -5,6 +5,8 @@ type EventCliSessionStarted = { ...@@ -5,6 +5,8 @@ type EventCliSessionStarted = {
nodeVersion: string nodeVersion: string
cliCommand: string cliCommand: string
isSrcDir: boolean | null isSrcDir: boolean | null
hasNowJson: boolean
isCustomServer: boolean | null
} }
export function eventVersion( export function eventVersion(
...@@ -23,6 +25,8 @@ export function eventVersion( ...@@ -23,6 +25,8 @@ export function eventVersion(
nodeVersion: process.version, nodeVersion: process.version,
cliCommand: event.cliCommand, cliCommand: event.cliCommand,
isSrcDir: event.isSrcDir, isSrcDir: event.isSrcDir,
hasNowJson: event.hasNowJson,
isCustomServer: event.isCustomServer,
} as EventCliSessionStarted, } as EventCliSessionStarted,
}, },
] ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment