Skip to content

chore: provide external plugins to webpack in order to fix tns preview --bundle command on android devices #3903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/definitions/preview-app-livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ declare global {

interface IPreviewAppPluginsService {
comparePluginsOnDevice(device: Device): Promise<void>;
getExternalPlugins(device: Device): string[];
}

interface IPreviewCommandHelper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
platform: device.platform,
appFilesUpdaterOptions: data.appFilesUpdaterOptions,
},
externals: this.$previewAppPluginsService.getExternalPlugins(device),
filesToSyncMap,
  startSyncFilesTimeout: startSyncFilesTimeout.bind(this)
}
Expand Down
15 changes: 15 additions & 0 deletions lib/services/livesync/playground/preview-app-plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
this.previewAppVersionWarnings[device.previewAppVersion].map(warning => this.$logger.warn(warning));
}

public getExternalPlugins(device: Device): string[] {
const devicePlugins = this.getDevicePlugins(device);
const result = _.keys(devicePlugins)
.filter(plugin => plugin.indexOf("nativescript") !== -1)
// exclude angular and vue related dependencies as they do not contain
// any native code. In this way, we will read them from the bundle
// and improve the app startup time by not reading a lot of
// files from the file system instead. Also, the core theme links
// are custom and should be handled by us build time.
.filter(plugin => !_.includes(["nativescript-angular", "nativescript-vue", "nativescript-intl", "nativescript-theme-core"], plugin));

result.push(...["tns-core-modules", "tns-core-modules-widgets"]);
return result;
}

private getDevicePlugins(device: Device): IStringDictionary {
try {
return JSON.parse(device.plugins);
Expand Down
3 changes: 2 additions & 1 deletion test/services/playground/preview-app-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ function createTestInjector(options?: {
injector.register("previewAppPluginsService", {
comparePluginsOnDevice: async () => {
isComparePluginsOnDeviceCalled = true;
}
},
getExternalPlugins: () => <string[]>[]
});
injector.register("projectFilesManager", ProjectFilesManager);
injector.register("previewAppLiveSyncService", PreviewAppLiveSyncService);
Expand Down
52 changes: 52 additions & 0 deletions test/services/playground/preview-app-plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,56 @@ describe("previewAppPluginsService", () => {
});
}
});
describe("getExternalPlugins", () => {
const testCases = [
{
name: "should return default plugins(`tns-core-modules` and `tns-core-modules-widgets`) when no plugins are provided",
plugins: {},
expectedPlugins: ["tns-core-modules", "tns-core-modules-widgets"]
},
{
name: "should exclude `nativescript-vue`",
plugins: { "nativescript-vue": "1.2.3" },
expectedPlugins: ["tns-core-modules", "tns-core-modules-widgets"]
},
{
name: "should exclude `nativescript-intl`",
plugins: { "nativescript-intl": "4.5.6" },
expectedPlugins: ["tns-core-modules", "tns-core-modules-widgets"]
},
{
name: "should exclude `nativescript-angular`",
plugins: { "nativescript-angular": "7.8.9" },
expectedPlugins: ["tns-core-modules", "tns-core-modules-widgets"]
},
{
name: "should exclude `nativescript-theme-core`",
plugins: { "nativescript-theme-core": "1.3.5" },
expectedPlugins: ["tns-core-modules", "tns-core-modules-widgets"]
},
{
name: "should return plugins that contain `nativescript` in their names",
plugins: {
"nativescript-facebook": "4.5.6"
},
expectedPlugins: ["nativescript-facebook", "tns-core-modules", "tns-core-modules-widgets"]
},
{
name: "should not return plugins that do not contain `nativescript` in their names",
plugins: {
lodash: "4.5.6",
xmlhttprequest: "1.2.3"
},
expectedPlugins: ["tns-core-modules", "tns-core-modules-widgets"]
}
];

_.each(testCases, testCase => {
it(`${testCase.name}`, () => {
const { previewAppPluginsService, device } = setup(testCase.plugins, testCase.plugins);
const actualPlugins = previewAppPluginsService.getExternalPlugins(device);
assert.deepEqual(actualPlugins, testCase.expectedPlugins);
});
});
});
});