Skip to content

Commit c5b01df

Browse files
Merge pull request #2853 from Shopify/support-checkout-component-types-for-customer-account
support checkout component types for customer account
2 parents 2de9f9a + c08332d commit c5b01df

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

packages/ui-extensions/buildTargetDts.ts

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ import type {
1414
import {Project} from 'ts-morph';
1515

1616
function copyComponentDefinitions({
17-
srcPath,
17+
srcPaths,
1818
buildPath,
1919
surface,
2020
}: {
21-
srcPath: string;
21+
srcPaths: string[];
2222
buildPath: string;
2323
surface: string;
2424
}) {
25-
const componentsSrcPath = join(srcPath, 'components');
25+
const componentsSrcPaths = srcPaths.map((srcPath) =>
26+
join(srcPath, 'components'),
27+
);
2628
const componentsBuildPath = join(
2729
buildPath,
2830
`ts/surfaces/${surface}/components`,
@@ -31,23 +33,28 @@ function copyComponentDefinitions({
3133
mkdirSync(buildPath, {recursive: true});
3234
}
3335

34-
if (!existsSync(componentsSrcPath)) {
36+
const exists = componentsSrcPaths.every((path) => existsSync(path));
37+
38+
if (!exists) {
3539
// eslint-disable-next-line no-console
3640
console.log('No components to copy');
3741
return false;
3842
}
3943

40-
const components = readdirSync(componentsSrcPath);
41-
components
42-
.filter((file) => {
43-
return file.endsWith('d.ts');
44-
})
45-
.forEach((file) => {
46-
copyFileSync(
47-
join(componentsSrcPath, file),
48-
join(componentsBuildPath, file),
49-
);
50-
});
44+
componentsSrcPaths.forEach((componentsSrcPath) => {
45+
const components = readdirSync(componentsSrcPath);
46+
components
47+
.filter((file) => {
48+
return file.endsWith('d.ts');
49+
})
50+
.forEach((file) => {
51+
copyFileSync(
52+
join(componentsSrcPath, file),
53+
join(componentsBuildPath, file),
54+
);
55+
});
56+
});
57+
5158
return true;
5259
}
5360

@@ -82,20 +89,23 @@ export type GlobalThis = typeof globalThis & {
8289
}
8390

8491
function processComponentDefinitions({
85-
srcPath,
92+
srcPaths,
8693
project,
8794
componentName,
8895
names,
8996
targetFile,
9097
}: {
91-
srcPath: string;
98+
srcPaths: string[];
9299
project: Project;
93100
componentName: string;
94101
names: Set<string>;
95102
targetFile: SourceFile;
96103
}) {
97-
const componentSourcePath = join(srcPath, `components/${componentName}.d.ts`);
98-
if (!existsSync(componentSourcePath)) {
104+
const componentSourcePath = srcPaths
105+
.map((srcPath) => join(srcPath, `components/${componentName}.d.ts`))
106+
.find((path) => existsSync(path));
107+
108+
if (!componentSourcePath) {
99109
// eslint-disable-next-line no-console
100110
console.log(
101111
`Component ${componentName} not found in ${componentSourcePath}`,
@@ -199,13 +209,13 @@ function extractTargetComponents(
199209
}
200210

201211
function createTargetDefinition({
202-
srcPath,
212+
srcPaths,
203213
buildPath,
204214
project,
205215
surface,
206216
target: {name, components},
207217
}: {
208-
srcPath: string;
218+
srcPaths: string[];
209219
buildPath: string;
210220
project: Project;
211221
surface: string;
@@ -221,7 +231,7 @@ function createTargetDefinition({
221231
componentName,
222232
names,
223233
targetFile,
224-
srcPath,
234+
srcPaths,
225235
});
226236
});
227237

@@ -230,11 +240,25 @@ function createTargetDefinition({
230240
targetFile.saveSync();
231241
}
232242

233-
export function buildTargetsDefinitions(directory: string, surface: string) {
243+
export function buildTargetsDefinitions(
244+
directory: string,
245+
surface: string,
246+
additionalComponentPaths: string[] = [],
247+
) {
234248
const project = new Project();
235249
const buildPath = resolve(directory, 'build');
236250
const srcPath = resolve(directory, `src/surfaces/${surface}`);
237-
const success = copyComponentDefinitions({srcPath, buildPath, surface});
251+
252+
const componentSrcPaths = [
253+
srcPath,
254+
...additionalComponentPaths.map((path) => resolve(directory, path)),
255+
];
256+
const success = copyComponentDefinitions({
257+
srcPaths: componentSrcPaths,
258+
buildPath,
259+
surface,
260+
});
261+
238262
if (!success) {
239263
// eslint-disable-next-line no-console
240264
console.log('Failed to copy components');
@@ -248,7 +272,7 @@ export function buildTargetsDefinitions(directory: string, surface: string) {
248272
const targets = extractTargetComponents(sourceFile);
249273
targets.forEach((target) => {
250274
createTargetDefinition({
251-
srcPath,
275+
srcPaths: componentSrcPaths,
252276
buildPath,
253277
project,
254278
surface,

packages/ui-extensions/loom.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default createPackage((pkg) => {
6161
buildTargetsDefinitions(
6262
resolve(process.cwd(), 'packages/ui-extensions'),
6363
'customer-account',
64+
['src/surfaces/checkout'],
6465
);
6566
completedSurfaces.add('customer-account');
6667
}

packages/ui-extensions/src/surfaces/customer-account/components/StandardComponents.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import {AnyComponent} from '../../checkout';
2+
13
export type StandardComponents =
4+
| AnyComponent
25
| 'Page'
36
| 'CustomerAccountAction'
47
| 'ImageGroup';

0 commit comments

Comments
 (0)