From 722dfdf3f865adea945d6324e212486de60187d1 Mon Sep 17 00:00:00 2001 From: Senthanal Sirpi Manohar Date: Wed, 11 Jun 2025 22:03:55 +0200 Subject: [PATCH 1/4] PFM-ISSUE-28887 Enhance deleteArtifact method to support JFrog credentials and improve .npmrc handling (cherry picked from commit 25b93b6464b8aaa507b0c1584e23e07ab0656edb) --- tools/scripts/artifacts/nx-project.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/scripts/artifacts/nx-project.ts b/tools/scripts/artifacts/nx-project.ts index 1ae60cc7..6fd275a4 100644 --- a/tools/scripts/artifacts/nx-project.ts +++ b/tools/scripts/artifacts/nx-project.ts @@ -183,7 +183,7 @@ export class NxProject { return npmPackage.versions.includes(version); } - public async deleteArtifact(version: Version) { + public async deleteArtifact(version: Version, jfrogCredentials: JfrogCredentials = null) { console.log("Checking if package exists in registry"); const scopedPackage = `${this.scope}/${this.name}`; if(!this.packageExists(scopedPackage, version.toString())) { @@ -197,6 +197,11 @@ export class NxProject { }@${version.toString()}` ); try { + const pathToProjectInDist = this.getPathToProjectInDist(); + if (!fs.existsSync(pathToProjectInDist) && jfrogCredentials) { + this.writeNPMRCInDist(jfrogCredentials, this.scope); + this.setVersionOrGeneratePackageJsonInDist(version, jfrogCredentials.url); + } console.log( execSync(`npm unpublish ${this.scope}/${this.name}@${version.toString()}`, { cwd: `${this.getPathToProjectInDist()}`, @@ -229,8 +234,12 @@ export class NxProject { this.npmrcContent + `${jfrogCredentials.getJfrogUrlNoHttp()}:email=${jfrogCredentials.user}`; console.log(this.npmrcContent + '\n\n'); - fs.writeFileSync(this.getNpmrcPathInDist(), this.npmrcContent); - console.log('wrote .npmrc to: ' + this.getNpmrcPathInDist()); + const npmrcPathInDist = this.getNpmrcPathInDist(); + if(!fs.existsSync(npmrcPathInDist)){ + fs.mkdirSync(path.dirname(npmrcPathInDist), { recursive: true }); + } + fs.writeFileSync(npmrcPathInDist, this.npmrcContent); + console.log('wrote .npmrc to: ' + npmrcPathInDist); } public setVersionOrGeneratePackageJsonInDist(version: Version, registry: string) { From 342cdc57e36ac9afdd68dfc2ce0372114dd10345 Mon Sep 17 00:00:00 2001 From: Senthanal Sirpi Manohar Date: Wed, 11 Jun 2025 22:09:36 +0200 Subject: [PATCH 2/4] PFM-ISSUE-28887 Enhance deleteArtifact method to support JFrog credentials and improve .npmrc handling (cherry picked from commit 43d65012d79603759f461231fd90d612123da11b) --- tools/scripts/artifacts/nx-project.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/scripts/artifacts/nx-project.ts b/tools/scripts/artifacts/nx-project.ts index 6fd275a4..62db329a 100644 --- a/tools/scripts/artifacts/nx-project.ts +++ b/tools/scripts/artifacts/nx-project.ts @@ -197,10 +197,17 @@ export class NxProject { }@${version.toString()}` ); try { + console.log(`Using Jfrog credentials: ${jfrogCredentials ? 'yes' : 'no'}`); const pathToProjectInDist = this.getPathToProjectInDist(); + console.log(`Path to project in dist: ${pathToProjectInDist}`); if (!fs.existsSync(pathToProjectInDist) && jfrogCredentials) { + console.log( + `Path to project in dist does not exist, creating it: ${pathToProjectInDist}` + ); this.writeNPMRCInDist(jfrogCredentials, this.scope); + console.log(`Setting version in package.json for ${this.name} to ${version.toString()}`); this.setVersionOrGeneratePackageJsonInDist(version, jfrogCredentials.url); + console.log(`Generated package.json: ${this.getPrettyPackageJson()}`); } console.log( execSync(`npm unpublish ${this.scope}/${this.name}@${version.toString()}`, { From cc3519e86c5b5f02de8bcb567014c43edc992985 Mon Sep 17 00:00:00 2001 From: Senthanal Sirpi Manohar Date: Wed, 11 Jun 2025 22:14:45 +0200 Subject: [PATCH 3/4] PFM-ISSUE-28887 Enhance deleteArtifact method to accept JFrog credentials (cherry picked from commit 7f942a90405aa96778dfc2b70ae06fa020dddb2b) --- tools/scripts/artifacts/artifacts-handler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/scripts/artifacts/artifacts-handler.ts b/tools/scripts/artifacts/artifacts-handler.ts index 61cb95f5..83b3cccc 100644 --- a/tools/scripts/artifacts/artifacts-handler.ts +++ b/tools/scripts/artifacts/artifacts-handler.ts @@ -115,7 +115,7 @@ export class ArtifactsHandler { if (project.isPublishable) { if (this.onlyDeleteArtifacts) await project.deleteArtifact( - this.currentVersion + this.currentVersion, this.jfrogCredentials ); else { project.build(); From 92c9c645d1114e1a24a3f6141805c54544750bf2 Mon Sep 17 00:00:00 2001 From: Senthanal Sirpi Manohar Date: Thu, 12 Jun 2025 12:22:08 +0200 Subject: [PATCH 4/4] PFM-ISSUE-28887 Remove debug log for JFrog credentials and add code quality configuration --- tools/scripts/artifacts/nx-project.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/scripts/artifacts/nx-project.ts b/tools/scripts/artifacts/nx-project.ts index 62db329a..d31d62d6 100644 --- a/tools/scripts/artifacts/nx-project.ts +++ b/tools/scripts/artifacts/nx-project.ts @@ -197,9 +197,7 @@ export class NxProject { }@${version.toString()}` ); try { - console.log(`Using Jfrog credentials: ${jfrogCredentials ? 'yes' : 'no'}`); const pathToProjectInDist = this.getPathToProjectInDist(); - console.log(`Path to project in dist: ${pathToProjectInDist}`); if (!fs.existsSync(pathToProjectInDist) && jfrogCredentials) { console.log( `Path to project in dist does not exist, creating it: ${pathToProjectInDist}`