Skip to content

Commit 7836fb2

Browse files
committed
fix(core): handle updates to pnpm-workspace.yaml in virtual tree when reading project config
1 parent 2247d5b commit 7836fb2

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

packages/nx/src/generators/utils/project-configuration.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,15 @@ function readAndCombineAllProjectConfigurations(tree: Tree): {
254254
const patterns = [
255255
'**/project.json',
256256
'project.json',
257-
...getGlobPatternsFromPackageManagerWorkspaces(tree.root, (p) =>
258-
readJson(tree, p, { expectComments: true })
257+
...getGlobPatternsFromPackageManagerWorkspaces(
258+
tree.root,
259+
(p) => readJson(tree, p, { expectComments: true }),
260+
<T extends Object>(p) => {
261+
const content = tree.read(p, 'utf-8');
262+
const { load } = require('@zkochan/js-yaml');
263+
return load(content, { filename: p }) as T;
264+
},
265+
(p) => tree.exists(p)
259266
),
260267
];
261268
const globbedFiles = globWithWorkspaceContextSync(tree.root, patterns);

packages/nx/src/plugins/package-json/create-nodes.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,14 @@ export function buildProjectConfigurationFromPackageJson(
237237
*/
238238
export function getGlobPatternsFromPackageManagerWorkspaces(
239239
root: string,
240-
readJson: <T extends Object>(path: string) => T = <T extends Object>(path) =>
241-
readJsonFile<T>(join(root, path)) // making this an arg allows us to reuse in devkit
240+
// allow overwriting these args so we can use them in devkit
241+
readJson: <T extends Object>(path: string) => T = <T extends Object>(
242+
path: string
243+
) => readJsonFile<T>(join(root, path)),
244+
readYaml: <T extends Object>(path: string) => T = <T extends Object>(
245+
path: string
246+
) => readYamlFile<T>(join(root, path)),
247+
exists: (path: string) => boolean = (p) => existsSync(join(root, p))
242248
): string[] {
243249
try {
244250
const patterns: string[] = [];
@@ -252,12 +258,10 @@ export function getGlobPatternsFromPackageManagerWorkspaces(
252258
)
253259
);
254260

255-
if (existsSync(join(root, 'pnpm-workspace.yaml'))) {
261+
if (exists('pnpm-workspace.yaml')) {
256262
try {
257263
const { packages } =
258-
readYamlFile<{ packages: string[] }>(
259-
join(root, 'pnpm-workspace.yaml')
260-
) ?? {};
264+
readYaml<{ packages: string[] }>('pnpm-workspace.yaml') ?? {};
261265
patterns.push(...normalizePatterns(packages || []));
262266
} catch (e: unknown) {
263267
output.warn({

0 commit comments

Comments
 (0)