Skip to content

Commit 132f9f8

Browse files
alan-agius4angular-robot[bot]
authored andcommitted
Revert "test: use NPM_CONFIG_legacy_peer_deps when testing prerelease versions of Angular material."
This reverts commit 04e7c25 as it is no longer needed due to the recent changes done in the material packages to expand the peer dependency. See: angular/components@6afe888
1 parent 3ebb195 commit 132f9f8

File tree

3 files changed

+38
-80
lines changed

3 files changed

+38
-80
lines changed

tests/legacy-cli/e2e/tests/build/material.ts

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,37 @@ import { isPrereleaseCli, updateJsonFile } from '../../utils/project';
77
const snapshots = require('../../ng-snapshot/package.json');
88

99
export default async function () {
10-
// `@angular/material` pre-release may not support the current version of `@angular/core` pre-release.
11-
// due to the order of releases FW -> CLI -> Material
12-
// In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
13-
const original_NPM_CONFIG_legacy_peer_deps = process.env['NPM_CONFIG_legacy_peer_deps'];
14-
const isPrerelease = await isPrereleaseCli();
10+
let tag = (await isPrereleaseCli()) ? '@next' : '';
11+
await ng('add', `@angular/material${tag}`, '--skip-confirmation');
1512

16-
let tag = isPrerelease ? '@next' : '';
17-
18-
try {
19-
process.env['NPM_CONFIG_legacy_peer_deps'] = isPrerelease
20-
? 'true'
21-
: original_NPM_CONFIG_legacy_peer_deps;
22-
23-
await ng('add', `@angular/material${tag}`, '--skip-confirmation');
24-
25-
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
26-
if (isSnapshotBuild) {
27-
await updateJsonFile('package.json', (packageJson) => {
28-
const dependencies = packageJson['dependencies'];
29-
// Angular material adds dependencies on other Angular packages
30-
// Iterate over all of the packages to update them to the snapshot version.
31-
for (const [name, version] of Object.entries(snapshots.dependencies)) {
32-
if (name in dependencies) {
33-
dependencies[name] = version;
34-
}
13+
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
14+
if (isSnapshotBuild) {
15+
await updateJsonFile('package.json', (packageJson) => {
16+
const dependencies = packageJson['dependencies'];
17+
// Angular material adds dependencies on other Angular packages
18+
// Iterate over all of the packages to update them to the snapshot version.
19+
for (const [name, version] of Object.entries(snapshots.dependencies)) {
20+
if (name in dependencies) {
21+
dependencies[name] = version;
3522
}
36-
37-
dependencies['@angular/material-moment-adapter'] =
38-
snapshots.dependencies['@angular/material-moment-adapter'];
39-
});
40-
await installWorkspacePackages();
41-
} else {
42-
if (!tag) {
43-
const installedMaterialVersion = JSON.parse(await readFile('package.json'))['dependencies'][
44-
'@angular/material'
45-
];
46-
tag = `@${installedMaterialVersion}`;
4723
}
48-
await installPackage(`@angular/material-moment-adapter${tag}`);
49-
}
5024

51-
await installPackage('moment');
52-
} finally {
53-
process.env['NPM_CONFIG_legacy_peer_deps'] = original_NPM_CONFIG_legacy_peer_deps;
25+
dependencies['@angular/material-moment-adapter'] =
26+
snapshots.dependencies['@angular/material-moment-adapter'];
27+
});
28+
await installWorkspacePackages();
29+
} else {
30+
if (!tag) {
31+
const installedMaterialVersion = JSON.parse(await readFile('package.json'))['dependencies'][
32+
'@angular/material'
33+
];
34+
tag = `@${installedMaterialVersion}`;
35+
}
36+
await installPackage(`@angular/material-moment-adapter${tag}`);
5437
}
5538

39+
await installPackage('moment');
40+
5641
await ng('build');
5742

5843
// Ensure moment adapter works (uses unique importing mechanism for moment)

tests/legacy-cli/e2e/tests/commands/add/add-material.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
11
import { assertIsError } from '../../../utils/utils';
22
import { expectFileToMatch, rimraf } from '../../../utils/fs';
33
import { uninstallPackage } from '../../../utils/packages';
4-
import { execWithEnv } from '../../../utils/process';
4+
import { ng } from '../../../utils/process';
55
import { isPrereleaseCli } from '../../../utils/project';
66

77
export default async function () {
88
// forcibly remove in case another test doesn't clean itself up
99
await rimraf('node_modules/@angular/material');
1010

11-
const isPrerelease = await isPrereleaseCli();
12-
const tag = isPrerelease ? '@next' : '';
13-
const processEnv = {
14-
...process.env,
15-
// `@angular/material` pre-release may not support the current version of `@angular/core` pre-release.
16-
// due to the order of releases FW -> CLI -> Material
17-
// In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
18-
'NPM_CONFIG_legacy_peer_deps': isPrerelease
19-
? 'true'
20-
: process.env['NPM_CONFIG_legacy_peer_deps'],
21-
};
11+
const tag = (await isPrereleaseCli()) ? '@next' : '';
2212

2313
try {
24-
await execWithEnv(
25-
'ng',
26-
['add', `@angular/material${tag}`, '--skip-confirmation', '--unknown'],
27-
processEnv,
28-
);
14+
await ng('add', `@angular/material${tag}`, '--unknown', '--skip-confirmation');
2915
} catch (error) {
3016
assertIsError(error);
3117
if (!(error as Error).message.includes(`Unknown option: '--unknown'`)) {
3218
throw error;
3319
}
3420
}
3521

36-
await execWithEnv(
37-
'ng',
38-
['add', `@angular/material${tag}`, '--theme', 'custom', '--verbose', '--skip-confirmation'],
39-
processEnv,
22+
await ng(
23+
'add',
24+
`@angular/material${tag}`,
25+
'--theme',
26+
'custom',
27+
'--verbose',
28+
'--skip-confirmation',
4029
);
41-
4230
await expectFileToMatch('package.json', /@angular\/material/);
4331

4432
// Clean up existing cdk package

tests/legacy-cli/e2e/tests/misc/invalid-schematic-dependencies.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expectFileToMatch } from '../../utils/fs';
2-
import { execWithEnv, extractNpmEnv, silentNpm } from '../../utils/process';
2+
import { execWithEnv, extractNpmEnv, ng, silentNpm } from '../../utils/process';
33
import { installPackage, uninstallPackage } from '../../utils/packages';
44
import { isPrereleaseCli } from '../../utils/project';
55

@@ -13,23 +13,8 @@ export default async function () {
1313
// Install outdated and incompatible version
1414
await installPackage('@schematics/angular@7');
1515

16-
const isPrerelease = await isPrereleaseCli();
17-
const tag = isPrerelease ? '@next' : '';
18-
19-
await execWithEnv(
20-
'ng',
21-
['add', `@angular/material${tag}`, '--skip-confirmation'],
22-
// `@angular/material` pre-release may not support the current version of `@angular/core` pre-release.
23-
// due to the order of releases FW -> CLI -> Material
24-
// In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
25-
{
26-
...process.env,
27-
'NPM_CONFIG_legacy_peer_deps': isPrerelease
28-
? 'true'
29-
: process.env['NPM_CONFIG_legacy_peer_deps'],
30-
},
31-
);
32-
16+
const tag = (await isPrereleaseCli()) ? '@next' : '';
17+
await ng('add', `@angular/material${tag}`, '--skip-confirmation');
3318
await expectFileToMatch('package.json', /@angular\/material/);
3419

3520
// Clean up existing cdk package

0 commit comments

Comments
 (0)