|
| 1 | +import { SemVer } from 'semver'; |
| 2 | +import { createProjectFromAsset } from '../../utils/assets'; |
| 3 | +import { expectFileMatchToExist, readFile } from '../../utils/fs'; |
| 4 | +import { setRegistry } from '../../utils/packages'; |
| 5 | +import { ng, noSilentNg } from '../../utils/process'; |
| 6 | +import { isPrereleaseCli, useCIChrome, useCIDefaults, NgCLIVersion } from '../../utils/project'; |
| 7 | + |
| 8 | +export default async function () { |
| 9 | + try { |
| 10 | + // We need to use the public registry because in the local NPM server we don't have |
| 11 | + // older versions @angular/cli packages which would cause `npm install` during `ng update` to fail. |
| 12 | + await setRegistry(false); |
| 13 | + await createProjectFromAsset('10.0-project', true); |
| 14 | + |
| 15 | + // CLI proiject version |
| 16 | + const { version: cliVersion } = JSON.parse( |
| 17 | + await readFile('./node_modules/@angular/cli/package.json'), |
| 18 | + ); |
| 19 | + const cliMajorProjectVersion = new SemVer(cliVersion).major; |
| 20 | + |
| 21 | + // CLI current version. |
| 22 | + const cliMajorVersion = NgCLIVersion.major; |
| 23 | + |
| 24 | + for (let version = cliMajorProjectVersion + 1; version < cliMajorVersion; version++) { |
| 25 | + // Run all the migrations until the current build major version - 1. |
| 26 | + // Example: when the project is using CLI version 10 and the build CLI version is 14. |
| 27 | + // We will run the following migrations: |
| 28 | + // - 10 -> 11 |
| 29 | + // - 11 -> 12 |
| 30 | + // - 12 -> 13 |
| 31 | + const { stdout } = await ng('update', `@angular/cli@${version}`, `@angular/core@${version}`); |
| 32 | + if (!stdout.includes("Executing migrations of package '@angular/cli'")) { |
| 33 | + throw new Error('Update did not execute migrations. OUTPUT: \n' + stdout); |
| 34 | + } |
| 35 | + } |
| 36 | + } finally { |
| 37 | + await setRegistry(true); |
| 38 | + } |
| 39 | + |
| 40 | + // Update Angular current build |
| 41 | + const extraUpdateArgs = isPrereleaseCli() ? ['--next', '--force'] : []; |
| 42 | + |
| 43 | + // For the latest/next release we purposely don't run `ng update @angular/core`. |
| 44 | + |
| 45 | + // During a major release when the branch version is bumped from `12.0.0-rc.x` to `12.0.0` there would be a period were in |
| 46 | + // the local NPM registry `@angular/cli@latest` will point to `12.0.0`, but on the public NPM repository `@angular/core@latest` will be `11.2.x`. |
| 47 | + |
| 48 | + // This causes `ng update @angular/core` to fail because of mismatching peer dependencies. |
| 49 | + |
| 50 | + // The reason for this is because of our bumping and release strategy. When we release a major version on NPM we don't tag it |
| 51 | + // `@latest` right away, but we wait for all teams to release their packages before doing so. While this is good because all team |
| 52 | + // packages gets tagged with `@latest` at the same time. This is problematic for our CI, since we test against the public NPM repo and are dependent on tags. |
| 53 | + |
| 54 | + // NB: `ng update @angular/cli` will still cause `@angular/core` packages to be updated therefore we still test updating the core package without running the command. |
| 55 | + |
| 56 | + await ng('update', '@angular/cli', ...extraUpdateArgs); |
| 57 | + |
| 58 | + // Setup testing to use CI Chrome. |
| 59 | + await useCIChrome('./'); |
| 60 | + await useCIChrome('./e2e/'); |
| 61 | + await useCIDefaults('ten-project'); |
| 62 | + |
| 63 | + // Run CLI commands. |
| 64 | + await ng('generate', 'component', 'my-comp'); |
| 65 | + await ng('test', '--watch=false'); |
| 66 | + await ng('e2e'); |
| 67 | + await ng('e2e', '--configuration=production'); |
| 68 | + |
| 69 | + // Verify project now creates bundles |
| 70 | + await noSilentNg('build', '--configuration=production'); |
| 71 | + await expectFileMatchToExist('dist/ten-project/', /main\.[0-9a-f]{16}\.js/); |
| 72 | +} |
0 commit comments