@@ -30,6 +30,7 @@ import {
3030 normalizeId
3131} from '../scripts/utils/packages.js'
3232import { envAsBoolean } from '@socketsecurity/registry/lib/env'
33+ import assert from 'node:assert'
3334
3435const {
3536 BABEL_RUNTIME ,
@@ -48,6 +49,9 @@ const CONSTANTS_JS = `${CONSTANTS}.js`
4849const CONSTANTS_STUB_CODE = createStubCode ( `../${ CONSTANTS_JS } ` )
4950const VENDOR_JS = `${ VENDOR } .js`
5051
52+ const IS_SENTRY_BUILD = envAsBoolean ( process . env [ 'SOCKET_WITH_SENTRY' ] ) ;
53+ const IS_PUBLISH = envAsBoolean ( process . env [ 'SOCKET_IS_PUBLISHED' ] )
54+
5155const distConstantsPath = path . join ( rootDistPath , CONSTANTS_JS )
5256const distModuleSyncPath = path . join ( rootDistPath , MODULE_SYNC )
5357const distRequirePath = path . join ( rootDistPath , REQUIRE )
@@ -112,13 +116,29 @@ function updateDepStatsSync(depStats) {
112116 delete depStats . dependencies [ key ]
113117 }
114118 }
119+
120+ console . log ( 'ass:' , assert )
121+ assert ( Object . keys ( editablePkgJson ?. content ?. bin ) . join ( ',' ) === 'socket,socket-npm,socket-npx' , 'If this fails, make sure to update the rollup sentry override for .bin to match the regular build!' ) ;
122+ if ( IS_SENTRY_BUILD ) {
123+ editablePkgJson . content [ 'name' ] = '@socketsecurity/socket-with-sentry'
124+ editablePkgJson . content [ 'description' ] = "CLI tool for Socket.dev, includes Sentry error handling, otherwise identical to the regular `socket` package"
125+ editablePkgJson . content [ 'bin' ] = {
126+ "socket-with-sentry" : "bin/cli.js" ,
127+ "socket-npm-with-sentry" : "bin/npm-cli.js" ,
128+ "socket-npx-with-sentry" : "bin/npx-cli.js"
129+ }
130+ // Add Sentry as a regular dep for this build
131+ depStats . dependencies [ '@sentry/node' ] = '9.1.0' ;
132+ }
133+
115134 depStats . dependencies = toSortedObject ( depStats . dependencies )
116135 depStats . devDependencies = toSortedObject ( depStats . devDependencies )
117136 depStats . esm = toSortedObject ( depStats . esm )
118137 depStats . external = toSortedObject ( depStats . external )
119138 depStats . transitives = toSortedObject ( depStats . transitives )
120139 // Write dep stats.
121140 writeFileSync ( depStatsPath , `${ formatObject ( depStats ) } \n` , 'utf8' )
141+
122142 // Update dependencies with additional inlined modules.
123143 editablePkgJson
124144 . update ( {
@@ -128,6 +148,14 @@ function updateDepStatsSync(depStats) {
128148 }
129149 } )
130150 . saveSync ( )
151+
152+ if ( IS_SENTRY_BUILD ) {
153+ // Replace the name in the package lock too, just in case.
154+ const lock = readFileSync ( 'package-lock.json' , 'utf8' ) ;
155+ // Note: this should just replace the first occurrence, even if there are more
156+ const lock2 = lock . replace ( '"name": "socket",' , '"name": "@socketsecurity/socket-with-sentry",' )
157+ writeFileSync ( 'package-lock.json' , lock2 )
158+ }
131159}
132160
133161function versionBanner ( _chunk ) {
@@ -151,8 +179,8 @@ function versionBanner(_chunk) {
151179 var SOCKET_CLI_PKG_JSON_VERSION = "${ pkgJsonVersion } "
152180 var SOCKET_CLI_GIT_HASH = "${ gitHash } "
153181 var SOCKET_CLI_BUILD_RNG = "${ rng } "
154- var SOCKET_CLI_VERSION = " ${ pkgJsonVersion } : ${ gitHash } : ${ rng } "
155- var SOCKET_PUB = ${ envAsBoolean ( process . env [ 'SOCKET_IS_PUBLISHED' ] ) }
182+ var SOCKET_PUB = ${ IS_PUBLISH }
183+ var SOCKET_CLI_VERSION = " ${ pkgJsonVersion } : ${ gitHash } : ${ rng } ${ IS_PUBLISH ? ':pub' : '' } "
156184 ` . trim ( ) . split ( '\n' ) . map ( s => s . trim ( ) ) . join ( '\n' )
157185}
158186
@@ -241,7 +269,7 @@ export default () => {
241269 socketModifyPlugin ( {
242270 find : processEnvSocketIsPublishedRegExp ,
243271 // Note: these are going to be bools in JS, not strings
244- replace : ( ) => ( envAsBoolean ( process . env [ 'SOCKET_IS_PUBLISHED' ] ) ? 'true' : 'false' )
272+ replace : ( ) => ( IS_PUBLISH ? 'true' : 'false' )
245273 } ) ,
246274 // Replace `process.env.SOCKET_CLI_VERSION` with var ref that rollup
247275 // adds to the top of each file.
0 commit comments