A loooong time ago I had tried building Chrome ext...
# javascript
e
A loooong time ago I had tried building Chrome extensions with K/JS. Now that we have file-to-file output it's worth trying again, should definitely be straightforward
a
Please report back how it goes
e
@andylamax I'm not sure if I'm missing some pieces but I can't make it output a .js file for each .kt file.
But there is one major problem. Being each extension file must be of type executable, you end up with multiple
main
functions, which are reported as conflicting.
@Artem Kobzar I'm not entirely sure on how the compiler works, but would allowing multiple
main
functions (one per file in case of
PER_FILE
granularity) be even possible?
I also get:
Module not found: Error: Can't resolve './background.mjs'
With the following structure:
a
Well, @Artem Kobzar said its not a full ready to use feature, so I guess a few things won't be working
a
So, right now, 1.9.20 has a problem with the main function. I've already merged a fix for this behavior, but it will be available only with the first betta of 2.0
✔️ 1
e
I guess I'll postpone trying this out to 2.0 then! Hopefully it will work with K1 too.
A question tho: in the above example the file with
main
didn't get the name I applied with
JsFileName
, and instead kept the module one. Is this expected? Name is `kjs-chrome-estension`but I did apply
JsFileName("plugin")
a
It will work with K1.
gratitude thank you 1
So, @JsFileName is applied only to the file with which you use it. The
kjs-chrome-extension.mjs
is a proxy file that exports all the JsExport declarations and runs all the module effects. To rename this file, I believe, you should use `moduleName`:
Copy code
// build.gradle.kts

...

js {
  moduleName = "plugin"
  ...
}

...
e
Yes I'm using it to rename some of my Node.js modules, that's it then. So basically the entry point is unaffected by
JsFileName
, got it.
mmh not sure how this would work in the case of a Chrome extension. I don't think we can make it work with a single module and per file compilation
a
It's okay. Only the main module will be renamed and I believe it should work for you even if other modules will use effects and exports
e
@Artem Kobzar thanks! One last thing I've noticed is that
JsFileName
enables you to change the target directory. This is valid for example:
JsFileName("../another/name")
It is definitely useful to detach the target dir from the package name, but probably it should be implemented as a separate annotation. Or it should be easier to specify "relative to the root dir"
a
Oh, I believe this is not something we want to add with this annotation. Thank you for noticing it. I'll change the behavior
✔️ 1
e
So basically you'll add name validation. Not a big lost functionality, but yeah I liked defining the target path