Skip to content

Commit ec774a3

Browse files
committed
refactor paths
1 parent 2e2db37 commit ec774a3

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

bin/next

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
import { resolve } from 'path'
3+
import { join } from 'path'
44
import { spawn } from 'cross-spawn'
55

66
const defaultCommand = 'dev'
@@ -21,7 +21,7 @@ if (commands.has(cmd)) {
2121
args = process.argv.slice(2)
2222
}
2323

24-
const bin = resolve(__dirname, 'next-' + cmd)
24+
const bin = join(__dirname, 'next-' + cmd)
2525

2626
const proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] })
2727
proc.on('close', (code) => process.exit(code))

server/build/webpack.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ export default async function createCompiler (dir, { hotReload = false } = {}) {
1414
entry[join('bundles', p)] = defaultEntries.concat(['./' + p])
1515
}
1616

17-
const nextPagesDir = resolve(__dirname, '..', '..', 'pages')
17+
const nextPagesDir = join(__dirname, '..', '..', 'pages')
1818

1919
const errorEntry = join('bundles', 'pages', '_error.js')
20-
const defaultErrorPath = resolve(nextPagesDir, '_error.js')
20+
const defaultErrorPath = join(nextPagesDir, '_error.js')
2121
if (!entry[errorEntry]) entry[errorEntry] = defaultErrorPath
2222

2323
const errorDebugEntry = join('bundles', 'pages', '_error-debug.js')
24-
const errorDebugPath = resolve(nextPagesDir, '_error-debug.js')
24+
const errorDebugPath = join(nextPagesDir, '_error-debug.js')
2525
entry[errorDebugEntry] = errorDebugPath
2626

27-
const nodeModulesDir = resolve(__dirname, '..', '..', '..', 'node_modules')
27+
const nodeModulesDir = join(__dirname, '..', '..', '..', 'node_modules')
2828

2929
const plugins = [
3030
hotReload
@@ -54,7 +54,7 @@ export default async function createCompiler (dir, { hotReload = false } = {}) {
5454
.concat(hotReload ? [{
5555
test: /\.js$/,
5656
loader: 'hot-self-accept-loader',
57-
include: resolve(dir, 'pages')
57+
include: join(dir, 'pages')
5858
}] : [])
5959
.concat([{
6060
test: /\.js$/,
@@ -91,7 +91,7 @@ export default async function createCompiler (dir, { hotReload = false } = {}) {
9191
context: dir,
9292
entry,
9393
output: {
94-
path: resolve(dir, '.next'),
94+
path: join(dir, '.next'),
9595
filename: '[name]',
9696
libraryTarget: 'commonjs2',
9797
publicPath: hotReload ? 'http://localhost:3030/' : null
@@ -109,13 +109,13 @@ export default async function createCompiler (dir, { hotReload = false } = {}) {
109109
resolve: {
110110
root: [
111111
nodeModulesDir,
112-
resolve(dir, 'node_modules')
112+
join(dir, 'node_modules')
113113
]
114114
},
115115
resolveLoader: {
116116
root: [
117117
nodeModulesDir,
118-
resolve(__dirname, 'loaders')
118+
join(__dirname, 'loaders')
119119
]
120120
},
121121
plugins,

server/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ export default class Server {
4141

4242
defineRoutes () {
4343
this.router.get('/_next/:path+', async (req, res, params) => {
44-
const p = resolve(__dirname, '../client', (params.path || []).join('/'))
44+
const p = join(__dirname, '..', 'client', ...(params.path || []))
4545
await this.serveStatic(req, res, p)
4646
})
4747

4848
this.router.get('/static/:path+', async (req, res, params) => {
49-
const p = resolve(this.dir, 'static', (params.path || []).join('/'))
49+
const p = join(this.dir, 'static', ...(params.path || []))
5050
await this.serveStatic(req, res, p)
5151
})
5252

server/render.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resolve } from 'path'
1+
import { join } from 'path'
22
import { parse } from 'url'
33
import { createElement } from 'react'
44
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
@@ -16,11 +16,11 @@ export async function render (url, ctx = {}, {
1616
staticMarkup = false
1717
} = {}) {
1818
const path = getPath(url)
19-
const mod = await requireModule(resolve(dir, '.next', 'dist', 'pages', path))
19+
const mod = await requireModule(join(dir, '.next', 'dist', 'pages', path))
2020
const Component = mod.default || mod
2121

2222
const props = await (Component.getInitialProps ? Component.getInitialProps(ctx) : {})
23-
const component = await read(resolve(dir, '.next', 'bundles', 'pages', path))
23+
const component = await read(join(dir, '.next', 'bundles', 'pages', path))
2424

2525
const { html, css } = StyleSheetServer.renderStatic(() => {
2626
const app = createElement(App, {
@@ -54,7 +54,7 @@ export async function render (url, ctx = {}, {
5454

5555
export async function renderJSON (url, { dir = process.cwd() } = {}) {
5656
const path = getPath(url)
57-
const component = await read(resolve(dir, '.next', 'bundles', 'pages', path))
57+
const component = await read(join(dir, '.next', 'bundles', 'pages', path))
5858
return { component }
5959
}
6060

@@ -72,5 +72,5 @@ export function errorToJSON (err) {
7272
}
7373

7474
function getPath (url) {
75-
return parse(url || '/').pathname.slice(1).replace(/\.json$/, '')
75+
return parse(url || '/').pathname.replace(/\.json$/, '')
7676
}

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import test from 'ava'
2-
import { resolve } from 'path'
2+
import { join } from 'path'
33
import build from '../server/build'
44
import { render as _render } from '../server/render'
55

6-
const dir = resolve(__dirname, 'fixtures', 'basic')
6+
const dir = join(__dirname, 'fixtures', 'basic')
77

88
test.before(() => build(dir))
99

0 commit comments

Comments
 (0)