fix(core): Pass registry and auth token to npm outdated for community packages (#31515)

Co-authored-by: Michael Kret <michael.k@radency.com>
Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com>
Co-authored-by: Bernhard Wittmann <bernhard.wittmann@n8n.io>
This commit is contained in:
Rohit Gahlawat 2026-10-02 12:32:34 +00:00 committed by GitHub
parent e0c27dd34f
commit 1998011d90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 1 deletions

View File

@ -135,7 +135,15 @@ describe('GET /community-packages', () => {
await authAgent.get('/community-packages').expect(200);
const args = [['outdated', '--json'], { doNotHandleError: true, cwd: expect.any(String) }];
const args = [
['outdated', '--json'],
{
doNotHandleError: true,
cwd: expect.any(String),
registry: 'https://registry.npmjs.org',
authToken: undefined,
},
];
expect(mockedExecuteNpmCommand).toHaveBeenCalledWith(...args);
});

View File

@ -35,6 +35,8 @@ describe('CommunityPackagesLifecycleService', () => {
});
const communityPackagesConfig = mock<CommunityPackagesConfig>({
unverifiedEnabled: true,
registry: 'https://registry.npmjs.org',
authToken: '',
});
const instanceSettingsLoaderConfig = mock<InstanceSettingsLoaderConfig>({
communityPackagesManagedByEnv: false,
@ -360,9 +362,32 @@ describe('CommunityPackagesLifecycleService', () => {
expect(mockedExecuteNpmCommand).toHaveBeenCalledWith(['outdated', '--json'], {
doNotHandleError: true,
cwd: '/tmp/n8n-nodes-download',
registry: communityPackagesConfig.registry,
authToken: communityPackagesConfig.authToken || undefined,
});
});
it('should pass custom registry and auth token to npm outdated', async () => {
communityPackagesConfig.unverifiedEnabled = true;
communityPackagesConfig.registry = 'http://localhost:4873';
communityPackagesConfig.authToken = 'my-secret-token';
communityPackagesService.getAllInstalledPackages.mockResolvedValue([installedPackage]);
communityPackagesService.matchPackagesWithUpdates.mockReturnValue([installedPackage]);
Object.defineProperty(communityPackagesService, 'hasMissingPackages', { value: false });
await lifecycle.listInstalledPackages();
expect(mockedExecuteNpmCommand).toHaveBeenCalledWith(['outdated', '--json'], {
doNotHandleError: true,
cwd: '/tmp/n8n-nodes-download',
registry: 'http://localhost:4873',
authToken: 'my-secret-token',
});
communityPackagesConfig.registry = 'https://registry.npmjs.org';
communityPackagesConfig.authToken = '';
});
it('should not run npm outdated when unverifiedEnabled is false', async () => {
communityPackagesConfig.unverifiedEnabled = false;
communityPackagesService.getAllInstalledPackages.mockResolvedValue([installedPackage]);

View File

@ -105,6 +105,8 @@ export class CommunityPackagesLifecycleService {
await executeNpmCommand(['outdated', '--json'], {
doNotHandleError: true,
cwd: this.instanceSettings.nodesDownloadDir,
registry: this.communityPackagesConfig.registry,
authToken: this.communityPackagesConfig.authToken || undefined,
});
} catch (error) {
if (isNpmExecErrorWithStdout(error) && error.code === 1) {