where does nativescript look for modules? - nativescript

where does nativescript look for modules as I read in http://www.bennadel.com/blog/2169-where-does-node-js-and-require-look-for-modules.htm the order for nodejs is like this:
(I don't have problem with relative paths,the problem is when no file path is used)
1-First, Node.js looks to see if the given module is a core module then in node_modules in this order:
for example for var utils = require( "utils" ); it like this :
./node_modules/utils.js
./node_modules/utils/index.js
./node_modules/utils/package.json
what about in nativescript what is the order of locations it looks for modues?

Usually, you would just npm to manage all your dependencies from the project root. NativeScript uses commonJS, so npm is used to distribute plugins. You can find out more here.
There are a number of slightly different approaches:
NPM Modules:
So to add the Nativescript OAuth you would run npm install knock-knock-jokes --save in the project root and then in the app var knockknock = require('knock-knock-jokes') would work.
NativeScript Plugins:
For Nativescript specific plugins, you can run tns plugin add nativescript-oauth for most nativescript applications, this will keep all dependencies recorded in your package.json file also.
With TypeScript
Also, you might like to use TypeScript to enable IntelliSense etc. In which case the syntax would be more like import * as tnsOAuthModule from 'nativescript-oauth'; and if the module doesn't have a definition file shipped with it on npm, then you might like to use the typings which will manage your typescript definitions.

Related

CKEditor5 failing to build with additional plug ins

I'm struggling with CKEditor and perhaps some of you may be able to help me, please...
Summary
I'm attempting a custom build of CKEditor5 by following this guide - https://ckeditor.com/docs/ckeditor5/latest/builds/guides/development/custom-builds.html - The idea is to include plugins which aren't in the standard builds.
When I build the CKEditor build, push back to Github and then try and install the editor into my nodejs app (npm install from Github), the editor works, but without the plugins I've added.
Environment
Windows 10 Pro (20H2)
NVM installed to manage node versions
Node 14.6.0 used for CKEditor54 build
Node 10.22.0 used for NodeJS Project (latest supported version in the paltform I am developing for)
Steps Taken
Fork the CKEditor5 repo.
Clone the repo to my desktop using git clone -b stable https://github.com/<MyGithubUsername>/ckeditor5.git.
Navigate to the build directory cd D:\_source\ckeditor5\packages\ckeditor5-build-classic.
Run npm install.
I install the Font plug in to use it in this build: npm install --save-dev #ckeditor5/ckeditor5-font.
I then update the build configuration by adding to src/ckeditor.js:
import Font from '#ckeditor/ckeditor5-font/src/font';
ClassicEditor.builtinPlugins = [ ..., Font]
ClassicEditor.defaultConfig = { toolbar: { items: [' ..., fontColor, fontBackgroundColor'] } }
At this point, the guide says you should run yarn run build, but i can't get Yarn to work in this dev environment for love nor money, so instead I use npm run build.
I test the build by opening sample/index.html in the browser and it looks fine; the Font plugin is loaded and the toolbar items appear.
I then use Git to stage the changes, then I Commit and Push to my cloned repository.
In the Nodejs project where I want to use ckeditor, I install the custom build using npm install <MyGithubUsername>/ckeditor5#stable
To the project I add import ClassicEditor from '#ckeditor/ckeditor5-build-classic/build/ckeditor';
The editor appears as you would expect it to, but without the Font plug in.
Back over in the CKEditor local repo, when I take a look at the ckeditor5\packages\ckeditor5-build-classic\build\ckeditor.js.mapand search for ckeditor5-font I find many instances of it, indicating that it has indeed included it into the build. When I look at the same file in my Nodejs project D:\_source\NodeJsProject\node_modules\#ckeditor\ckeditor5-build-classic\build\ckeditor.js.map there's no sign of ckeditor5-font; the sample.html in the NodeJS project works, but does not show the Font additions, nor do they show in the implementation in my project.
I find my waround pretty well, but I am far from being a pro front-end developer and this has me stumped.
Any help or guidance is greatly appreciated.
Hello i have created demo video of ckeditor5 in angular that cover custom build from github and online builder
https://youtu.be/HsjCkvEvQhA
Tip. try to remove some plugin then it will work . remove one plugin at time and build and check it, this way you will find out which plugin creating issue
some plugin create conflict so you have to remove it .

Install a dependency and save to package.json for a sub-package in yarn workspaces

I am trying to use Yarn Workspaces for my app that I am splitting into multiple packages such that I can share code between the mobile and web version of the app. Let me explain what I am trying to do with an example.
Let's say I currently have a mobile app called awesome-app. I am refactoring it by taking out the shared code and creating three packages as follows:
awesome-web
awesome-mobile
awesome-shared
Let's say I want to add new functionality to awesome-mobile for which I have to install depA to awesome-mobile. How can I do that such that yarn only installs depA and updates the package.json for the awesome-mobile. I tried using command yarn package <package-name> add depA but it ended up installing all the dependencies again which I want to avoid.
Also, let's say I want to use awesome-shared in awesome-web. Is there a yarn command such that it installs and updates the package.json for awesome-web automatically. Currently, I do it by hand and then I do yarn install in the root folder which ends up installing all the dependencies again.

nativescript 5.1 and tns_modules folder in IOS build

I had this issue before with some app (N 4.1).
Now i'm doing another app, and i have the same issue :
First, im preparing build:
tns build ios --for-device --release --provision MY_Provision
Nativescript is doing build, so next i'm opening it in XCode, and doing some twaks like version number etc...
Lastly i'm doing "Archieve" and trying to Validate this archieve.
The result is error, in the previous app written in N 4.1 i had the same but with another plugin, and now validation throws: Invalid build structure - binary app/rns_modules.fstevents.lib/binding/Release/FILE NAME.
many errors regarding this folder.
So i've just removed this directory and done another archieve and validation - app passed the validation.
So, my question is - do i need such number of plugins in tns_modules ?
Or better question - is there any way to determine what is not needed ?
Or, am i doing something wrong when building an app ? As seems massive number of directories here and i'm wondering if maybe there is some kind of cleanup or something ?
For now, the only way to store an app is to validate first, check what is blocking validation, delete this, check if app works (:() and try again.
Thank you.
Below, attached, folder that is blocking validation and amount of dirs inside of tns_modules.
pacakge.json:
NativeScript CLI will prepare (i.e. copy) all packages declared in the dependencies section of your package.json (and their dependencies) in tns_modules. All devDependencies and their dependencies will not be copied to the native Xcode/Android Studio project.
So, all packages that are required only for building the application, should be installed as devDependencies. For example, such packages are nativescript-dev-webpack, nativescript-dev-typescript, etc.
Also, it looks like you have installed NativeScript CLI as a dependency of your project. By default, it should be installed globally, i.e. npm i -g nativescript. In case you omit the -g flag, npm will install it as dependency of your project.
You can try:
rm -rf platforms
npm un --save nativescript
Check package.json for other packages with -dev in their names and ensure they are in the devDependencies section.
After that run tns build ios --forDevice.

File not found when using FacebookSDK with React Native < 0.40.0

I'm using React Native 0.37.0 (because my project uses react-native-navigation which is yet to support RN >= 0.40.0) and attempting to use the Facebook SDK.
I've followed the instruction steps on react-native-fbsdk's npm page, fully; and double-checked to ensure everything is installed, all the search paths are added etc.
When running my project in XCode I get a Buildtime error in the RCTFBSDK library. In the file RCTFBSDKAppEvents.h: 'React/RCTBridgeModuke.h' file not found.
The import line in that file is the new syntax for React 0.40.0:
#import <React/RCTBridgeModule.h>
Is there anything that I can do to make these versions of frameworks play together? I need the navigation library and the facebook one, so until I find a solution I'm completely blocked.
Anything else I can share to support an answer, just ask.
Probably because you are running the latest version of react-native-fbsdk which only works with RN >= 0.40.
Try uninstall react-native-fbsdk:
npm uninstall react-native-fbsdk --save
Then, reinstall with an older version:
npm install react-native-fbsdk#0.4.0 --save

Karma and Jasmine installation without npm

I want to use Karma and Jasmine to test my AngularJS application. All of the documentation I've found to install Karma and Jasmine involve using npm. I can't use npm because I am restricted, the reason doesn't matter. So far I have pulled Jasmine and Karma from Github using zip files. I want to add Karma and Jasmine to my project, but I don't think unzipping the entire contents of the respective GitHub repos is the way to go.
I'd like to know what I need to make Karma and Jasmine usable within my AngularJS project without using npm.
I guess it is possible, but will take a huuuuuge amount of work because of the dependencies. If you take a look at karma's repository, you can find a file package.json (here). In this file there is a property dependencies (link), which lists the modules karma depends on. So you'll have to find their sources, manually download all of them with respective version number and put in the folder called node_modules created in the karma module folder. But each of these modules karma depends on also has dependencies listed in their own package.json - you'll have to download them too keeping in mind version numbers and putting them in module's node_modules folder. And this dependency nesting can be really really deep.
Some modules may have extra scripts to be executed after they have been installed (scripts), which are called by NPM by default on installation. Maybe there are some other things which I am not aware of. Generally speaking it was designed to be installed via NPM and it's rarely the case when someone has no access to use it.
I would advise to ask somebody who has access to NPM to do an install of required packages and share the result of installation with you. Everything will be installed in the node_modules folder of the directory you run NPM commands from, it would be easy to do.
Here you can download version I've created, it has karma v0.13.1, karma-jasmine v0.3.6 and karma-chrome-launcher v0.2.0. I hope it will work for you, because we might have different OS (mine is Ubuntu 14.04 x64), I'm not sure if NPM does something OS-specific while installation of any package.
You should place the content of the archive to your project directory, to execute tests from your project folder use a terminal command:
./node_modules/karma/bin/karma start
I would still advise to solve the problem of accessing the NPM if you want to closely work with modules it stores.

Resources