Skip to content

Commit

Permalink
Upload source maps during prod build
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenSandwich committed Jul 24, 2024
1 parent 6ba4967 commit 6bb808f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ module.exports = withHashicorp({
],
webpack(config) {
config.plugins.push(HashiConfigPlugin())

if (process.env.VERCEL_ENV !== 'development') {
config.devtool = 'source-map'
}

return config
},
async headers() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"prestart": "hc-tools ./scripts/generate-tutorial-variant-map.ts && hc-tools ./scripts/extract-hvd-content.ts",
"prettier:check": "prettier --check .",
"prettier:write": "prettier --write .",
"postbuild": "hc-tools ./scripts/capture-build-metrics.ts dev-portal && next-sitemap",
"postbuild": "hc-tools ./scripts/capture-build-metrics.ts dev-portal && next-sitemap && hc-tools ./scripts/upload-source-maps.ts",
"rewrite-docs-content-links": "hc-tools ./scripts/docs-content-link-rewrites/rewrite-links.ts",
"sitemap": "next-sitemap",
"start:local-preview": "./scripts/content-repo-preview/start.sh",
Expand Down
45 changes: 45 additions & 0 deletions scripts/upload-source-maps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/

// import { unlinkSync } from 'fs'
import { execSync } from 'child_process'

const main = () => {
if (process.env.VERCEL_ENV === 'development') {
return
}

const LATEST_SHA = execSync('git rev-parse HEAD').toString().trim()
const PATH_PREFIX = 'https://developer.hashicorp.com/_next/static/'
const SERVICE = 'developer.hashicorp.com'

const DATADOG_API_KEY = process.env.DD_API_KEY

try {
const status = execSync(
`DATADOG_API_KEY=${DATADOG_API_KEY} npx @datadog/datadog-ci sourcemaps upload .next/static/ --service=${SERVICE} --release-version=${LATEST_SHA} --minified-path-prefix=${PATH_PREFIX}`
)

status
.toString()
.split('\n')
.forEach((line) => {
console.log(line)
})

console.log('Source maps uploaded successfully')

// Delete the source map file
// unlinkSync('.next/static/your-source-map-file.js.map')

console.log('Source map deleted successfully')
} catch (error) {
console.error(error)

console.log('Failed to upload source maps')
}
}

main()
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"jsx": "preserve",
"sourceMap": true,
"allowJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit 6bb808f

Please sign in to comment.