Skip to content

Commit

Permalink
Merge pull request #13006 from webpack/logging/improve-resolve-build-…
Browse files Browse the repository at this point in the history
…dependencies

improve logging for resolving build dependencies
  • Loading branch information
sokra committed Mar 29, 2021
2 parents 15110ea + cb94f3c commit 4b67afc
Showing 1 changed file with 74 additions and 14 deletions.
88 changes: 74 additions & 14 deletions lib/FileSystemInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,15 +1107,58 @@ class FileSystemInfo {
contextDependencies: resolveDirectories,
missingDependencies: resolveMissing
};
const expectedToString = expected => {
return expected ? ` (expected ${expected})` : "";
};
const jobToString = job => {
switch (job.type) {
case RBDT_RESOLVE_CJS:
return `resolve commonjs ${job.path}${expectedToString(
job.expected
)}`;
case RBDT_RESOLVE_ESM:
return `resolve esm ${job.path}${expectedToString(job.expected)}`;
case RBDT_RESOLVE_DIRECTORY:
return `resolve directory ${job.path}`;
case RBDT_RESOLVE_CJS_FILE:
return `resolve commonjs file ${job.path}${expectedToString(
job.expected
)}`;
case RBDT_RESOLVE_ESM_FILE:
return `resolve esm file ${job.path}${expectedToString(
job.expected
)}`;
case RBDT_DIRECTORY:
return `directory ${job.path}`;
case RBDT_FILE:
return `file ${job.path}`;
case RBDT_DIRECTORY_DEPENDENCIES:
return `directory dependencies ${job.path}`;
case RBDT_FILE_DEPENDENCIES:
return `file dependencies ${job.path}`;
}
return `unknown ${job.type} ${job.path}`;
};
const pathToString = job => {
let result = ` at ${jobToString(job)}`;
job = job.issuer;
while (job !== undefined) {
result += `\n at ${jobToString(job)}`;
job = job.issuer;
}
return result;
};
processAsyncTree(
Array.from(deps, dep => ({
type: RBDT_RESOLVE_CJS,
context,
path: dep,
expected: undefined
expected: undefined,
issuer: undefined
})),
20,
({ type, context, path, expected }, push, callback) => {
(job, push, callback) => {
const { type, context, path, expected } = job;
const resolveDirectory = path => {
const key = `d\n${context}\n${path}`;
if (resolveResults.has(key)) {
Expand All @@ -1139,7 +1182,8 @@ class FileSystemInfo {
type: RBDT_DIRECTORY,
context: undefined,
path: result,
expected: undefined
expected: undefined,
issuer: job
});
callback();
});
Expand All @@ -1157,7 +1201,9 @@ class FileSystemInfo {
} else {
invalidResolveResults.add(key);
this.logger.debug(
`Resolving '${path}' in ${context} for build dependencies doesn't lead to expected result '${expected}', but to '${result}' instead. Resolving dependencies are ignored for this path.`
`Resolving '${path}' in ${context} for build dependencies doesn't lead to expected result '${expected}', but to '${result}' instead. Resolving dependencies are ignored for this path.\n${pathToString(
job
)}`
);
}
} else {
Expand All @@ -1169,15 +1215,18 @@ class FileSystemInfo {
) {
return callback();
}
err.message += `\nwhile resolving '${path}' in ${context} as file`;
err.message += `\nwhile resolving '${path}' in ${context} as file\n${pathToString(
job
)}`;
return callback(err);
}
resolveResults.set(key, result);
push({
type: RBDT_FILE,
context: undefined,
path: result,
expected: undefined
expected: undefined,
issuer: job
});
}
callback();
Expand Down Expand Up @@ -1233,7 +1282,8 @@ class FileSystemInfo {
type: RBDT_FILE_DEPENDENCIES,
context: undefined,
path: realPath,
expected: undefined
expected: undefined,
issuer: job
});
callback();
});
Expand All @@ -1258,7 +1308,8 @@ class FileSystemInfo {
type: RBDT_DIRECTORY_DEPENDENCIES,
context: undefined,
path: realPath,
expected: undefined
expected: undefined,
issuer: job
});
callback();
});
Expand All @@ -1281,7 +1332,8 @@ class FileSystemInfo {
type: RBDT_FILE,
context: undefined,
path: childPath,
expected: undefined
expected: undefined,
issuer: job
});
const context = dirname(this.fs, path);
for (const modulePath of module.paths) {
Expand All @@ -1293,7 +1345,8 @@ class FileSystemInfo {
type: RBDT_RESOLVE_CJS_FILE,
context,
path: request,
expected: child.filename
expected: child.filename,
issuer: job
});
continue children;
}
Expand All @@ -1306,7 +1359,8 @@ class FileSystemInfo {
type: RBDT_RESOLVE_CJS_FILE,
context,
path: request,
expected: child.filename
expected: child.filename,
issuer: job
});
}
}
Expand Down Expand Up @@ -1351,7 +1405,8 @@ class FileSystemInfo {
type: RBDT_RESOLVE_ESM_FILE,
context,
path: dependency,
expected: undefined
expected: undefined,
issuer: job
});
} catch (e) {
this.logger.warn(
Expand All @@ -1361,13 +1416,15 @@ class FileSystemInfo {
)})'.\n` +
"Build dependencies behind this expression are ignored and might cause incorrect cache invalidation."
);
this.logger.debug(pathToString(job));
this.logger.debug(e.stack);
}
}
} catch (e) {
this.logger.warn(
`Parsing of ${path} for build dependencies failed and all dependencies of this file are ignored, which might cause incorrect cache invalidation..`
);
this.logger.debug(pathToString(job));
this.logger.debug(e.stack);
}
process.nextTick(callback);
Expand All @@ -1378,6 +1435,7 @@ class FileSystemInfo {
this.logger.log(
`Assuming ${path} has no dependencies as we were unable to assign it to any module system.`
);
this.logger.debug(pathToString(job));
}
process.nextTick(callback);
break;
Expand All @@ -1398,7 +1456,8 @@ class FileSystemInfo {
type: RBDT_DIRECTORY_DEPENDENCIES,
context: undefined,
path: parent,
expected: undefined
expected: undefined,
issuer: job
});
}
callback();
Expand All @@ -1420,7 +1479,8 @@ class FileSystemInfo {
type: RBDT_RESOLVE_DIRECTORY,
context: packagePath,
path: dep,
expected: undefined
expected: undefined,
issuer: job
});
}
}
Expand Down

0 comments on commit 4b67afc

Please sign in to comment.