You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@nx/devkit

Package Overview
Dependencies
Maintainers
5
Versions
1716
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nx/devkit - npm Package Compare versions

Comparing version
22.6.0-beta.2
to
22.6.0-beta.3
+22
src/utils/catalog/yarn-manager.d.ts
import { type Tree } from 'nx/src/devkit-exports';
import { type CatalogManager } from './manager';
import type { CatalogDefinitions, CatalogReference } from './types';
/**
* Yarn Berry (v4+) catalog manager implementation
*/
export declare class YarnCatalogManager implements CatalogManager {
readonly name = "yarn";
readonly catalogProtocol = "catalog:";
isCatalogReference(version: string): boolean;
parseCatalogReference(version: string): CatalogReference | null;
getCatalogDefinitionFilePaths(): string[];
getCatalogDefinitions(treeOrRoot: Tree | string): CatalogDefinitions | null;
resolveCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): string | null;
validateCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): void;
updateCatalogVersions(treeOrRoot: Tree | string, updates: Array<{
packageName: string;
version: string;
catalogName?: string;
}>): void;
}
//# sourceMappingURL=yarn-manager.d.ts.map
{"version":3,"file":"yarn-manager.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/yarn-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,KAAK,EACV,kBAAkB,EAElB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,QAAQ,CAAC,IAAI,UAAU;IACvB,QAAQ,CAAC,eAAe,cAAc;IAEtC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI5C,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAe/D,6BAA6B,IAAI,MAAM,EAAE;IAIzC,qBAAqB,CAAC,UAAU,EAAE,IAAI,GAAG,MAAM,GAAG,kBAAkB,GAAG,IAAI;IAe3E,uBAAuB,CACrB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI;IAsBhB,wBAAwB,CACtB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,IAAI;IAyHP,qBAAqB,CACnB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,OAAO,EAAE,KAAK,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,GACD,IAAI;CA+ER"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.YarnCatalogManager = void 0;
const js_yaml_1 = require("@zkochan/js-yaml");
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const devkit_exports_1 = require("nx/src/devkit-exports");
const devkit_internals_1 = require("nx/src/devkit-internals");
const manager_1 = require("./manager");
const YARNRC_FILENAME = '.yarnrc.yml';
/**
* Yarn Berry (v4+) catalog manager implementation
*/
class YarnCatalogManager {
constructor() {
this.name = 'yarn';
this.catalogProtocol = 'catalog:';
}
isCatalogReference(version) {
return version.startsWith(this.catalogProtocol);
}
parseCatalogReference(version) {
if (!this.isCatalogReference(version)) {
return null;
}
const catalogName = version.substring(this.catalogProtocol.length);
// Normalize both "catalog:" and "catalog:default" to the same representation
const isDefault = !catalogName || catalogName === 'default';
return {
catalogName: isDefault ? undefined : catalogName,
isDefaultCatalog: isDefault,
};
}
getCatalogDefinitionFilePaths() {
return [YARNRC_FILENAME];
}
getCatalogDefinitions(treeOrRoot) {
if (typeof treeOrRoot === 'string') {
const configPath = (0, node_path_1.join)(treeOrRoot, YARNRC_FILENAME);
if (!(0, node_fs_1.existsSync)(configPath)) {
return null;
}
return readConfigFromFs(configPath);
}
else {
if (!treeOrRoot.exists(YARNRC_FILENAME)) {
return null;
}
return readConfigFromTree(treeOrRoot, YARNRC_FILENAME);
}
}
resolveCatalogReference(treeOrRoot, packageName, version) {
const catalogRef = this.parseCatalogReference(version);
if (!catalogRef) {
return null;
}
const catalogDefs = this.getCatalogDefinitions(treeOrRoot);
if (!catalogDefs) {
return null;
}
let catalogToUse;
if (catalogRef.isDefaultCatalog) {
// Check both locations for default catalog
catalogToUse = catalogDefs.catalog ?? catalogDefs.catalogs?.default;
}
else if (catalogRef.catalogName) {
catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
}
return catalogToUse?.[packageName] || null;
}
validateCatalogReference(treeOrRoot, packageName, version) {
const catalogRef = this.parseCatalogReference(version);
if (!catalogRef) {
throw new Error(`Invalid catalog reference syntax: "${version}". Expected format: "catalog:" or "catalog:name"`);
}
const catalogDefs = this.getCatalogDefinitions(treeOrRoot);
if (!catalogDefs) {
throw new Error((0, manager_1.formatCatalogError)(`Cannot get Yarn catalog definitions. No ${YARNRC_FILENAME} found in workspace root.`, [`Create a ${YARNRC_FILENAME} file in your workspace root`]));
}
let catalogToUse;
if (catalogRef.isDefaultCatalog) {
const hasCatalog = !!catalogDefs.catalog;
const hasCatalogsDefault = !!catalogDefs.catalogs?.default;
// Error if both defined
if (hasCatalog && hasCatalogsDefault) {
throw new Error("The 'default' catalog was defined multiple times. Use the 'catalog' field or 'catalogs.default', but not both.");
}
catalogToUse = catalogDefs.catalog ?? catalogDefs.catalogs?.default;
if (!catalogToUse) {
const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
const suggestions = [
`Define a default catalog in ${YARNRC_FILENAME} under the "catalog" key`,
];
if (availableCatalogs.length > 0) {
suggestions.push(`Or select from the available named catalogs: ${availableCatalogs
.map((c) => `"catalog:${c}"`)
.join(', ')}`);
}
throw new Error((0, manager_1.formatCatalogError)(`No default catalog defined in ${YARNRC_FILENAME}`, suggestions));
}
}
else if (catalogRef.catalogName) {
catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
if (!catalogToUse) {
const availableCatalogs = Object.keys(catalogDefs.catalogs || {}).filter((c) => c !== 'default');
const defaultCatalog = !!catalogDefs.catalog
? 'catalog'
: !catalogDefs.catalogs?.default
? 'catalogs.default'
: null;
const suggestions = [
`Define the catalog in ${YARNRC_FILENAME} under the "catalogs" key`,
];
if (availableCatalogs.length > 0) {
suggestions.push(`Or select from the available named catalogs: ${availableCatalogs
.map((c) => `"catalog:${c}"`)
.join(', ')}`);
}
if (defaultCatalog) {
suggestions.push(`Or use the default catalog ("${defaultCatalog}")`);
}
throw new Error((0, manager_1.formatCatalogError)(`Catalog "${catalogRef.catalogName}" not found in ${YARNRC_FILENAME}`, suggestions));
}
}
if (!catalogToUse[packageName]) {
let catalogName;
if (catalogRef.isDefaultCatalog) {
// Context-aware messaging based on which location exists
const hasCatalog = !!catalogDefs.catalog;
catalogName = hasCatalog
? 'default catalog ("catalog")'
: 'default catalog ("catalogs.default")';
}
else {
catalogName = `catalog '${catalogRef.catalogName}'`;
}
const availablePackages = Object.keys(catalogToUse);
const suggestions = [
`Add "${packageName}" to ${catalogName} in ${YARNRC_FILENAME}`,
];
if (availablePackages.length > 0) {
suggestions.push(`Or select from the available packages in ${catalogName}: ${availablePackages
.map((p) => `"${p}"`)
.join(', ')}`);
}
throw new Error((0, manager_1.formatCatalogError)(`Package "${packageName}" not found in ${catalogName}`, suggestions));
}
}
updateCatalogVersions(treeOrRoot, updates) {
let checkExists;
let readYaml;
let writeYaml;
if (typeof treeOrRoot === 'string') {
const configPath = (0, node_path_1.join)(treeOrRoot, YARNRC_FILENAME);
checkExists = () => (0, node_fs_1.existsSync)(configPath);
readYaml = () => (0, node_fs_1.readFileSync)(configPath, 'utf-8');
writeYaml = (content) => (0, node_fs_1.writeFileSync)(configPath, content, 'utf-8');
}
else {
checkExists = () => treeOrRoot.exists(YARNRC_FILENAME);
readYaml = () => treeOrRoot.read(YARNRC_FILENAME, 'utf-8');
writeYaml = (content) => treeOrRoot.write(YARNRC_FILENAME, content);
}
if (!checkExists()) {
devkit_exports_1.output.warn({
title: `No ${YARNRC_FILENAME} found`,
bodyLines: [
`Cannot update catalog versions without a ${YARNRC_FILENAME} file.`,
`Create a ${YARNRC_FILENAME} file to use catalogs.`,
],
});
return;
}
try {
const configContent = readYaml();
const configData = (0, js_yaml_1.load)(configContent) || {};
let hasChanges = false;
for (const update of updates) {
const { packageName, version, catalogName } = update;
const normalizedCatalogName = catalogName === 'default' ? undefined : catalogName;
let targetCatalog;
if (!normalizedCatalogName) {
// Default catalog - update whichever exists, prefer catalog over catalogs.default
if (configData.catalog) {
targetCatalog = configData.catalog;
}
else if (configData.catalogs?.default) {
targetCatalog = configData.catalogs.default;
}
else {
// Neither exists, create catalog (shorthand syntax)
configData.catalog ??= {};
targetCatalog = configData.catalog;
}
}
else {
// Named catalog
configData.catalogs ??= {};
configData.catalogs[normalizedCatalogName] ??= {};
targetCatalog = configData.catalogs[normalizedCatalogName];
}
if (targetCatalog[packageName] !== version) {
targetCatalog[packageName] = version;
hasChanges = true;
}
}
if (hasChanges) {
writeYaml((0, js_yaml_1.dump)(configData, {
indent: 2,
quotingType: '"',
forceQuotes: true,
}));
}
}
catch (error) {
devkit_exports_1.output.error({
title: 'Failed to update catalog versions',
bodyLines: [error instanceof Error ? error.message : String(error)],
});
throw error;
}
}
}
exports.YarnCatalogManager = YarnCatalogManager;
function readConfigFromFs(path) {
try {
return (0, devkit_internals_1.readYamlFile)(path);
}
catch (error) {
devkit_exports_1.output.warn({
title: `Unable to parse ${YARNRC_FILENAME}`,
bodyLines: [error.toString()],
});
return null;
}
}
function readConfigFromTree(tree, path) {
const content = tree.read(path, 'utf-8');
try {
return (0, js_yaml_1.load)(content, { filename: path });
}
catch (error) {
devkit_exports_1.output.warn({
title: `Unable to parse ${YARNRC_FILENAME}`,
bodyLines: [error.toString()],
});
return null;
}
}
+3
-3
{
"name": "@nx/devkit",
"version": "22.6.0-beta.2",
"version": "22.6.0-beta.3",
"private": false,

@@ -36,3 +36,3 @@ "description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more. Learn more about [extending Nx by leveraging the Nx Devkit](https://nx.dev/extending-nx/intro/getting-started) on our docs.",

"yargs-parser": "21.1.1",
"minimatch": "10.1.1",
"minimatch": "10.2.1",
"enquirer": "~2.3.6"

@@ -42,3 +42,3 @@ },

"jest": "^30.0.2",
"nx": "22.6.0-beta.2"
"nx": "22.6.0-beta.3"
},

