Skip to content

Commit f26d5ab

Browse files
committed
fix(tools): fail gracefully when workspaces arent found
1 parent f71bfa9 commit f26d5ab

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.changeset/big-dingos-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@patternfly/pfe-tools": patch
3+
---
4+
5+
fail gracefully when dev server can't find workspace packages

tools/pfe-tools/dev-server.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function appendLines(body: string, ...lines: string[]): string {
2626
return [body, ...lines].join('\n');
2727
}
2828

29+
async function tryRead(pathname: string) {
30+
return readdir(pathname).catch(() => []);
31+
}
32+
2933
/**
3034
* Binds data from the node context to the dev-server's browser context.
3135
* exposed data is available by importing `@patternfly/pfe-tools/environment.js`.
@@ -38,12 +42,12 @@ function bindNodeDataToBrowser(options?: PfeDevServerConfigOptions): Plugin {
3842
if (context.path.endsWith('pfe-tools/environment.js')) {
3943
// TODO: calculate export names from npm workspaces
4044
// for now, `elements` is the only conventionally-supported workspace
41-
const elements = await readdir(join(rootDir, 'elements'));
42-
const core = await readdir(join(rootDir, 'core'));
45+
const elements = await tryRead(join(rootDir, 'elements'));
46+
const core = await tryRead(join(rootDir, 'core'));
4347
const transformed = appendLines(
4448
context.body as string,
4549
`export const elements = ${JSON.stringify(elements)};`,
46-
`export const core = ${JSON.stringify(core)};`
50+
`export const core = ${JSON.stringify(core)};`
4751
);
4852
return transformed;
4953
}

0 commit comments

Comments
 (0)