Skip to content

Commit

Permalink
fix(core): handle updates to pnpm-workspace.yaml in virtual tree when…
Browse files Browse the repository at this point in the history
… reading project config
  • Loading branch information
jaysoo committed Jan 21, 2025
1 parent 8d22e69 commit 8ae3480
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 9 additions & 2 deletions packages/nx/src/generators/utils/project-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,15 @@ function readAndCombineAllProjectConfigurations(tree: Tree): {
const patterns = [
'**/project.json',
'project.json',
...getGlobPatternsFromPackageManagerWorkspaces(tree.root, (p) =>
readJson(tree, p, { expectComments: true })
...getGlobPatternsFromPackageManagerWorkspaces(
tree.root,
(p) => readJson(tree, p, { expectComments: true }),
<T extends Object>(p) => {
const content = tree.read(p, 'utf-8');
const { load } = require('@zkochan/js-yaml');
return load(content, { filename: p }) as T;
},
(p) => tree.exists(p)
),
];
const globbedFiles = globWithWorkspaceContextSync(tree.root, patterns);
Expand Down
16 changes: 10 additions & 6 deletions packages/nx/src/plugins/package-json/create-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,14 @@ export function buildProjectConfigurationFromPackageJson(
*/
export function getGlobPatternsFromPackageManagerWorkspaces(
root: string,
readJson: <T extends Object>(path: string) => T = <T extends Object>(path) =>
readJsonFile<T>(join(root, path)) // making this an arg allows us to reuse in devkit
// allow overwriting these args so we can use them in devkit
readJson: <T extends Object>(path: string) => T = <T extends Object>(
path: string
) => readJsonFile<T>(join(root, path)),
readYaml: <T extends Object>(path: string) => T = <T extends Object>(
path: string
) => readYamlFile<T>(join(root, path)),
exists: (path: string) => boolean = (p) => existsSync(join(root, p))
): string[] {
try {
const patterns: string[] = [];
Expand All @@ -252,12 +258,10 @@ export function getGlobPatternsFromPackageManagerWorkspaces(
)
);

if (existsSync(join(root, 'pnpm-workspace.yaml'))) {
if (exists('pnpm-workspace.yaml')) {
try {
const { packages } =
readYamlFile<{ packages: string[] }>(
join(root, 'pnpm-workspace.yaml')
) ?? {};
readYaml<{ packages: string[] }>('pnpm-workspace.yaml') ?? {};
patterns.push(...normalizePatterns(packages || []));
} catch (e: unknown) {
output.warn({
Expand Down

0 comments on commit 8ae3480

Please sign in to comment.