Skip to content

Commit 7b43cc2

Browse files
committed
fix(migrate): remove useLegacyWorkflow property from nsconfig as its not respected anymore
1 parent 3c2cdf7 commit 7b43cc2

File tree

6 files changed

+63
-85
lines changed

6 files changed

+63
-85
lines changed

lib/controllers/migrate-controller.ts

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +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");
163164
this.$fs.deleteDirectory(path.join(projectData.projectDir, constants.HOOKS_DIR_NAME));
164165
this.$fs.deleteDirectory(path.join(projectData.projectDir, constants.PLATFORMS_DIR_NAME));
165166
this.$fs.deleteDirectory(path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME));

lib/definitions/project.d.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ interface INsConfig {
7474
appPath?: string;
7575
appResourcesPath?: string;
7676
shared?: boolean;
77-
useLegacyWorkflow?: boolean;
7877
previewAppSchema?: string;
7978
}
8079

@@ -101,11 +100,6 @@ interface IProjectData extends ICreateProjectData {
101100
*/
102101
isShared: boolean;
103102

104-
/**
105-
* Defines if the project has hmr enabled by default
106-
*/
107-
useLegacyWorkflow: boolean;
108-
109103
/**
110104
* Defines the schema for the preview app
111105
*/
@@ -150,6 +144,14 @@ interface IProjectDataService {
150144
*/
151145
removeNSProperty(projectDir: string, propertyName: string): void;
152146

147+
/**
148+
* Removes a property from `nsconfig.json`.
149+
* @param {string} projectDir The project directory - the place where the `nsconfig.json` is located.
150+
* @param {string} propertyName The name of the property to be removed.
151+
* @returns {void}
152+
*/
153+
removeNsConfigProperty(projectDir: string, propertyName: string): void;
154+
153155
/**
154156
* Removes dependency from package.json
155157
* @param {string} projectDir The project directory - the place where the root package.json is located.
@@ -192,12 +194,12 @@ interface IProjectDataService {
192194
*/
193195
getAppExecutableFiles(projectDir: string): string[];
194196

195-
/**
196-
* Returns a value from `nativescript` key in project's package.json.
197-
* @param {string} jsonData The project directory - the place where the root package.json is located.
198-
* @param {string} propertyName The name of the property to be checked in `nativescript` key.
199-
* @returns {any} The value of the property.
200-
*/
197+
/**
198+
* Returns a value from `nativescript` key in project's package.json.
199+
* @param {string} jsonData The project directory - the place where the root package.json is located.
200+
* @param {string} propertyName The name of the property to be checked in `nativescript` key.
201+
* @returns {any} The value of the property.
202+
*/
201203
getNSValueFromContent(jsonData: Object, propertyName: string): any;
202204
}
203205

@@ -496,7 +498,7 @@ interface IRemoveExtensionsOptions {
496498
pbxProjPath: string
497499
}
498500

499-
interface IRemoveWatchAppOptions extends IRemoveExtensionsOptions{}
501+
interface IRemoveWatchAppOptions extends IRemoveExtensionsOptions { }
500502

501503
interface IRubyFunction {
502504
functionName: string;

lib/project-data.ts

-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export class ProjectData implements IProjectData {
6161
public buildXcconfigPath: string;
6262
public podfilePath: string;
6363
public isShared: boolean;
64-
public useLegacyWorkflow: boolean;
6564
public previewAppSchema: string;
6665

6766
constructor(private $fs: IFileSystem,
@@ -137,7 +136,6 @@ export class ProjectData implements IProjectData {
137136
this.buildXcconfigPath = path.join(this.appResourcesDirectoryPath, this.$devicePlatformsConstants.iOS, constants.BUILD_XCCONFIG_FILE_NAME);
138137
this.podfilePath = path.join(this.appResourcesDirectoryPath, this.$devicePlatformsConstants.iOS, constants.PODFILE_NAME);
139138
this.isShared = !!(this.nsConfig && this.nsConfig.shared);
140-
this.useLegacyWorkflow = this.nsConfig && this.nsConfig.useLegacyWorkflow;
141139
this.previewAppSchema = this.nsConfig && this.nsConfig.previewAppSchema;
142140
return;
143141
}

lib/services/project-data-service.ts

+46-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as path from "path";
22
import { ProjectData } from "../project-data";
3+
import * as constants from "../constants";
4+
import { parseJson } from "../common/helpers";
35
import { exported } from "../common/decorators";
46
import {
57
NATIVESCRIPT_PROPS_INTERNAL_DELIMITER,
@@ -125,6 +127,12 @@ export class ProjectDataService implements IProjectDataService {
125127
};
126128
}
127129

130+
public removeNsConfigProperty(projectDir: string, propertyName: string): void {
131+
this.$logger.trace(`Removing "${propertyName}" property from nsconfig.`);
132+
this.updateNsConfigValue(projectDir, null, [propertyName]);
133+
this.$logger.trace(`"${propertyName}" property successfully removed.`);
134+
}
135+
128136
@exported("projectDataService")
129137
public async getAndroidAssetsStructure(opts: IProjectDir): Promise<IAssetGroup> {
130138
// TODO: Use image-size package to get the width and height of an image.
@@ -180,6 +188,43 @@ export class ProjectDataService implements IProjectDataService {
180188

181189
return files;
182190
}
191+
private refreshProjectData(projectDir: string) {
192+
if (this.projectDataCache[projectDir]) {
193+
this.projectDataCache[projectDir].initializeProjectData(projectDir);
194+
}
195+
}
196+
197+
private updateNsConfigValue(projectDir: string, updateObject?: INsConfig, propertiesToRemove?: string[]): void {
198+
const nsConfigPath = path.join(projectDir, constants.CONFIG_NS_FILE_NAME);
199+
const currentNsConfig = this.getNsConfig(nsConfigPath);
200+
let newNsConfig = currentNsConfig;
201+
if (updateObject) {
202+
newNsConfig = _.assign(newNsConfig || this.getNsConfigDefaultObject(), updateObject);
203+
}
204+
205+
if (newNsConfig && propertiesToRemove && propertiesToRemove.length) {
206+
newNsConfig = _.omit(newNsConfig, propertiesToRemove);
207+
}
208+
209+
if (newNsConfig) {
210+
this.$fs.writeJson(nsConfigPath, newNsConfig);
211+
this.refreshProjectData(projectDir);
212+
}
213+
}
214+
215+
private getNsConfig(nsConfigPath: string): INsConfig {
216+
let result: INsConfig = null;
217+
if (this.$fs.exists(nsConfigPath)) {
218+
const nsConfigContent = this.$fs.readText(nsConfigPath);
219+
try {
220+
result = <INsConfig>parseJson(nsConfigContent);
221+
} catch (e) {
222+
// invalid nsconfig => null
223+
}
224+
}
225+
226+
return result;
227+
}
183228

184229
private getImageDefinitions(): IImageDefinitionsStructure {
185230
const pathToImageDefinitions = path.join(__dirname, "..", "..", CLI_RESOURCES_DIR_NAME, AssetConstants.assets, AssetConstants.imageDefinitionsFileName);
@@ -334,7 +379,7 @@ export class ProjectDataService implements IProjectDataService {
334379
}
335380

336381
private getNsConfigDefaultObject(data?: Object): INsConfig {
337-
const config: INsConfig = { useLegacyWorkflow: false };
382+
const config: INsConfig = {};
338383
Object.assign(config, data);
339384

340385
return config;

test/options.ts

-67
Original file line numberDiff line numberDiff line change
@@ -263,73 +263,6 @@ describe("options", () => {
263263
});
264264

265265
describe("setupOptions", () => {
266-
const testCases = [
267-
{
268-
name: "no options are provided",
269-
args: [],
270-
data: [
271-
{ useLegacyWorkflow: undefined, expectedHmr: true, expectedBundle: true },
272-
{ useLegacyWorkflow: false, expectedHmr: true, expectedBundle: true },
273-
{ useLegacyWorkflow: true, expectedHmr: true, expectedBundle: true }
274-
]
275-
},
276-
{
277-
name: " --hmr is provided",
278-
args: ["--hmr"],
279-
data: [
280-
{ useLegacyWorkflow: undefined, expectedHmr: true, expectedBundle: true },
281-
{ useLegacyWorkflow: false, expectedHmr: true, expectedBundle: true },
282-
{ useLegacyWorkflow: true, expectedHmr: true, expectedBundle: true }
283-
]
284-
},
285-
{
286-
name: " --no-hmr is provided",
287-
args: ["--no-hmr"],
288-
data: [
289-
{ useLegacyWorkflow: undefined, expectedHmr: false, expectedBundle: true },
290-
{ useLegacyWorkflow: false, expectedHmr: false, expectedBundle: true },
291-
{ useLegacyWorkflow: true, expectedHmr: false, expectedBundle: true }
292-
]
293-
},
294-
{
295-
name: " --bundle is provided",
296-
args: ["--bundle"],
297-
data: [
298-
{ useLegacyWorkflow: undefined, expectedHmr: true, expectedBundle: true },
299-
{ useLegacyWorkflow: false, expectedHmr: true, expectedBundle: true },
300-
{ useLegacyWorkflow: true, expectedHmr: true, expectedBundle: true }
301-
]
302-
},
303-
{
304-
name: " --release is provided",
305-
args: ["--release"],
306-
data: [
307-
{ useLegacyWorkflow: undefined, expectedHmr: false, expectedBundle: true },
308-
{ useLegacyWorkflow: false, expectedHmr: false, expectedBundle: true },
309-
{ useLegacyWorkflow: true, expectedHmr: false, expectedBundle: true }
310-
]
311-
}
312-
];
313-
314-
_.each([undefined, false, true], useLegacyWorkflow => {
315-
_.each(testCases, testCase => {
316-
it(`should pass correctly when ${testCase.name} and useLegacyWorkflow is ${useLegacyWorkflow}`, () => {
317-
(testCase.args || []).forEach(arg => process.argv.push(arg));
318-
319-
const options: any = createOptions(testInjector);
320-
const projectData = <IProjectData>{ useLegacyWorkflow };
321-
options.setupOptions(projectData);
322-
323-
(testCase.args || []).forEach(arg => process.argv.pop());
324-
325-
const data = testCase.data.find(item => item.useLegacyWorkflow === useLegacyWorkflow);
326-
327-
assert.equal(!!options.argv.hmr, !!data.expectedHmr);
328-
assert.equal(!!options.argv.bundle, !!data.expectedBundle);
329-
});
330-
});
331-
});
332-
333266
const testCasesExpectingToThrow = [
334267
{
335268
name: "--release --hmr",

test/stubs.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ export class ProjectDataStub implements IProjectData {
327327
public buildXcconfigPath: string;
328328
public podfilePath: string;
329329
public isShared: boolean;
330-
public useLegacyWorkflow: boolean;
331330
public previewAppSchema: string;
332331

333332
public initializeProjectData(projectDir?: string): void {
@@ -532,7 +531,7 @@ export class ProjectDataService implements IProjectDataService {
532531
return [];
533532
}
534533

535-
getNSValueFromContent(): any {}
534+
getNSValueFromContent(): any { }
536535
}
537536

538537
export class ProjectHelperStub implements IProjectHelper {

0 commit comments

Comments
 (0)