Skip to content

Commit 2a78457

Browse files
Merge pull request #5280 from NativeScript/vladimirov/merge-rel-master
chore: merge release in master
2 parents a2da3d0 + 97089d0 commit 2a78457

18 files changed

+112
-27
lines changed

CHANGELOG.md

+11-1
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ 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.
25+
[package-manager-get](package-manager-get.html) | Prints the value of the current package manager.
2526
<% } %>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ position: 18
77

88
### Description
99

10-
Enables the specified package manager for the NativeScript CLI. Supported values are npm and yarn.
10+
Enables the specified package manager for the NativeScript CLI. Supported values are npm, yarn and pnpm.
1111

1212
### Commands
1313

@@ -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

+25
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+
<% } %>

docs/man_pages/start.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Command | Description
2323
[proxy](general/proxy.html) | Displays proxy settings.
2424
[migrate](general/migrate.html) | Migrates the app dependencies to a form compatible with NativeScript 6.0.
2525
[update](general/update.html) | Updates the project with the latest versions of iOS/Android runtimes and cross-platform modules.
26+
[package-manager](general/package-manager.html) | Prints the value of the current package manager.
2627

2728
## Project Development Commands
2829
Command | Description

lib/bootstrap.ts

+1-1
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

+2-2
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

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
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(`Please ensure you have the directory containing \`${packageManagerName}\` executable available in your PATH.`);
22+
this.$logger.printMarkdown(`You've successfully set \`${packageManagerName}\` as your package manager.`);
1923
}
2024
}
2125

lib/common/logger/logger.ts

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export class Logger implements ILogger {
4848
log4js.configure({ appenders, categories });
4949

5050
this.log4jsLogger = log4js.getLogger();
51+
if (level === LoggerLevel.TRACE || level === LoggerLevel.ALL) {
52+
this.warn(`The "${level}" log level might print some sensitive data like secrets or access tokens in request URLs. Be careful when you share this output.`, { wrapMessageWithBorders: true });
53+
}
5154
}
5255

