Skip to content

Commit 7485d03

Browse files
committed
refactor: remove projectData from dependencies of PreviewAppPluginsService in order to work from Sidekick
1 parent b59e85a commit 7485d03

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ import * as util from "util";
44
import { Device } from "nativescript-preview-sdk";
55
import { PluginComparisonMessages } from "./preview-app-constants";
66
import { NODE_MODULES_DIR_NAME } from "../../../common/constants";
7-
import { PLATFORMS_DIR_NAME } from "../../../constants";
7+
import { PLATFORMS_DIR_NAME, PACKAGE_JSON_FILE_NAME } from "../../../constants";
88

99
export class PreviewAppPluginsService implements IPreviewAppPluginsService {
1010
private previewAppVersionWarnings: IDictionary<string[]> = {};
1111

1212
constructor(private $fs: IFileSystem,
1313
private $logger: ILogger,
14-
private $pluginsService: IPluginsService,
15-
private $projectData: IProjectData) { }
14+
private $pluginsService: IPluginsService) { }
1615

1716
public async comparePluginsOnDevice(data: IPreviewAppLiveSyncData, device: Device): Promise<void> {
1817
if (!this.previewAppVersionWarnings[device.previewAppVersion]) {
1918
const devicePlugins = this.getDevicePlugins(device);
20-
const localPlugins = this.getLocalPlugins();
19+
const localPlugins = this.getLocalPlugins(data.projectDir);
2120
const warnings = _.keys(localPlugins)
2221
.map(localPlugin => {
2322
const localPluginVersion = localPlugins[localPlugin];
@@ -55,8 +54,8 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
5554
}
5655
}
5756

58-
private getLocalPlugins(): IStringDictionary {
59-
const projectFilePath = path.join(this.$projectData.projectDir, "package.json");
57+
private getLocalPlugins(projectDir: string): IStringDictionary {
58+
const projectFilePath = path.join(projectDir, PACKAGE_JSON_FILE_NAME);
6059
try {
6160
return this.$fs.readJson(projectFilePath).dependencies;
6261
} catch (err) {
@@ -66,7 +65,7 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
6665
}
6766

6867
private getWarningForPlugin(data: IPreviewAppLiveSyncData, localPlugin: string, localPluginVersion: string, devicePluginVersion: string, device: Device): string {
69-
if (data && data.appFilesUpdaterOptions && data.appFilesUpdaterOptions.bundle && this.isNativeScriptPluginWithoutNativeCode(localPlugin, device.platform)) {
68+
if (data && data.appFilesUpdaterOptions && data.appFilesUpdaterOptions.bundle && this.isNativeScriptPluginWithoutNativeCode(localPlugin, device.platform, data.projectDir)) {
7069
return null;
7170
}
7271

@@ -92,12 +91,13 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
9291
return util.format(PluginComparisonMessages.PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP, localPlugin, deviceId);
9392
}
9493

95-
private isNativeScriptPluginWithoutNativeCode(localPlugin: string, platform: string): boolean {
96-
return this.$pluginsService.isNativeScriptPlugin(localPlugin, this.$projectData) && !this.hasNativeCode(localPlugin, platform);
94+
private isNativeScriptPluginWithoutNativeCode(localPlugin: string, platform: string, projectDir: string): boolean {
95+
const pluginPackageJsonPath = path.join(projectDir, NODE_MODULES_DIR_NAME, localPlugin, PACKAGE_JSON_FILE_NAME);
96+
return this.$pluginsService.isNativeScriptPlugin(pluginPackageJsonPath) && !this.hasNativeCode(localPlugin, platform, projectDir);
9797
}
9898

99-
private hasNativeCode(localPlugin: string, platform: string): boolean {
100-
const nativeFolderPath = path.join(this.$projectData.projectDir, NODE_MODULES_DIR_NAME, localPlugin, PLATFORMS_DIR_NAME, platform.toLowerCase());
99+
private hasNativeCode(localPlugin: string, platform: string, projectDir: string): boolean {
100+
const nativeFolderPath = path.join(projectDir, NODE_MODULES_DIR_NAME, localPlugin, PLATFORMS_DIR_NAME, platform.toLowerCase());
101101
return this.$fs.exists(nativeFolderPath) && !this.$fs.isEmptyDir(nativeFolderPath);
102102
}
103103
}

test/services/playground/preview-app-plugins-service.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ function createTestInjector(localPlugins: IStringDictionary, options?: { isNativ
4343
trace: () => ({}),
4444
warn: (message: string) => warnParams.push(message)
4545
});
46-
injector.register("projectData", {
47-
projectDir
48-
});
4946
injector.register("previewAppPluginsService", PreviewAppPluginsService);
5047
return injector;
5148
}

0 commit comments

Comments
 (0)