Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(plugins): write manifests with LF instead of the platform newline

Juan Denis81208f2f684d
diff --git a/backend/app/services/plugin_service.py b/backend/app/services/plugin_service.py
index fc66e039..fd4b339d 100644
--- a/backend/app/services/plugin_service.py
+++ b/backend/app/services/plugin_service.py
@@ -1086,16 +1086,20 @@ def _install_from_buffer(buf, source_url, source_type, user_id=None, force=False
# write, and both append one. json.dump does not, so without it every
# install rewrote the file with the newline stripped and left a dirty
# working tree whose diff contained no actual change.
+ # newline='\n' matters for the same reason: .gitattributes pins the repo
+ # to `text=auto eol=lf`, but Python's text mode translates \n to \r\n on
+ # Windows, so a dev-machine install rewrote every tracked manifest with
+ # CRLF.
if has_backend:
manifest_out = os.path.join(backend_dest, 'plugin.json')
- with open(manifest_out, 'w') as f:
+ with open(manifest_out, 'w', newline='\n') as f:
json.dump(manifest, f, indent=2)
f.write('\n')
# Also write manifest to frontend dir
if has_frontend:
manifest_out = os.path.join(frontend_dest, 'plugin.json')
- with open(manifest_out, 'w') as f:
+ with open(manifest_out, 'w', newline='\n') as f:
json.dump(manifest, f, indent=2)
f.write('\n')
@@ -1355,9 +1359,10 @@ def _regenerate_frontend_manifest():
entry['styles'] = [f'plugins/{p.slug}/styles/{s}' for s in styles]
entries.append(entry)
- # Trailing newline for the same reason as the per-plugin manifests above:
- # scripts/sync-builtin-frontends.mjs writes this same tracked file with one.
- with open(manifest_path, 'w') as f:
+ # Trailing newline and LF for the same reasons as the per-plugin manifests
+ # above: scripts/sync-builtin-frontends.mjs writes this same tracked file
+ # with one, and .gitattributes pins the repo to eol=lf.
+ with open(manifest_path, 'w', newline='\n') as f:
json.dump({'plugins': entries}, f, indent=2)
f.write('\n')
diff --git a/backend/tests/BASELINE_COUNT b/backend/tests/BASELINE_COUNT
index 110b5c51..645e2f57 100644
--- a/backend/tests/BASELINE_COUNT
+++ b/backend/tests/BASELINE_COUNT
@@ -1 +1 @@
-3382
+3383
diff --git a/backend/tests/test_plugins_pipeline.py b/backend/tests/test_plugins_pipeline.py
index 991b0ffe..634eecc0 100644
--- a/backend/tests/test_plugins_pipeline.py
+++ b/backend/tests/test_plugins_pipeline.py
@@ -178,6 +178,26 @@ def test_reinstall_refreshes_metadata(app, plugin_dirs):
assert InstalledPlugin.query.filter_by(slug='serverkit-demo').count() == 1
+def test_installed_manifests_are_written_with_lf(app, plugin_dirs):
+ """Manifests are tracked files pinned to LF by .gitattributes.
+
+ Python's text mode rewrites \\n as \\r\\n on Windows, so an install run on a
+ dev machine used to rewrite every tracked manifest with CRLF and leave four
+ modified files behind after the suite -- a diff with no content change.
+ """
+ _write_builtin(plugin_dirs['builtin'])
+ plugin_service.install_builtin_extension('serverkit-demo')
+
+ # The demo builtin ships a frontend half only, so no backend manifest is
+ # written. _regenerate_frontend_manifest() is skipped under the testing
+ # config, so plugins-manifest.json is out of reach here too.
+ path = plugin_dirs['frontend'] / 'serverkit-demo' / 'plugin.json'
+ assert path.exists(), f'{path} was not written'
+ raw = path.read_bytes()
+ assert b'\r\n' not in raw, f'{path} was written with CRLF'
+ assert raw.endswith(b'\n'), f'{path} lost its trailing newline'
+
+
def test_reinstall_active_plugin_is_rejected(app, plugin_dirs):
_write_builtin(plugin_dirs['builtin'])
plugin_service.install_builtin_extension('serverkit-demo')