From 999b2b45c95f8f14c2997838ccf5a55cbcc28d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Fri, 22 Nov 2019 12:45:25 +0100 Subject: [PATCH] Prevents cache removal when running an install (#7699) * Prevents cache removal when running an install * Removes .bin as usual * Update CHANGELOG.md --- CHANGELOG.md | 7 +++++-- __tests__/commands/install/integration.js | 10 ++++++++++ .../cache-folder-nm/node_modules/.cache/hello.txt | 1 + .../fixtures/install/cache-folder-nm/package.json | 5 +++++ .../fixtures/install/cache-folder-nm/yarn.lock | 13 +++++++++++++ src/package-linker.js | 4 ++++ 6 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 __tests__/fixtures/install/cache-folder-nm/node_modules/.cache/hello.txt create mode 100644 __tests__/fixtures/install/cache-folder-nm/package.json create mode 100644 __tests__/fixtures/install/cache-folder-nm/yarn.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index e74725d637..deaf8ba8b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,15 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa ## Master +- Folders like `.cache` won't be pruned from the `node_modules` after each install. + + [#7699](https://github.com/yarnpkg/yarn/pull/7699) - [**Maƫl Nison**](https://twitter.com/arcanis) + - Correctly installs workspace child dependencies when workspace child not symlinked to root. [#7289](https://github.com/yarnpkg/yarn/pull/7289) - [**Daniel Tschinder**](https://github.com/danez) -- Makes running scripts with Plug'n Play possible on node 13 +- Makes running scripts with Plug'n Play possible on node 13. [#7650](https://github.com/yarnpkg/yarn/pull/7650) - [**Sander Verweij**](https://github.com/sverweij) @@ -16,7 +20,6 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa [#7151](https://github.com/yarnpkg/yarn/pull/7151) - [**Jeff Valore**](https://twitter.com/codingwithspike) - ## 1.19.1 **Important:** This release contains a cache bump. It will cause the very first install following the upgrade to take slightly more time, especially if you don't use the [Offline Mirror](https://yarnpkg.com/blog/2016/11/24/offline-mirror/) feature. After that everything will be back to normal. diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 0a05a4028b..ec78abb54e 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -117,6 +117,16 @@ test('installing a package with a renamed file should not delete it', () => expect(await fs.exists(`${config.cwd}/node_modules/pkg/state.js`)).toEqual(true); })); +test("installing a tree shouldn't remove preexisting cache directories", () => + runInstall({}, 'cache-folder-nm', async (config, reporter): Promise => { + expect(await fs.exists(`${config.cwd}/node_modules/.cache/hello.txt`)).toEqual(true); + + const reInstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd)); + await reInstall.init(); + + expect(await fs.exists(`${config.cwd}/node_modules/.cache/hello.txt`)).toEqual(true); + })); + test("installing a new package should correctly update it, even if the files mtime didn't change", () => runInstall({}, 'mtime-same', async (config, reporter): Promise => { await misc.sleep(2000); diff --git a/__tests__/fixtures/install/cache-folder-nm/node_modules/.cache/hello.txt b/__tests__/fixtures/install/cache-folder-nm/node_modules/.cache/hello.txt new file mode 100644 index 0000000000..557db03de9 --- /dev/null +++ b/__tests__/fixtures/install/cache-folder-nm/node_modules/.cache/hello.txt @@ -0,0 +1 @@ +Hello World diff --git a/__tests__/fixtures/install/cache-folder-nm/package.json b/__tests__/fixtures/install/cache-folder-nm/package.json new file mode 100644 index 0000000000..7bd6acf1a9 --- /dev/null +++ b/__tests__/fixtures/install/cache-folder-nm/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "feed": "0.3.0" + } +} diff --git a/__tests__/fixtures/install/cache-folder-nm/yarn.lock b/__tests__/fixtures/install/cache-folder-nm/yarn.lock new file mode 100644 index 0000000000..4ab6c0f534 --- /dev/null +++ b/__tests__/fixtures/install/cache-folder-nm/yarn.lock @@ -0,0 +1,13 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +feed@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/feed/-/feed-0.3.0.tgz#65bcc4c9c57fde8e277faf4afff80c2d1d90e82d" + dependencies: + xml ">= 0.0.5" + +"xml@>= 0.0.5": + version "1.0.1" + resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" diff --git a/src/package-linker.js b/src/package-linker.js index f66bda80fa..59ca3e8204 100644 --- a/src/package-linker.js +++ b/src/package-linker.js @@ -346,6 +346,10 @@ export default class PackageLinker { for (const subfile of await fs.readdir(filepath)) { possibleExtraneous.add(path.join(filepath, subfile)); } + } else if (file[0] === '.' && file !== '.bin') { + if (!(await fs.lstat(filepath)).isDirectory()) { + possibleExtraneous.add(filepath); + } } else { possibleExtraneous.add(filepath); }