Ceylon modules in different versions? - ceylon

I'm trying to make a simple app that utilizes the ceylon.http.server, ceylon.json, ceylon.io modules.
When I compile, I get these errors:
Error:(4, 8) ceylon: source code imports two different versions of module 'com.redhat.ceylon.langtools.classfile': version '1.3.1' and version '1.3.2'
Error:(4, 8) ceylon: source code imports two different versions of module 'com.redhat.ceylon.model': version '1.3.1' and version '1.3.2'
Error:(4, 8) ceylon: source code imports two different versions of module 'com.redhat.ceylon.common': version '1.3.1' and version '1.3.2'
Why do I get them? I thought Ceylon could handle utilizing the same module in different versions. In the Ceylon tour, Packages and modules it explicitly says "A runtime that features module isolation and the ability to manage multiple versions of the same module".
My module.ceylon looks like this:
native ("jvm")
module server "1.0.0" {
import ceylon.http.server "1.3.2";
import ceylon.json "1.3.2";
import ceylon.io "1.3.2";
}
My (only) source file runServer.ceylon looks like this:
import ceylon.http.server { ... }
import ceylon.io { ... }
"Run the module `server`."
shared void runServer() {
//create a HTTP server
value server = newServer {
//an endpoint, on the path /hello
Endpoint {
path = startsWith("/hello");
//handle requests to this path
service(Request request, Response response) =>
response.writeString("hello world");
}
};
//start the server on port 8080
server.start(SocketAddress("127.0.0.1",8080));
}

Your example code works for me. Is it possible that you are trying to compile this with Ceylon 1.3.1? I think the three modules in the error message are all dependencies of the language module, so I suspect that ceylon.http.server and the other imported modules pull in ceylon.language/1.3.2 and your compiler adds ceylon.language/1.3.1.

Related

Import vue-i18n and vue-flag-icon in Vite Vue 3 project

