@quenty/studio-bridge 0.1.1-canary.656.73a74af.0 → 0.2.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/build-scripts/transform-add-session-attribute.luau +17 -0
  3. package/dist/src/index.d.ts +0 -1
  4. package/dist/src/index.d.ts.map +1 -1
  5. package/dist/src/index.js +0 -1
  6. package/dist/src/index.js.map +1 -1
  7. package/dist/src/plugin/plugin-injector.d.ts.map +1 -1
  8. package/dist/src/plugin/plugin-injector.js +11 -34
  9. package/dist/src/plugin/plugin-injector.js.map +1 -1
  10. package/dist/src/process/index.d.ts +0 -2
  11. package/dist/src/process/index.d.ts.map +1 -1
  12. package/dist/src/process/index.js +0 -1
  13. package/dist/src/process/index.js.map +1 -1
  14. package/dist/src/server/studio-bridge-server.d.ts +1 -1
  15. package/dist/src/server/studio-bridge-server.d.ts.map +1 -1
  16. package/dist/src/server/studio-bridge-server.js +38 -12
  17. package/dist/src/server/studio-bridge-server.js.map +1 -1
  18. package/dist/src/server/studio-bridge-server.test.js +94 -19
  19. package/dist/src/server/studio-bridge-server.test.js.map +1 -1
  20. package/dist/src/server/web-socket-protocol.d.ts +7 -1
  21. package/dist/src/server/web-socket-protocol.d.ts.map +1 -1
  22. package/dist/src/server/web-socket-protocol.js +8 -4
  23. package/dist/src/server/web-socket-protocol.js.map +1 -1
  24. package/dist/src/server/web-socket-protocol.smoke.test.js +18 -9
  25. package/dist/src/server/web-socket-protocol.smoke.test.js.map +1 -1
  26. package/dist/src/server/web-socket-protocol.test.js +47 -5
  27. package/dist/src/server/web-socket-protocol.test.js.map +1 -1
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +5 -5
  30. package/src/index.ts +0 -1
  31. package/src/plugin/plugin-injector.ts +19 -45
  32. package/src/process/index.ts +0 -3
  33. package/src/server/studio-bridge-server.test.ts +113 -21
  34. package/src/server/studio-bridge-server.ts +66 -15
  35. package/src/server/web-socket-protocol.smoke.test.ts +18 -9
  36. package/src/server/web-socket-protocol.test.ts +61 -5
  37. package/src/server/web-socket-protocol.ts +15 -4
  38. package/templates/default-test-place/default.project.json +1 -1
  39. package/templates/studio-bridge-plugin/default.project.json +1 -1
  40. package/templates/studio-bridge-plugin/{plugin-template.server.lua → src/StudioBridgePlugin.server.lua} +18 -4
  41. package/dist/src/process/place-builder.d.ts +0 -16
  42. package/dist/src/process/place-builder.d.ts.map +0 -1
  43. package/dist/src/process/place-builder.js +0 -45
  44. package/dist/src/process/place-builder.js.map +0 -1
  45. package/src/process/place-builder.ts +0 -63
