Skip to content

Commit

Permalink
Merge pull request #5317 from Polymer/export-version
Browse files Browse the repository at this point in the history
Export the current Polymer version in polymer-element.js
  • Loading branch information
kevinpschaaf authored Aug 27, 2018
2 parents c7ee777 + f845842 commit 7a67e34
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 3 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ gulp.task('lint', gulp.series('lint-eslint'));
// TODO(timvdlippe): Add back `'generate-externs',` once we can generate externs again

gulp.task('update-version', () => {
return gulp.src('lib/utils/boot.js')
.pipe(replace(/(window.Polymer.version = )'\d+\.\d+\.\d+'/, `$1'${require('./package.json').version}'`))
.pipe(gulp.dest('lib/utils'));
return gulp.src('lib/mixins/element-mixin.js')
.pipe(replace(/(export const version = )'\d+\.\d+\.\d+'/, `$1'${require('./package.json').version}'`))
.pipe(gulp.dest('lib/mixins'));
});
14 changes: 14 additions & 0 deletions lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { PropertyEffects } from './property-effects.js';
import { PropertiesMixin } from './properties-mixin.js';
import { strictTemplatePolicy, allowTemplateFromDomModule } from '../utils/settings.js';

/**
* Current Polymer version in Semver notation.
* @type {string} Semver notation of the current version of Polymer.
*/
export const version = '3.0.5';

/**
* Element class mixin that provides the core API for Polymer's meta-programming
* features including template stamping, data-binding, attribute deserialization,
Expand Down Expand Up @@ -302,6 +308,14 @@ export const ElementMixin = dedupingMixin(base => {
*/
class PolymerElement extends polymerElementBase {

/**
* Current Polymer version in Semver notation.
* @type {string} Semver notation of the current version of Polymer.
*/
static get polymerElementVersion() {
return version;
}

/**
* Override of PropertiesMixin _finalizeClass to create observers and
* find the template.
Expand Down
2 changes: 1 addition & 1 deletion polymer-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/

import { ElementMixin } from './lib/mixins/element-mixin.js';
export { version } from './lib/mixins/element-mixin.js';
export { html } from './lib/utils/html-tag.js';

/**
Expand All @@ -27,4 +28,3 @@ export { html } from './lib/utils/html-tag.js';
* attribute deserialization, and property change observation
*/
export const PolymerElement = ElementMixin(HTMLElement);

3 changes: 3 additions & 0 deletions test/unit/polymer.element.html
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ <h1>Sub template</h1>
assert.equal(fixtureEl.getAttribute('prop'), 'propValue');
});

test('version', function() {
assert.isOk(el.constructor.polymerElementVersion);
});
});

suite('subclass', function() {
Expand Down

0 comments on commit 7a67e34

Please sign in to comment.