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 {
16+ acquirePackageInstallation ,
17+ type PackageInstallationLease ,
18+ } from './packageInstallation.js'
3819
3920export async function getAllPackageExports (
4021 packageString : string ,
4122 options : InstallPackageOptions = { } ,
4223) {
4324 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- )
25+ let installation : PackageInstallationLease | undefined
5026
5127 try {
28+ installation = await acquirePackageInstallation ( packageString , options )
29+ const { packageName, packagePath, installPath } = installation
5230 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 )
5831 const results = await getAllExports (
5932 packageString ,
6033 packagePath ,
@@ -68,7 +41,7 @@ export async function getAllPackageExports(
6841 Telemetry . packageExports ( packageString , startTime , false , err )
6942 throw err
7043 } finally {
71- await InstallationUtils . cleanupPath ( installPath )
44+ await installation ?. release ( )
7245 }
7346}
7447
@@ -78,34 +51,17 @@ export async function getPackageExportSizes(
7851) {
7952 const startTime = performance . now ( )
8053 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- )
54+ let installation : PackageInstallationLease | undefined
9455
9556 try {
96- throwIfAborted ( options . signal )
9757 const installStart = performance . now ( )
98- await installPackage ( packageString , installPath , options )
58+ installation = await acquirePackageInstallation ( packageString , options )
59+ const { packageName, packagePath, installPath } = installation
9960 throwIfAborted ( options . signal )
10061 timings . install = performance . now ( ) - installStart
10162 console . log (
10263 `[PERF] [ExportSizes] installPackage: ${ timings . install . toFixed ( 2 ) } ms` ,
10364 )
104-
105- // The package is installed in node_modules subdirectory
106- const packagePath =
107- normalPath || path . join ( installPath , 'node_modules' , packageName )
108-
10965 const getAllExportsStart = performance . now ( )
11066 const exportMap = await getAllExports (
11167 packageString ,
@@ -206,6 +162,6 @@ export async function getPackageExportSizes(
206162 Telemetry . packageExportsSizes ( packageString , startTime , false , options , err )
207163 throw err
208164 } finally {
209- await InstallationUtils . cleanupPath ( installPath )
165+ await installation ?. release ( )
210166 }
211167}
0 commit comments