Skip to content

Commit

Permalink
Merge pull request #11 from salesforce-ux/feature/optional-semver-module
Browse files Browse the repository at this point in the history
Allow overriding the semver resolution engine
  • Loading branch information
Kaelig committed Feb 21, 2016
2 parents eda8a67 + 0c17c9c commit 3695499
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ And the compiled CSS won't include `.button`:
.button-new { background: red; border: 3px solid blue; }
```

## Advanced Semantic Versioning Support

Need to compare version numbers such as `3.2.1-beta.5` and `1.2.3-alpha.2`?

By default, sass-deprecate only compares `$version` with `$app-version` in the form of `Major.Minor.Patch` (e.g. `1.2.3` with `2.0.0`).

For advanced SemVer support in the form of `Major.Minor.Patch-beta/alpha/rc.1`, define a `deprecate-version-greater-than($v1, $v2)` function, or rely on Hugo's [sass-semver](https://raw.githubusercontent.com/HugoGiraudel/sass-semver):

```scss
// Override the default SemVer resolution engine
// with sass-semver: https://github.com/HugoGiraudel/sass-semver
@import 'node_modules/sass-semver/index';

@function deprecate-version-greater-than($version, $app-version) {
@return gt($v1: $version, $v2: $app-version);
}

@import 'path-to/sass-deprecate/index';
```

## Running tests

Clone the repository, then:
Expand Down
43 changes: 27 additions & 16 deletions index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $deprecate-mode: 'sensible' !default;

// Major revision of a version
//
// @param {String} $version - Semver version (e.g. '1.0.0')
// @param {String} $version - SemVer version (e.g. '1.0.0')
// @return {Number} Major revision
//
// @example scss
Expand All @@ -65,7 +65,7 @@ $deprecate-mode: 'sensible' !default;

// Minor revision of a version
//
// @param {String} $version - Semver version (e.g. '1.50.0')
// @param {String} $version - SemVer version (e.g. '1.50.0')
// @return {Number} Minor revision
//
// @example scss
Expand All @@ -79,7 +79,7 @@ $deprecate-mode: 'sensible' !default;

// Patch revision of a version
//
// @param {String} $version - Semver version (e.g. '1.50.25')
// @param {String} $version - SemVer version (e.g. '1.50.25')
// @return {Number} Patch revision
//
// @example scss
Expand All @@ -96,7 +96,7 @@ $deprecate-mode: 'sensible' !default;
///
/// @require $app-version
/// @require $deprecate-mode
/// @param {String} $version - Semver-like version (e.g. '2.0.0')
/// @param {String} $version - SemVer-like version (e.g. '2.0.0')
/// @param {String} $message - Reason about why the code will be deprecated or possible workaround (e.g. 'Use .new-thing instead')
@mixin deprecate($version, $message: null) {
@if (type-of($version) != 'string') {
Expand All @@ -121,19 +121,30 @@ $deprecate-mode: 'sensible' !default;
}

// Define if the code is actually deprecated
@if (_d-version-major($version) > _d-version-major($app-version)) {
@content;
$deprecation-found: false;
@if (function-exists('deprecate-version-greater-than')) {
// A custom version comparison engine was found:
// rely on it to check if $version is greater than $app-version,
@if (deprecate-version-greater-than($version, $app-version)) {
@content;
$deprecation-found: false;
}
} @else {
@if (_d-version-major($version) == _d-version-major($app-version)) {
@if (_d-version-minor($version) > _d-version-minor($app-version)) {
@content;
$deprecation-found: false;
} @else {
@if (_d-version-minor($version) == _d-version-minor($app-version)) {
@if (_d-version-patch($version) > _d-version-patch($app-version)) {
@content;
$deprecation-found: false;
// No custom version comparison engine was found:
// fall back to simple version comparison tests.
@if (_d-version-major($version) > _d-version-major($app-version)) {
@content;
$deprecation-found: false;
} @else {
@if (_d-version-major($version) == _d-version-major($app-version)) {
@if (_d-version-minor($version) > _d-version-minor($app-version)) {
@content;
$deprecation-found: false;
} @else {
@if (_d-version-minor($version) == _d-version-minor($app-version)) {
@if (_d-version-patch($version) > _d-version-patch($app-version)) {
@content;
$deprecation-found: false;
}
}
}
}
Expand Down

0 comments on commit 3695499

Please sign in to comment.