Skip to content

Commit 4652bcd

Browse files
Merge pull request #307 from emulsify-ds/develop
Fix: Caching rotation bug and system install with tags
2 parents 54e14a6 + 974049c commit 4652bcd

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

src/handlers/systemInstall.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,15 @@ export default async function systemInstall(
118118
);
119119
}
120120

121-
let checkout = repo.checkout;
122121
// Attempt to get latest tag if no branch was supplied.
123-
if (!checkout) {
124-
checkout = await getRepositoryLatestTag(repo.repository);
122+
if (repo.checkout === undefined) {
123+
repo.checkout = await getRepositoryLatestTag(repo.repository);
125124
}
126125

127126
// Clone the system into the cache.
128127
await cloneIntoCache('systems', [repo.name])({
129128
repository: repo.repository,
130-
checkout: checkout,
129+
checkout: repo.checkout,
131130
});
132131

133132
// Load the system configuration file.

src/util/cache/copyItemFromCache.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
12
jest.mock('./getCachedItemPath', () =>
23
jest.fn(
34
() =>
45
'/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors',
56
),
67
);
78
import { copy, remove } from 'fs-extra';
9+
import getEmulsifyConfig from '../project/getEmulsifyConfig';
810
import copyItemFromCache from './copyItemFromCache';
911

12+
// Mock the getEmulsifyConfig function
13+
jest.mock('../project/getEmulsifyConfig', () => jest.fn());
14+
1015
describe('copyItemFromCache', () => {
16+
const mockConfig = {
17+
system: {
18+
checkout: 'checkoutBranch',
19+
},
20+
};
21+
22+
beforeEach(() => {
23+
jest.clearAllMocks();
24+
(getEmulsifyConfig as jest.Mock).mockResolvedValue(mockConfig); // Ensure proper casting
25+
});
26+
1127
it('can copy an item from cache to the given destination', async () => {
1228
await copyItemFromCache(
1329
'systems',
@@ -19,6 +35,7 @@ describe('copyItemFromCache', () => {
1935
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
2036
);
2137
});
38+
2239
it('can remove a destination before copying items from the cache if "force" is true', async () => {
2340
await copyItemFromCache(
2441
'systems',
@@ -30,4 +47,34 @@ describe('copyItemFromCache', () => {
3047
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
3148
);
3249
});
50+
51+
it('should handle missing emulsifyConfig system checkout', async () => {
52+
(getEmulsifyConfig as jest.Mock).mockResolvedValue({ system: {} });
53+
54+
await copyItemFromCache(
55+
'systems',
56+
['compound', 'components', '00-base', 'colors'],
57+
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
58+
);
59+
60+
expect(copy).toHaveBeenCalledWith(
61+
'/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors',
62+
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
63+
);
64+
});
65+
66+
it('should handle undefined emulsifyConfig', async () => {
67+
(getEmulsifyConfig as jest.Mock).mockResolvedValue(undefined);
68+
69+
await copyItemFromCache(
70+
'systems',
71+
['compound', 'components', '00-base', 'colors'],
72+
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
73+
);
74+
75+
expect(copy).toHaveBeenCalledWith(
76+
'/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors',
77+
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
78+
);
79+
});
3380
});

src/util/cache/copyItemFromCache.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { CacheBucket, CacheItemPath } from '@emulsify-cli/cache';
22
import { copy, remove } from 'fs-extra';
33
import getCachedItemPath from './getCachedItemPath';
4+
import getEmulsifyConfig from '../project/getEmulsifyConfig';
45

56
/**
67
* Accepts a cache bucket, item path, and item name, and copies the cached item to the
@@ -18,7 +19,17 @@ export default async function copyFileFromCache(
1819
destination: string,
1920
force = false,
2021
): Promise<void> {
21-
const source = getCachedItemPath(bucket, itemPath);
22+
// Get the existing checkout setting if we have it and use it.
23+
const emulsifyConfig = await getEmulsifyConfig();
24+
let checkout = '';
25+
if (
26+
emulsifyConfig != undefined &&
27+
emulsifyConfig.system &&
28+
emulsifyConfig.system.checkout
29+
) {
30+
checkout = emulsifyConfig.system.checkout;
31+
}
32+
const source = getCachedItemPath(bucket, itemPath, checkout);
2233

2334
if (force) {
2435
await remove(destination);

0 commit comments

Comments
 (0)