Skip to content

Commit

Permalink
chore: warn when scoping suffix is set too late (#10781)
Browse files Browse the repository at this point in the history
chore: log warning when using scoping suffix
  • Loading branch information
ilhan007 authored Feb 6, 2025
1 parent ac83d60 commit dffec17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/base/src/CustomElementsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const isTagRegistered = (tag: string) => {
return Definitions.has(tag);
};

const hasRegisteredTags = () => {
return Definitions.size > 0;
};

const getAllRegisteredTags = () => {
return [...Definitions.values()];
};
Expand Down Expand Up @@ -93,6 +97,7 @@ const displayFailedRegistrations = () => {
export {
registerTag,
isTagRegistered,
hasRegisteredTags,
getAllRegisteredTags,
recordTagRegistrationFailure,
};
10 changes: 9 additions & 1 deletion packages/base/src/CustomElementsScopeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { hasRegisteredTags } from "./CustomElementsRegistry.js";
import VersionInfo from "./generated/VersionInfo.js";

let suf: string;
Expand All @@ -16,7 +17,9 @@ const tagsCache = new Map<string, boolean>(); // true/false means the tag should

/**
* Sets the suffix to be used for custom elements scoping, f.e. pass "demo" to get tags such as "ui5-button-demo".
* Note: by default all tags starting with "ui5-" will be scoped, unless you change this by calling "setCustomElementsScopingRules"
*
* **Note:** By default all tags starting with "ui5-" will be scoped, unless you change this by calling "setCustomElementsScopingRules"
* **Note:** Setting the scoping suffix must be done before importing any components.
*
* @public
* @param suffix The scoping suffix
Expand All @@ -26,6 +29,11 @@ const setCustomElementsScopingSuffix = (suffix: string) => {
throw new Error("Only alphanumeric characters and dashes allowed for the scoping suffix");
}

if (hasRegisteredTags()) {
// eslint-disable-next-line no-console
console.warn("Setting the scoping suffix must be done before importing any components. For proper usage, read the scoping section: https://github.com/SAP/ui5-webcomponents/blob/main/docs/2-advanced/06-scoping.md.");
}

suf = suffix;
};

Expand Down

0 comments on commit dffec17

Please sign in to comment.