Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 0123a8d

Browse files
authored
fix: cli incompatibility with yarn v1 (#2645)
* Fix a CLI incompatibility with yarn v1 Signed-off-by: David Festal <dfestal@redhat.com> * wording Signed-off-by: David Festal <dfestal@redhat.com> * Add changeset Signed-off-by: David Festal <dfestal@redhat.com> --------- Signed-off-by: David Festal <dfestal@redhat.com>
1 parent 7d55b1d commit 0123a8d

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

.changeset/plenty-masks-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@janus-idp/cli": patch
3+
---
4+
5+
Fix Yarn v1 incompatibility in the `export-dynamic-plugin` command

packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

660656
export 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+
}

packages/cli/src/commands/export-dynamic-plugin/frontend.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export async function frontend(
112112
const monoRepoPackages = await getPackages(paths.targetDir);
113113
await customizeForDynamicUse({
114114
embedded: [],
115+
isYarnV1: false,
115116
monoRepoPackages,
116117
overridding: {
117118
name: `${name}-dynamic`,

0 commit comments

Comments
 (0)