Skip to content

Commit ef0d2cf

Browse files
NathanWalkerrigor789
authored andcommitted
chore: unit tests
1 parent 85f71b7 commit ef0d2cf

File tree

10 files changed

+471
-38
lines changed

10 files changed

+471
-38
lines changed

lib/definitions/pacote-service.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as pacote from "pacote";
21
import * as tar from "tar";
32
import { IProxySettingsBase } from "../common/declarations";
43

lib/definitions/pacote.d.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
5656
let smc: any = null;
5757
if (sourceMapRaw && sourceMapRaw.sourcemap) {
5858
const sourceMap = sourceMapRaw.sourcemap;
59-
smc = new sourcemap.SourceMapConsumer(sourceMap);
59+
smc = await sourcemap.SourceMapConsumer.with(sourceMap, filePath, (smc) => {
60+
return smc;
61+
});
6062
}
6163

6264
this.cache[filePath] = smc;

lib/services/pacote-service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as pacote from "pacote";
22
import * as tar from "tar";
33
import * as path from "path";
4+
import { PassThrough } from 'stream';
45
import * as _ from 'lodash';
56
import { cache } from "../common/decorators";
67
import { INpmConfigService, INodePackageManager } from "../declarations";
@@ -49,18 +50,20 @@ export class PacoteService implements IPacoteService {
4950
packageName = this.getRealPackageName(packageName);
5051
const pacoteOptions = await this.getPacoteBaseOptions();
5152

52-
return new Promise<void>((resolve, reject) => {
53+
return new Promise<void>(async (resolve, reject) => {
5354
this.$logger.trace(`Calling pacoteService.extractPackage for packageName: '${packageName}', destinationDir: '${destinationDirectory}' and options: ${options}`);
5455

55-
const source = pacote.tarball.stream(packageName, pacoteOptions);
56-
source.on("error", (err: Error) => {
56+
const source = await pacote.tarball(packageName, pacoteOptions).catch((err: Error) => {
5757
this.$logger.trace(`Error in source while trying to extract stream from ${packageName}. Error is ${err}`);
5858
reject(err);
5959
});
6060

6161
this.$logger.trace(`Creating extract tar stream with options: ${JSON.stringify(extractOptions, null, 2)}`);
62-
const destination = tar.x(extractOptions);
63-
source.pipe(destination);
62+
const destination = tar.x(extractOptions);
63+
// Initiate the source
64+
const sourceStream = new PassThrough();
65+
sourceStream.end(source);
66+
sourceStream.pipe(destination);
6467

6568
destination.on("error", (err: Error) => {
6669
this.$logger.trace(`Error in destination while trying to extract stream from ${packageName}. Error is ${err}`);

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

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

910
export class AddPlatformService implements IAddPlatformService {
1011
constructor(
1112
private $fs: IFileSystem,
1213
private $pacoteService: IPacoteService,
13-
private $projectDataService: IProjectDataService,
14+
// private $projectDataService: IProjectDataService,
15+
private $options: IOptions,
16+
private $packageManager: IPackageManager,
1417
private $terminalSpinnerService: ITerminalSpinnerService,
1518
private $analyticsService: IAnalyticsService,
1619
private $tempService: ITempService
@@ -20,15 +23,27 @@ export class AddPlatformService implements IAddPlatformService {
2023
const spinner = this.$terminalSpinnerService.createSpinner();
2124

2225
try {
23-
spinner.start();
26+
spinner.start();
2427

25-
const frameworkDirPath = await this.extractPackage(packageToInstall);
26-
const frameworkPackageJsonContent = this.$fs.readJson(path.join(frameworkDirPath, "..", "package.json"));
27-
const frameworkVersion = frameworkPackageJsonContent.version;
28-
29-
await this.setPlatformVersion(platformData, projectData, frameworkVersion);
30-
await this.trackPlatformVersion(frameworkVersion, platformData);
28+
let frameworkDirPath: string;
29+
let frameworkVersion: string;
30+
if (this.$options.frameworkPath) {
31+
frameworkDirPath = await this.extractPackage(packageToInstall);
32+
const frameworkPackageJsonContent = this.$fs.readJson(path.join(frameworkDirPath, "..", "package.json"));
33+
frameworkVersion = frameworkPackageJsonContent.version;
3134

35+
await this.setPlatformVersion(platformData, projectData, frameworkVersion);
36+
await this.trackPlatformVersion(frameworkVersion, platformData);
37+
} else {
38+
const [ name, version ] = packageToInstall.split('@');
39+
frameworkDirPath = path.join(projectData.projectDir, 'node_modules', name, PROJECT_FRAMEWORK_FOLDER_NAME);
40+
frameworkVersion = version;
41+
if (!projectData.devDependencies[name]) {
42+
await this.setPlatformVersion(platformData, projectData, version);
43+
}
44+
await this.trackPlatformVersion(version, platformData);
45+
}
46+
3247
if (!nativePrepare || !nativePrepare.skipNativePrepare) {
3348
await this.addNativePlatform(platformData, projectData, frameworkDirPath, frameworkVersion);
3449
}
@@ -44,8 +59,14 @@ export class AddPlatformService implements IAddPlatformService {
4459
}
4560

4661
public async setPlatformVersion(platformData: IPlatformData, projectData: IProjectData, frameworkVersion: string): Promise<void> {
47-
const frameworkPackageNameData = { version: frameworkVersion };
48-
this.$projectDataService.setNSValue(projectData.projectDir, platformData.frameworkPackageName, frameworkPackageNameData);
62+
// const frameworkPackageNameData = { version: frameworkVersion };
63+
// this.$projectDataService.setNSValue(projectData.projectDir, platformData.frameworkPackageName, frameworkPackageNameData);
64+
await this.$packageManager.install(`${platformData.frameworkPackageName}@${frameworkVersion}`, projectData.projectDir, {
65+
'save-dev': true,
66+
disableNpmInstall: true,
67+
frameworkPath: null,
68+
ignoreScripts: false
69+
});
4970
}
5071

5172
private async extractPackage(pkg: string): Promise<string> {

lib/services/project-data-service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ export class ProjectDataService implements IProjectDataService {
412412
}
413413

414414
public getRuntimePackage(projectDir: string, platform: constants.SupportedPlatform): IBasePluginData {
415-
console.log('projectdataservice getRuntimePackage platform:', platform)
416415
return this.$pluginsService.getDependenciesFromPackageJson(projectDir).devDependencies.find(d => {
417416
if (platform === constants.PlatformTypes.ios) {
418417
return [constants.SCOPED_IOS_RUNTIME_NAME, constants.TNS_IOS_RUNTIME_NAME].includes(d.name);

0 commit comments

Comments
 (0)