diff --git a/e2e/utils/index.ts b/e2e/utils/index.ts index 762485f3c3..647df192c9 100644 --- a/e2e/utils/index.ts +++ b/e2e/utils/index.ts @@ -21,7 +21,7 @@ export function currentCli() { let projName: string; -export function setCurrentProjName(name: string) { +function setCurrentProjName(name: string) { projName = name; return name; } @@ -42,19 +42,25 @@ export function runCreateWorkspace( style, base, packageManager, + cli, }: { preset: string; appName?: string; style?: string; base?: string; packageManager?: string; + cli?: string; } ) { + setCurrentProjName(name); + const linterArg = preset === 'angular' || preset === 'angular-nest' ? ' --linter=tslint' : ''; let command = `npx create-nx-workspace@${ process.env.PUBLISHED_VERSION - } ${name} --cli=${currentCli()} --preset=${preset} ${linterArg} --no-nxCloud --no-interactive`; + } ${name} --cli=${ + cli || currentCli() + } --preset=${preset} ${linterArg} --no-nxCloud --no-interactive`; if (appName) { command += ` --appName=${appName}`; } diff --git a/e2e/workspace/src/create-nx-workspace.test.ts b/e2e/workspace/src/create-nx-workspace.test.ts index 17cabf9df3..ff5556c072 100644 --- a/e2e/workspace/src/create-nx-workspace.test.ts +++ b/e2e/workspace/src/create-nx-workspace.test.ts @@ -1,4 +1,10 @@ -import { runCreateWorkspace, uniq } from '@nrwl/e2e/utils'; +import { + checkFilesDoNotExist, + checkFilesExist, + readJson, + runCreateWorkspace, + uniq, +} from '@nrwl/e2e/utils'; import { existsSync, mkdirSync } from 'fs-extra'; import { execSync } from 'child_process'; @@ -8,6 +14,15 @@ describe('create-nx-workspace', () => { runCreateWorkspace(wsName, { preset: 'empty', }); + + checkFilesExist( + 'workspace.json', + 'package.json', + 'package-lock.json', + 'apps/.gitkeep', + 'libs/.gitkeep' + ); + checkFilesDoNotExist('yarn.lock'); }); it('should be able to create an oss workspace', () => { @@ -110,4 +125,35 @@ describe('create-nx-workspace', () => { expect(existsSync(`${tmpDir}/${wsName}/package.json`)).toBeTruthy(); }); + + it('should respect package manager preference', () => { + const wsName = uniq('pm'); + const appName = uniq('app'); + runCreateWorkspace(wsName, { + preset: 'react', + style: 'css', + appName, + packageManager: 'yarn', + }); + + checkFilesExist('yarn.lock'); + checkFilesDoNotExist('package-lock.json'); + }); + + it('should store package manager preference for angular cli', () => { + const wsName = uniq('pm'); + const appName = uniq('app'); + runCreateWorkspace(wsName, { + preset: 'angular', + appName, + style: 'css', + packageManager: 'yarn', + cli: 'angular', + }); + + const workspaceJson = readJson('angular.json'); + expect(workspaceJson.cli.packageManager).toEqual('yarn'); + checkFilesExist('yarn.lock'); + checkFilesDoNotExist('package-lock.json'); + }); }); diff --git a/e2e/workspace/src/custom-layout.test.ts b/e2e/workspace/src/custom-layout.test.ts index b5e3f38792..ebe6bec59e 100644 --- a/e2e/workspace/src/custom-layout.test.ts +++ b/e2e/workspace/src/custom-layout.test.ts @@ -5,14 +5,13 @@ import { runCLI, runCLIAsync, runCreateWorkspace, - setCurrentProjName, uniq, yarnAdd, } from '@nrwl/e2e/utils'; describe('custom workspace layout', () => { it('should work', async () => { - const proj = setCurrentProjName(uniq('custom-layout-proj')); + const proj = uniq('custom-layout-proj'); runCreateWorkspace(proj, { preset: 'oss' }); yarnAdd('@nrwl/react @nrwl/angular @nrwl/express'); diff --git a/packages/workspace/src/schematics/shared-new/shared-new.ts b/packages/workspace/src/schematics/shared-new/shared-new.ts index 9f6b993ec0..f907e0f71a 100644 --- a/packages/workspace/src/schematics/shared-new/shared-new.ts +++ b/packages/workspace/src/schematics/shared-new/shared-new.ts @@ -134,6 +134,7 @@ export function sharedNew(cli: string, options: Schema): Rule { return chain([ schematic('workspace', { ...workspaceOpts, cli }), + cli === 'angular' ? setDefaultPackageManager(options) : noop(), setDefaultLinter(options), addPresetDependencies(options), addCloudDependencies(options), @@ -327,3 +328,17 @@ function setTSLintDefault() { return json; }); } + +function setDefaultPackageManager({ packageManager }: Schema) { + if (!packageManager) { + return noop(); + } + + return updateWorkspaceInTree((json) => { + if (!json.cli) { + json.cli = {}; + } + json.cli['packageManager'] = packageManager; + return json; + }); +}