Skip to content

Commit c71156f

Browse files
NathanWalkerrigor789
authored andcommitted
chore: test cleanup
1 parent ed5b8d3 commit c71156f

File tree

14 files changed

+101
-66
lines changed

14 files changed

+101
-66
lines changed

lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export class Hooks {
276276

277277
export class AndroidBuildDefaults {
278278
public static GradleVersion = "4.4";
279-
public static GradleAndroidPluginVersion = "3.1.2";
279+
public static GradleAndroidPluginVersion = "4.5.6";
280280
}
281281

282282
export const PACKAGE_PLACEHOLDER_NAME = "__PACKAGE__";

lib/controllers/platform-controller.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class PlatformController implements IPlatformController {
2121
public async addPlatform(addPlatformData: IAddPlatformData): Promise<void> {
2222
const [platform, version] = addPlatformData.platform.toLowerCase().split("@");
2323
const projectData = this.$projectDataService.getProjectData(addPlatformData.projectDir);
24-
const platformData = this.$platformsDataService.getPlatformData(platform, projectData);
24+
const platformData = this.$platformsDataService.getPlatformData(platform, projectData);
2525

2626
this.$logger.trace(`Creating NativeScript project for the ${platform} platform`);
2727
this.$logger.trace(`Path: ${platformData.projectRoot}`);
@@ -32,7 +32,7 @@ export class PlatformController implements IPlatformController {
3232

3333
const packageToInstall = await this.getPackageToInstall(platformData, projectData, addPlatformData.frameworkPath, version);
3434

35-
const installedPlatformVersion = await this.$addPlatformService.addPlatformSafe(projectData, platformData, packageToInstall, addPlatformData.nativePrepare);
35+
const installedPlatformVersion = await this.$addPlatformService.addPlatformSafe(projectData, platformData, packageToInstall, addPlatformData);
3636

3737
this.$fs.ensureDirectoryExists(path.join(projectData.platformsDir, platform));
3838
this.$logger.info(`Platform ${platform} successfully added. v${installedPlatformVersion}`);
@@ -50,17 +50,21 @@ export class PlatformController implements IPlatformController {
5050
}
5151

5252
private async getPackageToInstall(platformData: IPlatformData, projectData: IProjectData, frameworkPath?: string, version?: string): Promise<string> {
53-
let result = null;
53+
let result = null;
5454
if (frameworkPath) {
5555
if (!this.$fs.exists(frameworkPath)) {
5656
this.$errors.fail(`Invalid frameworkPath: ${frameworkPath}. Please ensure the specified frameworkPath exists.`);
5757
}
5858
result = path.resolve(frameworkPath);
5959
} else {
6060
if (!version) {
61-
const currentPlatformData = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
62-
version = (currentPlatformData && currentPlatformData.version) ||
63-
await this.$packageInstallationManager.getLatestCompatibleVersion(platformData.frameworkPackageName);
61+
version = projectData.devDependencies ? projectData.devDependencies[platformData.frameworkPackageName] : null;
62+
if (!version) {
63+
version = await this.$packageInstallationManager.getLatestCompatibleVersion(platformData.frameworkPackageName)
64+
}
65+
// const currentPlatformData = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
66+
// version = (currentPlatformData && currentPlatformData.version) ||
67+
// await this.$packageInstallationManager.getLatestCompatibleVersion(platformData.frameworkPackageName);
6468
}
6569

6670
result = `${platformData.frameworkPackageName}@${version}`;

lib/definitions/platform.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@ interface IPlatformController {
105105
}
106106

107107
interface IAddPlatformService {
108-
addPlatformSafe(projectData: IProjectData, platformData: IPlatformData, packageToInstall: string, nativePrepare: INativePrepare): Promise<string>;
108+
addPlatformSafe(projectData: IProjectData, platformData: IPlatformData, packageToInstall: string, addPlatformData: IAddPlatformData): Promise<string>;
109109
setPlatformVersion(platformData: IPlatformData, projectData: IProjectData, frameworkVersion: string): Promise<void>
110110
}

lib/options.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ export class Options {
171171

172172
public validateOptions(commandSpecificDashedOptions?: IDictionary<IDashedOption>): void {
173173
this.setupOptions(commandSpecificDashedOptions);
174-
const parsed = Object.create(null);
175-
// DO NOT REMOVE { } as when they are missing and some of the option values is false, the each stops as it thinks we have set "return false".
176-
_.each(_.keys(this.argv), optionName => {
174+
const parsed: any = {};
175+
for (const key of Object.keys(this.argv)) {
176+
const optionName = `${this.argv[key]}`;
177177
parsed[optionName] = this.getOptionValue(optionName);
178-
});
178+
}
179179

180180
_.each(parsed, (value: any, originalOptionName: string) => {
181181
// when this.options are passed to yargs, it returns all of them and the ones that are not part of process.argv are set to undefined.

lib/services/android-plugin-build-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
181181
const androidSourceDirectories = this.getAndroidSourceDirectories(options.platformsAndroidDirPath);
182182
const shortPluginName = getShortPluginName(options.pluginName);
183183
const pluginTempDir = path.join(options.tempPluginDirPath, shortPluginName);
184-
const pluginSourceFileHashesInfo = await this.getSourceFilesHashes(options.platformsAndroidDirPath, shortPluginName);
184+
const pluginSourceFileHashesInfo = await this.getSourceFilesHashes(options.platformsAndroidDirPath, shortPluginName);
185185

186186
const shouldBuildAar = await this.shouldBuildAar({
187187
manifestFilePath,
@@ -190,7 +190,7 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService {
190190
pluginSourceDir: options.platformsAndroidDirPath,
191191
shortPluginName,
192192
fileHashesInfo: pluginSourceFileHashesInfo
193-
});
193+
});
194194

195195
if (shouldBuildAar) {
196196
this.cleanPluginDir(pluginTempDir);

lib/services/livesync/playground/preview-app-files-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IPlatformsDataService } from "../../../definitions/platform";
77
import { IProjectDataService } from "../../../definitions/project";
88
import { IFileSystem, IProjectFilesManager, IProjectFilesProvider } from "../../../common/declarations";
99
import { injector } from "../../../common/yok";
10-
const isTextOrBinary = require('istextorbinary');
10+
import { isBinary } from "istextorbinary";
1111

1212
export class PreviewAppFilesService implements IPreviewAppFilesService {
1313
private excludedFileExtensions = [".ts", ".sass", ".scss", ".less"];
@@ -67,7 +67,7 @@ export class PreviewAppFilesService implements IPreviewAppFilesService {
6767
let binary = false;
6868

6969
if (event === PreviewSdkEventNames.CHANGE_EVENT_NAME) {
70-
binary = isTextOrBinary.isBinarySync(file);
70+
binary = isBinary(file);
7171
if (binary) {
7272
const bitmap = <string>this.$fs.readFile(file);
7373
const base64 = Buffer.from(bitmap).toString('base64');

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
5353
if (!this.$fs.getFsStats(filePath).isDirectory()) {
5454
const source = this.$fs.readText(filePath);
5555
const sourceMapRaw = sourceMapConverter.fromSource(source);
56-
let smc: any = null;
56+
let smc: any = null;
5757
if (sourceMapRaw && sourceMapRaw.sourcemap) {
5858
const sourceMap = sourceMapRaw.sourcemap;
59-
smc = await sourcemap.SourceMapConsumer.with(sourceMap, filePath, (smc) => {
60-
return smc;
59+
smc = await sourcemap.SourceMapConsumer.with(sourceMap, null, (c) => {
60+
return c;
6161
});
62-
}
62+
}
6363

6464
this.cache[filePath] = smc;
6565
}

lib/services/platform/add-platform-service.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
import * as path from "path";
22
import { PROJECT_FRAMEWORK_FOLDER_NAME, TrackActionNames, AnalyticsEventLabelDelimiter } from "../../constants";
33
import { performanceLog } from "../../common/decorators";
4-
import { IAddPlatformService, IPlatformData } from "../../definitions/platform";
5-
import { IProjectData, INativePrepare } from "../../definitions/project";//IProjectDataService
4+
import { IAddPlatformService, IPlatformData, IAddPlatformData } from "../../definitions/platform";
5+
import { IProjectData } from "../../definitions/project";//IProjectDataService
66
import { IFileSystem, IAnalyticsService } from "../../common/declarations";
77
import { injector } from "../../common/yok";
8-
import { IPackageManager, IOptions } from "../../declarations";
8+
import { IPackageManager } from "../../declarations";
99

1010
export class AddPlatformService implements IAddPlatformService {
1111
constructor(
1212
private $fs: IFileSystem,
1313
private $pacoteService: IPacoteService,
1414
// private $projectDataService: IProjectDataService,
15-
private $options: IOptions,
1615
private $packageManager: IPackageManager,
1716
private $terminalSpinnerService: ITerminalSpinnerService,
1817
private $analyticsService: IAnalyticsService,
1918
private $tempService: ITempService
2019
) { }
2120

22-
public async addPlatformSafe(projectData: IProjectData, platformData: IPlatformData, packageToInstall: string, nativePrepare: INativePrepare): Promise<string> {
21+
public async addPlatformSafe(projectData: IProjectData, platformData: IPlatformData, packageToInstall: string, addPlatformData: IAddPlatformData): Promise<string> {
2322
const spinner = this.$terminalSpinnerService.createSpinner();
2423

2524
try {
2625
spinner.start();
2726

2827
let frameworkDirPath: string;
2928
let frameworkVersion: string;
30-
if (this.$options.frameworkPath) {
29+
if (addPlatformData.frameworkPath) {
3130
frameworkDirPath = await this.extractPackage(packageToInstall);
3231
const frameworkPackageJsonContent = this.$fs.readJson(path.join(frameworkDirPath, "..", "package.json"));
3332
frameworkVersion = frameworkPackageJsonContent.version;
@@ -38,13 +37,16 @@ export class AddPlatformService implements IAddPlatformService {
3837
const [ name, version ] = packageToInstall.split('@');
3938
frameworkDirPath = path.join(projectData.projectDir, 'node_modules', name, PROJECT_FRAMEWORK_FOLDER_NAME);
4039
frameworkVersion = version;
40+
if (!projectData.devDependencies) {
41+
projectData.devDependencies = {};
42+
}
4143
if (!projectData.devDependencies[name]) {
4244
await this.setPlatformVersion(platformData, projectData, version);
4345
}
4446
await this.trackPlatformVersion(version, platformData);
4547
}
4648

47-
if (!nativePrepare || !nativePrepare.skipNativePrepare) {
49+
if (!addPlatformData.nativePrepare || !addPlatformData.nativePrepare.skipNativePrepare) {
4850
await this.addNativePlatform(platformData, projectData, frameworkDirPath, frameworkVersion);
4951
}
5052

@@ -59,6 +61,7 @@ export class AddPlatformService implements IAddPlatformService {
5961
}
6062

6163
public async setPlatformVersion(platformData: IPlatformData, projectData: IProjectData, frameworkVersion: string): Promise<void> {
64+
// TODO: We may want to write the version to nativescript.config.js here
6265
// const frameworkPackageNameData = { version: frameworkVersion };
6366
// this.$projectDataService.setNSValue(projectData.projectDir, platformData.frameworkPackageName, frameworkPackageNameData);
6467
await this.$packageManager.install(`${platformData.frameworkPackageName}@${frameworkVersion}`, projectData.projectDir, {

npm-shrinkwrap.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"@types/form-data": "2.5.0",
108108
"@types/glob": "^7.1.3",
109109
"@types/inquirer": "7.3.0",
110+
"@types/istextorbinary": "^2.3.0",
110111
"@types/lodash": "4.14.158",
111112
"@types/minimatch": "^3.0.3",
112113
"@types/node": "14.0.27",

0 commit comments

Comments
 (0)