Skip to content
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

fix(cli): mimic cordova's js-module logic when no name attribute #1959

Merged
merged 1 commit into from
Sep 16, 2019
Merged
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
13 changes: 8 additions & 5 deletions cli/src/cordova.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Config } from './config';
import { getJSModules, getPlatformElement, getPluginPlatform, getPlugins, getPluginType, printPlugins, Plugin, PluginType } from './plugin';
import { copySync, ensureDirSync, readFileAsync, removeSync, writeFileAsync } from './util/fs';
import { join, resolve } from 'path';
import { basename, extname, join, resolve } from 'path';
import { buildXmlElement, installDeps, log, logError, logFatal, logInfo, logWarn, readXML, resolveNode, writeXML } from './common';
import { copy as fsCopy, existsSync } from 'fs-extra';
import { getAndroidPlugins } from './android/common';
Expand Down Expand Up @@ -51,11 +51,12 @@ export function generateCordovaPluginsJSFile(config: Config, plugins: Plugin[],
if (jsModule.runs) {
runsModule = ',\n "runs": true';
}
const pluginModule = {
const pluginModule = {
clobber: clobberKey,
merge: mergeKey,
// mimics Cordova's module name logic if the name attr is missing
pluginContent: `{
"id": "${pluginId}.${jsModule.$.name}",
"id": "${pluginId + '.' + (jsModule.$.name || jsModule.$.src.match(/([^\/]+)\.js/)[1])}",
"file": "plugins/${pluginId}/${jsModule.$.src}",
"pluginId": "${pluginId}"${clobbersModule}${mergesModule}${runsModule}
}`
Expand Down Expand Up @@ -107,7 +108,9 @@ export async function copyPluginsJS(config: Config, cordovaPlugins: Plugin[], pl
copySync(join(p.rootPath, jsModule.$.src), filePath);
let data = await readFileAsync(filePath, 'utf8');
data = data.trim();
data = `cordova.define("${pluginId}.${jsModule.$.name}", function(require, exports, module) { \n${data}\n});`;
// mimics Cordova's module name logic if the name attr is missing
const name = pluginId + '.' + (jsModule.$.name || basename(jsModule.$.src, extname(jsModule.$.src)));
data = `cordova.define("${name}", function(require, exports, module) { \n${data}\n});`;
data = data.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script\s*>/gi, "")
await writeFileAsync(filePath, data, 'utf8');
}));
Expand Down Expand Up @@ -207,7 +210,7 @@ export async function copyCordovaJSFiles(config: Config, platform: string) {
let plugins: Plugin[] = [];
if (platform === config.ios.name) {
plugins = getIOSPlugins(allPlugins);
} else if (platform === config.android.name) {
} else if (platform === config.android.name) {
plugins = getAndroidPlugins(allPlugins);
}
const cordovaPlugins = plugins
Expand Down