@bubblydoo/uxp-devtools-common 0.0.3
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/dist/index.d.ts +17 -0
- package/dist/index.js +225 -0
- package/dist/index.js.map +1 -0
- package/dist/setup-devtools-url.d.ts +9 -0
- package/dist/setup-devtools-url.js +171 -0
- package/dist/setup-devtools-url.js.map +1 -0
- package/dist/uxp-logger.d.ts +8 -0
- package/dist/uxp-logger.js +10 -0
- package/dist/uxp-logger.js.map +1 -0
- package/fake-plugin/index.html +10 -0
- package/fake-plugin/manifest.json +121 -0
- package/package.json +44 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import CDP from 'chrome-remote-interface';
|
|
2
|
+
export { DevtoolsConnection, setupDevtoolsConnection } from './setup-devtools-url.js';
|
|
3
|
+
export { setGlobalUxpLogger } from './uxp-logger.js';
|
|
4
|
+
import '@adobe-fixed-uxp/uxp-devtools-core/core/common/Logger';
|
|
5
|
+
|
|
6
|
+
declare function setupCdpSession(cdtUrl: string): Promise<CDP.Client>;
|
|
7
|
+
interface ExecutionContextDescription {
|
|
8
|
+
id: number;
|
|
9
|
+
origin: string;
|
|
10
|
+
name: string;
|
|
11
|
+
uniqueId: string;
|
|
12
|
+
}
|
|
13
|
+
declare function waitForExecutionContextCreated(cdp: CDP.Client, runAfterListenerAttached?: () => Promise<void>): Promise<ExecutionContextDescription>;
|
|
14
|
+
|
|
15
|
+
declare function setupCdpSessionWithUxpDefaults(cdp: CDP.Client): Promise<void>;
|
|
16
|
+
|
|
17
|
+
export { setupCdpSession, setupCdpSessionWithUxpDefaults, waitForExecutionContextCreated };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import CDP from 'chrome-remote-interface';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import AppClient from '@adobe-fixed-uxp/uxp-devtools-core/core/service/clients/AppClient';
|
|
5
|
+
import Server from '@adobe-fixed-uxp/uxp-devtools-core/core/service/Server';
|
|
6
|
+
import DevToolsHelper from '@adobe-fixed-uxp/uxp-devtools-helper';
|
|
7
|
+
import z from 'zod';
|
|
8
|
+
import { Logger } from '@adobe-fixed-uxp/uxp-devtools-core/core/common/Logger';
|
|
9
|
+
|
|
10
|
+
// src/cdp-session.ts
|
|
11
|
+
async function setupCdpSession(cdtUrl) {
|
|
12
|
+
const uuid = crypto.randomUUID();
|
|
13
|
+
const cdp = await CDP({
|
|
14
|
+
useHostName: false,
|
|
15
|
+
local: true,
|
|
16
|
+
target: {
|
|
17
|
+
description: "CDT",
|
|
18
|
+
devtoolsFrontendUrl: null,
|
|
19
|
+
id: `cdt-${uuid}`,
|
|
20
|
+
title: "CDT",
|
|
21
|
+
type: "page",
|
|
22
|
+
url: "about:blank",
|
|
23
|
+
webSocketDebuggerUrl: cdtUrl
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return cdp;
|
|
27
|
+
}
|
|
28
|
+
async function waitForExecutionContextCreated(cdp, runAfterListenerAttached) {
|
|
29
|
+
const executionContextCreatedPromise = new Promise((resolve) => {
|
|
30
|
+
cdp.Runtime.on("executionContextCreated", (event) => {
|
|
31
|
+
resolve(event.context);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
if (runAfterListenerAttached) {
|
|
35
|
+
await runAfterListenerAttached();
|
|
36
|
+
}
|
|
37
|
+
return executionContextCreatedPromise;
|
|
38
|
+
}
|
|
39
|
+
function setGlobalUxpLogger() {
|
|
40
|
+
globalThis.UxpLogger = new Logger();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/setup-devtools-url.ts
|
|
44
|
+
Error.stackTraceLimit = Infinity;
|
|
45
|
+
setGlobalUxpLogger();
|
|
46
|
+
var DEFAULT_PORTS = [14001, 14002, 14003, 14004, 14005, 14006, 14007, 14008, 14009, 14010];
|
|
47
|
+
var loadReplySchema = z.object({
|
|
48
|
+
command: z.literal("reply"),
|
|
49
|
+
pluginSessionId: z.string(),
|
|
50
|
+
breakOnStart: z.boolean(),
|
|
51
|
+
requestId: z.number()
|
|
52
|
+
});
|
|
53
|
+
var validateReplySchema = z.object({
|
|
54
|
+
command: z.literal("reply"),
|
|
55
|
+
requestId: z.number(),
|
|
56
|
+
success: z.boolean()
|
|
57
|
+
});
|
|
58
|
+
var debugReplySchema = z.object({
|
|
59
|
+
command: z.literal("reply"),
|
|
60
|
+
wsdebugUrl: z.string(),
|
|
61
|
+
chromeDevToolsUrl: z.string()
|
|
62
|
+
});
|
|
63
|
+
async function fileExists(path2) {
|
|
64
|
+
try {
|
|
65
|
+
await fs.access(path2);
|
|
66
|
+
return true;
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function setupDevtoolsConnection(pluginPath, ports = DEFAULT_PORTS) {
|
|
72
|
+
if (!path.isAbsolute(pluginPath)) {
|
|
73
|
+
throw new Error("pluginPath must be an absolute path");
|
|
74
|
+
}
|
|
75
|
+
const manifestPath = path.join(pluginPath, "manifest.json");
|
|
76
|
+
if (!await fileExists(manifestPath)) {
|
|
77
|
+
throw new Error("manifest.json not found");
|
|
78
|
+
}
|
|
79
|
+
const devtoolsManager = new DevToolsHelper(true);
|
|
80
|
+
const appsList = devtoolsManager.getAppsList();
|
|
81
|
+
const isPsOpen = appsList.some((app) => app.appId === "PS");
|
|
82
|
+
if (!isPsOpen) {
|
|
83
|
+
throw new Error("Photoshop is not open");
|
|
84
|
+
}
|
|
85
|
+
const PORT = ports[Math.floor(Math.random() * ports.length)];
|
|
86
|
+
const server = new Server(PORT);
|
|
87
|
+
server.run();
|
|
88
|
+
devtoolsManager.setServerDetails(PORT);
|
|
89
|
+
console.log("port", PORT);
|
|
90
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
91
|
+
const psClient = server.clients.values().next().value;
|
|
92
|
+
if (!psClient) {
|
|
93
|
+
throw new Error("No PS client found");
|
|
94
|
+
}
|
|
95
|
+
if (!(psClient instanceof AppClient)) {
|
|
96
|
+
throw new TypeError("PS client is not an AppClient");
|
|
97
|
+
}
|
|
98
|
+
function callPluginHandler(psClient2, message, schema) {
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
psClient2.handler_Plugin(message, (error, response) => {
|
|
101
|
+
if (response?.error) {
|
|
102
|
+
reject(new Error(response.error));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (error) {
|
|
106
|
+
reject(error);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
console.log("response for", message.action, response);
|
|
110
|
+
resolve(schema.parse(response));
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const manifest = JSON.parse(await fs.readFile(manifestPath, "utf8"));
|
|
115
|
+
const pluginId = manifest.id;
|
|
116
|
+
const validateResult = await callPluginHandler(
|
|
117
|
+
psClient,
|
|
118
|
+
{
|
|
119
|
+
action: "validate",
|
|
120
|
+
command: "Plugin",
|
|
121
|
+
params: {
|
|
122
|
+
provider: {
|
|
123
|
+
type: "disk",
|
|
124
|
+
id: pluginId,
|
|
125
|
+
path: pluginPath
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
manifest
|
|
129
|
+
},
|
|
130
|
+
validateReplySchema
|
|
131
|
+
);
|
|
132
|
+
if (!validateResult.success) {
|
|
133
|
+
throw new Error("Validation failed");
|
|
134
|
+
}
|
|
135
|
+
const { pluginSessionId } = await callPluginHandler(
|
|
136
|
+
psClient,
|
|
137
|
+
{
|
|
138
|
+
action: "load",
|
|
139
|
+
command: "Plugin",
|
|
140
|
+
params: {
|
|
141
|
+
provider: {
|
|
142
|
+
type: "disk",
|
|
143
|
+
id: pluginId,
|
|
144
|
+
path: pluginPath
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
breakOnStart: false
|
|
148
|
+
},
|
|
149
|
+
loadReplySchema
|
|
150
|
+
);
|
|
151
|
+
const result = await callPluginHandler(
|
|
152
|
+
psClient,
|
|
153
|
+
{
|
|
154
|
+
action: "debug",
|
|
155
|
+
command: "Plugin",
|
|
156
|
+
pluginSessionId
|
|
157
|
+
},
|
|
158
|
+
debugReplySchema
|
|
159
|
+
);
|
|
160
|
+
const cdtUrl = result.wsdebugUrl.replace("ws=", "ws://");
|
|
161
|
+
const connection = {
|
|
162
|
+
url: cdtUrl,
|
|
163
|
+
teardown: async () => {
|
|
164
|
+
console.log("Tearing down devtools URL");
|
|
165
|
+
try {
|
|
166
|
+
await callPluginHandler(
|
|
167
|
+
psClient,
|
|
168
|
+
{
|
|
169
|
+
action: "unload",
|
|
170
|
+
command: "Plugin",
|
|
171
|
+
pluginSessionId
|
|
172
|
+
},
|
|
173
|
+
z.object({
|
|
174
|
+
command: z.literal("reply"),
|
|
175
|
+
requestId: z.number()
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
console.log("Plugin unloaded");
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error("Error unloading plugin:", error);
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
await server.close();
|
|
184
|
+
} catch (error) {
|
|
185
|
+
console.error("Error closing server:", error);
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
devtoolsManager.terminate();
|
|
189
|
+
console.log("DevToolsHelper terminated");
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.error("Error terminating DevToolsHelper:", error);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
return connection;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/uxp-cdp-defaults.ts
|
|
199
|
+
async function setupCdpSessionWithUxpDefaults(cdp) {
|
|
200
|
+
console.log("Setting up CDP defaults");
|
|
201
|
+
await cdp.Network.enable();
|
|
202
|
+
await cdp.Page.enable();
|
|
203
|
+
await cdp.Page.getResourceTree();
|
|
204
|
+
await cdp.Runtime.enable();
|
|
205
|
+
await cdp.DOM.enable();
|
|
206
|
+
await cdp.CSS.enable();
|
|
207
|
+
await cdp.Debugger.enable({ maxScriptsCacheSize: 1e7 });
|
|
208
|
+
await cdp.Debugger.setPauseOnExceptions({ state: "none" });
|
|
209
|
+
await cdp.Debugger.setAsyncCallStackDepth({ maxDepth: 32 });
|
|
210
|
+
await cdp.Overlay.enable();
|
|
211
|
+
await cdp.Overlay.setShowViewportSizeOnResize({ show: true });
|
|
212
|
+
await cdp.Profiler.enable();
|
|
213
|
+
await cdp.Log.enable();
|
|
214
|
+
await cdp.Target.setAutoAttach({
|
|
215
|
+
autoAttach: true,
|
|
216
|
+
waitForDebuggerOnStart: true,
|
|
217
|
+
flatten: true
|
|
218
|
+
});
|
|
219
|
+
await cdp.Debugger.setBlackboxPatterns({ patterns: [] });
|
|
220
|
+
await cdp.Runtime.runIfWaitingForDebugger();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export { setGlobalUxpLogger, setupCdpSession, setupCdpSessionWithUxpDefaults, setupDevtoolsConnection, waitForExecutionContextCreated };
|
|
224
|
+
//# sourceMappingURL=index.js.map
|
|
225
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cdp-session.ts","../src/uxp-logger.ts","../src/setup-devtools-url.ts","../src/uxp-cdp-defaults.ts"],"names":["path","psClient"],"mappings":";;;;;;;;;;AAEA,eAAsB,gBAAgB,MAAA,EAAgB;AACpD,EAAA,MAAM,IAAA,GAAO,OAAO,UAAA,EAAW;AAE/B,EAAA,MAAM,GAAA,GAAM,MAAM,GAAA,CAAI;AAAA,IACpB,WAAA,EAAa,KAAA;AAAA,IACb,KAAA,EAAO,IAAA;AAAA,IACP,MAAA,EAAQ;AAAA,MACN,WAAA,EAAa,KAAA;AAAA,MACb,mBAAA,EAAqB,IAAA;AAAA,MACrB,EAAA,EAAI,OAAO,IAAI,CAAA,CAAA;AAAA,MACf,KAAA,EAAO,KAAA;AAAA,MACP,IA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AAO;AACrB,EAAA,MAAM,GAAA,CAAI,IAAI,MAAA,EAAO;AACrB,EAAA,MAAM,IAAI,QAAA,CAAS,MAAA,CAAO,EAAE,mBAAA,EAAqB,KAAU,CAAA;AAC3D,EAAA,MAAM,IAAI,QAAA,CAAS,oBAAA,CAAqB,EAAE,KAAA,EAAO,QAAQ,CAAA;AACzD,EAAA,MAAM,IAAI,QAAA,CAAS,sBAAA,CAAuB,EAAE,QAAA,EAAU,IAAI,CAAA;AAC1D,EAAA,MAAM,GAAA,CAAI,QAAQ,MAAA,EAAO;AACzB,EAAA,MAAM,IAAI,OAAA,CAAQ,2BAAA,CAA4B,EAAE,IAAA,EAAM,MAAM,CAAA;AAC5D,EAAA,MAAM,GAAA,CAAI,SAAS,MAAA,EAAO;AAC1B,EAAA,MAAM,GAAA,CAAI,IAAI,MAAA,EAAO;AACrB,EAAA,MAAM,GAAA,CAAI,OAAO,aAAA,CAAc;AAAA,IAC7B,UAAA,EAAY,IAAA;AAAA,IACZ,sBAAA,EAAwB,IAAA;AAAA,IACxB,OAAA,EAAS;AAAA,GACV,CAAA;AACD,EAAA,MAAM,IAAI,QAAA,CAAS,mBAAA,CAAoB,EAAE,QAAA,EAAU,IAAI,CAAA;AACvD,EAAA,MAAM,GAAA,CAAI,QAAQ,uBAAA,EAAwB;AAC5C","file":"index.js","sourcesContent":["import CDP from 'chrome-remote-interface';\n\nexport async function setupCdpSession(cdtUrl: string) {\n const uuid = crypto.randomUUID();\n\n const cdp = await CDP({\n useHostName: false,\n local: true,\n target: {\n description: 'CDT',\n devtoolsFrontendUrl: null!,\n id: `cdt-${uuid}`,\n title: 'CDT',\n type: 'page',\n url: 'about:blank',\n webSocketDebuggerUrl: cdtUrl,\n },\n });\n\n return cdp;\n}\n\ninterface ExecutionContextDescription {\n id: number;\n origin: string;\n name: string;\n uniqueId: string;\n}\n\nexport async function waitForExecutionContextCreated(cdp: CDP.Client, runAfterListenerAttached?: () => Promise<void>) {\n const executionContextCreatedPromise = new Promise<ExecutionContextDescription>((resolve) => {\n cdp.Runtime.on('executionContextCreated', (event) => {\n resolve(event.context);\n });\n });\n if (runAfterListenerAttached) {\n await runAfterListenerAttached();\n }\n return executionContextCreatedPromise;\n}\n","import { Logger } from '@adobe-fixed-uxp/uxp-devtools-core/core/common/Logger';\n\n/* eslint-disable vars-on-top */\ndeclare global {\n var UxpLogger: Logger;\n}\n\nexport function setGlobalUxpLogger() {\n globalThis.UxpLogger = new Logger();\n}\n","/* eslint-disable no-console */\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport AppClient from '@adobe-fixed-uxp/uxp-devtools-core/core/service/clients/AppClient';\nimport Server from '@adobe-fixed-uxp/uxp-devtools-core/core/service/Server';\nimport DevToolsHelper from '@adobe-fixed-uxp/uxp-devtools-helper';\nimport z from 'zod';\nimport { setGlobalUxpLogger } from './uxp-logger';\n\nError.stackTraceLimit = Infinity;\n\nsetGlobalUxpLogger();\n\nconst DEFAULT_PORTS = [14001, 14002, 14003, 14004, 14005, 14006, 14007, 14008, 14009, 14010];\n\nconst loadReplySchema = z.object({\n command: z.literal('reply'),\n pluginSessionId: z.string(),\n breakOnStart: z.boolean(),\n requestId: z.number(),\n});\n\nconst validateReplySchema = z.object({\n command: z.literal('reply'),\n requestId: z.number(),\n success: z.boolean(),\n});\n\nconst debugReplySchema = z.object({\n command: z.literal('reply'),\n wsdebugUrl: z.string(),\n chromeDevToolsUrl: z.string(),\n});\n\nasync function fileExists(path: string) {\n try {\n await fs.access(path);\n return true;\n }\n catch {\n return false;\n }\n}\n\nexport interface DevtoolsConnection {\n /** Debugger websocket URL */\n url: string;\n /** Unload the plugin and tear down the Vulcan connection */\n teardown: () => Promise<void>;\n}\n\nexport async function setupDevtoolsConnection(pluginPath: string, ports: number[] = DEFAULT_PORTS): Promise<DevtoolsConnection> {\n if (!path.isAbsolute(pluginPath)) {\n throw new Error('pluginPath must be an absolute path');\n }\n const manifestPath = path.join(pluginPath, 'manifest.json');\n if (!await fileExists(manifestPath)) {\n throw new Error('manifest.json not found');\n }\n\n const devtoolsManager = new DevToolsHelper(true);\n const appsList = devtoolsManager.getAppsList();\n\n const isPsOpen = appsList.some(app => app.appId === 'PS');\n if (!isPsOpen) {\n throw new Error('Photoshop is not open');\n }\n\n const PORT = ports[Math.floor(Math.random() * ports.length)]!;\n\n const server = new Server(PORT);\n server.run();\n\n // this goes through Adobe's Vulcan system, which is a binary black box\n devtoolsManager.setServerDetails(PORT);\n\n console.log('port', PORT);\n\n await new Promise(resolve => setTimeout(resolve, 1500));\n\n const psClient = server.clients.values().next().value;\n\n if (!psClient) {\n throw new Error('No PS client found');\n }\n\n if (!(psClient instanceof AppClient)) {\n throw new TypeError('PS client is not an AppClient');\n }\n\n // const discoverReplySchema = z.object({\n // command: z.literal('reply'),\n // pluginSessionId: z.string(),\n // breakOnStart: z.boolean(),\n // requestId: z.number(),\n // });\n\n /**\n * Helper to promisify handler_Plugin calls with error handling and schema validation\n */\n function callPluginHandler<T extends z.ZodTypeAny>(\n psClient: AppClient,\n message: Parameters<AppClient['handler_Plugin']>[0],\n schema: T,\n ): Promise<z.infer<T>> {\n return new Promise((resolve, reject) => {\n psClient.handler_Plugin(message, (error: Error | null, response: any) => {\n if (response?.error) {\n reject(new Error(response.error));\n return;\n }\n if (error) {\n reject(error);\n return;\n }\n console.log('response for', message.action, response);\n resolve(schema.parse(response));\n });\n });\n }\n\n const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n const pluginId = manifest.id;\n\n const validateResult = await callPluginHandler(\n psClient,\n {\n action: 'validate',\n command: 'Plugin',\n params: {\n provider: {\n type: 'disk',\n id: pluginId,\n path: pluginPath,\n },\n },\n manifest,\n },\n validateReplySchema,\n );\n\n if (!validateResult.success) {\n throw new Error('Validation failed');\n }\n\n const { pluginSessionId } = await callPluginHandler(\n psClient,\n {\n action: 'load',\n command: 'Plugin',\n params: {\n provider: {\n type: 'disk',\n id: pluginId,\n path: pluginPath,\n },\n },\n breakOnStart: false,\n },\n loadReplySchema,\n );\n\n const result = await callPluginHandler(\n psClient,\n {\n action: 'debug',\n command: 'Plugin',\n pluginSessionId,\n },\n debugReplySchema,\n );\n\n const cdtUrl = result.wsdebugUrl.replace('ws=', 'ws://');\n\n const connection: DevtoolsConnection = {\n url: cdtUrl,\n teardown: async () => {\n console.log('Tearing down devtools URL');\n // Unload the plugin from Photoshop\n try {\n await callPluginHandler(\n psClient,\n {\n action: 'unload',\n command: 'Plugin',\n pluginSessionId,\n },\n z.object({\n command: z.literal('reply'),\n requestId: z.number(),\n }),\n );\n console.log('Plugin unloaded');\n }\n catch (error) {\n console.error('Error unloading plugin:', error);\n }\n\n try {\n await server.close();\n }\n catch (error) {\n console.error('Error closing server:', error);\n }\n\n // Terminate the DevToolsHelper (Adobe Vulcan native library)\n // This is crucial to prevent hanging handles\n try {\n devtoolsManager.terminate();\n console.log('DevToolsHelper terminated');\n }\n catch (error) {\n console.error('Error terminating DevToolsHelper:', error);\n }\n },\n };\n\n return connection;\n}\n","import type CDP from 'chrome-remote-interface';\n\nexport async function setupCdpSessionWithUxpDefaults(cdp: CDP.Client) {\n // these were all copied from wireshark\n console.log('Setting up CDP defaults');\n await cdp.Network.enable();\n await cdp.Page.enable();\n await cdp.Page.getResourceTree();\n await cdp.Runtime.enable();\n await cdp.DOM.enable();\n await cdp.CSS.enable();\n await cdp.Debugger.enable({ maxScriptsCacheSize: 10000000 });\n await cdp.Debugger.setPauseOnExceptions({ state: 'none' });\n await cdp.Debugger.setAsyncCallStackDepth({ maxDepth: 32 });\n await cdp.Overlay.enable();\n await cdp.Overlay.setShowViewportSizeOnResize({ show: true });\n await cdp.Profiler.enable();\n await cdp.Log.enable();\n await cdp.Target.setAutoAttach({\n autoAttach: true,\n waitForDebuggerOnStart: true,\n flatten: true,\n });\n await cdp.Debugger.setBlackboxPatterns({ patterns: [] });\n await cdp.Runtime.runIfWaitingForDebugger();\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface DevtoolsConnection {
|
|
2
|
+
/** Debugger websocket URL */
|
|
3
|
+
url: string;
|
|
4
|
+
/** Unload the plugin and tear down the Vulcan connection */
|
|
5
|
+
teardown: () => Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
declare function setupDevtoolsConnection(pluginPath: string, ports?: number[]): Promise<DevtoolsConnection>;
|
|
8
|
+
|
|
9
|
+
export { type DevtoolsConnection, setupDevtoolsConnection };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import AppClient from '@adobe-fixed-uxp/uxp-devtools-core/core/service/clients/AppClient';
|
|
4
|
+
import Server from '@adobe-fixed-uxp/uxp-devtools-core/core/service/Server';
|
|
5
|
+
import DevToolsHelper from '@adobe-fixed-uxp/uxp-devtools-helper';
|
|
6
|
+
import z from 'zod';
|
|
7
|
+
import { Logger } from '@adobe-fixed-uxp/uxp-devtools-core/core/common/Logger';
|
|
8
|
+
|
|
9
|
+
// src/setup-devtools-url.ts
|
|
10
|
+
function setGlobalUxpLogger() {
|
|
11
|
+
globalThis.UxpLogger = new Logger();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/setup-devtools-url.ts
|
|
15
|
+
Error.stackTraceLimit = Infinity;
|
|
16
|
+
setGlobalUxpLogger();
|
|
17
|
+
var DEFAULT_PORTS = [14001, 14002, 14003, 14004, 14005, 14006, 14007, 14008, 14009, 14010];
|
|
18
|
+
var loadReplySchema = z.object({
|
|
19
|
+
command: z.literal("reply"),
|
|
20
|
+
pluginSessionId: z.string(),
|
|
21
|
+
breakOnStart: z.boolean(),
|
|
22
|
+
requestId: z.number()
|
|
23
|
+
});
|
|
24
|
+
var validateReplySchema = z.object({
|
|
25
|
+
command: z.literal("reply"),
|
|
26
|
+
requestId: z.number(),
|
|
27
|
+
success: z.boolean()
|
|
28
|
+
});
|
|
29
|
+
var debugReplySchema = z.object({
|
|
30
|
+
command: z.literal("reply"),
|
|
31
|
+
wsdebugUrl: z.string(),
|
|
32
|
+
chromeDevToolsUrl: z.string()
|
|
33
|
+
});
|
|
34
|
+
async function fileExists(path2) {
|
|
35
|
+
try {
|
|
36
|
+
await fs.access(path2);
|
|
37
|
+
return true;
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function setupDevtoolsConnection(pluginPath, ports = DEFAULT_PORTS) {
|
|
43
|
+
if (!path.isAbsolute(pluginPath)) {
|
|
44
|
+
throw new Error("pluginPath must be an absolute path");
|
|
45
|
+
}
|
|
46
|
+
const manifestPath = path.join(pluginPath, "manifest.json");
|
|
47
|
+
if (!await fileExists(manifestPath)) {
|
|
48
|
+
throw new Error("manifest.json not found");
|
|
49
|
+
}
|
|
50
|
+
const devtoolsManager = new DevToolsHelper(true);
|
|
51
|
+
const appsList = devtoolsManager.getAppsList();
|
|
52
|
+
const isPsOpen = appsList.some((app) => app.appId === "PS");
|
|
53
|
+
if (!isPsOpen) {
|
|
54
|
+
throw new Error("Photoshop is not open");
|
|
55
|
+
}
|
|
56
|
+
const PORT = ports[Math.floor(Math.random() * ports.length)];
|
|
57
|
+
const server = new Server(PORT);
|
|
58
|
+
server.run();
|
|
59
|
+
devtoolsManager.setServerDetails(PORT);
|
|
60
|
+
console.log("port", PORT);
|
|
61
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
62
|
+
const psClient = server.clients.values().next().value;
|
|
63
|
+
if (!psClient) {
|
|
64
|
+
throw new Error("No PS client found");
|
|
65
|
+
}
|
|
66
|
+
if (!(psClient instanceof AppClient)) {
|
|
67
|
+
throw new TypeError("PS client is not an AppClient");
|
|
68
|
+
}
|
|
69
|
+
function callPluginHandler(psClient2, message, schema) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
psClient2.handler_Plugin(message, (error, response) => {
|
|
72
|
+
if (response?.error) {
|
|
73
|
+
reject(new Error(response.error));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (error) {
|
|
77
|
+
reject(error);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
console.log("response for", message.action, response);
|
|
81
|
+
resolve(schema.parse(response));
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const manifest = JSON.parse(await fs.readFile(manifestPath, "utf8"));
|
|
86
|
+
const pluginId = manifest.id;
|
|
87
|
+
const validateResult = await callPluginHandler(
|
|
88
|
+
psClient,
|
|
89
|
+
{
|
|
90
|
+
action: "validate",
|
|
91
|
+
command: "Plugin",
|
|
92
|
+
params: {
|
|
93
|
+
provider: {
|
|
94
|
+
type: "disk",
|
|
95
|
+
id: pluginId,
|
|
96
|
+
path: pluginPath
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
manifest
|
|
100
|
+
},
|
|
101
|
+
validateReplySchema
|
|
102
|
+
);
|
|
103
|
+
if (!validateResult.success) {
|
|
104
|
+
throw new Error("Validation failed");
|
|
105
|
+
}
|
|
106
|
+
const { pluginSessionId } = await callPluginHandler(
|
|
107
|
+
psClient,
|
|
108
|
+
{
|
|
109
|
+
action: "load",
|
|
110
|
+
command: "Plugin",
|
|
111
|
+
params: {
|
|
112
|
+
provider: {
|
|
113
|
+
type: "disk",
|
|
114
|
+
id: pluginId,
|
|
115
|
+
path: pluginPath
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
breakOnStart: false
|
|
119
|
+
},
|
|
120
|
+
loadReplySchema
|
|
121
|
+
);
|
|
122
|
+
const result = await callPluginHandler(
|
|
123
|
+
psClient,
|
|
124
|
+
{
|
|
125
|
+
action: "debug",
|
|
126
|
+
command: "Plugin",
|
|
127
|
+
pluginSessionId
|
|
128
|
+
},
|
|
129
|
+
debugReplySchema
|
|
130
|
+
);
|
|
131
|
+
const cdtUrl = result.wsdebugUrl.replace("ws=", "ws://");
|
|
132
|
+
const connection = {
|
|
133
|
+
url: cdtUrl,
|
|
134
|
+
teardown: async () => {
|
|
135
|
+
console.log("Tearing down devtools URL");
|
|
136
|
+
try {
|
|
137
|
+
await callPluginHandler(
|
|
138
|
+
psClient,
|
|
139
|
+
{
|
|
140
|
+
action: "unload",
|
|
141
|
+
command: "Plugin",
|
|
142
|
+
pluginSessionId
|
|
143
|
+
},
|
|
144
|
+
z.object({
|
|
145
|
+
command: z.literal("reply"),
|
|
146
|
+
requestId: z.number()
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
console.log("Plugin unloaded");
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error("Error unloading plugin:", error);
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
await server.close();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error("Error closing server:", error);
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
devtoolsManager.terminate();
|
|
160
|
+
console.log("DevToolsHelper terminated");
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.error("Error terminating DevToolsHelper:", error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
return connection;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { setupDevtoolsConnection };
|
|
170
|
+
//# sourceMappingURL=setup-devtools-url.js.map
|
|
171
|
+
//# sourceMappingURL=setup-devtools-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/uxp-logger.ts","../src/setup-devtools-url.ts"],"names":["path","psClient"],"mappings":";;;;;;;;;AAOO,SAAS,kBAAA,GAAqB;AACnC,EAAA,UAAA,CAAW,SAAA,GAAY,IAAI,MAAA,EAAO;AACpC;;;ACAA,KAAA,CAAM,eAAA,GAAkB,QAAA;AAExB,kBAAA,EAAmB;AAEnB,IAAM,aAAA,GAAgB,CAAC,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAK,CAAA;AAE3F,IAAM,eAAA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,CAAA;AAAA,MAC1D;AAAA,IACF;AAAA,GACF;AAEA,EAAA,OAAO,UAAA;AACT","file":"setup-devtools-url.js","sourcesContent":["import { Logger } from '@adobe-fixed-uxp/uxp-devtools-core/core/common/Logger';\n\n/* eslint-disable vars-on-top */\ndeclare global {\n var UxpLogger: Logger;\n}\n\nexport function setGlobalUxpLogger() {\n globalThis.UxpLogger = new Logger();\n}\n","/* eslint-disable no-console */\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport AppClient from '@adobe-fixed-uxp/uxp-devtools-core/core/service/clients/AppClient';\nimport Server from '@adobe-fixed-uxp/uxp-devtools-core/core/service/Server';\nimport DevToolsHelper from '@adobe-fixed-uxp/uxp-devtools-helper';\nimport z from 'zod';\nimport { setGlobalUxpLogger } from './uxp-logger';\n\nError.stackTraceLimit = Infinity;\n\nsetGlobalUxpLogger();\n\nconst DEFAULT_PORTS = [14001, 14002, 14003, 14004, 14005, 14006, 14007, 14008, 14009, 14010];\n\nconst loadReplySchema = z.object({\n command: z.literal('reply'),\n pluginSessionId: z.string(),\n breakOnStart: z.boolean(),\n requestId: z.number(),\n});\n\nconst validateReplySchema = z.object({\n command: z.literal('reply'),\n requestId: z.number(),\n success: z.boolean(),\n});\n\nconst debugReplySchema = z.object({\n command: z.literal('reply'),\n wsdebugUrl: z.string(),\n chromeDevToolsUrl: z.string(),\n});\n\nasync function fileExists(path: string) {\n try {\n await fs.access(path);\n return true;\n }\n catch {\n return false;\n }\n}\n\nexport interface DevtoolsConnection {\n /** Debugger websocket URL */\n url: string;\n /** Unload the plugin and tear down the Vulcan connection */\n teardown: () => Promise<void>;\n}\n\nexport async function setupDevtoolsConnection(pluginPath: string, ports: number[] = DEFAULT_PORTS): Promise<DevtoolsConnection> {\n if (!path.isAbsolute(pluginPath)) {\n throw new Error('pluginPath must be an absolute path');\n }\n const manifestPath = path.join(pluginPath, 'manifest.json');\n if (!await fileExists(manifestPath)) {\n throw new Error('manifest.json not found');\n }\n\n const devtoolsManager = new DevToolsHelper(true);\n const appsList = devtoolsManager.getAppsList();\n\n const isPsOpen = appsList.some(app => app.appId === 'PS');\n if (!isPsOpen) {\n throw new Error('Photoshop is not open');\n }\n\n const PORT = ports[Math.floor(Math.random() * ports.length)]!;\n\n const server = new Server(PORT);\n server.run();\n\n // this goes through Adobe's Vulcan system, which is a binary black box\n devtoolsManager.setServerDetails(PORT);\n\n console.log('port', PORT);\n\n await new Promise(resolve => setTimeout(resolve, 1500));\n\n const psClient = server.clients.values().next().value;\n\n if (!psClient) {\n throw new Error('No PS client found');\n }\n\n if (!(psClient instanceof AppClient)) {\n throw new TypeError('PS client is not an AppClient');\n }\n\n // const discoverReplySchema = z.object({\n // command: z.literal('reply'),\n // pluginSessionId: z.string(),\n // breakOnStart: z.boolean(),\n // requestId: z.number(),\n // });\n\n /**\n * Helper to promisify handler_Plugin calls with error handling and schema validation\n */\n function callPluginHandler<T extends z.ZodTypeAny>(\n psClient: AppClient,\n message: Parameters<AppClient['handler_Plugin']>[0],\n schema: T,\n ): Promise<z.infer<T>> {\n return new Promise((resolve, reject) => {\n psClient.handler_Plugin(message, (error: Error | null, response: any) => {\n if (response?.error) {\n reject(new Error(response.error));\n return;\n }\n if (error) {\n reject(error);\n return;\n }\n console.log('response for', message.action, response);\n resolve(schema.parse(response));\n });\n });\n }\n\n const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n const pluginId = manifest.id;\n\n const validateResult = await callPluginHandler(\n psClient,\n {\n action: 'validate',\n command: 'Plugin',\n params: {\n provider: {\n type: 'disk',\n id: pluginId,\n path: pluginPath,\n },\n },\n manifest,\n },\n validateReplySchema,\n );\n\n if (!validateResult.success) {\n throw new Error('Validation failed');\n }\n\n const { pluginSessionId } = await callPluginHandler(\n psClient,\n {\n action: 'load',\n command: 'Plugin',\n params: {\n provider: {\n type: 'disk',\n id: pluginId,\n path: pluginPath,\n },\n },\n breakOnStart: false,\n },\n loadReplySchema,\n );\n\n const result = await callPluginHandler(\n psClient,\n {\n action: 'debug',\n command: 'Plugin',\n pluginSessionId,\n },\n debugReplySchema,\n );\n\n const cdtUrl = result.wsdebugUrl.replace('ws=', 'ws://');\n\n const connection: DevtoolsConnection = {\n url: cdtUrl,\n teardown: async () => {\n console.log('Tearing down devtools URL');\n // Unload the plugin from Photoshop\n try {\n await callPluginHandler(\n psClient,\n {\n action: 'unload',\n command: 'Plugin',\n pluginSessionId,\n },\n z.object({\n command: z.literal('reply'),\n requestId: z.number(),\n }),\n );\n console.log('Plugin unloaded');\n }\n catch (error) {\n console.error('Error unloading plugin:', error);\n }\n\n try {\n await server.close();\n }\n catch (error) {\n console.error('Error closing server:', error);\n }\n\n // Terminate the DevToolsHelper (Adobe Vulcan native library)\n // This is crucial to prevent hanging handles\n try {\n devtoolsManager.terminate();\n console.log('DevToolsHelper terminated');\n }\n catch (error) {\n console.error('Error terminating DevToolsHelper:', error);\n }\n },\n };\n\n return connection;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Logger } from '@adobe-fixed-uxp/uxp-devtools-core/core/common/Logger';
|
|
2
|
+
|
|
3
|
+
// src/uxp-logger.ts
|
|
4
|
+
function setGlobalUxpLogger() {
|
|
5
|
+
globalThis.UxpLogger = new Logger();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { setGlobalUxpLogger };
|
|
9
|
+
//# sourceMappingURL=uxp-logger.js.map
|
|
10
|
+
//# sourceMappingURL=uxp-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/uxp-logger.ts"],"names":[],"mappings":";;;AAOO,SAAS,kBAAA,GAAqB;AACnC,EAAA,UAAA,CAAW,SAAA,GAAY,IAAI,MAAA,EAAO;AACpC","file":"uxp-logger.js","sourcesContent":["import { Logger } from '@adobe-fixed-uxp/uxp-devtools-core/core/common/Logger';\n\n/* eslint-disable vars-on-top */\ndeclare global {\n var UxpLogger: Logger;\n}\n\nexport function setGlobalUxpLogger() {\n globalThis.UxpLogger = new Logger();\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
</head>
|
|
7
|
+
<body style="color: white; display: flex; justify-content: center; align-items: center; height: 100vh">
|
|
8
|
+
Fake plugin for CDP debugger
|
|
9
|
+
</body>
|
|
10
|
+
</html>
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "co.bubblydoo.fake-plugin",
|
|
3
|
+
"name": "Fake Plugin",
|
|
4
|
+
"version": "0.0.6",
|
|
5
|
+
"main": "index.html",
|
|
6
|
+
"manifestVersion": 6,
|
|
7
|
+
"host": [
|
|
8
|
+
{
|
|
9
|
+
"app": "PS",
|
|
10
|
+
"minVersion": "24.2.0"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"entrypoints": [
|
|
14
|
+
{
|
|
15
|
+
"type": "panel",
|
|
16
|
+
"id": "co.bubblydoo.fake-plugin.main",
|
|
17
|
+
"label": {
|
|
18
|
+
"default": "Fake Plugin"
|
|
19
|
+
},
|
|
20
|
+
"minimumSize": {
|
|
21
|
+
"width": 230,
|
|
22
|
+
"height": 200
|
|
23
|
+
},
|
|
24
|
+
"maximumSize": {
|
|
25
|
+
"width": 2000,
|
|
26
|
+
"height": 2000
|
|
27
|
+
},
|
|
28
|
+
"preferredDockedSize": {
|
|
29
|
+
"width": 230,
|
|
30
|
+
"height": 300
|
|
31
|
+
},
|
|
32
|
+
"preferredFloatingSize": {
|
|
33
|
+
"width": 450,
|
|
34
|
+
"height": 400
|
|
35
|
+
},
|
|
36
|
+
"icons": [
|
|
37
|
+
{
|
|
38
|
+
"width": 23,
|
|
39
|
+
"height": 23,
|
|
40
|
+
"path": "icons/dark.png",
|
|
41
|
+
"scale": [
|
|
42
|
+
1,
|
|
43
|
+
2
|
|
44
|
+
],
|
|
45
|
+
"theme": [
|
|
46
|
+
"darkest",
|
|
47
|
+
"dark",
|
|
48
|
+
"medium"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"width": 23,
|
|
53
|
+
"height": 23,
|
|
54
|
+
"path": "icons/light.png",
|
|
55
|
+
"scale": [
|
|
56
|
+
1,
|
|
57
|
+
2
|
|
58
|
+
],
|
|
59
|
+
"theme": [
|
|
60
|
+
"lightest",
|
|
61
|
+
"light"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"featureFlags": {
|
|
68
|
+
"enableAlerts": true
|
|
69
|
+
},
|
|
70
|
+
"requiredPermissions": {
|
|
71
|
+
"localFileSystem": "fullAccess",
|
|
72
|
+
"launchProcess": {
|
|
73
|
+
"schemes": [
|
|
74
|
+
"https",
|
|
75
|
+
"slack",
|
|
76
|
+
"file",
|
|
77
|
+
"ws"
|
|
78
|
+
],
|
|
79
|
+
"extensions": [
|
|
80
|
+
".xd",
|
|
81
|
+
".psd",
|
|
82
|
+
".bat",
|
|
83
|
+
".cmd",
|
|
84
|
+
""
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
"clipboard": "readAndWrite",
|
|
88
|
+
"webview": {
|
|
89
|
+
"allow": "yes",
|
|
90
|
+
"allowLocalRendering": "yes",
|
|
91
|
+
"domains": "all",
|
|
92
|
+
"enableMessageBridge": "localAndRemote"
|
|
93
|
+
},
|
|
94
|
+
"ipc": {
|
|
95
|
+
"enablePluginCommunication": true
|
|
96
|
+
},
|
|
97
|
+
"allowCodeGenerationFromStrings": true
|
|
98
|
+
},
|
|
99
|
+
"icons": [
|
|
100
|
+
{
|
|
101
|
+
"width": 48,
|
|
102
|
+
"height": 48,
|
|
103
|
+
"path": "icons/plugin-icon.png",
|
|
104
|
+
"scale": [
|
|
105
|
+
1,
|
|
106
|
+
2
|
|
107
|
+
],
|
|
108
|
+
"theme": [
|
|
109
|
+
"darkest",
|
|
110
|
+
"dark",
|
|
111
|
+
"medium",
|
|
112
|
+
"lightest",
|
|
113
|
+
"light",
|
|
114
|
+
"all"
|
|
115
|
+
],
|
|
116
|
+
"species": [
|
|
117
|
+
"pluginList"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bubblydoo/uxp-devtools-common",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.3",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./setup-devtools-url": {
|
|
11
|
+
"types": "./dist/setup-devtools-url.d.ts",
|
|
12
|
+
"import": "./dist/setup-devtools-url.js"
|
|
13
|
+
},
|
|
14
|
+
"./uxp-logger": {
|
|
15
|
+
"types": "./dist/uxp-logger.d.ts",
|
|
16
|
+
"import": "./dist/uxp-logger.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"fake-plugin"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@adobe-fixed-uxp/uxp-devtools-core": "^1.6.3",
|
|
29
|
+
"@adobe-fixed-uxp/uxp-devtools-helper": "^1.6.2",
|
|
30
|
+
"chrome-remote-interface": "^0.33.3",
|
|
31
|
+
"zod": "^4.3.6"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/chrome-remote-interface": "^0.33.0",
|
|
35
|
+
"@types/node": "^20.8.7",
|
|
36
|
+
"tsup": "^8.3.5",
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
|
+
"@bubblydoo/tsconfig": "0.0.3"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup",
|
|
42
|
+
"dev": "tsup --watch"
|
|
43
|
+
}
|
|
44
|
+
}
|