@backstage-community/plugin-lighthouse-common 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,115 @@
1
+ # @backstage-community/plugin-lighthouse-common
2
+
3
+ ## 0.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 193a2a3: Migrated from the [backstage/backstage](https://github.com/backstage/backstage) monorepo.
8
+
9
+ ## 0.1.5
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+ - @backstage/config@1.2.0
15
+
16
+ ## 0.1.5-next.1
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+ - @backstage/config@1.2.0-next.1
22
+
23
+ ## 0.1.5-next.0
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+ - @backstage/config@1.1.2-next.0
29
+
30
+ ## 0.1.4
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies
35
+ - @backstage/config@1.1.1
36
+
37
+ ## 0.1.4-next.0
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies
42
+ - @backstage/config@1.1.1-next.0
43
+
44
+ ## 0.1.3
45
+
46
+ ### Patch Changes
47
+
48
+ - 406b786a2a2c: Mark package as being free of side effects, allowing more optimized Webpack builds.
49
+ - Updated dependencies
50
+ - @backstage/config@1.1.0
51
+
52
+ ## 0.1.3-next.2
53
+
54
+ ### Patch Changes
55
+
56
+ - 406b786a2a2c: Mark package as being free of side effects, allowing more optimized Webpack builds.
57
+ - Updated dependencies
58
+ - @backstage/config@1.1.0-next.2
59
+
60
+ ## 0.1.3-next.1
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies
65
+ - @backstage/config@1.1.0-next.1
66
+
67
+ ## 0.1.3-next.0
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies
72
+ - @backstage/config@1.1.0-next.0
73
+
74
+ ## 0.1.2
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies
79
+ - @backstage/config@1.0.8
80
+
81
+ ## 0.1.1
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies
86
+ - @backstage/config@1.0.7
87
+
88
+ ## 0.1.1-next.0
89
+
90
+ ### Patch Changes
91
+
92
+ - Updated dependencies
93
+ - @backstage/config@1.0.7-next.0
94
+
95
+ ## 0.1.0
96
+
97
+ ### Minor Changes
98
+
99
+ - eef62546ce: Introduce @backstage-community/plugin-lighthouse-common with the API implementation
100
+
101
+ ### Patch Changes
102
+
103
+ - Updated dependencies
104
+ - @backstage/config@1.0.6
105
+
106
+ ## 0.1.0-next.0
107
+
108
+ ### Minor Changes
109
+
110
+ - eef62546ce: Introduce @backstage-community/plugin-lighthouse-common with the API implementation
111
+
112
+ ### Patch Changes
113
+
114
+ - Updated dependencies
115
+ - @backstage/config@1.0.6
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @backstage-community/plugin-lighthouse-common
2
+
3
+ Common types and functionalities for lighthouse, to be shared between lighthouse and lighthouse-backend.
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ class FetchError extends Error {
4
+ get name() {
5
+ return this.constructor.name;
6
+ }
7
+ static async forResponse(resp) {
8
+ return new FetchError(
9
+ `Request failed with status code ${resp.status}.
10
+ Reason: ${await resp.text()}`
11
+ );
12
+ }
13
+ }
14
+ class LighthouseRestApi {
15
+ constructor(url) {
16
+ this.url = url;
17
+ }
18
+ static fromConfig(config) {
19
+ return new LighthouseRestApi(config.getString("lighthouse.baseUrl"));
20
+ }
21
+ async fetch(input, init) {
22
+ const resp = await fetch(`${this.url}${input}`, init);
23
+ if (!resp.ok)
24
+ throw await FetchError.forResponse(resp);
25
+ return await resp.json();
26
+ }
27
+ async getWebsiteList(options = {}) {
28
+ const { limit, offset } = options;
29
+ const params = new URLSearchParams();
30
+ if (typeof limit === "number")
31
+ params.append("limit", limit.toString());
32
+ if (typeof offset === "number")
33
+ params.append("offset", offset.toString());
34
+ return await this.fetch(
35
+ `/v1/websites?${params.toString()}`
36
+ );
37
+ }
38
+ async getWebsiteForAuditId(auditId) {
39
+ return await this.fetch(
40
+ `/v1/audits/${encodeURIComponent(auditId)}/website`
41
+ );
42
+ }
43
+ async triggerAudit(payload) {
44
+ return await this.fetch("/v1/audits", {
45
+ method: "POST",
46
+ body: JSON.stringify(payload),
47
+ headers: {
48
+ "Content-Type": "application/json"
49
+ }
50
+ });
51
+ }
52
+ async getWebsiteByUrl(websiteUrl) {
53
+ return this.fetch(
54
+ `/v1/websites/${encodeURIComponent(websiteUrl)}`
55
+ );
56
+ }
57
+ }
58
+
59
+ exports.FetchError = FetchError;
60
+ exports.LighthouseRestApi = LighthouseRestApi;
61
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/api.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\n\n/** @public */\nexport type LighthouseCategoryId =\n | 'pwa'\n | 'seo'\n | 'performance'\n | 'accessibility'\n | 'best-practices';\n\n/** @public */\nexport interface LighthouseCategoryAbbr {\n id: LighthouseCategoryId;\n score: number;\n title: string;\n}\n\n/** @public */\nexport interface LASListRequest {\n offset?: number;\n limit?: number;\n}\n\n/** @public */\nexport interface LASListResponse<Item> {\n items: Item[];\n total: number;\n offset: number;\n limit: number;\n}\n\n/** @public */\nexport interface AuditBase {\n id: string;\n url: string;\n timeCreated: string;\n}\n\n/** @public */\nexport interface AuditRunning extends AuditBase {\n status: 'RUNNING';\n}\n\n/** @public */\nexport interface AuditFailed extends AuditBase {\n status: 'FAILED';\n timeCompleted: string;\n}\n\n/** @public */\nexport interface AuditCompleted extends AuditBase {\n status: 'COMPLETED';\n timeCompleted: string;\n report: Object;\n categories: Record<LighthouseCategoryId, LighthouseCategoryAbbr>;\n}\n\n/** @public */\nexport type Audit = AuditRunning | AuditFailed | AuditCompleted;\n\n/** @public */\nexport interface Website {\n url: string;\n audits: Audit[];\n lastAudit: Audit;\n}\n\n/** @public */\nexport type WebsiteListResponse = LASListResponse<Website>;\n\n/** @public */\nexport type FormFactor = 'mobile' | 'desktop';\n\n/** @public */\nexport type LighthouseConfigSettings = {\n // For lighthouse 7+\n formFactor: FormFactor;\n screenEmulation:\n | {\n mobile: boolean;\n width: number;\n height: number;\n deviceScaleFactor: number;\n disabled: boolean;\n }\n | undefined;\n // For lighthouse before 7\n emulatedFormFactor: FormFactor;\n};\n\n/** @public */\nexport interface TriggerAuditPayload {\n url: string;\n options: {\n lighthouseConfig: {\n settings: LighthouseConfigSettings;\n };\n };\n}\n\n/** @public */\nexport class FetchError extends Error {\n get name(): string {\n return this.constructor.name;\n }\n\n static async forResponse(resp: Response): Promise<FetchError> {\n return new FetchError(\n `Request failed with status code ${\n resp.status\n }.\\nReason: ${await resp.text()}`,\n );\n }\n}\n\n/** @public */\nexport type LighthouseApi = {\n url: string;\n getWebsiteList: (listOptions: LASListRequest) => Promise<WebsiteListResponse>;\n getWebsiteForAuditId: (auditId: string) => Promise<Website>;\n triggerAudit: (payload: TriggerAuditPayload) => Promise<Audit>;\n getWebsiteByUrl: (websiteUrl: string) => Promise<Website>;\n};\n\n/** @public */\nexport class LighthouseRestApi implements LighthouseApi {\n static fromConfig(config: Config) {\n return new LighthouseRestApi(config.getString('lighthouse.baseUrl'));\n }\n\n constructor(public url: string) {}\n\n private async fetch<T = any>(input: string, init?: RequestInit): Promise<T> {\n const resp = await fetch(`${this.url}${input}`, init);\n if (!resp.ok) throw await FetchError.forResponse(resp);\n return await resp.json();\n }\n\n async getWebsiteList(\n options: LASListRequest = {},\n ): Promise<WebsiteListResponse> {\n const { limit, offset } = options;\n const params = new URLSearchParams();\n if (typeof limit === 'number') params.append('limit', limit.toString());\n if (typeof offset === 'number') params.append('offset', offset.toString());\n return await this.fetch<WebsiteListResponse>(\n `/v1/websites?${params.toString()}`,\n );\n }\n\n async getWebsiteForAuditId(auditId: string): Promise<Website> {\n return await this.fetch<Website>(\n `/v1/audits/${encodeURIComponent(auditId)}/website`,\n );\n }\n\n async triggerAudit(payload: TriggerAuditPayload): Promise<Audit> {\n return await this.fetch<Audit>('/v1/audits', {\n method: 'POST',\n body: JSON.stringify(payload),\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n }\n\n async getWebsiteByUrl(websiteUrl: string): Promise<Website> {\n return this.fetch<Website>(\n `/v1/websites/${encodeURIComponent(websiteUrl)}`,\n );\n }\n}\n"],"names":[],"mappings":";;AAqHO,MAAM,mBAAmB,KAAM,CAAA;AAAA,EACpC,IAAI,IAAe,GAAA;AACjB,IAAA,OAAO,KAAK,WAAY,CAAA,IAAA,CAAA;AAAA,GAC1B;AAAA,EAEA,aAAa,YAAY,IAAqC,EAAA;AAC5D,IAAA,OAAO,IAAI,UAAA;AAAA,MACT,CAAA,gCAAA,EACE,KAAK,MACP,CAAA;AAAA,QAAc,EAAA,MAAM,IAAK,CAAA,IAAA,EAAM,CAAA,CAAA;AAAA,KACjC,CAAA;AAAA,GACF;AACF,CAAA;AAYO,MAAM,iBAA2C,CAAA;AAAA,EAKtD,YAAmB,GAAa,EAAA;AAAb,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA,CAAA;AAAA,GAAc;AAAA,EAJjC,OAAO,WAAW,MAAgB,EAAA;AAChC,IAAA,OAAO,IAAI,iBAAA,CAAkB,MAAO,CAAA,SAAA,CAAU,oBAAoB,CAAC,CAAA,CAAA;AAAA,GACrE;AAAA,EAIA,MAAc,KAAe,CAAA,KAAA,EAAe,IAAgC,EAAA;AAC1E,IAAM,M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A,MAC5B,OAAS,EAAA;AAAA,QACP,cAAgB,EAAA,kBAAA;AAAA,OAClB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAM,gBAAgB,UAAsC,EAAA;AAC1D,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA,MACV,CAAA,aAAA,EAAgB,kBAAmB,CAAA,UAAU,CAAC,CAAA,CAAA;AAAA,KAChD,CAAA;AAAA,GACF;AACF;;;;;"}
@@ -0,0 +1,103 @@
1
+ import { Config } from '@backstage/config';
2
+
3
+ /** @public */
4
+ type LighthouseCategoryId = 'pwa' | 'seo' | 'performance' | 'accessibility' | 'best-practices';
5
+ /** @public */
6
+ interface LighthouseCategoryAbbr {
7
+ id: LighthouseCategoryId;
8
+ score: number;
9
+ title: string;
10
+ }
11
+ /** @public */
12
+ interface LASListRequest {
13
+ offset?: number;
14
+ limit?: number;
15
+ }
16
+ /** @public */
17
+ interface LASListResponse<Item> {
18
+ items: Item[];
19
+ total: number;
20
+ offset: number;
21
+ limit: number;
22
+ }
23
+ /** @public */
24
+ interface AuditBase {
25
+ id: string;
26
+ url: string;
27
+ timeCreated: string;
28
+ }
29
+ /** @public */
30
+ interface AuditRunning extends AuditBase {
31
+ status: 'RUNNING';
32
+ }
33
+ /** @public */
34
+ interface AuditFailed extends AuditBase {
35
+ status: 'FAILED';
36
+ timeCompleted: string;
37
+ }
38
+ /** @public */
39
+ interface AuditCompleted extends AuditBase {
40
+ status: 'COMPLETED';
41
+ timeCompleted: string;
42
+ report: Object;
43
+ categories: Record<LighthouseCategoryId, LighthouseCategoryAbbr>;
44
+ }
45
+ /** @public */
46
+ type Audit = AuditRunning | AuditFailed | AuditCompleted;
47
+ /** @public */
48
+ interface Website {
49
+ url: string;
50
+ audits: Audit[];
51
+ lastAudit: Audit;
52
+ }
53
+ /** @public */
54
+ type WebsiteListResponse = LASListResponse<Website>;
55
+ /** @public */
56
+ type FormFactor = 'mobile' | 'desktop';
57
+ /** @public */
58
+ type LighthouseConfigSettings = {
59
+ formFactor: FormFactor;
60
+ screenEmulation: {
61
+ mobile: boolean;
62
+ width: number;
63
+ height: number;
64
+ deviceScaleFactor: number;
65
+ disabled: boolean;
66
+ } | undefined;
67
+ emulatedFormFactor: FormFactor;
68
+ };
69
+ /** @public */
70
+ interface TriggerAuditPayload {
71
+ url: string;
72
+ options: {
73
+ lighthouseConfig: {
74
+ settings: LighthouseConfigSettings;
75
+ };
76
+ };
77
+ }
78
+ /** @public */
79
+ declare class FetchError extends Error {
80
+ get name(): string;
81
+ static forResponse(resp: Response): Promise<FetchError>;
82
+ }
83
+ /** @public */
84
+ type LighthouseApi = {
85
+ url: string;
86
+ getWebsiteList: (listOptions: LASListRequest) => Promise<WebsiteListResponse>;
87
+ getWebsiteForAuditId: (auditId: string) => Promise<Website>;
88
+ triggerAudit: (payload: TriggerAuditPayload) => Promise<Audit>;
89
+ getWebsiteByUrl: (websiteUrl: string) => Promise<Website>;
90
+ };
91
+ /** @public */
92
+ declare class LighthouseRestApi implements LighthouseApi {
93
+ url: string;
94
+ static fromConfig(config: Config): LighthouseRestApi;
95
+ constructor(url: string);
96
+ private fetch;
97
+ getWebsiteList(options?: LASListRequest): Promise<WebsiteListResponse>;
98
+ getWebsiteForAuditId(auditId: string): Promise<Website>;
99
+ triggerAudit(payload: TriggerAuditPayload): Promise<Audit>;
100
+ getWebsiteByUrl(websiteUrl: string): Promise<Website>;
101
+ }
102
+
103
+ export { type Audit, type AuditBase, type AuditCompleted, type AuditFailed, type AuditRunning, FetchError, type FormFactor, type LASListRequest, type LASListResponse, type LighthouseApi, type LighthouseCategoryAbbr, type LighthouseCategoryId, type LighthouseConfigSettings, LighthouseRestApi, type TriggerAuditPayload, type Website, type WebsiteListResponse };
@@ -0,0 +1,58 @@
1
+ class FetchError extends Error {
2
+ get name() {
3
+ return this.constructor.name;
4
+ }
5
+ static async forResponse(resp) {
6
+ return new FetchError(
7
+ `Request failed with status code ${resp.status}.
8
+ Reason: ${await resp.text()}`
9
+ );
10
+ }
11
+ }
12
+ class LighthouseRestApi {
13
+ constructor(url) {
14
+ this.url = url;
15
+ }
16
+ static fromConfig(config) {
17
+ return new LighthouseRestApi(config.getString("lighthouse.baseUrl"));
18
+ }
19
+ async fetch(input, init) {
20
+ const resp = await fetch(`${this.url}${input}`, init);
21
+ if (!resp.ok)
22
+ throw await FetchError.forResponse(resp);
23
+ return await resp.json();
24
+ }
25
+ async getWebsiteList(options = {}) {
26
+ const { limit, offset } = options;
27
+ const params = new URLSearchParams();
28
+ if (typeof limit === "number")
29
+ params.append("limit", limit.toString());
30
+ if (typeof offset === "number")
31
+ params.append("offset", offset.toString());
32
+ return await this.fetch(
33
+ `/v1/websites?${params.toString()}`
34
+ );
35
+ }
36
+ async getWebsiteForAuditId(auditId) {
37
+ return await this.fetch(
38
+ `/v1/audits/${encodeURIComponent(auditId)}/website`
39
+ );
40
+ }
41
+ async triggerAudit(payload) {
42
+ return await this.fetch("/v1/audits", {
43
+ method: "POST",
44
+ body: JSON.stringify(payload),
45
+ headers: {
46
+ "Content-Type": "application/json"
47
+ }
48
+ });
49
+ }
50
+ async getWebsiteByUrl(websiteUrl) {
51
+ return this.fetch(
52
+ `/v1/websites/${encodeURIComponent(websiteUrl)}`
53
+ );
54
+ }
55
+ }
56
+
57
+ export { FetchError, LighthouseRestApi };
58
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/api.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Config } from '@backstage/config';\n\n/** @public */\nexport type LighthouseCategoryId =\n | 'pwa'\n | 'seo'\n | 'performance'\n | 'accessibility'\n | 'best-practices';\n\n/** @public */\nexport interface LighthouseCategoryAbbr {\n id: LighthouseCategoryId;\n score: number;\n title: string;\n}\n\n/** @public */\nexport interface LASListRequest {\n offset?: number;\n limit?: number;\n}\n\n/** @public */\nexport interface LASListResponse<Item> {\n items: Item[];\n total: number;\n offset: number;\n limit: number;\n}\n\n/** @public */\nexport interface AuditBase {\n id: string;\n url: string;\n timeCreated: string;\n}\n\n/** @public */\nexport interface AuditRunning extends AuditBase {\n status: 'RUNNING';\n}\n\n/** @public */\nexport interface AuditFailed extends AuditBase {\n status: 'FAILED';\n timeCompleted: string;\n}\n\n/** @public */\nexport interface AuditCompleted extends AuditBase {\n status: 'COMPLETED';\n timeCompleted: string;\n report: Object;\n categories: Record<LighthouseCategoryId, LighthouseCategoryAbbr>;\n}\n\n/** @public */\nexport type Audit = AuditRunning | AuditFailed | AuditCompleted;\n\n/** @public */\nexport interface Website {\n url: string;\n audits: Audit[];\n lastAudit: Audit;\n}\n\n/** @public */\nexport type WebsiteListResponse = LASListResponse<Website>;\n\n/** @public */\nexport type FormFactor = 'mobile' | 'desktop';\n\n/** @public */\nexport type LighthouseConfigSettings = {\n // For lighthouse 7+\n formFactor: FormFactor;\n screenEmulation:\n | {\n mobile: boolean;\n width: number;\n height: number;\n deviceScaleFactor: number;\n disabled: boolean;\n }\n | undefined;\n // For lighthouse before 7\n emulatedFormFactor: FormFactor;\n};\n\n/** @public */\nexport interface TriggerAuditPayload {\n url: string;\n options: {\n lighthouseConfig: {\n settings: LighthouseConfigSettings;\n };\n };\n}\n\n/** @public */\nexport class FetchError extends Error {\n get name(): string {\n return this.constructor.name;\n }\n\n static async forResponse(resp: Response): Promise<FetchError> {\n return new FetchError(\n `Request failed with status code ${\n resp.status\n }.\\nReason: ${await resp.text()}`,\n );\n }\n}\n\n/** @public */\nexport type LighthouseApi = {\n url: string;\n getWebsiteList: (listOptions: LASListRequest) => Promise<WebsiteListResponse>;\n getWebsiteForAuditId: (auditId: string) => Promise<Website>;\n triggerAudit: (payload: TriggerAuditPayload) => Promise<Audit>;\n getWebsiteByUrl: (websiteUrl: string) => Promise<Website>;\n};\n\n/** @public */\nexport class LighthouseRestApi implements LighthouseApi {\n static fromConfig(config: Config) {\n return new LighthouseRestApi(config.getString('lighthouse.baseUrl'));\n }\n\n constructor(public url: string) {}\n\n private async fetch<T = any>(input: string, init?: RequestInit): Promise<T> {\n const resp = await fetch(`${this.url}${input}`, init);\n if (!resp.ok) throw await FetchError.forResponse(resp);\n return await resp.json();\n }\n\n async getWebsiteList(\n options: LASListRequest = {},\n ): Promise<WebsiteListResponse> {\n const { limit, offset } = options;\n const params = new URLSearchParams();\n if (typeof limit === 'number') params.append('limit', limit.toString());\n if (typeof offset === 'number') params.append('offset', offset.toString());\n return await this.fetch<WebsiteListResponse>(\n `/v1/websites?${params.toString()}`,\n );\n }\n\n async getWebsiteForAuditId(auditId: string): Promise<Website> {\n return await this.fetch<Website>(\n `/v1/audits/${encodeURIComponent(auditId)}/website`,\n );\n }\n\n async triggerAudit(payload: TriggerAuditPayload): Promise<Audit> {\n return await this.fetch<Audit>('/v1/audits', {\n method: 'POST',\n body: JSON.stringify(payload),\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n }\n\n async getWebsiteByUrl(websiteUrl: string): Promise<Website> {\n return this.fetch<Website>(\n `/v1/websites/${encodeURIComponent(websiteUrl)}`,\n );\n }\n}\n"],"names":[],"mappings":"AAqHO,MAAM,mBAAmB,KAAM,CAAA;AAAA,EACpC,IAAI,IAAe,GAAA;AACjB,IAAA,OAAO,KAAK,WAAY,CAAA,IAAA,CAAA;AAAA,GAC1B;AAAA,EAEA,aAAa,YAAY,IAAqC,EAAA;AAC5D,IAAA,OAAO,IAAI,UAAA;AAAA,MACT,CAAA,gCAAA,EACE,KAAK,MACP,CAAA;AAAA,QAAc,EAAA,MAAM,IAAK,CAAA,IAAA,EAAM,C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AA,EAEA,MAAM,qBAAqB,OAAmC,EAAA;AAC5D,IAAA,OAAO,MAAM,IAAK,CAAA,KAAA;AAAA,MAChB,CAAA,WAAA,EAAc,kBAAmB,CAAA,OAAO,CAAC,CAAA,QAAA,CAAA;AAAA,KAC3C,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,aAAa,OAA8C,EAAA;AAC/D,IAAO,OAAA,MAAM,IAAK,CAAA,KAAA,CAAa,YAAc,EAAA;AAAA,MAC3C,MAAQ,EAAA,MAAA;AAAA,MACR,IAAA,EAAM,IAAK,CAAA,SAAA,CAAU,OAAO,CAAA;AAAA,MAC5B,OAAS,EAAA;AAAA,QACP,cAAgB,EAAA,kBAAA;AAAA,OAClB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAM,gBAAgB,UAAsC,EAAA;AAC1D,IAAA,OAAO,IAAK,CAAA,KAAA;AAAA,MACV,CAAA,aAAA,EAAgB,kBAAmB,CAAA,UAAU,CAAC,CAAA,CAAA;AAAA,KAChD,CAAA;AAAA,GACF;AACF;;;;"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@backstage-community/plugin-lighthouse-common",
3
+ "version": "0.1.6",
4
+ "description": "Common functionalities for lighthouse, to be shared between lighthouse and lighthouse-backend plugin",
5
+ "backstage": {
6
+ "role": "common-library"
7
+ },
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "main": "dist/index.cjs.js",
11
+ "module": "dist/index.esm.js",
12
+ "types": "dist/index.d.ts"
13
+ },
14
+ "keywords": [
15
+ "lighthouse"
16
+ ],
17
+ "homepage": "https://backstage.io",
18
+ "bugs": {
19
+ "url": "https://github.com/backstage/backstage/issues"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/backstage/community-plugins",
24
+ "directory": "workspaces/lighthouse/plugins/lighthouse-common"
25
+ },
26
+ "license": "Apache-2.0",
27
+ "sideEffects": false,
28
+ "main": "dist/index.cjs.js",
29
+ "types": "dist/index.d.ts",
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "scripts": {
34
+ "build": "backstage-cli package build",
35
+ "clean": "backstage-cli package clean",
36
+ "lint": "backstage-cli package lint",
37
+ "prepack": "backstage-cli package prepack",
38
+ "postpack": "backstage-cli package postpack",
39
+ "test": "backstage-cli package test"
40
+ },
41
+ "dependencies": {
42
+ "@backstage/config": "^1.2.0"
43
+ },
44
+ "devDependencies": {
45
+ "@backstage/cli": "^0.26.3"
46
+ },
47
+ "module": "dist/index.esm.js"
48
+ }