Skip to content

Commit a24e2ef

Browse files
committed
feat: expose runsAfter to add-ons
1 parent c7fd9aa commit a24e2ef

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

.changeset/loose-colts-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
feat: expose `runsAfter` to add-ons

packages/addons/storybook/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export default defineAddon({
66
shortDescription: 'frontend workshop',
77
homepage: 'https://storybook.js.org',
88
options: {},
9+
setup: ({ runsAfter }) => {
10+
runsAfter('vitest');
11+
runsAfter('eslint');
12+
},
913
run: async ({ sv }) => {
1014
await sv.execute(['storybook@latest', 'init', '--skip-install', '--no-dev'], 'inherit');
1115
sv.devDependency(`@types/node`, getNodeTypesVersion());

packages/cli/lib/install.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@ export function setupAddons(
8787
const addonSetupResults: Record<string, AddonSetupResult> = {};
8888

8989
for (const addon of addons) {
90-
const setupResult: AddonSetupResult = { unsupported: [], dependsOn: [] };
90+
const setupResult: AddonSetupResult = { unsupported: [], dependsOn: [], runsAfter: [] };
9191
addon.setup?.({
9292
...workspace,
93-
dependsOn: (name) => setupResult.dependsOn.push(name),
94-
unsupported: (reason) => setupResult.unsupported.push(reason)
93+
dependsOn: (name) => {
94+
setupResult.dependsOn.push(name);
95+
setupResult.runsAfter.push(name);
96+
},
97+
unsupported: (reason) => setupResult.unsupported.push(reason),
98+
runsAfter: (name) => setupResult.runsAfter.push(name)
9599
});
96100
addonSetupResults[addon.id] = setupResult;
97101
}
@@ -181,13 +185,10 @@ async function runAddon({ addon, multiple, workspace }: RunAddon) {
181185
}
182186

183187
// orders addons by putting addons that don't require any other addon in the front.
184-
// This is a drastic simplification, as this could still cause some inconvenient cituations,
188+
// This is a drastic simplification, as this could still cause some inconvenient circumstances,
185189
// but works for now in contrary to the previous implementation
186190
function orderAddons(addons: Array<Addon<any>>, setupResults: Record<string, AddonSetupResult>) {
187191
return addons.sort((a, b) => {
188-
// Adding storybook last means it will correctly detect and integrate with other addons like vitest and eslint
189-
if (a.id === 'storybook') return 1;
190-
if (b.id === 'storybook') return -1;
191-
return setupResults[a.id]?.dependsOn?.length - setupResults[b.id]?.dependsOn?.length;
192+
return setupResults[a.id]?.runsAfter?.length - setupResults[b.id]?.runsAfter?.length;
192193
});
193194
}

packages/core/addon/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type Addon<Args extends OptionDefinition> = {
3737
workspace: Workspace<Args> & {
3838
dependsOn: (name: string) => void;
3939
unsupported: (reason: string) => void;
40+
runsAfter: (addonName: string) => void;
4041
}
4142
) => MaybePromise<void>;
4243
run: (workspace: Workspace<Args> & { sv: SvApi }) => MaybePromise<void>;
@@ -59,7 +60,7 @@ export function defineAddon<Args extends OptionDefinition>(config: Addon<Args>):
5960
return config;
6061
}
6162

62-
export type AddonSetupResult = { dependsOn: string[]; unsupported: string[] };
63+
export type AddonSetupResult = { dependsOn: string[]; unsupported: string[]; runsAfter: string[] };
6364

6465
export type AddonWithoutExplicitArgs = Addon<Record<string, Question>>;
6566
export type AddonConfigWithoutExplicitArgs = Addon<Record<string, Question>>;

0 commit comments

Comments
 (0)