Skip to content

Commit 0d4623e

Browse files
committed
Restore toml-patch using @decimalturn/toml-patch (#246)
> [!NOTE] This work is originally by @DecimalTurn (PR #229). This PR is a resubmission because CI requires repository secrets that GitHub does not provide for fork builds. ## Original Description This change still resolves #143 like in #227, but it retains comments preservation when editing TOML config files. ## Additional Context from Original PR - The maintained fork (@decimalturn/toml-patch) has been verified to not have the same problem described in #143 - A new test was added to ensure the issue is caught: DecimalTurn/toml-patch@5c139ca - The maintainer is committed to maintaining this fork for the foreseeable future - The scoped package name (@decimalturn/toml-patch) will be maintained ## Changes 1. Replaced `smol-toml` with `@decimalturn/toml-patch` in package dependencies 2. Updated `updateConfigToml` function to use TOML.patch() instead of stringify() 3. Removed the note about losing comments and formatting from documentation 4. Updated tests to use the new package 5. Added proper typing for parsed config variables ## Benefits - Preserves comments and formatting in config.toml files - Resolves the issue with missing sections (from #143) - Maintains comment preservation capability (from original toml-patch) --- Credit: @DecimalTurn for the original implementation and maintaining the toml-patch fork
1 parent 6aa7afb commit 0d4623e

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pgflow': patch
3+
---
4+
5+
Fix config.toml corruption with minimal configs while preserving comments. Switch to @decimalturn/toml-patch 0.3.7 (maintained fork) which fixes issue #143 and preserves TOML comments and formatting. Thanks to @DecimalTurn for maintaining the fork and contributing this fix.

pkgs/cli/__tests__/commands/install/update-config-toml.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
22
import fs from 'fs';
33
import path from 'path';
44
import os from 'os';
5-
import { parse as parseTOML, stringify as stringifyTOML } from 'smol-toml';
5+
import { parse as parseTOML, stringify as stringifyTOML } from '@decimalturn/toml-patch';
66
import { updateConfigToml } from '../../../src/commands/install/update-config-toml';
77

88
describe('updateConfigToml', () => {
@@ -59,7 +59,7 @@ redirect_uri = "http://localhost:54321/auth/v1/callback"
5959
console.log('---');
6060

6161
// First, verify the output is valid TOML that can be parsed
62-
let parsedConfig;
62+
let parsedConfig: any;
6363
expect(() => {
6464
parsedConfig = parseTOML(updatedContent);
6565
}).not.toThrow();
@@ -134,7 +134,7 @@ enabled = true
134134
const updatedContent = fs.readFileSync(configPath, 'utf8');
135135

136136
// First verify the TOML is valid and parseable
137-
let parsedConfig;
137+
let parsedConfig: any;
138138
expect(() => {
139139
parsedConfig = parseTOML(updatedContent);
140140
}).not.toThrow();

pkgs/cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"dependencies": {
2222
"@clack/prompts": "^0.10.1",
2323
"@commander-js/extra-typings": "^13.1.0",
24+
"@decimalturn/toml-patch": "0.3.7",
2425
"@pgflow/core": "workspace:*",
2526
"chalk": "^5.4.1",
26-
"commander": "^13.1.0",
27-
"smol-toml": "^1.4.2"
27+
"commander": "^13.1.0"
2828
},
2929
"publishConfig": {
3030
"access": "public"

pkgs/cli/src/commands/install/update-config-toml.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { log, confirm, note } from '@clack/prompts';
4-
import { parse as parseTOML, stringify as stringifyTOML } from 'smol-toml';
4+
import * as TOML from '@decimalturn/toml-patch';
55
import chalk from 'chalk';
66

77
/**
@@ -21,8 +21,7 @@ type SupabaseConfig = {
2121

2222
/**
2323
* Updates the config.toml file with necessary configurations for EdgeWorker
24-
*
25-
* NOTE: Comments and custom formatting will be lost. A backup is always created.
24+
* while preserving comments and formatting
2625
*
2726
* Makes the following changes:
2827
* 1. Enables the connection pooler
@@ -53,10 +52,9 @@ export async function updateConfigToml({
5352
}
5453

5554
const configContent = fs.readFileSync(configPath, 'utf8');
56-
5755
let config: SupabaseConfig;
5856
try {
59-
config = parseTOML(configContent) as SupabaseConfig;
57+
config = TOML.parse(configContent) as SupabaseConfig;
6058
} catch (parseError) {
6159
const errorMsg = parseError instanceof Error ? parseError.message : String(parseError);
6260
log.error(`Invalid TOML syntax in ${configPath}: ${errorMsg}`);
@@ -132,11 +130,11 @@ ${chalk.green('+ policy = "per_worker"')}`);
132130
updatedConfig.db.pooler.pool_mode = 'transaction';
133131
updatedConfig.edge_runtime.policy = 'per_worker';
134132

135-
// Stringify the updated config
136-
// Note: This will not preserve comments from the original file
137133
let updatedContent: string;
138134
try {
139-
updatedContent = stringifyTOML(updatedConfig);
135+
updatedContent = TOML.patch(configContent, updatedConfig, {
136+
trailingComma: false,
137+
});
140138
} catch (stringifyError) {
141139
const errorMsg = stringifyError instanceof Error ? stringifyError.message : String(stringifyError);
142140
log.error(`Failed to generate TOML for ${configPath}: ${errorMsg}`);

pnpm-lock.yaml

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)