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

Commit 5b37474

Browse files
misticevilebottnawi
authored andcommitted
fix: generate normalized cache context relative paths (#54)
1 parent 148b2a0 commit 5b37474

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

package-lock.json

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"loader-utils": "^1.1.0",
4242
"mkdirp": "^0.5.1",
4343
"neo-async": "^2.6.0",
44+
"normalize-path": "^3.0.0",
4445
"schema-utils": "^1.0.0"
4546
},
4647
"devDependencies": {
@@ -66,7 +67,6 @@
6667
"jest": "^23.6.0",
6768
"lint-staged": "^8.1.0",
6869
"memory-fs": "^0.4.1",
69-
"normalize-path": "^3.0.0",
7070
"pre-commit": "^1.0.0",
7171
"prettier": "^1.15.2",
7272
"standard-version": "^4.0.0",

src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
const fs = require('fs');
55
const path = require('path');
6+
const normalizePath = require('normalize-path');
67
const async = require('neo-async');
78
const crypto = require('crypto');
89
const mkdirp = require('mkdirp');
@@ -33,13 +34,13 @@ function pathWithCacheContext(cacheContext, originalPath) {
3334
if (originalPath.includes(cacheContext)) {
3435
return originalPath
3536
.split('!')
36-
.map((subPath) => path.relative(cacheContext, subPath))
37+
.map((subPath) => normalizePath(path.relative(cacheContext, subPath)))
3738
.join('!');
3839
}
3940

4041
return originalPath
4142
.split('!')
42-
.map((subPath) => path.resolve(cacheContext, subPath))
43+
.map((subPath) => normalizePath(path.resolve(cacheContext, subPath)))
4344
.join('!');
4445
}
4546

test/__snapshots__/cacheContext-option.test.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`cacheContext option should generate absolute paths to the project root 2: errors 1`] = `Array []`;
3+
exports[`cacheContext option should generate absolute paths to the project root: errors 1`] = `Array []`;
44

5-
exports[`cacheContext option should generate absolute paths to the project root 2: warnings 1`] = `Array []`;
5+
exports[`cacheContext option should generate absolute paths to the project root: warnings 1`] = `Array []`;
66

77
exports[`cacheContext option should generate relative paths to the project root: errors 1`] = `Array []`;
88

test/cacheContext-option.test.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const path = require('path');
2+
23
const normalizePath = require('normalize-path');
4+
35
const { webpack } = require('./helpers');
46

57
const mockCacheLoaderWriteFn = jest.fn();
@@ -26,9 +28,7 @@ const mockRelativeWebpackConfig = {
2628
};
2729

2830
const buildSnapshotReadyDeps = (deps) =>
29-
deps.map((dep) =>
30-
Object.assign({}, dep, { mtime: null, path: normalizePath(dep.path) })
31-
);
31+
deps.map((dep) => Object.assign({}, dep, { mtime: null, path: dep.path }));
3232

3333
const buildCacheLoaderCallsData = (calls) =>
3434
Array.from(
@@ -38,7 +38,7 @@ const buildCacheLoaderCallsData = (calls) =>
3838

3939
return builtCalls.set(rawData.remainingRequest, {
4040
...rawData,
41-
remainingRequest: normalizePath(rawData.remainingRequest),
41+
remainingRequest: rawData.remainingRequest,
4242
dependencies: buildSnapshotReadyDeps(rawData.dependencies),
4343
contextDependencies: buildSnapshotReadyDeps(
4444
rawData.contextDependencies
@@ -79,7 +79,22 @@ describe('cacheContext option', () => {
7979
expect(stats.compilation.errors).toMatchSnapshot('errors');
8080
});
8181

82-
it('should generate absolute paths to the project root 2', async () => {
82+
it('should generate normalized relative paths to the project root', async () => {
83+
const testId = './basic/index.js';
84+
await webpack(testId, mockRelativeWebpackConfig);
85+
86+
const cacheLoaderCallsData = buildCacheLoaderCallsData(
87+
mockCacheLoaderWriteFn.mock.calls
88+
).sort(sortData);
89+
90+
expect(
91+
cacheLoaderCallsData.every(
92+
(call) => call.remainingRequest === normalizePath(call.remainingRequest)
93+
)
94+
);
95+
});
96+
97+
it('should generate absolute paths to the project root', async () => {
8398
const testId = './basic/index.js';
8499
const stats = await webpack(testId, mockBaseWebpackConfig);
85100

0 commit comments

Comments
 (0)