Skip to content

Commit

Permalink
refactor: specify version in define.js instead of getters (#6568)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Oct 5, 2023
1 parent 052be13 commit 2372ed5
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 38 deletions.
7 changes: 7 additions & 0 deletions packages/component-base/src/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
* Copyright (c) 2021 - 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/

export function defineCustomElement(CustomElement) {
const defined = customElements.get(CustomElement.is);
if (!defined) {
Object.defineProperty(CustomElement, 'version', {
get() {
return '24.3.0-alpha1';
},
});

customElements.define(CustomElement.is, CustomElement);
} else {
const definedVersion = defined.version;
Expand Down
4 changes: 0 additions & 4 deletions packages/component-base/src/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ const registered = new Set();
*/
export const ElementMixin = (superClass) =>
class VaadinElementMixin extends DirMixin(superClass) {
static get version() {
return '24.3.0-alpha1';
}

/** @protected */
static finalize() {
super.finalize();
Expand Down
22 changes: 22 additions & 0 deletions packages/component-base/test/define.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect } from '@esm-bundle/chai';
import { defineCustomElement } from '../src/define.js';

describe('define', () => {
before(() => {
defineCustomElement(
class XElement extends HTMLElement {
static get is() {
return 'x-element';
}
},
);
});

it('should define a custom element', () => {
expect(customElements.get('x-element')).to.be.ok;
});

it('should have a valid version number', () => {
expect(customElements.get('x-element').version).to.match(/^(\d+\.)?(\d+\.)?(\d+)(-(alpha|beta|rc)\d+)?$/u);
});
});
12 changes: 0 additions & 12 deletions packages/component-base/test/element-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ describe('ElementMixin', () => {
});
});

describe('version', () => {
let XElement;

before(() => {
XElement = defineCE('x-element');
});

it('should have a valid version number', () => {
expect(XElement.version).to.match(/^(\d+\.)?(\d+\.)?(\d+)(-(alpha|beta|rc)\d+)?$/u);
});
});

describe('registrations', () => {
let ElementFoo;

Expand Down
4 changes: 0 additions & 4 deletions packages/field-highlighter/src/vaadin-field-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ export class FieldHighlighter extends HTMLElement {
return 'vaadin-field-highlighter';
}

static get version() {
return '24.3.0-alpha1';
}

static init(field) {
if (!field._highlighterController) {
// Create instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export class Templatizer extends PolymerElement {
return 'vaadin-template-renderer-templatizer';
}

static get version() {
return '24.3.0-alpha1';
}

static create(component, template) {
const templatizer = new this();
templatizer.__template = template;
Expand Down
4 changes: 0 additions & 4 deletions packages/vaadin-lumo-styles/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class Lumo extends HTMLElement {
static get is() {
return 'vaadin-lumo-styles';
}

static get version() {
return '24.3.0-alpha1';
}
}

defineCustomElement(Lumo);
Expand Down
4 changes: 0 additions & 4 deletions packages/vaadin-material-styles/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class Material extends HTMLElement {
static get is() {
return 'vaadin-material-styles';
}

static get version() {
return '24.3.0-alpha1';
}
}

defineCustomElement(Material);
Expand Down
7 changes: 1 addition & 6 deletions scripts/updateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ async function main() {
const fromRegex = new RegExp(`'${oldVersion.split('.').join('\\.')}'`, 'gu');
const newVersion = `'${version.replace(/^v/u, '')}'`;
const results = await replace({
files: [
'packages/**/version.{js,ts}',
'packages/component-base/src/*.{js,ts}',
'packages/field-highlighter/src/vaadin-field-highlighter.js',
'packages/polymer-legacy-adapter/src/template-renderer-templatizer.js',
],
files: ['packages/component-base/src/define.js'],
from: fromRegex,
to: newVersion,
});
Expand Down

0 comments on commit 2372ed5

Please sign in to comment.