cordova/exec fails within meteor project - javascript

After building a Cordova plugin with plugman, installing it in meteor 2.3.2 and running meteor run android-build, I get the following error from within the plugin:
Unable to resolve some modules:
"cordova/exec" in ~/MeteorApp/MyPlugin/www/MyPlugin.js (web.browser)
The error line is from line 2 in the generate MyPlugin.js
// ~/MeteorApp/MyPlugin/www/MyPlugin.js
// I added this check for cordova myself
if (cordova && cordova.exec ) {
var exec = require('cordova/exec');
exports.coolMethod = function (arg0, success, error) {
exec(success, error, 'MyPlugin', 'coolMethod', [arg0]);
};
}
My meteor structure includes the plugin folder at the route of the app
I installed the package using meteor add cordova:my.plugin.id#file://path/to/plugin/project
Cordova version 10.0.8
I have the following plugin structure:
pluginDir/
src/
android/
MyPlugin.java
www/
MyPlugin.js
package.json
plugin.xml
I have tested the plugin inside a Cordova app and that works just fine.
I bet the issue here is how meteor exposes the internal Cordova object.

Solution
Meteor already wraps the cordova object so really instead of importing cordova/exec in the /www plugin definition I simply had to use cordova.exec('my logic goes here')
The above is scaffolded with plugman and the /www folder and files get generated automatically, as well as the above code.
The code above is valid within Cordova, but this logic fails within Meteor.
Extra comments
Only Android support was required for this plugin and the cordova.exec() logic was moved into a Meteor api method.
Because of this Android-only requirement the /www folder and references was removed.
The /www folder may be reintroduced in the future in order to define a nice fallback for web usage scenarios, but it's unlikely for our internal plugin.

Related

How to do module resolution when an npm package contains multiple namespaces/submodules

A project I am working with is using this package: https://www.npmjs.com/package/#ethersproject/abstract-provider
within an SDK we are building..
After installation, the SDK node_modules folder contains the #ethersproject directory which contains an abstract-provider directory as well as multiple other directories, each their own namespace with separate package.json files.
We use the code in the sdk as follows:
import { Provider } from '#ethersproject/abstract-provider';
and this works fine for webpack based projects which import our SDK (such as a React app using create-react-app).
When I want to use our SDK in a project which DOESN'T use a bundler such as webpack (such as a very simple frontend pulling in our sdk with importmap as here: https://github.com/unegma/rainprotocol__verify-gating), we are getting an error:
Failed to resolve module specifier "#ethersproject/abstract-provider". Relative references must start with either "/", "./", or "../".
I'm assuming this is because our SDK doesn't know how to resolve #ethersproject/abstract-provider because abstract-provider is a submodule of #ethersproject (which isn't even a module itself).
What is the way to solve this issue? Do we need to create a decs.d.ts file in our SDK root which contains something like: declare module "#ethersproject/abstract-provider; or is there a different way to do this?

Electron application can't resolve 'greenworks-linux32' on Steamworks integration

I have html5 application built for desktop with Electron. I currently try to integrate Greenworks SDK for Steamworks SDK to support achievements in it.
I tried both electron-rebuild and node-gyp ways to integrate Greenworks resulted in the same error - application crashes on startup with a problem in module resolving - "greenworks-linux32.node cannot be found”.
I tried to download this file separately and put it in greenworks/lib. But the problem persists. I also tried to put whole greenworks folder in the same folder with script that calls Greenworks API.
I use the following build:
Greenworks: [v0.10.0 x64]
Steamworks SDK: [v1.40]
Electron: [v1.6.15]
Folder structure is as follows:
app/
steam_appid.txt
node_modules/
greenworks/
greenworks.js
lib/
greenworks-linux32.node
greenworks-linux64.node
greenworks-osx64.node
greenworks-win32.node
greenworks-win64.node
libsdkencryptedappticket.dylib
libsdkencryptedappticket.so
libsdkencryptedappticket64.so
libsteam_api.dylib
libsteam_api.so
libsteam_api64.so
sdkencryptedappticket.dll
sdkencryptedappticket.lib
sdkencryptedappticket64.dll
sdkencryptedappticket64.lib
steam_api.dll
steam_api.lib
steam_api64.dll
steam_api64.lib
public/
index.html
electron/
Please share any thoughts on what could it be. I have an idea that the problem caused. The problem appears only when I'm calling Greenworks API.
I used this guide to proceed: https://github.com/greenheartgames/greenworks/blob/master/docs/build-instructions-electron.md

Javascript error in simple Aurelia ASP.Net 5.0 RC1 Setup

