Skip to content

Commit 34ff02b

Browse files
committed
Fix how app name is set from the AppLoader
1 parent b4ad9dd commit 34ff02b

File tree

4 files changed

+88
-11
lines changed

4 files changed

+88
-11
lines changed

packages/app/src/cli/models/app/app.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const LegacyAppSchema = zod
4848
.object({
4949
client_id: zod.number().optional(),
5050
name: zod.string().optional(),
51+
handle: zod.string().optional(),
5152
scopes: zod
5253
.string()
5354
.transform((scopes) => normalizeDelimitedString(scopes) ?? '')
@@ -80,14 +81,16 @@ function fixSingleWildcards(value: string[] | undefined) {
8081
*/
8182
export const AppSchema = zod.object({
8283
client_id: zod.string(),
84+
extension_directories: ExtensionDirectoriesSchema,
85+
name: zod.string().optional(),
86+
handle: zod.string().optional(),
8387
build: zod
8488
.object({
8589
automatically_update_urls_on_dev: zod.boolean().optional(),
8690
dev_store_url: zod.string().optional(),
8791
include_config_on_deploy: zod.boolean().optional(),
8892
})
8993
.optional(),
90-
extension_directories: ExtensionDirectoriesSchema,
9194
web_directories: zod.array(zod.string()).optional(),
9295
})
9396

@@ -168,7 +171,7 @@ export function isLegacyAppSchema(item: AppConfiguration): item is LegacyAppConf
168171
*/
169172
export function isCurrentAppSchema(item: AppConfiguration): item is CurrentAppConfiguration {
170173
const {path, ...rest} = item
171-
return isType(AppSchema.nonstrict(), rest)
174+
return isType(AppSchema.passthrough(), rest)
172175
}
173176

174177
/**

packages/app/src/cli/models/app/loader.test.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,80 @@ wrong = "property"
264264
const app = await loadApp({directory: tmpDir, specifications: [], userProvidedConfigName: undefined})
265265

266266
// Then
267-
expect(app.name).toBe('my_app')
267+
expect(app.name).toBe('for-testing')
268+
})
269+
270+
test('uses handle from configuration as app name when present', async () => {
271+
// Given
272+
const appConfiguration = `
273+
name = "display-name"
274+
handle = "app-handle"
275+
client_id = "1234567890"
276+
application_url = "https://example.com/lala"
277+
embedded = true
278+
279+
[webhooks]
280+
api_version = "2023-07"
281+
282+
[auth]
283+
redirect_urls = [ "https://example.com/api/auth" ]
284+
`
285+
await writeConfig(appConfiguration)
286+
287+
// When
288+
const app = await loadTestingApp()
289+
290+
// Then
291+
expect(app.name).toBe('app-handle')
292+
})
293+
294+
test('uses name from configuration when handle is not present', async () => {
295+
// Given
296+
const appConfiguration = `
297+
name = "config-name"
298+
client_id = "1234567890"
299+
application_url = "https://example.com/lala"
300+
embedded = true
301+
302+
[webhooks]
303+
api_version = "2023-07"
304+
305+
[auth]
306+
redirect_urls = [ "https://example.com/api/auth" ]
307+
`
308+
await writeConfig(appConfiguration)
309+
310+
// When
311+
const app = await loadTestingApp()
312+
313+
// Then
314+
expect(app.name).toBe('config-name')
315+
})
316+
317+
test('falls back to package.json name when handle and name are not in configuration', async () => {
318+
// Given
319+
const appConfiguration = `
320+
client_id = "1234567890"
321+
application_url = "https://example.com/lala"
322+
embedded = true
323+
324+
[webhooks]
325+
api_version = "2023-07"
326+
327+
[auth]
328+
redirect_urls = [ "https://example.com/api/auth" ]
329+
`
330+
await writeConfig(appConfiguration, {
331+
name: 'package-json-name',
332+
dependencies: {},
333+
devDependencies: {},
334+
})
335+
336+
// When
337+
const app = await loadTestingApp()
338+
339+
// Then
340+
expect(app.name).toBe('package-json-name')
268341
})
269342

270343
test('defaults to npm as the package manager when the configuration is valid', async () => {

packages/app/src/cli/models/app/loader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ class AppLoader<TConfig extends AppConfiguration, TModuleSpec extends ExtensionS
343343
const packageJSONPath = joinPath(directory, 'package.json')
344344

345345
// These don't need to be processed again if the app is being reloaded
346-
const name = this.previousApp?.name ?? (await loadAppName(directory))
346+
const configName = 'name' in configuration ? configuration.name : undefined
347+
const name = this.previousApp?.name ?? configuration.handle ?? configName ?? (await loadAppName(directory))
347348
const nodeDependencies = this.previousApp?.nodeDependencies ?? (await getDependencies(packageJSONPath))
348349
const packageManager = this.previousApp?.packageManager ?? (await getPackageManager(directory))
349350
const usesWorkspaces = this.previousApp?.usesWorkspaces ?? (await appUsesWorkspaces(directory))

packages/app/src/cli/services/context/breakdown-extensions.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ describe('configExtensionsIdentifiersBreakdown', () => {
874874

875875
// Then
876876
expect(result).toEqual({
877-
existingFieldNames: ['name', 'application_url', 'embedded', 'pos', 'app_proxy', 'webhooks'],
877+
existingFieldNames: ['application_url', 'embedded', 'pos', 'app_proxy', 'webhooks'],
878878
existingUpdatedFieldNames: [],
879879
newFieldNames: [],
880880
deletedFieldNames: [],
@@ -965,7 +965,7 @@ describe('configExtensionsIdentifiersBreakdown', () => {
965965

966966
// Then
967967
expect(result).toEqual({
968-
existingFieldNames: ['name', 'application_url', 'embedded', 'webhooks'],
968+
existingFieldNames: ['application_url', 'embedded', 'webhooks'],
969969
existingUpdatedFieldNames: [],
970970
newFieldNames: [],
971971
deletedFieldNames: [],
@@ -1055,7 +1055,7 @@ describe('configExtensionsIdentifiersBreakdown', () => {
10551055

10561056
// Then
10571057
expect(result).toEqual({
1058-
existingFieldNames: ['name', 'webhooks'],
1058+
existingFieldNames: ['webhooks'],
10591059
existingUpdatedFieldNames: ['application_url', 'embedded'],
10601060
newFieldNames: [],
10611061
deletedFieldNames: [],
@@ -1114,7 +1114,7 @@ describe('configExtensionsIdentifiersBreakdown', () => {
11141114
expect(result).toEqual({
11151115
existingFieldNames: ['application_url', 'embedded'],
11161116
existingUpdatedFieldNames: [],
1117-
newFieldNames: ['name', 'webhooks', 'pos'],
1117+
newFieldNames: ['webhooks', 'pos'],
11181118
deletedFieldNames: [],
11191119
})
11201120
})
@@ -1217,7 +1217,7 @@ describe('configExtensionsIdentifiersBreakdown', () => {
12171217

12181218
// Then
12191219
expect(result).toEqual({
1220-
existingFieldNames: ['name', 'application_url', 'embedded', 'webhooks'],
1220+
existingFieldNames: ['application_url', 'embedded', 'webhooks'],
12211221
existingUpdatedFieldNames: [],
12221222
newFieldNames: [],
12231223
deletedFieldNames: ['pos'],
@@ -1808,7 +1808,7 @@ describe('configExtensionsIdentifiersBreakdown', () => {
18081808
expect(result).toEqual({
18091809
existingFieldNames: ['webhooks', 'application_url'],
18101810
existingUpdatedFieldNames: [],
1811-
newFieldNames: ['name', 'embedded'],
1811+
newFieldNames: ['embedded'],
18121812
deletedFieldNames: [],
18131813
})
18141814
})
@@ -1847,7 +1847,7 @@ describe('configExtensionsIdentifiersBreakdown', () => {
18471847
expect(result).toEqual({
18481848
existingFieldNames: [],
18491849
existingUpdatedFieldNames: [],
1850-
newFieldNames: ['name', 'application_url', 'embedded', 'webhooks'],
1850+
newFieldNames: ['application_url', 'embedded', 'webhooks'],
18511851
deletedFieldNames: [],
18521852
})
18531853
})

0 commit comments

Comments
 (0)