@@ -45,0 +45,0 @@ "peerDependencies": {

@@ -1,1 +0,1 @@

{"version":3,"file":"manager-factory.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/manager-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGhD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,MAAM,GACpB,cAAc,GAAG,IAAI,CASvB"}
{"version":3,"file":"manager-factory.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/manager-factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIhD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,MAAM,GACpB,cAAc,GAAG,IAAI,CAWvB"}

@@ -6,2 +6,3 @@ "use strict";

const pnpm_manager_1 = require("./pnpm-manager");
const yarn_manager_1 = require("./yarn-manager");
/**

@@ -15,2 +16,4 @@ * Factory function to get the appropriate catalog manager based on the package manager

return new pnpm_manager_1.PnpmCatalogManager();
case 'yarn':
return new yarn_manager_1.YarnCatalogManager();
default:

@@ -17,0 +20,0 @@ return null;

import type { Tree } from 'nx/src/devkit-exports';
import type { PnpmWorkspaceYaml } from 'nx/src/utils/pnpm-workspace';
import type { CatalogReference } from './types';
import type { CatalogDefinitions, CatalogReference } from './types';
export declare function formatCatalogError(error: string, suggestions: string[]): string;
/**

@@ -11,7 +11,8 @@ * Interface for catalog managers that handle package manager-specific catalog implementations.

parseCatalogReference(version: string): CatalogReference | null;
getCatalogDefinitionFilePaths(): string[];
/**
* Get catalog definitions from the workspace.
*/
getCatalogDefinitions(workspaceRoot: string): PnpmWorkspaceYaml | null;
getCatalogDefinitions(tree: Tree): PnpmWorkspaceYaml | null;
getCatalogDefinitions(workspaceRoot: string): CatalogDefinitions | null;
getCatalogDefinitions(tree: Tree): CatalogDefinitions | null;
/**

@@ -18,0 +19,0 @@ * Resolve a catalog reference to an actual version.

@@ -1,1 +0,1 @@

{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAE7C,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAEhE;;OAEG;IACH,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAAC;IACvE,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,iBAAiB,GAAG,IAAI,CAAC;IAE5D;;OAEG;IACH,uBAAuB,CACrB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CAAC;IACjB,uBAAuB,CACrB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CAAC;IAEjB;;OAEG;IACH,wBAAwB,CACtB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,IAAI,CAAC;IACR,wBAAwB,CACtB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,IAAI,CAAC;IAER;;OAEG;IACH,qBAAqB,CACnB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,KAAK,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,GACD,IAAI,CAAC;IACR,qBAAqB,CACnB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,KAAK,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,GACD,IAAI,CAAC;CACT"}
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEpE,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EAAE,GACpB,MAAM,CAWR;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAE7C,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAAC;IAEhE,6BAA6B,IAAI,MAAM,EAAE,CAAC;IAE1C;;OAEG;IACH,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAAC;IACxE,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,kBAAkB,GAAG,IAAI,CAAC;IAE7D;;OAEG;IACH,uBAAuB,CACrB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CAAC;IACjB,uBAAuB,CACrB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CAAC;IAEjB;;OAEG;IACH,wBAAwB,CACtB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,IAAI,CAAC;IACR,wBAAwB,CACtB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,IAAI,CAAC;IAER;;OAEG;IACH,qBAAqB,CACnB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,KAAK,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,GACD,IAAI,CAAC;IACR,qBAAqB,CACnB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,KAAK,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,GACD,IAAI,CAAC;CACT"}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatCatalogError = formatCatalogError;
function formatCatalogError(error, suggestions) {
let message = error;
if (suggestions.length > 0) {
message += '\n\nSuggestions:';
suggestions.forEach((suggestion) => {
message += `\n • ${suggestion}`;
});
}
return message;
}
import { type Tree } from 'nx/src/devkit-exports';
import type { PnpmWorkspaceYaml } from 'nx/src/utils/pnpm-workspace';
import type { CatalogManager } from './manager';
import { type CatalogReference } from './types';
import { type CatalogManager } from './manager';
import type { CatalogDefinitions, CatalogReference } from './types';
/**

@@ -13,3 +12,4 @@ * PNPM-specific catalog manager implementation

parseCatalogReference(version: string): CatalogReference | null;
getCatalogDefinitions(treeOrRoot: Tree | string): PnpmWorkspaceYaml | null;
getCatalogDefinitionFilePaths(): string[];
getCatalogDefinitions(treeOrRoot: Tree | string): CatalogDefinitions | null;
resolveCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): string | null;

@@ -16,0 +16,0 @@ validateCatalogReference(treeOrRoot: Tree | string, packageName: string, version: string): void;

@@ -1,1 +0,1 @@

{"version":3,"file":"pnpm-manager.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/pnpm-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,QAAQ,CAAC,IAAI,UAAU;IACvB,QAAQ,CAAC,eAAe,cAAc;IAEtC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI5C,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAe/D,qBAAqB,CAAC,UAAU,EAAE,IAAI,GAAG,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAe1E,uBAAuB,CACrB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI;IAuBhB,wBAAwB,CACtB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,IAAI;IA0HP,qBAAqB,CACnB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,OAAO,EAAE,KAAK,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,GACD,IAAI;CAgFR"}
{"version":3,"file":"pnpm-manager.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/pnpm-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,KAAK,EACV,kBAAkB,EAElB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAIjB;;GAEG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,QAAQ,CAAC,IAAI,UAAU;IACvB,QAAQ,CAAC,eAAe,cAAc;IAEtC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI5C,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI;IAe/D,6BAA6B,IAAI,MAAM,EAAE;IAIzC,qBAAqB,CAAC,UAAU,EAAE,IAAI,GAAG,MAAM,GAAG,kBAAkB,GAAG,IAAI;IAe3E,uBAAuB,CACrB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI;IAsBhB,wBAAwB,CACtB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,GACd,IAAI;IAyHP,qBAAqB,CACnB,UAAU,EAAE,IAAI,GAAG,MAAM,EACzB,OAAO,EAAE,KAAK,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,GACD,IAAI;CAgFR"}

@@ -9,2 +9,4 @@ "use strict";

const devkit_internals_1 = require("nx/src/devkit-internals");
const manager_1 = require("./manager");
const PNPM_WORKSPACE_FILENAME = 'pnpm-workspace.yaml';
/**

@@ -33,15 +35,18 @@ * PNPM-specific catalog manager implementation

}
getCatalogDefinitionFilePaths() {
return [PNPM_WORKSPACE_FILENAME];
}
getCatalogDefinitions(treeOrRoot) {
if (typeof treeOrRoot === 'string') {
const pnpmWorkspacePath = (0, node_path_1.join)(treeOrRoot, 'pnpm-workspace.yaml');
if (!(0, node_fs_1.existsSync)(pnpmWorkspacePath)) {
const configPath = (0, node_path_1.join)(treeOrRoot, PNPM_WORKSPACE_FILENAME);
if (!(0, node_fs_1.existsSync)(configPath)) {
return null;
}
return readYamlFileFromFs(pnpmWorkspacePath);
return readConfigFromFs(configPath);
}
else {
if (!treeOrRoot.exists('pnpm-workspace.yaml')) {
if (!treeOrRoot.exists(PNPM_WORKSPACE_FILENAME)) {
return null;
}
return readYamlFileFromTree(treeOrRoot, 'pnpm-workspace.yaml');
return readConfigFromTree(treeOrRoot, PNPM_WORKSPACE_FILENAME);
}

@@ -54,4 +59,4 @@ }

}
const workspaceConfig = this.getCatalogDefinitions(treeOrRoot);
if (!workspaceConfig) {
const catalogDefs = this.getCatalogDefinitions(treeOrRoot);
if (!catalogDefs) {
return null;

@@ -62,7 +67,6 @@ }

// Check both locations for default catalog
catalogToUse =
workspaceConfig.catalog ?? workspaceConfig.catalogs?.default;
catalogToUse = catalogDefs.catalog ?? catalogDefs.catalogs?.default;
}
else if (catalogRef.catalogName) {
catalogToUse = workspaceConfig.catalogs?.[catalogRef.catalogName];
catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
}

@@ -76,10 +80,10 @@ return catalogToUse?.[packageName] || null;

}
const workspaceConfig = this.getCatalogDefinitions(treeOrRoot);
if (!workspaceConfig) {
throw new Error(formatCatalogError('Cannot get Pnpm Catalog definitions. No pnpm-workspace.yaml found in workspace root.', ['Create a pnpm-workspace.yaml file in your workspace root']));
const catalogDefs = this.getCatalogDefinitions(treeOrRoot);
if (!catalogDefs) {
throw new Error((0, manager_1.formatCatalogError)(`Cannot get Pnpm catalog definitions. No ${PNPM_WORKSPACE_FILENAME} found in workspace root.`, [`Create a ${PNPM_WORKSPACE_FILENAME} file in your workspace root`]));
}
let catalogToUse;
if (catalogRef.isDefaultCatalog) {
const hasCatalog = !!workspaceConfig.catalog;
const hasCatalogsDefault = !!workspaceConfig.catalogs?.default;
const hasCatalog = !!catalogDefs.catalog;
const hasCatalogsDefault = !!catalogDefs.catalogs?.default;
// Error if both defined (matches pnpm behavior)

@@ -89,8 +93,7 @@ if (hasCatalog && hasCatalogsDefault) {

}
catalogToUse =
workspaceConfig.catalog ?? workspaceConfig.catalogs?.default;
catalogToUse = catalogDefs.catalog ?? catalogDefs.catalogs?.default;
if (!catalogToUse) {
const availableCatalogs = Object.keys(workspaceConfig.catalogs || {});
const availableCatalogs = Object.keys(catalogDefs.catalogs || {});
const suggestions = [
'Define a default catalog in pnpm-workspace.yaml under the "catalog" key',
`Define a default catalog in ${PNPM_WORKSPACE_FILENAME} under the "catalog" key`,
];

@@ -102,16 +105,16 @@ if (availableCatalogs.length > 0) {

}
throw new Error(formatCatalogError('No default catalog defined in pnpm-workspace.yaml', suggestions));
throw new Error((0, manager_1.formatCatalogError)(`No default catalog defined in ${PNPM_WORKSPACE_FILENAME}`, suggestions));
}
}
else if (catalogRef.catalogName) {
catalogToUse = workspaceConfig.catalogs?.[catalogRef.catalogName];
catalogToUse = catalogDefs.catalogs?.[catalogRef.catalogName];
if (!catalogToUse) {
const availableCatalogs = Object.keys(workspaceConfig.catalogs || {}).filter((c) => c !== 'default');
const defaultCatalog = !!workspaceConfig.catalog
const availableCatalogs = Object.keys(catalogDefs.catalogs || {}).filter((c) => c !== 'default');
const defaultCatalog = !!catalogDefs.catalog
? 'catalog'
: !workspaceConfig.catalogs?.default
: !catalogDefs.catalogs?.default
? 'catalogs.default'
: null;
const suggestions = [
'Define the catalog in pnpm-workspace.yaml under the "catalogs" key',
`Define the catalog in ${PNPM_WORKSPACE_FILENAME} under the "catalogs" key`,
];

@@ -126,3 +129,3 @@ if (availableCatalogs.length > 0) {

}
throw new Error(formatCatalogError(`Catalog "${catalogRef.catalogName}" not found in pnpm-workspace.yaml`, suggestions));
throw new Error((0, manager_1.formatCatalogError)(`Catalog "${catalogRef.catalogName}" not found in ${PNPM_WORKSPACE_FILENAME}`, suggestions));
}

@@ -134,3 +137,3 @@ }

// Context-aware messaging based on which location exists
const hasCatalog = !!workspaceConfig.catalog;
const hasCatalog = !!catalogDefs.catalog;
catalogName = hasCatalog

@@ -145,3 +148,3 @@ ? 'default catalog ("catalog")'

const suggestions = [
`Add "${packageName}" to ${catalogName} in pnpm-workspace.yaml`,
`Add "${packageName}" to ${catalogName} in ${PNPM_WORKSPACE_FILENAME}`,
];

@@ -153,3 +156,3 @@ if (availablePackages.length > 0) {

}
throw new Error(formatCatalogError(`Package "${packageName}" not found in ${catalogName}`, suggestions));
throw new Error((0, manager_1.formatCatalogError)(`Package "${packageName}" not found in ${catalogName}`, suggestions));
}

@@ -162,18 +165,18 @@ }

if (typeof treeOrRoot === 'string') {
const workspaceYamlPath = (0, node_path_1.join)(treeOrRoot, 'pnpm-workspace.yaml');
checkExists = () => (0, node_fs_1.existsSync)(workspaceYamlPath);
readYaml = () => (0, node_fs_1.readFileSync)(workspaceYamlPath, 'utf-8');
writeYaml = (content) => (0, node_fs_1.writeFileSync)(workspaceYamlPath, content, 'utf-8');
const configPath = (0, node_path_1.join)(treeOrRoot, PNPM_WORKSPACE_FILENAME);
checkExists = () => (0, node_fs_1.existsSync)(configPath);
readYaml = () => (0, node_fs_1.readFileSync)(configPath, 'utf-8');
writeYaml = (content) => (0, node_fs_1.writeFileSync)(configPath, content, 'utf-8');
}
else {
checkExists = () => treeOrRoot.exists('pnpm-workspace.yaml');
readYaml = () => treeOrRoot.read('pnpm-workspace.yaml', 'utf-8');
writeYaml = (content) => treeOrRoot.write('pnpm-workspace.yaml', content);
checkExists = () => treeOrRoot.exists(PNPM_WORKSPACE_FILENAME);
readYaml = () => treeOrRoot.read(PNPM_WORKSPACE_FILENAME, 'utf-8');
writeYaml = (content) => treeOrRoot.write(PNPM_WORKSPACE_FILENAME, content);
}
if (!checkExists()) {
devkit_exports_1.output.warn({
title: 'No pnpm-workspace.yaml found',
title: `No ${PNPM_WORKSPACE_FILENAME} found`,
bodyLines: [
'Cannot update catalog versions without a pnpm-workspace.yaml file.',
'Create a pnpm-workspace.yaml file to use catalogs.',
`Cannot update catalog versions without a ${PNPM_WORKSPACE_FILENAME} file.`,
`Create a ${PNPM_WORKSPACE_FILENAME} file to use catalogs.`,
],

@@ -184,4 +187,4 @@ });

try {
const workspaceContent = readYaml();
const workspaceData = (0, js_yaml_1.load)(workspaceContent) || {};
const configContent = readYaml();
const configData = (0, js_yaml_1.load)(configContent) || {};
let hasChanges = false;

@@ -194,12 +197,12 @@ for (const update of updates) {

// Default catalog - update whichever exists, prefer catalog over catalogs.default
if (workspaceData.catalog) {
targetCatalog = workspaceData.catalog;
if (configData.catalog) {
targetCatalog = configData.catalog;
}
else if (workspaceData.catalogs?.default) {
targetCatalog = workspaceData.catalogs.default;
else if (configData.catalogs?.default) {
targetCatalog = configData.catalogs.default;
}
else {
// Neither exists, create catalog (shorthand syntax)
workspaceData.catalog ??= {};
targetCatalog = workspaceData.catalog;
configData.catalog ??= {};
targetCatalog = configData.catalog;
}

@@ -209,5 +212,5 @@ }

// Named catalog
workspaceData.catalogs ??= {};
workspaceData.catalogs[normalizedCatalogName] ??= {};
targetCatalog = workspaceData.catalogs[normalizedCatalogName];
configData.catalogs ??= {};
configData.catalogs[normalizedCatalogName] ??= {};
targetCatalog = configData.catalogs[normalizedCatalogName];
}

@@ -220,3 +223,3 @@ if (targetCatalog[packageName] !== version) {

if (hasChanges) {
writeYaml((0, js_yaml_1.dump)(workspaceData, {
writeYaml((0, js_yaml_1.dump)(configData, {
indent: 2,

@@ -238,3 +241,3 @@ quotingType: '"',

exports.PnpmCatalogManager = PnpmCatalogManager;
function readYamlFileFromFs(path) {
function readConfigFromFs(path) {
try {

@@ -245,3 +248,3 @@ return (0, devkit_internals_1.readYamlFile)(path);

devkit_exports_1.output.warn({
title: 'Unable to parse pnpm-workspace.yaml',
title: `Unable to parse ${PNPM_WORKSPACE_FILENAME}`,
bodyLines: [error.toString()],

@@ -252,11 +255,10 @@ });

}
function readYamlFileFromTree(tree, path) {
function readConfigFromTree(tree, path) {
const content = tree.read(path, 'utf-8');
const { load } = require('@zkochan/js-yaml');
try {
return load(content, { filename: path });
return (0, js_yaml_1.load)(content, { filename: path });
}
catch (error) {
devkit_exports_1.output.warn({
title: 'Unable to parse pnpm-workspace.yaml',
title: `Unable to parse ${PNPM_WORKSPACE_FILENAME}`,
bodyLines: [error.toString()],

@@ -267,11 +269,1 @@ });

}
function formatCatalogError(error, suggestions) {
let message = error;
if (suggestions && suggestions.length > 0) {
message += '\n\nSuggestions:';
suggestions.forEach((suggestion) => {
message += `\n • ${suggestion}`;
});
}
return message;
}

@@ -5,2 +5,9 @@ export interface CatalogReference {

}
export interface CatalogEntry {
[packageName: string]: string;
}
export interface CatalogDefinitions {
catalog?: CatalogEntry;
catalogs?: Record<string, CatalogEntry>;
}
//# sourceMappingURL=types.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,OAAO,CAAC;CAC3B"}
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../packages/devkit/src/utils/catalog/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACzC"}