1- import { chmodSync , readFileSync , writeFileSync } from 'node:fs'
1+ import { chmodSync , writeFileSync } from 'node:fs'
22import path from 'node:path'
33import { fileURLToPath } from 'node:url'
44
5- import { hasKeys , toSortedObject } from '@socketsecurity/registry/lib/objects'
5+ import { toSortedObject } from '@socketsecurity/registry/lib/objects'
6+ import { readPackageJsonSync } from '@socketsecurity/registry/lib/packages'
67
78import baseConfig from './rollup.base.config.mjs'
89import { readJsonSync } from '../scripts/utils/fs.js'
910import { formatObject } from '../scripts/utils/objects.js'
10- import { readPackageJsonSync } from '../scripts/utils/packages.js'
1111
1212const __dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) )
1313
@@ -16,8 +16,7 @@ const depStatsPath = path.join(rootPath, '.dep-stats.json')
1616const distPath = path . join ( rootPath , 'dist' )
1717const srcPath = path . join ( rootPath , 'src' )
1818
19- const pkgJsonPath = path . resolve ( rootPath , 'package.json' )
20- const pkgJson = readPackageJsonSync ( pkgJsonPath )
19+ const editablePkgJson = readPackageJsonSync ( rootPath , { editable : true } )
2120
2221export default ( ) => {
2322 const config = baseConfig ( {
@@ -40,6 +39,7 @@ export default () => {
4039 plugins : [
4140 {
4241 writeBundle ( ) {
42+ const { content : pkgJson } = editablePkgJson
4343 const { '@cyclonedx/cdxgen' : cdxgenRange , synp : synpRange } =
4444 pkgJson . dependencies
4545 const { depStats } = config . meta
@@ -71,28 +71,19 @@ export default () => {
7171
7272 // Write dep stats
7373 writeFileSync ( depStatsPath , `${ formatObject ( depStats ) } \n` , 'utf8' )
74-
7574 // Make dist files chmod +x
7675 chmodSync ( path . join ( distPath , 'cli.js' ) , 0o755 )
7776 chmodSync ( path . join ( distPath , 'npm-cli.js' ) , 0o755 )
7877 chmodSync ( path . join ( distPath , 'npx-cli.js' ) , 0o755 )
79-
8078 // Update dependencies with additional inlined modules
81- writeFileSync (
82- pkgJsonPath ,
83- readFileSync ( pkgJsonPath , 'utf8' ) . replace (
84- / (?< = " d e p e n d e n c i e s " : \s * ) \{ [ ^ \} ] * \} / ,
85- ( ) => {
86- const deps = {
87- ...depStats . dependencies ,
88- ...depStats . transitives
89- }
90- const formatted = formatObject ( deps , 4 )
91- return hasKeys ( deps ) ? formatted . replace ( '}' , ' }' ) : formatted
79+ editablePkgJson
80+ . update ( {
81+ dependencies : {
82+ ...depStats . dependencies ,
83+ ...depStats . transitives
9284 }
93- ) ,
94- 'utf8'
95- )
85+ } )
86+ . saveSync ( )
9687 }
9788 }
9889 ]
0 commit comments