Skip to content

Commit

Permalink
[FEATURE] Specification: Add getId method
Browse files Browse the repository at this point in the history
Returns the ID defined by the provider. Should not be used for general
purposes for which "getName" should still be preferred.

Required for #589
  • Loading branch information
matz3 committed Mar 30, 2023
1 parent 1e2aa0e commit 7bdb47a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/specifications/Project.js
Expand Up @@ -61,7 +61,8 @@ class Project extends Specification {
* @returns {boolean} True if the project is a framework project
*/
isFrameworkProject() {
return this.__id.startsWith("@openui5/") || this.__id.startsWith("@sapui5/");
const id = this.getId();
return id.startsWith("@openui5/") || id.startsWith("@sapui5/");
}

/**
Expand Down
24 changes: 21 additions & 3 deletions lib/specifications/Specification.js
Expand Up @@ -97,8 +97,10 @@ class Specification {
this._version = version;
this._modulePath = modulePath;

// The configured name (metadata.name) should be the unique identifier
// The ID property as supplied by the translators is only here for debugging and potential tracing purposes
// The ID property is filled from the provider (e.g. package.json "name") and might differ between providers.
// It is mainly used to detect framework libraries marked by @openui5 / @sapui5 scopes of npm package.
// (see Project#isFrameworkProject)
// In general, the configured name (metadata.name) should be used instead as the unique identifier of a project.
this.__id = id;

// Deep clone config to prevent changes by reference
Expand Down Expand Up @@ -157,7 +159,23 @@ class Specification {

/* === Attributes === */
/**
* Get the name of this specification
* Get the ID of this specification.
*
* <p><b>Note: </b>Only to be used in special occasions as it specific to the provider that was used and does
* not necessarily represent something defined by the project.</p>
*
* For general purposes of a unique identifier use
* {@link @ui5/project/specifications/Specification#getName getName} instead.
*
* @public
* @returns {string} Specification ID
*/
getId() {
return this.__id;
}

/**
* Get the name of this specification. Represents a unique identifier.
*
* @public
* @returns {string} Specification name
Expand Down
1 change: 1 addition & 0 deletions test/lib/specifications/Specification.js
Expand Up @@ -66,6 +66,7 @@ test("Specification can't be instantiated", (t) => {

test("Instantiate a basic project", async (t) => {
const project = await Specification.create(t.context.basicProjectInput);
t.is(project.getId(), "application.a.id", "Returned correct ID");
t.is(project.getName(), "application.a", "Returned correct name");
t.is(project.getVersion(), "1.0.0", "Returned correct version");
t.is(project.getRootPath(), applicationAPath, "Returned correct project path");
Expand Down

0 comments on commit 7bdb47a

Please sign in to comment.