Skip to content

Commit 1c36baf

Browse files
dguobestander
authored andcommitted
Add optional offline mirror pruning (#2836)
1 parent 2072978 commit 1c36baf

File tree

16 files changed

+134
-2
lines changed

16 files changed

+134
-2
lines changed

__tests__/commands/remove.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,13 @@ test.concurrent('removes subdependencies', (): Promise<void> => {
140140
assert.equal(lockFileLines[0], 'dep-c@^1.0.0:');
141141
});
142142
});
143+
144+
test.concurrent('can prune the offline mirror', (): Promise<void> => {
145+
return runRemove(['dep-a'], {}, 'prune-offline-mirror', async (config, reporter) => {
146+
const mirrorPath = 'mirror-for-offline';
147+
assert(!await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-a-1.0.0.tgz`)));
148+
// dep-a depends on dep-b, so dep-b should also be pruned
149+
assert(!await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-b-1.0.0.tgz`)));
150+
assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-c-1.0.0.tgz`)));
151+
});
152+
});

__tests__/commands/upgrade.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,16 @@ test.concurrent('doesn\'t warn when peer dependency is still met after upgrade',
165165
'peer-dependency-no-warn',
166166
);
167167
});
168+
169+
test.concurrent('can prune the offline mirror', (): Promise<void> => {
170+
return runUpgrade(['dep-a@1.1.0'], {}, 'prune-offline-mirror', async (config): ?Promise<void> => {
171+
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));
172+
assert(lockfile.indexOf('dep-a@1.1.0:') === 0);
173+
174+
const mirrorPath = 'mirror-for-offline';
175+
assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-a-1.1.0.tgz`)));
176+
assert(!await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-a-1.0.0.tgz`)));
177+
// In 1.1.0, dep-a doesn't depend on dep-b anymore, so dep-b should be pruned
178+
assert(!await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-b-1.0.0.tgz`)));
179+
});
180+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
yarn-offline-mirror "./mirror-for-offline"
6+
yarn-offline-mirror-pruning true
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"dep-a": "1.0.0",
4+
"dep-c": "1.0.0"
5+
}
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
dep-a@1.0.0:
6+
version "1.0.0"
7+
resolved dep-a-1.0.0.tgz#d170a960654001b74bdee4747e71f744ecf0a24f
8+
dependencies:
9+
dep-b "1.0.0"
10+
11+
dep-b@1.0.0:
12+
version "1.0.0"
13+
resolved dep-b-1.0.0.tgz#fa3fab4e36d8eb93ac74790748a30547e9cb0f3f
14+
15+
dep-c@1.0.0:
16+
version "1.0.0"
17+
resolved dep-c-1.0.0.tgz#67156f3be73744a1d4b7c959c4d0d3575e54f442
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
yarn-offline-mirror "./mirror-for-offline"
6+
yarn-offline-mirror-pruning true
Binary file not shown.

0 commit comments

Comments
 (0)