提交 04993166 编写于 作者: T Tim Neutkens 提交者: 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
上级 c5faf73c
......@@ -6,7 +6,7 @@ import mkdirpOrig from 'mkdirp'
import nanoid from 'next/dist/compiled/nanoid/index.js'
import path from 'path'
import { promisify } from 'util'
import findUp from 'find-up'
import formatWebpackMessages from '../client/dev/error-overlay/format-webpack-messages'
import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../lib/constants'
import { findPagesDir } from '../lib/find-pages-dir'
......@@ -125,6 +125,8 @@ export default async function build(dir: string, conf = null): Promise<void> {
eventVersion({
cliCommand: 'build',
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))
......
#!/usr/bin/env node
import { resolve, join } from 'path'
import { resolve } from 'path'
import arg from 'next/dist/compiled/arg/index.js'
import { existsSync } from 'fs'
import startServer from '../server/lib/start-server'
......@@ -57,7 +57,11 @@ const nextDev: cliCommand = argv => {
startedDevelopmentServer(appUrl)
startServer({ dir, dev: true }, port, args['--hostname'])
startServer(
{ dir, dev: true, isNextDevCommand: true },
port,
args['--hostname']
)
.then(async app => {
await app.prepare()
})
......
......@@ -5,7 +5,7 @@ import mkdirpModule from 'mkdirp'
import { cpus } from 'os'
import { dirname, join, resolve, sep } from 'path'
import { promisify } from 'util'
import findUp from 'find-up'
import { AmpPageStatus, formatAmpMessages } from '../build/output/index'
import createSpinner from '../build/spinner'
import { API_ROUTE } from '../lib/constants'
......@@ -95,7 +95,14 @@ export default async function(
const distDir = join(dir, nextConfig.distDir)
if (!options.buildExport) {
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
......
......@@ -6,7 +6,7 @@ import React from 'react'
import { UrlWithParsedQuery } from 'url'
import { promisify } from 'util'
import Watchpack from 'watchpack'
import findUp from 'find-up'
import { ampValidation } from '../build/output/index'
import * as Log from '../build/output/log'
import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../lib/constants'
......@@ -41,8 +41,9 @@ export default class DevServer extends Server {
private setDevReady?: Function
private webpackWatcher?: Watchpack | null
private hotReloader?: HotReloader
private isCustomServer: boolean
constructor(options: ServerConstructor) {
constructor(options: ServerConstructor & { isNextDevCommand?: boolean }) {
super({ ...options, dev: true })
this.renderOpts.dev = true
;(this.renderOpts as any).ErrorDebug = ErrorDebug
......@@ -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`
)
}
this.isCustomServer = !options.isNextDevCommand
this.pagesDir = findPagesDir(this.dir)
}
......@@ -211,6 +213,8 @@ export default class DevServer extends Server {
eventVersion({
cliCommand: 'dev',
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 = {
nodeVersion: string
cliCommand: string
isSrcDir: boolean | null
hasNowJson: boolean
isCustomServer: boolean | null
}
export function eventVersion(
......@@ -23,6 +25,8 @@ export function eventVersion(
nodeVersion: process.version,
cliCommand: event.cliCommand,
isSrcDir: event.isSrcDir,
hasNowJson: event.hasNowJson,
isCustomServer: event.isCustomServer,
} as EventCliSessionStarted,
},
]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册