1- import meow from 'meow'
1+ import path from 'node:path'
2+
3+ import spawn from '@npmcli/promise-spawn'
24import { getManifestData } from '@socketsecurity/registry'
5+ import meow from 'meow'
36
47import { printFlagList } from '../utils/formatting'
58import { writeFileUtf8 } from '../utils/fs'
@@ -17,6 +20,8 @@ import type {
1720 StringKeyValueObject
1821} from '../utils/package-manager-detector'
1922
23+ const distPath = __dirname
24+
2025const OVERRIDES_FIELD_NAME = 'overrides'
2126
2227const RESOLUTIONS_FIELD_NAME = 'resolutions'
@@ -54,17 +59,22 @@ type CreateManifest = (
5459
5560const createManifestByAgent : Record < Agent , CreateManifest > = {
5661 npm : ( ref : PackageJSONObject , overrides : Overrides ) =>
57- < PackageJSONObject > { ...ref , overrides } ,
62+ ( < unknown > { __proto__ : null , ...ref , overrides } ) as PackageJSONObject ,
5863 pnpm : ( ref : PackageJSONObject , overrides : Overrides ) =>
59- < PackageJSONObject > {
64+ ( < unknown > {
65+ __proto__ : null ,
6066 ...ref ,
6167 pnpm : < PackageJSONObject > {
6268 ...( < StringKeyValueObject > ( ref [ 'pnpm' ] ?? { } ) ) ,
6369 overrides
6470 }
65- } ,
71+ } ) as PackageJSONObject ,
6672 yarn : ( ref : PackageJSONObject , overrides : Overrides ) =>
67- < PackageJSONObject > { ...ref , resolutions : overrides }
73+ ( < unknown > {
74+ __proto__ : null ,
75+ ...ref ,
76+ resolutions : overrides
77+ } ) as PackageJSONObject
6878} as const
6979
7080type LockIncludes = ( lockSrc : string , name : string ) => boolean
@@ -253,7 +263,10 @@ async function addOverrides(
253263 for ( const name of allPackages ) {
254264 if ( ! hasOwn ( overrides , name ) && lockIncludes ( lockSrc , name ) ) {
255265 if ( clonedOverrides === undefined ) {
256- clonedOverrides = { ...overrides }
266+ clonedOverrides = ( < unknown > {
267+ __proto__ : null ,
268+ ...overrides
269+ } ) as Overrides
257270 }
258271 addedCount += 1
259272 packageNames . add ( name )
@@ -289,8 +302,6 @@ export const optimize: CliSubcommand = {
289302 importMeta
290303 )
291304 if ( commandContext ) {
292- //const spinnerText = 'Searching dependencies...'
293- //const spinner = ora(spinnerText).start()
294305 const { agent, lockSrc, pkgJson, pkgPath, pkgJsonStr, supported } =
295306 await detect ( {
296307 cwd : process . cwd ( ) ,
@@ -342,6 +353,7 @@ export const optimize: CliSubcommand = {
342353 for ( const config of configs ) {
343354 await addOverrides (
344355 < AddOverridesConfig > {
356+ __proto__ : null ,
345357 lockSrc,
346358 pkgPath,
347359 pkgJson,
@@ -351,6 +363,17 @@ export const optimize: CliSubcommand = {
351363 aoState
352364 )
353365 }
366+ if ( agent === 'npm' ) {
367+ const wrapperPath = path . join ( distPath , 'npm-cli.js' )
368+ await spawn ( process . execPath , [ wrapperPath , ...argv ] , {
369+ stdio : 'inherit' ,
370+ env : ( < unknown > {
371+ __proto__ : null ,
372+ ...process . env ,
373+ UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE : '1'
374+ } ) as NodeJS . ProcessEnv
375+ } )
376+ }
354377 }
355378 const { size : count } = aoState . packageNames
356379 if ( count ) {
0 commit comments