Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add factory #7

Open
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

dmitry-shibanov
Copy link

Description:
Describe your changes.

Related issue:
Add link to the related issue.

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

src/main.ts Outdated Show resolved Hide resolved
src/distibutions/base-distribution.ts Outdated Show resolved Hide resolved
src/distibutions/base-distribution.ts Outdated Show resolved Hide resolved
protected filterVersions(nodeVersions: INodeVersion[]) {
const versions: string[] = [];

const dataFileName = this.getDistFileName(this.nodeInfo.arch);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I think we can get the architecture directly in the method since nodeInfo is available as a class property

const evaluatedVersion = this.evaluateVersions(versions);

if (evaluatedVersion) {
this.nodeInfo.versionSpec = evaluatedVersion;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the idea of overwriting the versionSpec property since we need to keep in mind that it changes at some point in time, this is not obvious. In my understanding, this violates the principle of encapsulation. I prefer to use a separate class property for this case.

toolPath = await this.downloadNodejs(toolName);
}

if (this.osPlat != 'win32') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use such checks in several places. Should we add the isWindows variable just for readability?

`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
const toolName = this.getNodejsDistInfo(evaluatedVersion, this.osPlat);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I think we can get the osPlat directly in the method since it is available as a class property.

I am also confused by the variable name (toolName). We get a complex object, not just the tool name.

src/distibutions/base-distribution.ts Outdated Show resolved Hide resolved
src/distibutions/official_builds/official_builds.ts Outdated Show resolved Hide resolved
src/distibutions/official_builds/official_builds.ts Outdated Show resolved Hide resolved
Copy link

@marko-zivic-93 marko-zivic-93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

}
}

let toolPath = this.findVersionInHoostedToolCacheDirectory();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Hoosted

@@ -0,0 +1,18 @@
export interface INodejs {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be rename to something like Inputs or ActionInputs or NodeInputs?

Comment on lines 15 to 41
function identifyDistribution(versionSpec: string) {
let distribution = Distributions.DEFAULT;
if (versionSpec.includes(Distributions.NIGHTLY)) {
distribution = Distributions.NIGHTLY;
} else if (versionSpec.includes(Distributions.CANARY)) {
distribution = Distributions.CANARY;
} else if (versionSpec.includes(Distributions.RC)) {
distribution = Distributions.RC;
}

return distribution;
}

export function getNodejsDistribution(
installerOptions: INodejs
): BaseDistribution {
const distributionName = identifyDistribution(installerOptions.versionSpec);
switch (distributionName) {
case Distributions.NIGHTLY:
return new NightlyNodejs(installerOptions);
case Distributions.CANARY:
return new CanaryBuild(installerOptions);
case Distributions.RC:
return new RcBuild(installerOptions);
default:
return new OfficialBuilds(installerOptions);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can merge it to the single method? This way we would avoid duplication.

Comment on lines 45 to 47
nodeVersions = nodeVersions ?? (await this.getNodejsVersions());
const versions = this.filterVersions(nodeVersions);
const evaluatedVersion = this.evaluateVersions(versions);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 3 lines look like duplicate of what we have under checkLatest condition.
What if we include filterVersions inside this.getNodejsVersions?

super(nodeInfo);
}

protected findVersionInHoostedToolCacheDirectory(): string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems to be identical in all subclasses. Can we move it to base class? Or may be simplify it somehow to avoid code duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants