Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ module.exports = function nuts(opts) {

// Change filename to use download proxy
.map(function(entry) {
entry.filename = getBaseDownloadUrl(req) + entry.version+'/'+entry.filename;
entry.filename = getBaseDownloadUrl(req) + '/' + entry.version+'/'+entry.filename;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, how was this working before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't. This is a change I made (to support proxying). We weren't doing Windows releases before so this never got called.


return entry;
})
Expand Down
6 changes: 5 additions & 1 deletion lib/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var semver = require('semver');

var platforms = require('./platforms');

var channelRe = /^[a-z]*/

// Creates filter function that checks for updates
function newVersionFilter(opts) {
return function(version) {
Expand Down Expand Up @@ -41,6 +43,8 @@ function supportsPlatform(requestedPlatform, versionPlatforms) {
platforms.satisfies(requestedPlatform, _.pluck(versionPlatforms, 'type')));
}



module.exports = function(github, opts) {
// Normalize tag name
function normalizeTag(tag) {
Expand All @@ -53,7 +57,7 @@ module.exports = function(github, opts) {
var suffix = tag.split('-')[1];
if (!suffix) return 'stable';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may have moved this out of the closure to allow for testing. Is there another way to to it? Would be nice not to have to move it. Maybe we could test the function that calls into extractChannel instead? idk.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, testing is the only reason why I moved it out. It would be nicer to test the public function that calls this instead. The only reason I didn't do that is time. It would require mocking responses from Github. (And there's no benefit for this function being in the closure). Though that's probably a good thing to do in the end - and probably before submitting a PR into the main Nuts repo.

Hmm... I'll see if I can knock out a quick mock and test things a better way.


return suffix.split('.')[0];
return suffix.match(channelRe)[0] || suffix.split('.')[0];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll write tests for this...

}

// Normalize a release to a version
Expand Down
67 changes: 19 additions & 48 deletions lib/win-releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,14 @@ var _ = require('lodash');
var semver = require('semver');
var stripBom = require('strip-bom');

// Ordered list of supported channel
var CHANNEL_MAGINITUDE = 1000;
var CHANNELS = [
'alpha', 'beta', 'unstable', 'rc'
];

// RELEASES parsing
var releaseRe = /^([0-9a-fA-F]{40})\s+(\S+)\s+(\d+)[\r]*$/;


// Hash a prerelease
function hashPrerelease(s) {
if (_.isString(s[0])) {
return (_.indexOf(CHANNELS, s[0]) + 1) * CHANNEL_MAGINITUDE + (s[1] || 0);
} else {
return s[0];
}
};

// Map a semver version to a windows version
function normVersion(tag) {
var parts = new semver.SemVer(tag);
var prerelease = "";

if (parts.prerelease && parts.prerelease.length > 0) {
prerelease = hashPrerelease(parts.prerelease);
}

return [
parts.major,
parts.minor,
parts.patch
].join('.') + (prerelease? '.'+prerelease : '');
}
var suffixRe = /(-full|-delta)?\.nupkg/;
var versionRe = /\d+(\.\d+){0,3}(-[a-z][0-9a-z-\.]*$)?$/;
var prereleaseRe = /-[a-z][0-9a-z-\.]*$/;

// Parse RELEASES file
// https://github.com/Squirrel/Squirrel.Windows/blob/0d1250aa6f0c25fe22e92add78af327d1277d97d/src/Squirrel/ReleaseExtensions.cs#L19
// https://github.com/Squirrel/Squirrel.Windows/blob/2cc6bfe3c51d0cd0a56511deb8bdab8172aed409/src/Squirrel/ReleaseExtensions.cs#L13-L14
function parseRELEASES(content) {
return _.chain(stripBom(content))
.replace('\r\n', '\n')
Expand All @@ -49,21 +20,22 @@ function parseRELEASES(content) {

var filename = parts[2];
var isDelta = filename.indexOf('-full.nupkg') == -1;

var filenameParts = filename
.replace(".nupkg", "")
.replace("-delta", "")
.replace("-full", "")
.split(/\.|-/)
.reverse();

var version = _.chain(filenameParts)
.filter(function(x) {
return /^\d+$/.exec(x);
var version = _.chain(
filename
.replace(suffixRe, '')
.match(versionRe)
)
.thru(function(matchResult) {
return matchResult ? matchResult[0] : '';
})
.replace(prereleaseRe, function(prerelease) {
// NuGet doesn't support dots in prereleases
// https://docs.nuget.org/create/versioning#user-content-prerelease-versions
return prerelease.replace(/\./g, '');
})
.reverse()
.value()
.join('.');
.value();

if (!version) throw new Error('Release missing valid version: ' + filename);

return {
sha: parts[1],
Expand Down Expand Up @@ -100,7 +72,6 @@ function generateRELEASES(entries) {
}

module.exports = {
normVersion: normVersion,
parse: parseRELEASES,
generate: generateRELEASES
};
Loading