Skip to content

Commit 3cbca04

Browse files
committed
Reduce diff
1 parent f17aee3 commit 3cbca04

2 files changed

Lines changed: 22 additions & 66 deletions

File tree

packages/app/src/cli/models/extensions/specifications/type-generation.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ export function createTypeDefinition({
331331
...(intentsTypeDefinition ? [intentsTypeDefinition] : []),
332332
...(shopifyUtilityTypes ? [shopifyUtilityTypes] : []),
333333
` const shopify: ${shopifyType};`,
334-
' const globalThis: {',
335-
' shopify: typeof shopify;',
336-
' };',
334+
' const globalThis: { shopify: typeof shopify };',
337335
'}',
338336
'',
339337
]

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

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,15 +1284,11 @@ Please check the configuration in ${uiExtension.configurationPath}`),
12841284
new Set([
12851285
`//@ts-ignore\ndeclare module './src/index.jsx' {
12861286
const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;
1287-
const globalThis: {
1288-
shopify: typeof shopify;
1289-
};
1287+
const globalThis: { shopify: typeof shopify };
12901288
}\n`,
12911289
`//@ts-ignore\ndeclare module './src/condition/should-render.js' {
12921290
const shopify: import('@shopify/ui-extensions/admin.product-details.action.should-render').Api;
1293-
const globalThis: {
1294-
shopify: typeof shopify;
1295-
};
1291+
const globalThis: { shopify: typeof shopify };
12961292
}\n`,
12971293
]),
12981294
],
@@ -1349,15 +1345,11 @@ Please check the configuration in ${uiExtension.configurationPath}`),
13491345
new Set([
13501346
`//@ts-ignore\ndeclare module './src/index.jsx' {
13511347
const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;
1352-
const globalThis: {
1353-
shopify: typeof shopify;
1354-
};
1348+
const globalThis: { shopify: typeof shopify };
13551349
}\n`,
13561350
`//@ts-ignore\ndeclare module './src/another-target-module.jsx' {
13571351
const shopify: import('@shopify/ui-extensions/admin.orders-details.block.render').Api;
1358-
const globalThis: {
1359-
shopify: typeof shopify;
1360-
};
1352+
const globalThis: { shopify: typeof shopify };
13611353
}\n`,
13621354
]),
13631355
],
@@ -1366,9 +1358,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
13661358
new Set([
13671359
`//@ts-ignore\ndeclare module './should-render.js' {
13681360
const shopify: import('@shopify/ui-extensions/admin.product-details.action.should-render').Api;
1369-
const globalThis: {
1370-
shopify: typeof shopify;
1371-
};
1361+
const globalThis: { shopify: typeof shopify };
13721362
}\n`,
13731363
]),
13741364
],
@@ -1483,14 +1473,10 @@ Please check the configuration in ${uiExtension.configurationPath}`),
14831473

14841474
// Then - should include types for imported modules when single target
14851475
expect(Array.from(typeDefinitionsByFile.get(shopifyDtsPath) ?? [])).toContain(
1486-
`//@ts-ignore\ndeclare module './src/utils/helper.js' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1487-
shopify: typeof shopify;
1488-
};\n}\n`,
1476+
`//@ts-ignore\ndeclare module './src/utils/helper.js' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
14891477
)
14901478
expect(Array.from(typeDefinitionsByFile.get(shopifyDtsPath) ?? [])).toContain(
1491-
`//@ts-ignore\ndeclare module './src/components/Button.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1492-
shopify: typeof shopify;
1493-
};\n}\n`,
1479+
`//@ts-ignore\ndeclare module './src/components/Button.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
14941480
)
14951481
})
14961482
})
@@ -1549,9 +1535,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
15491535

15501536
// Then - should generate union type for shared module
15511537
expect(Array.from(types ?? [])).toContain(
1552-
`//@ts-ignore\ndeclare module './shared/utils.js' {\n const shopify:\n | import('@shopify/ui-extensions/admin.product-details.action.render').Api\n | import('@shopify/ui-extensions/admin.orders-details.block.render').Api;\n const globalThis: {
1553-
shopify: typeof shopify;
1554-
};\n}\n`,
1538+
`//@ts-ignore\ndeclare module './shared/utils.js' {\n const shopify:\n | import('@shopify/ui-extensions/admin.product-details.action.render').Api\n | import('@shopify/ui-extensions/admin.orders-details.block.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
15551539
)
15561540
})
15571541
})
@@ -1612,9 +1596,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
16121596
// Then - should generate union types for shared files
16131597
// when targets are from different surfaces (admin vs checkout)
16141598
expect(types).toContain(
1615-
`//@ts-ignore\ndeclare module './src/components/Shared.jsx' {\n const shopify:\n | import('@shopify/ui-extensions/admin.product-details.action.render').Api\n | import('@shopify/ui-extensions/purchase.checkout.block.render').Api;\n const globalThis: {
1616-
shopify: typeof shopify;
1617-
};\n}\n`,
1599+
`//@ts-ignore\ndeclare module './src/components/Shared.jsx' {\n const shopify:\n | import('@shopify/ui-extensions/admin.product-details.action.render').Api\n | import('@shopify/ui-extensions/purchase.checkout.block.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
16181600
)
16191601
})
16201602
})
@@ -1664,14 +1646,10 @@ Please check the configuration in ${uiExtension.configurationPath}`),
16641646

