on 06-24-2014 1:08 PM
I'm trying to use third party Javascript libraries for my projects in the XS Engine. Let's assume I'm writing a script that has two direct dependencies:
my-app.js
|-- dependency-a.js
|-- dependency-b.js
|-- subdependency-b1.js
|-- subdependency-b2.js
How can I make dependency-a.js and dependency-b.js (including their dependencies) available for my-app.js in the XS Engine?
Does the XS Engine support some kind of package management / module system (like CommonJS)?
Currently the only method I found for one Javascript file to depend on another is to make the dependency an *.xsjslib file and import it. This isn't a feasible solution in my scenario, because:
1. Pretty much all server-side libraries I want to use are modules based on CommonJS (mainly written for Node.js), and would have to be adapted
2. Not all libraries I use have been validated by JSLint, so HANA doesn't actually allow me to activate them till they are (is there a way to disable JSLint?)
In order to use them in server side JavaScript they must have the file extension XSJSLIB and be imported. They also must pass the server side JSLint checks for activation. The client side JSLint checks, which are more strict, can be ignored or disabled at the project level.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
UPDATE:
The error I reported below was in my js code. Not sure where, but doesn't appear to be an "XS issue".
For others looking at this thread, below is a more detailed example for your reference.
/////////////////////////////////////////////
STRUCTURE:
-Content
--MyPackage
---MyApp.xsjs
---MyLib.xsjslib
//////////////////////////////////////////////
MyApp.xsjs code:
$.import("MyPackage","MyLib");
var x = $.MyPackage.MyLib.MyObject.MyFunction("my test string");
$.response.setBody(x);
///////////////////////////////////////////////
MyLib.xsjslib code:
var MyObject:{
MyFunction: function (myString) {
return = "You passed in the string: " + myString;
}
};
ORIGINAL:
I'm getting the following error:
Found the following errors:
===========================
TypeError: "xml2json" is read-only (line 146 position 0 in /sales/xml2json.xsjslib)
here is my import code:
$.import("sales","xml2json");
xsjslib and xsjs are in the same package, sales, as shown below.
Content
-Sales
--ccw.xsjs
--xml2json.xsjslib
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.