Skip to content

Commit 6311a4e

Browse files
authored
fix: versioned sd-input validation (#2817)
<!-- ## Title: Please consider adding the [skip chromatic] flag to the PR title in case you dont need chromatic testing your changes. --> ## Description: Current versioning script was also changing events inside of the `assumeInteractionOn` array on the form controller. With this fix, we introduce a more robust strategy to identify patterns that should not be versioned. Original build output: <img width="512" height="80" alt="Screenshot 2026-02-26 at 13 16 56" src="https://github.com/user-attachments/assets/b43ccd6d-0fad-497f-bc7a-4d6ac0cf46b1" /> Build output with fixed versioning: <img width="526" height="74" alt="Screenshot 2026-02-26 at 13 18 21" src="https://github.com/user-attachments/assets/2d514e77-9601-48fc-9bda-9ccef59896b7" /> Versioned `sd-input` validation with fixed build output: https://github.com/user-attachments/assets/44dffcc3-1228-4b6b-ac64-369ba291aa17 ## Definition of Reviewable: <!-- *PR notes: Irrelevant elements should be removed.* --> - [ ] Documentation is created/updated - [ ] Migration Guide is created/updated <!-- *PR notes: If this PR includes a BREAKING CHANGE, a migration guide is needed to explain how users can migrate between versions. * --> - [ ] E2E tests (features, a11y, bug fixes) are created/updated <!-- *If this PR includes a bug fix, an E2E test is necessary to verify the change. If the fix is purely visual, ensuring it is captured within our chromatic screenshot tests is sufficient.* --> - [ ] Stories (features, a11y) are created/updated - [ ] relevant tickets are linked
1 parent 8f94bcd commit 6311a4e

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

.changeset/salty-frogs-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@solid-design-system/versioning': patch
3+
---
4+
5+
Improved versioning script with more robust strategy to identify patterns that should not be changed. This is specially important for events inside the `assumeInteractionOn` array which affect components like the `sd-input`.

packages/versioning/index.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,34 @@ export function versionComponents({ source, destination, components }) {
7373

7474
export function replaceComponentName(fileContent, componentName, version) {
7575
const currentVersion = version.replace(/\./g, '-');
76+
const pattern = new RegExp(`sd-${componentName}`, 'g');
7677

77-
// Events, CSS Variables and URLs to Storybook should not be versioned
78-
const regex = new RegExp(`(?<!this.emit\\("|-|--)sd-${componentName}`, 'g');
79-
return fileContent.replace(regex, `sd-${currentVersion}-${componentName}`);
78+
return fileContent.replace(pattern, (match, offset) => {
79+
// Extract up to 50 characters before the match.
80+
// We clamp the start at 0 to avoid negative indices.
81+
const beforeStartIndex = Math.max(0, offset - 50);
82+
83+
// The text immediately before the match, used to detect patterns like:
84+
// - this.emit("sd-…")
85+
// - assumeInteractionOn arrays
86+
const textBeforeMatch = fileContent.slice(beforeStartIndex, offset);
87+
88+
// The text immediately after the match (up to 10 chars).
89+
// Used to detect Storybook URLs like: sd-button--docs
90+
const textAfterMatch = fileContent.slice(offset + match.length, offset + match.length + 10);
91+
92+
// skips css variables
93+
if (fileContent.slice(Math.max(0, offset - 2), offset) === '--') return match;
94+
95+
// skips storybook urls
96+
if (textAfterMatch.startsWith('--docs')) return match;
97+
98+
// skips event names passed to this.emit
99+
if (textBeforeMatch.endsWith('this.emit("')) return match;
100+
101+
// skips event names in assumeInteractionOn arrays
102+
if (textBeforeMatch.includes('assumeInteractionOn')) return match;
103+
104+
return `sd-${currentVersion}-${componentName}`;
105+
});
80106
}

packages/versioning/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ test('should not replace event names', () => {
6262
assert.strictEqual(result, fileContent); // No replacements in event names
6363
});
6464

65+
test('should not replace assumeInteractionOn events', () => {
66+
const fileContent = `
67+
const controller = new FormControlController(this, {
68+
assumeInteractionOn: ['sd-input']
69+
});
70+
`;
71+
const result = replaceComponentName(fileContent, 'input', '3.2.1');
72+
assert.strictEqual(result, fileContent); // No replacements in assumeInteractionOn event names
73+
});
74+
6575
test('should replace multiple occurrences', () => {
6676
const fileContent = `
6777
<div class="sd-button"></div>

0 commit comments

Comments
 (0)