@@ -129,7 +129,11 @@ export interface IPnpmShrinkwrapYaml extends Lockfile {
129129 registry ?: string ;
130130}
131131
132- export interface ILoadFromFileOptions {
132+ export interface ILoadFromStringOptions {
133+ subspaceHasNoProjects : boolean ;
134+ }
135+
136+ export interface ILoadFromFileOptions extends ILoadFromStringOptions {
133137 withCaching ?: boolean ;
134138}
135139
@@ -323,7 +327,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
323327 private readonly _integrities : Map < string , Map < string , string > > ;
324328 private _pnpmfileConfiguration : PnpmfileConfiguration | undefined ;
325329
326- private constructor ( shrinkwrapJson : IPnpmShrinkwrapYaml , hash : string ) {
330+ private constructor ( shrinkwrapJson : IPnpmShrinkwrapYaml , hash : string , subspaceHasNoProjects : boolean ) {
327331 super ( ) ;
328332 this . hash = hash ;
329333 this . _shrinkwrapJson = shrinkwrapJson ;
@@ -351,11 +355,21 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
351355 this . overrides = new Map ( Object . entries ( shrinkwrapJson . overrides || { } ) ) ;
352356 this . packageExtensionsChecksum = shrinkwrapJson . packageExtensionsChecksum ;
353357
354- // Lockfile v9 always has "." in importers filed.
355- this . isWorkspaceCompatible =
356- this . shrinkwrapFileMajorVersion >= ShrinkwrapFileMajorVersion . V9
357- ? this . importers . size > 1
358- : this . importers . size > 0 ;
358+ let isWorkspaceCompatible : boolean ;
359+ const importerCount : number = this . importers . size ;
360+ if ( this . shrinkwrapFileMajorVersion >= ShrinkwrapFileMajorVersion . V9 ) {
361+ // Lockfile v9 always has "." in importers filed.
362+ if ( subspaceHasNoProjects ) {
363+ // If there are no projects in this subspace, the "." importer will be the only importer
364+ isWorkspaceCompatible = importerCount === 1 ;
365+ } else {
366+ isWorkspaceCompatible = importerCount > 1 ;
367+ }
368+ } else {
369+ isWorkspaceCompatible = importerCount > 0 ;
370+ }
371+
372+ this . isWorkspaceCompatible = isWorkspaceCompatible ;
359373
360374 this . _integrities = new Map ( ) ;
361375 }
@@ -387,11 +401,11 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
387401
388402 public static loadFromFile (
389403 shrinkwrapYamlFilePath : string ,
390- options : ILoadFromFileOptions = { }
404+ options : ILoadFromFileOptions
391405 ) : PnpmShrinkwrapFile | undefined {
392406 try {
393407 const shrinkwrapContent : string = FileSystem . readFile ( shrinkwrapYamlFilePath ) ;
394- return PnpmShrinkwrapFile . loadFromString ( shrinkwrapContent ) ;
408+ return PnpmShrinkwrapFile . loadFromString ( shrinkwrapContent , options ) ;
395409 } catch ( error ) {
396410 if ( FileSystem . isNotExistError ( error as Error ) ) {
397411 return undefined ; // file does not exist
@@ -400,13 +414,17 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
400414 }
401415 }
402416
403- public static loadFromString ( shrinkwrapContent : string ) : PnpmShrinkwrapFile {
417+ public static loadFromString (
418+ shrinkwrapContent : string ,
419+ options : ILoadFromStringOptions
420+ ) : PnpmShrinkwrapFile {
404421 const hash : string = crypto . createHash ( 'sha-256' ) . update ( shrinkwrapContent , 'utf8' ) . digest ( 'hex' ) ;
405422 const cached : PnpmShrinkwrapFile | undefined = cacheByLockfileHash . get ( hash ) ;
406423 if ( cached ) {
407424 return cached ;
408425 }
409426
427+ const { subspaceHasNoProjects } = options ;
410428 const shrinkwrapJson : IPnpmShrinkwrapYaml = yamlModule . load ( shrinkwrapContent ) as IPnpmShrinkwrapYaml ;
411429 if ( ( shrinkwrapJson as LockfileFileV9 ) . snapshots ) {
412430 const lockfile : IPnpmShrinkwrapYaml | null = convertLockfileV9ToLockfileObject (
@@ -436,10 +454,11 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
436454 lockfile . dependencies [ name ] = PnpmShrinkwrapFile . getLockfileV9PackageId ( name , versionSpecifier ) ;
437455 }
438456 }
439- return new PnpmShrinkwrapFile ( lockfile , hash ) ;
457+
458+ return new PnpmShrinkwrapFile ( lockfile , hash , subspaceHasNoProjects ) ;
440459 }
441460
442- return new PnpmShrinkwrapFile ( shrinkwrapJson , hash ) ;
461+ return new PnpmShrinkwrapFile ( shrinkwrapJson , hash , subspaceHasNoProjects ) ;
443462 }
444463
445464 public getShrinkwrapHash ( experimentsConfig ?: IExperimentsJson ) : string {
0 commit comments