NativeScript / nx

NativeScript for Nx.
Other
64 stars 17 forks source link

What is the recommended method to add nativescript plugin #17

Closed mahmoudajawad closed 3 years ago

mahmoudajawad commented 3 years ago

When an NS app is created using this Nx plugin, it creates app-specific packages.json file inside the app folder. Assuming I'm going to install nativescript plugins to be used in the app using npm, which packages.json file should be modified for that?

On another instance, how can I use NS CLI to add plugins to apps in Nx workspace? Where the CLI would add the package, and is it the best practice for both NS and Nx?

NathanWalker commented 3 years ago

@mahmoudajawad This is a topic that comes up often. Generally Nx approach prefers to manage all dependencies at the root package.json. This typically works well and usually you could even share those root level package dependencies via file ref's to various app packages. However webpack5 does not currently like file referenced dependencies (those like "file: ../../etc.."). We've been exploring various configurations with webpack5 which may play well still with file ref'd deps as although it may look ugly it's quite useful in practice. We're also exploring the ability to not even have to define package dep's of {N} apps in their own package by utilize webpack to pull naturally from even the root package.json.

Currently you will want to manage your dependencies at the root for the workspace in general and can configured package dep's in the {N} app as well. This will likely shift in the coming weeks as webpack5 is evolving fast.

mahmoudajawad commented 3 years ago

That's verbose and I appreciate. Also, what about using NS CLI to add plugin? Do I use ns add plugin X as usual or do I do something different?

NathanWalker commented 3 years ago

@mahmoudajawad You can cd apps/nativescript-yourapp and use ns add plugin X as usual or you can install a plugin in root and share it up and install with npm directly into the app. Flexibility in that regard for whichever fits your case there.

mahmoudajawad commented 3 years ago

I see. That's where I failed as I didn't try to run the command from the app folder, but root.

Would you welcome a quick PR to point this out in README? I do think adding it is worth it as huge part of NativeScript is its amazing eco-system of plug-ins and libs.

mahmoudajawad commented 3 years ago

@NathanaelA, what do you think of this: https://github.com/mahmoudajawad/nx/commit/5468e2cee76b572bef33e036ed3a9b816c40d84d

Also, I added some notes about versions as one of the biggest challenges I usually come across with any nativescript written-material is the inability to figure out the correct version-pool for the different parts of the structure.

mahmoudajawad commented 3 years ago

An update to using both the approaches: It seems that plugins that require pods (iOS) don't seem to work if installed at root-level, but fine on app-level. For instance, I tried installing both:

@nativescript/background-http
nativescript-websockets

at root-level, which rendered an error with nativescript-websockets. Afterwards, I installed it at app-level and it worked fine. I just want to be clear that I didn't clear nativescript app folder (npx nx run nativescript-<app-name>:clear) before re-running the app.

NathanWalker commented 3 years ago

@NathanaelA, what do you think of this: mahmoudajawad@5468e2c

Also, I added some notes about versions as one of the biggest challenges I usually come across with any nativescript written-material is the inability to figure out the correct version-pool for the different parts of the structure.

Thank you - left couple quick comments there and with those changes a PR would be much appreciated.

An update to using both the approaches: It seems that plugins that require pods (iOS) don't seem to work if installed at root-level, but fine on app-level. For instance, I tried installing both:

@nativescript/background-http
nativescript-websockets

at root-level, which rendered an error with nativescript-websockets. Afterwards, I installed it at app-level and it worked fine. I just want to be clear that I didn't clear nativescript app folder (npx nx run nativescript-<app-name>:clear) before re-running the app.

This is something we've been investigating as well. We believe it's related to npm 7 or webpack5 or cli (or all the above). Anticipate having that triaged this month because that should work the same whether coming from root package or app's package but you are correct right now that if a plugin contains platforms folder with native includes, the plugin must be added to app package.json at moment.

mahmoudajawad commented 3 years ago

Closed by #22.