Provided dependency from project (Gradle) - android-studio

How can we declare a dependency as provided from another module? i.e. something like:
dependencies {
compile 'javax.persistence:persistence-api:1.0'
provided 'com.google.code.gson:gson:2.5'
}
but instead of pulling dependency from a repo, I want to include a project in another project. I would expect something like this to work:
dependency {
compile 'javax.persistence:persistence-api:1.0'
provided project(':mymodule')
}

Gradle does not have a built in provided scope/configuration. You can define your own provided configuration. See here: https://stackoverflow.com/a/34899917/745574
But in your case, you do not really need it. As long as mymodule is already in settings.gradle, just include your module as:
compile project(':mymodule')

Related

Importing the correct Wasi module in node.js

I've been stuck on something for some time now. I'm trying to use WebAssembly from Node.js, but in order to do that, I need NodeJs to instantiate a Wasi object. This is implemented here: https://github.com/nodejs/node/blob/master/lib/wasi.js and the documentation is here: https://nodejs.org/api/wasi.html
It is imported through import { WASI } from 'wasi';
But I have no idea how to access the correct wasi implementation, when I add wasi to the dependencies it will install https://www.npmjs.com/package/wasi which is an old user implementation which I don't need. It also does not conform the API documentation from above, it is not usable. My IDE's (WebStorm) code inspection features act as if it is the correct implementation, but when executing the code, it becomes clear it's using a wrong implementation.
If I don't install any at all package I get Cannot find package 'wasi' imported from ...
So the question is, how do I use the WASI class declared in https://github.com/nodejs/node/blob/master/lib/wasi.js?
The solution is to include the command line argument --experimental-wasi-unstable-preview1 when running node! (noted underneath the code example in https://nodejs.org/api/wasi.html)
Ex: node --experimental-wasi-unstable-preview1 index.js

Kotlin/JS — Compile a JS library with types defined in NPM dependency

I’m trying to write a library using the new Kotlin/JS IR compiler. Specifically, I want to write the library using Kotlin, but to publish it as a NPM package to be used in a Typescript/Node project.
I have a NPM dependency in the project defined which already has TS types defined and a readily available.
To allow the library to work smoothly together with using it in tandem with this dependency in a project it would make sense to use the already defined TS types when available.
As an example, I want to define a function in my library foo(message: Message) where Message is actually a type coming from the NPM dependency.
What I hoped to be able to achieve would be an output where the generated types in my compiled output contained something like this:
import * as someDep from 'some-dependency'
export namespace foo.bar.baz {
function foo(message: someDep.Message): void;
}
However, I haven’t been able to get this done. Instead, the Message is simply just there as an undefined type, meaning the d.ts file is essentially broken.
For an example of a simple project which tries to do what I’m asking about see: GitHub - jsfr/sample-kotlin-js
Here I create a simple abstract class named Consumer which should be able to take a Message type from the external google-protobuf NPM library. However, in the resulting d.ts file the Message is present with no definition of itself.
Is what I’m trying to do here possible or is there some other approach I should take instead? This seems like an important thing to be able to do for good interoperability.

Hilt dependency implementation in multi-module development

I have created a module named dependencies where I have put all depConstraints I need so I don't have to implement the dependency in each module individually.
I have added Hilt dependencies in my depConstraints'sgradle file but when I want to use Hilt in another module I get the following error
Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found.
Is there a way to use the depConstraints module's dependencies in my other modules (for example app module) without implementing them individually in each module's scope?
This error may not mean what it says. It pops up when anything with gradle files is wrong and obscures the real error.
Try to comment out hilt plugin import and hilt block (if exists) inside build.gradle file, then Sync Project with Gradle files - most of the time there will be another error.
I spent so much time thinking hilt was the issue, but actually it never was.

How can I include additional modules in a NodeJS custom binary?

I am building a custom binary of NodeJS from the latest code base for an embedded system. I have a couple modules that I would like to ship as standard with the binary - or even run a custom script the is compiled into the binary and can be invoked through a command line option.
So two questions:
1) I vaguely remember that node allowed to include custom modules during build time but I went through the latest 5.9.0 configure script and I can't see anything related - or maybe I am missing it.
2) Did someone already do something similar? If yes, what were the best practices you came up with?
I am not looking for something like Electron or other binary bundlers but actually building into the node binary.
Thanks,
Andy
So I guess I figure it out much faster that I thought.
For anyone else, you can add any NPM module to it and just add the actual source files to the node.gyp configuration file.
Compile it and run the custom binary. It's all in there now.
> var cmu = require("cmu");
undefined
> cmu
{ version: [Function] }
> cmu.version()
'It worked!'
> `
After studying this for quite a while, I have to say that the flyandi's answer is not quite true. You cannot add any NPM module just by adding it to the node.gyp.
You can only add pure JavaScript modules this way. To be able to embed a C++ module (I deliberately don't use the word "native", because that one is quite ambiguous in nodeJS terminology - just look at the sources).
To summarize this:
To embed a JS module to your custom nodejs, just add it in the library_files section of the node.gyp file. Also note that it should be placed within the lib folder, otherwise you'll have troubles requiring the module. That's because the name/path listed in node.gyp / library_files is used to encode the id of the module in the node_javascript.cc intermediate file which is then used when searching for the built-in modules.
To embed a native module is much more difficult. The best way I have found so far is to build the module as a static library instead of dynamic, which for cmake(-js) based module you can achieve by changing the SHARED parameter to STATIC like this:
add_library(${PROJECT_NAME} STATIC ${SRC})
instead of:
add_library(${PROJECT_NAME} SHARED ${SRC})
And also changing the suffix:
set_target_properties(
${PROJECT_NAME}
PROPERTIES
PREFIX ""
SUFFIX ".lib") /* instead of .node */
Then you can link it from node.gyp by adding this section:
'link_settings': {
'libraries' : [
"path/to/my/library.lib",
#...add other static dependencies
],
},
(how to do this with node-gyp based project should be quite ease to google)
This allows you to build the module, but you won't be able to require it, because require() function in node can only be used to load built-in JS modules, external JS modules or external dynamic node modules. But now we have a built-in C++ module. Well, lot of node integrated modules are C++, but they always have a JS wrapper in /lib, and those wrappers they use process.binding() to load the C++ module. That is, process.binding() is sort of a require() function for integrated C++ modules.
That said, we also need to call require.binding() instead of require to load our integrated module. To be able to do that, we have to make our module "built-in" first.
We can do that by replacing
NODE_MODULE(mymodule, InitAll)
int the module definition with
NODE_BUILTIN_MODULE_CONTEXT_AWARE(mymodule, InitAll)
which will register it as internal module and from now on we can process.binding() it.
Note that NODE_BUILTIN_MODULE_CONTEXT_AWARE is not defined in node.h as NODE_MODULE but in node_internals.h so you either have to include that one, or copy the macro definition over to your cpp file (the first one is of course better because the nodejs API tends to change quite often...).
The last thing we need to do is to list our newly integrated module among the others so that the node knows to initialize them (that is include them within the list of modules used when searching for the modules loaded with process.binding()). In node_internals.h there is this macro:
#define NODE_BUILTIN_STANDARD_MODULES(V) \
V(async_wrap) \
V(buffer) \
V(cares_wrap) \
...
So just add the your module to the list the same way as the others V(mymodule).
I might have forgotten some step, so ask in the comments if you think I have missed something.
If you wonder why would anyone even want to do this... You can come up with several reasons, but here's one most important to me: Those package managers used to pack your project within one executable (like pkg or nexe) work only with node-gyp based modules. If you, like me, need to use cmake based module, the final executable won't work...

Create package that references another package in solution

I often have this situation:
Foo.sln
Foo.csproj
Foo.Wpf.csproj
Then I create:
A nuget package Foo.nupkg
A package for Foo.Wpf.nupkg referencing Foo.nupkg.
I could not find out how to specify that dependency in the docs.
Just create a paket.template for each project and make sure you set the "type" property to "project". Paket will figure things out automatically for you
Edit:
Sample:
Foo.sln
Foo.csproj
paket.template
Foo.Wpf.csproj
paket.template
Where the paket.template files looks like this:
type project
// This assumes that Author and Version are specified in the project.
If you want to override the defaults check out the docs

Resources