UNPKG

@naxodev/gonx

Version:

Modern Nx plugin to use Go in a Nx workspace

65 lines 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const node_path_1 = require("node:path"); const release_1 = require("nx/release"); const MANIFEST_FILENAME = 'go.mod'; // NOTE: We use the full project path as the project name, which ensures compatibility // with Go's release tagging convention (projectRoot/vx.x.x) and prevents name conflicts. /** * Implements versioning actions for Go projects. * This class manages versioning operations for Go modules using Git tags. */ class GoVersionActions extends release_1.VersionActions { constructor() { super(...arguments); this.validManifestFilenames = [MANIFEST_FILENAME]; } // The `go.mod` file does not contain the package version. // The version must be retrieved from Git tags or the Go registry. // For `nx release --first-release`, a default fallback is provided for the git-tag strategy. async readCurrentVersionFromSourceManifest(tree) { return { currentVersion: '0.0.0', manifestPath: (0, node_path_1.join)(this.projectGraphNode.data.root, 'go.mod'), }; } // Retrieve the module name of the project and attempt to fetch its version from the Go registry. async readCurrentVersionFromRegistry(tree, currentVersionResolverMetadata) { try { const manifestPath = (0, node_path_1.join)(this.projectGraphNode.data.root, MANIFEST_FILENAME); const content = tree.read(manifestPath, 'utf-8'); const moduleNameMatch = content.match(/module\s+([^\s]+)/); const moduleName = moduleNameMatch ? moduleNameMatch[1] : ''; const result = await fetch(`https://proxy.golang.org/${encodeURIComponent(moduleName)}/@latest`); if (result === null || result === void 0 ? void 0 : result.ok) { const response = (await result.json()); // Get the latest version from the list const latestVersion = response.Version; return { currentVersion: latestVersion, logText: `Retrieved version ${latestVersion} from proxy.golang.org for ${moduleName}`, }; } } catch (error) { console.error(error); throw new Error(`Unable to determine the current version of "${this.projectGraphNode.name}" from proxy.golang.org.`); } } // For local dependencies, Go ignores the version specified in the module and always uses the one in the local path. readCurrentVersionOfDependency(tree, projectGraph, dependencyProjectName) { throw new Error('Method not implemented.'); } // Since go.mod does not contain the version, we cannot update it. async updateProjectVersion(tree, newVersion) { // We do nothing on go projects by default return []; } // For local dependencies, Go ignores the version specified in the module and always uses the one in the local path. // However, we could implement this in the future to improve the consistency and readability of the code. async updateProjectDependencies(tree, projectGraph, dependenciesToUpdate) { return []; } } exports.default = GoVersionActions; //# sourceMappingURL=go-version-actions.js.map