Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/schematics/update/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ export default function(options: PostUpdateSchema): Rule {
return (tree: Tree, context: SchematicContext) => {
const schematicsToRun: { name: string; version: string; }[] = [];

const from = _coerceVersionNumber(options.from);
if (!from) {
throw new SchematicsException(
`Invalid from option: ${JSON.stringify(options.from)}`,
);
}

const to = semver.validRange('<=' + options.to);
if (!to) {
throw new SchematicsException(
`Invalid to option: ${JSON.stringify(options.to)}`,
);
}

// Create the collection for the package.
const collection = context.engine.createCollection(options.collection);
for (const name of collection.listSchematicNames()) {
Expand All @@ -68,7 +82,8 @@ export default function(options: PostUpdateSchema): Rule {
);
}

if (semver.gt(version, options.from) && semver.lte(version, options.to)) {
if (semver.gt(version, from) &&
semver.satisfies(version, to, { includePrerelease: true })) {
schematicsToRun.push({ name, version });
}
}
Expand Down
69 changes: 69 additions & 0 deletions packages/schematics/update/migrate/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,75 @@ describe('@schematics/update:migrate', () => {
}),
).toPromise().then(done, done.fail);
});

it('supports partial version ranges with only major', done => {
// Since we cannot run tasks in unit tests, we need to validate that the default
// update schematic updates the package.json appropriately, AND validate that the
// migrate schematic actually do work appropriately, in a separate test.
schematicRunner.runSchematicAsync('migrate', {
package: 'test',
collection: require.resolve('./test/migration.json'),
from: '1',
to: '2',
}, appTree).pipe(
map(tree => {
const resultJson = JSON.parse(tree.readContent('/migrations'));

expect(resultJson).toEqual([
'migration-03', // "1.0.5"
'migration-05', // "1.1.0-beta.0"
'migration-04', // "1.1.0-beta.1"
'migration-02', // "1.1.0"
'migration-13', // "1.1.0"
'migration-19', // "1.1"
'migration-06', // "1.4.0"
'migration-17', // "2.0.0-alpha"
'migration-16', // "2.0.0-alpha.5"
'migration-08', // "2.0.0-beta.0"
'migration-07', // "2.0.0-rc.0"
'migration-12', // "2.0.0-rc.4"
'migration-14', // "2.0.0"
'migration-20', // "2"
'migration-15', // "2.0.1"
'migration-11', // "2.1.0"
]);
}),
).toPromise().then(done, done.fail);
});

it('supports partial version ranges with major and minor', done => {
// Since we cannot run tasks in unit tests, we need to validate that the default
// update schematic updates the package.json appropriately, AND validate that the
// migrate schematic actually do work appropriately, in a separate test.
schematicRunner.runSchematicAsync('migrate', {
package: 'test',
collection: require.resolve('./test/migration.json'),
from: '1.0',
to: '2.0',
}, appTree).pipe(
map(tree => {
const resultJson = JSON.parse(tree.readContent('/migrations'));

expect(resultJson).toEqual([
'migration-03', // "1.0.5"
'migration-05', // "1.1.0-beta.0"
'migration-04', // "1.1.0-beta.1"
'migration-02', // "1.1.0"
'migration-13', // "1.1.0"
'migration-19', // "1.1"
'migration-06', // "1.4.0"
'migration-17', // "2.0.0-alpha"
'migration-16', // "2.0.0-alpha.5"
'migration-08', // "2.0.0-beta.0"
'migration-07', // "2.0.0-rc.0"
'migration-12', // "2.0.0-rc.4"
'migration-14', // "2.0.0"
'migration-20', // "2"
'migration-15', // "2.0.1"
]);
}),
).toPromise().then(done, done.fail);
});
});


Expand Down