From 7d2a3018d9e5ba7c4c3f568937ab399877501deb Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Fri, 10 Nov 2023 09:39:49 +0100
Subject: [PATCH] fix(containerbase): remove circular datasource import
 (#25685)

---
 lib/modules/manager/bundler/artifacts.spec.ts |  2 --
 lib/util/exec/containerbase.ts                | 15 ++++++++++++++-
 lib/util/exec/index.spec.ts                   |  1 -
 lib/util/git/index.spec.ts                    |  1 -
 lib/util/object.spec.ts                       |  4 ----
 5 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/lib/modules/manager/bundler/artifacts.spec.ts b/lib/modules/manager/bundler/artifacts.spec.ts
index df9b06bdad..a999715318 100644
--- a/lib/modules/manager/bundler/artifacts.spec.ts
+++ b/lib/modules/manager/bundler/artifacts.spec.ts
@@ -53,8 +53,6 @@ const updatedGemfileLock = {
 describe('modules/manager/bundler/artifacts', () => {
   describe('updateArtifacts', () => {
     beforeEach(() => {
-      jest.resetModules();
-
       delete process.env.GEM_HOME;
 
       env.getChildProcessEnv.mockReturnValue(envMock.basic);
diff --git a/lib/util/exec/containerbase.ts b/lib/util/exec/containerbase.ts
index 5a27d1dd0d..3df791e8df 100644
--- a/lib/util/exec/containerbase.ts
+++ b/lib/util/exec/containerbase.ts
@@ -2,7 +2,7 @@ import is from '@sindresorhus/is';
 import { quote } from 'shlex';
 import { GlobalConfig } from '../../config/global';
 import { logger } from '../../logger';
-import { getPkgReleases } from '../../modules/datasource';
+import type { ReleaseResult } from '../../modules/datasource';
 import * as allVersioning from '../../modules/versioning';
 import { id as composerVersioningId } from '../../modules/versioning/composer';
 import { id as gradleVersioningId } from '../../modules/versioning/gradle';
@@ -198,6 +198,19 @@ const allToolConfig: Record<string, ToolConfig> = {
   },
 };
 
+let _getPkgReleases: Promise<typeof import('../../modules/datasource')> | null =
+  null;
+
+async function getPkgReleases(
+  toolConfig: ToolConfig,
+): Promise<ReleaseResult | null> {
+  if (_getPkgReleases === null) {
+    _getPkgReleases = import('../../modules/datasource');
+  }
+  const { getPkgReleases } = await _getPkgReleases;
+  return getPkgReleases(toolConfig);
+}
+
 export function supportsDynamicInstall(toolName: string): boolean {
   return !!allToolConfig[toolName];
 }
diff --git a/lib/util/exec/index.spec.ts b/lib/util/exec/index.spec.ts
index 68616cbf37..3e3385b442 100644
--- a/lib/util/exec/index.spec.ts
+++ b/lib/util/exec/index.spec.ts
@@ -47,7 +47,6 @@ describe('util/exec/index', () => {
   beforeEach(() => {
     dockerModule.resetPrefetchedImages();
     jest.restoreAllMocks();
-    jest.resetModules();
     processEnvOrig = process.env;
     GlobalConfig.reset();
   });
diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts
index 3e36ab49ff..c2be59f4a4 100644
--- a/lib/util/git/index.spec.ts
+++ b/lib/util/git/index.spec.ts
@@ -95,7 +95,6 @@ describe('util/git/index', () => {
   const OLD_ENV = process.env;
 
   beforeEach(async () => {
-    jest.resetModules();
     process.env = { ...OLD_ENV };
     origin = await tmp.dir({ unsafeCleanup: true });
     const repo = Git(origin.path);
diff --git a/lib/util/object.spec.ts b/lib/util/object.spec.ts
index 046c7c0f47..ab2f62d0df 100644
--- a/lib/util/object.spec.ts
+++ b/lib/util/object.spec.ts
@@ -1,10 +1,6 @@
 import { coerceObject, hasKey } from './object';
 
 describe('util/object', () => {
-  beforeEach(() => {
-    jest.resetModules();
-  });
-
   it('finds key in regular object', () => {
     expect(hasKey('foo', { foo: true })).toBeTrue();
   });
-- 
GitLab