11import Telemetry from './utils/telemetry.utils.js'
22import { performance } from 'node:perf_hooks'
3- import path from 'node:path'
43
54import createDebug from 'debug'
65
76const debug = createDebug ( 'bp:worker' )
87
9- import {
10- getExternals ,
11- parsePackageString ,
12- throwIfAborted ,
13- } from './utils/common.utils.js'
8+ import { getExternals , throwIfAborted } from './utils/common.utils.js'
149import { getAllExports } from './utils/exports.utils.js'
15- import InstallationUtils from './utils/installation.utils.js'
1610import BuildUtils from './utils/build.utils.js'
1711import type {
1812 GetPackageStatsOptions ,
1913 InstallPackageOptions ,
2014} from './common.types.js'
21-
22- async function installPackage (
23- packageString : string ,
24- installPath : string ,
25- options : InstallPackageOptions ,
26- ) {
27- const { isLocal } = parsePackageString ( packageString )
28-
29- await InstallationUtils . installPackage ( packageString , installPath , {
30- isLocal,
31- client : options . client ,
32- limitConcurrency : options . limitConcurrency ,
33- networkConcurrency : options . networkConcurrency ,
34- installTimeout : options . installTimeout ,
35- signal : options . signal ,
36- } )
37- }
15+ import { preparePackage , type PreparedPackage } from './packageInstallation.js'
3816
3917export async function getAllPackageExports (
4018 packageString : string ,
4119 options : InstallPackageOptions = { } ,
4220) {
4321 const startTime = performance . now ( )
44- const { name : packageName , normalPath } = parsePackageString ( packageString )
45- const installPath = await InstallationUtils . preparePath (
46- packageName ,
47- options . client ,
48- options . signal ,
49- )
22+ let preparedPackage : PreparedPackage | undefined
5023
5124 try {
25+ preparedPackage = await preparePackage ( packageString , options , false )
26+ const { packageName, packagePath, installPath } = preparedPackage
5227 throwIfAborted ( options . signal )
53- await installPackage ( packageString , installPath , options )
54- throwIfAborted ( options . signal )
55- // The package is installed in node_modules subdirectory
56- const packagePath =
57- normalPath || path . join ( installPath , 'node_modules' , packageName )
5828 const results = await getAllExports (
5929 packageString ,
6030 packagePath ,
@@ -68,7 +38,7 @@ export async function getAllPackageExports(
6838 Telemetry . packageExports ( packageString , startTime , false , err )
6939 throw err
7040 } finally {
71- await InstallationUtils . cleanupPath ( installPath )
41+ await preparedPackage ?. cleanup ( )
7242 }
7343}
7444
@@ -78,34 +48,17 @@ export async function getPackageExportSizes(
7848) {
7949 const startTime = performance . now ( )
8050 const timings : Record < string , number > = { }
81-
82- const { name : packageName , normalPath } = parsePackageString ( packageString )
83-
84- const preparePathStart = performance . now ( )
85- const installPath = await InstallationUtils . preparePath (
86- packageName ,
87- options . client ,
88- options . signal ,
89- )
90- timings . preparePath = performance . now ( ) - preparePathStart
91- console . log (
92- `[PERF] [ExportSizes] preparePath: ${ timings . preparePath . toFixed ( 2 ) } ms` ,
93- )
51+ let preparedPackage : PreparedPackage | undefined
9452
9553 try {
96- throwIfAborted ( options . signal )
9754 const installStart = performance . now ( )
98- await installPackage ( packageString , installPath , options )
55+ preparedPackage = await preparePackage ( packageString , options )
56+ const { packageName, packagePath, installPath, buildPath } = preparedPackage
9957 throwIfAborted ( options . signal )
10058 timings . install = performance . now ( ) - installStart
10159 console . log (
10260 `[PERF] [ExportSizes] installPackage: ${ timings . install . toFixed ( 2 ) } ms` ,
10361 )
104-
105- // The package is installed in node_modules subdirectory
106- const packagePath =
107- normalPath || path . join ( installPath , 'node_modules' , packageName )
108-
10962 const getAllExportsStart = performance . now ( )
11063 const exportMap = await getAllExports (
11164 packageString ,
@@ -152,7 +105,8 @@ export async function getPackageExportSizes(
152105 // oxlint-disable-next-line no-await-in-loop
153106 const chunkDetails = await BuildUtils . buildPackageIgnoringMissingDeps ( {
154107 name : packageName ,
155- installPath,
108+ installPath : buildPath ,
109+ dependencyPath : installPath ,
156110 externals,
157111 options : {
158112 customImports : chunk ,
@@ -206,6 +160,6 @@ export async function getPackageExportSizes(
206160 Telemetry . packageExportsSizes ( packageString , startTime , false , options , err )
207161 throw err
208162 } finally {
209- await InstallationUtils . cleanupPath ( installPath )
163+ await preparedPackage ?. cleanup ( )
210164 }
211165}
0 commit comments