Skip to content

Commit a952a47

Browse files
committed
fix: change the logic so useLegacyWorkflow name is used from nsconfig file
1 parent 08f2a8e commit a952a47

File tree

5 files changed

+93
-69
lines changed

5 files changed

+93
-69
lines changed

lib/definitions/project.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ interface INsConfig {
7474
appPath?: string;
7575
appResourcesPath?: string;
7676
shared?: boolean;
77-
isHmrEnabledByDefault?: boolean;
77+
useLegacyWorkflow?: boolean;
7878
}
7979

8080
interface IProjectData extends ICreateProjectData {
@@ -103,7 +103,7 @@ interface IProjectData extends ICreateProjectData {
103103
/**
104104
* Defines if the project has hmr enabled by default
105105
*/
106-
isHmrEnabledByDefault: boolean;
106+
useLegacyWorkflow: boolean;
107107

108108
/**
109109
* Initializes project data with the given project directory. If none supplied defaults to --path option or cwd.

lib/options.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,25 @@ export class Options {
2828

2929
// HACK: temporary solution for 5.3.0 release (until the webpack only feature)
3030
const parsed = require("yargs-parser")(process.argv.slice(2), { 'boolean-negation': false });
31+
const noBundle = parsed && (parsed.bundle === false || parsed.bundle === 'false');
32+
if (noBundle && this.argv.hmr) {
33+
this.$errors.failWithoutHelp("The options --no-bundle and --hmr cannot be used simultaneously.");
34+
}
35+
36+
if (projectData && projectData.useLegacyWorkflow === false) {
37+
this.argv.bundle = this.argv.bundle !== undefined ? this.argv.bundle : "webpack";
38+
this.argv.hmr = !this.argv.release;
39+
}
40+
3141
// --no-hmr -> hmr: false or --hmr false -> hmr: 'false'
3242
const noHmr = parsed && (parsed.hmr === false || parsed.hmr === 'false');
3343
if (noHmr) {
3444
this.argv.hmr = false;
35-
return;
3645
}
3746

38-
if (projectData && projectData.isHmrEnabledByDefault) {
39-
this.argv.bundle = this.argv.bundle !== undefined ? this.argv.bundle : "webpack";
40-
this.argv.hmr = !this.argv.release;
47+
if (noBundle) {
48+
this.argv.bundle = undefined;
49+
this.argv.hmr = false;
4150
}
4251
}
4352

lib/project-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class ProjectData implements IProjectData {
6161
public buildXcconfigPath: string;
6262
public podfilePath: string;
6363
public isShared: boolean;
64-
public isHmrEnabledByDefault: boolean;
64+
public useLegacyWorkflow: boolean;
6565

6666
constructor(private $fs: IFileSystem,
6767
private $errors: IErrors,
@@ -136,7 +136,7 @@ export class ProjectData implements IProjectData {
136136
this.buildXcconfigPath = path.join(this.appResourcesDirectoryPath, this.$devicePlatformsConstants.iOS, constants.BUILD_XCCONFIG_FILE_NAME);
137137
this.podfilePath = path.join(this.appResourcesDirectoryPath, this.$devicePlatformsConstants.iOS, constants.PODFILE_NAME);
138138
this.isShared = !!(this.nsConfig && this.nsConfig.shared);
139-
this.isHmrEnabledByDefault = !!(this.nsConfig && this.nsConfig.isHmrEnabledByDefault);
139+
this.useLegacyWorkflow = this.nsConfig && this.nsConfig.useLegacyWorkflow;
140140
return;
141141
}
142142

test/options.ts

Lines changed: 75 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -263,93 +263,108 @@ describe("options", () => {
263263
});
264264

265265
describe("setupOptions", () => {
266-
const testsWithNoHmrByDefault = [
266+
const testCases = [
267267
{
268-
name: "no nsconfig.json ",
269-
isHmrEnabledByDefault: false,
268+
name: "no options are provided",
270269
args: [],
271-
expectedHmr: false,
272-
expectedBundle: false
270+
data: [
271+
{ useLegacyWorkflow: undefined, expectedHmr: false, expectedBundle: false },
272+
{ useLegacyWorkflow: false, expectedHmr: true, expectedBundle: true },
273+
{ useLegacyWorkflow: true, expectedHmr: false, expectedBundle: false }
274+
]
273275
},
274276
{
275-
name: "no nsconfig.json and --hmr is provided",
276-
isHmrEnabledByDefault: false,
277+
name: " --hmr is provided",
277278
args: ["--hmr"],
278-
expectedHmr: true,
279-
expectedBundle: true
279+
data: [
280+
{ useLegacyWorkflow: undefined, expectedHmr: true, expectedBundle: true },
281+
{ useLegacyWorkflow: false, expectedHmr: true, expectedBundle: true },
282+
{ useLegacyWorkflow: true, expectedHmr: true, expectedBundle: true }
283+
]
280284
},
281285
{
282-
name: "no nsconfig.json and --no-hmr is provided",
283-
isHmrEnabledByDefault: false,
286+
name: " --no-hmr is provided",
284287
args: ["--no-hmr"],
285-
expectedHmr: false,
286-
expectedBundle: false
288+
data: [
289+
{ useLegacyWorkflow: undefined, expectedHmr: false, expectedBundle: false },
290+
{ useLegacyWorkflow: false, expectedHmr: false, expectedBundle: true },
291+
{ useLegacyWorkflow: true, expectedHmr: false, expectedBundle: false }
292+
]
287293
},
288294
{
289-
name: "no nsconfig.json and --release is provided",
290-
isHmrEnabledByDefault: false,
291-
args: ["--release"],
292-
expectedHmr: false,
293-
expectedBundle: false
294-
},
295-
{
296-
name: "no nsconfig.json and --bundle is provided",
297-
isHmrEnabledByDefault: false,
295+
name: " --bundle is provided",
298296
args: ["--bundle"],
299-
expectedHmr: false,
300-
expectedBundle: true
301-
}
302-
];
303-
const testsWithHmrByDefault = <any>[
304-
{
305-
name: "has nsconfig.json",
306-
isHmrEnabledByDefault: true,
307-
expectedHmr: true,
308-
expectedBundle: true
297+
data: [
298+
{ useLegacyWorkflow: undefined, expectedHmr: false, expectedBundle: true },
299+
{ useLegacyWorkflow: false, expectedHmr: true, expectedBundle: true },
300+
{ useLegacyWorkflow: true, expectedHmr: false, expectedBundle: true }
301+
]
309302
},
310303
{
311-
name: "has nsconfig.json and --hmr is provided",
312-
isHmrEnabledByDefault: true,
313-
args: ["--hmr"],
314-
expectedHmr: true,
315-
expectedBundle: true
304+
name: " --no-bundle is provided",
305+
args: ["--no-bundle"],
306+
data: [
307+
{ useLegacyWorkflow: undefined, expectedHmr: false, expectedBundle: false },
308+
{ useLegacyWorkflow: false, expectedHmr: false, expectedBundle: false },
309+
{ useLegacyWorkflow: true, expectedHmr: false, expectedBundle: false }
310+
]
316311
},
317312
{
318-
name: "has nsconfig.json and --no-hmr is provided",
319-
isHmrEnabledByDefault: true,
320-
args: ["--no-hmr"],
321-
expectedHmr: false,
322-
expectedBundle: false
323-
},
324-
{
325-
name: "has nsconfig.json and --release is provided",
326-
isHmrEnabledByDefault: true,
313+
name: " --release is provided",
327314
args: ["--release"],
328-
expectedHmr: false,
329-
expectedBundle: true
315+
data: [
316+
{ useLegacyWorkflow: undefined, expectedHmr: false, expectedBundle: false },
317+
{ useLegacyWorkflow: false, expectedHmr: false, expectedBundle: true },
318+
{ useLegacyWorkflow: true, expectedHmr: false, expectedBundle: false }
319+
]
320+
}
321+
];
322+
323+
_.each([undefined, false, true], useLegacyWorkflow => {
324+
_.each(testCases, testCase => {
325+
it(`should pass correctly when ${testCase.name} and useLegacyWorkflow is ${useLegacyWorkflow}`, () => {
326+
(testCase.args || []).forEach(arg => process.argv.push(arg));
327+
328+
const options = createOptions(testInjector);
329+
const projectData = <IProjectData>{ useLegacyWorkflow };
330+
options.setupOptions(projectData);
331+
332+
(testCase.args || []).forEach(arg => process.argv.pop());
333+
334+
const data = testCase.data.find(item => item.useLegacyWorkflow === useLegacyWorkflow);
335+
336+
assert.equal(!!options.argv.hmr, !!data.expectedHmr);
337+
assert.equal(!!options.argv.bundle, !!data.expectedBundle);
338+
});
339+
});
340+
});
341+
342+
const testCasesExpectingToThrow = [
343+
{
344+
name: "--release --hmr",
345+
args: ["--release", "--hmr"],
346+
expectedError: "The options --release and --hmr cannot be used simultaneously."
330347
},
331348
{
332-
name: "has nsconfig.json and --bundle is provided",
333-
isHmrEnabledByDefault: true,
334-
args: ["--bundle"],
335-
expectedHmr: true,
336-
expectedBundle: true
349+
name: "--no-bundle --hmr",
350+
args: ["--no-bundle", "--hmr"],
351+
expectedError: "The options --no-bundle and --hmr cannot be used simultaneously."
337352
}
338353
];
339-
const testCases = testsWithNoHmrByDefault.concat(testsWithHmrByDefault);
340354

341-
_.each(testCases, testCase => {
342-
it(`should pass correctly when ${testCase.name}`, () => {
355+
_.each(testCasesExpectingToThrow, testCase => {
356+
it(`should fail when ${testCase.name}`, () => {
357+
let actualError = null;
358+
const errors = testInjector.resolve("errors");
359+
errors.failWithoutHelp = (error: string) => actualError = error;
343360
(testCase.args || []).forEach(arg => process.argv.push(arg));
344361

345362
const options = createOptions(testInjector);
346-
const projectData = <IProjectData>{ isHmrEnabledByDefault: testCase.isHmrEnabledByDefault };
347-
options.setupOptions(projectData);
363+
options.setupOptions(null);
348364

349365
(testCase.args || []).forEach(arg => process.argv.pop());
350366

351-
assert.equal(!!options.argv.hmr, !!testCase.expectedHmr);
352-
assert.equal(!!options.argv.bundle, !!testCase.expectedBundle);
367+
assert.deepEqual(actualError, testCase.expectedError);
353368
});
354369
});
355370
});

test/stubs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export class ProjectDataStub implements IProjectData {
331331
public buildXcconfigPath: string;
332332
public podfilePath: string;
333333
public isShared: boolean;
334-
public isHmrEnabledByDefault: boolean;
334+
public useLegacyWorkflow: boolean;
335335

336336
public initializeProjectData(projectDir?: string): void {
337337
this.projectDir = this.projectDir || projectDir;

0 commit comments

Comments
 (0)