fix(core): store packageManager preference in angular.json
This commit is contained in:
parent
89826063a0
commit
7383af3fb3
@ -21,7 +21,7 @@ export function currentCli() {
|
|||||||
|
|
||||||
let projName: string;
|
let projName: string;
|
||||||
|
|
||||||
export function setCurrentProjName(name: string) {
|
function setCurrentProjName(name: string) {
|
||||||
projName = name;
|
projName = name;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -42,19 +42,25 @@ export function runCreateWorkspace(
|
|||||||
style,
|
style,
|
||||||
base,
|
base,
|
||||||
packageManager,
|
packageManager,
|
||||||
|
cli,
|
||||||
}: {
|
}: {
|
||||||
preset: string;
|
preset: string;
|
||||||
appName?: string;
|
appName?: string;
|
||||||
style?: string;
|
style?: string;
|
||||||
base?: string;
|
base?: string;
|
||||||
packageManager?: string;
|
packageManager?: string;
|
||||||
|
cli?: string;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
setCurrentProjName(name);
|
||||||
|
|
||||||
const linterArg =
|
const linterArg =
|
||||||
preset === 'angular' || preset === 'angular-nest' ? ' --linter=tslint' : '';
|
preset === 'angular' || preset === 'angular-nest' ? ' --linter=tslint' : '';
|
||||||
let command = `npx create-nx-workspace@${
|
let command = `npx create-nx-workspace@${
|
||||||
process.env.PUBLISHED_VERSION
|
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) {
|
if (appName) {
|
||||||
command += ` --appName=${appName}`;
|
command += ` --appName=${appName}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 { existsSync, mkdirSync } from 'fs-extra';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
|
|
||||||
@ -8,6 +14,15 @@ describe('create-nx-workspace', () => {
|
|||||||
runCreateWorkspace(wsName, {
|
runCreateWorkspace(wsName, {
|
||||||
preset: 'empty',
|
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', () => {
|
it('should be able to create an oss workspace', () => {
|
||||||
@ -110,4 +125,35 @@ describe('create-nx-workspace', () => {
|
|||||||
|
|
||||||
expect(existsSync(`${tmpDir}/${wsName}/package.json`)).toBeTruthy();
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,14 +5,13 @@ import {
|
|||||||
runCLI,
|
runCLI,
|
||||||
runCLIAsync,
|
runCLIAsync,
|
||||||
runCreateWorkspace,
|
runCreateWorkspace,
|
||||||
setCurrentProjName,
|
|
||||||
uniq,
|
uniq,
|
||||||
yarnAdd,
|
yarnAdd,
|
||||||
} from '@nrwl/e2e/utils';
|
} from '@nrwl/e2e/utils';
|
||||||
|
|
||||||
describe('custom workspace layout', () => {
|
describe('custom workspace layout', () => {
|
||||||
it('should work', async () => {
|
it('should work', async () => {
|
||||||
const proj = setCurrentProjName(uniq('custom-layout-proj'));
|
const proj = uniq('custom-layout-proj');
|
||||||
runCreateWorkspace(proj, { preset: 'oss' });
|
runCreateWorkspace(proj, { preset: 'oss' });
|
||||||
yarnAdd('@nrwl/react @nrwl/angular @nrwl/express');
|
yarnAdd('@nrwl/react @nrwl/angular @nrwl/express');
|
||||||
|
|
||||||
|
|||||||
@ -134,6 +134,7 @@ export function sharedNew(cli: string, options: Schema): Rule {
|
|||||||
|
|
||||||
return chain([
|
return chain([
|
||||||
schematic('workspace', { ...workspaceOpts, cli }),
|
schematic('workspace', { ...workspaceOpts, cli }),
|
||||||
|
cli === 'angular' ? setDefaultPackageManager(options) : noop(),
|
||||||
setDefaultLinter(options),
|
setDefaultLinter(options),
|
||||||
addPresetDependencies(options),
|
addPresetDependencies(options),
|
||||||
addCloudDependencies(options),
|
addCloudDependencies(options),
|
||||||
@ -327,3 +328,17 @@ function setTSLintDefault() {
|
|||||||
return json;
|
return json;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setDefaultPackageManager({ packageManager }: Schema) {
|
||||||
|
if (!packageManager) {
|
||||||
|
return noop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return updateWorkspaceInTree((json) => {
|
||||||
|
if (!json.cli) {
|
||||||
|
json.cli = {};
|
||||||
|
}
|
||||||
|
json.cli['packageManager'] = packageManager;
|
||||||
|
return json;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user