Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(base): introduce static version property for component class #3582

Merged
merged 5 commits into from Sep 8, 2023

Conversation

crav710
Copy link
Contributor

@crav710 crav710 commented Aug 24, 2023

Description

Adding Static property for component classes which can be useful for component libraries to handle scenarios like version conflict.

Related issue(s)

Motivation and context

Adding version to SWC components would help component library to make decision in below scenarios ::

  • If the registered component's version is semver compatible with the component libraries' dependency, there's no need to register the library's version of the component
  • If the registered component's version is not semver compatible the library might register and use the component using a custom tag name.
  • The component library could possibly smooth over backwards-incompatible changes by knowing what the registered version is and work around compatibility issues.

Versioning would also help in long term approach for custom scoped registries as discussed in #3556

How has this been tested?

  • Unit test for base.test has been written to check the version is present in SpectrumElement
  • Tested via storybook to check if the version is set correctly.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

@github-actions
Copy link

github-actions bot commented Aug 24, 2023

Tachometer results

Chrome

accordion permalink

Version Bytes Avg Time vs remote vs branch
npm latest 405 kB 253.36ms - 257.23ms - unsure 🔍
-1% - +1%
-2.73ms - +2.06ms
branch 400 kB 254.22ms - 257.04ms unsure 🔍
-1% - +1%
-2.06ms - +2.73ms
-

action-bar permalink

Version Bytes Avg Time vs remote vs branch
npm latest 476 kB 120.31ms - 121.27ms - unsure 🔍
-1% - +0%
-1.26ms - +0.44ms
branch 471 kB 120.50ms - 121.90ms unsure 🔍
-0% - +1%
-0.44ms - +1.26ms
-

action-button permalink

Version Bytes Avg Time vs remote vs branch
npm latest 506 kB 233.17ms - 235.85ms - slower ❌
8% - 10%
17.37ms - 20.77ms
branch 502 kB 214.40ms - 216.49ms faster ✔
7% - 9%
17.37ms - 20.77ms
-

action-group permalink

Version Bytes Avg Time vs remote vs branch
npm latest 527 kB 132.54ms - 134.95ms - unsure 🔍
-2% - +1%
-2.18ms - +1.76ms
branch 522 kB 132.39ms - 135.51ms unsure 🔍
-1% - +2%
-1.76ms - +2.18ms
-

action-menu permalink

Version Bytes Avg Time vs remote vs branch
npm latest 624 kB 245.69ms - 248.90ms - faster ✔
1% - 3%
1.61ms - 6.33ms
branch 620 kB 249.53ms - 253.00ms slower ❌
1% - 3%
1.61ms - 6.33ms
-
Firefox

accordion permalink

Version Bytes Avg Time vs remote vs branch
npm latest 405 kB 543.67ms - 572.77ms - unsure 🔍
-3% - +5%
-15.39ms - +27.47ms
branch 400 kB 536.45ms - 567.91ms unsure 🔍
-5% - +3%
-27.47ms - +15.39ms
-

action-bar permalink

Version Bytes Avg Time vs remote vs branch
npm latest 476 kB 342.66ms - 365.66ms - unsure 🔍
-5% - +4%
-19.66ms - +14.22ms
branch 471 kB 344.45ms - 369.31ms unsure 🔍
-4% - +6%
-14.22ms - +19.66ms
-

action-button permalink

Version Bytes Avg Time vs remote vs branch
npm latest 506 kB 502.63ms - 534.85ms - unsure 🔍
-5% - +5%
-24.89ms - +23.57ms
branch 502 kB 501.30ms - 537.50ms unsure 🔍
-5% - +5%
-23.57ms - +24.89ms
-

action-group permalink

Version Bytes Avg Time vs remote vs branch
npm latest 527 kB 334.98ms - 367.34ms - unsure 🔍
-4% - +9%
-12.57ms - +29.81ms
branch 522 kB 328.85ms - 356.23ms unsure 🔍
-8% - +3%
-29.81ms - +12.57ms
-

action-menu permalink

Version Bytes Avg Time vs remote vs branch
npm latest 624 kB 497.15ms - 526.81ms - unsure 🔍
-5% - +4%
-23.48ms - +19.84ms
branch 620 kB 498.01ms - 529.59ms unsure 🔍
-4% - +5%
-19.84ms - +23.48ms
-

@crav710 crav710 requested a review from benjamind August 29, 2023 15:32
Copy link
Collaborator

@Westbrook Westbrook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitty things, but really close. Seems like we'd be in a good place to test this out on the next release after those small points of clean up.

tools/base/src/Base.ts Outdated Show resolved Hide resolved
"files": ["./base/src/version.js"],
"rules": {
"notice/notice": "off"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this needed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the generator can't add this information, should we add this file to .eslintignore instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I guess the question is why isn't listing it there enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the intension here is to allow the linter to run on both the files (d.ts & .js) as tools/**/*.d.ts excludes tools/base/src/version.d.ts file from tools in .eslintignore
Then to ignore the header error for version.js we had to add the above override rule inside .eslintrc.json.

I believe we can safely remove the last line !tools/base/src/version.js as it's included by default. Although if we just add tools/base/src/version.js to .eslintignore we would not require the above change in .eslintrc.json.

@rickharris why is it necessary to add version.d.ts & version.js files to linter ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that we can eslintignore the files if we'd like to. I also think you're right that we can remove !tools/base/src/version.js from the eslintignore file. Either option should be fine, just a preference of if we want to ignore the whole file or just the header rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Westbrook added tools/base/src/version.js to .eslintignore & removed the header override.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to remove the updates to this file with that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Removed it.

@@ -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 '../src/version';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Westbrook After adding the file extensions I see that all tests are failing reason being the version.js is being created/updated using genversion & it's excluded from build so version.dev.js is not created & all the test's fail.
Is it okay to roll back to removing extension from version as only version.js file is being created ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File extensions are required. Checkout my other note re *.dev.js files.

tools/base/src/Base.ts Show resolved Hide resolved
Copy link
Collaborator

@Westbrook Westbrook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is failing because by default our tooling expects there to be both a version.js file AND a version.dev.js file. The laziest answer is to give it what it wants and build both files in the pre-commit. Alternatively, we could add specific support for version.js in this script so that the expectation of the version.dev.js file is not created. Both are a tiny bit awkward, so I'm fine with either.

@crav710
Copy link
Contributor Author

crav710 commented Sep 8, 2023

@Westbrook Added the support in script by removing the development condition similar to .css.

Copy link
Collaborator

@Westbrook Westbrook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try it. If it does work for the team, I'd love for us to go back and document it's usage, and how other teams might override it, etc. but for now we can keep it more on the quiet side.

:shipit:

@Westbrook Westbrook force-pushed the crav710/3574-static-version-support branch from fb302ac to 0071ff7 Compare September 8, 2023 20:46
@Westbrook Westbrook changed the title feat(base): Introduce static version property for component class fix(base): introduce static version property for component class Sep 8, 2023
@Westbrook Westbrook merged commit e7e2b76 into main Sep 8, 2023
44 of 46 checks passed
@Westbrook Westbrook deleted the crav710/3574-static-version-support branch September 8, 2023 20:58
blunteshwar pushed a commit that referenced this pull request Sep 12, 2023
* 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 <rickharris@users.noreply.github.com>
Co-authored-by: Ravi Sharma <ravi.sharma@adobe.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat]: Introduce publicly-accessible version to SWC components
3 participants