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

Generate normalized cache context relative paths #54

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
"loader-utils": "^1.1.0",
"mkdirp": "^0.5.1",
"neo-async": "^2.6.0",
"normalize-path": "^3.0.0",
"schema-utils": "^1.0.0"
},
"devDependencies": {
@@ -66,7 +67,6 @@
"jest": "^23.6.0",
"lint-staged": "^8.1.0",
"memory-fs": "^0.4.1",
"normalize-path": "^3.0.0",
"pre-commit": "^1.0.0",
"prettier": "^1.15.2",
"standard-version": "^4.0.0",
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
*/
const fs = require('fs');
const path = require('path');
const normalizePath = require('normalize-path');
const async = require('neo-async');
const crypto = require('crypto');
const mkdirp = require('mkdirp');
@@ -33,13 +34,13 @@ function pathWithCacheContext(cacheContext, originalPath) {
if (originalPath.includes(cacheContext)) {
return originalPath
.split('!')
.map((subPath) => path.relative(cacheContext, subPath))
.map((subPath) => normalizePath(path.relative(cacheContext, subPath)))
.join('!');
}

return originalPath
.split('!')
.map((subPath) => path.resolve(cacheContext, subPath))
.map((subPath) => normalizePath(path.resolve(cacheContext, subPath)))
.join('!');
}

4 changes: 2 additions & 2 deletions test/__snapshots__/cacheContext-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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

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

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

25 changes: 20 additions & 5 deletions test/cacheContext-option.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const path = require('path');

const normalizePath = require('normalize-path');

const { webpack } = require('./helpers');

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

const buildSnapshotReadyDeps = (deps) =>
deps.map((dep) =>
Object.assign({}, dep, { mtime: null, path: normalizePath(dep.path) })
);
deps.map((dep) => Object.assign({}, dep, { mtime: null, path: dep.path }));

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

return builtCalls.set(rawData.remainingRequest, {
...rawData,
remainingRequest: normalizePath(rawData.remainingRequest),
remainingRequest: rawData.remainingRequest,
dependencies: buildSnapshotReadyDeps(rawData.dependencies),
contextDependencies: buildSnapshotReadyDeps(
rawData.contextDependencies
@@ -79,7 +79,22 @@ describe('cacheContext option', () => {
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it('should generate absolute paths to the project root 2', async () => {
it('should generate normalized relative paths to the project root', async () => {
const testId = './basic/index.js';
await webpack(testId, mockRelativeWebpackConfig);

const cacheLoaderCallsData = buildCacheLoaderCallsData(
mockCacheLoaderWriteFn.mock.calls
).sort(sortData);

expect(
cacheLoaderCallsData.every(
(call) => call.remainingRequest === normalizePath(call.remainingRequest)
)
);
});

it('should generate absolute paths to the project root', async () => {
const testId = './basic/index.js';
const stats = await webpack(testId, mockBaseWebpackConfig);