I'm having trouble setting up my project to use a local meteor package instead of a "remote" one. The meteor package I'm trying to use locally is a copy of meteortesting:mocha (so I can put my own logs into it).
Here's what I've done:
Git cloned the meteortesting:mocha repo onto my machine
Copied the repo into my project root folder with cp -r [PATH]/meteor-mocha **.**
Set METEOR_PACKAGE_DIRS=./meteor-mocha
But when I run meteor add meteortesting:mocha (which is the name of my local package in ./meteor-mocha/package/package.js) it still adds the registered/online meteortesting:mocha package instead of finding my local one.
I also tried fooling around with the name of my local package (i.e. name:"meteortesting:mochalocal") to differentiate it, but when I ran meteor add meteortesting:mochalocal it gives the error "error: no such package"
Does anyone know why this may be the case? I based my set up on this article
I know I can also try to put it in ./packages, but I wasn't sure how to approach that with this repo because it's more than just a package.js folder.
UPDATE 9/12:
Here is what I've tried (which doesn't work) with adding my local package to ./packages:
You can use the ./packages folder inside your project. Copy the package folder inside this. Then you will have:
./packages/meteortesting:mocha
Or you can use another folder to your packages. Example:
/home/my_packages
Then set this:
METEOR_PACKAGE_DIRS=/home/my_packages
Then your package will be in this path:
/home/my_packages/meteortesting:mocha
Related
I have a mono repo and want to link a component library inside a package which contains this library as a dependency. But as we control this library and make changes, I want to be able to test it locally.
cd <library_path>
npm link
cd <monorepo_path>
npm link --workspace <target_package> <library>
When I execute find: find -name '<library>' I can find the library in the <target_package> node_modules directory as well as in the roots node_modules directory, which means the one in the <target_package> will take precedence, but this is the published one, not the linked one. The linked one lives in the root.
When I install my node_modules without linking the package, the library lives only inside the root node_modules.
I tried several things without success.
How can I override the workspace dependency temporarily to use the local library from npm link?
EDIT:
I found a temporary workaround in our webpack configuration with hardcoding which path to use for this dependency.
However, this is not a satisfying solution in my opinion.
I am working on a VueJS web app. One of the modules it uses is a wrapper for a javascript library installed through npm and packaged to integrate into vuejs. It does not quite fit our needs, we need to add some functionality to it, so I want to fork it and edit it.
The repo has two folders: src and dist.
As far as I understand, src is the actual src code while dist is a minified version for distribution. Questions:
If I want to edit it, how do I deal with the contents of /dist ? Do I delete it?
Do components installed through npm use the /src/ version or the /dist/ one?
If I delete /dist, work on the /src code, how do I recreate /dist based on the modified /src files?
Thank you.
Based on your questions, I would suggest you get a bit more familiar into your stack and how to actually build your appication.
Generally speaking the /dist folder contains automatically generated files, which may be uploaded to a webserver of your choice. Since you are using VueJS, you should be able to generate these files by running npm run build.
If I want to edit it, how do I deal with the contents of /dist ? Do I delete it?
As I already mentioned, these files are automatically generated by running npm run build. Therefore everytime you run this command, everything in /dist, will be automatically updated.
Do components installed through npm use the /src/ version or the /dist/ one?
Your working directory is always /src. Dependencies can be used like in any other application (this example uses Axios, which is a http client):
import axios from 'axios';
const httpClient = axios.create({ baseURL: 'https://api.something.com' });
httpClient.get(/* ... */);
If you are a beginner and are not 100% sure about how to use depencencies, I highly encourage you to read this article: An Absolute Beginner's Guide to Using npm
If I delete /dist, work on the /src code, how do I recreate /dist based on the modified /src files?
You do not have to delete anything in /dist. Simply running npm run build automatically will add the latest changes.
Please keep in mind that running npm run build is only relevant for your production environment. For your development environment you always want to use a dev server, which can be started with npm run serve.
I want to do something like this, where, I want to keep all my packages globally just like node package itself. So for example in my package.json I have a package name called "Highcharts" I want to install it globally I don't want to create a local node_modules folder and use it but I want to access it from outside so next time whenever I want to create a copy of my project folder I should be able to use highcharts directly without using npm install. Is it possible?
globally installed node_modules - > Users/user/AppData/Roaming/node_modules/highcharts
app
src
node_modules (I don't want to keep it)
package.json
tsconfig.json
angular.json
How to link these globally installed node_modules with the current app or any app which we want to create?
Any help will be appreciated. Thank you so much :)
local packages are installed in the project directory
global packages are installed in a single place in your system
Usually it is a good idea to have all npm packages required for your project installed locally (project folder). This makes sure, that you can have dozens of applications which are running a different versions of each package if needed.
export NODE_PATH='yourdir'/node_modules
Hello, if am getting right, you want to keep all dependencies global.
You can just run install with -g command. Those libraries will be available in node installation folder.
From the Node docs
If the NODE_PATH environment variable is set to a colon-delimited list of absolute paths, then node will search those paths for modules if they are not found elsewhere. (Note: On Windows, NODE_PATH is delimited by semicolons instead of colons.)
Additionally, node will search in the following locations:
1: $HOME/.node_modules
2: $HOME/.node_libraries
3: $PREFIX/lib/node
Where $HOME is the user's home directory, and $PREFIX is node's configured node_prefix.
These are mostly for historic reasons. You are highly encouraged to place your dependencies locally in node_modules folders. They will be loaded faster, and more reliably.
I hope I answered, you just need to manage the paths to node_modules wherever you have kept it.
I have a javascript application with eslint set-up and the needed Node modules, all in the same project folder. Node is only used so that eslint works.
The whole thing is pushed to GitHub and I'm noticing now the whole node-modules is getting uploaded with it (17mb approx), again I'm just using node for eslint only.
I feel like I'm doing something wrong and that I have set-up my project incorrectly. Should I be using .ignore here in git or something else, or I'm I overthinking this.
Thanks
Create a .gitignore file at the root of your project. Add node_modules to it. Remove the node_modules folder from your local repo. Recommit the changes. Then push up again.
Then run npm i on your terminal/command line to get the eslint packages back on your local computer. Now the directory will no longer be pushed on future commits.
You should use .gitignore for pushing redundant file to your repo here
https://git-scm.com/docs/gitignore
Here is the sample .gitignore file for Node from github
https://github.com/github/gitignore/blob/master/Node.gitignore
I am trying to get up and running with Meteor and seeing what it can offer, while I like it overall, it seems it's a very very rigid system.
I set up a small testing setup using Velocity, it opens a small overlay window on the side which has a class of "velocityOverlay". The overlay is really small and makes error stack traces wrap. All I wanted to do was to edit the css of the "velocityOverlay" and increase the width.
I somehow (after wasting time) managed to find that Meteor is actually putting all the packages in my user directory by default, once I found that, I found the needed css file...
velocity_html-reporter/.0.5.1.aykpxq++os+web.browser+web.cordova/web.browser/packages/velocity_html-reporter/lib/client-report.less.css
And I did a small edit to the width, next thing you know the meteor app crashes when trying to launch using the "meteor" command throwing a "Error: couldn't read entire resource" error. I can't even edit the bootstrap.css file I installed using "ian_bootstrap-3".
Further more, I can't find any way to install packages locally just for my particular project, what if I wanted to modify a package only for my particular project? this is very easy to do in vanilla Node.js, you simply don't use the "-g" when using "npm install".
To add to that, within my project root, there is another ".meteor/local/build/web.browser" folder with most of the global package files replicated again. When does Meteor use which? This is very confusing.
You can run a package locally very easily.
Download it from Github (for example) and put it in the packages/ directory of your application like this /packages/package_name.
Then add it to your application with the same meteor add package_name command as usual.
Meteor will automatically look in the local folder before anywhere else and compile the package with the rest of your code.
This allows you to do any modification you want on the package and test it locally before publishing it to the registry.
Also, folders located in .meteor/local/* are used for building purpose only and are generated automatically by Meteor. So it is not the best place to edit the files!
This worked for me https://atmospherejs.com/i/publishing. mrt link-package didn't work for me, might just be outdated code.
Steps:
Download (or clone) package from GitHub to local dir
Stop meteor if running
2.1. Make sure you have a packages folder: mkdir packages
Locally link your package:
3.1 If you have mrt installed: Run mrt link-package /path/to/package in a project dir
3.2 If you don't have mrt: ln -s /path/to/package packages/package
Then run meteor add developer:package-name, do not forget to change package name
Run meteor in a project dir
From now any changes in developer:package-name package folder will cause rebuilding of project app
Download the package and place it in new package directory in your project root.
open the package.js inside the downloaded package and remove the author's name in the property "name:"
e.g: - name:'dburles:google-maps' to name:'google-maps'
then run
meteor add google-maps