Is there an effective way to include a local npm d...
# javascript
s
Is there an effective way to include a local npm dependency in a gradle build?
a
cc @snrostov
d
👀
s
What does you mean by
local
npm dependency?
you can create gradle subproject, and add dependencies between subprojects. Kotlin Gradle JS plugin will link them together using
yarn
workspaces.
d
I have a
library-version.tgz
file that I need to include as dependency.
Also, while we're on this topic, I also need to be able to specify plain http urls. Like
yarn add
supports. When I do
npm("http://....../package.tgz", "")
,
@
gets appended to the end of the resolved dependency, causing resolution to fail.
s
This looks like a bug, let me check…
@Dominaezzz This works for me:
Copy code
implementation npm("@fancyapps/fancybox", "<https://github.com/fancyapps/fancybox#3.0>")
So, in your case it should be something like this:
npm("package", "http://....../package.tgz")
Does it work for you?
d
Let me try.
Okay, that works. The dependency shows in the gradle window with
implementation(npm("@olm/olm","<https://packages.matrix.org/npm/olm/olm-3.1.0.tgz>"))
.
Although, I can't seem to get this to work.
Copy code
js("""
global.Olm = require('olm')
""")
I get
Copy code
Error: Cannot find module 'olm'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at test (/home/dominaezzz/IdeaProjects/MatrixKt/olm/src/jsMain/kotlin/sample/SampleJs.kt:13:22)
    at SampleTestsJS.testHello (/home/dominaezzz/IdeaProjects/MatrixKt/olm/src/jsTest/kotlin/sample/SampleTestsJS.kt:11:9)
    at /home/dominaezzz/IdeaProjects/MatrixKt/build/js/packages/MatrixKt-olm-test/kotlin/MatrixKt-olm-test.js:60:38
    at Object.fn [as test] (/home/dominaezzz/IdeaProjects/MatrixKt/build/js/packages_imported/kotlin-test-nodejs-runner/src/KotlinTestRunner.ts:12:25)
    at Object.test (/home/dominaezzz/IdeaProjects/MatrixKt/build/js/packages_imported/kotlin-test-nodejs-runner/src/KotlinTestTeamCityReporter.ts:80:28)
    at test (/home/dominaezzz/IdeaProjects/MatrixKt/build/js/packages_imported/kotlin-test/1.3.41/src/main/kotlin/kotlin/test/TestApi.kt:57:15)
I'm not sure if it's because of the dependency resolution or not. 🤷🏼
s
I guess you should write
require('@olm/olm')
instead of
require('olm')
d
Oh, that did the trick. 😅 I'm new to npm and JS.
s
@snrostov Just seeing the response to this. I appreciate you getting back. What I meant by
local
was a js lib that I had written. I was trying to figure out how to include it as an npm dependency. So it would be properly resolved through
@JsModule
Without looking, npm allows for
file
resolution in
package.json
from what I remember.
npm()
didn't seem to allow for that.
Btw, thank for very much for all the work on this.
☝🏼 1