Skip to content

Commit a4020b0

Browse files
authored
fix(storybook): when migrating to 12.1 do not throw if project has no targets (#6490)
ISSUES CLOSED: #6128
1 parent fedcfc4 commit a4020b0

File tree

2 files changed

+65
-36
lines changed

2 files changed

+65
-36
lines changed

packages/storybook/src/migrations/update-12-1-0/fix-storybook-tsconfig.spec.ts

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,79 @@ import updateStorybookTsconfig from './fix-storybook-tsconfig';
55
describe('Fix Storybook TSConfig to avoid VSCode error', () => {
66
let tree: Tree;
77

8-
beforeEach(async () => {
9-
tree = createTreeWithEmptyWorkspace();
10-
11-
writeJson(tree, 'workspace.json', {
12-
projects: {
13-
['home-ui-react']: {
14-
projectType: 'library',
15-
root: 'libs/home/ui-react',
16-
sourceRoot: 'libs/home/ui-react/src',
17-
targets: {
18-
storybook: {
19-
builder: '@nrwl/storybook:storybook',
20-
options: {
21-
uiFramework: '@storybook/react',
22-
port: 4400,
23-
config: {
24-
configFolder: 'libs/home/ui-react/.storybook',
8+
describe('when project has valid configuration and targets', () => {
9+
beforeEach(async () => {
10+
tree = createTreeWithEmptyWorkspace();
11+
12+
writeJson(tree, 'workspace.json', {
13+
projects: {
14+
['home-ui-react']: {
15+
projectType: 'library',
16+
root: 'libs/home/ui-react',
17+
sourceRoot: 'libs/home/ui-react/src',
18+
targets: {
19+
storybook: {
20+
builder: '@nrwl/storybook:storybook',
21+
options: {
22+
uiFramework: '@storybook/react',
23+
port: 4400,
24+
config: {
25+
configFolder: 'libs/home/ui-react/.storybook',
26+
},
2527
},
2628
},
2729
},
2830
},
2931
},
30-
},
32+
});
33+
34+
writeJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json', {
35+
extends: '../tsconfig.json',
36+
compilerOptions: {
37+
emitDecoratorMetadata: true,
38+
},
39+
});
3140
});
3241

33-
writeJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json', {
34-
extends: '../tsconfig.json',
35-
compilerOptions: {
36-
emitDecoratorMetadata: true,
37-
},
42+
it(`should add outDir to the storybook tsconfig to avoid VSCode errors`, async () => {
43+
await updateStorybookTsconfig(tree);
44+
45+
expect(
46+
readJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json')
47+
).toMatchObject({
48+
extends: '../tsconfig.json',
49+
compilerOptions: {
50+
emitDecoratorMetadata: true,
51+
outDir: '',
52+
},
53+
});
3854
});
3955
});
4056

41-
it(`should add outDir to the storybook tsconfig to avoid VSCode errors`, async () => {
42-
await updateStorybookTsconfig(tree);
43-
44-
expect(
45-
readJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json')
46-
).toMatchObject({
47-
extends: '../tsconfig.json',
48-
compilerOptions: {
49-
emitDecoratorMetadata: true,
50-
outDir: '',
51-
},
57+
describe('when project has no targets', () => {
58+
beforeEach(async () => {
59+
tree = createTreeWithEmptyWorkspace();
60+
61+
writeJson(tree, 'workspace.json', {
62+
projects: {
63+
['home-ui-react']: {
64+
projectType: 'library',
65+
root: 'libs/home/ui-react',
66+
sourceRoot: 'libs/home/ui-react/src',
67+
},
68+
},
69+
});
70+
71+
writeJson(tree, 'libs/home/ui-react/.storybook/tsconfig.json', {
72+
extends: '../tsconfig.json',
73+
compilerOptions: {
74+
emitDecoratorMetadata: true,
75+
},
76+
});
77+
});
78+
79+
it(`should not throw errors`, async () => {
80+
await expect(updateStorybookTsconfig(tree)).resolves.not.toThrow();
5281
});
5382
});
5483
});

packages/storybook/src/migrations/update-12-1-0/fix-storybook-tsconfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default async function updateStorybookTsconfig(tree: Tree) {
2323
),
2424
};
2525

26-
const storybookExecutor = Object.keys(targets).find(
26+
const storybookExecutor = Object.keys(targets || {}).find(
2727
(x) => targets[x].executor === '@nrwl/storybook:storybook'
2828
);
2929

@@ -38,7 +38,7 @@ export default async function updateStorybookTsconfig(tree: Tree) {
3838
}
3939

4040
const isReactProject = isFramework('react', {
41-
uiFramework: targets[storybookExecutor].options
41+
uiFramework: targets[storybookExecutor]?.options
4242
?.uiFramework as Parameters<typeof isFramework>[1]['uiFramework'],
4343
});
4444

0 commit comments

Comments
 (0)