From 0499316650478d4340addc2c64ebe53c5e7e146f Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Fri, 8 Nov 2019 09:03:50 -0800 Subject: [PATCH] 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 --- packages/next/build/index.ts | 4 +++- packages/next/cli/next-dev.ts | 8 ++++++-- packages/next/export/index.ts | 11 +++++++++-- packages/next/server/next-dev-server.ts | 8 ++++++-- packages/next/telemetry/events/version.ts | 4 ++++ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 45c5001488..a9034d7f29 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -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 { 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)) diff --git a/packages/next/cli/next-dev.ts b/packages/next/cli/next-dev.ts index f3a7570c3e..624ed2a329 100755 --- a/packages/next/cli/next-dev.ts +++ b/packages/next/cli/next-dev.ts @@ -1,5 +1,5 @@ #!/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() }) diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index 17d112c6ae..b486ee759d 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -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 diff --git a/packages/next/server/next-dev-server.ts b/packages/next/server/next-dev-server.ts index 5e715d19c2..c4d5100702 100644 --- a/packages/next/server/next-dev-server.ts +++ b/packages/next/server/next-dev-server.ts @@ -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, }) ) } diff --git a/packages/next/telemetry/events/version.ts b/packages/next/telemetry/events/version.ts index 843de93c04..8c23ff5166 100644 --- a/packages/next/telemetry/events/version.ts +++ b/packages/next/telemetry/events/version.ts @@ -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, }, ] -- GitLab