Skip to content

Commit

Permalink
fix: avoid relaunching running tasks
Browse files Browse the repository at this point in the history
Mutating tasks caused them to appear to be different than existing
executions, causing them to be relaunched even when an equivalent task
had already been started. Avoid mutating tasks that are not created
internally (as opposed to fetched from existing tasks) so that such
comparisons work as expected.
  • Loading branch information
joshbolduc committed Feb 20, 2023
1 parent 09c9aa4 commit 9d669f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 12 additions & 3 deletions src/server/createProcessTask.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ProcessExecution, Task, TaskScope } from 'vscode';
import { ProcessExecution, Task, TaskRevealKind, TaskScope } from 'vscode';
import type { EnvironmentVariables } from './EnvironmentVariables';

export const createProcessTask = (
binPath: string,
args: string[],
cwdPath: string | undefined,
injectedEnv: EnvironmentVariables,
) =>
new Task(
) => {
const task = new Task(
{ type: 'story-explorer' },
TaskScope.Workspace,
'Storybook Server',
Expand All @@ -17,3 +17,12 @@ export const createProcessTask = (
env: injectedEnv,
}),
);

task.isBackground = true;
task.detail = 'Storybook Development Server';
task.presentationOptions = {
reveal: TaskRevealKind.Silent,
};

return task;
};
8 changes: 1 addition & 7 deletions src/server/getOrCreateTask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isDeepStrictEqual } from 'util';
import { firstValueFrom } from 'rxjs';
import { TaskRevealKind, tasks } from 'vscode';
import { tasks } from 'vscode';
import { storybookConfigLocation } from '../config/storybookConfigLocation';
import { serverInternalEnvironmentVariablesConfigSuffix } from '../constants/constants';
import { logDebug } from '../log/log';
Expand Down Expand Up @@ -121,12 +121,6 @@ export const getOrCreateTask = async () => {
return undefined;
}

task.isBackground = true;
task.detail = 'Storybook Development Server';
task.presentationOptions = {
reveal: TaskRevealKind.Silent,
};

const existingExecution = tasks.taskExecutions.find(
(execution) =>
isDeepStrictEqual(execution.task.definition, task.definition) &&
Expand Down

0 comments on commit 9d669f4

Please sign in to comment.