-
-
Notifications
You must be signed in to change notification settings - Fork 197
feat() - [Yarn Support - Part 1 and 2] Yarn and Package Manager implementation #4050
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
Conversation
lib/base-package-manager.ts
Outdated
export class BasePackageManager { | ||
constructor(private packageManager: string) { } | ||
|
||
protected getNpmExecutableName(isWindows: boolean): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to provide isWindows
as param. You can determine it inside the method. Just need to inject $hostInfo
.
constructor(private packageManager: string,
private $hostInfo: IHostInfo){ }
protected getNpmExecutableName(): string {
const isWindows = this.$hostInfo.isWindows;
}
You'll need to change this https://github.com/NativeScript/nativescript-cli/pull/4050/files#diff-5d0fca739bb2fbd7cab602dbeaa30b89R17 as well
super('npm', $hostInfo);
This also should be changed https://github.com/NativeScript/nativescript-cli/pull/4050/files#diff-5d0fca739bb2fbd7cab602dbeaa30b89L11
constructor($hostInfo: IHostInfo, ...) { }
NOTE: No private
before $hostInfo
.
lib/base-package-manager.ts
Outdated
|
||
const npmExecutable = this.getNpmExecutableName(isWindows); | ||
|
||
if (childProcess.stdout) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is duplicated to this https://github.com/NativeScript/nativescript-cli/blob/master/lib/common/child-process.ts#L57
So I suggest to inject $childProcess: IChildProcess
in constructor and reuse the logic here.
protected async processPackageManagerInstall(params: string[], opts: { cwd: string }) {
const npmExecutable = this.getNpmExecutableName();
const stdioValue = isInteractive() ? "inherit" : "pipe";
const result = await this.$childProcess.spawnFromEvent(npmExecutable, params, "close", { cwd: opts.cwd, stdio: stdioValue });
return result;
}
These 2 methods should be deleted in this case:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thanks for the contribution.
lib/package-manager.ts
Outdated
private $yarn: INodePackageManager, | ||
private $userSettingsService: IUserSettingsService | ||
) { | ||
this._determinePackageManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is async
so it is possible to call some method from the class and this.packageManager
to be null.
So I suggest an approach similar to this https://github.com/NativeScript/nativescript-cli/blob/master/lib/common/mobile/android/android-debug-bridge.ts#L56.
@cache()
private async init(): Promise<void> {
this.packageManager = await this._determinePackageManager();
}
@exported("packageManager")
@invokeInit()
public install(packageName: string, pathToSave: string, config: INodePackageManagerInstallOptions): Promise<INpmInstallResultInfo> {
return this.packageManager.install(packageName, pathToSave, config);
}
This way this._determinePackageManager();
should be removed from constructor and all methods that relied on this.packageManager
should be decorated with @invokeInit()
On the other side init()
method is decorated with cache()
decorator so the value will be persisted and this._determinePackageManager()
will be called only once.
Also we can rewrite _determinePackageManager
method:
private async _determinePackageManager(): Promise<void> {
let pm = null;
try {
pm = await this.$userSettingsService.getSettingValue('packageManager');
} catch (err) {
this.$errors.fail(`Unable to read package manager config from user settings ${err}`);
}
if (pm === 'yarn' || this.$options.yarn) {
this.packageManager = this.$yarn;
} else {
this.packageManager = this.$npm;
}
}
lib/yarn-package-manager.ts
Outdated
|
||
@exported("yarn") | ||
getCachePath(): Promise<string> { | ||
throw new Error("Method not implemented."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.$errors.fail("Method not implemented.");
lib/yarn-package-manager.ts
Outdated
|
||
@exported("yarn") | ||
public search(filter: string[], config: IDictionary<string | boolean>): Promise<string> { | ||
throw new Error("Method not implemented. Yarn does not support searching for packages in the registry."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.$errors.fail("Method not implemented. Yarn does not support searching for packages in the registry.");
Yes, absolutely! Congratulations on this quality PR! Have a badge! |
@Fatme Thanks! Our motivation was not the gift card 😅. We actually want to start using yarn to continue the development of The California Court Access App. So far we noticed some speed improvements when building for Android. |
refactor() - [Yarn Support - Part 2] - Replace npm with package manag…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Work! 💯
I was ready to merge your PR and noticed the followings:
I suggest to integrate
Also all references to |
@Fatme Thanks for catching that! We'll also open another diff after this to refactor the |
@Fatme Are we ok to merge this? |
Yes, absolutely! I'm waiting for green light from our QAs and after that I'll merge the PR. |
Congratulations on being two of the winners in the {N} First-time contributors contest! You can claim your prize by contacting us at nativescriptwinners[at]progress.com not later than Nov 30th 2018 . Make sure you send us the following info: Best regards, |
PR Checklist
What is the current behavior?
Limited to only use NPM as package manager.
What is the new behavior?
Add support for the Yarn package manager.
Implements #2737.
We split this into two parts since it was a big diff. Can you please review part 2 ? CC: @rosen-vladimirov
Also do I qualify for the amazon gift card since it's my first contribution? 😛