fix(storybook): fix .eslintrc.json being undefined when adding storybook to project (#3851)

This commit is contained in:
Jason Jean 2020-10-02 08:43:39 -04:00 committed by GitHub
parent ad56f5785a
commit 6fb780e474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 3 deletions

View File

@ -1,7 +1,11 @@
import { Tree } from '@angular-devkit/schematics';
import { readJsonInTree, getProjectConfig } from '@nrwl/workspace';
import {
readJsonInTree,
getProjectConfig,
updateJsonInTree,
} from '@nrwl/workspace';
import { createTestUILib, runSchematic } from '../../utils/testing';
import { callRule, createTestUILib, runSchematic } from '../../utils/testing';
import { getTsConfigContent, TsConfig } from '../../utils/utils';
import * as fileUtils from '@nrwl/workspace/src/core/file-utils';
@ -143,4 +147,36 @@ describe('schematic:configuration', () => {
]
`);
});
it("should update the project's .eslintrc.json if config exists", async () => {
appTree = await createTestUILib('test-ui-lib2', '@nrwl/angular', {
linter: 'eslint',
});
appTree = await callRule(
updateJsonInTree('libs/test-ui-lib2/.eslintrc.json', (json) => {
json.parserOptions = {
project: [],
};
return json;
}),
appTree
);
const tree = await runSchematic(
'configuration',
{ name: 'test-ui-lib2' },
appTree
);
expect(
readJsonInTree(tree, 'libs/test-ui-lib2/.eslintrc.json').parserOptions
).toMatchInlineSnapshot(`
Object {
"project": Array [
"libs/test-ui-lib2/.storybook/tsconfig.json",
],
}
`);
});
});

View File

@ -241,6 +241,7 @@ function updateLintConfig(schema: StorybookConfigureSchema): Rule {
`${projectConfig.root}/.storybook/tsconfig.json`
);
}
return json;
}
);
},

View File

@ -63,13 +63,15 @@ export function runMigration(migrationName: string, options: any, tree: Tree) {
export async function createTestUILib(
libName: string,
collectionName: '@nrwl/angular' | '@nrwl/react'
collectionName: '@nrwl/angular' | '@nrwl/react',
options: any = {}
): Promise<Tree> {
let appTree = Tree.empty();
appTree = createEmptyWorkspace(appTree);
appTree = await callRule(
externalSchematic(collectionName, 'library', {
name: libName,
...options,
}),
appTree
);