[8.9] Fix yarn es snapshot cache hit (#161183) (#161390)

# Backport

This will backport the following commits from `main` to `8.9`:
- [Fix yarn es snapshot cache hit
(#161183)](https://github.com/elastic/kibana/pull/161183)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco
Vettorello","email":"marco.vettorello@elastic.co"},"sourceCommit":{"committedDate":"2023-07-06T19:00:29Z","message":"Fix
yarn es snapshot cache hit (#161183)\n\nThe `yarn es` command provides a
useful `--use-cached` to avoid\r\nredownloading the cache, but this is
always skipped because no one set\r\nthe `exists` field is required by
the command to check if the cache is\r\navailable.\r\n\r\nThis commit
just adds that `exists` property where is needed (when reading\r\nthe
`.meta` file) and leaves the rest of the code unaltered.\r\nI could have
implemented the same behavior by returning `null` from the\r\n`readMeta`
and doing a null check where we checked for the `exists`\r\nproperty.
Please feel free which approach you feel
better.","sha":"acba5fb088407c205355d73d65c198d1fe977760","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["build","release_note:skip","backport:all-open","v8.10.0"],"number":161183,"url":"https://github.com/elastic/kibana/pull/161183","mergeCommit":{"message":"Fix
yarn es snapshot cache hit (#161183)\n\nThe `yarn es` command provides a
useful `--use-cached` to avoid\r\nredownloading the cache, but this is
always skipped because no one set\r\nthe `exists` field is required by
the command to check if the cache is\r\navailable.\r\n\r\nThis commit
just adds that `exists` property where is needed (when reading\r\nthe
`.meta` file) and leaves the rest of the code unaltered.\r\nI could have
implemented the same behavior by returning `null` from the\r\n`readMeta`
and doing a null check where we checked for the `exists`\r\nproperty.
Please feel free which approach you feel
better.","sha":"acba5fb088407c205355d73d65c198d1fe977760"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161183","number":161183,"mergeCommit":{"message":"Fix
yarn es snapshot cache hit (#161183)\n\nThe `yarn es` command provides a
useful `--use-cached` to avoid\r\nredownloading the cache, but this is
always skipped because no one set\r\nthe `exists` field is required by
the command to check if the cache is\r\navailable.\r\n\r\nThis commit
just adds that `exists` property where is needed (when reading\r\nthe
`.meta` file) and leaves the rest of the code unaltered.\r\nI could have
implemented the same behavior by returning `null` from the\r\n`readMeta`
and doing a null check where we checked for the `exists`\r\nproperty.
Please feel free which approach you feel
better.","sha":"acba5fb088407c205355d73d65c198d1fe977760"}}]}]
BACKPORT-->

Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
This commit is contained in:
Kibana Machine 2023-07-06 16:06:09 -04:00 committed by GitHub
parent f50b05c50a
commit 71227e03a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,13 +18,16 @@ export const cache = {
return {
...JSON.parse(meta),
exists: true,
};
} catch (e) {
if (e.code !== 'ENOENT') {
throw e;
}
return {};
return {
exists: false,
};
}
},