test(@schematics/angular): update version 8 migration to use NPM packages

This is needed as otherwise the installation of older packages will fai.
This commit is contained in:
Alan Agius 2021-03-17 18:22:05 +01:00
parent 0199170ec7
commit b1fa5bd1bf
4 changed files with 57 additions and 21 deletions

View File

@ -3,8 +3,7 @@
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine",
"node"
"jasmine"
]
},
"files": [

View File

@ -2,6 +2,7 @@ import { join } from 'path';
import { getGlobalVariable } from '../utils/env';
import { expectFileToExist, writeFile } from '../utils/fs';
import { gitClean } from '../utils/git';
import { setRegistry as setNPMConfigRegistry } from '../utils/packages';
import { ng, npm } from '../utils/process';
import { prepareProjectForE2e, updateJsonFile } from '../utils/project';
@ -21,14 +22,7 @@ export default async function() {
const isCI = getGlobalVariable('ci');
// Ensure local test registry is used when outside a project
if (isCI) {
// Safe to set a user configuration on CI
await npm('config', 'set', 'registry', testRegistry);
} else {
// Yarn does not use the environment variable so an .npmrc file is also required
await writeFile('.npmrc', `registry=${testRegistry}`);
process.env['NPM_CONFIG_REGISTRY'] = testRegistry;
}
await setNPMConfigRegistry(true);
await ng('new', 'test-project', '--skip-install', ...extraArgs);
await expectFileToExist(join(process.cwd(), 'test-project'));

View File

@ -1,23 +1,47 @@
import { createProjectFromAsset } from '../../utils/assets';
import { expectFileMatchToExist } from '../../utils/fs';
import { installWorkspacePackages } from '../../utils/packages';
import { ng, noSilentNg, silentNpm } from '../../utils/process';
import { getGlobalVariable } from '../../utils/env';
import { expectFileMatchToExist, rimraf, writeFile } from '../../utils/fs';
import { installWorkspacePackages, setRegistry } from '../../utils/packages';
import { ng, noSilentNg } from '../../utils/process';
import { isPrereleaseCli, useBuiltPackages, useCIChrome, useCIDefaults } from '../../utils/project';
export default async function() {
await createProjectFromAsset('8.0-project');
await ng('update', '@angular/cli', '--migrate-only', '--from=8');
export default async function () {
await createProjectFromAsset('8.0-project', true, true);
// We need to use the public registry because in the local NPM server we don't have
// older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
try {
await setRegistry(false);
await useBuiltPackages();
await installWorkspacePackages();
// Update Angular CLI.
await ng('update', '@angular/cli', '--migrate-only', '--from=8');
} finally {
await setRegistry(true);
}
if (!getGlobalVariable('ci')) {
const testRegistry = getGlobalVariable('package-registry');
await writeFile('.npmrc', `registry=${testRegistry}`);
}
// Update Angular.
const extraUpdateArgs = await isPrereleaseCli() ? ['--next', '--force'] : [];
await ng('update', '@angular/core', ...extraUpdateArgs);
// Use the packages we are building in this commit, and CI Chrome.
await useBuiltPackages();
await useCIChrome('./');
await useCIChrome('./e2e/');
await useCIDefaults('eight-project');
await installWorkspacePackages();
// Update Angular.
const extraUpdateArgs = await isPrereleaseCli() ? ['--next', '--force'] : [];
await ng('update', '@angular/core', ...extraUpdateArgs);
// This is needed as otherwise causes local modules not to override already present modules
await rimraf('node_modules/@angular-devkit');
await rimraf('node_modules/@angular/cli');
await installWorkspacePackages();
// Run CLI commands.
await ng('generate', 'component', 'my-comp');

View File

@ -1,5 +1,6 @@
import { getGlobalVariable } from './env';
import { ProcessOutput, silentNpm, silentYarn } from './process';
import { writeFile } from './fs';
import { ProcessOutput, npm, silentNpm, silentYarn } from './process';
export function getActivePackageManager(): 'npm' | 'yarn' {
const value = getGlobalVariable('package-manager');
@ -39,3 +40,21 @@ export async function uninstallPackage(name: string): Promise<ProcessOutput> {
return silentYarn('remove', name);
}
}
export async function setRegistry(useTestRegistry: boolean): Promise<void> {
const url = useTestRegistry
? getGlobalVariable('package-registry')
: 'https://registry.npmjs.org';
const isCI = getGlobalVariable('ci');
// Ensure local test registry is used when outside a project
if (isCI) {
// Safe to set a user configuration on CI
await npm('config', 'set', 'registry', url);
} else {
// Yarn does not use the environment variable so an .npmrc file is also required
await writeFile('.npmrc', `registry=${url}`);
process.env['NPM_CONFIG_REGISTRY'] = url;
}
}