5356
public initializeCliLogger(opts?: ILoggerOptions): void {

lib/common/services/help-service.ts

+1-1
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/common/test/unit-tests/mobile/device-log-provider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const createTestInjector = (): IInjector => {
3939
projectIdentifiers: {
4040
android: "org.nativescript.appTestLogs",
4141
ios: "org.nativescript.appTestLogs"
42-
}
42+
},
43+
projectDir: "projectDir"
4344
};
4445
},
4546
getNSValue: (projectDir: string, propertyName: string): any => {

lib/constants.ts

+6
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

+6
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.

lib/package-manager.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11

22
import { cache, exported, invokeInit } from './common/decorators';
33
import { performanceLog } from "./common/decorators";
4+
import { PackageManagers } from './constants';
45
export class PackageManager implements IPackageManager {
56
private packageManager: INodePackageManager;
7+
private _packageManagerName: string;
68

79
constructor(
810
private $errors: IErrors,
@@ -19,6 +21,11 @@ export class PackageManager implements IPackageManager {
1921
this.packageManager = await this._determinePackageManager();
2022
}
2123

24+
@invokeInit()
25+
public async getPackageManagerName(): Promise<string> {
26+
return this._packageManagerName;
27+
}
28+
2229
@exported("packageManager")
2330
@performanceLog()
2431
@invokeInit()
@@ -97,11 +104,14 @@ export class PackageManager implements IPackageManager {
97104
this.$errors.fail(`Unable to read package manager config from user settings ${err}`);
98105
}
99106

100-
if (pm === 'yarn' || this.$options.yarn) {
107+
if (pm === PackageManagers.yarn || this.$options.yarn) {
108+
this._packageManagerName = PackageManagers.yarn;
101109
return this.$yarn;
102-
} else if (pm === 'pnpm' || this.$options.pnpm) {
110+
} else if (pm === PackageManagers.pnpm || this.$options.pnpm) {
111+
this._packageManagerName = PackageManagers.pnpm;
103112
return this.$pnpm;
104113
} else {
114+
this._packageManagerName = PackageManagers.npm;
105115
return this.$npm;
106116
}
107117
}

lib/services/log-source-map-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
128128
const { dir, ext, name } = path.parse(sourceFile);
129129
const platformSpecificName = `${name}.${platform.toLowerCase()}`;
130130
const platformSpecificFile = path.format({ dir, ext, name: platformSpecificName });
131-
if (this.$fs.exists(platformSpecificFile)) {
131+
if (this.$fs.exists(path.join(projectData.projectDir, platformSpecificFile))) {
132132
this.originalFilesLocationCache[sourceFile] = platformSpecificFile;
133133
} else {
134134
this.originalFilesLocationCache[sourceFile] = sourceFile;

lib/services/webpack/webpack-compiler-service.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as child_process from "child_process";
33
import * as semver from "semver";
44
import { EventEmitter } from "events";
55
import { performanceLog } from "../../common/decorators";
6-
import { WEBPACK_COMPILATION_COMPLETE, WEBPACK_PLUGIN_NAME } from "../../constants";
6+
import { WEBPACK_COMPILATION_COMPLETE, WEBPACK_PLUGIN_NAME, PackageManagers } from "../../constants";
77

88
export class WebpackCompilerService extends EventEmitter implements IWebpackCompilerService {
99
private webpackProcesses: IDictionary<child_process.ChildProcess> = {};
@@ -18,6 +18,7 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
1818
private $logger: ILogger,
1919
private $mobileHelper: Mobile.IMobileHelper,
2020
private $cleanupService: ICleanupService,
21+
private $packageManager: IPackageManager,
2122
private $packageInstallationManager: IPackageInstallationManager
2223
) { super(); }
2324

@@ -155,6 +156,15 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
155156
}
156157
}
157158

159+
private async shouldUsePreserveSymlinksOption(): Promise<boolean> {
160+
// pnpm does not require symlink (https://github.com/nodejs/node-eps/issues/46#issuecomment-277373566)
161+
// and it also does not work in some cases.
162+
// Check https://github.com/NativeScript/nativescript-cli/issues/5259 for more information
163+
const currentPackageManager = await this.$packageManager.getPackageManagerName();
164+
const res = currentPackageManager !== PackageManagers.pnpm;
165+
return res;
166+
}
167+
158168
@performanceLog()
159169
private async startWebpackProcess(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<child_process.ChildProcess> {
160170
if (!this.$fs.exists(projectData.webpackConfigPath)) {
@@ -164,18 +174,22 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
164174
const envData = this.buildEnvData(platformData.platformNameLowerCase, projectData, prepareData);
165175
const envParams = await this.buildEnvCommandLineParams(envData, platformData, projectData, prepareData);
166176
const additionalNodeArgs = semver.major(process.version) <= 8 ? ["--harmony"] : [];
177+
178+
if (await this.shouldUsePreserveSymlinksOption()) {
179+
additionalNodeArgs.push("--preserve-symlinks");
180+
}
181+
182+
if (process.arch === "x64") {
183+
additionalNodeArgs.unshift("--max_old_space_size=4096");
184+
}
185+
167186
const args = [
168187
...additionalNodeArgs,
169-
"--preserve-symlinks",
170188
path.join(projectData.projectDir, "node_modules", "webpack", "bin", "webpack.js"),
171189
`--config=${projectData.webpackConfigPath}`,
172190
...envParams
173191
];
174192

175-
if (process.arch === "x64") {
176-
args.unshift("--max_old_space_size=4096");
177-
}
178-
179193
if (prepareData.watch) {
180194
args.push("--watch");
181195
}

test/services/log-source-map-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function createTestInjector(): IInjector {
1919
projectIdentifiers: {
2020
android: "org.nativescript.sourceMap",
2121
ios: "org.nativescript.sourceMap"
22-
}
22+
},
23+
projectDir: "projectDir"
2324
};
2425
},
2526
getNSValue: (projectDir: string, propertyName: string): any => {

test/services/webpack/webpack-compiler-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ function getAllEmittedFiles(hash: string) {
1313

1414
function createTestInjector(): IInjector {
1515
const testInjector = new Yok();
16+
testInjector.register("packageManager", {
17+
getPackageManagerName: async () => "npm"
18+
});
1619
testInjector.register("webpackCompilerService", WebpackCompilerService);
1720
testInjector.register("childProcess", {});
1821
testInjector.register("hooksService", {});

0 commit comments

Comments
 (0)