diff --git a/dist/index.js b/dist/index.js index 00efa73..5b10e8d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -55,6 +55,7 @@ function getExistingNugetConfig(processRoot) { return defaultConfigName; } function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { + var _a, _b; core.info(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`); let xml; let sourceKeys = []; @@ -73,31 +74,26 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) { if (typeof json.configuration === 'undefined') { throw new Error(`The provided NuGet.config seems invalid.`); } - if (typeof json.configuration.packageSources != 'undefined') { - if (typeof json.configuration.packageSources.add != 'undefined') { - // file has at least one - if (typeof json.configuration.packageSources.add[0] === 'undefined') { - // file has only one - if (json.configuration.packageSources.add['@_value'] - .toLowerCase() - .includes(feedUrl.toLowerCase())) { - const key = json.configuration.packageSources.add['@_key']; + if ((_b = (_a = json.configuration) === null || _a === void 0 ? void 0 : _a.packageSources) === null || _b === void 0 ? void 0 : _b.add) { + const packageSources = json.configuration.packageSources.add; + if (Array.isArray(packageSources)) { + packageSources.forEach(source => { + const value = source['@_value']; + core.debug(`source '${value}'`); + if (value.toLowerCase().includes(feedUrl.toLowerCase())) { + const key = source['@_key']; sourceKeys.push(key); core.debug(`Found a URL with key ${key}`); } - } - else { - // file has 2+ - for (let i = 0; i < json.configuration.packageSources.add.length; i++) { - const source = json.configuration.packageSources.add[i]; - const value = source['@_value']; - core.debug(`source '${value}'`); - if (value.toLowerCase().includes(feedUrl.toLowerCase())) { - const key = source['@_key']; - sourceKeys.push(key); - core.debug(`Found a URL with key ${key}`); - } - } + }); + } + else { + if (packageSources['@_value'] + .toLowerCase() + .includes(feedUrl.toLowerCase())) { + const key = packageSources['@_key']; + sourceKeys.push(key); + core.debug(`Found a URL with key ${key}`); } } } diff --git a/src/authutil.ts b/src/authutil.ts index 60a4dd7..b9c0e15 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -71,36 +71,28 @@ function writeFeedToFile( if (typeof json.configuration === 'undefined') { throw new Error(`The provided NuGet.config seems invalid.`); } - if (typeof json.configuration.packageSources != 'undefined') { - if (typeof json.configuration.packageSources.add != 'undefined') { - // file has at least one - if (typeof json.configuration.packageSources.add[0] === 'undefined') { - // file has only one - if ( - json.configuration.packageSources.add['@_value'] - .toLowerCase() - .includes(feedUrl.toLowerCase()) - ) { - const key = json.configuration.packageSources.add['@_key']; + if (json.configuration?.packageSources?.add) { + const packageSources = json.configuration.packageSources.add; + + if (Array.isArray(packageSources)) { + packageSources.forEach(source => { + const value = source['@_value']; + core.debug(`source '${value}'`); + if (value.toLowerCase().includes(feedUrl.toLowerCase())) { + const key = source['@_key']; sourceKeys.push(key); core.debug(`Found a URL with key ${key}`); } - } else { - // file has 2+ - for ( - let i = 0; - i < json.configuration.packageSources.add.length; - i++ - ) { - const source = json.configuration.packageSources.add[i]; - const value = source['@_value']; - core.debug(`source '${value}'`); - if (value.toLowerCase().includes(feedUrl.toLowerCase())) { - const key = source['@_key']; - sourceKeys.push(key); - core.debug(`Found a URL with key ${key}`); - } - } + }); + } else { + if ( + packageSources['@_value'] + .toLowerCase() + .includes(feedUrl.toLowerCase()) + ) { + const key = packageSources['@_key']; + sourceKeys.push(key); + core.debug(`Found a URL with key ${key}`); } } }