Skip to content

chore: merge release in master #5280

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

Merged
merged 15 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
NativeScript CLI Changelog
================

6.4.1 (2020, February 19)
6.4.1 (2020, February 21)
===

### New

* [Implemented #5255](https://github.com/NativeScript/nativescript-cli/issues/5255): Warn if the CLI might print sensitive data to the output

### Fixed

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


6.4.0 (2020, February 11)
Expand Down
3 changes: 2 additions & 1 deletion docs/man_pages/general/package-manager-get.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ General | `$ tns package-manager get`

Command | Description
----------|----------
[package-manager-set](package-manager-set.html) | Enables the specified package manager for the NativeScript CLI. Supported values are npm and yarn.
[package-manager-set](package-manager-set.html) | Enables the specified package manager for the NativeScript CLI. Supported values are npm, yarn and pnpm.
[package-manager-get](package-manager-get.html) | Prints the value of the current package manager.
<% } %>
4 changes: 2 additions & 2 deletions docs/man_pages/general/package-manager-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ position: 18

### Description

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

### Commands

Expand All @@ -17,7 +17,7 @@ General | `$ tns package-manager set <PackageManager>`

### Arguments

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

<% if(isHtml) { %>

Expand Down
25 changes: 25 additions & 0 deletions docs/man_pages/general/package-manager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<% if (isJekyll) { %>---
title: tns package-manager get
position: 19
---<% } %>

# tns package-manager get

### Description

Prints the value of the current package manager.

### Commands

Usage | Synopsis
------|-------
General | `$ tns package-manager get`

<% if(isHtml) { %>

### Related Commands

Command | Description
----------|----------
[package-manager-set](package-manager-set.html) | Enables the specified package manager for the NativeScript CLI. Supported values are npm, yarn and pnpm.
<% } %>
1 change: 1 addition & 0 deletions docs/man_pages/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Command | Description
[proxy](general/proxy.html) | Displays proxy settings.
[migrate](general/migrate.html) | Migrates the app dependencies to a form compatible with NativeScript 6.0.
[update](general/update.html) | Updates the project with the latest versions of iOS/Android runtimes and cross-platform modules.
[package-manager](general/package-manager.html) | Prints the value of the current package manager.

## Project Development Commands
Command | Description
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ $injector.requirePublic("packageManager", "./package-manager");
$injector.requirePublic("npm", "./node-package-manager");
$injector.requirePublic("yarn", "./yarn-package-manager");
$injector.requirePublic("pnpm", "./pnpm-package-manager");
$injector.requireCommand("package-manager|*get", "./commands/package-manager-get");
$injector.requireCommand("package-manager|set", "./commands/package-manager-set");
$injector.requireCommand("package-manager|get", "./commands/package-manager-get");

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

Expand Down
4 changes: 2 additions & 2 deletions lib/common/commands/package-manager-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class PackageManagerGetCommand implements ICommand {
}

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

$injector.registerCommand("package-manager|get", PackageManagerGetCommand);
$injector.registerCommand("package-manager|*get", PackageManagerGetCommand);
20 changes: 12 additions & 8 deletions lib/common/commands/package-manager-set.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { PackageManagers } from "../../constants";

export class PackageManagerCommand implements ICommand {

constructor(private $userSettingsService: IUserSettingsService,
private $errors: IErrors,
private $logger: ILogger,
private $stringParameter: ICommandParameter) { }

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

public execute(args: string[]): Promise<void> {
if (args[0] === 'yarn') {
return this.$userSettingsService.saveSetting("packageManager", "yarn");
} else if (args[0] === 'pnpm') {
return this.$userSettingsService.saveSetting("packageManager", "pnpm");
} else if (args[0] === 'npm') {
return this.$userSettingsService.saveSetting("packageManager", "npm");
public async execute(args: string[]): Promise<void> {
const packageManagerName = args[0];
const supportedPackageManagers = Object.keys(PackageManagers);
if (supportedPackageManagers.indexOf(packageManagerName) === -1) {
this.$errors.fail(`${packageManagerName} is not a valid package manager. Supported values are: ${supportedPackageManagers.join(", ")}.`);
}
return this.$errors.fail(`${args[0]} is not a valid package manager. Only yarn or npm are supported.`);

await this.$userSettingsService.saveSetting("packageManager", packageManagerName);

this.$logger.printMarkdown(`Please ensure you have the directory containing \`${packageManagerName}\` executable available in your PATH.`);
this.$logger.printMarkdown(`You've successfully set \`${packageManagerName}\` as your package manager.`);
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/common/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class Logger implements ILogger {
log4js.configure({ appenders, categories });

this.log4jsLogger = log4js.getLogger();
if (level === LoggerLevel.TRACE || level === LoggerLevel.ALL) {
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 });
}
}

public initializeCliLogger(opts?: ILoggerOptions): void {
Expand Down
2 changes: 1 addition & 1 deletion lib/common/services/help-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class HelpService implements IHelpService {

private async convertCommandNameToFileName(commandData: ICommandData): Promise<string> {
let { commandName } = commandData;
const defaultCommandMatch = commandName && commandName.match(/(\w+?)\|\*/);
const defaultCommandMatch = commandName && commandName.match(/([\w-]+?)\|\*/);
if (defaultCommandMatch) {
this.$logger.trace("Default command found. Replace current command name '%s' with '%s'.", commandName, defaultCommandMatch[1]);
commandName = defaultCommandMatch[1];
Expand Down
3 changes: 2 additions & 1 deletion lib/common/test/unit-tests/mobile/device-log-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const createTestInjector = (): IInjector => {
projectIdentifiers: {
android: "org.nativescript.appTestLogs",
ios: "org.nativescript.appTestLogs"
}
},
projectDir: "projectDir"
};
},
getNSValue: (projectDir: string, propertyName: string): any => {
Expand Down
6 changes: 6 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,9 @@ export enum LoggerConfigData {
}

export const EMIT_APPENDER_EVENT_NAME = "logData";

export enum PackageManagers {
npm = "npm",
pnpm = "pnpm",
yarn = "yarn"
}
6 changes: 6 additions & 0 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ interface INodePackageManager {
}

interface IPackageManager extends INodePackageManager {
/**
* Gets the name of the package manager used for the current process.
* It can be read from the user settings or by passing -- option.
*/
getPackageManagerName(): Promise<string>;

/**
* Gets the version corresponding to the tag for the package
* @param {string} packageName The name of the package.
Expand Down
14 changes: 12 additions & 2 deletions lib/package-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

import { cache, exported, invokeInit } from './common/decorators';
import { performanceLog } from "./common/decorators";
import { PackageManagers } from './constants';
export class PackageManager implements IPackageManager {
private packageManager: INodePackageManager;
private _packageManagerName: string;

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

@invokeInit()
public async getPackageManagerName(): Promise<string> {
return this._packageManagerName;
}

@exported("packageManager")
@performanceLog()
@invokeInit()
Expand Down Expand Up @@ -97,11 +104,14 @@ export class PackageManager implements IPackageManager {
this.$errors.fail(`Unable to read package manager config from user settings ${err}`);
}

if (pm === 'yarn' || this.$options.yarn) {
if (pm === PackageManagers.yarn || this.$options.yarn) {
this._packageManagerName = PackageManagers.yarn;
return this.$yarn;
} else if (pm === 'pnpm' || this.$options.pnpm) {
} else if (pm === PackageManagers.pnpm || this.$options.pnpm) {
this._packageManagerName = PackageManagers.pnpm;
return this.$pnpm;
} else {
this._packageManagerName = PackageManagers.npm;
return this.$npm;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/log-source-map-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
const { dir, ext, name } = path.parse(sourceFile);
const platformSpecificName = `${name}.${platform.toLowerCase()}`;
const platformSpecificFile = path.format({ dir, ext, name: platformSpecificName });
if (this.$fs.exists(platformSpecificFile)) {
if (this.$fs.exists(path.join(projectData.projectDir, platformSpecificFile))) {
this.originalFilesLocationCache[sourceFile] = platformSpecificFile;
} else {
this.originalFilesLocationCache[sourceFile] = sourceFile;
Expand Down
26 changes: 20 additions & 6 deletions lib/services/webpack/webpack-compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as child_process from "child_process";
import * as semver from "semver";
import { EventEmitter } from "events";
import { performanceLog } from "../../common/decorators";
import { WEBPACK_COMPILATION_COMPLETE, WEBPACK_PLUGIN_NAME } from "../../constants";
import { WEBPACK_COMPILATION_COMPLETE, WEBPACK_PLUGIN_NAME, PackageManagers } from "../../constants";

export class WebpackCompilerService extends EventEmitter implements IWebpackCompilerService {
private webpackProcesses: IDictionary<child_process.ChildProcess> = {};
Expand All @@ -18,6 +18,7 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
private $logger: ILogger,
private $mobileHelper: Mobile.IMobileHelper,
private $cleanupService: ICleanupService,
private $packageManager: IPackageManager,
private $packageInstallationManager: IPackageInstallationManager
) { super(); }

Expand Down Expand Up @@ -155,6 +156,15 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
}
}

private async shouldUsePreserveSymlinksOption(): Promise<boolean> {
// pnpm does not require symlink (https://github.com/nodejs/node-eps/issues/46#issuecomment-277373566)
// and it also does not work in some cases.
// Check https://github.com/NativeScript/nativescript-cli/issues/5259 for more information
const currentPackageManager = await this.$packageManager.getPackageManagerName();
const res = currentPackageManager !== PackageManagers.pnpm;
return res;
}

@performanceLog()
private async startWebpackProcess(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<child_process.ChildProcess> {
if (!this.$fs.exists(projectData.webpackConfigPath)) {
Expand All @@ -164,18 +174,22 @@ export class WebpackCompilerService extends EventEmitter implements IWebpackComp
const envData = this.buildEnvData(platformData.platformNameLowerCase, projectData, prepareData);
const envParams = await this.buildEnvCommandLineParams(envData, platformData, projectData, prepareData);
const additionalNodeArgs = semver.major(process.version) <= 8 ? ["--harmony"] : [];

if (await this.shouldUsePreserveSymlinksOption()) {
additionalNodeArgs.push("--preserve-symlinks");
}

if (process.arch === "x64") {
additionalNodeArgs.unshift("--max_old_space_size=4096");
}

const args = [
...additionalNodeArgs,
"--preserve-symlinks",
path.join(projectData.projectDir, "node_modules", "webpack", "bin", "webpack.js"),
`--config=${projectData.webpackConfigPath}`,
...envParams
];

if (process.arch === "x64") {
args.unshift("--max_old_space_size=4096");
}

if (prepareData.watch) {
args.push("--watch");
}
Expand Down
3 changes: 2 additions & 1 deletion test/services/log-source-map-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function createTestInjector(): IInjector {
projectIdentifiers: {
android: "org.nativescript.sourceMap",
ios: "org.nativescript.sourceMap"
}
},
projectDir: "projectDir"
};
},
getNSValue: (projectDir: string, propertyName: string): any => {
Expand Down
3 changes: 3 additions & 0 deletions test/services/webpack/webpack-compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function getAllEmittedFiles(hash: string) {

function createTestInjector(): IInjector {
const testInjector = new Yok();
testInjector.register("packageManager", {
getPackageManagerName: async () => "npm"
});
testInjector.register("webpackCompilerService", WebpackCompilerService);
testInjector.register("childProcess", {});
testInjector.register("hooksService", {});
Expand Down