Skip to content

Commit 7e58a0c

Browse files
FatmeFatme
authored andcommitted
Merge pull request #1082 from NativeScript/fatme/merge-release-1.4.3
Merge release
2 parents b926ed1 + 81c3fdf commit 7e58a0c

11 files changed

+251
-41
lines changed

config/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"PROXY_HOSTNAME": "127.0.0.1",
66
"TYPESCRIPT_COMPILER_OPTIONS": {},
77
"CI_LOGGER": false,
8-
"ANDROID_DEBUG_UI_MAC": "Google Chrome"
8+
"ANDROID_DEBUG_UI_MAC": "Google Chrome",
9+
"USE_POD_SANDBOX": true
910
}

lib/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class Configuration extends configBaseLib.ConfigBase implements IConfigur
1111
TYPESCRIPT_COMPILER_OPTIONS = {};
1212
USE_PROXY = false;
1313
ANDROID_DEBUG_UI: string = null;
14+
USE_POD_SANDBOX: boolean = true;
1415

1516
/*don't require logger and everything that has logger as dependency in config.js due to cyclic dependency*/
1617
constructor(protected $fs: IFileSystem) {

lib/declarations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface INpmInstallationManager {
1515
cacheUnpack(packageName: string, version: string, unpackTarget?: string): IFuture<void>;
1616
install(packageName: string, options?: INpmInstallOptions): IFuture<string>;
1717
getLatestVersion(packageName: string): IFuture<string>;
18+
getLatestCompatibleVersion(packageName: string): IFuture<string>;
1819
getCachedPackagePath(packageName: string, version: string): string;
1920
addCleanCopyToCache(packageName: string, version: string): IFuture<void>;
2021
}
@@ -36,6 +37,7 @@ interface IStaticConfig extends Config.IStaticConfig { }
3637

3738
interface IConfiguration extends Config.IConfig {
3839
ANDROID_DEBUG_UI: string;
40+
USE_POD_SANDBOX: boolean;
3941
}
4042

4143
interface IApplicationPackage {

lib/npm-installation-manager.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import semver = require("semver");
66
import * as npm from "npm";
77
import * as constants from "./constants";
88

9+
interface IVersionData {
10+
major: string;
11+
minor: string;
12+
patch: string;
13+
}
14+
915
export class NpmInstallationManager implements INpmInstallationManager {
1016
private static NPM_LOAD_FAILED = "Failed to retrieve data from npm. Please try again a little bit later.";
1117
private versionsCache: IDictionary<string[]>;
@@ -20,7 +26,8 @@ export class NpmInstallationManager implements INpmInstallationManager {
2026
private $lockfile: ILockFile,
2127
private $errors: IErrors,
2228
private $options: IOptions,
23-
private $fs: IFileSystem) {
29+
private $fs: IFileSystem,
30+
private $staticConfig: IStaticConfig) {
2431
this.versionsCache = {};
2532
this.$npm.load().wait();
2633
}
@@ -63,6 +70,27 @@ export class NpmInstallationManager implements INpmInstallationManager {
6370
}).future<string>()();
6471
}
6572

73+
public getLatestCompatibleVersion(packageName: string): IFuture<string> {
74+
return (() => {
75+
let latestVersion = this.getLatestVersion(packageName).wait();
76+
let data = this.$npm.view(packageName, "versions").wait();
77+
let versions: string[] = data[latestVersion].versions;
78+
79+
let versionData = this.getVersionData(this.$staticConfig.version);
80+
81+
let compatibleVersions = _(versions)
82+
.map(ver => this.getVersionData(ver))
83+
.filter(verData => versionData.major === verData.major && versionData.minor === verData.minor)
84+
.sortBy(verData => verData.patch)
85+
.value();
86+
87+
let result = _.last(compatibleVersions);
88+
89+
let latestCompatibleVersion = `${result.major}.${result.minor}.${result.patch}`;
90+
return latestCompatibleVersion;
91+
}).future<string>()();
92+
}
93+
6694
public install(packageName: string, opts?: INpmInstallOptions): IFuture<string> {
6795
return (() => {
6896
this.$lockfile.lock().wait();
@@ -131,7 +159,7 @@ export class NpmInstallationManager implements INpmInstallationManager {
131159
}
132160
return this.$options.frameworkPath;
133161
} else {
134-
version = version || this.getLatestVersion(packageName).wait();
162+
version = version || this.getLatestCompatibleVersion(packageName).wait();
135163
let packagePath = this.getCachedPackagePath(packageName, version);
136164
this.addToCache(packageName, version).wait();
137165
return packagePath;
@@ -163,5 +191,10 @@ export class NpmInstallationManager implements INpmInstallationManager {
163191
return this.$fs.exists(directory).wait() && this.$fs.enumerateFilesInDirectorySync(directory).length > 0;
164192
}).future<boolean>()();
165193
}
194+
195+
private getVersionData(version: string): IVersionData {
196+
let [ major, minor, patch ] = version.split(".");
197+
return { major, minor, patch };
198+
}
166199
}
167200
$injector.register("npmInstallationManager", NpmInstallationManager);

lib/services/android-project-service.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,14 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
100100
if(this.$options.symlink) {
101101
this.symlinkDirectory("build-tools", this.platformData.projectRoot, frameworkDir).wait();
102102
this.symlinkDirectory("libs", this.platformData.projectRoot, frameworkDir).wait();
103-
this.symlinkDirectory("src", this.platformData.projectRoot, frameworkDir).wait();
104-
105-
this.$fs.symlink(path.join(frameworkDir, "build.gradle"), path.join(this.platformData.projectRoot, "build.gradle")).wait();
106-
this.$fs.symlink(path.join(frameworkDir, "settings.gradle"), path.join(this.platformData.projectRoot, "settings.gradle")).wait();
107103
} else {
108-
this.copy(this.platformData.projectRoot, frameworkDir, "build-tools libs src", "-R");
109-
this.copy(this.platformData.projectRoot, frameworkDir, "build.gradle settings.gradle", "-f");
104+
this.copy(this.platformData.projectRoot, frameworkDir, "build-tools libs", "-R");
110105
}
111106

107+
// These files and directories should not be symlinked as CLI is modifying them and we'll change the original values as well.
108+
this.copy(this.platformData.projectRoot, frameworkDir, "src", "-R");
109+
this.copy(this.platformData.projectRoot, frameworkDir, "build.gradle settings.gradle", "-f");
110+
112111
this.cleanResValues(targetSdkVersion, frameworkVersion).wait();
113112

114113
}).future<any>()();

