Skip to content

Commit

Permalink
Enable JavaScript source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Nov 23, 2022
1 parent f4046ab commit 3032ffd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion tasks/gulp/__tests__/after-build-dist.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ describe('dist/', () => {
})

describe('govuk-frontend-[version].min.js', () => {
let filename
let javascript

beforeAll(async () => {
javascript = await readFile(join(configPaths.dist, `govuk-frontend-${pkg.version}.min.js`), 'utf8')
filename = `govuk-frontend-${pkg.version}.min.js`
javascript = await readFile(join(configPaths.dist, filename), 'utf8')
})

it('should have the correct version name', () => {
expect(javascript).toBeTruthy()
})

it('should contain source mapping URL', () => {
expect(javascript).toMatch(new RegExp(`//# sourceMappingURL=${filename}.map$`))
})
})
})
5 changes: 4 additions & 1 deletion tasks/gulp/__tests__/after-build-package.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ describe('package/', () => {
const importFilter = /^govuk(?!-)/

// All source `**/*.mjs` files compiled to `**/*.js`
const output = [join(requirePath, `${name}.js`)]
const output = [
join(requirePath, `${name}.js`),
join(requirePath, `${name}.js.map`) // with source map
]

// Only source `./govuk/**/*.mjs` files copied to `./govuk-esm/**/*.mjs`
if (importFilter.test(requirePath)) {
Expand Down
8 changes: 6 additions & 2 deletions tasks/gulp/compile-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ export async function compileJavaScripts () {
? componentNameToJavaScriptModuleName(name)
: 'GOVUKFrontend'

return compileJavaScript(gulp.src(slash(join(configPaths.src, file))), moduleName)
.pipe(gulp.dest(slash(join(destPath, modulePath))))
return compileJavaScript(gulp.src(slash(join(configPaths.src, file)), {
sourcemaps: true
}), moduleName)
.pipe(gulp.dest(slash(join(destPath, modulePath)), {
sourcemaps: '.'
}))
}))
}

Expand Down

0 comments on commit 3032ffd

Please sign in to comment.