diff --git a/package-lock.json b/package-lock.json index 51b6bdaed..2e3834bad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15058,7 +15058,7 @@ }, "packages/plugin-sdk": { "name": "@termix-ssh/plugin-sdk", - "version": "1.0.6", + "version": "1.0.7", "license": "Apache-2.0", "dependencies": { "@deadendjs/swagger-jsdoc": "^8.1.2", diff --git a/packages/plugin-sdk/CHANGELOG.md b/packages/plugin-sdk/CHANGELOG.md index bfa8b42a4..89a59deba 100644 --- a/packages/plugin-sdk/CHANGELOG.md +++ b/packages/plugin-sdk/CHANGELOG.md @@ -1,5 +1,11 @@ # 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 ### Added diff --git a/packages/plugin-sdk/PLUGIN-GUIDE.md b/packages/plugin-sdk/PLUGIN-GUIDE.md index 13531978b..9647223eb 100644 --- a/packages/plugin-sdk/PLUGIN-GUIDE.md +++ b/packages/plugin-sdk/PLUGIN-GUIDE.md @@ -1,6 +1,6 @@ # 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 `@termix-ssh/plugin-sdk`, so the copy in your `node_modules` always matches the SDK you have installed. diff --git a/packages/plugin-sdk/package.json b/packages/plugin-sdk/package.json index f5b207942..6c6e5e2d3 100644 --- a/packages/plugin-sdk/package.json +++ b/packages/plugin-sdk/package.json @@ -1,6 +1,6 @@ { "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.", "license": "Apache-2.0", "repository": { diff --git a/packages/plugin-sdk/src/ddl.ts b/packages/plugin-sdk/src/ddl.ts index fac788076..61d318d55 100644 --- a/packages/plugin-sdk/src/ddl.ts +++ b/packages/plugin-sdk/src/ddl.ts @@ -309,17 +309,27 @@ export function splitStatements(source: string): string[] { continue; } if (char === ";") { - if (current.trim()) statements.push(current.trim()); + if (hasSql(current)) statements.push(current.trim()); current = ""; continue; } current += char; } - if (current.trim()) statements.push(current.trim()); + if (hasSql(current)) statements.push(current.trim()); 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. */ export function dropTableSql( dialect: SqlDialect, diff --git a/src/backend/tests/plugins/table-ddl.test.ts b/src/backend/tests/plugins/table-ddl.test.ts index 14f6c5aae..7f818e4e2 100644 --- a/src/backend/tests/plugins/table-ddl.test.ts +++ b/src/backend/tests/plugins/table-ddl.test.ts @@ -308,4 +308,11 @@ describe("adoptTableSql", () => { const joined = adoptTableSql("sqlite", "fleets", adopted).join("\n"); 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"]); + }); });