@@ -42,6 +42,7 @@ export async function backend(opts: OptionValues): Promise<string> {
4242 const targetRelativePath = 'dist-dynamic' ;
4343 const target = path . join ( paths . targetDir , targetRelativePath ) ;
4444 const yarn = 'yarn' ;
45+ const yarnVersion = execSync ( `${ yarn } --version` ) . toString ( ) . trim ( ) ;
4546
4647 const pkgContent = await fs . readFile (
4748 paths . resolveTarget ( 'package.json' ) ,
@@ -151,12 +152,6 @@ throw new Error(
151152 [ key : string ] : string ;
152153 } = { } ;
153154
154- function embeddedPackageRelativePath ( p : ResolvedEmbedded ) : string {
155- return path . join (
156- 'embedded' ,
157- p . packageName . replace ( / ^ @ / , '' ) . replace ( / \/ / , '-' ) ,
158- ) ;
159- }
160155 for ( const embedded of embeddedResolvedPackages ) {
161156 const embeddedDestRelativeDir = embeddedPackageRelativePath ( embedded ) ;
162157 const embeddedDestDir = path . join ( target , embeddedDestRelativeDir ) ;
@@ -211,6 +206,7 @@ throw new Error(
211206 ) ;
212207 await customizeForDynamicUse ( {
213208 embedded : embeddedResolvedPackages ,
209+ isYarnV1 : yarnVersion . startsWith ( '1.' ) ,
214210 monoRepoPackages,
215211 sharedPackages : sharedPackagesRules ,
216212 overridding : {
@@ -277,6 +273,7 @@ throw new Error(
277273 ) ;
278274 await customizeForDynamicUse ( {
279275 embedded : embeddedResolvedPackages ,
276+ isYarnV1 : yarnVersion . startsWith ( '1.' ) ,
280277 monoRepoPackages,
281278 sharedPackages : sharedPackagesRules ,
282279 overridding : {
@@ -359,10 +356,9 @@ throw new Error(
359356 if ( opts . install ) {
360357 Task . log ( `Installing private dependencies of the main package` ) ;
361358
362- const version = execSync ( `${ yarn } --version` ) . toString ( ) . trim ( ) ;
363359 const logFile = 'yarn-install.log' ;
364360 const redirect = `> ${ logFile } ` ;
365- const yarnInstall = version . startsWith ( '1.' )
361+ const yarnInstall = yarnVersion . startsWith ( '1.' )
366362 ? `${ yarn } install --production${
367363 yarnLockExists ? ' --frozen-lockfile' : ''
368364 } ${ redirect } `
@@ -659,6 +655,7 @@ function checkWorkspacePackageVersion(
659655
660656export function customizeForDynamicUse ( options : {
661657 embedded : ResolvedEmbedded [ ] ;
658+ isYarnV1 : boolean ;
662659 monoRepoPackages : Packages | undefined ;
663660 sharedPackages ?: SharedPackagesRules | undefined ;
664661 overridding ?:
@@ -757,6 +754,23 @@ export function customizeForDynamicUse(options: {
757754 pkgToCustomize . peerDependencies [ dep ] =
758755 pkgToCustomize . dependencies [ dep ] ;
759756 delete pkgToCustomize . dependencies [ dep ] ;
757+
758+ continue ;
759+ }
760+
761+ // If yarn v1, then detect if the current dep is an embedded one,
762+ // and if it is the case replace the version by the file protocol
763+ // (like what we do for the resolutions).
764+ if ( options . isYarnV1 ) {
765+ const embeddedDep = options . embedded . find (
766+ e =>
767+ e . packageName === dep &&
768+ checkWorkspacePackageVersion ( dependencyVersionSpec , e ) ,
769+ ) ;
770+ if ( embeddedDep ) {
771+ pkgToCustomize . dependencies [ dep ] =
772+ `file:./${ embeddedPackageRelativePath ( embeddedDep ) } ` ;
773+ }
760774 }
761775 }
762776 }
@@ -921,3 +935,10 @@ function validatePluginEntryPoints(target: string): string {
921935
922936 return '' ;
923937}
938+
939+ function embeddedPackageRelativePath ( p : ResolvedEmbedded ) : string {
940+ return path . join (
941+ 'embedded' ,
942+ p . packageName . replace ( / ^ @ / , '' ) . replace ( / \/ / , '-' ) ,
943+ ) ;
944+ }
0 commit comments