@@ -5,29 +5,33 @@ describe('encodeMessage', () => {
5
5
  it('encodes a welcome message', () => {
6
6
  const json = encodeMessage({
7
7
  type: 'welcome',
8
+ sessionId: 'abc-123',
8
9
  payload: { sessionId: 'abc-123' },
9
10
  });
10
11
  const parsed = JSON.parse(json);
11
12
  expect(parsed).toEqual({
12
13
  type: 'welcome',
14
+ sessionId: 'abc-123',
13
15
  payload: { sessionId: 'abc-123' },
14
16
  });
15
17
  });
16
18
 
17
19
  it('encodes a shutdown message', () => {
18
- const json = encodeMessage({ type: 'shutdown', payload: {} });
20
+ const json = encodeMessage({ type: 'shutdown', sessionId: 'abc-123', payload: {} });
19
21
  const parsed = JSON.parse(json);
20
- expect(parsed).toEqual({ type: 'shutdown', payload: {} });
22
+ expect(parsed).toEqual({ type: 'shutdown', sessionId: 'abc-123', payload: {} });
21
23
  });
22
24
 
23
25
  it('encodes an execute message', () => {
24
26
  const json = encodeMessage({
25
27
  type: 'execute',
28
+ sessionId: 'abc-123',
26
29
  payload: { script: 'print("hi")' },
27
30
  });
28
31
  const parsed = JSON.parse(json);
29
32
  expect(parsed).toEqual({
30
33
  type: 'execute',
34
+ sessionId: 'abc-123',
31
35
  payload: { script: 'print("hi")' },
32
36
  });
33
37
  });
@@ -39,24 +43,37 @@ describe('decodePluginMessage', () => {
39
43
  const msg = decodePluginMessage(
40
44
  JSON.stringify({
41
45
  type: 'hello',
46
+ sessionId: 'test-session',
42
47
  payload: { sessionId: 'test-session' },
43
48
  })
44
49
  );
45
50
  expect(msg).toEqual({
46
51
  type: 'hello',
52
+ sessionId: 'test-session',
47
53
  payload: { sessionId: 'test-session' },
48
54
  });
49
55
  });
50
56
 
51
- it('returns null for hello without sessionId', () => {
57
+ it('returns null for hello without sessionId in payload', () => {
52
58
  const msg = decodePluginMessage(
53
59
  JSON.stringify({
54
60
  type: 'hello',
61
+ sessionId: 'test-session',
55
62
  payload: {},
56
63
  })
57
64
  );
58
65
  expect(msg).toBeNull();
59
66
  });
67
+
68
+ it('returns null for hello without top-level sessionId', () => {
69
+ const msg = decodePluginMessage(
70
+ JSON.stringify({
71
+ type: 'hello',
72
+ payload: { sessionId: 'test-session' },
73
+ })
74
+ );
75
+ expect(msg).toBeNull();
76
+ });
60
77
  });
61
78
 
62
79
  describe('output', () => {
@@ -64,6 +81,7 @@ describe('decodePluginMessage', () => {
64
81
  const msg = decodePluginMessage(
65
82
  JSON.stringify({
66
83
  type: 'output',
84
+ sessionId: 'test-session',
67
85
  payload: {
68
86
  messages: [
69
87
  { level: 'Print', body: 'Hello world' },
@@ -74,6 +92,7 @@ describe('decodePluginMessage', () => {
74
92
  );
75
93
  expect(msg).toEqual({
76
94
  type: 'output',
95
+ sessionId: 'test-session',
77
96
  payload: {
78
97
  messages: [
79
98
  { level: 'Print', body: 'Hello world' },
@@ -87,6 +106,7 @@ describe('decodePluginMessage', () => {
87
106
  const msg = decodePluginMessage(
88
107
  JSON.stringify({
89
108
  type: 'output',
109
+ sessionId: 'test-session',
90
110
  payload: {
91
111
  messages: [
92
112
  { level: 'Print', body: 'valid' },
@@ -99,6 +119,7 @@ describe('decodePluginMessage', () => {
99
119
  );
100
120
  expect(msg).toEqual({
101
121
  type: 'output',
122
+ sessionId: 'test-session',
102
123
  payload: {
103
124
  messages: [{ level: 'Print', body: 'valid' }],
104
125
  },
@@ -109,11 +130,22 @@ describe('decodePluginMessage', () => {
109
130
  const msg = decodePluginMessage(
110
131
  JSON.stringify({
111
132
  type: 'output',
133
+ sessionId: 'test-session',
112
134
  payload: { messages: 'not-an-array' },
113
135
  })
114
136
  );
115
137
  expect(msg).toBeNull();
116
138
  });
139
+
140
+ it('returns null for output without top-level sessionId', () => {
141
+ const msg = decodePluginMessage(
142
+ JSON.stringify({
143
+ type: 'output',
144
+ payload: { messages: [{ level: 'Print', body: 'test' }] },
145
+ })
146
+ );
147
+ expect(msg).toBeNull();
148
+ });
117
149
  });
118
150
 
119
151
  describe('scriptComplete', () => {
@@ -121,11 +153,13 @@ describe('decodePluginMessage', () => {
121
153
  const msg = decodePluginMessage(
122
154
  JSON.stringify({
123
155
  type: 'scriptComplete',
156
+ sessionId: 'test-session',
124
157
  payload: { success: true },
125
158
  })
126
159
  );
127
160
  expect(msg).toEqual({
128
161
  type: 'scriptComplete',
162
+ sessionId: 'test-session',
129
163
  payload: { success: true, error: undefined },
130
164
  });
131
165
  });
@@ -134,11 +168,13 @@ describe('decodePluginMessage', () => {
134
168
  const msg = decodePluginMessage(
135
169
  JSON.stringify({
136
170
  type: 'scriptComplete',
171
+ sessionId: 'test-session',
137
172
  payload: { success: false, error: 'Script errored' },
138
173
  })
139
174
  );
140
175
  expect(msg).toEqual({
141
176
  type: 'scriptComplete',
177
+ sessionId: 'test-session',
142
178
  payload: { success: false, error: 'Script errored' },
143
179
  });
144
180
  });
@@ -147,11 +183,22 @@ describe('decodePluginMessage', () => {
147
183
  const msg = decodePluginMessage(
148
184
  JSON.stringify({
149
185
  type: 'scriptComplete',
186
+ sessionId: 'test-session',
150
187
  payload: { success: 'yes' },
151
188
  })
152
189
  );
153
190
  expect(msg).toBeNull();
154
191
  });
192
+
193
+ it('returns null for scriptComplete without top-level sessionId', () => {
194
+ const msg = decodePluginMessage(
195
+ JSON.stringify({
196
+ type: 'scriptComplete',
197
+ payload: { success: true },
198
+ })
199
+ );
200
+ expect(msg).toBeNull();
201
+ });
155
202
  });
156
203
 
157
204
  describe('malformed messages', () => {
@@ -164,11 +211,19 @@ describe('decodePluginMessage', () => {
164
211
  });
165
212
 
166
213
  it('returns null for missing type', () => {
167
- expect(decodePluginMessage(JSON.stringify({ payload: {} }))).toBeNull();
214
+ expect(decodePluginMessage(JSON.stringify({ sessionId: 's', payload: {} }))).toBeNull();
168
215
  });
169
216
 
170
217
  it('returns null for missing payload', () => {
171
- expect(decodePluginMessage(JSON.stringify({ type: 'hello' }))).toBeNull();
218
+ expect(decodePluginMessage(JSON.stringify({ type: 'hello', sessionId: 's' }))).toBeNull();
219
+ });
220
+
221
+ it('returns null for missing sessionId', () => {
222
+ expect(
223
+ decodePluginMessage(
224
+ JSON.stringify({ type: 'hello', payload: { sessionId: 's' } })
225
+ )
226
+ ).toBeNull();
172
227
  });
173
228
 
174
229
  it('returns null for unknown message type', () => {
@@ -176,6 +231,7 @@ describe('decodePluginMessage', () => {
176
231
  decodePluginMessage(
177
232
  JSON.stringify({
178
233
  type: 'unknown',
234
+ sessionId: 'test',
179
235
  payload: {},
180
236
  })
181
237
  )
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * WebSocket message protocol shared between the Node.js server and the Roblox
3
- * Studio plugin. All messages are JSON-encoded: `{ type: string, payload: object }`.
3
+ * Studio plugin. All messages are JSON-encoded: `{ type: string, sessionId: string, payload: object }`.
4
4
  */
5
5
 
6
6
  // ---------------------------------------------------------------------------
@@ -15,6 +15,7 @@ export type OutputLevel = 'Print' | 'Info' | 'Warning' | 'Error';
15
15
 
16
16
  export interface HelloMessage {
17
17
  type: 'hello';
18
+ sessionId: string;
18
19
  payload: {
19
20
  sessionId: string;
20
21
  };
@@ -22,6 +23,7 @@ export interface HelloMessage {
22
23
 
23
24
  export interface OutputMessage {
24
25
  type: 'output';
26
+ sessionId: string;
25
27
  payload: {
26
28
  messages: Array<{
27
29
  level: OutputLevel;
@@ -32,6 +34,7 @@ export interface OutputMessage {
32
34
 
33
35
  export interface ScriptCompleteMessage {
34
36
  type: 'scriptComplete';
37
+ sessionId: string;
35
38
  payload: {
36
39
  success: boolean;
37
40
  error?: string;
@@ -46,6 +49,7 @@ export type PluginMessage = HelloMessage | OutputMessage | ScriptCompleteMessage
46
49
 
47
50
  export interface WelcomeMessage {
48
51
  type: 'welcome';
52
+ sessionId: string;
49
53
  payload: {
50
54
  sessionId: string;
51
55
  };
@@ -53,6 +57,7 @@ export interface WelcomeMessage {
53
57
 
54
58
  export interface ExecuteMessage {
55
59
  type: 'execute';
60
+ sessionId: string;
56
61
  payload: {
57
62
  script: string;
58
63
  };
@@ -60,6 +65,7 @@ export interface ExecuteMessage {
60
65
 
61
66
  export interface ShutdownMessage {
62
67
  type: 'shutdown';
68
+ sessionId: string;
63
69
  payload: Record<string, never>;
64
70
  }
65
71
 
@@ -90,12 +96,16 @@ export function decodePluginMessage(raw: string): PluginMessage | null {
90
96
  return null;
91
97
  }
92
98
 
93
- const { type, payload } = obj as { type: string; payload: Record<string, unknown> };
99
+ if (typeof obj.sessionId !== 'string') {
100
+ return null;
101
+ }
102
+
103
+ const { type, sessionId, payload } = obj as { type: string; sessionId: string; payload: Record<string, unknown> };
94
104
 
95
105
  switch (type) {
96
106
  case 'hello':
97
107
  if (typeof payload.sessionId === 'string') {
98
- return { type: 'hello', payload: { sessionId: payload.sessionId } };
108
+ return { type: 'hello', sessionId, payload: { sessionId: payload.sessionId } };
99
109
  }
100
110
  return null;
101
111
 
@@ -110,7 +120,7 @@ export function decodePluginMessage(raw: string): PluginMessage | null {
110
120
  typeof (m as Record<string, unknown>).body === 'string'
111
121
  )
112
122
  .map((m) => ({ level: m.level, body: m.body }));
113
- return { type: 'output', payload: { messages } };
123
+ return { type: 'output', sessionId, payload: { messages } };
114
124
  }
115
125
  return null;
116
126
 
@@ -118,6 +128,7 @@ export function decodePluginMessage(raw: string): PluginMessage | null {
118
128
  if (typeof payload.success === 'boolean') {
119
129
  return {
120
130
  type: 'scriptComplete',
131
+ sessionId,
121
132
  payload: {
122
133
  success: payload.success,
123
134
  error: typeof payload.error === 'string' ? payload.error : undefined,
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "StudioBridgeMinimal",
2
+ "name": "StudioBridgeTestPlace",
3
3
  "tree": {
4
4
  "$className": "DataModel",
5
5
  "ServerScriptService": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "StudioBridgePlugin",
3
3
  "tree": {
4
- "$path": "plugin-template.server.lua"
4
+ "$path": "src"
5
5
  }
6
6
  }
@@ -9,15 +9,22 @@
9
9
  local HttpService = game:GetService("HttpService")
10
10
  local LogService = game:GetService("LogService")
11
11
  local RunService = game:GetService("RunService")
12
+ local Workspace = game:GetService("Workspace")
13
+
14
+ local PORT = "{{PORT}}"
15
+ local SESSION_ID = "{{SESSION_ID}}"
12
16
 
13
17
  -- Only run inside Studio
14
- if not RunService:IsStudio() then
18
+ if not RunService:IsStudio() or RunService:IsRunning() then
15
19
  return
16
20
  end
17
21
 
18
- local PORT = "{{PORT}}"
19
- local SESSION_ID = "{{SESSION_ID}}"
20
- local WS_URL = "ws://localhost:" .. PORT
22
+ local thisPlaceSessionId = Workspace:GetAttribute("StudioBridgeSessionId")
23
+ if thisPlaceSessionId ~= SESSION_ID then
24
+ return
25
+ end
26
+
27
+ local WS_URL = "ws://localhost:" .. PORT .. "/" .. SESSION_ID
21
28
 
22
29
  -- ---------------------------------------------------------------------------
23
30
  -- Helpers
@@ -41,6 +48,7 @@ local function send(client, msgType, payload)
41
48
  local ok, err = pcall(function()
42
49
  client:Send(jsonEncode({
43
50
  type = msgType,
51
+ sessionId = SESSION_ID,
44
52
  payload = payload,
45
53
  }))
46
54
  end)
@@ -157,6 +165,12 @@ local function connectAsync()
157
165
  return
158
166
  end
159
167
 
168
+ -- Validate session ID on every incoming message
169
+ if msg.sessionId ~= SESSION_ID then
170
+ warn("[StudioBridge] Ignoring message with wrong session ID")
171
+ return
172
+ end
173
+
160
174
  if msg.type == "welcome" then
161
175
  -- Handshake accepted — ready for execute messages
162
176
  print("[StudioBridge] Connected, ready for commands")
@@ -1,16 +0,0 @@
1
- /**
2
- * Builds a minimal .rbxl place file via rojo for use when no place is
3
- * provided. The place just has ServerScriptService with LoadStringEnabled
4
- * so that loadstring() works in the injected plugin.
5
- */
6
- export interface BuiltPlace {
7
- /** Absolute path to the .rbxl file */
8
- placePath: string;
9
- /** Remove the temp directory (idempotent) */
10
- cleanupAsync: () => Promise<void>;
11
- }
12
- /**
13
- * Build a minimal .rbxl place file in a temp directory using rojo.
14
- */
15
- export declare function buildMinimalPlaceAsync(): Promise<BuiltPlace>;
16
- //# sourceMappingURL=place-builder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"place-builder.d.ts","sourceRoot":"","sources":["../../../src/process/place-builder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,UAAU,CAAC,CAmClE"}
@@ -1,45 +0,0 @@
1
- /**
2
- * Builds a minimal .rbxl place file via rojo for use when no place is
3
- * provided. The place just has ServerScriptService with LoadStringEnabled
4
- * so that loadstring() works in the injected plugin.
5
- */
6
- import * as fs from 'fs/promises';
7
- import * as os from 'os';
8
- import * as path from 'path';
9
- import { OutputHelper } from '@quenty/cli-output-helpers';
10
- import { rojoBuildAsync, resolveTemplatePath } from '@quenty/nevermore-template-helpers';
11
- const projectPath = resolveTemplatePath(import.meta.url, path.join('default-test-place', 'default.project.json'));
12
- /**
13
- * Build a minimal .rbxl place file in a temp directory using rojo.
14
- */
15
- export async function buildMinimalPlaceAsync() {
16
- const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'studio-bridge-'));
17
- OutputHelper.verbose(`[StudioBridge] Building minimal place in ${tmpDir}`);
18
- try {
19
- const placePath = path.join(tmpDir, 'minimal.rbxl');
20
- await rojoBuildAsync({ projectPath, output: placePath });
21
- OutputHelper.verbose(`[StudioBridge] Minimal place built: ${placePath}`);
22
- return {
23
- placePath,
24
- cleanupAsync: async () => {
25
- try {
26
- await fs.rm(tmpDir, { recursive: true, force: true });
27
- }
28
- catch {
29
- // best effort
30
- }
31
- },
32
- };
33
- }
34
- catch (err) {
35
- try {
36
- await fs.rm(tmpDir, { recursive: true, force: true });
37
- }
38
- catch {
39
- // best effort
40
- }
41
- const message = err instanceof Error ? err.message : String(err);
42
- throw new Error(`Failed to build minimal place via rojo. Is rojo installed and on PATH?\n${message}`);
43
- }
44
- }
45
- //# sourceMappingURL=place-builder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"place-builder.js","sourceRoot":"","sources":["../../../src/process/place-builder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzF,MAAM,WAAW,GAAG,mBAAmB,CACrC,MAAM,CAAC,IAAI,CAAC,GAAG,EACf,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CACxD,CAAC;AASF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAC1C,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAE1E,YAAY,CAAC,OAAO,CAClB,4CAA4C,MAAM,EAAE,CACrD,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QACpD,MAAM,cAAc,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAEzD,YAAY,CAAC,OAAO,CAAC,uCAAuC,SAAS,EAAE,CAAC,CAAC;QAEzE,OAAO;YACL,SAAS;YACT,YAAY,EAAE,KAAK,IAAI,EAAE;gBACvB,IAAI,CAAC;oBACH,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBACxD,CAAC;gBAAC,MAAM,CAAC;oBACP,cAAc;gBAChB,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;QAAC,MAAM,CAAC;YACP,cAAc;QAChB,CAAC;QAED,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,MAAM,IAAI,KAAK,CACb,2EAA2E,OAAO,EAAE,CACrF,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -1,63 +0,0 @@
1
- /**
2
- * Builds a minimal .rbxl place file via rojo for use when no place is
3
- * provided. The place just has ServerScriptService with LoadStringEnabled
4
- * so that loadstring() works in the injected plugin.
5
- */
6
-
7
- import * as fs from 'fs/promises';
8
- import * as os from 'os';
9
- import * as path from 'path';
10
- import { OutputHelper } from '@quenty/cli-output-helpers';
11
- import { rojoBuildAsync, resolveTemplatePath } from '@quenty/nevermore-template-helpers';
12
-
13
- const projectPath = resolveTemplatePath(
14
- import.meta.url,
15
- path.join('default-test-place', 'default.project.json')
16
- );
17
-
18
- export interface BuiltPlace {
19
- /** Absolute path to the .rbxl file */
20
- placePath: string;
21
- /** Remove the temp directory (idempotent) */
22
- cleanupAsync: () => Promise<void>;
23
- }
24
-
25
- /**
26
- * Build a minimal .rbxl place file in a temp directory using rojo.
27
- */
28
- export async function buildMinimalPlaceAsync(): Promise<BuiltPlace> {
29
- const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'studio-bridge-'));
30
-
31
- OutputHelper.verbose(
32
- `[StudioBridge] Building minimal place in ${tmpDir}`
33
- );
34
-
35
- try {
36
- const placePath = path.join(tmpDir, 'minimal.rbxl');
37
- await rojoBuildAsync({ projectPath, output: placePath });
38
-
39
- OutputHelper.verbose(`[StudioBridge] Minimal place built: ${placePath}`);
40
-
41
- return {
42
- placePath,
43
- cleanupAsync: async () => {
44
- try {
45
- await fs.rm(tmpDir, { recursive: true, force: true });
46
- } catch {
47
- // best effort
48
- }
49
- },
50
- };
51
- } catch (err) {
52
- try {
53
- await fs.rm(tmpDir, { recursive: true, force: true });
54
- } catch {
55
- // best effort
56
- }
57
-
58
- const message = err instanceof Error ? err.message : String(err);
59
- throw new Error(
60
- `Failed to build minimal place via rojo. Is rojo installed and on PATH?\n${message}`
61
- );
62
- }
63
- }