Skip to content

Commit

Permalink
feat(asdf): improve .tool-versions generator
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Mar 9, 2022
1 parent 8b3be6e commit af213c8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/generators/asdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export async function generateVersionConfigs(config: PackageConfig): Promise<voi
if (!config.versionsText) return;

const lines: string[] = [];
for (const versionText of config.versionsText.split('\n')) {
for (const versionText of config.versionsText.trim().split('\n')) {
const line = versionText.trim();
if (!line.startsWith('nodejs ')) {
if (line && line.split(/\s+/)[0] !== 'nodejs') {
lines.push(line);
continue;
}
Expand All @@ -31,15 +31,15 @@ export async function generateVersionConfigs(config: PackageConfig): Promise<voi

const toolVersionsPath = path.resolve(config.dirPath, '.tool-versions');
if (lines.length) {
await promisePool.run(() => fs.promises.writeFile(toolVersionsPath, lines.join('\n')));
await promisePool.run(() => fs.promises.writeFile(toolVersionsPath, lines.join('\n') + '\n'));
} else {
await promisePool.run(() => fs.promises.rm(toolVersionsPath, { force: true }));
}
}

function updateLine(line: string, insertionIndex: number, lines: string[]): void {
const prefix = line.split(' ') + ' ';
const index = lines.findIndex((l) => l.startsWith(prefix));
const [prefix] = line.split(' ');
const index = lines.findIndex((l) => l.split(/\s+/)[0] === prefix);
if (index >= 0) {
lines[index] = line;
} else {
Expand Down

0 comments on commit af213c8

Please sign in to comment.