From 098f3fd7e9b2be7e0a1026c3c9ee52696a8f842d Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Thu, 31 May 2018 20:56:04 +0200 Subject: [PATCH] Rename `dist` to `server` to be more consistent (#4506) Previously we called this directory holding the pages/chunks for server rendering `.next/dist` instead of `.next/server` which is confusing both when looking at it and in the codebase, since there's also `distDir` as a configuration option. Also made this a constant in `next/constants` so functionality using this can be easily found. --- lib/constants.js | 1 + server/build/webpack.js | 19 ++----------------- server/export.js | 4 ++-- server/render.js | 6 +++--- server/require.js | 4 ++-- .../{dist => server}/bundles/pages/_error.js | 2 +- .../{dist => server}/bundles/pages/index.js | 2 +- .../bundles/pages/non-existent-child.js | 0 .../{dist => server}/bundles/pages/world.js | 2 +- .../{dist => server}/pages-manifest.json | 0 test/isolated/require-page.test.js | 3 ++- 11 files changed, 15 insertions(+), 28 deletions(-) rename test/isolated/_resolvedata/{dist => server}/bundles/pages/_error.js (94%) rename test/isolated/_resolvedata/{dist => server}/bundles/pages/index.js (94%) rename test/isolated/_resolvedata/{dist => server}/bundles/pages/non-existent-child.js (100%) rename test/isolated/_resolvedata/{dist => server}/bundles/pages/world.js (94%) rename test/isolated/_resolvedata/{dist => server}/pages-manifest.json (100%) diff --git a/lib/constants.js b/lib/constants.js index 19cb7992..cbf93723 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -4,3 +4,4 @@ export const PHASE_PRODUCTION_SERVER = 'phase-production-server' export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server' export const PAGES_MANIFEST = 'pages-manifest.json' export const BUILD_MANIFEST = 'build-manifest.json' +export const SERVER_DIRECTORY = 'server' diff --git a/server/build/webpack.js b/server/build/webpack.js index e85e0dff..accb5d9c 100644 --- a/server/build/webpack.js +++ b/server/build/webpack.js @@ -12,18 +12,11 @@ import DynamicChunksPlugin from './plugins/dynamic-chunks-plugin' import UnlinkFilePlugin from './plugins/unlink-file-plugin' import PagesManifestPlugin from './plugins/pages-manifest-plugin' import BuildManifestPlugin from './plugins/build-manifest-plugin' +import {SERVER_DIRECTORY} from '../../lib/constants' const nextDir = path.join(__dirname, '..', '..', '..') const nextNodeModulesDir = path.join(nextDir, 'node_modules') const nextPagesDir = path.join(nextDir, 'pages') -const defaultPages = [ - '_error.js', - '_document.js', - '_app.js' -] -const interpolateNames = new Map(defaultPages.map((p) => { - return [path.join(nextPagesDir, p), `dist/bundles/pages/${p}`] -})) function externalsConfig (dir, isServer) { const externals = [] @@ -98,7 +91,7 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer } }, output: { - path: path.join(dir, config.distDir, isServer ? 'dist' : ''), // server compilation goes to `.next/dist` + path: path.join(dir, config.distDir, isServer ? SERVER_DIRECTORY : ''), filename: '[name]', libraryTarget: 'commonjs2', // This saves chunks with the name given via require.ensure() @@ -163,14 +156,6 @@ export default async function getBaseWebpackConfig (dir, {dev = false, isServer dev && !isServer && new webpack.HotModuleReplacementPlugin(), // Hot module replacement dev && new UnlinkFilePlugin(), dev && new CaseSensitivePathPlugin(), // Since on macOS the filesystem is case-insensitive this will make sure your path are case-sensitive - dev && new webpack.LoaderOptionsPlugin({ - options: { - context: dir, - customInterpolateName (url, name, opts) { - return interpolateNames.get(this.resourcePath) || url - } - } - }), dev && new WriteFilePlugin({ exitOnErrors: false, log: false, diff --git a/server/export.js b/server/export.js index b3fb1261..8334a6e7 100644 --- a/server/export.js +++ b/server/export.js @@ -5,7 +5,7 @@ import walk from 'walk' import { extname, resolve, join, dirname, sep } from 'path' import { existsSync, readFileSync, writeFileSync } from 'fs' import getConfig from './config' -import {PHASE_EXPORT, PAGES_MANIFEST} from '../lib/constants' +import {PHASE_EXPORT, SERVER_DIRECTORY, PAGES_MANIFEST} from '../lib/constants' import { renderToHTML } from './render' import { getAvailableChunks } from './utils' import { setAssetPrefix } from '../lib/asset' @@ -23,7 +23,7 @@ export default async function (dir, options, configuration) { } const buildId = readFileSync(join(nextDir, 'BUILD_ID'), 'utf8') - const pagesManifest = require(join(nextDir, 'dist', PAGES_MANIFEST)) + const pagesManifest = require(join(nextDir, SERVER_DIRECTORY, PAGES_MANIFEST)) const pages = Object.keys(pagesManifest) const defaultPathMap = {} diff --git a/server/render.js b/server/render.js index 4dd5a836..3b0ef23d 100644 --- a/server/render.js +++ b/server/render.js @@ -11,7 +11,7 @@ import { getAvailableChunks } from './utils' import Head, { defaultHead } from '../lib/head' import ErrorDebug from '../lib/error-debug' import { flushChunks } from '../lib/dynamic' -import { BUILD_MANIFEST } from '../lib/constants' +import { BUILD_MANIFEST, SERVER_DIRECTORY } from '../lib/constants' import { applySourcemaps } from './lib/source-map-support' const logger = console @@ -56,8 +56,8 @@ async function doRender (req, res, pathname, query, { await ensurePage(page, { dir, hotReloader }) } - const documentPath = join(dir, dist, 'dist', 'bundles', 'pages', '_document') - const appPath = join(dir, dist, 'dist', 'bundles', 'pages', '_app') + const documentPath = join(dir, dist, SERVER_DIRECTORY, 'bundles', 'pages', '_document') + const appPath = join(dir, dist, SERVER_DIRECTORY, 'bundles', 'pages', '_app') const buildManifest = require(join(dir, dist, BUILD_MANIFEST)) let [Component, Document, App] = await Promise.all([ requirePage(page, {dir, dist}), diff --git a/server/require.js b/server/require.js index dda23bc2..816fe2be 100644 --- a/server/require.js +++ b/server/require.js @@ -1,5 +1,5 @@ import {join, posix} from 'path' -import {PAGES_MANIFEST} from '../lib/constants' +import {PAGES_MANIFEST, SERVER_DIRECTORY} from '../lib/constants' export function pageNotFoundError (page) { const err = new Error(`Cannot find module for page: ${page}`) @@ -28,7 +28,7 @@ export function normalizePagePath (page) { } export function getPagePath (page, {dir, dist}) { - const serverBuildPath = join(dir, dist, 'dist') + const serverBuildPath = join(dir, dist, SERVER_DIRECTORY) const pagesManifest = require(join(serverBuildPath, PAGES_MANIFEST)) try { diff --git a/test/isolated/_resolvedata/dist/bundles/pages/_error.js b/test/isolated/_resolvedata/server/bundles/pages/_error.js similarity index 94% rename from test/isolated/_resolvedata/dist/bundles/pages/_error.js rename to test/isolated/_resolvedata/server/bundles/pages/_error.js index 0af8646c..3d2eea3b 100644 --- a/test/isolated/_resolvedata/dist/bundles/pages/_error.js +++ b/test/isolated/_resolvedata/server/bundles/pages/_error.js @@ -1,3 +1,3 @@ module.exports = { test: 'error' -} \ No newline at end of file +} diff --git a/test/isolated/_resolvedata/dist/bundles/pages/index.js b/test/isolated/_resolvedata/server/bundles/pages/index.js similarity index 94% rename from test/isolated/_resolvedata/dist/bundles/pages/index.js rename to test/isolated/_resolvedata/server/bundles/pages/index.js index 30de59be..3dc6289b 100644 --- a/test/isolated/_resolvedata/dist/bundles/pages/index.js +++ b/test/isolated/_resolvedata/server/bundles/pages/index.js @@ -1,3 +1,3 @@ module.exports = { test: 'hello' -} \ No newline at end of file +} diff --git a/test/isolated/_resolvedata/dist/bundles/pages/non-existent-child.js b/test/isolated/_resolvedata/server/bundles/pages/non-existent-child.js similarity index 100% rename from test/isolated/_resolvedata/dist/bundles/pages/non-existent-child.js rename to test/isolated/_resolvedata/server/bundles/pages/non-existent-child.js diff --git a/test/isolated/_resolvedata/dist/bundles/pages/world.js b/test/isolated/_resolvedata/server/bundles/pages/world.js similarity index 94% rename from test/isolated/_resolvedata/dist/bundles/pages/world.js rename to test/isolated/_resolvedata/server/bundles/pages/world.js index 24ca31a3..8e914ecb 100644 --- a/test/isolated/_resolvedata/dist/bundles/pages/world.js +++ b/test/isolated/_resolvedata/server/bundles/pages/world.js @@ -1,3 +1,3 @@ module.exports = { test: 'world' -} \ No newline at end of file +} diff --git a/test/isolated/_resolvedata/dist/pages-manifest.json b/test/isolated/_resolvedata/server/pages-manifest.json similarity index 100% rename from test/isolated/_resolvedata/dist/pages-manifest.json rename to test/isolated/_resolvedata/server/pages-manifest.json diff --git a/test/isolated/require-page.test.js b/test/isolated/require-page.test.js index bdd368de..de7c63ab 100644 --- a/test/isolated/require-page.test.js +++ b/test/isolated/require-page.test.js @@ -1,10 +1,11 @@ /* global describe, it, expect */ import { join } from 'path' +import {SERVER_DIRECTORY} from 'next/constants' import requirePage, {getPagePath, normalizePagePath, pageNotFoundError} from '../../dist/server/require' const sep = '/' -const pathToBundles = join(__dirname, '_resolvedata', 'dist', 'bundles', 'pages') +const pathToBundles = join(__dirname, '_resolvedata', SERVER_DIRECTORY, 'bundles', 'pages') describe('pageNotFoundError', () => { it('Should throw error with ENOENT code', () => {