16651647
// Then - should resolve aliased imports and include types
16661648
expect(Array.from(typeDefinitionsByFile.get(shopifyDtsPath) ?? [])).toContain(
1667-
`//@ts-ignore\ndeclare module './src/utils/helper.js' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1668-
shopify: typeof shopify;
1669-
};\n}\n`,
1649+
`//@ts-ignore\ndeclare module './src/utils/helper.js' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
16701650
)
16711651
expect(Array.from(typeDefinitionsByFile.get(shopifyDtsPath) ?? [])).toContain(
1672-
`//@ts-ignore\ndeclare module './src/components/Button.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1673-
shopify: typeof shopify;
1674-
};\n}\n`,
1652+
`//@ts-ignore\ndeclare module './src/components/Button.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
16751653
)
16761654
})
16771655
})
@@ -1742,9 +1720,7 @@ Please check the configuration in ${uiExtension.configurationPath}`),
17421720

17431721
const extensionTypes = typeDefinitionsByFile.get(extensionShopifyDtsPath)
17441722
expect(Array.from(extensionTypes ?? [])).toContain(
1745-
`//@ts-ignore\ndeclare module './src/index.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1746-
shopify: typeof shopify;
1747-
};\n}\n`,
1723+
`//@ts-ignore\ndeclare module './src/index.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
17481724
)
17491725

17501726
expect(Array.from(extensionTypes ?? [])).not.toContain(expect.stringContaining('helpers/utils.ts'))
@@ -1818,14 +1794,10 @@ Please check the configuration in ${uiExtension.configurationPath}`),
18181794

18191795
// Then - should include type definition for both the main file and the root-level shared file
18201796
expect(Array.from(types ?? [])).toContain(
1821-
`//@ts-ignore\ndeclare module './src/extension.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1822-
shopify: typeof shopify;
1823-
};\n}\n`,
1797+
`//@ts-ignore\ndeclare module './src/extension.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
18241798
)
18251799
expect(Array.from(types ?? [])).toContain(
1826-
`//@ts-ignore\ndeclare module './shared_file.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1827-
shopify: typeof shopify;
1828-
};\n}\n`,
1800+
`//@ts-ignore\ndeclare module './shared_file.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
18291801
)
18301802
})
18311803
})
@@ -1918,24 +1890,16 @@ Please check the configuration in ${uiExtension.configurationPath}`),
19181890
// Then - should include type definitions for all files:
19191891
// main file, component, and both root-level shared files
19201892
expect(types).toContain(
1921-
`//@ts-ignore\ndeclare module './src/extension.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1922-
shopify: typeof shopify;
1923-
};\n}\n`,
1893+
`//@ts-ignore\ndeclare module './src/extension.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
19241894
)
19251895
expect(types).toContain(
1926-
`//@ts-ignore\ndeclare module './src/components/Component.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1927-
shopify: typeof shopify;
1928-
};\n}\n`,
1896+
`//@ts-ignore\ndeclare module './src/components/Component.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
19291897
)
19301898
expect(types).toContain(
1931-
`//@ts-ignore\ndeclare module './shared_file.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1932-
shopify: typeof shopify;
1933-
};\n}\n`,
1899+
`//@ts-ignore\ndeclare module './shared_file.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
19341900
)
19351901
expect(types).toContain(
1936-
`//@ts-ignore\ndeclare module './utils.js' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
1937-
shopify: typeof shopify;
1938-
};\n}\n`,
1902+
`//@ts-ignore\ndeclare module './utils.js' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
19391903
)
19401904
})
19411905
})
@@ -2030,23 +1994,17 @@ Please check the configuration in ${uiExtension.configurationPath}`),
20301994
// Then - should include type definitions for all files in the chain:
20311995
// 1. Main extension file
20321996
expect(types).toContain(
2033-
`//@ts-ignore\ndeclare module './src/extension.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
2034-
shopify: typeof shopify;
2035-
};\n}\n`,
1997+
`//@ts-ignore\ndeclare module './src/extension.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
20361998
)
20371999

20382000
// 2. Component file that imports from root
20392001
expect(types).toContain(
2040-
`//@ts-ignore\ndeclare module './src/components/Button.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
2041-
shopify: typeof shopify;
2042-
};\n}\n`,
2002+
`//@ts-ignore\ndeclare module './src/components/Button.jsx' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
20432003
)
20442004

20452005
// 3. Root-level shared file (imported by component, not directly by extension)
20462006
expect(types).toContain(
2047-
`//@ts-ignore\ndeclare module './shared_utils.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: {
2048-
shopify: typeof shopify;
2049-
};\n}\n`,
2007+
`//@ts-ignore\ndeclare module './shared_utils.ts' {\n const shopify: import('@shopify/ui-extensions/admin.product-details.action.render').Api;\n const globalThis: { shopify: typeof shopify };\n}\n`,
20502008
)
20512009

20522010
// Verify we have exactly 3 type definitions (no duplicates)

0 commit comments

Comments
 (0)