I have very little experience with nodejs/typescript/visual studio development, and could use some advice and directions.
I'm starting a new vs2015 solution to develop several nodejs scoped modules.
My questions are:
How should I structure my project folders?
Is there a particular toolchain or workflow I should use?
Here's what I've hacked together so far:
The project seems to compile and run fine, but there were quite a few issues:
When something changes in #product/core, #product/analysis did not pick it up
Typescript error: Member not found
npm install/update does not work
Have to manually delete node_modules followed by "npm install"
Deleting/reinstalling node_modules gets past typescript compiler errors
But then Resharper has problem picking it up, unless I unload/reload the project
Have to manually delete node_modules followed by "npm install"
This is the way to go. I feel like these IDEs should support sync like atom-typescript does : https://github.com/TypeStrong/atom-typescript#sync and so does alm : https://basarat.gitbooks.io/alm/content/features/typescript.html#sync
Sadly the sync version of VS is a restart / a big enough fs change at the moment.
Related
I'm trying to write an npm package that will be published and used as a framework in other projects. The problem is -- I can't figure out a solid workflow for working on it at the same time as working on projects that depend on it.
I know this seems super basic and that npm link solves the issue, but this is a bigger one than just being able to import one local package from another.
I have my framework package scaffolded out; let's call it gumby, It exports a function that does console.log('hello from gumby'). That's all that matters for right now.
Now I'm ready to create a project that will use gumby. Let's call this one client. I set that up too and npm link gumby so client can import from it, etc. OK cool, it's working as expected.
So now it's time to publish gumby. I run npm publish and it goes out to npm as version 0.0.1.
At this point, how do I get the published, npm-hosted version of gumby into the package.json for client? I mean, I could just delete the symlinked copy from my node_modules and then yarn add gumby, but what if I want to go back and work on it locally again? And then run it against the npm version again? And then work on it some more? And then...
You get the point, I imagine. There's no obvious way to switch between the npm copy of a package that you're working on, and the local one. There's the additional problem of how to do that without messing with your package.json too much, e.g. what if I accidentally commit to it version control with some weird file:// dependency path. Any suggestions would be much appreciated.
For local development, having the package symlinked is definitely the way to go, the idea of constantly publishing / re-installing the package sounds like a total pain.
The real issue sounds more like you’re concerned about committing a dev configuration to prod - you could address that problem with something as simple as a pre-commit hook on your VCS e.g. block if it detects any local file references in the package.json.
We build a web application and our project uses various npm packages for development, testing and run-time.
The project is built as part of a large project in TFS. TFS runs ant to build the project. Our build.xml first runs npm install, then transpiles and minifies the TypeScript and Sass files (using Grunt tasks) and then builds the final war fie.
This all works OK, but our TFS is not allowed to access the Internet during the build, only our local network. Therefore, we have all the npm libraries we use copied to a file server in our network, and our package.json dependencies point to paths on that file server.
Does this seems like a reasonable solution?
The problem we have is that the npm install takes about 10 minutes to get all the >50 packages we use (which includes karma, grunt, sass, tslint, etc. – total is 170MB).
We are now looking for way to reduce the TFS build time. One option is to but the node_modules in our source control and skip the npm install step, but is seems wrong to put third-party code in our source control.
I’d love to hear other ideas to handle this and have shorter build time.
Note that on developers machine the project builds in no time, as all packages are already installed, but TFS builds start by getting a clean environment from source control, so nothing is installed.
Tough problem. You could have TFS check if your package.json checksum has changed in order to determine if a "clean" is necessary. You'd still have a 10 minute build whenever package.json is updated, but package.json changes are usually infrequent.
The lines become blurred when you host your own npm libraries since this is essentially taking a snapshot of only the dependencies you need. Therefore, if you added a dependency, colors, you'd have to update your npm repo. That could be viewed as updating the node_modules folder on your npm repo. It's a static list of available dependencies which essentially defeats the purpose of a package.json (unless of course other internal apps use the internal npm repo).
BUT, I digress, I'd argue that the best option is to have a package.json checksum for TFS to know if it should bother rebuilding node_modules.
I've inherited a MEANJS project that I've successfully managed to open in Visual Studio 2015 via the "Build me a project from existing Node code" route.
Unfortunately, I currently get > 2000 compilation errors!
In the 'node_modules (node)' directory it is complaining of Duplicate identifiers (TS2300). These point toward 2 identical compiler.ts files located under the following directories.
\node_modules\bower\node_modules\insight\node_modules\inquirer\node_modules\rx\src\core\expressions\
\node_modules\bower\node_modules\inquirer\node_modules\inquirer\node_modules\rx\src\core\expressions\
Is there an NPM 'tidy up everything' option that I could you please?
You may try to clear npm cache by typing:
npm cache clear
The solution was to exclude the node_modules folder from the Project.
I've encountered something in node.js that'd I'd like to submit a patch for. I've also located a Github issue in which somebody also complained about the same annoyance. The issue has been tagged saying that patches are welcome. So, I'd like to try to supply a patch.
But, what's the best way to do this? I've forked the main node repository, and I've located the spots in the C++ code that an adjustment could be made. Before I make these changes though, I am trying to figure out how to test these changes of mine. I've got the official node package installed globally. I'm on Windows. How can I test this modified version of node?
You can install node-gyp to build the addon manually (npm install node-gyp -g). Then just change to the addon's root directory and simply do node-gyp rebuild after you make changes.
After further investigation, the vcbuild.bat produces project files that can simply be opened up with Visual Studio. So, code editing and debugging can all easily be done within VS. Awesome!
I've been using Node.js and npm for a few weeks with great success and have started to question the best practice for installing local modules. I understand the Global vs Local argument, however, my question has more to do with where to place a local install. Let's say that I have a project located at ~/ProjectA/ which is version controlled and worked on by multiple developers. When initially playing with Node.js and npm I wasn't aware of the default local installation paths and just simply installed the necessary modules in a default terminal which resulted in a installation path of ~/node_modules. What this ended up doing is requiring all the other developers working on the project to install the modules on their own machines in order to run the application. Having seen where some of the developers ran npm install I'm still really surprised that it worked on their machines at all (I guess it relates to how Node.js and require() looks for modules), but needless to say, it worked.
Now that the project is getting past the "toying around" stage, I would like to setup the project folder correctly. So, my question is, should the modules be installed at ~/ProjectA/node_modules and therefore be part of the version controlled project files, or should it continue to be located at a developer-machine specific location...or does it not really matter at all?
I'm just looking for a little "best-practice" guidance on this one and what others do when setting up your projects.
I think that the "best practice" here is to keep the dependencies within the project folder.
Almostly all Node projects I've seen so far (I'm a Node developer has about 8 months now) do that.
You don't need to version control the dependencies. That's how I manage my Node projects:
Keep the versions locked in the package.json file, so everyone gets the same working version, or use the npm shrinkwrap command in your project root.
Add the node_modules folder to your VCS ignore file (I use git, so mine is .gitignore)
Be happy, you're done!