Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Safonkin committed Apr 22, 2021
2 parents b81836a + 20e6808 commit cde58ab
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
3 changes: 2 additions & 1 deletion __tests__/versionutil.test.ts
Expand Up @@ -13,6 +13,8 @@ describe('version tests', () => {
);

each([
['3.x', '3.x'],
['3.*', '3.*'],
['3.1.x', '3.1'],
['1.1.*', '1.1'],
['2.0', '2.0']
Expand Down Expand Up @@ -42,7 +44,6 @@ describe('version tests', () => {
'.2.3',
'.2.x',
'1',
'2.x',
'*.*.1',
'*.1',
'*.',
Expand Down
30 changes: 22 additions & 8 deletions dist/index.js
Expand Up @@ -4840,14 +4840,26 @@ const github = __importStar(__webpack_require__(469));
const xmlbuilder = __importStar(__webpack_require__(312));
const xmlParser = __importStar(__webpack_require__(989));
function configAuthentication(feedUrl, existingFileLocation = '', processRoot = process.cwd()) {
const existingNuGetConfig = path.resolve(processRoot, existingFileLocation == '' ? 'nuget.config' : existingFileLocation);
const existingNuGetConfig = path.resolve(processRoot, existingFileLocation === ''
? getExistingNugetConfig(processRoot)
: existingFileLocation);
const tempNuGetConfig = path.resolve(processRoot, '../', 'nuget.config');
writeFeedToFile(feedUrl, existingNuGetConfig, tempNuGetConfig);
}
exports.configAuthentication = configAuthentication;
function isValidKey(key) {
return /^[\w\-\.]+$/i.test(key);
}
function getExistingNugetConfig(processRoot) {
const defaultConfigName = 'nuget.config';
const configFileNames = fs
.readdirSync(processRoot)
.filter(filename => filename.toLowerCase() === defaultConfigName);
if (configFileNames.length) {
return configFileNames[0];
}
return defaultConfigName;
}
function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
console.log(`dotnet-auth: Finding any source references in ${existingFileLocation}, writing a new temporary configuration file with credentials to ${tempFileLocation}`);
let xml;
Expand Down Expand Up @@ -16872,14 +16884,16 @@ class DotNetVersionInfo {
return;
}
//Note: No support for previews when using generic
let parts = version.split('.');
const parts = version.split('.');
if (parts.length < 2 || parts.length > 3)
this.throwInvalidVersionFormat();
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
this.throwInvalidVersionFormat();
}
let major = this.getVersionNumberOrThrow(parts[0]);
let minor = this.getVersionNumberOrThrow(parts[1]);
const major = this.getVersionNumberOrThrow(parts[0]);
const minor = ['x', '*'].includes(parts[1])
? parts[1]
: this.getVersionNumberOrThrow(parts[1]);
this.fullversion = major + '.' + minor;
}
getVersionNumberOrThrow(input) {
Expand All @@ -16897,7 +16911,7 @@ class DotNetVersionInfo {
}
}
throwInvalidVersionFormat() {
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*';
throw new Error('Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*');
}
/**
* If true exacatly one version should be resolved
Expand Down Expand Up @@ -17000,7 +17014,7 @@ class DotnetCoreInstaller {
}
console.log(process.env['PATH']);
if (resultCode != 0) {
throw `Failed to install dotnet ${resultCode}. ${output}`;
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
}
});
}
Expand Down Expand Up @@ -17028,7 +17042,7 @@ class DotnetCoreInstaller {
// Sort for latest version
releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version']));
if (releasesInfo.length == 0) {
throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`;
throw new Error(`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`);
}
let release = releasesInfo[0];
return release['sdk']['version'];
Expand All @@ -17049,7 +17063,7 @@ class DotnetCoreInstaller {
return versionParts[0] == sdkParts[0];
});
if (releasesInfo.length === 0) {
throw `Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`;
throw new Error(`Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`);
}
return releasesInfo[0]['releases.json'];
});
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion src/authutil.ts
Expand Up @@ -13,7 +13,9 @@ export function configAuthentication(
) {
const existingNuGetConfig: string = path.resolve(
processRoot,
existingFileLocation == '' ? 'nuget.config' : existingFileLocation
existingFileLocation === ''
? getExistingNugetConfig(processRoot)
: existingFileLocation
);

const tempNuGetConfig: string = path.resolve(
Expand All @@ -29,6 +31,17 @@ function isValidKey(key: string): boolean {
return /^[\w\-\.]+$/i.test(key);
}

function getExistingNugetConfig(processRoot: string) {
const defaultConfigName = 'nuget.config';
const configFileNames = fs
.readdirSync(processRoot)
.filter(filename => filename.toLowerCase() === defaultConfigName);
if (configFileNames.length) {
return configFileNames[0];
}
return defaultConfigName;
}

function writeFeedToFile(
feedUrl: string,
existingFileLocation: string,
Expand Down
26 changes: 17 additions & 9 deletions src/installer.ts
Expand Up @@ -30,16 +30,18 @@ export class DotNetVersionInfo {
}

//Note: No support for previews when using generic
let parts: string[] = version.split('.');
const parts: string[] = version.split('.');

if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();

if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
this.throwInvalidVersionFormat();
}

let major = this.getVersionNumberOrThrow(parts[0]);
let minor = this.getVersionNumberOrThrow(parts[1]);
const major = this.getVersionNumberOrThrow(parts[0]);
const minor = ['x', '*'].includes(parts[1])
? parts[1]
: this.getVersionNumberOrThrow(parts[1]);

this.fullversion = major + '.' + minor;
}
Expand All @@ -60,7 +62,9 @@ export class DotNetVersionInfo {
}

private throwInvalidVersionFormat() {
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*';
throw new Error(
'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'
);
}

/**
Expand Down Expand Up @@ -187,7 +191,7 @@ export class DotnetCoreInstaller {
console.log(process.env['PATH']);

if (resultCode != 0) {
throw `Failed to install dotnet ${resultCode}. ${output}`;
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
}
}

Expand Down Expand Up @@ -236,7 +240,9 @@ export class DotnetCoreInstaller {
);

if (releasesInfo.length == 0) {
throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`;
throw new Error(
`Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`
);
}

let release = releasesInfo[0];
Expand Down Expand Up @@ -264,9 +270,11 @@ export class DotnetCoreInstaller {
});

if (releasesInfo.length === 0) {
throw `Could not find info for version ${versionParts.join(
'.'
)} at ${DotNetCoreIndexUrl}`;
throw new Error(
`Could not find info for version ${versionParts.join(
'.'
)} at ${DotNetCoreIndexUrl}`
);
}

return releasesInfo[0]['releases.json'];
Expand Down

0 comments on commit cde58ab

Please sign in to comment.