feat(angular): install correct versions for setup-ssr (#14278)
This commit is contained in:
parent
b7a134baf6
commit
b8fc0f87ba
@ -2,6 +2,7 @@ import {
|
||||
NxJsonConfiguration,
|
||||
readJson,
|
||||
readProjectConfiguration,
|
||||
updateJson,
|
||||
updateProjectConfiguration,
|
||||
} from '@nrwl/devkit';
|
||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||
@ -177,4 +178,31 @@ describe('setupSSR', () => {
|
||||
readProjectConfiguration(tree, 'app1').targets.server
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should install the correct versions when using older versions of Angular', async () => {
|
||||
// ARRANGE
|
||||
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
||||
|
||||
await applicationGenerator(tree, {
|
||||
name: 'app1',
|
||||
});
|
||||
|
||||
updateJson(tree, 'package.json', (json) => ({
|
||||
...json,
|
||||
dependencies: {
|
||||
'@angular/core': '14.2.0',
|
||||
},
|
||||
}));
|
||||
|
||||
// ACT
|
||||
await setupSsr(tree, { project: 'app1' });
|
||||
|
||||
// ASSERT
|
||||
const pkgJson = readJson(tree, 'package.json');
|
||||
expect(pkgJson.dependencies['@angular/platform-server']).toEqual('~14.2.0');
|
||||
expect(pkgJson.dependencies['@nguniversal/express-engine']).toEqual(
|
||||
'~14.2.0'
|
||||
);
|
||||
expect(pkgJson.devDependencies['@nguniversal/builders']).toEqual('~14.2.0');
|
||||
});
|
||||
});
|
||||
|
||||
@ -11,7 +11,13 @@ import {
|
||||
updateAppModule,
|
||||
updateProjectConfig,
|
||||
} from './lib';
|
||||
import { angularVersion, ngUniversalVersion } from '../../utils/versions';
|
||||
import {
|
||||
angularVersion,
|
||||
ngUniversalVersion,
|
||||
versions,
|
||||
} from '../../utils/versions';
|
||||
import { getInstalledAngularVersionInfo } from '../utils/angular-version-utils';
|
||||
import { coerce, major } from 'semver';
|
||||
|
||||
export async function setupSsr(tree: Tree, schema: Schema) {
|
||||
const options = normalizeOptions(tree, schema);
|
||||
@ -20,14 +26,27 @@ export async function setupSsr(tree: Tree, schema: Schema) {
|
||||
updateAppModule(tree, options);
|
||||
updateProjectConfig(tree, options);
|
||||
|
||||
const installedAngularVersion = getInstalledAngularVersionInfo(tree);
|
||||
const ngUniversalVersionToUse =
|
||||
installedAngularVersion.major < major(coerce(angularVersion))
|
||||
? versions[`angularV${installedAngularVersion.major}`]
|
||||
?.ngUniversalVersion ?? ngUniversalVersion
|
||||
: ngUniversalVersion;
|
||||
|
||||
const ngPlatformServerVersionToUse =
|
||||
installedAngularVersion.major < major(coerce(angularVersion))
|
||||
? versions[`angularV${installedAngularVersion.major}`]?.angularVersion ??
|
||||
angularVersion
|
||||
: angularVersion;
|
||||
|
||||
addDependenciesToPackageJson(
|
||||
tree,
|
||||
{
|
||||
'@nguniversal/express-engine': ngUniversalVersion,
|
||||
'@angular/platform-server': angularVersion,
|
||||
'@nguniversal/express-engine': ngUniversalVersionToUse,
|
||||
'@angular/platform-server': ngPlatformServerVersionToUse,
|
||||
},
|
||||
{
|
||||
'@nguniversal/builders': ngUniversalVersion,
|
||||
'@nguniversal/builders': ngUniversalVersionToUse,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ export const tsLibVersion = '^2.3.0';
|
||||
export const ngUniversalVersion = '~15.0.0';
|
||||
export const corsVersion = '~2.8.5';
|
||||
export const expressVersion = '~4.18.2';
|
||||
export const moduleFederationNodeVersion = '~0.9.9';
|
||||
export const moduleFederationNodeVersion = '~0.10.1';
|
||||
|
||||
export const angularEslintVersion = '~15.0.0';
|
||||
export const tailwindVersion = '^3.0.2';
|
||||
@ -50,7 +50,7 @@ export const versions = {
|
||||
ngUniversalVersion: '~14.2.0',
|
||||
corsVersion: '~2.8.5',
|
||||
expressVersion: '~4.18.2',
|
||||
moduleFederationNodeVersion: '~0.9.9',
|
||||
moduleFederationNodeVersion: '^0.10.1',
|
||||
angularEslintVersion: '~14.0.4',
|
||||
tailwindVersion: '^3.0.2',
|
||||
postcssVersion: '^8.4.5',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user