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
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,16 @@ class Bumper extends Plugin {
case 'yaml':
return writeFileSync(file, yaml.dump(parsed, { indent: indent.length }));
case 'toml':
const tomlString = toml.stringify(parsed);
// handle empty objects for sections
const tomlContent = tomlString.replace(/^([a-zA-Z0-9\.\-]+) \= \{ \}/g, '[$1]');
var tomlContent = data;

castArray(path).forEach(path => {
const latestPath = path.split('.').at(-1);
const versionMatch = new RegExp(`${latestPath}[\\W\\w]+?(${latestVersion.replaceAll('.', '\\.')})` || '');
tomlContent = tomlContent.replace(versionMatch, (match, group1) => {
return match.replace(group1, versionPrefix + version);
});
});

return writeFileSync(file, tomlContent);
case 'ini':
return writeFileSync(file, ini.encode(parsed));
Expand Down
17 changes: 16 additions & 1 deletion test/toml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { readFile } from './globals/file-utils.js';

mock({
'./foo.toml': `[tool.test]${EOL}version = "${CURRENT_VERSION}"${EOL}`,
'./cargo.toml': `[workspace]${EOL}${EOL}[package]${EOL}name = "hello_world"${EOL}version = "${CURRENT_VERSION}"${EOL}authors = [ "Alice <a@example.com>", "Bob <b@example.com>" ]${EOL}${EOL}[dependencies]${EOL}time = "0.1.12"${EOL}`
'./cargo.toml': `[workspace]${EOL}${EOL}[package]${EOL}name = "hello_world"${EOL}version = "${CURRENT_VERSION}"${EOL}authors = [ "Alice <a@example.com>", "Bob <b@example.com>" ]${EOL}${EOL}[dependencies]${EOL}time = "0.1.12"${EOL}`,
'./pyproject.toml': `[project]${EOL}name = "foo"${EOL}version = "${CURRENT_VERSION}"${EOL}# these are authors${EOL}authors = [{ name = "Alice", email = "a@example.com" }]${EOL}`
});

describe('toml file', { concurrency: true }, () => {
Expand Down Expand Up @@ -85,4 +86,18 @@ describe('toml file', { concurrency: true }, () => {
`[workspace]${EOL}${EOL}[package]${EOL}name = "hello_world"${EOL}version = "${NEW_VERSION}"${EOL}authors = [ "Alice <a@example.com>", "Bob <b@example.com>" ]${EOL}${EOL}[dependencies]${EOL}time = "0.1.12"${EOL}`
);
});

it('should read/write minimal changes', async () => {
const options = {
[NAMESPACE]: {
out: { file: './pyproject.toml', path: 'project.version' }
}
};
const plugin = factory(Bumper, { NAMESPACE, options });
await runTasks(plugin);
assert.equal(
readFile('./pyproject.toml'),
`[project]${EOL}name = "foo"${EOL}version = "${NEW_VERSION}"${EOL}# these are authors${EOL}authors = [{ name = "Alice", email = "a@example.com" }]${EOL}`
);
});
});
Loading