-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload source maps during prod build (#2523)
* Upload source maps during prod build * Remove commented out code * conditional logic for service string Co-authored-by: Zach Shilton <[email protected]> * Make path prefex generic * Add additional logic checks to prevent upload script from running in dev or when VERCEL_ENV is undefined --------- Co-authored-by: Heat Hamilton <[email protected]> Co-authored-by: Zach Shilton <[email protected]>
- Loading branch information
1 parent
2e1a961
commit f50afe7
Showing
5 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters