Skip to content

Commit 91f4e91

Browse files
committed
* use extension handle in extension messages
* update app proxy messaging * add tests for app proxy messaging
1 parent ebaf571 commit 91f4e91

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

packages/app/src/cli/models/extensions/specifications/app_config_app_proxy.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import spec from './app_config_app_proxy.js'
1+
import spec, {type AppProxyConfigType} from './app_config_app_proxy.js'
22
import {placeholderAppConfiguration} from '../../app/app.test-data.js'
33
import {describe, expect, test} from 'vitest'
44

@@ -50,4 +50,37 @@ describe('app_config_app_proxy', () => {
5050
})
5151
})
5252
})
53+
54+
describe('getDevSessionUpdateMessages', () => {
55+
test('should return both messages when app_proxy config is present', async () => {
56+
// Given
57+
const config: AppProxyConfigType = {
58+
app_proxy: {
59+
url: 'https://my-proxy.dev',
60+
subpath: 'apps',
61+
prefix: 'proxy',
62+
},
63+
}
64+
65+
// When
66+
const result = await spec.getDevSessionUpdateMessages!(config)
67+
68+
// Then
69+
expect(result).toEqual([
70+
'Using URL: https://my-proxy.dev',
71+
'Any changes to prefix and subpath will only apply to new installs',
72+
])
73+
})
74+
75+
test('should return empty array when no app_proxy config is present', async () => {
76+
// Given
77+
const config: AppProxyConfigType = {}
78+
79+
// When
80+
const result = await spec.getDevSessionUpdateMessages!(config)
81+
82+
// Then
83+
expect(result).toEqual([])
84+
})
85+
})
5386
})

packages/app/src/cli/models/extensions/specifications/app_config_app_proxy.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const AppProxySchema = BaseSchema.extend({
1313
.optional(),
1414
})
1515

16+
export type AppProxyConfigType = zod.infer<typeof AppProxySchema>
17+
1618
export const AppProxySpecIdentifier = 'app_proxy'
1719

1820
const AppProxyTransformConfig: TransformationConfig = {
@@ -26,10 +28,10 @@ const appProxySpec: ExtensionSpecification = createConfigExtensionSpecification(
2628
schema: AppProxySchema,
2729
transformConfig: AppProxyTransformConfig,
2830
getDevSessionUpdateMessages: async (config) => {
29-
return [
30-
`Using app proxy URL: ${config.app_proxy?.url}`,
31-
`Note: Changes to app proxy prefix and subpath won't affect existing installations.`,
32-
]
31+
if (!config.app_proxy) {
32+
return []
33+
}
34+
return [`Using URL: ${config.app_proxy.url}`, `Any changes to prefix and subpath will only apply to new installs`]
3335
},
3436
patchWithAppDevURLs: (config, urls) => {
3537
if (urls.appProxy) {

packages/app/src/cli/services/dev/processes/dev-session/dev-session-logger.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ describe('DevSessionLogger', () => {
177177
devUUID: '',
178178
localIdentifier: '',
179179
idEnvironmentVariableName: '',
180+
handle: 'test-extension',
180181
} as unknown as ExtensionInstance
181182

182183
const event: AppEvent = {
@@ -194,7 +195,7 @@ describe('DevSessionLogger', () => {
194195
await logger.logExtensionUpdateMessages(event)
195196
expect(output).toMatchInlineSnapshot(`
196197
[
197-
"└ This has been updated.",
198+
"[90m└ [39mThis has been updated.",
198199
]
199200
`)
200201
})
@@ -206,6 +207,7 @@ describe('DevSessionLogger', () => {
206207
devUUID: '',
207208
localIdentifier: '',
208209
idEnvironmentVariableName: '',
210+
handle: 'test-extension',
209211
} as unknown as ExtensionInstance
210212

211213
const event: AppEvent = {

packages/app/src/cli/services/dev/processes/dev-session/dev-session-logger.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ export class DevSessionLogger {
8080
extensionEvents.map(async (eve) => {
8181
if (eve.type === EventType.Deleted) return []
8282
const messages = await eve.extension.getDevSessionUpdateMessages()
83-
return messages ?? []
83+
return messages?.map((message) => ({message, prefix: eve.extension.handle})) ?? []
8484
}),
8585
)
8686
const messages = messageArrays.flat()
8787

8888
const logPromises = messages.map((message, index) => {
89-
const messageContent = outputContent`${outputToken.gray(index === messages.length - 1 ? '└ ' : '│ ')}${message}`
90-
.value
91-
return this.log(messageContent, 'app-preview')
89+
const messageContent = outputContent`${outputToken.gray(index === messages.length - 1 ? '└ ' : '│ ')}${
90+
message.message
91+
}`.value
92+
return this.log(messageContent, message.prefix)
9293
})
9394
await Promise.all(logPromises)
9495
}

0 commit comments

Comments
 (0)