Skip to content

Commit

Permalink
fix(base): introduce static version property for component class (#3582)
Browse files Browse the repository at this point in the history
* fix(base): add static version property

* chore: version update by commit

* refactor: added version.js to eslintignore and  updated file extensions

* fix(base): fixed unit test case & removed development condition from version.js

* refactor: removed notice rule override as version.js has been added to .eslintignore

---------

Co-authored-by: Rick Harris <[email protected]>
Co-authored-by: Ravi Sharma <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2023
1 parent 716d67e commit e7e2b76
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ packages/**/*.d.ts
packages/*/node_modules/**/*
tools/**/*.d.ts
tools/*/node_modules/**/*
config/*
config/*
tools/base/src/version.js
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ tools/**/*.test-vrt.ts
!tools/*/test/global.d.ts
!tools/*/global.d.ts
!tools/*/local.d.ts
!tools/base/src/version.js
!tools/base/src/version.d.ts


.wireit

Expand Down
5 changes: 4 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
. "$(dirname "$0")/_/husky.sh"

STAGED_FILES_TO_LINT=$(git diff --name-only --cached --diff-filter=d -- "*.ts" "*.js")
VERSION_FILE=$(dirname "$0")/../tools/base/src/version.js
yarn eslint -f pretty $STAGED_FILES_TO_LINT
yarn analyze
yarn lint:css
yarn pretty-quick --staged
yarn pretty-quick --staged
yarn genversion --es6 --semi $VERSION_FILE
git add $VERSION_FILE
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"fast-glob": "^3.2.12",
"fs-extra": "^11.1.1",
"geckodriver": "4.2.0",
"genversion": "^3.1.1",
"gh-pages": "^4.0.0",
"gunzip-maybe": "^1.4.2",
"husky": "^8.0.3",
Expand Down Expand Up @@ -253,7 +254,8 @@
"!test/visual/rollup.config.js",
"!test/visual/src/review.js",
"!test/visual/src/index.html",
"!test/visual/wds-vrt.config.js"
"!test/visual/wds-vrt.config.js",
"!tools/base/src/version.js"
],
"clean": "if-file-deleted"
},
Expand All @@ -271,7 +273,8 @@
"output": [
"packages/**/*.d.ts",
"tools/**/*.d.ts",
"!**/local.d.ts"
"!**/local.d.ts",
"!tools/base/src/version.d.ts"
],
"clean": "if-file-deleted"
},
Expand Down
5 changes: 3 additions & 2 deletions tasks/hydrate-export-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const excludes = [
* }
* - explodes wildcards
* - excludes files in the `excludes` list above
* - does not expose `development` conditions on `*.css.js` files
* - does not expose `development` conditions on `*.css.js` files & version.js file
* - saves back into the `package.json` without linting
*
*/
Expand Down Expand Up @@ -85,7 +85,8 @@ const hydrateExportMap = async (exportMapPath) => {
if (
key.endsWith('.css.js') ||
exportMapResolved[key].endsWith('.css.js') ||
(key !== '.' && !key.endsWith('.js'))
(key !== '.' && !key.endsWith('.js')) ||
key.search('version.js') > -1
) {
// simple map for assets without "development" versions
exportMapExploded[key] = exportMapResolved[key];
Expand Down
1 change: 1 addition & 0 deletions tools/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"development": "./src/streaming-listener.dev.js",
"default": "./src/streaming-listener.js"
},
"./src/version.js": "./src/version.js",
"./condition-attribute-with-id.js": {
"development": "./condition-attribute-with-id.dev.js",
"default": "./condition-attribute-with-id.js"
Expand Down
5 changes: 4 additions & 1 deletion tools/base/src/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ governing permissions and limitations under the License.
*/

import { LitElement, ReactiveElement } from 'lit';
import { version } from '@spectrum-web-components/base/src/version.js';
type ThemeRoot = HTMLElement & {
startManagingContentDirection: (el: HTMLElement) => void;
stopManagingContentDirection: (el: HTMLElement) => void;
Expand Down Expand Up @@ -183,7 +184,9 @@ export function SpectrumMixin<T extends Constructor<ReactiveElement>>(
return SpectrumMixinElement;
}

export class SpectrumElement extends SpectrumMixin(LitElement) {}
export class SpectrumElement extends SpectrumMixin(LitElement) {
static VERSION = version;
}

if (window.__swc.DEBUG) {
const ignoreWarningTypes = {
Expand Down
12 changes: 12 additions & 0 deletions tools/base/src/version.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
export declare const version: string;
2 changes: 2 additions & 0 deletions tools/base/src/version.js

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

4 changes: 4 additions & 0 deletions tools/base/test/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ governing permissions and limitations under the License.
*/
import { SpectrumElement } from '@spectrum-web-components/base';
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
import { version } from '@spectrum-web-components/base/src/version.js';

class DirElement extends SpectrumElement {}

Expand All @@ -32,4 +33,7 @@ describe('Base', () => {
expect(el.dir).to.equal('rtl');
expect(el.isLTR).to.be.false;
});
it('has a static VERSION property', () => {
expect(DirElement.VERSION).to.equal(version);
});
});
27 changes: 27 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13250,6 +13250,13 @@ find-my-way@^7.6.0:
fast-querystring "^1.0.0"
safe-regex2 "^2.0.0"

find-package@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/find-package/-/find-package-1.0.0.tgz#d7738da67e3c5f055c24d3e19aa1aeed063c3e83"
integrity sha512-yVn71XCCaNgxz58ERTl8nA/8YYtIQDY9mHSrgFBfiFtdNNfY0h183Vh8BRkKxD8x9TUw3ec290uJKhDVxqGZBw==
dependencies:
parents "^1.0.1"

find-replace@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/find-replace/-/find-replace-3.0.0.tgz#3e7e23d3b05167a76f770c9fbd5258b0def68c38"
Expand Down Expand Up @@ -13650,6 +13657,14 @@ gensync@^1.0.0-beta.1, gensync@^1.0.0-beta.2:
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==

genversion@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/genversion/-/genversion-3.1.1.tgz#5da18c1ea21813b560f923b37dbbb0df528b7c06"
integrity sha512-/H861PMsihhjgX2qqhTN8egM11V04imhA+3JRFY3jjPua2Sy1NqaqqQPjSP8rdM9jZoKpFhVj9g3Fs9XPCjBYQ==
dependencies:
commander "^7.2.0"
find-package "^1.0.0"

get-amd-module-type@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/get-amd-module-type/-/get-amd-module-type-5.0.1.tgz#bef38ea3674e1aa1bda9c59c8b0da598582f73f2"
Expand Down Expand Up @@ -20613,6 +20628,13 @@ parent-module@^1.0.0:
dependencies:
callsites "^3.0.0"

parents@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parents/-/parents-1.0.1.tgz#fedd4d2bf193a77745fe71e371d73c3307d9c751"
integrity sha512-mXKF3xkoUt5td2DoxpLmtOmZvko9VfFpwRwkKDHSNvgmpLAeBo18YDhcPbBzJq+QLCHMbGOfzia2cX4U+0v9Mg==
dependencies:
path-platform "~0.11.15"

parse-conflict-json@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/parse-conflict-json/-/parse-conflict-json-2.0.2.tgz#3d05bc8ffe07d39600dc6436c6aefe382033d323"
Expand Down Expand Up @@ -20915,6 +20937,11 @@ path-parse@^1.0.6, path-parse@^1.0.7:
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==

path-platform@~0.11.15:
version "0.11.15"
resolved "https://registry.yarnpkg.com/path-platform/-/path-platform-0.11.15.tgz#e864217f74c36850f0852b78dc7bf7d4a5721bf2"
integrity sha512-Y30dB6rab1A/nfEKsZxmr01nUotHX0c/ZiIAsCTatEe1CmS5Pm5He7fZ195bPT7RdquoaL8lLxFCMQi/bS7IJg==

path-root-regex@^0.1.0:
version "0.1.2"
resolved "https://registry.yarnpkg.com/path-root-regex/-/path-root-regex-0.1.2.tgz#bfccdc8df5b12dc52c8b43ec38d18d72c04ba96d"
Expand Down

0 comments on commit e7e2b76

Please sign in to comment.