Skip to content

Commit 4b143fc

Browse files
arunodatimneutkens
authored andcommitted
Make sure dynamic imports works on Windows (vercel#3641)
* Make sure dynamic imports works on Windows * Fix an issue with the load test firmware. * Fix symlink creation on Unix
1 parent 5818e6f commit 4b143fc

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ dist
55
# dependencies
66
node_modules
77
package-lock.json
8+
test/node_modules
89

910
# logs
1011
*.log

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@
126126
"husky": "0.14.3",
127127
"jest-cli": "21.2.0",
128128
"lint-staged": "4.2.3",
129+
"mkdirp": "0.5.1",
129130
"node-fetch": "1.7.3",
130131
"node-notifier": "5.1.2",
131132
"nyc": "11.2.1",
132133
"portfinder": "1.0.13",
133134
"react": "16.2.0",
134135
"react-dom": "16.2.0",
136+
"rimraf": "2.6.2",
135137
"standard": "9.0.2",
136138
"taskr": "1.1.0",
137139
"wd": "1.4.1"

server/build/plugins/nextjs-ssr-import.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, sep } from 'path'
1+
import { join } from 'path'
22

33
// This plugin modifies the require-ensure code generated by Webpack
44
// to work with Next.js SSR
@@ -13,7 +13,10 @@ export default class NextJsSsrImportPlugin {
1313
compilation.mainTemplate.plugin('require-ensure', (code) => {
1414
// Update to load chunks from our custom chunks directory
1515
const chunksDirPath = join(this.dir, this.dist, 'dist')
16-
let updatedCode = code.replace('require("./"', `require("${chunksDirPath}${sep}"`)
16+
// Make sure even in windows, the path looks like in unix
17+
// Node.js require system will convert it accordingly
18+
const chunksDirPathNormalized = chunksDirPath.replace(/\\/g, '/')
19+
let updatedCode = code.replace('require("./"', `require("${chunksDirPathNormalized}/"`)
1720

1821
// Replace a promise equivalent which runs in the same loop
1922
// If we didn't do this webpack's module loading process block us from

taskfile.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const notifier = require('node-notifier')
22
const childProcess = require('child_process')
3+
const rimraf = require('rimraf')
4+
const mkdirp = require('mkdirp')
35
const isWindows = /^win/.test(process.platform)
46

57
export async function compile (task) {
@@ -26,12 +28,21 @@ export async function client (task, opts) {
2628
notify('Compiled client files')
2729
}
2830

31+
// Create node_modules/next for the use of test apps
32+
export async function symlinkNextForTesting () {
33+
rimraf.sync('test/node_modules/next')
34+
mkdirp.sync('test/node_modules')
35+
36+
const symlinkCommand = isWindows ? 'mklink /D "next" "..\\..\\"' : 'ln -s ../../ next'
37+
childProcess.execSync(symlinkCommand, { cwd: 'test/node_modules' })
38+
}
39+
2940
export async function copy (task) {
3041
await task.source('pages/**/*.js').target('dist/pages')
3142
}
3243

3344
export async function build (task) {
34-
await task.serial(['copy', 'compile'])
45+
await task.serial(['symlinkNextForTesting', 'copy', 'compile'])
3546
}
3647

3748
export default async function (task) {
@@ -53,8 +64,10 @@ export async function release (task) {
5364
// the lifetime of the original npm script.
5465

5566
export async function pretest (task) {
67+
// Start chromedriver
5668
const processName = isWindows ? 'chromedriver.cmd' : 'chromedriver'
5769
childProcess.spawn(processName, { stdio: 'inherit' })
70+
5871
// We need to do this, otherwise this task's process will keep waiting.
5972
setTimeout(() => process.exit(0), 2000)
6073
}

test/node_modules/next

-1
This file was deleted.

yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -4083,7 +4083,7 @@ [email protected]:
40834083
dependencies:
40844084
minimist "0.0.8"
40854085

4086-
[email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
4086+
[email protected].1, [email protected].x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkdirp@~0.5.1:
40874087
version "0.5.1"
40884088
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
40894089
dependencies:
@@ -5123,7 +5123,7 @@ right-align@^0.1.1:
51235123
dependencies:
51245124
align-text "^0.1.1"
51255125

5126-
rimraf@2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
5126+
rimraf@2, rimraf@2.6.2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.5.1, rimraf@^2.5.4, rimraf@^2.6.1:
51275127
version "2.6.2"
51285128
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
51295129
dependencies:

0 commit comments

Comments
 (0)