Skip to content

Commit

Permalink
Fix meteor release validation
Browse files Browse the repository at this point in the history
Replace naive parsing logic with proper semver coercion, fixes compatibility with releases 1.10+
  • Loading branch information
ramijarrar committed Feb 14, 2020
1 parent 0d7a575 commit 03df135
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 40 deletions.
2 changes: 2 additions & 0 deletions distribution/lib/azure.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

require("core-js/modules/es.array.for-each");

require("core-js/modules/es.array.map");

require("core-js/modules/es.object.assign");
Expand Down
2 changes: 2 additions & 0 deletions distribution/lib/bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

require("core-js/modules/es.array.for-each");

Object.defineProperty(exports, "__esModule", {
value: true
});
Expand Down
33 changes: 14 additions & 19 deletions distribution/lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ require("core-js/modules/es.array.includes");

require("core-js/modules/es.string.includes");

require("core-js/modules/es.string.replace");

Object.defineProperty(exports, "__esModule", {
value: true
});
Expand All @@ -14,6 +12,8 @@ exports.validateSettings = validateSettings;

var _fs = _interopRequireDefault(require("fs"));

var _semver = _interopRequireDefault(require("semver"));

var _jsonfile = _interopRequireDefault(require("jsonfile"));

var _winston = _interopRequireDefault(require("winston"));
Expand Down Expand Up @@ -47,33 +47,28 @@ function validateMeteor(architecture) {
/* Abort the program if files are not found, this is a strong
indication we may not be in the root project directory */
throw new Error('You must be in a Meteor project directory');
} // Determine major/minor version numbers by stripping non-numeric characters from release
} // -- Validate current Meteor release compatibility


var versionNumbers = release.replace(/[^0-9]/g, '');
var majorVersion = Number.parseInt(versionNumbers.charAt(0), 10);
var minorVersion = Number.parseInt(versionNumbers.charAt(1), 10); // Ensure project does not use 'force-ssl' package
_winston.default.debug('validate current Meteor release compatibility');

_winston.default.debug('check for incompatible \'force-ssl\' package');
var releaseSemver = _semver.default.coerce(release); // Ensure >= 1.4

if (packages.includes('force-ssl')) {
throw new Error('The "force-ssl" package is not supported. Please read the docs to configure an HTTPS redirect in your web config.');
} // Ensure current Meteor release is >= 1.4

if (!_semver.default.satisfies(releaseSemver, '>=1.4.0')) {
throw new Error('Meteor version must be >=1.4.0');
} // Ensure >= 1.6 for 64-bit architecture

_winston.default.debug('check current Meteor release >= 1.4');

if (majorVersion < 1 || minorVersion < 4) {
throw new Error('Meteor version must be >= 1.4');
} // Ensure current Meteor release >= 1.6 for 64-bit architecture
if (architecture === '64' && !_semver.default.satisfies(releaseSemver, '>=1.6.0')) {
throw new Error('Meteor version must be >=1.6.0 for 64-bit Node');
} // Ensure project does not use 'force-ssl' package


if (architecture === '64') {
_winston.default.debug('check current Meteor release >= 1.6 for 64-bit Node');
_winston.default.debug('check for incompatible \'force-ssl\' package');

if (majorVersion < 1 || minorVersion < 6) {
throw new Error('Meteor version must be >= 1.6 for 64-bit Node');
}
if (packages.includes('force-ssl')) {
throw new Error('The "force-ssl" package is not supported. Please read the docs to configure an HTTPS redirect in your web config.');
}
}

Expand Down
62 changes: 59 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"ms-rest-azure": "^2.6.0",
"p-iteration": "^1.1.8",
"regenerator-runtime": "^0.13.3",
"semver": "^7.1.3",
"shelljs": "^0.8.3",
"tar": "^4.4.13",
"tmp": "^0.1.0",
Expand Down
28 changes: 10 additions & 18 deletions source/lib/validation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Validation methods

import fs from 'fs';
import semver from 'semver';
import jsonfile from 'jsonfile';
import winston from 'winston';
import nth from 'lodash.nth';
Expand Down Expand Up @@ -28,30 +29,21 @@ export function validateMeteor(architecture) {
throw new Error('You must be in a Meteor project directory');
}

// Determine major/minor version numbers by stripping non-numeric characters from release
const versionNumbers = release.replace(/[^0-9]/g, '');
const majorVersion = Number.parseInt(versionNumbers.charAt(0), 10);
const minorVersion = Number.parseInt(versionNumbers.charAt(1), 10);
// -- Validate current Meteor release compatibility
winston.debug('validate current Meteor release compatibility');
const releaseSemver = semver.coerce(release);
// Ensure >= 1.4
if (!semver.satisfies(releaseSemver, '>=1.4.0')) { throw new Error('Meteor version must be >=1.4.0'); }
// Ensure >= 1.6 for 64-bit architecture
if (architecture === '64' && !semver.satisfies(releaseSemver, '>=1.6.0')) {
throw new Error('Meteor version must be >=1.6.0 for 64-bit Node');
}

// Ensure project does not use 'force-ssl' package
winston.debug('check for incompatible \'force-ssl\' package');
if (packages.includes('force-ssl')) {
throw new Error('The "force-ssl" package is not supported. Please read the docs to configure an HTTPS redirect in your web config.');
}

// Ensure current Meteor release is >= 1.4
winston.debug('check current Meteor release >= 1.4');
if (majorVersion < 1 || minorVersion < 4) {
throw new Error('Meteor version must be >= 1.4');
}

// Ensure current Meteor release >= 1.6 for 64-bit architecture
if (architecture === '64') {
winston.debug('check current Meteor release >= 1.6 for 64-bit Node');
if (majorVersion < 1 || minorVersion < 6) {
throw new Error('Meteor version must be >= 1.6 for 64-bit Node');
}
}
}

export function validateSettings(filePath) {
Expand Down

0 comments on commit 03df135

Please sign in to comment.