Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/config/src/cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export function parseCargoToml(cargoPath: string): CargoManifest {
return TOML.parse(content) as CargoManifest;
}

export function isCratePublishable(manifest: CargoManifest): boolean {
const publish = manifest.package?.publish;
const noRegistries = Array.isArray(publish) && publish.length === 0;
return publish !== false && !noRegistries;
}

export function isCargoToml(filePath: string): boolean {
return path.basename(filePath) === 'Cargo.toml';
}
2 changes: 1 addition & 1 deletion packages/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { type CargoManifest, isCargoToml, parseCargoToml } from './cargo.js';
export { type CargoManifest, isCargoToml, isCratePublishable, parseCargoToml } from './cargo.js';
export { ConfigError } from './errors.js';
export {
type LoadOptions,
Expand Down
5 changes: 5 additions & 0 deletions packages/publish/src/registry/cargo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import { isCratePublishable } from '@releasekit/config';
import { buildDependencyGraph, debug, type GraphPackage } from '@releasekit/core';
import { createGitCli } from '@releasekit/git';
import { createPublishError, PublishErrorCode } from '../errors/index.js';
Expand Down Expand Up @@ -129,6 +130,10 @@ function findCrates(updates: Array<{ newVersion: string; filePath: string; dir:
if (!cargo.package?.name) {
continue;
}
if (!isCratePublishable(cargo)) {
debug(`Skipping crate ${cargo.package.name}: publish = false`);
continue;
}

crates.push({
packageName: cargo.package.name,
Expand Down
22 changes: 22 additions & 0 deletions packages/publish/test/unit/stages/cargo-publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,28 @@ describe('cargo-publish stage', () => {
expect((init?.headers as Record<string, string>)?.['User-Agent']).toMatch(/releasekit/);
});

it.each(['publish = false', 'publish = []'])('should skip a crate with %s', async (publishLine) => {
const { execCommand } = await import('../../../src/utils/exec.js');
const dir = createTmpDir();
const pkgDir = path.join(dir, 'packages', 'napi');
fs.mkdirSync(pkgDir, { recursive: true });
fs.writeFileSync(path.join(pkgDir, 'package.json'), '{"name":"napi","version":"1.0.0"}');
fs.writeFileSync(path.join(pkgDir, 'Cargo.toml'), `[package]\nname = "napi"\nversion = "1.0.0"\n${publishLine}\n`);

const ctx = createContext(dir, {
input: {
dryRun: false,
updates: [{ packageName: 'napi', newVersion: '1.1.0', filePath: 'packages/napi/package.json' }],
changelogs: [],
tags: [],
},
});
await runCargoPublishStage(ctx);

expect(vi.mocked(execCommand).mock.calls.filter((c) => c[0] === 'cargo')).toHaveLength(0);
expect(ctx.output.cargo).toHaveLength(0);
});

it('should skip packages without Cargo.toml', async () => {
const { execCommand } = await import('../../../src/utils/exec.js');
const dir = createTmpDir();
Expand Down
6 changes: 2 additions & 4 deletions packages/version/src/core/versionEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'node:path';
import { cwd } from 'node:process';
import { inspect } from 'node:util';
import { getPackagesSync, type Package, type Packages } from '@manypkg/get-packages';
import { filterPackagesByConfig, parseCargoToml, parsePubspec } from '@releasekit/config';
import { filterPackagesByConfig, isCratePublishable, parseCargoToml, parsePubspec } from '@releasekit/config';
import { isPrivatePackageJson, shouldMatchPackageTargets } from '@releasekit/core';
import { minimatch } from 'minimatch';
import * as yaml from 'yaml';
Expand Down Expand Up @@ -187,9 +187,7 @@ export class VersionEngine {
// Parse Cargo.toml
const cargoData = parseCargoToml(fullCargoPath);

// Skip crates that explicitly opt out of publishing (`publish = false` or `publish = []`).
const publishField = cargoData.package?.publish;
if (publishField === false || (Array.isArray(publishField) && publishField.length === 0)) {
if (!isCratePublishable(cargoData)) {
log(`Skipping Rust package at ${packageDir}: publish = false`, 'debug');
continue;
}
Expand Down
Loading