Skip to content

Commit 02bf213

Browse files
authored
[9.0] fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231) (elastic#215028)
# Backport This will backport the following commits from `main` to `9.0`: - [fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231)](elastic#211231) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Tiago Costa","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-02-14T17:07:41Z","message":"fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231)\n\nThis PR solves an issue detected in the populate bundle cache plugin\nafter the webpack v5 migration. On the new version webpack v5 returns a\nlot of incomplete paths when we walk over file dependencies or internal\nmodules. The heuristic logic used previously was faulty so the fixes\nturns to use a cached filesystem api instead.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"16a9136b93e2b9bc2e5d86ff7167a8ae0a563cdb","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["chore","Team:Operations","release_note:skip","backport:prev-major","v8.18.0","v9.1.0","v8.19.0","v8.17.3","v8.16.5"],"title":"fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin","number":211231,"url":"https://github.com/elastic/kibana/pull/211231","mergeCommit":{"message":"fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231)\n\nThis PR solves an issue detected in the populate bundle cache plugin\nafter the webpack v5 migration. On the new version webpack v5 returns a\nlot of incomplete paths when we walk over file dependencies or internal\nmodules. The heuristic logic used previously was faulty so the fixes\nturns to use a cached filesystem api instead.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"16a9136b93e2b9bc2e5d86ff7167a8ae0a563cdb"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/211284","number":211284,"state":"MERGED","mergeCommit":{"sha":"4bcd166b3aabbccbca03bd0a86110e29f0812171","message":"[8.18] fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231) (elastic#211284)\n\n# Backport\n\nThis will backport the following commits from `main` to `8.18`:\n- [fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache\nplugin (elastic#211231)](https://github.com/elastic/kibana/pull/211231)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\nCo-authored-by: Tiago Costa <[email protected]>"}},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/211231","number":211231,"mergeCommit":{"message":"fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231)\n\nThis PR solves an issue detected in the populate bundle cache plugin\nafter the webpack v5 migration. On the new version webpack v5 returns a\nlot of incomplete paths when we walk over file dependencies or internal\nmodules. The heuristic logic used previously was faulty so the fixes\nturns to use a cached filesystem api instead.\n\n---------\n\nCo-authored-by: kibanamachine <[email protected]>","sha":"16a9136b93e2b9bc2e5d86ff7167a8ae0a563cdb"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/211285","number":211285,"state":"MERGED","mergeCommit":{"sha":"73a5339547c64f9060465c4368e216744ce8d514","message":"[8.x] fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231) (elastic#211285)\n\n# Backport\n\nThis will backport the following commits from `main` to `8.x`:\n- [fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache\nplugin (elastic#211231)](https://github.com/elastic/kibana/pull/211231)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\nCo-authored-by: Tiago Costa <[email protected]>"}},{"branch":"8.17","label":"v8.17.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/211672","number":211672,"state":"MERGED","mergeCommit":{"sha":"8f8369753beb6ed6ebd6ac705948b917d5abefc4","message":"[8.17] fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231) (elastic#211672)\n\n# Backport\n\nThis will backport the following commits from `main` to `8.17`:\n- [fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache\nplugin (elastic#211231)](https://github.com/elastic/kibana/pull/211231)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n"}},{"branch":"8.16","label":"v8.16.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/211674","number":211674,"state":"MERGED","mergeCommit":{"sha":"851913bd02ee74230a43a8c2788f606be0189dd2","message":"[8.16] fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache plugin (elastic#211231) (elastic#211674)\n\n# Backport\n\nThis will backport the following commits from `main` to `8.16`:\n- [fix(NA): use filesystem apis on kbn/optimizer populate_bundle_cache\nplugin (elastic#211231)](https://github.com/elastic/kibana/pull/211231)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n"}}]}] BACKPORT-->
1 parent b1aefb7 commit 02bf213

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

packages/kbn-optimizer/src/worker/populate_bundle_cache_plugin.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface InputFileSystem {
3737
encoding: null | undefined,
3838
callback: (err: Error | null, stats: Buffer) => void
3939
) => void;
40+
statSync: (path: string) => any;
4041
}
4142

4243
/**
@@ -48,6 +49,22 @@ interface InputFileSystem {
4849
*/
4950
const EXTRA_SCSS_WORK_UNITS = 100;
5051

52+
const fileCheckCache = new Map();
53+
function isFile(inputFileSystem: InputFileSystem, path: string) {
54+
if (fileCheckCache.has(path)) {
55+
return fileCheckCache.get(path);
56+
}
57+
58+
try {
59+
const result = inputFileSystem.statSync(path).isFile();
60+
fileCheckCache.set(path, result);
61+
return result;
62+
} catch (err) {
63+
fileCheckCache.set(path, false);
64+
return false; // Path does not exist or is not a file
65+
}
66+
}
67+
5168
export class PopulateBundleCachePlugin {
5269
constructor(
5370
private readonly workerConfig: WorkerConfig,
@@ -78,7 +95,7 @@ export class PopulateBundleCachePlugin {
7895
// in webpack v5 there a lot of paths collected that are not real files
7996
// but instead folders or partial paths.
8097
// Here we're verifying if what we have as indeed a filepath
81-
if (Path.extname(path).length > 0) {
98+
if (isFile(inputFs, path)) {
8299
realFileDeps.push(path);
83100
allFileDepsPathSet.add(path);
84101
}
@@ -127,7 +144,7 @@ export class PopulateBundleCachePlugin {
127144
for (const module of compilation.modules) {
128145
if (isNormalModule(module)) {
129146
const path = getModulePath(module);
130-
if (Path.extname(path).length === 0) {
147+
if (!isFile(inputFs, path)) {
131148
continue;
132149
}
133150

0 commit comments

Comments
 (0)