mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
fix(sdk): skip comment-only chunks when splitting migrations
This commit is contained in:
1 parent
cc5dce18e2
commit
d2851982a6
6 files changed
+28
-5
No files matched your search
Generated
+1
-1
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user