Skip to content

Commit

Permalink
fix(angular): change the resolution order of the tsconfig.json config
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaudAV committed Nov 24, 2021
1 parent d6ba659 commit 57a96ac
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
7 changes: 4 additions & 3 deletions app/angular/src/builders/build-storybook/index.spec.ts
Expand Up @@ -5,6 +5,7 @@ import * as path from 'path';

const buildStandaloneMock = jest.fn();
jest.doMock('@storybook/angular/standalone', () => buildStandaloneMock);
jest.doMock('find-up', () => ({ sync: () => './storybook/tsconfig.ts' }));

const cpSpawnMock = {
spawn: jest.fn(),
Expand Down Expand Up @@ -86,7 +87,7 @@ describe('Build Storybook Builder', () => {
quiet: false,
outputDir: 'storybook-static',
mode: 'static',
tsConfig: 'src/tsconfig.app.json',
tsConfig: './storybook/tsconfig.ts',
});
});

Expand Down Expand Up @@ -153,7 +154,7 @@ describe('Build Storybook Builder', () => {
expect(output.success).toBeTruthy();
expect(cpSpawnMock.spawn).toHaveBeenCalledWith('compodoc', [
'-p',
'src/tsconfig.app.json',
'./storybook/tsconfig.ts',
'-d',
'',
'-e',
Expand All @@ -173,7 +174,7 @@ describe('Build Storybook Builder', () => {
quiet: false,
outputDir: 'storybook-static',
mode: 'static',
tsConfig: 'src/tsconfig.app.json',
tsConfig: './storybook/tsconfig.ts',
});
});
});
6 changes: 5 additions & 1 deletion app/angular/src/builders/build-storybook/index.ts
Expand Up @@ -9,6 +9,7 @@ import { JsonObject } from '@angular-devkit/core';
import { from, Observable, of, throwError } from 'rxjs';
import { CLIOptions } from '@storybook/core-common';
import { catchError, map, mapTo, switchMap } from 'rxjs/operators';
import { sync as findUpSync } from 'find-up';

// eslint-disable-next-line import/no-extraneous-dependencies
import buildStandalone, { StandaloneOptions } from '@storybook/angular/standalone';
Expand Down Expand Up @@ -99,7 +100,10 @@ async function setup(options: StorybookBuilderOptions, context: BuilderContext)
}

return {
tsConfig: options.tsConfig ?? browserOptions.tsConfig ?? undefined,
tsConfig:
options.tsConfig ??
findUpSync('tsconfig.json', { cwd: options.configDir }) ??
browserOptions.tsConfig,
};
}

Expand Down
7 changes: 4 additions & 3 deletions app/angular/src/builders/start-storybook/index.spec.ts
Expand Up @@ -5,6 +5,7 @@ import * as path from 'path';

const buildStandaloneMock = jest.fn();
jest.doMock('@storybook/angular/standalone', () => buildStandaloneMock);
jest.doMock('find-up', () => ({ sync: () => './storybook/tsconfig.ts' }));

const cpSpawnMock = {
spawn: jest.fn(),
Expand Down Expand Up @@ -92,7 +93,7 @@ describe('Start Storybook Builder', () => {
sslCa: undefined,
sslCert: undefined,
sslKey: undefined,
tsConfig: 'src/tsconfig.app.json',
tsConfig: './storybook/tsconfig.ts',
});
});

Expand Down Expand Up @@ -165,7 +166,7 @@ describe('Start Storybook Builder', () => {
expect(output.success).toBeTruthy();
expect(cpSpawnMock.spawn).toHaveBeenCalledWith('compodoc', [
'-p',
'src/tsconfig.app.json',
'./storybook/tsconfig.ts',
'-d',
'',
'-e',
Expand All @@ -190,7 +191,7 @@ describe('Start Storybook Builder', () => {
sslCa: undefined,
sslCert: undefined,
sslKey: undefined,
tsConfig: 'src/tsconfig.app.json',
tsConfig: './storybook/tsconfig.ts',
});
});
});
6 changes: 5 additions & 1 deletion app/angular/src/builders/start-storybook/index.ts
Expand Up @@ -14,6 +14,7 @@ import {
import { from, Observable, of } from 'rxjs';
import { CLIOptions } from '@storybook/core-common';
import { map, switchMap, mapTo } from 'rxjs/operators';
import { sync as findUpSync } from 'find-up';

// eslint-disable-next-line import/no-extraneous-dependencies
import buildStandalone, { StandaloneOptions } from '@storybook/angular/standalone';
Expand Down Expand Up @@ -122,7 +123,10 @@ async function setup(options: StorybookBuilderOptions, context: BuilderContext)
}

return {
tsConfig: options.tsConfig ?? browserOptions.tsConfig ?? undefined,
tsConfig:
options.tsConfig ??
findUpSync('tsconfig.json', { cwd: options.configDir }) ??
browserOptions.tsConfig,
};
}
function runInstance(options: StandaloneOptions) {
Expand Down
4 changes: 2 additions & 2 deletions app/angular/src/server/framework-preset-angular-cli.ts
Expand Up @@ -118,8 +118,8 @@ async function getBuilderOptions(
...(options.angularBuilderOptions as JsonObject),
tsConfig:
options.tsConfig ??
browserTargetOptions.tsConfig ??
findUpSync('tsconfig.json', { cwd: options.configDir }),
findUpSync('tsconfig.json', { cwd: options.configDir }) ??
browserTargetOptions.tsConfig,
};
logger.info(`=> Using angular project with "tsConfig:${builderOptions.tsConfig}"`);

Expand Down

0 comments on commit 57a96ac

Please sign in to comment.