2024-09-11 02:37:36 +00:00
"use strict" ;
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Copyright ( c ) Microsoft Corporation . All rights reserved .
* Licensed under the MIT License . See License . txt in the project root for license information .
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
2025-03-01 02:01:53 +00:00
var _ _importDefault = ( this && this . _ _importDefault ) || function ( mod ) {
return ( mod && mod . _ _esModule ) ? mod : { "default" : mod } ;
} ;
2024-09-11 02:37:36 +00:00
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
exports . getProductionDependencies = getProductionDependencies ;
2025-03-01 02:01:53 +00:00
const fs _1 = _ _importDefault ( require ( "fs" ) ) ;
const path _1 = _ _importDefault ( require ( "path" ) ) ;
const child _process _1 = _ _importDefault ( require ( "child_process" ) ) ;
const root = fs _1 . default . realpathSync ( path _1 . default . dirname ( path _1 . default . dirname ( _ _dirname ) ) ) ;
2024-09-06 13:18:02 +00:00
function getNpmProductionDependencies ( folder ) {
let raw ;
2024-09-11 02:37:36 +00:00
try {
2025-03-01 02:01:53 +00:00
raw = child _process _1 . default . execSync ( 'npm ls --all --omit=dev --parseable' , { cwd : folder , encoding : 'utf8' , env : { ... process . env , NODE _ENV : 'production' } , stdio : [ null , null , null ] } ) ;
2024-09-11 02:37:36 +00:00
}
catch ( err ) {
2024-09-06 13:18:02 +00:00
const regex = /^npm ERR! .*$/gm ;
let match ;
while ( match = regex . exec ( err . message ) ) {
if ( /ELSPROBLEMS/ . test ( match [ 0 ] ) ) {
continue ;
}
else if ( /invalid: xterm/ . test ( match [ 0 ] ) ) {
continue ;
}
else if ( /A complete log of this run/ . test ( match [ 0 ] ) ) {
continue ;
}
else {
throw err ;
}
2024-09-11 02:37:36 +00:00
}
2024-09-06 13:18:02 +00:00
raw = err . stdout ;
2024-09-11 02:37:36 +00:00
}
2024-09-06 13:18:02 +00:00
return raw . split ( /\r?\n/ ) . filter ( line => {
2025-03-01 02:01:53 +00:00
return ! ! line . trim ( ) && path _1 . default . relative ( root , line ) !== path _1 . default . relative ( root , folder ) ;
2024-09-06 13:18:02 +00:00
} ) ;
2024-09-11 02:37:36 +00:00
}
function getProductionDependencies ( folderPath ) {
2024-09-06 13:18:02 +00:00
const result = getNpmProductionDependencies ( folderPath ) ;
2024-09-11 02:37:36 +00:00
// Account for distro npm dependencies
2025-03-01 02:01:53 +00:00
const realFolderPath = fs _1 . default . realpathSync ( folderPath ) ;
const relativeFolderPath = path _1 . default . relative ( root , realFolderPath ) ;
2024-09-06 13:18:02 +00:00
const distroFolderPath = ` ${ root } /.build/distro/npm/ ${ relativeFolderPath } ` ;
2025-03-01 02:01:53 +00:00
if ( fs _1 . default . existsSync ( distroFolderPath ) ) {
2024-09-06 13:18:02 +00:00
result . push ( ... getNpmProductionDependencies ( distroFolderPath ) ) ;
2024-09-11 02:37:36 +00:00
}
return [ ... new Set ( result ) ] ;
}
if ( require . main === module ) {
console . log ( JSON . stringify ( getProductionDependencies ( root ) , null , ' ' ) ) ;
}
//# sourceMappingURL=dependencies.js.map