Skip to content

Commit 5ab0d30

Browse files
Merge pull request #5265 from NativeScript/vladimirov/fix-pnpm
fix: package-manager and pnpm support fixes
2 parents 3b6ae39 + 3b363eb commit 5ab0d30

File tree

13 files changed

+100
-23
lines changed

13 files changed

+100
-23
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
NativeScript CLI Changelog
22
================
33

4-
6.4.1 (2020, February 19)
4+
6.4.1 (2020, February 21)
55
===
66

7+
### New
8+
9+
* [Implemented #5255](https://github.com/NativeScript/nativescript-cli/issues/5255): Warn if the CLI might print sensitive data to the output
10+
711
### Fixed
812

913
* [Fixed #5236](https://github.com/NativeScript/nativescript-cli/issues/5236): File paths from device logs are not clickable
1014
* [Fixed #5251](https://github.com/NativeScript/nativescript-cli/issues/5251): External files are not livesynced
1115
* [Fixed #5252](https://github.com/NativeScript/nativescript-cli/issues/5252): Logs from platform specific files point to incorrect file
16+
* [Fixed #5259](https://github.com/NativeScript/nativescript-cli/issues/5259): Unable to use pnpm on macOS and Linux
17+
* [Fixed #5260](https://github.com/NativeScript/nativescript-cli/issues/5260): `tns package-manager set invalid_value` does not say pnpm is supported
18+
* [Fixed #5261](https://github.com/NativeScript/nativescript-cli/issues/5261): `tns package-manager set <valid value>` does not give any output
19+
* [Fixed #5262](https://github.com/NativeScript/nativescript-cli/issues/5262): `tns package-manager` fails with error
20+
* [Fixed #5263](https://github.com/NativeScript/nativescript-cli/issues/5263): `tns package-manager` docs does not list pnpm as supported value
21+
* [Fixed #5264](https://github.com/NativeScript/nativescript-cli/issues/5264): `tns package-manager --help` fails with error
1222

1323

1424
6.4.0 (2020, February 11)

docs/man_pages/general/package-manager-get.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ General | `$ tns package-manager get`
2121

2222
Command | Description
2323
----------|----------
24-
[package-manager-set](package-manager-set.html) | Enables the specified package manager for the NativeScript CLI. Supported values are npm and yarn.
24+
[package-manager-set](package-manager-set.html) | Enables the specified package manager for the NativeScript CLI. Supported values are npm, yarn and pnpm.
2525
<% } %>

docs/man_pages/general/package-manager-set.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ General | `$ tns package-manager set <PackageManager>`
1717

1818
### Arguments
1919

20-
* `<PackageManager>` is the name of the package manager. Supported values are npm and yarn.
20+
* `<PackageManager>` is the name of the package manager. Supported values are npm, yarn and pnpm.
2121

2222
<% if(isHtml) { %>
2323

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<% if (isJekyll) { %>---
2+
title: tns package-manager get
3+
position: 19
4+
---<% } %>
5+
6+
# tns package-manager get
7+
8+
### Description
9+
10+
Prints the value of the current package manager.
11+
12+
### Commands
13+
14+
Usage | Synopsis
15+
------|-------
16+
General | `$ tns package-manager get`
17+
18+
<% if(isHtml) { %>
19+
20+
### Related Commands
21+
22+
Command | Description
23+
----------|----------
24+
[package-manager-set](package-manager-set.html) | Enables the specified package manager for the NativeScript CLI. Supported values are npm, yarn and pnpm.
25+
<% } %>

lib/bootstrap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ $injector.requirePublic("packageManager", "./package-manager");
113113
$injector.requirePublic("npm", "./node-package-manager");
114114
$injector.requirePublic("yarn", "./yarn-package-manager");
115115
$injector.requirePublic("pnpm", "./pnpm-package-manager");
116+
$injector.requireCommand("package-manager|*get", "./commands/package-manager-get");
116117
$injector.requireCommand("package-manager|set", "./commands/package-manager-set");
117-
$injector.requireCommand("package-manager|get", "./commands/package-manager-get");
118118

119119
$injector.require("packageInstallationManager", "./package-installation-manager");
120120

lib/common/commands/package-manager-get.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export class PackageManagerGetCommand implements ICommand {
1515
}
1616

1717
const result = await this.$userSettingsService.getSettingValue("packageManager");
18-
this.$logger.info(`Your current package manager is ${result || "npm"}.`);
18+
this.$logger.printMarkdown(`Your current package manager is \`${result || "npm"}\`.`);
1919
}
2020
}
2121

22-
$injector.registerCommand("package-manager|get", PackageManagerGetCommand);
22+
$injector.registerCommand("package-manager|*get", PackageManagerGetCommand);

lib/common/commands/package-manager-set.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
import { PackageManagers } from "../../constants";
12

23
export class PackageManagerCommand implements ICommand {
34

45
constructor(private $userSettingsService: IUserSettingsService,
56
private $errors: IErrors,
7+
private $logger: ILogger,
68
private $stringParameter: ICommandParameter) { }
79

810
public allowedParameters: ICommandParameter[] = [this.$stringParameter];
911

10-
public execute(args: string[]): Promise<void> {
11-
if (args[0] === 'yarn') {
12-
return this.$userSettingsService.saveSetting("packageManager", "yarn");
13-
} else if (args[0] === 'pnpm') {
14-
return this.$userSettingsService.saveSetting("packageManager", "pnpm");
15-
} else if (args[0] === 'npm') {
16-
return this.$userSettingsService.saveSetting("packageManager", "npm");
12+
public async execute(args: string[]): Promise<void> {
13+
const packageManagerName = args[0];
14+
const supportedPackageManagers = Object.keys(PackageManagers);
15+
if (supportedPackageManagers.indexOf(packageManagerName) === -1) {
16+
this.$errors.fail(`${packageManagerName} is not a valid package manager. Supported values are: ${supportedPackageManagers.join(", ")}.`);
1717
}
18-
return this.$errors.fail(`${args[0]} is not a valid package manager. Only yarn or npm are supported.`);
18+
19+
await this.$userSettingsService.saveSetting("packageManager", packageManagerName);
20+
21+
this.$logger.printMarkdown(`You've successfully set \`${packageManagerName}\` as your package manager.`);
1922
}
2023
}
2124

lib/common/services/help-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class HelpService implements IHelpService {
183183

184184
private async convertCommandNameToFileName(commandData: ICommandData): Promise<string> {
185185
let { commandName } = commandData;
186-
const defaultCommandMatch = commandName && commandName.match(/(\w+?)\|\*/);
186+
const defaultCommandMatch = commandName && commandName.match(/([\w-]+?)\|\*/);
187187
if (defaultCommandMatch) {
188188
this.$logger.trace("Default command found. Replace current command name '%s' with '%s'.", commandName, defaultCommandMatch[1]);
189189
commandName = defaultCommandMatch[1];

lib/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,9 @@ export enum LoggerConfigData {
415415
}
416416

417417
export const EMIT_APPENDER_EVENT_NAME = "logData";
418+
419+
export enum PackageManagers {
420+
npm = "npm",
421+
pnpm = "pnpm",
422+
yarn = "yarn"
423+
}

lib/declarations.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ interface INodePackageManager {
7676
}
7777

7878
interface IPackageManager extends INodePackageManager {
79+
/**
80+
* Gets the name of the package manager used for the current process.
81+
* It can be read from the user settings or by passing -- option.
82+
*/
83+
getPackageManagerName(): Promise<string>;
84+
7985
/**
8086
* Gets the version corresponding to the tag for the package
8187
* @param {string} packageName The name of the package.

0 commit comments

Comments
 (0)