Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
feat(utils): sourceMappingURL
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Oct 9, 2021
1 parent dca9764 commit 9119cc1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/utils/__tests__/source-mapping-url.util.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Testcase } from '@tests/utils/types'
import type { SourceMapComment } from '@trext/types'
import testSubject from '../source-mapping-url.util'

/**
* @file Unit Tests - sourceMappingURL
* @module trext/utils/tests/unit/sourceMappingURL
*/

describe('unit:utils/sourceMappingURL', () => {
type Case = Testcase<SourceMapComment> & {
filename: string
ext: string | undefined
}

const cases: Case[] = [
{
expected: '//# sourceMappingURL=dog.interface.js',
ext: undefined,
filename: 'dog.interface.js'
}
]

const name = "should return source map comment given ['$filename',$ext]"

it.each<Case>(cases)(name, testcase => {
// Arrange
const { expected, ext, filename } = testcase

// Act + Expect
expect(testSubject(filename, ext)).toBe(expected)
})
})
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

export { default as ignore404 } from './ignore-404.util'
export { default as saveFile } from './save-file.util'
export { default as sourceMappingURL } from './source-mapping-url.util'
20 changes: 20 additions & 0 deletions src/utils/source-mapping-url.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { SourceMapComment } from '@trext/types'
import path from 'path'

/**
* @file Utilities - sourceMappingURL
* @module trext/utils/sourceMappingURL
*/

/**
* Returns a source map comment.
*
* @param {string} filename - Name of source file
* @param {string} [ext] - Extension to remove
* @return {SourceMapComment} Comment referencing a source map
*/
const sourceMappingURL = (filename: string, ext?: string): SourceMapComment => {
return `//# sourceMappingURL=${path.basename(filename, ext)}`
}

export default sourceMappingURL

0 comments on commit 9119cc1

Please sign in to comment.