diff --git a/packages/angular/src/schematics/application/__snapshots__/application.spec.ts.snap b/packages/angular/src/schematics/application/__snapshots__/application.spec.ts.snap index 28962a5c7e..0090f34fbc 100644 --- a/packages/angular/src/schematics/application/__snapshots__/application.spec.ts.snap +++ b/packages/angular/src/schematics/application/__snapshots__/application.spec.ts.snap @@ -96,7 +96,6 @@ Object { "prefix": "proj", "projectType": "application", "root": "apps/my-dir/my-app", - "schematics": Object {}, "sourceRoot": "apps/my-dir/my-app/src", } `; @@ -232,7 +231,6 @@ Object { "prefix": "proj", "projectType": "application", "root": "apps/my-app", - "schematics": Object {}, "sourceRoot": "apps/my-app/src", } `; diff --git a/packages/angular/src/schematics/application/application.spec.ts b/packages/angular/src/schematics/application/application.spec.ts index e5d6a01189..c386b12c57 100644 --- a/packages/angular/src/schematics/application/application.spec.ts +++ b/packages/angular/src/schematics/application/application.spec.ts @@ -309,21 +309,6 @@ describe('app', () => { true ); }); - - it('should set it as default', async () => { - const result = await runSchematic( - 'app', - { name: 'myApp', style: 'scss' }, - appTree - ); - const workspaceJson = readJsonInTree(result, 'workspace.json'); - - expect(workspaceJson.projects['my-app'].schematics).toEqual({ - '@schematics/angular:component': { - style: 'scss', - }, - }); - }); }); describe('--linter', () => { diff --git a/packages/angular/src/schematics/application/application.ts b/packages/angular/src/schematics/application/application.ts index 054bbeed22..dd7ec0e34f 100644 --- a/packages/angular/src/schematics/application/application.ts +++ b/packages/angular/src/schematics/application/application.ts @@ -484,6 +484,7 @@ function updateProject(options: NormalizedSchema): Rule { options.name, options.appProjectRoot ); + delete fixedProject.schematics; delete fixedProject.architect.test; @@ -803,10 +804,6 @@ export default function (schema: Schema): Rule { skipInstall: true, skipPackageJson: false, }), - // TODO: Remove this after Angular 10.1.0 - (host) => { - host.delete('tsconfig.json'); - }, addSchematicFiles(appProjectRoot, options), options.e2eTestRunner === 'protractor' ? move(e2eProjectRoot, options.e2eProjectRoot) diff --git a/packages/angular/src/schematics/library/lib/update-project.ts b/packages/angular/src/schematics/library/lib/update-project.ts index 7fad561b66..a63c0613ee 100644 --- a/packages/angular/src/schematics/library/lib/update-project.ts +++ b/packages/angular/src/schematics/library/lib/update-project.ts @@ -130,15 +130,7 @@ export function updateProject(options: NormalizedSchema): Rule { options.projectRoot ); - fixedProject.schematics = fixedProject.schematics || {}; - if (options.style !== 'css') { - fixedProject.schematics = { - ...fixedProject.schematics, - '@schematics/angular:component': { - style: options.style, - }, - }; - } + delete fixedProject.schematics; if (!options.publishable && !options.buildable) { delete fixedProject.architect.build; diff --git a/packages/angular/src/schematics/library/library.spec.ts b/packages/angular/src/schematics/library/library.spec.ts index dddb289741..ecf91da28b 100644 --- a/packages/angular/src/schematics/library/library.spec.ts +++ b/packages/angular/src/schematics/library/library.spec.ts @@ -1026,24 +1026,6 @@ describe('lib', () => { }); }); - describe('--style scss', () => { - it('should set it as default', async () => { - const result = await runSchematic( - 'lib', - { name: 'myLib', style: 'scss' }, - appTree - ); - - const workspaceJson = readJsonInTree(result, 'workspace.json'); - - expect(workspaceJson.projects['my-lib'].schematics).toEqual({ - '@schematics/angular:component': { - style: 'scss', - }, - }); - }); - }); - describe('--unit-test-runner karma', () => { it('should generate karma configuration', async () => { const resultTree = await runSchematic( diff --git a/packages/devkit/index.ts b/packages/devkit/index.ts index 871f6194c4..05ef8aceeb 100644 --- a/packages/devkit/index.ts +++ b/packages/devkit/index.ts @@ -9,15 +9,15 @@ export { NxJsonProjectConfiguration, } from '@nrwl/tao/src/shared/nx'; export { TargetContext } from '@nrwl/tao/src/commands/run'; -export { formatFiles } from './src/schematics/format-files'; +export { formatFiles } from './src/generators/format-files'; export { readJson } from './src/utils/read-json'; -export { generateFiles } from './src/schematics/generate-files'; +export { generateFiles } from './src/generators/generate-files'; export { installPackagesTask } from './src/tasks/install-packages-task'; export { addProjectConfiguration, readProjectConfiguration, updateProjectConfiguration, -} from './src/schematics/project-configuration'; +} from './src/generators/project-configuration'; export { names } from './src/utils/names'; export { getWorkspaceLayout } from './src/utils/get-workspace-layout'; export { offsetFromRoot } from './src/utils/offset-from-root'; diff --git a/packages/devkit/src/schematics/format-files.ts b/packages/devkit/src/generators/format-files.ts similarity index 62% rename from packages/devkit/src/schematics/format-files.ts rename to packages/devkit/src/generators/format-files.ts index 1c02e6eb5e..0effa47de7 100644 --- a/packages/devkit/src/schematics/format-files.ts +++ b/packages/devkit/src/generators/format-files.ts @@ -1,6 +1,8 @@ import { Tree } from '@nrwl/tao/src/shared/tree'; import * as path from 'path'; import type * as Prettier from 'prettier'; +import { getWorkspacePath } from '../utils/get-workspace-layout'; +import { Workspaces } from '@nrwl/tao/src/shared/workspace'; let prettier: typeof Prettier; try { @@ -12,6 +14,8 @@ try { * @param host - the file system tree */ export async function formatFiles(host: Tree) { + updateWorkspaceJsonToMatchFormatVersion(host); + if (!prettier) return; const files = new Set( @@ -41,8 +45,23 @@ export async function formatFiles(host: Tree) { prettier.format(file.content.toString(), options) ); } catch (e) { - console.warn(`Could not format ${file.path} because ${e.message}`); + console.warn(`Could not format ${file.path}. Error: "${e.message}"`); } }) ); } + +function updateWorkspaceJsonToMatchFormatVersion(host: Tree) { + const ws = new Workspaces(); + const path = getWorkspacePath(host); + try { + const workspaceJson = JSON.parse(host.read(path).toString()); + const reformatted = ws.reformattedWorkspaceJsonOrNull(workspaceJson); + if (reformatted) { + host.write(path, JSON.stringify(reformatted, null, 2)); + } + } catch (e) { + console.error(`Failed to format: ${path}`); + console.error(e); + } +} diff --git a/packages/devkit/src/schematics/generate-files.ts b/packages/devkit/src/generators/generate-files.ts similarity index 100% rename from packages/devkit/src/schematics/generate-files.ts rename to packages/devkit/src/generators/generate-files.ts diff --git a/packages/devkit/src/schematics/project-configuration.ts b/packages/devkit/src/generators/project-configuration.ts similarity index 95% rename from packages/devkit/src/schematics/project-configuration.ts rename to packages/devkit/src/generators/project-configuration.ts index 8ed17d82b3..e564a73c18 100644 --- a/packages/devkit/src/schematics/project-configuration.ts +++ b/packages/devkit/src/generators/project-configuration.ts @@ -9,6 +9,7 @@ import { NxJsonConfiguration, NxJsonProjectConfiguration, } from '@nrwl/tao/src/shared/nx'; +import { getWorkspacePath } from '../utils/get-workspace-layout'; /** * Adds project configuration to the Nx workspace. @@ -140,8 +141,3 @@ function addProjectToNxJson( }; host.write('nx.json', JSON.stringify(nxJson)); } - -function getWorkspacePath(host: Tree) { - const possibleFiles = ['/workspace.json', '/angular.json', '/.angular.json']; - return possibleFiles.filter((path) => host.exists(path))[0]; -} diff --git a/packages/devkit/src/tests/create-tree-with-empty-workspace.ts b/packages/devkit/src/tests/create-tree-with-empty-workspace.ts index 7f6c2fd0f7..b679406a5e 100644 --- a/packages/devkit/src/tests/create-tree-with-empty-workspace.ts +++ b/packages/devkit/src/tests/create-tree-with-empty-workspace.ts @@ -6,10 +6,7 @@ import { FsTree } from '@nrwl/tao/src/shared/tree'; export function createTreeWithEmptyWorkspace() { const tree = new FsTree('/virtual', false); - tree.write( - '/workspace.json', - JSON.stringify({ version: 1, projects: {}, newProjectRoot: '' }) - ); + tree.write('/workspace.json', JSON.stringify({ version: 1, projects: {} })); tree.write( '/package.json', JSON.stringify({ diff --git a/packages/devkit/src/utils/get-workspace-layout.ts b/packages/devkit/src/utils/get-workspace-layout.ts index 76b41acc41..b8bcf647be 100644 --- a/packages/devkit/src/utils/get-workspace-layout.ts +++ b/packages/devkit/src/utils/get-workspace-layout.ts @@ -21,3 +21,8 @@ export function getWorkspaceLayout( const npmScope = nxJson.npmScope; return { ...layout, npmScope }; } + +export function getWorkspacePath(host: Tree) { + const possibleFiles = ['/workspace.json', '/angular.json']; + return possibleFiles.filter((path) => host.exists(path))[0]; +} diff --git a/packages/next/src/schematics/application/lib/add-project.ts b/packages/next/src/schematics/application/lib/add-project.ts index b30eeed6e8..b975651fc0 100644 --- a/packages/next/src/schematics/application/lib/add-project.ts +++ b/packages/next/src/schematics/application/lib/add-project.ts @@ -62,7 +62,6 @@ export function addProject(options: NormalizedSchema): Rule { root: options.appProjectRoot, sourceRoot: options.appProjectRoot, projectType: 'application', - schematics: {}, architect, }; diff --git a/packages/node/src/schematics/application/application.ts b/packages/node/src/schematics/application/application.ts index 6fbb5053b0..37ba59a3f6 100644 --- a/packages/node/src/schematics/application/application.ts +++ b/packages/node/src/schematics/application/application.ts @@ -96,7 +96,6 @@ function updateWorkspaceJson(options: NormalizedSchema): Rule { sourceRoot: join(options.appProjectRoot, 'src'), projectType: 'application', prefix: options.name, - schematics: {}, architect: {}, }; diff --git a/packages/nx-plugin/src/schematics/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ b/packages/nx-plugin/src/schematics/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ index 7f0bca39f1..fed4940703 100644 --- a/packages/nx-plugin/src/schematics/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ +++ b/packages/nx-plugin/src/schematics/generator/files/generator/__fileName__/generator.spec.ts__tmpl__ @@ -1,5 +1,5 @@ import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import { Tree } from '@nrwl/devkit'; +import { Tree, readProjectConfiguration } from '@nrwl/devkit'; import generator from './generator'; import { <%= className %>GeneratorSchema } from './schema'; @@ -14,27 +14,7 @@ describe('<%= name %> generator', () => { it('should run successfully', async () => { generator(appTree, options); - const workspace = JSON.parse(appTree.read('workspace.json').toString()); - expect(workspace.projects['test']).toMatchInlineSnapshot(` - Object { - "projectType": "library", - "root": "libs/test", - "sourceRoot": "libs/test/src", - "targets": Object { - "build": Object { - "executor": "<%= npmPackageName %>:build", - }, - }, - } - `); - - const nxjson = JSON.parse(appTree.read('nx.json').toString()); - expect(nxjson.projects).toMatchInlineSnapshot(` - Object { - "test": Object { - "tags": Array [], - }, - } - `); + const config = readProjectConfiguration(appTree, 'test'); + expect(config).toBeDefined(); }) }); diff --git a/packages/react/src/schematics/application/lib/add-project.ts b/packages/react/src/schematics/application/lib/add-project.ts index 5dcf5f2e1b..f842e56b6f 100644 --- a/packages/react/src/schematics/application/lib/add-project.ts +++ b/packages/react/src/schematics/application/lib/add-project.ts @@ -85,7 +85,6 @@ export function addProject(options: NormalizedSchema): Rule { root: options.appProjectRoot, sourceRoot: join(options.appProjectRoot, 'src'), projectType: 'application', - schematics: {}, architect, }; diff --git a/packages/react/src/schematics/library/library.ts b/packages/react/src/schematics/library/library.ts index 25fb371383..822558a164 100644 --- a/packages/react/src/schematics/library/library.ts +++ b/packages/react/src/schematics/library/library.ts @@ -182,7 +182,6 @@ function addProject(options: NormalizedSchema): Rule { root: options.projectRoot, sourceRoot: join(normalize(options.projectRoot), 'src'), projectType: 'library', - schematics: {}, architect, }; return json; diff --git a/packages/tao/src/commands/ngcli-adapter.ts b/packages/tao/src/commands/ngcli-adapter.ts index 7b32c166c6..d8287e2079 100644 --- a/packages/tao/src/commands/ngcli-adapter.ts +++ b/packages/tao/src/commands/ngcli-adapter.ts @@ -269,9 +269,10 @@ class NxScopedHost extends virtualFs.ScopedHost { map((r) => { try { const w = JSON.parse(Buffer.from(r).toString()); - return Buffer.from( - JSON.stringify(new Workspaces().toOldFormat(w), null, 2) - ); + const formatted = new Workspaces().toOldFormatOrNull(w); + return formatted + ? Buffer.from(JSON.stringify(formatted, null, 2)) + : r; } catch (e) { return r; } @@ -294,12 +295,15 @@ class NxScopedHost extends virtualFs.ScopedHost { if (newFormat) { try { const w = JSON.parse(Buffer.from(content).toString()); - return super.write( - path, - Buffer.from( - JSON.stringify(new Workspaces().toNewFormat(w), null, 2) - ) - ); + const formatted = new Workspaces().toNewFormatOrNull(w); + if (formatted) { + return super.write( + path, + Buffer.from(JSON.stringify(formatted, null, 2)) + ); + } else { + return super.write(path, content); + } } catch (e) { return super.write(path, content); } @@ -328,7 +332,9 @@ class NxScopedHost extends virtualFs.ScopedHost { switchMap((isAngularJson) => { return super .read((isAngularJson ? '/angular.json' : '/workspace.json') as any) - .pipe(map((r) => !!JSON.parse(Buffer.from(r).toString()).generators)); + .pipe( + map((r) => JSON.parse(Buffer.from(r).toString()).version === 2) + ); }) ); } diff --git a/packages/tao/src/shared/workspace.ts b/packages/tao/src/shared/workspace.ts index c3cb8c95da..1280129c34 100644 --- a/packages/tao/src/shared/workspace.ts +++ b/packages/tao/src/shared/workspace.ts @@ -112,17 +112,31 @@ export class Workspaces { return this.toNewFormat(w); } + reformattedWorkspaceJsonOrNull(w: any) { + return w.version === 2 + ? this.toNewFormatOrNull(w) + : this.toOldFormatOrNull(w); + } + toNewFormat(w: any) { + const f = this.toNewFormatOrNull(w); + return f ? f : w; + } + + toNewFormatOrNull(w: any) { + let formatted = false; Object.values(w.projects || {}).forEach((project: any) => { if (project.architect) { project.targets = project.architect; delete project.architect; + formatted = true; } Object.values(project.targets || {}).forEach((target: any) => { if (target.builder) { target.executor = target.builder; delete target.builder; + formatted = true; } }); }); @@ -130,21 +144,28 @@ export class Workspaces { if (w.schematics) { w.generators = w.schematics; delete w.schematics; + formatted = true; } - return w; + if (formatted) { + w.version = 2; + } + return formatted ? w : null; } - toOldFormat(w: any) { + toOldFormatOrNull(w: any) { + let formatted = false; Object.values(w.projects || {}).forEach((project: any) => { if (project.targets) { project.architect = project.targets; delete project.targets; + formatted = true; } Object.values(project.architect || {}).forEach((target: any) => { if (target.executor) { target.builder = target.executor; - delete target.execuctor; + delete target.executor; + formatted = true; } }); }); @@ -152,8 +173,12 @@ export class Workspaces { if (w.generators) { w.schematics = w.generators; delete w.generators; + formatted = true; } - return w; + if (formatted) { + w.version = 1; + } + return formatted ? w : null; } isNxExecutor(nodeModule: string, executor: string) { diff --git a/packages/web/src/schematics/application/application.ts b/packages/web/src/schematics/application/application.ts index 2d88bbe889..dcb66c235c 100644 --- a/packages/web/src/schematics/application/application.ts +++ b/packages/web/src/schematics/application/application.ts @@ -140,7 +140,6 @@ function addProject(options: NormalizedSchema): Rule { root: options.appProjectRoot, sourceRoot: join(normalize(options.appProjectRoot), 'src'), projectType: 'application', - schematics: {}, architect, }; diff --git a/packages/workspace/src/command-line/format.ts b/packages/workspace/src/command-line/format.ts index ce48a9c69b..7e6b51ee62 100644 --- a/packages/workspace/src/command-line/format.ts +++ b/packages/workspace/src/command-line/format.ts @@ -8,9 +8,15 @@ import { onlyWorkspaceProjects, } from '../core/project-graph'; import { filterAffected } from '../core/affected-project-graph'; -import { calculateFileChanges } from '../core/file-utils'; +import { calculateFileChanges, readWorkspaceJson } from '../core/file-utils'; import * as yargs from 'yargs'; import { NxArgs, splitArgsIntoNxArgsAndOverrides } from './utils'; +import { + workspaceConfigName, + Workspaces, +} from '@nrwl/tao/src/shared/workspace'; +import { appRootPath } from '@nrwl/workspace/src/utils/app-root'; +import { readFileSync, writeFileSync } from 'fs-extra'; const PRETTIER_EXTENSIONS = [ 'ts', @@ -40,6 +46,7 @@ export function format(command: 'check' | 'write', args: yargs.Arguments) { switch (command) { case 'write': + updateWorkspaceJsonToMatchFormatVersion(); chunkList.forEach((chunk) => write(chunk)); break; case 'check': @@ -124,3 +131,22 @@ function prettierPath() { ); return path.join(basePath, 'bin-prettier.js'); } + +function updateWorkspaceJsonToMatchFormatVersion() { + const ws = new Workspaces(); + try { + const workspaceJson = JSON.parse( + readFileSync(workspaceConfigName(appRootPath)).toString() + ); + const reformatted = ws.reformattedWorkspaceJsonOrNull(workspaceJson); + if (reformatted) { + writeFileSync( + workspaceConfigName(appRootPath), + JSON.stringify(reformatted, null, 2) + ); + } + } catch (e) { + console.error(`Failed to format: ${path}`); + console.error(e); + } +} diff --git a/packages/workspace/src/migrations/update-9-4-0/add-decorate-cli.spec.ts b/packages/workspace/src/migrations/update-9-4-0/add-decorate-cli.spec.ts index c7670f667f..e85224c103 100644 --- a/packages/workspace/src/migrations/update-9-4-0/add-decorate-cli.spec.ts +++ b/packages/workspace/src/migrations/update-9-4-0/add-decorate-cli.spec.ts @@ -5,7 +5,7 @@ import { runMigration } from '../../utils/testing'; function createAngularCLIPoweredWorkspace() { const tree = createEmptyWorkspace(Tree.empty()); tree.delete('workspace.json'); - tree.create('angular.json', ''); + tree.create('angular.json', '{}'); return tree; } diff --git a/packages/workspace/src/schematics/library/library.ts b/packages/workspace/src/schematics/library/library.ts index 54d97a8ed1..ac4ffbaf65 100644 --- a/packages/workspace/src/schematics/library/library.ts +++ b/packages/workspace/src/schematics/library/library.ts @@ -53,7 +53,6 @@ function addProject(options: NormalizedSchema): Rule { root: options.projectRoot, sourceRoot: join(normalize(options.projectRoot), 'src'), projectType: 'library', - schematics: {}, architect, }; return json; diff --git a/packages/workspace/src/schematics/new/new.ts b/packages/workspace/src/schematics/new/new.ts index 58239b278d..bc92ac9deb 100644 --- a/packages/workspace/src/schematics/new/new.ts +++ b/packages/workspace/src/schematics/new/new.ts @@ -141,7 +141,7 @@ export default function (options: Schema): Rule { addCloudDependencies(options), move('/', options.directory), addTasks(options), - formatFiles(), + formatFiles({ skipFormat: false }, options.directory), ])(Tree.empty(), context); }; } diff --git a/packages/workspace/src/utils/ast-utils.spec.ts b/packages/workspace/src/utils/ast-utils.spec.ts index a57a44254d..1d9c80dfce 100644 --- a/packages/workspace/src/utils/ast-utils.spec.ts +++ b/packages/workspace/src/utils/ast-utils.spec.ts @@ -159,7 +159,10 @@ describe('addDepsToPackageJson', () => { }) ); - const testRunner = new SchematicTestRunner('@nrwl/jest', null); + const testRunner = new SchematicTestRunner( + '@nrwl/jest', + join(__dirname, '../../../jest/collection.json') + ); await testRunner .callRule(() => { @@ -188,7 +191,10 @@ describe('addDepsToPackageJson', () => { }) ); - const testRunner = new SchematicTestRunner('@nrwl/jest', null); + const testRunner = new SchematicTestRunner( + '@nrwl/jest', + join(__dirname, '../../../jest/collection.json') + ); await testRunner .callRule(() => { diff --git a/packages/workspace/src/utils/ast-utils.ts b/packages/workspace/src/utils/ast-utils.ts index 6209658add..d888b57596 100644 --- a/packages/workspace/src/utils/ast-utils.ts +++ b/packages/workspace/src/utils/ast-utils.ts @@ -367,15 +367,15 @@ export function insert(host: Tree, modulePath: string, changes: Change[]) { } // sort changes so that the highest pos goes first - const orderedChanges = changes.sort((a, b) => b.order - a.order); + const orderedChanges = changes.sort((a, b) => b.order - a.order) as any; const recorder = host.beginUpdate(modulePath); for (const change of orderedChanges) { - if (change instanceof InsertChange) { + if (change.type == 'insert') { recorder.insertLeft(change.pos, change.toAdd); - } else if (change instanceof RemoveChange) { + } else if (change.type == 'remove') { recorder.remove(change.pos - 1, change.toRemove.length + 1); - } else if (change instanceof ReplaceChange) { + } else if (change.type == 'replace') { recorder.remove(change.pos, change.oldText.length); recorder.insertLeft(change.pos, change.newText); } else if (change.type === 'noop') { diff --git a/packages/workspace/src/utils/cli-config-utils.ts b/packages/workspace/src/utils/cli-config-utils.ts index dbeb82758b..c6b4546254 100644 --- a/packages/workspace/src/utils/cli-config-utils.ts +++ b/packages/workspace/src/utils/cli-config-utils.ts @@ -3,7 +3,7 @@ import { readJsonInTree } from './ast-utils'; import { NxJson } from '@nrwl/workspace/src/core/shared-interfaces'; export function getWorkspacePath(host: Tree) { - const possibleFiles = ['/workspace.json', '/angular.json', '/.angular.json']; + const possibleFiles = ['/workspace.json', '/angular.json']; return possibleFiles.filter((path) => host.exists(path))[0]; } diff --git a/packages/workspace/src/utils/rules/format-files.ts b/packages/workspace/src/utils/rules/format-files.ts index 2654be2812..538d0f8087 100644 --- a/packages/workspace/src/utils/rules/format-files.ts +++ b/packages/workspace/src/utils/rules/format-files.ts @@ -6,22 +6,32 @@ import { SchematicContext, Tree, } from '@angular-devkit/schematics'; -let prettier; -try { - prettier = require('prettier'); -} catch (e) {} import { from } from 'rxjs'; import { filter, map, mergeMap } from 'rxjs/operators'; import * as path from 'path'; import { appRootPath } from '../app-root'; +import { Workspaces } from '@nrwl/tao/src/shared/workspace'; + +let prettier; +try { + prettier = require('prettier'); +} catch (e) {} export function formatFiles( - options: { skipFormat: boolean } = { skipFormat: false } + options: { skipFormat: boolean } = { skipFormat: false }, + directory: string = '' ): Rule { - if (options.skipFormat || !prettier) { + if (options.skipFormat) { return noop(); } + return (host: Tree, context: SchematicContext) => { + updateWorkspaceJsonToMatchFormatVersion(host, directory); + + if (!prettier) { + return host; + } + const files = new Set( host.actions .filter((action) => action.kind !== 'd' && action.kind !== 'r') @@ -64,3 +74,27 @@ export function formatFiles( ); }; } + +function updateWorkspaceJsonToMatchFormatVersion( + host: Tree, + directory: string +) { + const ws = new Workspaces(); + const possibleFiles = [ + `${directory}/workspace.json`, + `${directory}/angular.json`, + ]; + const path = possibleFiles.filter((path) => host.exists(path))[0]; + try { + if (path) { + const workspaceJson = JSON.parse(host.read(path).toString()); + const reformatted = ws.reformattedWorkspaceJsonOrNull(workspaceJson); + if (reformatted) { + host.overwrite(path, JSON.stringify(reformatted, null, 2)); + } + } + } catch (e) { + console.error(`Failed to format: ${path}`); + console.error(e); + } +} diff --git a/scripts/patched-jest-resolver.js b/scripts/patched-jest-resolver.js index 7c6e70ee3a..d4f885b500 100644 --- a/scripts/patched-jest-resolver.js +++ b/scripts/patched-jest-resolver.js @@ -50,6 +50,8 @@ module.exports = function (path, options) { } // Try to use the defaultResolver try { + if (path.startsWith('@nrwl/')) throw new Error('custom resolution'); + if (path.indexOf('@nrwl/workspace') > -1) { throw 'Reference to local Nx package found. Use local version instead.'; }