Skip to content

Commit

Permalink
Merge pull request #303 from emulsify-ds/fix-1.x-system-install-with-…
Browse files Browse the repository at this point in the history
…tags

Fix: 1.x system install with tags
  • Loading branch information
callinmullaney authored Oct 24, 2024
2 parents b6837ec + 1d5b5c1 commit 974049c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/handlers/systemInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,15 @@ export default async function systemInstall(
);
}

let checkout = repo.checkout;
// Attempt to get latest tag if no branch was supplied.
if (!checkout) {
checkout = await getRepositoryLatestTag(repo.repository);
if (repo.checkout === undefined) {
repo.checkout = await getRepositoryLatestTag(repo.repository);
}

// Clone the system into the cache.
await cloneIntoCache('systems', [repo.name])({
repository: repo.repository,
checkout: checkout,
checkout: repo.checkout,
});

// Load the system configuration file.
Expand Down
47 changes: 47 additions & 0 deletions src/util/cache/copyItemFromCache.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
jest.mock('./getCachedItemPath', () =>
jest.fn(
() =>
'/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors',
),
);
import { copy, remove } from 'fs-extra';
import getEmulsifyConfig from '../project/getEmulsifyConfig';
import copyItemFromCache from './copyItemFromCache';

// Mock the getEmulsifyConfig function
jest.mock('../project/getEmulsifyConfig', () => jest.fn());

describe('copyItemFromCache', () => {
const mockConfig = {
system: {
checkout: 'checkoutBranch',
},
};

beforeEach(() => {
jest.clearAllMocks();
(getEmulsifyConfig as jest.Mock).mockResolvedValue(mockConfig); // Ensure proper casting
});

it('can copy an item from cache to the given destination', async () => {
await copyItemFromCache(
'systems',
Expand All @@ -19,6 +35,7 @@ describe('copyItemFromCache', () => {
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
);
});

it('can remove a destination before copying items from the cache if "force" is true', async () => {
await copyItemFromCache(
'systems',
Expand All @@ -30,4 +47,34 @@ describe('copyItemFromCache', () => {
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
);
});

it('should handle missing emulsifyConfig system checkout', async () => {
(getEmulsifyConfig as jest.Mock).mockResolvedValue({ system: {} });

await copyItemFromCache(
'systems',
['compound', 'components', '00-base', 'colors'],
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
);

expect(copy).toHaveBeenCalledWith(
'/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors',
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
);
});

it('should handle undefined emulsifyConfig', async () => {
(getEmulsifyConfig as jest.Mock).mockResolvedValue(undefined);

await copyItemFromCache(
'systems',
['compound', 'components', '00-base', 'colors'],
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
);

expect(copy).toHaveBeenCalledWith(
'/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors',
'/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors',
);
});
});
13 changes: 12 additions & 1 deletion src/util/cache/copyItemFromCache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CacheBucket, CacheItemPath } from '@emulsify-cli/cache';
import { copy, remove } from 'fs-extra';
import getCachedItemPath from './getCachedItemPath';
import getEmulsifyConfig from '../project/getEmulsifyConfig';

/**
* Accepts a cache bucket, item path, and item name, and copies the cached item to the
Expand All @@ -18,7 +19,17 @@ export default async function copyFileFromCache(
destination: string,
force = false,
): Promise<void> {
const source = getCachedItemPath(bucket, itemPath);
// Get the existing checkout setting if we have it and use it.
const emulsifyConfig = await getEmulsifyConfig();
let checkout = '';
if (
emulsifyConfig != undefined &&
emulsifyConfig.system &&
emulsifyConfig.system.checkout
) {
checkout = emulsifyConfig.system.checkout;
}
const source = getCachedItemPath(bucket, itemPath, checkout);

if (force) {
await remove(destination);
Expand Down

0 comments on commit 974049c

Please sign in to comment.