Replies: 12 comments
-
Not quite correct. When it comes to organization field, it only generates appropriate package.json#name value (@myorg/package-name). Modifying require statements in generated js code is only useful in legacy backend, because IR backend embeds all kotlin-js dependencies in generated js file already, so given the fact that legacy backend will go away soon, I don't think it's worth adding support for require tweaks in js files at this stage. As for versions, npm-publish automatically adds all relevant modules and versions from gradle's dependencies { implementation(npm("xxx", "version")) }. The reason it's excluding kotlin dependencies is the same as above, IR backend already embeds them inside generated js. For legacy mode it adds them via bundled dependencies, since most of the time kotlin js dependencies are not available on npm. To getter understand what's going on, run |
Beta Was this translation helpful? Give feedback.
-
Just to be clear, this was by no means me saying no to the idea, I'm just clarifying current behaviours and looking to hear your further thoughts if you still think something could work better, given the context. |
Beta Was this translation helpful? Give feedback.
-
Hello @mpetuska, sorry for my late answer.
I was astonished by this statement, expecially the "IR backend embeds all kotlin-js dependencies in generated js file already" part, so I experimented a little bit with that. But first of all, let me explain why I was astonished. So what's the actual functioning of the IR backend.
After a few try-and-error, and some readings, I ended up believing this is the correct setup for writing Node libraries in Kt. So I hope I was able to explain why I believe the feature above are important and why they will still be important for the IR backend. |
Beta Was this translation helpful? Give feedback.
-
This sounds like a TON of work, but if you're feeling brave I'm happy for you to implement it under some experimental config flag (disabled by default). The reason I'd like it under flag is that this would be a bit too invasive to user's config to leave as default behaviour, so having them to agree with it explicitly seems sensible. Also it's prone to break with each kotlin release as it would depend quite a lot on kotlin plugin's internals. |
Beta Was this translation helpful? Give feedback.
-
Also I'm still not convinced it's even possible to disable IR backend "bundling" of kotlin.js dependencies. Your experiment repo doesn't really have any libraries (just executables) |
Beta Was this translation helpful? Give feedback.
-
Hold on with the implementation a bit if you don't mind, I've asked JB guys to join this discussion to clarify the IR backend behaviours for us. |
Beta Was this translation helpful? Give feedback.
-
Well, actually not that much. It's slightly more than a find & replace in JS sources... or at least it works like that in `kt-npm-publish}.
That's the plan if you don't mind.
What do you mean by "libraries"? Do you mean dependencies?
No problem with that: I'm currently working on my PhD thesis, so the time for coding is pretty low. |
Beta Was this translation helpful? Give feedback.
-
Basically |
Beta Was this translation helpful? Give feedback.
-
Hey, just re-read your comments on reaktive discussion regarding this. Especially
I now get what you mean and agree that this is indeed a must for a plugin as most of the people scope the package to publish to GH. |
Beta Was this translation helpful? Give feedback.
-
Just had a go with reaktive lib setup for this and to be honest I didn't encounter any issues when importing scoped declarations without tinkering with generated js files, so I guess just modifying package.json is enough. |
Beta Was this translation helpful? Give feedback.
-
What did you tried exactly? Imho renaming of node project in js sources is hard when multiple interdependent KtJs projects must be renamed consistently to be published togheter. So if you have two projects, Issues may arise when one tries to import require('bar') instead of require('@org/bar') So, renaming of a module should step through the renaming of the package.json of that module, plus the renaming of that module in any other module of the same project which depends on it. This is a complex task indeed. However, if the renaming should just add an |
Beta Was this translation helpful? Give feedback.
-
Ah, I think I get the idea. Renaming is only needed for kotlin.js consumers of the module, and NOT the module itself, right? That actually gave me an idea. How about instead of tinkering with js files, we intercept webpack task and just declare kotlin.js dependencies as webpack externals (this is how pm dependencies are currently excluded from bundling). The problem then is that the module would only be able to see @JsExport declarations from that other kotlin.js module, therefore introducing a hard separation between modules. Finally, if you just rename references, that doesn't achieve anything as bar would still get bundled into foo js output and not declared in package.json. |
Beta Was this translation helpful? Give feedback.
-
Hello @mpetuska,
I'm trying to understand whether two relevant features of mine are currently supported by
npm-publish
.In case they are not, they could be my first actual contribution to your plugin!
Feature 1: Organizations
I see that
npm-publish
lets the user specify an organization for the generated JS project, via the following syntax:What's the actual semantics of this statement?
I would expect this makes the generated
package.json
contain a field of the form"name": "@my.org/<projectName>"
.Is my intuition correct?
Furthermore, to make this coherent with NPM packaging, I would also expect this statement to make any other JS sub-project generate JS code contain statements of the form
require("@my.org/<projectName>")
instead ofrequire("<projectName>")
.Is this the case?
My plugin,
kt-npm-publish
does not technically provide anorganization
field, yet it does provide an easy way to alter the generated JS code, in order to inject organizations into it.Would a similar feature be useful in
npm-publish
?Feature 2: Automatic conversion of generated dependencies from local to general
Currently, the JS/NPM transpiler generates
package.json
files where dependencies are in the "local" form:whereas NPM publishing requires dependencies to be in "general" form:
Ideally, any plugin should provide an easy way to automatically switch from local to general form, without having to specify versions or package names explicitly---which would be redundant w.r.t. ad-hoc section of the
build.gradle(.kts)
files.Is this currently supported by
npm-publish
?To the best of my understanding, you currently only support the removal/retaining of dependencies by name, or the hard-coding of a particular dependency, given its name and version---which should therefore be explicitly represented.
Is my intuition correct?
Beta Was this translation helpful? Give feedback.
All reactions