fix(nx): processing tests config properly on ng-add
This commit is contained in:
parent
48dae930ab
commit
d7184dfd56
@ -33,7 +33,6 @@ import {
|
|||||||
import { DEFAULT_NRWL_PRETTIER_CONFIG } from '../workspace/workspace';
|
import { DEFAULT_NRWL_PRETTIER_CONFIG } from '../workspace/workspace';
|
||||||
import { JsonArray } from '@angular-devkit/core';
|
import { JsonArray } from '@angular-devkit/core';
|
||||||
import { updateWorkspace } from '../../utils/workspace';
|
import { updateWorkspace } from '../../utils/workspace';
|
||||||
import { writeToFile } from '../../utils/fileutils';
|
|
||||||
|
|
||||||
function updatePackageJson() {
|
function updatePackageJson() {
|
||||||
return updateJsonInTree('package.json', packageJson => {
|
return updateJsonInTree('package.json', packageJson => {
|
||||||
@ -136,11 +135,13 @@ function updateAngularCLIJson(options: Schema): Rule {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const testOptions = defaultProject.targets.get('test').options;
|
const testOptions = defaultProject.targets.get('test').options;
|
||||||
|
testOptions.tsConfig = join(newRoot, 'tsconfig.spec.json');
|
||||||
testOptions.main = testOptions.main && convertAsset(testOptions.main);
|
testOptions.main = testOptions.main && convertAsset(testOptions.main);
|
||||||
testOptions.polyfills =
|
testOptions.polyfills =
|
||||||
testOptions.polyfills && convertAsset(testOptions.polyfills);
|
testOptions.polyfills && convertAsset(testOptions.polyfills);
|
||||||
testOptions.tsConfig = join(newRoot, 'tsconfig.spec.json');
|
testOptions.karmaConfig =
|
||||||
testOptions.karmaConfig = join(newRoot, 'karma.conf.js');
|
testOptions.karmaConfig &&
|
||||||
|
join(newRoot, getFilename(testOptions.karmaConfig as string));
|
||||||
testOptions.assets =
|
testOptions.assets =
|
||||||
testOptions.assets && (testOptions.assets as JsonArray).map(convertAsset);
|
testOptions.assets && (testOptions.assets as JsonArray).map(convertAsset);
|
||||||
testOptions.styles =
|
testOptions.styles =
|
||||||
@ -212,25 +213,25 @@ function updateAngularCLIJson(options: Schema): Rule {
|
|||||||
tsConfig: join(e2eRoot, 'tsconfig.json')
|
tsConfig: join(e2eRoot, 'tsconfig.json')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
e2eProject.targets.get('e2e').options.protractorConfig = join(
|
const e2eOptions = e2eProject.targets.get('e2e').options;
|
||||||
e2eRoot,
|
e2eOptions.protractorConfig =
|
||||||
'protractor.conf.js'
|
e2eOptions.protractorConfig && join(e2eRoot, 'protractor.conf.js');
|
||||||
);
|
|
||||||
defaultProject.targets.delete('e2e');
|
defaultProject.targets.delete('e2e');
|
||||||
} else if (workspace.projects.has(e2eName)) {
|
} else if (getE2eProject(workspace)) {
|
||||||
// updates the e2e project
|
// updates the e2e project
|
||||||
const e2eProject = workspace.projects.get(e2eName);
|
const e2eProject = getE2eProject(workspace);
|
||||||
e2eProject.root = e2eRoot;
|
e2eProject.root = e2eRoot;
|
||||||
e2eProject.sourceRoot = undefined;
|
e2eProject.sourceRoot = undefined;
|
||||||
|
|
||||||
if (e2eProject.targets.has('lint')) {
|
if (e2eProject.targets.has('lint')) {
|
||||||
const lintOptions = e2eProject.targets.get('lint').options;
|
const lintOptions = e2eProject.targets.get('lint').options;
|
||||||
lintOptions.tsConfig = join(e2eRoot, 'tsconfig.json');
|
lintOptions.tsConfig = join(e2eRoot, getFilename(lintOptions.tsConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e2eProject.targets.has('e2e')) {
|
if (e2eProject.targets.has('e2e')) {
|
||||||
const e2eOptions = e2eProject.targets.get('e2e').options;
|
const e2eOptions = e2eProject.targets.get('e2e').options;
|
||||||
e2eOptions.protractorConfig = join(e2eRoot, 'protractor.conf.js');
|
e2eOptions.protractorConfig =
|
||||||
|
e2eOptions.protractorConfig && join(e2eRoot, 'protractor.conf.js');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -242,24 +243,6 @@ function updateTsConfig(options: Schema): Rule {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseLoadChildren(loadChildrenString: string) {
|
|
||||||
const [path, className] = loadChildrenString.split('#');
|
|
||||||
return {
|
|
||||||
path,
|
|
||||||
className
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function serializeLoadChildren({
|
|
||||||
path,
|
|
||||||
className
|
|
||||||
}: {
|
|
||||||
path: string;
|
|
||||||
className: string;
|
|
||||||
}) {
|
|
||||||
return `${path}#${className}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateTsConfigsJson(options: Schema) {
|
function updateTsConfigsJson(options: Schema) {
|
||||||
return (host: Tree) => {
|
return (host: Tree) => {
|
||||||
const workspaceJson = readJsonInTree(host, 'angular.json');
|
const workspaceJson = readJsonInTree(host, 'angular.json');
|
||||||
@ -268,12 +251,12 @@ function updateTsConfigsJson(options: Schema) {
|
|||||||
|
|
||||||
const offset = '../../';
|
const offset = '../../';
|
||||||
updateJsonFile(app.architect.build.options.tsConfig, json => {
|
updateJsonFile(app.architect.build.options.tsConfig, json => {
|
||||||
json.extends = `${offset}tsconfig.json`;
|
json.extends = offset + getFilename(app.architect.build.options.tsConfig);
|
||||||
json.compilerOptions.outDir = `${offset}dist/out-tsc`;
|
json.compilerOptions.outDir = `${offset}dist/out-tsc`;
|
||||||
});
|
});
|
||||||
|
|
||||||
updateJsonFile(app.architect.test.options.tsConfig, json => {
|
updateJsonFile(app.architect.test.options.tsConfig, json => {
|
||||||
json.extends = `${offset}tsconfig.json`;
|
json.extends = offset + getFilename(app.architect.test.options.tsConfig);
|
||||||
json.compilerOptions.outDir = `${offset}dist/out-tsc`;
|
json.compilerOptions.outDir = `${offset}dist/out-tsc`;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -285,7 +268,9 @@ function updateTsConfigsJson(options: Schema) {
|
|||||||
|
|
||||||
if (e2eProject) {
|
if (e2eProject) {
|
||||||
updateJsonFile(e2eProject.architect.lint.options.tsConfig, json => {
|
updateJsonFile(e2eProject.architect.lint.options.tsConfig, json => {
|
||||||
json.extends = `${offsetFromRoot(e2eProject.root)}tsconfig.json`;
|
json.extends =
|
||||||
|
offsetFromRoot(e2eProject.root) +
|
||||||
|
getFilename(e2eProject.architect.lint.options.tsConfig);
|
||||||
json.compilerOptions = {
|
json.compilerOptions = {
|
||||||
...json.compilerOptions,
|
...json.compilerOptions,
|
||||||
outDir: `${offsetFromRoot(e2eProject.root)}dist/out-tsc`
|
outDir: `${offsetFromRoot(e2eProject.root)}dist/out-tsc`
|
||||||
@ -364,7 +349,9 @@ function moveOutOfSrc(
|
|||||||
} else if (!err) {
|
} else if (!err) {
|
||||||
context.logger.info(`Renamed ${from} -> ${to}`);
|
context.logger.info(`Renamed ${from} -> ${to}`);
|
||||||
} else {
|
} else {
|
||||||
context.logger.warn(`Tried to rename ${from} -> ${to} but ${err.message}`);
|
context.logger.warn(
|
||||||
|
`Tried to rename ${from} -> ${to} but ${err.message}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -379,6 +366,13 @@ function getE2eKey(workspaceJson: any) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getE2eName(workspaceJson: any) {
|
||||||
|
const appName = Object.keys(workspaceJson.projects).find(key => {
|
||||||
|
return !!workspaceJson.projects[key].architect.build;
|
||||||
|
});
|
||||||
|
return appName + '-e2e';
|
||||||
|
}
|
||||||
|
|
||||||
function getE2eProject(workspaceJson: any) {
|
function getE2eProject(workspaceJson: any) {
|
||||||
const key = getE2eKey(workspaceJson);
|
const key = getE2eKey(workspaceJson);
|
||||||
if (key) {
|
if (key) {
|
||||||
@ -397,23 +391,17 @@ function moveExistingFiles(options: Schema) {
|
|||||||
// No context is passed because it should not be required to have a browserslist
|
// No context is passed because it should not be required to have a browserslist
|
||||||
moveOutOfSrc(options.name, 'browserslist');
|
moveOutOfSrc(options.name, 'browserslist');
|
||||||
|
|
||||||
moveOutOfSrc(
|
moveOutOfSrc(options.name, app.architect.build.options.tsConfig, context);
|
||||||
options.name,
|
|
||||||
app.architect.test.options.karmaConfig,
|
|
||||||
context
|
|
||||||
);
|
|
||||||
|
|
||||||
moveOutOfSrc(
|
moveOutOfSrc(options.name, app.architect.test.options.tsConfig, context);
|
||||||
options.name,
|
|
||||||
app.architect.build.options.tsConfig,
|
|
||||||
context
|
|
||||||
);
|
|
||||||
|
|
||||||
moveOutOfSrc(
|
if (app.architect.test.options.karmaConfig) {
|
||||||
options.name,
|
moveOutOfSrc(
|
||||||
app.architect.test.options.tsConfig,
|
options.name,
|
||||||
context
|
app.architect.test.options.karmaConfig,
|
||||||
);
|
context
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (app.architect.server) {
|
if (app.architect.server) {
|
||||||
moveOutOfSrc(
|
moveOutOfSrc(
|
||||||
@ -431,19 +419,23 @@ function moveExistingFiles(options: Schema) {
|
|||||||
`Renamed ${oldAppSourceRoot} -> ${newAppSourceRoot}`
|
`Renamed ${oldAppSourceRoot} -> ${newAppSourceRoot}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
context.logger.error(`Tried to rename ${oldAppSourceRoot} -> ${newAppSourceRoot} but ${err.message}`);
|
context.logger.error(
|
||||||
|
`Tried to rename ${oldAppSourceRoot} -> ${newAppSourceRoot} but ${err.message}`
|
||||||
|
);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (e2eApp) {
|
if (e2eApp) {
|
||||||
const oldE2eRoot = 'e2e';
|
const oldE2eRoot = 'e2e';
|
||||||
const newE2eRoot = join('apps', getE2eKey(workspaceJson) + '-e2e');
|
const newE2eRoot = join('apps', getE2eName(workspaceJson));
|
||||||
renameSync(oldE2eRoot, newE2eRoot, err => {
|
renameSync(oldE2eRoot, newE2eRoot, err => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
context.logger.info(`Renamed ${oldE2eRoot} -> ${newE2eRoot}`);
|
context.logger.info(`Renamed ${oldE2eRoot} -> ${newE2eRoot}`);
|
||||||
} else {
|
} else {
|
||||||
context.logger.error(`Tried to rename ${oldE2eRoot} -> ${newE2eRoot} but ${err.message}`);
|
context.logger.error(
|
||||||
|
`Tried to rename ${oldE2eRoot} -> ${newE2eRoot} but ${err.message}`
|
||||||
|
);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -475,7 +467,7 @@ function createAdditionalFiles(options: Schema): Rule {
|
|||||||
[options.name]: {
|
[options.name]: {
|
||||||
tags: []
|
tags: []
|
||||||
},
|
},
|
||||||
[getE2eKey(workspaceJson) + '-e2e']: {
|
[getE2eName(workspaceJson)]: {
|
||||||
tags: []
|
tags: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user