I’m trying to use Kotlin for firebase functions. I...
# javascript
s
I’m trying to use Kotlin for firebase functions. I’m getting problems because Kotlin is exporting other keys as well, which makes firebase throw an error. Here are the additional keys it has that it shouldn’t:
Copy code
$$importsForInline$$,com,firebase
Firebase basically expects a node file with only firebase functions exported. How can I achieve this?
t
com
,
firebase
- package names?
a
I don't think there is a way to limit exports in the Kotlin/JS compiler output. What you could do is have all the functions you want to export in a separate module. I am not familiar with firebase, but I suppose splitting code into a few JS modules shouldn't be an issue for it. Am I wrong?
t
I don't think there is a way to limit exports in the Kotlin/JS compiler output.
It can be modified via Webpack configuration.
If package is problem - it can be "removed" via webpack
output.libraryExport
property or via Gradle plugin - https://github.com/turansky/kfc-plugins#component
a
Thank you for pointing this out. Doesn't this solve a different issue though? Correct me if I'm wrong, but it seems that
output.libraryExport
may be used to modify the package (
require('foo').org.blah.A
->
require('foo').A
), but cannot be used to remove some exports, while keeping the others. I suspect there should be some JS tool to remove some exports from a module, but I don't think that's it.
If you don't need to test those "additinal functions" you could make them
internal
and pass the
-Xfriend-modules-disabled
flag to the compiler. That would prevent the compiler from exporting
internal
declarations.
t
but cannot be used to remove some exports
@anton.bannykh I have example for this theme. I use DCE to keep only required, but in common case
output.libraryExport
does the same job. Example
Copy code
// exported
aaa.ComponentA
bbb.ComponentB
ccc.ComponentC
+
Copy code
output.libraryExport = ["bbb"]
=
Copy code
// exported
ComponentB
https://github.com/turansky/kfc-plugins/tree/master/examples/component-extension
🆒 1
🙏 1
🆗 1
i
@spierce7 So, if TL;DR you can put all necessarily declarations on one package
org.example
And then you can tell webpack to export only this package via
output.libraryExport=['org', example']
, it means that your object will contain only declarations from package
org.example
You can set
libraryExport
manually with
webpack.config.d/library.js
:
Copy code
// it will be redundant in 1.3.70
config.output = config.output || {}
config.output.library = <module-name>
config.output.libraryTarget = 'umd'

// it is necessary both before 1.3.70 and in 1.3.70
config.output.libraryExport = ['org', example']
s
Does the node.js application packaging use web pack?
i
No, nodejs has no bundle yet, we have feature request, you can describe your use case here https://youtrack.jetbrains.com/issue/KT-35620 Seems that it makes sense (not sure that webpack, but maybe some analogues for js packaging)
a
@turansky My bad, thank you for clarifying how it works! 🙂 🙏
i
but in common case
output.libraryExport
does the same job.
@turansky I just want to tell about difference, that it is correct only for export, you’re right, that from export point of view effect is the similar, but the main difference, that in fact
libraryExport
don’t remove signature, and they are in the code anyway, but DCE really remove declarations, and reduce file size
👌 1
t
s
@Ilya Goncharov [JB] Is how the app behaves in terms of exports going to change in 1.4? I remember hearing that right now it’s assumed that everything is open and can be accessed, and in 1.4 its assumed everything is closed except explicitly annotated otherwise My problem is that kotlin packages are being exported. Is that changing in 1.4?