Skip to content

Commit

Permalink
Merge branch 'main' into heat/chore/remove-onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
heatlikeheatwave authored Jul 29, 2024
2 parents 40c6ccc + 25a6174 commit 5b3d518
Show file tree
Hide file tree
Showing 4 changed files with 60 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 && 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
53 changes: 53 additions & 0 deletions scripts/upload-source-maps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { execSync } from 'child_process'

/**
* Uploads source maps to Datadog and then deletes source maps to prevent bundle size increase and leaking of source code.
*/
const main = () => {
if (
typeof process.env.VERCEL_ENV === 'undefined' ||
process.env.VERCEL_ENV === 'development'
) {
return
}

const LATEST_SHA = process.env.VERCEL_GIT_COMMIT_SHA
const PATH_PREFIX =
process.env.VERCEL_ENV === 'production'
? 'https://developer.hashicorp.com/_next/static/'
: `https://${process.env.VERCEL_BRANCH_URL}/_next/static/`
const SERVICE =
process.env.VERCEL_ENV === 'production'
? 'developer.hashicorp.com'
: 'non-prod.developer.hashicorp.com'

const DATADOG_API_KEY = process.env.DD_API_KEY

try {
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} --disable-git`,
{ stdio: 'inherit' }
)

console.log('Source maps uploaded successfully')
} catch (error) {
console.error(error)

console.log('Failed to upload sourcemaps')
}

// delete sourcemaps
try {
execSync(`rm -f .next/static/**/*.js.map`)
} catch (error) {
console.error(error)

console.log('Failed to delete sourcemaps')
}
}

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 5b3d518

Please sign in to comment.