Skip to content

Commit

Permalink
feat(DryMongoBinary): rename "legacyHomeCache" to "homeCache"
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
"legacyHomeCache" has been renamed to "homeCache" when using "DryMongoBinary" directly
  • Loading branch information
hasezoey committed Aug 15, 2023
1 parent 2b9179a commit eb7b691
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
20 changes: 10 additions & 10 deletions packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts
Expand Up @@ -38,7 +38,7 @@ export interface DryMongoBinaryPaths {
/** Path from `DOWNLOAD_DIR` config option */
resolveConfig: string;
/** Path for "~/.config/" (user home) */
legacyHomeCache: string;
homeCache: string;
/** Path for "PROJECT/node_modules/.cache/" (project local cache) */
modulesCache: string;
/** Path for relative to CWD "CWD/" (relative CWD path) */
Expand Down Expand Up @@ -274,7 +274,7 @@ export class DryMongoBinary {
): Promise<DryMongoBinaryPaths> {
log('generatePaths', opts);
const final: DryMongoBinaryPaths = {
legacyHomeCache: '',
homeCache: '',
modulesCache: '',
relative: '',
resolveConfig: '',
Expand All @@ -299,9 +299,9 @@ export class DryMongoBinary {
final.modulesCache = this.combineBinaryName(path.resolve(tmpModulesCache), binaryName);
}

const legacyHomeCache = path.resolve(this.homedir(), '.cache/mongodb-binaries');
const homeCache = path.resolve(this.homedir(), '.cache/mongodb-binaries');

final.legacyHomeCache = this.combineBinaryName(legacyHomeCache, binaryName);
final.homeCache = this.combineBinaryName(homeCache, binaryName);

// Resolve the config value "DOWNLOAD_DIR" if provided, otherwise remove from list
const resolveConfigValue =
Expand Down Expand Up @@ -351,10 +351,10 @@ export class DryMongoBinary {

return [true, paths.resolveConfig];
}
if (await pathExists(paths.legacyHomeCache)) {
log(`generateDownloadPath: Found binary in legacyHomeCache: "${paths.legacyHomeCache}"`);
if (await pathExists(paths.homeCache)) {
log(`generateDownloadPath: Found binary in homeCache: "${paths.homeCache}"`);

return [true, paths.legacyHomeCache];
return [true, paths.homeCache];
}
if (await pathExists(paths.modulesCache)) {
log(`generateDownloadPath: Found binary in modulesCache: "${paths.modulesCache}"`);
Expand All @@ -375,10 +375,10 @@ export class DryMongoBinary {

return [false, paths.resolveConfig];
}
if (preferGlobal && !!paths.legacyHomeCache) {
log(`generateDownloadPath: using global (preferGlobal) "${paths.legacyHomeCache}"`);
if (preferGlobal && !!paths.homeCache) {
log(`generateDownloadPath: using global (preferGlobal) "${paths.homeCache}"`);

return [false, paths.legacyHomeCache];
return [false, paths.homeCache];
}
// this case may not happen, if somehow the cwd gets changed outside of "node_modules" reach
if (paths.modulesCache.length > 0) {
Expand Down
Expand Up @@ -70,7 +70,7 @@ describe('DryBinary', () => {
{
await utils.mkdir(path.resolve(tmpDir, 'node_modules/mongodb-memory-server')); // mock being in an postinstall directory path
await utils.mkdir(path.resolve(tmpDir, 'node_modules/.cache')); // mock having an local modules cache
await utils.mkdir(path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries')); // mock having an "legacy" global directory
await utils.mkdir(path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries')); // mock having an global directory in home
await fspromises.writeFile(path.resolve(tmpDir, 'package.json'), '');
}
});
Expand All @@ -96,7 +96,7 @@ describe('DryBinary', () => {
expect(returnValue).toStrictEqual({
resolveConfig: '', // empty because not having an extra config value
relative: path.resolve(tmpDir, 'mongodb-binaries', binaryName),
legacyHomeCache: path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries', binaryName),
homeCache: path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries', binaryName),
modulesCache: path.resolve(tmpDir, 'node_modules/.cache/mongodb-memory-server', binaryName),
} as binary.DryMongoBinaryPaths);
});
Expand All @@ -112,7 +112,7 @@ describe('DryBinary', () => {
'mongodb-binaries',
binaryName
),
legacyHomeCache: path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries', binaryName),
homeCache: path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries', binaryName),
modulesCache: path.resolve(tmpDir, 'node_modules/.cache/mongodb-memory-server', binaryName),
} as binary.DryMongoBinaryPaths);
});
Expand All @@ -124,7 +124,7 @@ describe('DryBinary', () => {
expect(returnValue).toStrictEqual({
resolveConfig: path.resolve('/some/custom/path', binaryName),
relative: path.resolve(tmpDir, 'mongodb-binaries', binaryName),
legacyHomeCache: path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries', binaryName),
homeCache: path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries', binaryName),
modulesCache: path.resolve(tmpDir, 'node_modules/.cache/mongodb-memory-server', binaryName),
} as binary.DryMongoBinaryPaths);
});
Expand All @@ -136,7 +136,7 @@ describe('DryBinary', () => {
expect(returnValue).toStrictEqual({
resolveConfig: '', // empty because not having an extra config value
relative: path.resolve(tmpDir2, 'mongodb-binaries', binaryName),
legacyHomeCache: path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries', binaryName),
homeCache: path.resolve(tmpDir, 'homedir/.cache/mongodb-binaries', binaryName),
modulesCache: '', // because not being in an project
} as binary.DryMongoBinaryPaths);
});
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('DryBinary', () => {
jest.spyOn(fspromises, 'access').mockResolvedValueOnce(void 0);
const expectedPath = '/some/systembinary/somewhere';
expectedPaths = {
legacyHomeCache: '',
homeCache: '',
modulesCache: '',
relative: '',
resolveConfig: '',
Expand All @@ -270,7 +270,7 @@ describe('DryBinary', () => {
it('should return the DOWNLOAD_DIR when provided', async () => {
const expectedPath = '/some/custom/path/binary';
expectedPaths = {
legacyHomeCache: '',
homeCache: '',
modulesCache: '',
relative: '',
resolveConfig: expectedPath,
Expand All @@ -281,10 +281,10 @@ describe('DryBinary', () => {
expect(returnValue).toStrictEqual([true, expectedPath]);
});

it('should return the legacyHome when provided', async () => {
it('should return the homeCache when provided', async () => {
const expectedPath = '/some/home/path/binary';
expectedPaths = {
legacyHomeCache: expectedPath,
homeCache: expectedPath,
modulesCache: '',
relative: '',
resolveConfig: '/no',
Expand All @@ -298,7 +298,7 @@ describe('DryBinary', () => {
it('should return the modulesCache when provided', async () => {
const expectedPath = '/some/.cache/path/binary';
expectedPaths = {
legacyHomeCache: '/no',
homeCache: '/no',
modulesCache: expectedPath,
relative: '',
resolveConfig: '/no',
Expand All @@ -312,7 +312,7 @@ describe('DryBinary', () => {
it('should return the relative when provided', async () => {
const expectedPath = '/some/relative/path/binary';
expectedPaths = {
legacyHomeCache: '/no',
homeCache: '/no',
modulesCache: '/no',
relative: expectedPath,
resolveConfig: '/no',
Expand All @@ -328,7 +328,7 @@ describe('DryBinary', () => {
it('should return the DOWNLOAD_DIR when provided', async () => {
const expectedPath = '/some/custom/path/binary';
expectedPaths = {
legacyHomeCache: '',
homeCache: '',
modulesCache: '',
relative: '',
resolveConfig: expectedPath,
Expand All @@ -338,11 +338,11 @@ describe('DryBinary', () => {
expect(returnValue).toStrictEqual([false, expectedPath]);
});

it('should return the legacyHome when provided with PREFER_GLOBAL "true"', async () => {
it('should return the homeCache when provided with PREFER_GLOBAL "true"', async () => {
process.env[envName(ResolveConfigVariables.PREFER_GLOBAL_PATH)] = 'true';
const expectedPath = '/some/home/path/binary';
expectedPaths = {
legacyHomeCache: expectedPath,
homeCache: expectedPath,
modulesCache: '',
relative: '',
resolveConfig: '',
Expand All @@ -356,7 +356,7 @@ describe('DryBinary', () => {
process.env[envName(ResolveConfigVariables.PREFER_GLOBAL_PATH)] = 'false';
const expectedPath = '/some/.cache/path/binary';
expectedPaths = {
legacyHomeCache: '',
homeCache: '',
modulesCache: expectedPath,
relative: '',
resolveConfig: '',
Expand All @@ -370,7 +370,7 @@ describe('DryBinary', () => {
process.env[envName(ResolveConfigVariables.PREFER_GLOBAL_PATH)] = 'false';
const expectedPath = '/some/relative/path/binary';
expectedPaths = {
legacyHomeCache: '',
homeCache: '',
modulesCache: '',
relative: expectedPath,
resolveConfig: '',
Expand Down

0 comments on commit eb7b691

Please sign in to comment.