From 8cfda00009de156c849b460a246b1b57cd0b3e4a Mon Sep 17 00:00:00 2001 From: katerina Date: Tue, 5 Jan 2021 13:04:44 +0200 Subject: [PATCH] feat(core): export a function returning a normalized workspace config 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 --- packages/workspace/index.ts | 6 +++++- packages/workspace/src/core/file-utils.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/workspace/index.ts b/packages/workspace/index.ts index 820c2c2f7d6d6..e994ca26f0fb8 100644 --- a/packages/workspace/index.ts +++ b/packages/workspace/index.ts @@ -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, diff --git a/packages/workspace/src/core/file-utils.ts b/packages/workspace/src/core/file-utils.ts index 22adcdd0c172d..2b76e14c581f8 100644 --- a/packages/workspace/src/core/file-utils.ts +++ b/packages/workspace/src/core/file-utils.ts @@ -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'); @@ -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';