Does an ember package imported component use its parents library version? - ember.js

I tried to use a component from an imported package inside a class in ember.
I expected the component to use its own version of ember-intl.
It resulted in the imported package using the parents version of ember-intl.
I have ember-intl 5.7.0 in parent and 4.3.0 used in an imported package.
There is a component called <Calendar> from the imported package used in a parent class which has a string that looks like:
"{Date} was selected for <span class='exampleName'".
4.3.0 will handle this string fine but 5.7.0 will fail as the major version change was that apostrophes were made into escape characters :[
node_modules shows that the child package resolves to 4.3.0 but during runtime it fails due to the apostrophe.
The imported component uses a service by injecting it:
import { inject as service } from '#ember/service';
intl: service()
I've added logging to both versions to see which is used and it is the parent version.
I would prefer not to downgrade the parent or alter the child library.
Can anyone explain why this is happening?
If any more info is needed, let me know, thanks.

You can only ever have one copy of a package at any given time -- allowing duplicates would explode your bundle size very rapidly (exponentially, even).
In best case scenarios, the "app version" will win, but in worst case scenarios, you duplicate dependencies in your app -- this can be linted against with ember-cli-dependency-lint
Because ember-intl relies on app-wide state, tho, it's not possible to get in to duplicate dependencies in your app -- because you can only ever have one copy of a service.
I recommend upgrading the package you're using, since ember-intl is nearly on v6 right now, and v4 is very old.

Related

WebStorm with Babel not working with import statements

I'm using WebStorm 2017.1.3, although also tried with latest EAP, and i can't get import from statement to work. I just keep getting the following error:
import Utils from './utils'
^^^^^^
SyntaxError: Unexpected token import
In my packages.json i have babel-cli, babel-preset-env and babel-preset-es2015 defined. I have followed various blog posts and videos but still get same error.
ES6 is enabled in settings and i tried adding Babel file watch as per documentation but nothing seems to work. This feels like it should be a lot easier and just work, so i must be missing a important part of the jigsaw.
Does anyone have a working step by step, from fresh project, how to guide in configuring webstorm to work with import ?
Some places say use file watch, others say just to change project configuration interpreter to use babel-node. Other say must use Gulp... very confusing.
Thank you.
fLo
To make things clear: this is not about configuring WebStorm, error comes from Node.js interpreter that runs your code. Node.js still doesn't support ES6 modules natively (actually, no JavaScript runtime currently supports them - ECMAScript does not define a "Loader" specification which determines how Modules are inserted into the runtime. The Loader spec is being defined by WHATWG, but is not yet finalized). So, to get ES6 imports/exports accepted, you need using transpilers. Current industry standard is Babel
The most simple way to make it work is the following:
install babel in your project using npm install --save-dev babel-cli babel-preset-env
create a .babelrc file in project root dir:
{ "presets": ["env"] }
in your Node.js Run configuration, pass -r babel-register to Node:
With this configuration, your code will be transpiled on-the-fly by Babel, no file watchers, etc. are needed

ember electron:package build failed, caused by ember-browserify

when I want to build my ember electron app with ember electron:package
I always get the error:
Build failed.
File: assets/vendor.js (91129:6)
The Broccoli Plugin: [UglifyWriter] failed with:
followed by several lines of "Error at...:" (always within node_modules)
I could figure out that it must have something to do with ember-browserify.
I am importing this node module in a service.js file:
import Usabilla from 'npm:usabilla-api';
The curious thing is, that with ember electron (like ember serve) everything is fine and I can use the node module without any errors. Issues only occur when I want to package the app to the .dmg and exe files for distribution.
What am I missing ?
Thanks for any help or hints!
Your build is failing on the minification step. Possibly because of the size of one of the packages you're pulling in or because it's already been minified. Minification only happens when you're building for production or packaging which is why you're not seeing the issue when you run locally.
From the EmberCLI docs on minification, where you'll find more on the minifaction step:
the js-files are minified with broccoli-uglify-js in the production-env by default. You can pass custom options to the minifier via the minifyJS:options object in your ember-cli-build
You can exclude specific files/resources that are causing problems:
To exclude assets from dist/assets from being minificated, one can pass options for broccoli-uglify-sourcemap
I just create the demo app in c drive and it's working perfectly.

Generated Service with Axis outside Liferay, can't use it inside plugins

Using Liferay 6.2 CE GA6 here.
In my current project I am forced to use a SOAP-RPC webservice generated outside liferay. I have the WSDL file and the procedure I used to get the client was:
Downloaded Axis 1.4 (same that Liferay 6.2 CE GA6 uses, I think)
Used WSDL2Java to generate Java classes that use the remote service.
Did a local test with those classes - everything fine.
Included those classes in a EXT plugin and deployed that plugin to
Liferay.
Created Arquilian test and run that test FROM ECLIPSE - Everything
works.
And now, thinking I got this covered, I created a new Service Plugin, created a test method:
public Boolean canICallMyService(){
MyWsCaller wsClient = new MyWsCaller();
return true;
}
And bam, exception:
09:33:21,394 ERROR
[http-bio-8080-exec-18][JSONWebServiceServiceAction:87] Unresolved
compilation problems: _ The import javax.xml.rpc cannot be
resolved_ The method X() from the type XServiceXmlCCServiceLocator
refers to the missing type ServiceException_ ServiceException cannot
be resolved to a type_ [Sanitized]
I know this must be related with me using Axis libs and Liferay using Axis libs as well, but I can't figure out how to overcome this classpath error. The import in question is jaxrpc.jar, that is included in Liferay's lib (webapps\ROOT\WEB-INF\lib). I have included in ALSO in my EXT plugin's lib directory. If I remove it from the EXT's lib, then the Arquilian test also fails with same error.
I have tried to put the required libs in the lib/ext in tomcat, this just makes Liferay give up on life at start with multiple Axis cast errors on all portlets.
Anyone has any idea what is the correct procedure and how can I replicate it?
I just want to use a Axis 1.4 generated webservice within a Portlet.
My current solution, that I consider kind of lame, is to deploy the webservice as a servlet in the same container and just run calls to localhost/service?q=parametersThatINeed. Works, and no Axis libs conflits.. but not really ideal.

Ember Cli - Transpiling vendor ES6 dependency in ember-cli-build?

I'm writing an Ember.js application using Ember Cli, and I want to include a non-bower dependency - basically a dependency from my vendor folder.
The instructions on doing so is telling me to add the following line into my ember-cli-build.js file:
app.import('vendor/dependency-to-include.js');
That would work fine with a normal ES5 flavored dependency, but what if I want to add a dependency written in ES6?
Right now it just delivers it to the browser untouched, which produces an error like:
Uncaught SyntaxError: Unexpected reserved word
because my ES6 flavored dependency uses the following syntax:
import Util from './util
I'm guessing that I need to tell ember-cli-build to transpile this particular dependency before passing it on to the browser, but how do I go about doing that?
Thanks
For transpiling imported dependencies you need to run the imported file(s) through the broccoli addon broccoli-babel-transpiler. For a basic example, checkout this file: https://github.com/thefrontside/ember-impagination/blob/2fa38d26ef1b27a3db7df109faa872db243e5e4c/index.js. You can adapt this addon to an in-repo addon for your project.
See this link for the background discussion and #rwjblue and #cowboyd on the actual fix: https://github.com/ember-cli/ember-cli/issues/2949
Are you currently including Babel within your project? I would have thought that it checks your vendor directory the same as it does everything else and converts the ES6 code to ES5.
The other option would be to just convert the file to ES5 manually whenever you need to include a vendor file with ES6 syntax. Not necessarily ideal, but if it's a static file then it's something you'll need to do once and then forget about.

Compile unit tests in Adobe CQ5 CRXDE that reference Felix OSGI bundle JUnit code

I want to write some unit tests that run within Adobe CQ 5.4. I am doing what is described in this article for testing within CQ:
http://jtoee.com/2011/09/799/
However, after I create the unit test class in my Java code, it won't compile within CRXDE because it can't resolve the org.junit namespaces. I installed and activated the JUnit bundle in Felix as described (Apache Sling JUnit Core), but I am guessing there is something else I need to do in order for this active Felix bundle to be found in CRXDE. The Felix bundle in the CQ5 instance I am connected to shows these exported packages:
junit.framework,version=4.8.2
org.apache.sling.junit,version=1.0.7.SNAPSHOT
org.apache.sling.junit.annotations,version=1.0.7.SNAPSHOT
org.junit,version=4.8.2
org.junit.matchers,version=4.8.2
org.junit.rules,version=4.8.2
org.junit.runner,version=4.8.2
org.junit.runner.manipulation,version=4.8.2
org.junit.runner.notification,version=4.8.2
org.junit.runners,version=4.8.2
org.junit.runners.model,version=4.8.2
In this sample unit test code below, the last three import statements "cannot be resolved."
import org.apache.sling.api.resource.*;
import org.junit.*;
import org.junit.runner.*;
import org.apache.sling.junit.annotations.*;
#RunWith(SlingAnnotationsTestRunner.class)
public class MyUnitTest {
public ResourceResolver getResourceResolver() {
try {
return getResourceResolverFactory().
getAdministrativeResourceResolver(null);
} catch (LoginException e) {
fail(e.toString());
}
return null;
}
}
It is my novice understanding that the OSGI bundle installed in Felix should be accessible for me to reference in my Java classes using CRXDE, but it isn't happening for the JUnit bundle I installed. Why not? What do I need to do to get CRXDE to find the OSGI bundle reference and compile within CRXDE?
What you're doing looks correct at first sight.
Did you try restarting CQ after installing the required bundles? In theory that should not be required but I'm wondering if the bundle compiler is picking up the newly available packages correctly.
I have uploaded a content package with a similar simple example at http://dl.dropbox.com/u/715349/cq5-examples/junit-tests-1.0.zip (md5 2915123ad581aa225bd531247ea02878), after installing this package on a fresh CQ 5.4 instance the example test is correctly executed via http://localhost:4502/system/sling/junit/
You might want to try my sample and compare with yours.
Short Answer
The problem is not with CQ, the problem is with CRXDE. CRXDE automatically downloads and caches required jar files on your local machine so they don't have to be retrieved constantly from CQ.
If you switch to the 'Package Explore' navigation and then expand the project '{SERVER}{PORT}{HASH}' you should see a folder called Referenced Libraries. Right click and select Build Path >> Configure Build Path. From there you can add any dependencies you want into the project.
Long Answer
CRXDE is not a good tool for creating bundles. It is much better to create bundles through a full fledged IDE such as Eclipse and utilize Apache Maven as a build tool. Apache Maven can automatically manage your dependencies, run tests on your code and separate test vs. runtime dependencies.
That way you can avoid having to load dependencies that you don't really need such a jUnit into your OSGi console and you have more control over how your bundle is built and deployed.
Day has a really nice guide to getting you set up with building CQ projects with Eclipse.
http://dev.day.com/docs/v5_2/html-resources/cq5_guide_developer/ch04s02.html