Skip to content

Commit 327bb22

Browse files
committed
Code improvements
1 parent 0ef2ded commit 327bb22

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

lib/virtual.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function VirtualModulesPlugin(compiler) {
5858
const segments = file.split(/[\\/]/);
5959
let count = segments.length - 1;
6060
const minCount = segments[0] ? 1 : 0;
61+
// create directories for each segment (to prevent files not being in a directory)
6162
while (count > minCount) {
6263
const dir = segments.slice(0, count).join(path.sep) || path.sep;
6364
try {
@@ -123,7 +124,7 @@ VirtualModulesPlugin.prototype.writeModule = function(filePath, contents) {
123124
const stats = new VirtualStats({
124125
dev: 8675309,
125126
ino: inode++,
126-
mode: 33188,
127+
mode: 16877,
127128
nlink: 0,
128129
uid: 1000,
129130
gid: 1000,
@@ -175,17 +176,11 @@ VirtualModulesPlugin.prototype.writeModule = function(filePath, contents) {
175176
};
176177

177178
function getData(storage, key) {
178-
// Webpack 5
179-
if (storage._data instanceof Map) {
180-
return storage._data.get(key);
181-
} else if (storage._data) {
182-
return storage.data[key];
183-
} else if (storage.data instanceof Map) {
184-
// Webpack v4
179+
const data = storage._data /* webpack 5 */ || storage.data /* webpack 4 */;
180+
if (data instanceof Map) {
185181
return storage.data.get(key);
186-
} else {
187-
return storage.data[key];
188182
}
183+
return data.data[key];
189184
}
190185

191186
function setData(backendOrStorage, key, valueFactory) {

0 commit comments

Comments
 (0)