@backstage/backend-dev-utils 0.1.4 → 0.1.6-next.0
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 +12 -0
- package/dist/DevDataStore.cjs.js +59 -0
- package/dist/DevDataStore.cjs.js.map +1 -0
- package/dist/index.cjs.js +2 -171
- package/dist/index.cjs.js.map +1 -1
- package/dist/ipcClient.cjs.js +78 -0
- package/dist/ipcClient.cjs.js.map +1 -0
- package/package.json +22 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @backstage/backend-dev-utils
|
|
2
2
|
|
|
3
|
+
## 0.1.6-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2bae83a: Internal update for Node.js v24 support.
|
|
8
|
+
|
|
9
|
+
## 0.1.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3a35172: Fix `EventEmitter` memory leak in the development utilities
|
|
14
|
+
|
|
3
15
|
## 0.1.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ipcClient = require('./ipcClient.cjs.js');
|
|
4
|
+
|
|
5
|
+
class DevDataStore {
|
|
6
|
+
static #instance;
|
|
7
|
+
/**
|
|
8
|
+
* Tries to acquire a DevDataStore instance. This will only succeed when the backend
|
|
9
|
+
* process is being run through the `@backstage/cli` in development mode.
|
|
10
|
+
*
|
|
11
|
+
* @returns A DevDataStore instance, or undefined if not available.
|
|
12
|
+
*/
|
|
13
|
+
static get() {
|
|
14
|
+
if (ipcClient.ipcClient) {
|
|
15
|
+
if (!this.#instance) {
|
|
16
|
+
this.#instance = new DevDataStore(ipcClient.ipcClient);
|
|
17
|
+
}
|
|
18
|
+
return this.#instance;
|
|
19
|
+
}
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
/** @internal */
|
|
23
|
+
static forTest(client) {
|
|
24
|
+
return new DevDataStore(client);
|
|
25
|
+
}
|
|
26
|
+
#client;
|
|
27
|
+
constructor(client) {
|
|
28
|
+
this.#client = client;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Save data to the data store.
|
|
32
|
+
*
|
|
33
|
+
* @param key - The key used to identify the data.
|
|
34
|
+
* @param data - The data to save. The data will be serialized using advanced IPC serialization.
|
|
35
|
+
* @returns A promise that resolves to a result object that indicates whether the data was saved.
|
|
36
|
+
*/
|
|
37
|
+
async save(key, data) {
|
|
38
|
+
return this.#client.request(
|
|
39
|
+
"DevDataStore.save",
|
|
40
|
+
{ key, data }
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Loads data from the data store.
|
|
45
|
+
*
|
|
46
|
+
* @param key - The key used to identify the data.
|
|
47
|
+
* @returns A promise that resolves to a result object that indicates whether the data was loaded, as well as the data.
|
|
48
|
+
*/
|
|
49
|
+
async load(key) {
|
|
50
|
+
const result = await this.#client.request(
|
|
51
|
+
"DevDataStore.load",
|
|
52
|
+
{ key }
|
|
53
|
+
);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.DevDataStore = DevDataStore;
|
|
59
|
+
//# sourceMappingURL=DevDataStore.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DevDataStore.cjs.js","sources":["../src/DevDataStore.ts"],"sourcesContent":["/*\n * Copyright 2023 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 { BackstageIpcClient, ipcClient } from './ipcClient';\n\ninterface SaveRequest {\n key: string;\n data: unknown;\n}\n\ninterface SaveResponse {\n saved: boolean;\n}\n\ninterface LoadRequest {\n key: string;\n}\n\ninterface LoadResponse {\n loaded: boolean;\n data: unknown;\n}\n\n/**\n * A data store that can be used to store temporary data during development.\n *\n * @public\n */\nexport class DevDataStore {\n static #instance?: DevDataStore;\n\n /**\n * Tries to acquire a DevDataStore instance. This will only succeed when the backend\n * process is being run through the `@backstage/cli` in development mode.\n *\n * @returns A DevDataStore instance, or undefined if not available.\n */\n static get(): DevDataStore | undefined {\n if (ipcClient) {\n if (!this.#instance) {\n this.#instance = new DevDataStore(ipcClient);\n }\n return this.#instance;\n }\n return undefined;\n }\n\n /** @internal */\n static forTest(client: Pick<BackstageIpcClient, 'request'>): DevDataStore {\n return new DevDataStore(client as BackstageIpcClient);\n }\n\n #client: BackstageIpcClient;\n\n private constructor(client: BackstageIpcClient) {\n this.#client = client;\n }\n\n /**\n * Save data to the data store.\n *\n * @param key - The key used to identify the data.\n * @param data - The data to save. The data will be serialized using advanced IPC serialization.\n * @returns A promise that resolves to a result object that indicates whether the data was saved.\n */\n async save<T>(key: string, data: T): Promise<{ saved: boolean }> {\n return this.#client.request<SaveRequest, SaveResponse>(\n 'DevDataStore.save',\n { key, data },\n );\n }\n\n /**\n * Loads data from the data store.\n *\n * @param key - The key used to identify the data.\n * @returns A promise that resolves to a result object that indicates whether the data was loaded, as well as the data.\n */\n async load<T>(key: string): Promise<{ loaded: boolean; data: T }> {\n const result = await this.#client.request<LoadRequest, LoadResponse>(\n 'DevDataStore.load',\n { key },\n );\n return result as { loaded: boolean; data: T };\n }\n}\n"],"names":["ipcClient"],"mappings":";;;;AAyCO,MAAM,YAAA,CAAa;AAAA,EACxB,OAAO,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP,OAAO,GAAA,GAAgC;AACrC,IAAA,IAAIA,mBAAA,EAAW;AACb,MAAA,IAAI,CAAC,KAAK,SAAA,EAAW;AACnB,QAAA,IAAA,CAAK,SAAA,GAAY,IAAI,YAAA,CAAaA,mBAAS,CAAA;AAAA,MAC7C;AACA,MAAA,OAAO,IAAA,CAAK,SAAA;AAAA,IACd;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AAAA;AAAA,EAGA,OAAO,QAAQ,MAAA,EAA2D;AACxE,IAAA,OAAO,IAAI,aAAa,MAA4B,CAAA;AAAA,EACtD;AAAA,EAEA,OAAA;AAAA,EAEQ,YAAY,MAAA,EAA4B;AAC9C,IAAA,IAAA,CAAK,OAAA,GAAU,MAAA;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,IAAA,CAAQ,GAAA,EAAa,IAAA,EAAsC;AAC/D,IAAA,OAAO,KAAK,OAAA,CAAQ,OAAA;AAAA,MAClB,mBAAA;AAAA,MACA,EAAE,KAAK,IAAA;AAAK,KACd;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,KAAQ,GAAA,EAAoD;AAChE,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,OAAA,CAAQ,OAAA;AAAA,MAChC,mBAAA;AAAA,MACA,EAAE,GAAA;AAAI,KACR;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,177 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var DevDataStore = require('./DevDataStore.cjs.js');
|
|
4
4
|
|
|
5
|
-
var __accessCheck$1 = (obj, member, msg) => {
|
|
6
|
-
if (!member.has(obj))
|
|
7
|
-
throw TypeError("Cannot " + msg);
|
|
8
|
-
};
|
|
9
|
-
var __privateGet$1 = (obj, member, getter) => {
|
|
10
|
-
__accessCheck$1(obj, member, "read from private field");
|
|
11
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
12
|
-
};
|
|
13
|
-
var __privateAdd$1 = (obj, member, value) => {
|
|
14
|
-
if (member.has(obj))
|
|
15
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
16
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
17
|
-
};
|
|
18
|
-
var __privateSet$1 = (obj, member, value, setter) => {
|
|
19
|
-
__accessCheck$1(obj, member, "write to private field");
|
|
20
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
|
-
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
24
|
-
set _(value) {
|
|
25
|
-
__privateSet$1(obj, member, value, setter);
|
|
26
|
-
},
|
|
27
|
-
get _() {
|
|
28
|
-
return __privateGet$1(obj, member, getter);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
var _messageId, _sendMessage;
|
|
32
|
-
const requestType = "@backstage/cli/channel/request";
|
|
33
|
-
const responseType = "@backstage/cli/channel/response";
|
|
34
|
-
const IPC_TIMEOUT_MS = 5e3;
|
|
35
|
-
const _BackstageIpcClient = class _BackstageIpcClient {
|
|
36
|
-
constructor(sendMessage) {
|
|
37
|
-
__privateAdd$1(this, _messageId, 0);
|
|
38
|
-
__privateAdd$1(this, _sendMessage, void 0);
|
|
39
|
-
__privateSet$1(this, _sendMessage, sendMessage);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Creates a new client if we're in a child process with IPC and BACKSTAGE_CLI_CHANNEL is set.
|
|
43
|
-
*/
|
|
44
|
-
static create() {
|
|
45
|
-
var _a;
|
|
46
|
-
const sendMessage = (_a = process.send) == null ? void 0 : _a.bind(process);
|
|
47
|
-
return sendMessage && process.env.BACKSTAGE_CLI_CHANNEL ? new _BackstageIpcClient(sendMessage) : void 0;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Send a request to the parent process and wait for a response.
|
|
51
|
-
*/
|
|
52
|
-
async request(method, body) {
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
const id = __privateWrapper(this, _messageId)._++;
|
|
55
|
-
const request = {
|
|
56
|
-
type: requestType,
|
|
57
|
-
id,
|
|
58
|
-
method,
|
|
59
|
-
body
|
|
60
|
-
};
|
|
61
|
-
let timeout = void 0;
|
|
62
|
-
const messageHandler = (response) => {
|
|
63
|
-
if ((response == null ? void 0 : response.type) !== responseType) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (response.id !== id) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
clearTimeout(timeout);
|
|
70
|
-
timeout = void 0;
|
|
71
|
-
process.removeListener("message", messageHandler);
|
|
72
|
-
if ("error" in response) {
|
|
73
|
-
const error = new Error(response.error.message);
|
|
74
|
-
if (response.error.name) {
|
|
75
|
-
error.name = response.error.name;
|
|
76
|
-
}
|
|
77
|
-
reject(error);
|
|
78
|
-
} else {
|
|
79
|
-
resolve(response.body);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
timeout = setTimeout(() => {
|
|
83
|
-
reject(new Error(`IPC request '${method}' with ID ${id} timed out`));
|
|
84
|
-
process.removeListener("message", messageHandler);
|
|
85
|
-
}, IPC_TIMEOUT_MS);
|
|
86
|
-
timeout.unref();
|
|
87
|
-
process.addListener("message", messageHandler);
|
|
88
|
-
__privateGet$1(this, _sendMessage).call(this, request, (e) => {
|
|
89
|
-
if (e) {
|
|
90
|
-
reject(e);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
_messageId = new WeakMap();
|
|
97
|
-
_sendMessage = new WeakMap();
|
|
98
|
-
let BackstageIpcClient = _BackstageIpcClient;
|
|
99
|
-
const ipcClient = BackstageIpcClient.create();
|
|
100
5
|
|
|
101
|
-
var __accessCheck = (obj, member, msg) => {
|
|
102
|
-
if (!member.has(obj))
|
|
103
|
-
throw TypeError("Cannot " + msg);
|
|
104
|
-
};
|
|
105
|
-
var __privateGet = (obj, member, getter) => {
|
|
106
|
-
__accessCheck(obj, member, "read from private field");
|
|
107
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
108
|
-
};
|
|
109
|
-
var __privateAdd = (obj, member, value) => {
|
|
110
|
-
if (member.has(obj))
|
|
111
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
112
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
113
|
-
};
|
|
114
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
115
|
-
__accessCheck(obj, member, "write to private field");
|
|
116
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
117
|
-
return value;
|
|
118
|
-
};
|
|
119
|
-
var _instance, _client;
|
|
120
|
-
const _DevDataStore = class _DevDataStore {
|
|
121
|
-
constructor(client) {
|
|
122
|
-
__privateAdd(this, _client, void 0);
|
|
123
|
-
__privateSet(this, _client, client);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Tries to acquire a DevDataStore instance. This will only succeed when the backend
|
|
127
|
-
* process is being run through the `@backstage/cli` in development mode.
|
|
128
|
-
*
|
|
129
|
-
* @returns A DevDataStore instance, or undefined if not available.
|
|
130
|
-
*/
|
|
131
|
-
static get() {
|
|
132
|
-
if (ipcClient) {
|
|
133
|
-
if (!__privateGet(this, _instance)) {
|
|
134
|
-
__privateSet(this, _instance, new _DevDataStore(ipcClient));
|
|
135
|
-
}
|
|
136
|
-
return __privateGet(this, _instance);
|
|
137
|
-
}
|
|
138
|
-
return void 0;
|
|
139
|
-
}
|
|
140
|
-
/** @internal */
|
|
141
|
-
static forTest(client) {
|
|
142
|
-
return new _DevDataStore(client);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Save data to the data store.
|
|
146
|
-
*
|
|
147
|
-
* @param key - The key used to identify the data.
|
|
148
|
-
* @param data - The data to save. The data will be serialized using advanced IPC serialization.
|
|
149
|
-
* @returns A promise that resolves to a result object that indicates whether the data was saved.
|
|
150
|
-
*/
|
|
151
|
-
async save(key, data) {
|
|
152
|
-
return __privateGet(this, _client).request(
|
|
153
|
-
"DevDataStore.save",
|
|
154
|
-
{ key, data }
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Loads data from the data store.
|
|
159
|
-
*
|
|
160
|
-
* @param key - The key used to identify the data.
|
|
161
|
-
* @returns A promise that resolves to a result object that indicates whether the data was loaded, as well as the data.
|
|
162
|
-
*/
|
|
163
|
-
async load(key) {
|
|
164
|
-
const result = await __privateGet(this, _client).request(
|
|
165
|
-
"DevDataStore.load",
|
|
166
|
-
{ key }
|
|
167
|
-
);
|
|
168
|
-
return result;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
_instance = new WeakMap();
|
|
172
|
-
_client = new WeakMap();
|
|
173
|
-
__privateAdd(_DevDataStore, _instance, void 0);
|
|
174
|
-
let DevDataStore = _DevDataStore;
|
|
175
6
|
|
|
176
|
-
exports.DevDataStore = DevDataStore;
|
|
7
|
+
exports.DevDataStore = DevDataStore.DevDataStore;
|
|
177
8
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const requestType = "@backstage/cli/channel/request";
|
|
4
|
+
const responseType = "@backstage/cli/channel/response";
|
|
5
|
+
const IPC_TIMEOUT_MS = 5e3;
|
|
6
|
+
class BackstageIpcClient {
|
|
7
|
+
#messageId = 0;
|
|
8
|
+
#sendMessage;
|
|
9
|
+
#handlers = /* @__PURE__ */ new Map();
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new client if we're in a child process with IPC and BACKSTAGE_CLI_CHANNEL is set.
|
|
12
|
+
*/
|
|
13
|
+
static create() {
|
|
14
|
+
const sendMessage = process.send?.bind(process);
|
|
15
|
+
const client = sendMessage && process.env.BACKSTAGE_CLI_CHANNEL ? new BackstageIpcClient(sendMessage) : void 0;
|
|
16
|
+
if (client) {
|
|
17
|
+
process.on(
|
|
18
|
+
"message",
|
|
19
|
+
(message, _sendHandle) => client.handleMessage(message, _sendHandle)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return client;
|
|
23
|
+
}
|
|
24
|
+
constructor(sendMessage) {
|
|
25
|
+
this.#sendMessage = sendMessage;
|
|
26
|
+
}
|
|
27
|
+
handleMessage(message, _sendHandle) {
|
|
28
|
+
const isResponse = (msg) => msg?.type === responseType;
|
|
29
|
+
if (isResponse(message)) {
|
|
30
|
+
this.#handlers.get(message.id)?.(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Send a request to the parent process and wait for a response.
|
|
35
|
+
*/
|
|
36
|
+
async request(method, body) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const id = this.#messageId++;
|
|
39
|
+
const request = {
|
|
40
|
+
type: requestType,
|
|
41
|
+
id,
|
|
42
|
+
method,
|
|
43
|
+
body
|
|
44
|
+
};
|
|
45
|
+
let timeout = void 0;
|
|
46
|
+
const responseHandler = (response) => {
|
|
47
|
+
clearTimeout(timeout);
|
|
48
|
+
timeout = void 0;
|
|
49
|
+
this.#handlers.delete(id);
|
|
50
|
+
if ("error" in response) {
|
|
51
|
+
const error = new Error(response.error.message);
|
|
52
|
+
if (response.error.name) {
|
|
53
|
+
error.name = response.error.name;
|
|
54
|
+
}
|
|
55
|
+
reject(error);
|
|
56
|
+
} else {
|
|
57
|
+
resolve(response.body);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
timeout = setTimeout(() => {
|
|
61
|
+
reject(new Error(`IPC request '${method}' with ID ${id} timed out`));
|
|
62
|
+
this.#handlers.delete(id);
|
|
63
|
+
}, IPC_TIMEOUT_MS);
|
|
64
|
+
timeout.unref();
|
|
65
|
+
this.#handlers.set(id, responseHandler);
|
|
66
|
+
this.#sendMessage(request, void 0, void 0, (e) => {
|
|
67
|
+
if (e) {
|
|
68
|
+
reject(e);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const ipcClient = BackstageIpcClient.create();
|
|
75
|
+
|
|
76
|
+
exports.BackstageIpcClient = BackstageIpcClient;
|
|
77
|
+
exports.ipcClient = ipcClient;
|
|
78
|
+
//# sourceMappingURL=ipcClient.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipcClient.cjs.js","sources":["../src/ipcClient.ts"],"sourcesContent":["/*\n * Copyright 2023 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\ntype SendMessage = Exclude<typeof process.send, undefined>;\n\ninterface Request {\n id: number;\n method: string;\n body: unknown;\n type: string;\n}\n\ntype Response =\n | {\n type: string;\n id: number;\n body: unknown;\n }\n | {\n type: string;\n id: number;\n error: Error;\n };\n\ntype ResponseHandler = (response: Response) => void;\n\nconst requestType = '@backstage/cli/channel/request';\nconst responseType = '@backstage/cli/channel/response';\n\nconst IPC_TIMEOUT_MS = 5000;\n\n/**\n * The client side of an IPC communication channel.\n *\n * @internal\n */\nexport class BackstageIpcClient {\n #messageId = 0;\n #sendMessage: SendMessage;\n #handlers: Map<number, ResponseHandler> = new Map();\n\n /**\n * Creates a new client if we're in a child process with IPC and BACKSTAGE_CLI_CHANNEL is set.\n */\n static create(): BackstageIpcClient | undefined {\n const sendMessage = process.send?.bind(process);\n const client =\n sendMessage && process.env.BACKSTAGE_CLI_CHANNEL\n ? new BackstageIpcClient(sendMessage)\n : undefined;\n\n if (client) {\n process.on('message', (message, _sendHandle) =>\n client.handleMessage(message, _sendHandle),\n );\n }\n\n return client;\n }\n\n constructor(sendMessage: SendMessage) {\n this.#sendMessage = sendMessage;\n }\n\n private handleMessage(message: unknown, _sendHandle: unknown) {\n const isResponse = (msg: unknown): msg is Response =>\n (msg as Response)?.type === responseType;\n\n if (isResponse(message)) {\n this.#handlers.get(message.id)?.(message);\n }\n }\n\n /**\n * Send a request to the parent process and wait for a response.\n */\n async request<TRequestBody, TResponseBody>(\n method: string,\n body: TRequestBody,\n ): Promise<TResponseBody> {\n return new Promise((resolve, reject) => {\n const id = this.#messageId++;\n\n const request: Request = {\n type: requestType,\n id,\n method,\n body,\n };\n\n let timeout: NodeJS.Timeout | undefined = undefined;\n\n const responseHandler: ResponseHandler = (response: Response) => {\n clearTimeout(timeout);\n timeout = undefined;\n this.#handlers.delete(id);\n\n if ('error' in response) {\n const error = new Error(response.error.message);\n if (response.error.name) {\n error.name = response.error.name;\n }\n reject(error);\n } else {\n resolve(response.body as TResponseBody);\n }\n };\n\n timeout = setTimeout(() => {\n reject(new Error(`IPC request '${method}' with ID ${id} timed out`));\n this.#handlers.delete(id);\n }, IPC_TIMEOUT_MS);\n timeout.unref();\n\n this.#handlers.set(id, responseHandler);\n this.#sendMessage(request, undefined, undefined, (e: Error | null) => {\n if (e) {\n reject(e);\n }\n });\n });\n }\n}\n\nexport const ipcClient = BackstageIpcClient.create();\n"],"names":[],"mappings":";;AAuCA,MAAM,WAAA,GAAc,gCAAA;AACpB,MAAM,YAAA,GAAe,iCAAA;AAErB,MAAM,cAAA,GAAiB,GAAA;AAOhB,MAAM,kBAAA,CAAmB;AAAA,EAC9B,UAAA,GAAa,CAAA;AAAA,EACb,YAAA;AAAA,EACA,SAAA,uBAA8C,GAAA,EAA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|
5
|
-
|
|
6
|
-
|
|
3
|
+
"version": "0.1.6-next.0",
|
|
4
|
+
"backstage": {
|
|
5
|
+
"role": "node-library"
|
|
6
|
+
},
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public",
|
|
9
9
|
"main": "dist/index.cjs.js",
|
|
10
10
|
"types": "dist/index.d.ts"
|
|
11
11
|
},
|
|
12
|
-
"backstage": {
|
|
13
|
-
"role": "node-library"
|
|
14
|
-
},
|
|
15
12
|
"homepage": "https://backstage.io",
|
|
16
13
|
"repository": {
|
|
17
14
|
"type": "git",
|
|
18
15
|
"url": "https://github.com/backstage/backstage",
|
|
19
16
|
"directory": "packages/backend-dev-utils"
|
|
20
17
|
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"main": "dist/index.cjs.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
21
24
|
"scripts": {
|
|
22
|
-
"start": "backstage-cli package start",
|
|
23
25
|
"build": "backstage-cli package build",
|
|
24
|
-
"lint": "backstage-cli package lint",
|
|
25
|
-
"test": "backstage-cli package test",
|
|
26
26
|
"clean": "backstage-cli package clean",
|
|
27
|
+
"lint": "backstage-cli package lint",
|
|
27
28
|
"prepack": "backstage-cli package prepack",
|
|
28
|
-
"postpack": "backstage-cli package postpack"
|
|
29
|
+
"postpack": "backstage-cli package postpack",
|
|
30
|
+
"start": "backstage-cli package start",
|
|
31
|
+
"test": "backstage-cli package test"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
31
|
-
"@backstage/cli": "
|
|
34
|
+
"@backstage/cli": "0.35.0-next.2"
|
|
32
35
|
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
+
"typesVersions": {
|
|
37
|
+
"*": {
|
|
38
|
+
"package.json": [
|
|
39
|
+
"package.json"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
36
43
|
}
|