Skip to content

Commit b9b57a1

Browse files
Fail if --bundle is specified but no bundler (#3246)
* Fail if --bundle is specified but no bundler * Make bundle option string * Document --bundle option * Change default * Update submodule ref
1 parent cc835bd commit b9b57a1

18 files changed

+68
-24
lines changed

docs/man_pages/project/testing/build-android.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ build android
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns build android [--compileSdk <API Level>] [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings] [--copy-to <File Path>]`
6+
General | `$ tns build android [--compileSdk <API Level>] [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings] [--copy-to <File Path>] [--bundle [<value>] [--env.*]]`
77

88
Builds the project for Android and produces an APK that you can manually deploy on device or in the native emulator.
99

@@ -15,6 +15,8 @@ Builds the project for Android and produces an APK that you can manually deploy
1515
* `--key-store-alias` - Provides the alias for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1616
* `--key-store-alias-password` - Provides the password for the alias specified with `--key-store-alias-password`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1717
* `--copy-to` - Specifies the file path where the built `.apk` will be copied. If it points to a non-existent directory, it will be created. If the specified value is directory, the original file name will be used.
18+
* `--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`.
19+
* `--env.*` - Specifies additional flags that the bundler may process. May be passed multiple times. For example: `--env.uglify --env.snapshot`.
1820

1921
### Attributes
2022
`<API Level>` is a valid Android API level. For example: 22, 23.<% if(isHtml) { %> For a complete list of the Android API levels and their corresponding Android versions, click [here](http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#platform).<% } %>

docs/man_pages/project/testing/build-ios.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ build ios
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns build ios [--for-device] [--release] [--copy-to <File Path>] [--provision [<UUID/name>]]`
6+
General | `$ tns build ios [--for-device] [--release] [--copy-to <File Path>] [--provision [<UUID/name>]] [--bundle [<value>] [--env.*]]`
77

88
Builds the project for iOS and produces an `APP` or `IPA` that you can manually deploy in the iOS Simulator or on device, respectively.
99

@@ -17,6 +17,8 @@ Builds the project for iOS and produces an `APP` or `IPA` that you can manually
1717
* `--copy-to` - Specifies the file path where the built `.ipa` will be copied. If it points to a non-existent directory, it will be created. If the specified value is directory, the original file name will be used.
1818
* `--team-id` - If used without parameter, lists all team names and ids. If used with team name or id, it will switch to automatic signing mode and configure the .xcodeproj file of your app. In this case .xcconfig should not contain any provisioning/team id flags. This team id will be further used for codesigning the app. For Xcode 9.0+, xcodebuild will be allowed to update and modify automatically managed provisioning profiles.
1919
* `--provision` - If used without parameter, lists all eligible provisioning profiles. If used with UUID or name of your provisioning profile, it will switch to manual signing mode and configure the .xcodeproj file of your app. In this case xcconfig should not contain any provisioning/team id flags. This provisioning profile will be further used for codesigning the app.
20+
* `--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`.
21+
* `--env.*` - Specifies additional flags that the bundler may process. May be passed multiple times. For example: `--env.uglify --env.snapshot`.
2022
<% } %>
2123
<% if(isHtml) { %>
2224
### Command Limitations

docs/man_pages/project/testing/run-android.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ run android
33

44
Usage | Synopsis
55
---|---
6-
Run on all connected devices and running emulators | `$ tns run android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
7-
Run on a selected connected device or running emulator. Will start emulator with specified `Device Identifier`, if not already running. | `$ tns run android --device <Device ID> [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
8-
Start a default emulator if none are running, or run application on all connected emulators. | `$ tns run android --emulator [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch]`
6+
Run on all connected devices and running emulators | `$ tns run android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
7+
Run on a selected connected device or running emulator. Will start emulator with specified `Device Identifier`, if not already running. | `$ tns run android --device <Device ID> [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
8+
Start a default emulator if none are running, or run application on all connected emulators. | `$ tns run android --emulator [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
99

1010
Runs your project on a connected Android device or in a native Android emulator, if configured. This is shorthand for prepare, build and deploy. While your app is running, prints the output from the application in the console and watches for changes in your code. Once a change is detected, it synchronizes the change with all selected devices and restarts/refreshes the application.
1111

@@ -20,6 +20,8 @@ Runs your project on a connected Android device or in a native Android emulator,
2020
* `--key-store-password` - Provides the password for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
2121
* `--key-store-alias` - Provides the alias for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
2222
* `--key-store-alias-password` - Provides the password for the alias specified with `--key-store-alias-password`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
23+
* `--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`.
24+
* `--env.*` - Specifies additional flags that the bundler may process. May be passed multiple times. For example: `--env.uglify --env.snapshot`.
2325

2426
### Attributes
2527
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns device android --available-devices`

docs/man_pages/project/testing/run-ios.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ run ios
33

44
Usage | Synopsis
55
---|---
6-
Run on all connected devices | `$ tns run ios [--release] [--justlaunch]`
7-
Run on a selected connected device. Will start simulator with specified `Device Identifier`, if not already running. | `$ tns run ios [--device <Device ID>] [--release] [--justlaunch]`
8-
Start an emulator and run the app inside it | `$ tns run ios --emulator [--release]`
6+
Run on all connected devices | `$ tns run ios [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
7+
Run on a selected connected device. Will start simulator with specified `Device Identifier`, if not already running. | `$ tns run ios [--device <Device ID>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]`
8+
Start an emulator and run the app inside it | `$ tns run ios --emulator [--release] [--bundle [<value>] [--env.*]]`
99

1010
Runs your project on a connected iOS device or in the iOS Simulator, if configured. This is shorthand for prepare, build and deploy. While your app is running, prints the output from the application in the console and watches for changes in your code. Once a change is detected, it synchronizes the change with all selected devices and restarts/refreshes the application.
1111

@@ -20,6 +20,8 @@ Runs your project on a connected iOS device or in the iOS Simulator, if configur
2020
* `--clean` - If set, forces rebuilding the native application.
2121
* `--no-watch` - If set, changes in your code will not be reflected during the execution of this command.
2222
* `--release` - If set, produces a release build. Otherwise, produces a debug build.
23+
* `--bundle` - Specifies that a bundler (e.g. webpack) should be used if one is present. If no value is passed will default to `webpack`.
24+
* `--env.*` - Specifies additional flags that the bundler may process. May be passed multiple times. For example: `--env.uglify --env.snapshot`.
2325

2426
### Attributes
2527
* `<Device ID>` is the index or `Device Identifier` of the target device as listed by `$ tns device ios --available-devices`

lib/commands/appstore-upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class PublishIOS implements ICommand {
5656
if (!ipaFilePath) {
5757
const platform = this.$devicePlatformsConstants.iOS;
5858
// No .ipa path provided, build .ipa on out own.
59-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
59+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
6060
const platformInfo: IPreparePlatformInfo = {
6161
platform,
6262
appFilesUpdaterOptions,

lib/commands/base-bundler.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export abstract class BundleBase {
2+
private bundlersMap: IStringDictionary = {
3+
webpack: "nativescript-dev-webpack"
4+
};
5+
6+
constructor(protected $projectData: IProjectData,
7+
protected $errors: IErrors,
8+
protected $options: IOptions) {
9+
this.$projectData.initializeProjectData();
10+
}
11+
12+
protected validateBundling(): void {
13+
if (this.$options.bundle) {
14+
const bundlePluginName = this.bundlersMap[this.$options.bundle];
15+
if (!bundlePluginName || (!this.$projectData.devDependencies[bundlePluginName] && !this.$projectData.dependencies[bundlePluginName])) {
16+
this.$errors.fail("Passing --bundle requires a bundling plugin. No bundling plugin found or the specified bundling plugin is invalid.");
17+
}
18+
}
19+
}
20+
}

lib/commands/build.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
2+
import { BundleBase } from "./base-bundler";
23

3-
export class BuildCommandBase {
4+
export class BuildCommandBase extends BundleBase {
45
constructor(protected $options: IOptions,
56
protected $errors: IErrors,
67
protected $projectData: IProjectData,
78
protected $platformsData: IPlatformsData,
89
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
910
protected $platformService: IPlatformService) {
11+
super($projectData, $errors, $options);
1012
this.$projectData.initializeProjectData();
1113
}
1214

1315
public async executeCore(args: string[]): Promise<void> {
1416
const platform = args[0].toLowerCase();
15-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
17+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
1618
const platformInfo: IPreparePlatformInfo = {
1719
platform,
1820
appFilesUpdaterOptions,
@@ -47,6 +49,8 @@ export class BuildCommandBase {
4749
if (!this.$platformService.isPlatformSupportedForOS(platform, this.$projectData)) {
4850
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
4951
}
52+
53+
super.validateBundling();
5054
}
5155
}
5256

lib/commands/clean-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class CleanAppCommandBase implements ICommand {
1414
}
1515

1616
public async execute(args: string[]): Promise<void> {
17-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
17+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
1818
return this.$platformService.cleanDestinationApp(this.platform.toLowerCase(), appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
1919
}
2020

lib/commands/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class DeployOnDeviceCommand implements ICommand {
1414
}
1515

1616
public async execute(args: string[]): Promise<void> {
17-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
17+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
1818
const deployOptions: IDeployPlatformOptions = {
1919
clean: this.$options.clean,
2020
device: this.$options.device,

lib/commands/prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class PrepareCommand implements ICommand {
1010
}
1111

1212
public async execute(args: string[]): Promise<void> {
13-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
13+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
1414
const platformInfo: IPreparePlatformInfo = {
1515
platform: args[0],
1616
appFilesUpdaterOptions,

lib/commands/run.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
22
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
33
import { cache } from "../common/decorators";
4+
import { BundleBase } from "./base-bundler";
45

5-
export class RunCommandBase implements ICommand {
6+
export class RunCommandBase extends BundleBase implements ICommand {
67

78
public platform: string;
89
constructor(protected $platformService: IPlatformService,
@@ -14,7 +15,9 @@ export class RunCommandBase implements ICommand {
1415
protected $platformsData: IPlatformsData,
1516
private $hostInfo: IHostInfo,
1617
private $liveSyncCommandHelper: ILiveSyncCommandHelper
17-
) { }
18+
) {
19+
super($projectData, $errors, $options);
20+
}
1821

1922
public allowedParameters: ICommandParameter[] = [];
2023
public async execute(args: string[]): Promise<void> {
@@ -40,6 +43,8 @@ export class RunCommandBase implements ICommand {
4043
await platformProjectService.validate(this.$projectData);
4144
}
4245

46+
super.validateBundling();
47+
4348
return true;
4449
}
4550

lib/declarations.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ interface IBundle {
326326
bundle: boolean;
327327
}
328328

329+
interface IBundleString {
330+
bundle: string;
331+
}
332+
329333
interface IPlatformTemplate {
330334
platformTemplate: string;
331335
}
@@ -374,7 +378,7 @@ interface IPort {
374378
port: Number;
375379
}
376380

377-
interface IOptions extends ICommonOptions, IBundle, IPlatformTemplate, IEmulator, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions, INpmInstallConfigurationOptions, IPort, IEnvOptions {
381+
interface IOptions extends ICommonOptions, IBundleString, IPlatformTemplate, IEmulator, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions, INpmInstallConfigurationOptions, IPort, IEnvOptions {
378382
all: boolean;
379383
client: boolean;
380384
compileSdk: number;

lib/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class Options extends commonOptionsLibPath.OptionsBase {
3030
ng: { type: OptionType.Boolean },
3131
tsc: { type: OptionType.Boolean },
3232
androidTypings: { type: OptionType.Boolean },
33-
bundle: { type: OptionType.Boolean },
33+
bundle: { type: OptionType.String },
3434
all: { type: OptionType.Boolean },
3535
teamId: { type: OptionType.Object },
3636
syncAllFiles: { type: OptionType.Boolean, default: false },

lib/services/app-files-updater.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class AppFilesUpdater {
77
constructor(
88
private appSourceDirectoryPath: string,
99
private appDestinationDirectoryPath: string,
10-
public options: { release: boolean; bundle: boolean },
10+
public options: IAppFilesUpdaterOptions,
1111
public fs: IFileSystem
1212
) {
1313
}

lib/services/livesync/livesync-command-helper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
9898
for (const currentPlatform of availablePlatforms) {
9999
const deployPlatformInfo: IDeployPlatformInfo = {
100100
platform: currentPlatform,
101-
appFilesUpdaterOptions: this.$options,
101+
appFilesUpdaterOptions: {
102+
bundle: !!this.$options.bundle,
103+
release: this.$options.release
104+
},
102105
deployOptions,
103106
projectData: this.$projectData,
104107
config: this.$options,

lib/services/test-execution-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class TestExecutionService implements ITestExecutionService {
5656
const socketIoJsUrl = `http://localhost:${this.$options.port}/socket.io/socket.io.js`;
5757
const socketIoJs = (await this.$httpClient.httpRequest(socketIoJsUrl)).body;
5858
this.$fs.writeFile(path.join(projectDir, TestExecutionService.SOCKETIO_JS_FILE_NAME), socketIoJs);
59-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
59+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
6060
const preparePlatformInfo: IPreparePlatformInfo = {
6161
platform,
6262
appFilesUpdaterOptions,
@@ -181,7 +181,7 @@ class TestExecutionService implements ITestExecutionService {
181181
this.$fs.writeFile(path.join(projectDir, TestExecutionService.CONFIG_FILE_NAME), configJs);
182182
}
183183

184-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
184+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
185185
const preparePlatformInfo: IPreparePlatformInfo = {
186186
platform,
187187
appFilesUpdaterOptions,

test/npm-support.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async function preparePlatform(testInjector: IInjector): Promise<void> {
201201

202202
await platformService.preparePlatform({
203203
platform: "android",
204-
appFilesUpdaterOptions: { bundle: options.bundle, release: options.release },
204+
appFilesUpdaterOptions: { bundle: !!options.bundle, release: options.release },
205205
platformTemplate: "",
206206
projectData,
207207
config: options,

0 commit comments

Comments
 (0)