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

Abstract Last-Install.flag file into a reusable class #546

Merged
merged 4 commits into from
Mar 2, 2018

Conversation

nickpape
Copy link
Contributor

@nickpape nickpape commented Mar 1, 2018

  • Introduce a last-install.flag API
  • Also, fix a bug with installing the package manager

@nickpape nickpape requested a review from octogonz March 1, 2018 22:52
/**
* A helper class for managing last-install flags, which are persistent and
* indicate that something installed in the folder was sucessfully completed.
* It also compares state, so that if something like the Node JS version has changed,
Copy link
Collaborator

@octogonz octogonz Mar 1, 2018

Choose a reason for hiding this comment

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

Node JS [](start = 57, length = 7)

Node.js #Resolved

* it can invalidate the last install.
* @internal
*/
export class LastInstallFlag {
Copy link
Collaborator

@octogonz octogonz Mar 1, 2018

Choose a reason for hiding this comment

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

LastInstallFlag [](start = 13, length = 15)

Add a unit test #Resolved

* @param folderPath - the folder that this flag is managing
* @param _state - optional, the state that should be managed or compared
*/
constructor(folderPath: string, private _state: Object = {}) {
Copy link
Collaborator

@octogonz octogonz Mar 1, 2018

Choose a reason for hiding this comment

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

private [](start = 34, length = 7)

Never use this language feature. It hides the data fields, which are arguably the most important aspect of a class. (The thesis of object-oriented programming is to focus on data instead of operations; if the nouns are clearly defined then the interpretation of the verbs will be obvious.) #Resolved

*/
public isValid(): boolean {
try {
return _.isEqual(fsx.readJsonSync(this._flagPath), this._state);
Copy link
Collaborator

@octogonz octogonz Mar 1, 2018

Choose a reason for hiding this comment

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

readJsonSync [](start = 27, length = 12)

Test whether the file exists, to avoid an "expected exception" #Resolved

/**
* Writes the flag file to disk with the current state
*/
public set(): void {
Copy link
Collaborator

@octogonz octogonz Mar 1, 2018

Choose a reason for hiding this comment

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

set [](start = 9, length = 3)

"set" is a keyword. Also it's not super clear.

Maybe "create"? #Resolved

/**
* Returns the full path to the flag file
*/
public get flagPath(): string {
Copy link
Collaborator

@octogonz octogonz Mar 1, 2018

Choose a reason for hiding this comment

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

flagPath [](start = 13, length = 8)

lastInstallFlag.flagPath seems redundant, maybe just "path"? #Resolved

* it can invalidate the last install.
* @internal
*/
export class LastInstallFlag {
Copy link
Collaborator

@octogonz octogonz Mar 1, 2018

Choose a reason for hiding this comment

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

LastInstallFlag [](start = 13, length = 15)

I feel like the class name should have the word "file' in it, since that's a pretty important aspect of this API. (Then maybe the verbs could be something like create/delete/test instead of set/clear?) #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can fix this later if we decide to generalize this API


In reply to: 171727085 [](ancestors = 171727085)

*/
public isValid(): boolean {
try {
return _.isEqual(fsx.readJsonSync(this._flagPath), this._state);
Copy link
Collaborator

@octogonz octogonz Mar 1, 2018

Choose a reason for hiding this comment

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

fsx.readJsonSync(this._flagPath) [](start = 23, length = 32)

for debugging purposes, it might be useful to store the readJsonSync() result in a local variable #Resolved

Copy link
Collaborator

@octogonz octogonz left a comment

Choose a reason for hiding this comment

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

:shipit:

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.

2 participants