Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

Commit 4bc6732

Browse files
misticevilebottnawi
authored andcommitted
fix: watch on windows (#74)
1 parent 1369c05 commit 4bc6732

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

Diff for: package-lock.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"loader-utils": "^1.1.0",
4444
"mkdirp": "^0.5.1",
4545
"neo-async": "^2.6.0",
46-
"normalize-path": "^3.0.0",
4746
"schema-utils": "^1.0.0"
4847
},
4948
"devDependencies": {
@@ -70,6 +69,7 @@
7069
"jest": "^24.5.0",
7170
"lint-staged": "^8.1.0",
7271
"memory-fs": "^0.4.1",
72+
"normalize-path": "^3.0.0",
7373
"pre-commit": "^1.0.0",
7474
"prettier": "^1.15.2",
7575
"standard-version": "^4.0.0",

Diff for: src/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const fs = require('fs');
55
const os = require('os');
66
const path = require('path');
7-
const normalizePath = require('normalize-path');
87
const async = require('neo-async');
98
const crypto = require('crypto');
109
const mkdirp = require('mkdirp');
@@ -38,13 +37,13 @@ function pathWithCacheContext(cacheContext, originalPath) {
3837
if (originalPath.includes(cacheContext)) {
3938
return originalPath
4039
.split('!')
41-
.map((subPath) => normalizePath(path.relative(cacheContext, subPath)))
40+
.map((subPath) => path.relative(cacheContext, subPath))
4241
.join('!');
4342
}
4443

4544
return originalPath
4645
.split('!')
47-
.map((subPath) => normalizePath(path.resolve(cacheContext, subPath)))
46+
.map((subPath) => path.resolve(cacheContext, subPath))
4847
.join('!');
4948
}
5049

Diff for: test/cacheContext-option.test.js

+38-14
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,32 @@ const sortData = (a, b) => {
4040
return 0;
4141
};
4242

43-
const buildSnapshotReadyDeps = (deps) =>
44-
deps.map((dep) => Object.assign({}, dep, { mtime: null, path: dep.path }));
45-
46-
const buildCacheLoaderCallsData = (calls) =>
43+
const buildSnapshotReadyDeps = (deps, normalizePaths = true) =>
44+
deps.map((dep) =>
45+
Object.assign({}, dep, {
46+
mtime: null,
47+
path: normalizePaths ? normalizePath(dep.path) : dep.path,
48+
})
49+
);
50+
51+
const buildCacheLoaderCallsData = (calls, normalizePaths = true) =>
4752
Array.from(
4853
calls
4954
.reduce((builtCalls, call) => {
5055
const [, rawData] = call;
5156

5257
return builtCalls.set(rawData.remainingRequest, {
5358
...rawData,
54-
remainingRequest: rawData.remainingRequest,
55-
dependencies: buildSnapshotReadyDeps(rawData.dependencies),
59+
remainingRequest: normalizePaths
60+
? normalizePath(rawData.remainingRequest)
61+
: rawData.remainingRequest,
62+
dependencies: buildSnapshotReadyDeps(
63+
rawData.dependencies,
64+
normalizePaths
65+
),
5666
contextDependencies: buildSnapshotReadyDeps(
57-
rawData.contextDependencies
67+
rawData.contextDependencies,
68+
normalizePaths
5869
),
5970
});
6071
}, new Map())
@@ -82,19 +93,32 @@ describe('cacheContext option', () => {
8293
expect(stats.compilation.errors).toMatchSnapshot('errors');
8394
});
8495

85-
it('should generate normalized relative paths to the project root', async () => {
96+
it('should generate non normalized relative paths to the project root on windows', async () => {
8697
const testId = './basic/index.js';
8798
await webpack(testId, mockRelativeWebpackConfig);
8899

89100
const cacheLoaderCallsData = buildCacheLoaderCallsData(
90-
mockCacheLoaderWriteFn.mock.calls
101+
mockCacheLoaderWriteFn.mock.calls,
102+
false
91103
);
92104

93-
expect(
94-
cacheLoaderCallsData.every(
95-
(call) => call.remainingRequest === normalizePath(call.remainingRequest)
96-
)
97-
).toBeTruthy();
105+
// NOTE: this test prevents to generate normalized paths for the generated cache assets
106+
// under windows which will break the watcher due to a bug on watchpack/chokidar
107+
if (process.platform === 'win32') {
108+
expect(
109+
cacheLoaderCallsData.every(
110+
(call) =>
111+
call.remainingRequest !== normalizePath(call.remainingRequest)
112+
)
113+
).toBeTruthy();
114+
} else {
115+
expect(
116+
cacheLoaderCallsData.every(
117+
(call) =>
118+
call.remainingRequest === normalizePath(call.remainingRequest)
119+
)
120+
).toBeTruthy();
121+
}
98122
});
99123

100124
it('should generate absolute paths to the project root', async () => {

0 commit comments

Comments
 (0)