Skip to content

Commit 8d2bbf9

Browse files
alexnewmannnrauchg
authored andcommitted
Refactor the build server to remove tie to fs (vercel#1656)
1 parent 6e0e230 commit 8d2bbf9

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

server/build/index.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { tmpdir } from 'os'
22
import { join } from 'path'
3-
import getConfig from '../config'
43
import fs from 'mz/fs'
54
import uuid from 'uuid'
65
import del from 'del'
@@ -14,10 +13,8 @@ export default async function build (dir) {
1413

1514
try {
1615
await runCompiler(compiler)
17-
18-
// Pass in both the buildDir and the dir to retrieve config
19-
await writeBuildStats(buildDir, dir)
20-
await writeBuildId(buildDir, dir)
16+
await writeBuildStats(buildDir)
17+
await writeBuildId(buildDir)
2118
} catch (err) {
2219
console.error(`> Failed to build on ${buildDir}`)
2320
throw err
@@ -48,24 +45,22 @@ function runCompiler (compiler) {
4845
})
4946
}
5047

51-
async function writeBuildStats (buildDir, dir) {
52-
const dist = getConfig(dir).distDir
48+
async function writeBuildStats (dir) {
5349
// Here we can't use hashes in webpack chunks.
5450
// That's because the "app.js" is not tied to a chunk.
5551
// It's created by merging a few assets. (commons.js and main.js)
5652
// So, we need to generate the hash ourself.
5753
const assetHashMap = {
5854
'app.js': {
59-
hash: await md5File(join(buildDir, dist, 'app.js'))
55+
hash: await md5File(join(dir, '.next', 'app.js'))
6056
}
6157
}
62-
const buildStatsPath = join(buildDir, dist, 'build-stats.json')
58+
const buildStatsPath = join(dir, '.next', 'build-stats.json')
6359
await fs.writeFile(buildStatsPath, JSON.stringify(assetHashMap), 'utf8')
6460
}
6561

66-
async function writeBuildId (buildDir, dir) {
67-
const dist = getConfig(dir).distDir
68-
const buildIdPath = join(buildDir, dist, 'BUILD_ID')
62+
async function writeBuildId (dir) {
63+
const buildIdPath = join(dir, '.next', 'BUILD_ID')
6964
const buildId = uuid.v4()
7065
await fs.writeFile(buildIdPath, buildId, 'utf8')
7166
}

server/build/replace.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import getConfig from '../config'
44

55
export default async function replaceCurrentBuild (dir, buildDir) {
66
const dist = getConfig(dir).distDir
7-
const buildDist = getConfig(buildDir).distDir
87
const _dir = join(dir, dist)
9-
const _buildDir = join(buildDir, dist)
10-
const oldDir = join(buildDir, `${buildDist}.old`)
8+
const _buildDir = join(buildDir, '.next')
9+
const oldDir = join(buildDir, '.next.old')
1110

1211
try {
1312
await move(_dir, oldDir)

server/build/webpack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export default async function createCompiler (dir, { dev = false, quiet = false,
265265
context: dir,
266266
entry,
267267
output: {
268-
path: join(buildDir || dir, config.distDir),
268+
path: buildDir ? join(buildDir, '.next') : join(dir, config.distDir),
269269
filename: '[name]',
270270
libraryTarget: 'commonjs2',
271271
publicPath: '/_webpack/',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy