fix(sdk): skip comment-only chunks when splitting migrations

This commit is contained in:
LukeGus committed 2026-10-15 21:52:11 -05:00
1 parent cc5dce18e2
commit d2851982a6
6 files changed
+28 -5

No files matched your search

+1 -1
View File
@@ -15058,7 +15058,7 @@
}, },
"packages/plugin-sdk": { "packages/plugin-sdk": {
"name": "@termix-ssh/plugin-sdk", "name": "@termix-ssh/plugin-sdk",
"version": "1.0.6", "version": "1.0.7",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@deadendjs/swagger-jsdoc": "^8.1.2", "@deadendjs/swagger-jsdoc": "^8.1.2",
+6
View File
@@ -1,5 +1,11 @@
# Changelog # Changelog
## 1.0.7
### Fixed
- A migration file, or a part of one, holding only comments made core fail to start the plugin
## 1.0.6 ## 1.0.6
### Added ### Added
+1 -1
View File
@@ -1,6 +1,6 @@
# Termix plugin guide # Termix plugin guide
SDK 1.0.6 | Plugin API 1.2.0 SDK 1.0.7 | Plugin API 1.2.0
This guide is for anyone, person or AI coding tool, building a Termix plugin. It ships inside This guide is for anyone, person or AI coding tool, building a Termix plugin. It ships inside
`@termix-ssh/plugin-sdk`, so the copy in your `node_modules` always matches the SDK you have installed. `@termix-ssh/plugin-sdk`, so the copy in your `node_modules` always matches the SDK you have installed.
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@termix-ssh/plugin-sdk", "name": "@termix-ssh/plugin-sdk",
"version": "1.0.6", "version": "1.0.7",
"description": "The contract between Termix core and a plugin: types, the capability catalog and the manifest schema.", "description": "The contract between Termix core and a plugin: types, the capability catalog and the manifest schema.",
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": { "repository": {
+12 -2
View File
@@ -309,17 +309,27 @@ export function splitStatements(source: string): string[] {
continue; continue;
} }
if (char === ";") { if (char === ";") {
if (current.trim()) statements.push(current.trim()); if (hasSql(current)) statements.push(current.trim());
current = ""; current = "";
continue; continue;
} }
current += char; current += char;
} }
if (current.trim()) statements.push(current.trim()); if (hasSql(current)) statements.push(current.trim());
return statements; return statements;
} }
/** False for a chunk that is only comments, which a driver refuses to run. */
function hasSql(chunk: string): boolean {
return (
chunk
.replace(/--[^\n]*/g, "")
.replace(/\/\*[\s\S]*?\*\//g, "")
.trim() !== ""
);
}
/** DROP statement for a definition, for removePluginData. */ /** DROP statement for a definition, for removePluginData. */
export function dropTableSql( export function dropTableSql(
dialect: SqlDialect, dialect: SqlDialect,
@@ -308,4 +308,11 @@ describe("adoptTableSql", () => {
const joined = adoptTableSql("sqlite", "fleets", adopted).join("\n"); const joined = adoptTableSql("sqlite", "fleets", adopted).join("\n");
expect(splitStatements(joined)).toHaveLength(3); expect(splitStatements(joined)).toHaveLength(3);
}); });
it("drops a chunk that is only comments", () => {
expect(splitStatements("-- nothing to do here.\n")).toEqual([]);
expect(
splitStatements("/* note */;\n-- why\nSELECT 1;\n-- trailing"),
).toEqual(["-- why\nSELECT 1"]);
});
}); });