lib/services/init-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class InitService implements IInitService {
9999

100100
private getVersionData(packageName: string): IFuture<IStringDictionary> {
101101
return (() => {
102-
let latestVersion = this.$npmInstallationManager.getLatestVersion(packageName).wait();
102+
let latestVersion = this.$npmInstallationManager.getLatestCompatibleVersion(packageName).wait();
103103
if(this.useDefaultValue) {
104104
return this.buildVersionData(latestVersion);
105105
}

lib/services/ios-project-service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
3232
private $options: IOptions,
3333
private $injector: IInjector,
3434
$projectDataService: IProjectDataService,
35-
private $prompter: IPrompter) {
35+
private $prompter: IPrompter,
36+
private $config: IConfiguration) {
3637
super($fs, $projectData, $projectDataService);
3738
}
3839

@@ -499,7 +500,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
499500

500501
private executePodInstall(): IFuture<any> {
501502
this.$logger.info("Installing pods...");
502-
return this.$childProcess.spawnFromEvent("pod", ["install"], "close", { cwd: this.platformData.projectRoot, stdio: 'inherit' });
503+
let podTool = this.$config.USE_POD_SANDBOX ? "sandbox-pod" : "pod";
504+
return this.$childProcess.spawnFromEvent(podTool, ["install"], "close", { cwd: this.platformData.projectRoot, stdio: 'inherit' });
503505
}
504506

505507
private prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"main": "./lib/nativescript-cli.js",
1212
"scripts": {
13-
"test": "node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 60000 test/ lib/common/test/unit-tests",
13+
"test": "node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- --ui mocha-fibers --recursive --reporter spec --require test/test-bootstrap.js --timeout 150000 test/ lib/common/test/unit-tests",
1414
"postinstall": "node postinstall.js",
1515
"preuninstall": "node preuninstall.js"
1616
},

test/npm-installation-manager.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/// <reference path=".d.ts" />
2+
"use strict";
3+
4+
import {assert} from "chai";
5+
import * as ConfigLib from "../lib/config";
6+
import * as ErrorsLib from "../lib/common/errors";
7+
import * as FsLib from "../lib/common/file-system";
8+
import * as HostInfoLib from "../lib/common/host-info";
9+
import * as LoggerLib from "../lib/common/logger";
10+
import * as NpmInstallationManagerLib from "../lib/npm-installation-manager";
11+
import * as OptionsLib from "../lib/options";
12+
import * as StaticConfigLib from "../lib/config";
13+
14+
import Future = require("fibers/future");
15+
import yok = require("../lib/common/yok");
16+
17+
function createTestInjector(): IInjector {
18+
let testInjector = new yok.Yok();
19+
20+
testInjector.register("config", ConfigLib.Configuration);
21+
testInjector.register("logger", LoggerLib.Logger);
22+
testInjector.register("lockfile", { });
23+
testInjector.register("errors", ErrorsLib.Errors);
24+
testInjector.register("options", OptionsLib.Options);
25+
testInjector.register("fs", FsLib.FileSystem);
26+
testInjector.register("hostInfo", HostInfoLib.HostInfo);
27+
testInjector.register("staticConfig", StaticConfigLib.StaticConfig);
28+
29+
testInjector.register("npmInstallationManager", NpmInstallationManagerLib.NpmInstallationManager);
30+
31+
return testInjector;
32+
}
33+
34+
function mockNpm(testInjector: IInjector, versions: string[], latestVersion: string) {
35+
testInjector.register("npm", {
36+
view: (packageName: string, propertyName: string) => {
37+
return (() => {
38+
if(propertyName === "versions") {
39+
let result = Object.create(null);
40+
result[latestVersion] = {
41+
"versions": versions
42+
};
43+
44+
return result;
45+
}
46+
47+
throw new Error(`Unable to find propertyName ${propertyName}.`);
48+
}).future<any>()();
49+
},
50+
load: () => Future.fromResult()
51+
});
52+
}
53+
54+
describe("Npm installation manager tests", () => {
55+
it("returns correct latest compatible version when only one exists", () => {
56+
let testInjector = createTestInjector();
57+
58+
let versions = ["1.4.0"];
59+
let latestVersion = "1.4.0";
60+
61+
mockNpm(testInjector, versions, latestVersion);
62+
63+
// Mock staticConfig.version
64+
let staticConfig = testInjector.resolve("staticConfig");
65+
staticConfig.version = "1.4.0";
66+
67+
// Mock npmInstallationManager.getLatestVersion
68+
let npmInstallationManager = testInjector.resolve("npmInstallationManager");
69+
npmInstallationManager.getLatestVersion = (packageName: string) => Future.fromResult(latestVersion);
70+
71+
let actualLatestCompatibleVersion = npmInstallationManager.getLatestCompatibleVersion("").wait();
72+
let expectedLatestCompatibleVersion = "1.4.0";
73+
assert.equal(actualLatestCompatibleVersion, expectedLatestCompatibleVersion);
74+
});
75+
it("returns correct latest compatible version", () => {
76+
let testInjector = createTestInjector();
77+
78+
let versions = ["1.2.0", "1.3.0", "1.3.1", "1.3.2", "1.3.3", "1.4.0"];
79+
let latestVersion = "1.3.3";
80+
81+
mockNpm(testInjector, versions, latestVersion);
82+
83+
// Mock staticConfig.version
84+
let staticConfig = testInjector.resolve("staticConfig");
85+
staticConfig.version = "1.3.0";
86+
87+
// Mock npmInstallationManager.getLatestVersion
88+
let npmInstallationManager = testInjector.resolve("npmInstallationManager");
89+
npmInstallationManager.getLatestVersion = (packageName: string) => Future.fromResult(latestVersion);
90+
91+
let actualLatestCompatibleVersion = npmInstallationManager.getLatestCompatibleVersion("").wait();
92+
let expectedLatestCompatibleVersion = "1.3.3";
93+
assert.equal(actualLatestCompatibleVersion, expectedLatestCompatibleVersion);
94+
});
95+
});

0 commit comments

Comments
 (0)