Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

fix(prepare): allow prepare to go ahead when artifacts are not yet published #706

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default interface FetchAnArtifact
{
fetchArtifact(packageName: string,artifactDirectory: string,version?:string):void
fetchArtifact(packageName: string,artifactDirectory: string,version?:string,isToContinueOnMissingArtifact?:boolean):void
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import * as fs from "fs-extra";
import child_process = require("child_process");
import path = require("path");
import FetchAnArtifact from "./FetchAnArtifact";
import SFPLogger, { COLOR_WARNING } from "@dxatscale/sfpowerscripts.core/lib/logger/SFPLogger";

export class FetchAnArtifactFromNPM implements FetchAnArtifact {

constructor(
private scope: string,
private npmrcPath: string
) {
constructor(private scope: string, private npmrcPath: string) {
if (this.npmrcPath) {
try
{
try {
fs.copyFileSync(this.npmrcPath, path.resolve(".npmrc"));
} catch(error)
{
throw new Error("We were unable to find or copy the .npmrc file as provided due to "+error.message);
} catch (error) {
throw new Error(
"We were unable to find or copy the .npmrc file as provided due to " +
error.message
);
}

if (!fs.existsSync("package.json")) {
Expand All @@ -29,29 +27,34 @@ export class FetchAnArtifactFromNPM implements FetchAnArtifact {
}
}


public fetchArtifact(
packageName: string,
artifactDirectory: string,
version?:string
version?: string,
isToContinueOnMissingArtifact?: boolean
) {
// NPM package names must be lowercase
packageName = packageName.toLowerCase();

let cmd: string;
if (this.scope)
cmd = `npm pack @${this.scope}/${packageName}_sfpowerscripts_artifact`;
else cmd = `npm pack ${packageName}_sfpowerscripts_artifact`;

if(version)
cmd += `@${version}`


console.log(`Fetching ${packageName} using ${cmd}`);

child_process.execSync(cmd, {
cwd: artifactDirectory,
stdio: "pipe",
});
try {
// NPM package names must be lowercase
packageName = packageName.toLowerCase();

let cmd: string;
if (this.scope)
cmd = `npm pack @${this.scope}/${packageName}_sfpowerscripts_artifact`;
else cmd = `npm pack ${packageName}_sfpowerscripts_artifact`;

if (version) cmd += `@${version}`;

console.log(`Fetching ${packageName} using ${cmd}`);

child_process.execSync(cmd, {
cwd: artifactDirectory,
stdio: "pipe",
});
} catch (error) {
if(!isToContinueOnMissingArtifact)
throw error;
else
SFPLogger.log( COLOR_WARNING(`Artifact for ${packageName} missing in NPM Registry provided, This might result in deployment failures`))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import SFPLogger, { COLOR_WARNING } from "@dxatscale/sfpowerscripts.core/lib/logger/SFPLogger";
import child_process = require("child_process");
import FetchAnArtifact from "./FetchAnArtifact";

Expand All @@ -7,29 +8,37 @@ export class FetchAnArtifactUsingScript implements FetchAnArtifact {
public fetchArtifact(
packageName: string,
artifactDirectory: string,
version: string
version: string,
isToContinueOnMissingArtifact?: boolean
) {
let cmd: string;
try {
let cmd: string;

if (version) {
if (process.platform !== "win32") {
cmd = `bash -e "${this.scriptPath}" "${packageName}" "${version}" "${artifactDirectory}"`;
if (version) {
if (process.platform !== "win32") {
cmd = `bash -e "${this.scriptPath}" "${packageName}" "${version}" "${artifactDirectory}"`;
} else {
cmd = `cmd.exe /c "${this.scriptPath}" "${packageName}" "${version}" "${artifactDirectory}"`;
}
} else {
cmd = `cmd.exe /c "${this.scriptPath}" "${packageName}" "${version}" "${artifactDirectory}"`;
if (process.platform !== "win32") {
cmd = `bash -e ${this.scriptPath} ${packageName} ${artifactDirectory}`;
} else {
cmd = `cmd.exe /c ${this.scriptPath} ${packageName} ${artifactDirectory}`;
}
}
} else {
if (process.platform !== "win32") {
cmd = `bash -e ${this.scriptPath} ${packageName} ${artifactDirectory}`;
} else {
cmd = `cmd.exe /c ${this.scriptPath} ${packageName} ${artifactDirectory}`;
}
}

console.log(`Fetching ${packageName} using ${cmd}`);
console.log(`Fetching ${packageName} using ${cmd}`);

child_process.execSync(cmd, {
cwd: process.cwd(),
stdio: "pipe",
});
child_process.execSync(cmd, {
cwd: process.cwd(),
stdio: "pipe",
});
} catch (error) {
if(!isToContinueOnMissingArtifact)
throw error;
else
SFPLogger.log( COLOR_WARNING(`Artifact for ${packageName} missing in NPM Registry provided, This might result in deployment failures`))
}
}
}
5 changes: 4 additions & 1 deletion packages/sfpowerscripts-cli/src/impl/prepare/PrepareImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ export default class PrepareImpl {
).getArtifactFetcher();


//During Prepare, there could be a race condition where a main is merged with a new package
//but the package is not yet available in the validated package list and can cause prepare to fail
packages.forEach((pkg) => {
artifactFetcher.fetchArtifact(
pkg.package,
"artifacts",
this.pool.fetchArtifacts.npm ? this.pool.fetchArtifacts.npm.npmtag : null
this.pool.fetchArtifacts.npm ? this.pool.fetchArtifacts.npm.npmtag : null,
true
);
});

Expand Down