Skip to content

Commit 44bab5d

Browse files
author
Fatme
authored
Merge pull request #3950 from NativeScript/fatme/remove-project-data
refactor: remove projectData from PreviewAppPluginsService in order to work from Sidekick
2 parents 19bf215 + c1b6a3e commit 44bab5d

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

lib/definitions/plugins.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface IPluginsService {
1515
validate(platformData: IPlatformData, projectData: IProjectData): Promise<void>;
1616
preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise<void>;
1717
convertToPluginData(cacheData: any, projectDir: string): IPluginData;
18-
isNativeScriptPlugin(pluginName: string, projectData: IProjectData): boolean;
18+
isNativeScriptPlugin(pluginPackageJsonPath: string): boolean;
1919
}
2020

2121
interface IPackageJsonDepedenciesResult {

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
}

lib/services/plugins-service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as path from "path";
22
import * as shelljs from "shelljs";
33
import * as semver from "semver";
44
import * as constants from "../constants";
5-
import { NODE_MODULES_DIR_NAME } from "../common/constants";
65

76
export class PluginsService implements IPluginsService {
87
private static INSTALL_COMMAND_NAME = "install";
@@ -208,8 +207,7 @@ export class PluginsService implements IPluginsService {
208207
};
209208
}
210209

211-
public isNativeScriptPlugin(pluginName: string, projectData: IProjectData): boolean {
212-
const pluginPackageJsonPath = path.join(projectData.projectDir, NODE_MODULES_DIR_NAME, pluginName, "package.json");
210+
public isNativeScriptPlugin(pluginPackageJsonPath: string): boolean {
213211
const pluginPackageJsonContent = this.$fs.readJson(pluginPackageJsonPath);
214212
return pluginPackageJsonContent && pluginPackageJsonContent.nativescript;
215213
}

lib/tools/node-modules/node-modules-dest-copy.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export class TnsModulesCopy {
1111
constructor(
1212
private outputRoot: string,
1313
private $options: IOptions,
14-
private $fs: IFileSystem
14+
private $fs: IFileSystem,
15+
private $pluginsService: IPluginsService
1516
) {
1617
}
1718

@@ -67,9 +68,7 @@ export class TnsModulesCopy {
6768
const pathToDependency = path.join(dependenciesFolder, d);
6869
const pathToPackageJson = path.join(pathToDependency, constants.PACKAGE_JSON_FILE_NAME);
6970

70-
// TODO: Reuse pluginsService.isNativeScriptPlugin after making it work with full path.
71-
const pluginPackageJsonContent = this.$fs.readJson(pathToPackageJson);
72-
if (pluginPackageJsonContent && pluginPackageJsonContent.nativescript) {
71+
if (this.$pluginsService.isNativeScriptPlugin(pathToPackageJson)) {
7372
this.$fs.deleteDirectory(path.join(pathToDependency, constants.PLATFORMS_DIR_NAME));
7473
}
7574

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

Lines changed: 1 addition & 4 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
}
@@ -112,7 +109,7 @@ describe("previewAppPluginsService", () => {
112109
const originalGetLocalPlugins = (<any>previewAppPluginsService).getLocalPlugins;
113110
(<any>previewAppPluginsService).getLocalPlugins = () => {
114111
isGetLocalPluginsCalled = true;
115-
return originalGetLocalPlugins.apply(previewAppPluginsService);
112+
return originalGetLocalPlugins.apply(previewAppPluginsService, [projectDir]);
116113
};
117114

118115
const previewLiveSyncData = createPreviewLiveSyncData({ bundle: false });

0 commit comments

Comments
 (0)