Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59e0893

Browse files
authored
support plugins with dots in their npm scope (#3687)
1 parent 12b5338 commit 59e0893

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/pluginManager.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ describe("PluginManager", () => {
99
it("should match scoped plugin names", () => {
1010
expect(PluginManager.isQualifiedPluginIdentifier("@organisation/homebridge-dummy-plugin")).toBeTruthy();
1111
});
12+
13+
it("should match scoped plugin names with dots", () => {
14+
expect(PluginManager.isQualifiedPluginIdentifier("@organisation.com/homebridge-dummy-plugin")).toBeTruthy();
15+
});
1216
});
1317

1418
describe("PluginManager.extractPluginName", () => {
@@ -19,6 +23,10 @@ describe("PluginManager", () => {
1923
it("should extract scoped plugin names", function() {
2024
expect(PluginManager.extractPluginName("@organisation/homebridge-dummy-plugin")).toBe("homebridge-dummy-plugin");
2125
});
26+
27+
it("should extract scoped plugin names with scopes with dots in their name", function() {
28+
expect(PluginManager.extractPluginName("@organisation.com/homebridge-dummy-plugin")).toBe("homebridge-dummy-plugin");
29+
});
2230
});
2331

2432
describe("PluginManager.extractPluginScope", () => {
@@ -29,6 +37,10 @@ describe("PluginManager", () => {
2937
it("should extract scope for scoped plugin names", function() {
3038
expect(PluginManager.extractPluginScope("@organisation/homebridge-dummy-plugin")).toBe("@organisation");
3139
});
40+
41+
it("should extract scope for scoped plugin names with dots in their name", function() {
42+
expect(PluginManager.extractPluginScope("@organisation.com/homebridge-dummy-plugin")).toBe("@organisation.com");
43+
});
3244
});
3345

3446
describe("...Name", () => {

src/pluginManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface PluginManagerOptions {
6464
export class PluginManager {
6565

6666
// name must be prefixed with 'homebridge-' or '@scope/homebridge-'
67-
private static readonly PLUGIN_IDENTIFIER_PATTERN = /^((@[\w-]*)\/)?(homebridge-[\w-]*)$/;
67+
private static readonly PLUGIN_IDENTIFIER_PATTERN = /^((@[\w-]+(\.[\w-]+)*)\/)?(homebridge-[\w-]+)$/;
6868

6969
private readonly api: HomebridgeAPI;
7070

@@ -104,7 +104,7 @@ export class PluginManager {
104104
}
105105

106106
public static extractPluginName(name: string): PluginName { // extract plugin name without @scope/ prefix
107-
return name.match(PluginManager.PLUGIN_IDENTIFIER_PATTERN)![3];
107+
return name.match(PluginManager.PLUGIN_IDENTIFIER_PATTERN)![4];
108108
}
109109

110110
public static extractPluginScope(name: string): string { // extract the "@scope" of a npm module name

0 commit comments

Comments
 (0)