I am attempting to setup a very basic Aurelia project in ASP.Net 5.0 RC1. I am getting the following JavaScript error after doing a basic initial setup. I am using TypeScript.
Unhandled promise rejection Error: XHR error (404 Not Found) loading http://localhost:5392/core-js.js
Error loading http://localhost:5392/core-js.js as "core-js" from http://localhost:5392/jspm_packages/npm/aurelia-loader#1.0.0-beta.1/aurelia-loader.js
at o (http://localhost:5392/jspm_packages/system.js:4:12694)
at XMLHttpRequest.s.onreadystatechange (http://localhost:5392/jspm_packages/system.js:4:13219)
(anonymous function) # es6.promise.js:138
The setup I did is as follows.
Create Empty ASP.Net 5.0 template.
Install Microsoft.AspNet.StaticFiles from nuget and set up app.UseFileServer.
From git bash run jspm init with the following settings.
Package.json file does not exist, create it? [yes]:
Would you like jspm to prefix the jspm package.json properties under jspm? [yes]:
Enter server baseURL (public folder path) [./]:./wwwroot
Enter jspm packages folder [wwwroot\jspm_packages]:
Enter config file path [wwwroot\config.js]:
Configuration file wwwroot\config.js doesn't exist, create it? [yes]:
Enter client baseURL (public folder URL) [/]:
Do you wish to use a transpiler? [yes]:
Which ES6 transpiler would you like to use, Babel, TypeScript or Traceur? [babel]:typescript
From git bash run jspm install aurelia-framework and jspm install aurelia-bootstrapper.
Add the index.html, app.html, and app.ts file from the aurelia docs.
Fire up IIS Express, load page, get error.
Is there a step I am missing in this setup?
It seems like this is a known issue. The fix is somewhat simple. If you add a core-js mapping at the top of the map section in config.js, it fixes it.
For example,
map: {
"core-js": "npm:core-js#1.2.6",
// other mappings
}

cordova-plugin-barcode-scanner2 failing to build

I have PhoneGap build app I am trying to build. In my config.xml I have:
<gap:plugin name="cordova-plugin-barcode-scanner2" source="npm" />
I use this for a bar code scanner in my app. When I build it the Android version builds just fine and works. When I build the iPhone version I receive this error:
Error - Plugin error (you probably need to remove plugin files from your app): Fetching plugin "cordova-plugin-barcode-scanner2" via npm Installing "cordova-plugin-barcodescanner" for ios Error during processing of action! Attempting to revert... Failed to install 'cordova-plugin-barcodescanner':Error: Uh oh! "/private/tmp/gimlet/320/1536482/project/cordova/plugins/cordova-plugin-barcodescanner/src/ios/CDVBarcodeScanner.mm" not found! at Object.module.exports.common.copyFile (/usr/local/lib/node_modules/pgb-plugman/node_modules/pgb-cordova-lib/src/plugman/platforms/common.js:38:40) at Object.module.exports.common.copyNewFile (/usr/local/lib/node_modules/pgb-plugman/node_modules/pgb-cordova-lib/src/plugman/platforms/common.js:69:16) at installHelper (/usr/local/lib/node_modules/pgb-plugman/node_modules/pgb-cordova-lib/src/plugman/platforms/ios.js:54:16) at Object.module.exports.source-file.install (/usr/local/lib/node_modules/pgb-plugman/node_modules/pgb-cordova-lib/src/plugman/platforms/ios.js:139:13) at installWrapper (/usr/local/lib/node_modules/pgb-plugman/node_modules/pgb-cordova-lib/src/platforms/platforms.js:77:32) at Object.ActionStack.process (/usr/local/lib/node_modules/pgb-plugman/node_modules/pgb-cordova-lib/src/plugman/util/action-stack.js:68:25) at handleInstall (/usr/local/lib/node_modules/pgb-plugman/node_modules/pgb-cordova-lib/src/plugman/install.js:576:20) at /usr/local/lib/node_modules/pgb-plugman/node_modules/pgb-cordova-lib/src/plugman/install.js:368:24 at _fulfilled (/usr/local/lib/node_modules/pgb-plugman/node_modules/q/q.js:787:54) at self.promiseDispatch.done (/usr/local/lib/node_modules/pgb-plugman/node_modules/q/q.js:816:30) Uh oh! "/private/tmp/gimlet/320/1536482/project/cordova/plugins/cordova-plugin-barcodescanner/src/ios/CDVBarcodeScanner.mm" not found!
On the PhoneGap frequentley asked quuestions page they refer to this error with this solution:
The most likely cause for this error is error is that you have
included plugin javascript files in your app package, such as
barcodescanner.js, GAPlugin.js, cdv-plugin-fb-connect.js, or any other
plugin files such as the childbrowser assets directory.
Previously we used pluginstall to install plugins, which would simply
overwrite files in your app. However we recently migrated to plugman,
which will not overwrite these files and instead fails. So make sure
you remove them!
But I searched my entire project and can not find barcodescanner.js
Any ideas?

How to rename react-native entry file (index.ios.js)

When I init a react-native project, index.ios.js is created as project entry file.
Can I change this file's name and if so, how?
When you start a react-native app you'll see this message output by the React Packager:
Running packager on port 8081
and then:
Looking for JS files in
/Users/gbirman/gil/mapily
React packager ready.
By this point, the packager has compiled your JS files and is serving them with the .js extension renamed to .bundle. For example, your index.io.js file is compiled and served from:
http://localhost:8081/index.ios.bundle
If you added another file foo.js in the same directory as index.ios.js, the packager would serve it from:
http://localhost:8081/foo.bundle
You can confirm this by opening that url in your browser.
Now to answer your question, your project has an iOS/AppDelegate.m file with the following line:
jsCodeLocation = [NSURL URLWithString:#"http://localhost:8081/index.ios.bundle"];
... as you can see, it loads the index.ios.bundle. You can change the path/filename there to whatever you want, but it's probably best to stick with the recommended approach of naming your entry file index.io.js
Suppose you've moved your index.ios.js into a folder called dist. You need to do two things
For your development environment: Update jsBundleURLForBundleRoot in AppDelegate.m to match your updated path.
For your release bundle: Open your Xcode project. You'll need to update the Bundle React Native code and images task under Build Phases for your project. Update the shell script in this section to look like below:
export NODE_BINARY=node
../node_modules/react-native/packager/react-native-xcode.sh dist/index.ios.js
react-native-xcode.sh accepts the ENTRY_FILE as an optional first argument, defaulting to index.ios.js if none is found.
Updated Build Phases Example
Reference - react-native/scripts/react-native-xcode.sh

Categories