Skip to content

Commit

Permalink
fix(nx): migrate command should not download migrations for packages …
Browse files Browse the repository at this point in the history
…that arent installed
  • Loading branch information
vsavkin committed Oct 26, 2019
1 parent 294224b commit 35f20b1
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 22 deletions.
4 changes: 3 additions & 1 deletion e2e/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ forEachCli(() => {
const before = content.substring(0, start);
const after = content.substring(end);
const newFetch = `
function fetch(packageName) {
function createFetcher(logger) {
return function fetch(packageName) {
if (packageName === 'migrate-parent-package') {
return Promise.resolve({
version: '2.0.0',
Expand All @@ -96,6 +97,7 @@ forEachCli(() => {
return Promise.resolve({version: '9.0.0'});
}
}
}
`;

return `${before}${newFetch}${after}`;
Expand Down
34 changes: 33 additions & 1 deletion packages/tao/src/commands/migrate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('Migration', () => {
describe('packageJson patch', () => {
it('should throw an error when the target package is not available', async () => {
const migrator = new Migrator({
versions: () => null,
versions: () => '1.0',
fetch: (p, v) => {
throw new Error('cannot fetch');
},
Expand Down Expand Up @@ -312,6 +312,38 @@ describe('Migration', () => {
}
});
});

it('should not throw when packages are missing', async () => {
const migrator = new Migrator({
versions: p => (p === '@nrwl/nest' ? null : '1.0.0'),
fetch: (p, v) =>
Promise.resolve({
version: '2.0.0',
packageJsonUpdates: { one: { version: '2.0.0', packages: {} } }
}),
from: {},
to: {}
});
await migrator.updatePackageJson('@nrwl/workspace', '2.0.0');
});

it('should only fetch packages that are installed', async () => {
const migrator = new Migrator({
versions: p => (p === '@nrwl/nest' ? null : '1.0.0'),
fetch: (p, v) => {
if (p === '@nrwl/nest') {
throw new Error('Boom');
}
return Promise.resolve({
version: '2.0.0',
packageJsonUpdates: { one: { version: '2.0.0', packages: {} } }
});
},
from: {},
to: {}
});
await migrator.updatePackageJson('@nrwl/workspace', '2.0.0');
});
});

describe('migrations', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/tao/src/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ export class Migrator {
targetVersion = this.to[targetPackage];
}

if (!this.versions(targetPackage)) {
return {
[targetPackage]: {
version: target.version,
alwaysAddToPackageJson: !!target.alwaysAddToPackageJson
}
};
}

let migrationsJson;
try {
migrationsJson = await this.fetch(targetPackage, targetVersion);
Expand Down
22 changes: 11 additions & 11 deletions scripts/e2e-ci1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ mkdir -p tmp/angular
mkdir -p tmp/nx

export SELECTED_CLI=$1
jest --maxWorkers=1 ./build/e2e/affected.test.js
jest --maxWorkers=1 ./build/e2e/command-line.test.js
jest --maxWorkers=1 ./build/e2e/cypress.test.js
jest --maxWorkers=1 ./build/e2e/delegate-to-cli.test.js
jest --maxWorkers=1 ./build/e2e/downgrade-module.test.js
jest --maxWorkers=1 ./build/e2e/help.test.js
jest --maxWorkers=1 ./build/e2e/jest.test.js
jest --maxWorkers=1 ./build/e2e/karma.test.js
jest --maxWorkers=1 ./build/e2e/list.test.js
jest --maxWorkers=1 ./build/e2e/migrate.test.js
jest --maxWorkers=1 ./build/e2e/new.test.js
jest --maxWorkers=1 ./build/e2e/affected.test.js &&
jest --maxWorkers=1 ./build/e2e/command-line.test.js &&
jest --maxWorkers=1 ./build/e2e/cypress.test.js &&
jest --maxWorkers=1 ./build/e2e/delegate-to-cli.test.js &&
jest --maxWorkers=1 ./build/e2e/downgrade-module.test.js &&
jest --maxWorkers=1 ./build/e2e/help.test.js &&
jest --maxWorkers=1 ./build/e2e/jest.test.js &&
jest --maxWorkers=1 ./build/e2e/karma.test.js &&
jest --maxWorkers=1 ./build/e2e/list.test.js &&
jest --maxWorkers=1 ./build/e2e/migrate.test.js &&
jest --maxWorkers=1 ./build/e2e/new.test.js &&
jest --maxWorkers=1 ./build/e2e/next.test.js
18 changes: 9 additions & 9 deletions scripts/e2e-ci2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ mkdir -p tmp/angular
mkdir -p tmp/nx

export SELECTED_CLI=$1
jest --maxWorkers=1 ./build/e2e/ng-add.test.js
jest --maxWorkers=1 ./build/e2e/ngrx.test.js
jest --maxWorkers=1 ./build/e2e/node.test.js
jest --maxWorkers=1 ./build/e2e/print-affected.test.js
jest --maxWorkers=1 ./build/e2e/react.test.js
jest --maxWorkers=1 ./build/e2e/report.test.js
jest --maxWorkers=1 ./build/e2e/upgrade-module.test.js
jest --maxWorkers=1 ./build/e2e/web.test.js
jest --maxWorkers=1 ./build/e2e/storybook.test.js
jest --maxWorkers=1 ./build/e2e/ng-add.test.js &&
jest --maxWorkers=1 ./build/e2e/ngrx.test.js &&
jest --maxWorkers=1 ./build/e2e/node.test.js &&
jest --maxWorkers=1 ./build/e2e/print-affected.test.js &&
jest --maxWorkers=1 ./build/e2e/react.test.js &&
jest --maxWorkers=1 ./build/e2e/report.test.js &&
jest --maxWorkers=1 ./build/e2e/upgrade-module.test.js &&
jest --maxWorkers=1 ./build/e2e/web.test.js &&
jest --maxWorkers=1 ./build/e2e/storybook.test.js
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15489,6 +15489,14 @@ saxes@^3.1.5:
dependencies:
xmlchars "^2.1.1"

scheduler@^0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.15.0.tgz#6bfcf80ff850b280fed4aeecc6513bc0b4f17f8e"
integrity sha512-xAefmSfN6jqAa7Kuq7LIJY0bwAPG3xlCj0HMEBQk1lxYiDKZscY2xJ5U/61ZTrYbmNQbXa+gc7czPkVo11tnCg==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

scheduler@^0.16.2:
version "0.16.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.2.tgz#f74cd9d33eff6fc554edfb79864868e4819132c1"
Expand Down

0 comments on commit 35f20b1

Please sign in to comment.