Skip to content

Commit 67a46c9

Browse files
committed
chore: fix pr comments
1 parent 552c9df commit 67a46c9

File tree

5 files changed

+76
-11
lines changed

5 files changed

+76
-11
lines changed

lib/controllers/migrate-controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
4646
{ packageName: "nativescript-dev-sass", isDev: true, replaceWith: "node-sass" },
4747
{ packageName: "nativescript-dev-typescript", isDev: true, replaceWith: "typescript" },
4848
{ packageName: "nativescript-dev-less", isDev: true, shouldRemove: true, warning: "LESS CSS is not supported out of the box. In order to enable it, follow the steps in this feature request: https://github.com/NativeScript/nativescript-dev-webpack/issues/967" },
49-
{ packageName: constants.WEBPACK_PLUGIN_NAME, isDev: true, shouldAddIfMissing: true, verifiedVersion: "1.0.0-rc-2019-07-08-114453-02" },
49+
{ packageName: constants.WEBPACK_PLUGIN_NAME, isDev: true, shouldAddIfMissing: true, verifiedVersion: "1.0.0-rc-2019-07-08-135456-03" },
5050
{ packageName: "nativescript-camera", verifiedVersion: "4.5.0" },
5151
{ packageName: "nativescript-geolocation", verifiedVersion: "5.1.0" },
5252
{ packageName: "nativescript-imagepicker", verifiedVersion: "6.2.0" },
@@ -160,7 +160,7 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
160160

161161
private async cleanUpProject(projectData: IProjectData): Promise<void> {
162162
this.$logger.info("Clean old project artefacts.");
163-
this.$projectDataService.removeNsConfigProperty(projectData.projectDir, "useLegacyWorkflow");
163+
this.$projectDataService.removeNSConfigProperty(projectData.projectDir, "useLegacyWorkflow");
164164
this.$fs.deleteDirectory(path.join(projectData.projectDir, constants.HOOKS_DIR_NAME));
165165
this.$fs.deleteDirectory(path.join(projectData.projectDir, constants.PLATFORMS_DIR_NAME));
166166
this.$fs.deleteDirectory(path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME));

