diff --git a/README.md b/README.md index 8827034..71555c2 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,8 @@ const res = await semgrator({ }) console.log(res.result) +console.log(res.changed) +console.log(res.version) ``` ### Getting intermediate results diff --git a/src/lib/semgrator.ts b/src/lib/semgrator.ts index 4ccb1f9..85383e9 100644 --- a/src/lib/semgrator.ts +++ b/src/lib/semgrator.ts @@ -28,6 +28,7 @@ interface SemgratorParamsWithPath interface SemgratorResult { version: string + changed: boolean result: Output } @@ -81,14 +82,16 @@ async function* processMigrations( ): AsyncGenerator> { let result = input as unknown let lastVersion = version + let changed = false for await (const migration of migrations) { if (semver.gt(migration.version, lastVersion)) { // @ts-expect-error result = await migration.up(result) lastVersion = migration.toVersion || migration.version + changed = true } - yield { version: lastVersion, result: result as Output } + yield { version: lastVersion, result: result as Output, changed } } } diff --git a/src/test/semgrator.test.ts b/src/test/semgrator.test.ts index e4864be..11a1ee5 100644 --- a/src/test/semgrator.test.ts +++ b/src/test/semgrator.test.ts @@ -9,7 +9,7 @@ type SeenBy = { } test('apply all migrations', async t => { - const plan = tspl(t, { plan: 3 }) + const plan = tspl(t, { plan: 4 }) const m1: Migration = { version: '2.0.0', async up(input) { @@ -43,6 +43,7 @@ test('apply all migrations', async t => { }) plan.equal(res.version, '2.4.0') + plan.equal(res.changed, true) plan.deepEqual(res.result, { foo: 'bar', seenBy: '2.4.0', @@ -91,7 +92,7 @@ test('apply only needed', async t => { }) test('apply no migrations', async t => { - const plan = tspl(t, { plan: 2 }) + const plan = tspl(t, { plan: 3 }) const m1: Migration = { version: '2.0.0', async up(input) { @@ -123,6 +124,7 @@ test('apply no migrations', async t => { }) plan.equal(res.version, '2.30.1') + plan.equal(res.changed, false) plan.deepEqual(res.result, { foo: 'bar', })