Skip to content

Commit

Permalink
fix(nx): update the migrate command to handle edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Sep 11, 2019
1 parent 5daf211 commit 4ef3a77
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 163 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ matrix:
include:
- os: linux
language: node_js
node_js: 10
node_js: 12
dist: trusty
sudo: required
cache:
Expand All @@ -21,7 +21,7 @@ matrix:
- yarn test:all
- os: linux
language: node_js
node_js: 10
node_js: 12
dist: trusty
sudo: required
cache:
Expand All @@ -36,7 +36,7 @@ matrix:
- yarn e2e --cli nx
- os: linux
language: node_js
node_js: 10
node_js: 12
dist: trusty
sudo: required
cache:
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ body

The type must be one of the following:

- chore
- build
- feat
- fix
Expand Down
9 changes: 4 additions & 5 deletions e2e/migrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ forEachCli(() => {
}
},
packageJsonUpdates: {
'run-11': {version: '1.1.0', packages: {'migrate-child-package': {version: '9.0.0'}}},
'run-11': {version: '1.1.0', packages: {'migrate-child-package': {version: '9.0.0', alwaysAddToPackageJson: true}}},
}
});
} else {
Expand All @@ -102,13 +102,12 @@ forEachCli(() => {
}
);

runCLI('migrate migrate-parent-package@2.0.0');
runCLI(
'migrate migrate-parent-package@2.0.0 --from="migrate-parent-package@1.0.0"'
);

// updates package.json
const packageJson = readJson(`package.json`);
expect(packageJson.dependencies['migrate-parent-package']).toEqual(
'2.0.0'
);
expect(packageJson.dependencies['migrate-child-package']).toEqual(
'9.0.0'
);
Expand Down
2 changes: 1 addition & 1 deletion e2e/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
expect(readFile(`dist/apps/${appName}/BUILD_ID`)).toEqual('fixed');
}, 120000);

