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(); diff --git a/tools/scripts/artifacts/nx-project.ts b/tools/scripts/artifacts/nx-project.ts index 1ae60cc7..d31d62d6 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,16 @@ export class NxProject { }@${version.toString()}` ); try { + const pathToProjectInDist = this.getPathToProjectInDist(); + 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()}`, { cwd: `${this.getPathToProjectInDist()}`, @@ -229,8 +239,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) {