Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved nanoid use from next-server to next/build #5441

Merged
merged 1 commit into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/next-server/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ const defaultConfig: NextConfig = {
assetPrefix: '',
configOrigin: 'default',
useFileSystemPublicRoutes: true,
generateBuildId: () => {
// nanoid is a small url-safe uuid generator
const nanoid = require('nanoid')
return nanoid()
},
generateBuildId: () => null,
generateEtags: true,
pageExtensions: ['jsx', 'js']
}
Expand Down
8 changes: 7 additions & 1 deletion packages/next/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'path'
import promisify from '../lib/promisify'
import fs from 'fs'
import webpack from 'webpack'
import nanoid from 'nanoid'
import loadConfig from 'next-server/next-config'
import { PHASE_PRODUCTION_BUILD, BUILD_ID_FILE } from 'next-server/constants'
import getBaseWebpackConfig from './webpack'
Expand All @@ -11,9 +12,14 @@ const writeFile = promisify(fs.writeFile)

export default async function build (dir, conf = null) {
const config = loadConfig(PHASE_PRODUCTION_BUILD, dir, conf)
const buildId = await config.generateBuildId() // defaults to a uuid
const distDir = join(dir, config.distDir)

let buildId = await config.generateBuildId() // defaults to a uuid
if (buildId == null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== is intentional here to catch null or undefined (either would mess up any potential string methods)

or would you prefer to make this more explicit like typeof buildId == "string"?

// nanoid is a small url-safe uuid generator
buildId = nanoid()
}

try {
await access(dir, (fs.constants || fs).W_OK)
} catch (err) {
Expand Down