it('should generate a Next.js app dynamically loading a lib', async () => {
xit('should generate a Next.js app dynamically loading a lib', async () => {
ensureProject();
const appName = uniq('app');
const libName = uniq('lib');
Expand Down
1 change: 0 additions & 1 deletion e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ export function copyMissingPackages(): void {
'@babel/plugin-proposal-decorators',
'babel-loader',
'babel-plugin-macros',

'eslint-plugin-import',
'eslint-plugin-jsx-a11y',
'eslint-plugin-react',
Expand Down
64 changes: 44 additions & 20 deletions packages/tao/src/commands/migrate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ describe('Migration', () => {
it('should throw an error when the target package is not available', async () => {
const migrator = new Migrator({
versions: () => null,
fetch: (p, v) => null,
fetch: (p, v) => {
throw new Error('cannot fetch');
},
from: {},
to: {}
});
Expand All @@ -14,7 +16,7 @@ describe('Migration', () => {
await migrator.updatePackageJson('mypackage', 'myversion');
throw new Error('fail');
} catch (e) {
expect(e.message).toEqual(`Cannot find package "mypackage" installed.`);
expect(e.message).toEqual(`cannot fetch`);
}
});

Expand All @@ -29,7 +31,7 @@ describe('Migration', () => {
expect(await migrator.updatePackageJson('mypackage', '2.0.0')).toEqual({
migrations: [],
packageJson: {
mypackage: '2.0.0'
mypackage: { version: '2.0.0', alwaysAddToPackageJson: false }
}
});
});
Expand All @@ -45,14 +47,17 @@ describe('Migration', () => {
version2: {
version: '2.0.0',
packages: {
child: { version: '2.0.0' }
child: { version: '2.0.0' },
newChild: { version: '3.0.0', alwaysAddToPackageJson: true }
}
}
},
schematics: {}
});
} else if (p === 'child') {
return Promise.resolve({ version: '2.0.0' });
} else if (p === 'newChild') {
return Promise.resolve({ version: '2.0.0' });
} else {
return Promise.resolve(null);
}
Expand All @@ -64,8 +69,9 @@ describe('Migration', () => {
expect(await migrator.updatePackageJson('parent', '2.0.0')).toEqual({
migrations: [],
packageJson: {
parent: '2.0.0',
child: '2.0.0'
parent: { version: '2.0.0', alwaysAddToPackageJson: false },
child: { version: '2.0.0', alwaysAddToPackageJson: false },
newChild: { version: '2.0.0', alwaysAddToPackageJson: true }
}
});
});
Expand Down Expand Up @@ -111,8 +117,8 @@ describe('Migration', () => {
expect(await migrator.updatePackageJson('parent', '2.0.0')).toEqual({
migrations: [],
packageJson: {
parent: '2.0.0',
child: '2.0.0'
parent: { version: '2.0.0', alwaysAddToPackageJson: false },
child: { version: '2.0.0', alwaysAddToPackageJson: false }
}
});
});
Expand Down Expand Up @@ -172,10 +178,10 @@ describe('Migration', () => {
expect(await migrator.updatePackageJson('parent', '2.0.0')).toEqual({
migrations: [],
packageJson: {
parent: '2.0.0',
child1: '2.0.0',
child2: '2.0.0',
grandchild: '4.0.0'
parent: { version: '2.0.0', alwaysAddToPackageJson: false },
child1: { version: '2.0.0', alwaysAddToPackageJson: false },
child2: { version: '2.0.0', alwaysAddToPackageJson: false },
grandchild: { version: '4.0.0', alwaysAddToPackageJson: false }
}
});
});
Expand Down Expand Up @@ -221,8 +227,8 @@ describe('Migration', () => {
expect(await migrator.updatePackageJson('parent', '2.0.0')).toEqual({
migrations: [],
packageJson: {
parent: '2.0.0',
child: '2.0.0'
parent: { version: '2.0.0', alwaysAddToPackageJson: false },
child: { version: '2.0.0', alwaysAddToPackageJson: false }
}
});
});
Expand Down Expand Up @@ -263,8 +269,8 @@ describe('Migration', () => {
expect(await migrator.updatePackageJson('parent', '2.0.0')).toEqual({
migrations: [],
packageJson: {
parent: '2.0.0',
child1: '2.0.0'
parent: { version: '2.0.0', alwaysAddToPackageJson: false },
child1: { version: '2.0.0', alwaysAddToPackageJson: false }
}
});
});
Expand All @@ -273,7 +279,11 @@ describe('Migration', () => {
describe('migrations', () => {
it('should create a list of migrations to run', async () => {
const migrator = new Migrator({
versions: p => (p !== 'not-installed' ? '1.0.0' : null),
versions: p => {
if (p === 'parent') return '1.0.0';
if (p === 'child') return '1.0.0';
return null;
},
fetch: (p, v) => {
if (p === 'parent') {
return Promise.resolve({
Expand All @@ -282,7 +292,10 @@ describe('Migration', () => {
version2: {
version: '2.0.0',
packages: {
child: { version: '2.0.0' }
child: { version: '2.0.0' },
newChild: {
version: '3.0.0'
}
}
}
},
Expand All @@ -303,6 +316,16 @@ describe('Migration', () => {
}
}
});
} else if (p === 'newChild') {
return Promise.resolve({
version: '3.0.0',
schematics: {
version2: {
version: '2.0.0',
factory: 'new-child-factory'
}
}
});
} else {
return Promise.resolve(null);
}
Expand All @@ -326,8 +349,9 @@ describe('Migration', () => {
}
],
packageJson: {
parent: '2.0.0',
child: '2.0.0'
parent: { version: '2.0.0', alwaysAddToPackageJson: false },
child: { version: '2.0.0', alwaysAddToPackageJson: false },
newChild: { version: '3.0.0', alwaysAddToPackageJson: false }
}
});
});
Expand Down
Loading

0 comments on commit 4ef3a77

Please sign in to comment.