lib/definitions/project.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ interface IProjectDataService {
150150
* @param {string} propertyName The name of the property to be removed.
151151
* @returns {void}
152152
*/
153-
removeNsConfigProperty(projectDir: string, propertyName: string): void;
153+
removeNSConfigProperty(projectDir: string, propertyName: string): void;
154154

155155
/**
156156
* Removes dependency from package.json

lib/services/project-data-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class ProjectDataService implements IProjectDataService {
127127
};
128128
}
129129

130-
public removeNsConfigProperty(projectDir: string, propertyName: string): void {
130+
public removeNSConfigProperty(projectDir: string, propertyName: string): void {
131131
this.$logger.trace(`Removing "${propertyName}" property from nsconfig.`);
132132
this.updateNsConfigValue(projectDir, null, [propertyName]);
133133
this.$logger.trace(`"${propertyName}" property successfully removed.`);
@@ -219,7 +219,7 @@ export class ProjectDataService implements IProjectDataService {
219219
try {
220220
result = <INsConfig>parseJson(nsConfigContent);
221221
} catch (e) {
222-
// invalid nsconfig => null
222+
this.$logger.trace("The `nsconfig` content is not a valid JSON. Parse error: ", e);
223223
}
224224
}
225225

test/services/project-data-service.ts

+70-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { Yok } from "../../lib/common/yok";
22
import { assert } from "chai";
33
import { ProjectDataService } from "../../lib/services/project-data-service";
44
import { LoggerStub, ProjectDataStub } from "../stubs";
5-
import { NATIVESCRIPT_PROPS_INTERNAL_DELIMITER, PACKAGE_JSON_FILE_NAME, AssetConstants, ProjectTypes } from '../../lib/constants';
5+
import { NATIVESCRIPT_PROPS_INTERNAL_DELIMITER, PACKAGE_JSON_FILE_NAME, CONFIG_NS_FILE_NAME, AssetConstants, ProjectTypes } from '../../lib/constants';
66
import { DevicePlatformsConstants } from "../../lib/common/mobile/device-platforms-constants";
77
import { basename, join } from "path";
88
import { FileSystem } from "../../lib/common/file-system";
9+
import { regExpEscape } from "../../lib/common/helpers";
910

1011
const CLIENT_NAME_KEY_IN_PROJECT_FILE = "nativescript";
1112

@@ -41,7 +42,7 @@ const testData: any = [
4142
}
4243
];
4344

44-
const createTestInjector = (readTextData?: string): IInjector => {
45+
const createTestInjector = (packageJsonContent?: string, nsConfigContent?: string): IInjector => {
4546
const testInjector = new Yok();
4647
testInjector.register("projectData", ProjectDataStub);
4748
testInjector.register("staticConfig", {
@@ -55,10 +56,14 @@ const createTestInjector = (readTextData?: string): IInjector => {
5556
},
5657

5758
readText: (filename: string, encoding?: IReadFileOptions | string): string => {
58-
return readTextData;
59+
if (filename.indexOf("package.json") > -1) {
60+
return packageJsonContent;
61+
} else if (filename.indexOf("nsconfig.json") > -1) {
62+
return nsConfigContent;
63+
}
5964
},
6065

61-
exists: (filePath: string): boolean => basename(filePath) === PACKAGE_JSON_FILE_NAME,
66+
exists: (filePath: string): boolean => (basename(filePath) === PACKAGE_JSON_FILE_NAME || basename(filePath) === CONFIG_NS_FILE_NAME),
6267

6368
readJson: (filePath: string): any => null,
6469

@@ -91,7 +96,7 @@ const createTestInjector = (readTextData?: string): IInjector => {
9196
return testInjector;
9297
};
9398

94-
describe("projectDataService", () => {
99+
describe.only("projectDataService", () => {
95100
const generateJsonDataFromTestData = (currentTestData: any, skipNativeScriptKey?: boolean) => {
96101
const props = currentTestData.propertyName.split(NATIVESCRIPT_PROPS_INTERNAL_DELIMITER);
97102
const data: any = {};
@@ -245,6 +250,66 @@ describe("projectDataService", () => {
245250
});
246251
});
247252

253+
describe("removeNSConfigProperty", () => {
254+
255+
const generateExpectedDataFromTestData = (currentTestData: any) => {
256+
const props = currentTestData.propertyName.split(NATIVESCRIPT_PROPS_INTERNAL_DELIMITER);
257+
props.splice(props.length - 1, 1);
258+
259+
const data: any = {};
260+
let currentData: any = data;
261+
262+
_.each(props, (prop) => {
263+
currentData = currentData[prop] = {};
264+
});
265+
266+
return data;
267+
};
268+
269+
_.each(testData, currentTestData => {
270+
271+
it(currentTestData.description, () => {
272+
const testInjector = createTestInjector(null, generateFileContentFromTestData(currentTestData, true));
273+
const fs: IFileSystem = testInjector.resolve("fs");
274+
275+
let dataPassedToWriteJson: any = null;
276+
fs.writeJson = (filename: string, data: any, space?: string, encoding?: string): void => {
277+
dataPassedToWriteJson = data;
278+
};
279+
280+
const projectDataService: IProjectDataService = testInjector.resolve("projectDataService");
281+
const propDelimiterRegExp = new RegExp(regExpEscape(NATIVESCRIPT_PROPS_INTERNAL_DELIMITER), "g");
282+
const propertySelector = currentTestData.propertyName.replace(propDelimiterRegExp, ".");
283+
projectDataService.removeNSConfigProperty("projectDir", propertySelector);
284+
285+
assert.deepEqual(dataPassedToWriteJson, generateExpectedDataFromTestData(currentTestData));
286+
});
287+
288+
});
289+
290+
it("removes only the selected property", () => {
291+
const initialData: any = {};
292+
initialData[CLIENT_NAME_KEY_IN_PROJECT_FILE] = {
293+
"root": {
294+
"id": "1",
295+
"constantItem": "myValue"
296+
}
297+
};
298+
299+
const testInjector = createTestInjector(JSON.stringify(initialData));
300+
const fs: IFileSystem = testInjector.resolve("fs");
301+
302+
let dataPassedToWriteJson: any = null;
303+
fs.writeJson = (filename: string, data: any, space?: string, encoding?: string): void => {
304+
dataPassedToWriteJson = data;
305+
};
306+
307+
const projectDataService: IProjectDataService = testInjector.resolve("projectDataService");
308+
projectDataService.removeNSProperty("projectDir", getPropertyName(["root", "id"]));
309+
assert.deepEqual(dataPassedToWriteJson, { nativescript: { root: { constantItem: "myValue" } } });
310+
});
311+
});
312+
248313
describe("removeDependency", () => {
249314
it("removes specified dependency from project file", () => {
250315
const currentTestData = {

test/stubs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ export class ProjectDataService implements IProjectDataService {
506506

507507
removeNSProperty(propertyName: string): void { }
508508

509-
removeNsConfigProperty(projectDir: string, propertyName: string): void { }
509+
removeNSConfigProperty(projectDir: string, propertyName: string): void { }
510510

511511
removeDependency(dependencyName: string): void { }
512512

0 commit comments

Comments
 (0)