Skip to content

Commit

Permalink
fix(MigrationSource): skip sourcemap files
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Dec 6, 2019
1 parent f66aa54 commit f8c0feb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Migrator/MigrationSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { join, isAbsolute, extname } from 'path'
import { MigrationNode } from '@ioc:Adonis/Lucid/Migrator'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
import { ConnectionConfigContract } from '@ioc:Adonis/Lucid/Database'
import { isNotSourceMapFile } from '../utils'

/**
* Migration source exposes the API to read the migration files
Expand All @@ -41,7 +42,9 @@ export class MigrationSource {
return
}

return resolve(files.sort().map((file) => {
return resolve(files.sort().filter((file) => {
return isNotSourceMapFile(file)
}).map((file) => {
return {
absPath: join(path, file),
name: join(directoryPath, file.replace(RegExp(`${extname(file)}$`), '')),
Expand Down
5 changes: 5 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/// <reference path="../../adonis-typings/index.ts" />

import { extname } from 'path'
import { Exception } from '@poppinss/utils'
import { RelationContract, ModelContract } from '@ioc:Adonis/Lucid/Model'

Expand Down Expand Up @@ -67,3 +68,7 @@ export function difference (main: any[], other: []) {
})
})
}

export function isNotSourceMapFile (file: string) {
return !['.map'].includes(extname(file))
}
19 changes: 19 additions & 0 deletions test/migrations/migration-source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ test.group('MigrationSource', (group) => {
])
})

test('only use javascript files for migration', async (assert) => {
const app = new Application(fs.basePath, {} as any, {} as any, {})
const migrationSource = new MigrationSource(db.getRawConnection('primary')!.config, app)

await fs.add('database/migrations/foo.js', 'module.exports = class Foo {}')
await fs.add('database/migrations/foo.js.map', '{}')

const directories = await migrationSource.getMigrations()

assert.deepEqual(directories.map((file) => {
return { absPath: file.absPath, name: file.name }
}), [
{
absPath: join(fs.basePath, 'database/migrations/foo.js'),
name: 'database/migrations/foo',
},
])
})

test('sort multiple migration directories seperately', async (assert) => {
const app = new Application(fs.basePath, {} as any, {} as any, {})
const config = Object.assign({}, db.getRawConnection('primary')!.config, {
Expand Down

0 comments on commit f8c0feb

Please sign in to comment.