I built my Vue 3 project with Vite. I was in need of some plugins for my app. I have tried importing both of them. I have installed both with npm i vue-i18n vue-flag-icon and tried importing both of them independently.
// In main.js
import VueI18n from 'vue-i18n' // error
This gives the following error:
main.js:4 Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/vue-i18n.js?v=4951897a' does not provide an export named 'default' (at main.js:4:8)
// In main.js
import FlagIcon from 'vue-flag-icon' // error
This crashes the app with the following error:
[[ERROR] Could not resolve "./icon/Flag"
node_modules/vue-flag-icon/components/index.js:1:17:
1 │ import Flag from './icon/Flag'
╵ ~~~~~~~~~~~~~
I have tried both of these in a non-Vite project with the standard vue-cli and it works flawlessly. Is there something I need to do for it to work with Vite?
I fixed the first import by using this line:
// In main.js
...
import {createI18n} from 'vue-i18n' // no error
// Whereafter I can use the function I need to set the plugin.
const i18n = createI18n({
locale: 'en', // set locale
fallbackLocale: 'nl', // set fallback locale
messages, // set locale messages
}
createApp(App).use(i18n)
...
I understand that I imported the function to make an instance of I18n instead of importing the whole object. But I do not understand why that works or why I would need to do that.
I also have no idea the second plugin doesn't work, I have heard that Vue 2 plugins don't work on Vue 3 and that plugin is 5 years old, so I assume it's made for Vue 2. Anyways, that doesn't explain why it works with vue-cli.

JavaScript import statements running code

I'm trying to diagnose a problem thats recently arisen for us, after upgrading our suppported browser (~40 -> ~60)
We have this effective code in an external (now unsupported) library, that sits in an iffe:
(function(window, undefined){
# external library
if(!window.terribleIdea){
window.terribleIdea = {}
}
<some code>
if(!window.terribleIdea.config.url){
window.terribleIdea.config.url = 'the wrong url'
}
localStorage.set('somethingImportant', getStuff(window.terribleIdea.config.url))
})( window );
Now we did have a bootstap type file that looked like this:
# appBootstrapper.js
import applyConfig from './app/configApplier';
import ALL_ANGULAR_MODULES from './app'; # contains angular.module set up for
# app and every dependency
fetchConfig()
.then(applyConfig)
.then () => angular.bootstrap(document, [ALL_ANGULAR_MODULES])
.catch( error => {
alert(`It borked: ${error.message}`)
});
Amongst other things applyConfig does:
window.terribleIdea = {
config: {
url: 'not terrible'
}
}
What now happens, is that the import statement of ALL_ANGULAR_MODULES ends up running the code in the external library, and setting local storage. What we think used to happen is that it was only called on angular.bootstrap running.
Now what I need to find out is, has the functionality of the import statement changed in a later version of chrome, or has it always been running this code and gone unnoticed?
All I can find is references to Dynamic Imports, and the order of scripts running, in <script></script> tags.
It is hard to debug without access to the project (see discussion in comments above). Here are some possibilities worth exploring while encountering such issues. It is of course possible that it was like this all along.
Change in the bundler configuration. Webpack accepts entries as arrays, and order matters in them.
Change in the way the bundler/dependency manager reacts to dynamic imports
Change in the way your application loads its dependency during the its bootstrap phase. It is not (imo) angular specific, as many app use some kind of "componentization" which translates in files executed in a different order they are imported (as they may only export constructors or whatnot).

Importing json file into angular 4.x TypeScript application

Lets say I've got the following json file (root of angular application):
{
"propertyName": "ABC"
}
I know that TypeScript cannot handle JSON imports directly so I delcared the following module according to TypeScript module documentation using wildcard (typings.d.ts):
declare module "*.json" {
const value: any;
export default value;
}
Now I am able to import a local json file (structure above) like this:
import * as config from './config.json';
After that I am able to use any property of the import like this:
let propertyA: string = (<any>config).propertyName;
Everything is fine, but when I try to use
let propertyA: string = config.propertyName;
I get the following error message:
ERROR in src/main.ts(9,26): error TS2339: Property 'propertyName'
does not exist on type 'typeof "*.json"'.
Any suggestions how to avoid this error during build process? The process finished successfully (including this error message) and I'm able to use the web application and also the needed property. It just generates an error message
I've had a similiar problem, since it's a json file, doesn't have a module and doesn't need to be compiled you can import it like it would be in javascript.
const config = require('./config.json');
There won't be any any error accessing the config attributes then and it still be working fine.
Remember you may need to import the #types/node package in order to use the require method.

Jenkins: import external package from Jenkinsfile using declarative syntax

I had a groovy code wich contains "import groovy.json.JsonSlurper".
I have spent a day testing and i dont know how to load external libraries using declarative syntax.
This is my code:
pipeline {
agent any
import groovy.json.JsonSlurper
stages {
stage("test") {
steps {
}
}
}
}
I have read the jenkins documentation, and i have tried to use the next but without success:
#Grab('groovy.json.JsonSlurper')
import groovy.json.JsonSlurper
both import and #Grab is not recognized. Some idea?
Thanks!
What #Daniel Majano says is true about the import syntax, but the #Grab syntax I found holds differences of behavior between a Pipeline script maintained directly in Jenkins vs Pipeline script from SCM.
When I placed a Grab command in the Pipeline script for a tester pipeline job I found that it didn't make any difference whether the Grab command was there or if it was commented out.
However when used from a Pipeline script from SCM it would throw the following exception...
java.lang.RuntimeException: No suitable ClassLoader found for grab
I removed it from the SCM script and everything worked out in the end.
Additional Background
I'm not sure why the grab was choking in the SCM version, but there's definitely some working parts to the groovy editor because if you define a partial grab command it will give you some validation errors pointing to the broken line as you see in the red X box below, with the error The missing attribute "module" is required in #Grab annotations:
Therefore the script validator is aware of the Grab annotation as it calls it and that it has both a group and module attribute. I'm using the so called shorthand notation in this example.

Using JUnit in Jython - NameError for assertTrue

Environment Details
Mac OS X 10.9
Oracle JDK 1.7.0_55 64-bit
jython-standalone-2.5.3.jar
junit-4.11
What I have done so far
I have added the junit jar to /Library/Java/Extensions.
I invoked Jython as follows java -jar jython-standalone-2.5.3.jar
In the Jython interpreter, I imported the following import org.junit.Assert, and this import was successful.
Problem
When I tried to use assertTrue, I got a NameError in the interpreter. Why is this so?
I understand that assertTrue is a static method. Not sure what implication this has when I try to use it in Jython.
Additional Context
I am using XMLUnit in Jython. Was able to successfully import the Diff class from org.custommonkey.xmlunit in Jython. Also able to use the methods in this class, and call them on a Diff object. The result of this method call is what I am trying to pass to assertTrue, when it throws the error.
from org.custommonkey.xmlunit import Diff
import org.junit.Assert
xml1 = ...some XML string...
xml2 = ...some XML string...
myDiff = Diff(xml1, xml2)
assertTrue(myDiff.similar())
Hope this additional information is useful in identifying a solution to this problem.
Latest Status
I narrowed it down to setting this property python.security.respectJavaAccessibility = false, since the Assert() constructor is protected.
Still trying to get it to work. Any help is greatly appreciated.
Figured it out.
In addition to junit.jar file, the hamcrest-core.jar file also needed to be copied to /Library/Java/Extensions.
Then I got rid of the jython.jar file, and instead installed it using the jython installer.
After the installation was completed, I updated the registry file in the installation folder, specifically setting this property python.security.respectJavaAccessibility = false.
Now I am able to see the assertTrue method, and no longer getting a NameError.