Hey friends! I'm migrating to the JS IR compiler and had a question: We previously had some "js in...
a
Hey friends! I'm migrating to the JS IR compiler and had a question: We previously had some "js interface tests" in our
jsTest
sourceset which would basically do something ugly like:
Copy code
js("""
  var assert = require('assert');
  var moduleUnderTest = require('myGroup-myModule');
  assert(moduleUnderTest.method("parameter") == expectedResponse);
""")
While a little janky, this kind of test let us verify that things like JsName were added where expected and that we didn't accidentally break the public API for our JS consumers. Now, under JS IR, the
require
for my module is failing, because there's no JS file in the expected path. There is a package.json though. Does anyone know how to get the module import working again under IR? I'd also be happy to replace this with a JS file (instead of using
js()
) that actually uses the final JS artifacts if anyone has an example of a project that does that! EDIT: it looks like I can remove the
require(…)
and get some stuff working, but not everything...
b
Yep, everything is in the same module scope with ir. Remember in js module == file
a
Running into weird issues for some test cases that I've removed the
require
for, where it's complaining that
com is not defined
(the object I'm trying to call is in
<http://com.org|com.org>.package.MyObject
) In others though, it works fine Hopefully I can figure that out…
b
Ah, you're still scoped in "submodule". For example, if your kt file is in package com.one, on js side for that file you're scoped to com{ one{}} js object already
👀 1
If you need to refer from something in parent or "cousin" packages, you'll need to grab reference to that in some kotlin val first
Just guessing here, though. So let me know how wrong I actually was.
To keep things simple I'd recommend keeping js tests in root package (i.e. no package declaration in kt)
a
Hmm so I tried removing the package declaration and it didn't fix it
Grabbing a reference via a kotlin val before the
js(…)
block does work, but the goal of the test cases is to make sure that the namespaces all line up with what's expected, so I'd prefer not to do it that way
Somehow using
_<http://.com.org|.com.org>.package.MyObject
does work, but I'm not sure where the
_
is coming from and when/why it's needed.. It doesn't look like it's needed in our actual JS project that consumes the kotlin JS artifacts Right now, I'm trying to just replace all my
var moduleUnderTest = require(…);
with
var moduleUnderTest = _;
to see if that fixes things
Update for anyone who runs into this in the future: things work after replacing
var myModule = require("my-module-name")
with
var myModule = _