diff --git a/CHANGELOG.md b/CHANGELOG.md index 726f708..ccbbb7d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [1.12.2] 2024-10-02 + +- Fix backwards compatibility of default values (#110) + ## [1.12.1] 2024-10-02 - Fix errors with default values (#107) diff --git a/package-lock.json b/package-lock.json index 8a58a6e..f523bc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tasks-shell-input", - "version": "1.12.1", + "version": "1.12.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tasks-shell-input", - "version": "1.12.1", + "version": "1.12.2", "devDependencies": { "@types/glob": "8.1.0", "@types/node": "20.11.30", diff --git a/package.json b/package.json index e524cda..53d83b2 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Tasks Shell Input", "description": "Use shell commands as input for your tasks", "icon": "icon.png", - "version": "1.12.1", + "version": "1.12.2", "publisher": "augustocdias", "repository": { "url": "https://github.com/augustocdias/vscode-shell-command" diff --git a/src/lib/CommandHandler.test.ts b/src/lib/CommandHandler.test.ts index 0594ed2..b20f564 100644 --- a/src/lib/CommandHandler.test.ts +++ b/src/lib/CommandHandler.test.ts @@ -66,9 +66,14 @@ describe("Simple cases", async () => { test("Command as array of strings", async () => { mockVscode.setMockData(mockData); + const args = { + command: ["cat", "${file}"], + useFirstResult: true, + taskId: "inputTest", + }; const handler = new CommandHandler( - {command: ["cat", "${file}"], useFirstResult: true}, + args, new UserInputContext(), mockExtensionContext as unknown as vscode.ExtensionContext, child_process, @@ -250,6 +255,42 @@ test("stdio", async () => { } }); +describe("Workspace state", () => { + test("It should return an array even if the saved value is a string", async () => { + const testDataPath = path.join(__dirname, "../test/testData/simple"); + + const tasksJson = await import(path.join(testDataPath, ".vscode/tasks.json")); + const mockData = (await import(path.join(testDataPath, "mockData.ts"))).default; + mockVscode.setMockData(mockData); + const input = tasksJson.inputs[0].args; + + class CommandHandlerTestHelper extends CommandHandler { + public getDefault() { + return super.getDefault(); + } + } + + for (const workspaceStateGet of [ + () => "test", + () => ["test"], + ]) { + const handler = new CommandHandlerTestHelper( + {...input, rememberPrevious: true}, + new UserInputContext(), + { + ...mockExtensionContext, + workspaceState: { + get: workspaceStateGet, + }, + } as unknown as vscode.ExtensionContext, + child_process, + ); + + expect(handler.getDefault()).toStrictEqual(["test"]); + } + }); +}); + describe("Errors", async () => { test("It should trigger an error for an empty result", async () => { const testDataPath = path.join(__dirname, "../test/testData/errors"); diff --git a/src/lib/CommandHandler.ts b/src/lib/CommandHandler.ts index a8d155c..7bb1cf0 100755 --- a/src/lib/CommandHandler.ts +++ b/src/lib/CommandHandler.ts @@ -225,7 +225,12 @@ export class CommandHandler { protected getDefault() { if (this.args.rememberPrevious && this.args.taskId) { - return this.context.workspaceState.get(this.args.taskId, []); + const result = this.context.workspaceState + .get(this.args.taskId, []); + + // Backwards compatibilty for before multiselect when default was + // saved as string not array. + return (typeof result === "string") ? [result] : result; } return []; diff --git a/src/test/testData/simple/.vscode/tasks.json b/src/test/testData/simple/.vscode/tasks.json index 53310f9..0928e62 100644 --- a/src/test/testData/simple/.vscode/tasks.json +++ b/src/test/testData/simple/.vscode/tasks.json @@ -14,6 +14,7 @@ "type": "command", "command": "shellCommand.execute", "args": { + "taskId": "inputTest", "command": "cat ${file}", "multiselect": true, "cwd": "${workspaceFolder}", diff --git a/src/test/testData/simple/mockData.ts b/src/test/testData/simple/mockData.ts index ecb3037..7a4e018 100644 --- a/src/test/testData/simple/mockData.ts +++ b/src/test/testData/simple/mockData.ts @@ -9,6 +9,7 @@ export default { "type": "command", "command": "shellCommand.execute", "args": { + "taskId": "inputTest", "command": "cat ${file}", "cwd": "${workspaceFolder}", "env": {