Skip to content

Commit e9412d5

Browse files
authored
fix(nextjs): if there is no tsconfig.app.json or tsconfig.lib.json then set path to tsconfig.json (#4101)
Storybook configuration could not be added to nextjs apps because they have a tsconfig.json and not a tsconfig.app.json ISSUES CLOSED: #4092
1 parent 4f545a1 commit e9412d5

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

packages/storybook/src/schematics/configuration/configuration.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
applyWithSkipExisting,
2424
isFramework,
2525
getTsConfigContent,
26+
TsConfig,
2627
} from '../../utils/utils';
2728
import { CypressConfigureSchema } from '../cypress-project/cypress-project';
2829
import { StorybookConfigureSchema } from './schema';
@@ -143,21 +144,43 @@ function createProjectStorybookDir(
143144
};
144145
}
145146

146-
function getTsConfigPath(tree: Tree, projectName: string): string {
147+
function getTsConfigPath(
148+
tree: Tree,
149+
projectName: string,
150+
path?: string
151+
): string {
147152
const { projectType } = getProjectConfig(tree, projectName);
148153
const projectPath = getProjectConfig(tree, projectName).root;
149154
return join(
150155
projectPath,
151-
projectType === 'application' ? 'tsconfig.app.json' : 'tsconfig.lib.json'
156+
path && path.length > 0
157+
? path
158+
: projectType === 'application'
159+
? 'tsconfig.app.json'
160+
: 'tsconfig.lib.json'
152161
);
153162
}
154163

155164
function configureTsProjectConfig(schema: StorybookConfigureSchema): Rule {
156165
const { name: projectName } = schema;
157166

158167
return (tree: Tree) => {
159-
const tsConfigPath = getTsConfigPath(tree, projectName);
160-
const tsConfigContent = getTsConfigContent(tree, tsConfigPath);
168+
let tsConfigPath: string;
169+
let tsConfigContent: TsConfig;
170+
171+
try {
172+
tsConfigPath = getTsConfigPath(tree, projectName);
173+
tsConfigContent = getTsConfigContent(tree, tsConfigPath);
174+
} catch {
175+
/**
176+
* Custom app configurations
177+
* may contain a tsconfig.json
178+
* instead of a tsconfig.app.json.
179+
*/
180+
181+
tsConfigPath = getTsConfigPath(tree, projectName, 'tsconfig.json');
182+
tsConfigContent = getTsConfigContent(tree, tsConfigPath);
183+
}
161184

162185
tsConfigContent.exclude = [
163186
...(tsConfigContent.exclude || []),

0 commit comments

Comments
 (0)