Skip to content

Commit

Permalink
feat(core): export a function returning a normalized workspace config
Browse files Browse the repository at this point in the history
Storybook expects the format of workspace.json to match angular.json. This is not the case.
Storybook now will read the workspace.json file using the new function. This will allow us to manage
the new formats.

ISSUES CLOSED: #4305
  • Loading branch information
mandarini authored and vsavkin committed Jan 5, 2021
1 parent 0c0a29d commit 8cfda00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ export {
export { output } from './src/utils/output';
export { commandsObject } from './src/command-line/nx-commands';
export { supportedNxCommands } from './src/command-line/supported-nx-commands';
export { readWorkspaceJson, readNxJson } from './src/core/file-utils';
export {
readWorkspaceJson,
readNxJson,
readWorkspaceConfig,
} from './src/core/file-utils';
export { NxJson } from './src/core/shared-interfaces';
export {
ProjectGraphNode,
Expand Down
12 changes: 11 additions & 1 deletion packages/workspace/src/core/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ProjectGraphNode } from './project-graph';
import { Environment, NxJson } from './shared-interfaces';
import { defaultFileHasher } from './hasher/file-hasher';
import { performance } from 'perf_hooks';
import { Workspaces } from '@nrwl/tao/src/shared/workspace';
import { toOldFormatOrNull, Workspaces } from '@nrwl/tao/src/shared/workspace';

const ignore = require('ignore');

Expand Down Expand Up @@ -168,6 +168,16 @@ export function readWorkspaceJson(): any {
return ws.readWorkspaceConfiguration();
}

export function readWorkspaceConfig(opts: { format: 'angularCli' | 'nx' }) {
const json = readWorkspaceJson();
if (opts.format === 'angularCli') {
const formatted = toOldFormatOrNull(json);
return formatted ? formatted : json;
} else {
return json;
}
}

export function workspaceFileName() {
if (fileExists(`${appRootPath}/angular.json`)) {
return 'angular.json';
Expand Down

0 comments on commit 8cfda00

Please sign in to comment.