Releasing javascript library... how should I handle the external dependencies? - javascript

I'm releasing a javascript library.
My library depends on other libraries.
Some of those libraries are available through npm, some through bower.
How can I release the compiled version of my library? Should I contain the compressed dependencies' code as well? To achieve that, should I use something like grunt?

you can distribute it through bower as in bower.json you already describe the dependency if your library meant for Client side script
From http://bower.io/
{
"name": "my-project",
"version": "1.0.0",
"main": "path/to/main.css",
"ignore": [
".jshintrc",
"**/*.txt"
],
"dependencies": {
"<name>": "<version>",
"<name>": "<folder>",
"<name>": "<package>"
},
"devDependencies": {
"<test-framework-name>": "<version>"
}
}
Other wise if it is Server side for Node then only npm should do the work

Related

Javascript dependency in PHP library

I have a PHP library that depends on a Javascript repo (also my lib). In the PHP lib, I don't want a CDN url or a minified copy. The PHP lib uses a framework (also home-brewed) that will compile the JS files together along with all the resources on my site.
I don't want to change anything about the JS lib, aka I don't want to make a composer.json file. I'm aware git submodule exists, though I'm not sure how to use it and I've read that it's a thoroughly bad way to handle dependencies, and I'm guessing my submodules wouldn't get included through composer?
Are there any other ways to include a JS dependency in a PHP library? (aside from copy+pasting the files) (and/or tips to make submodule a good option)
Composer defaults to using the metadata from Packagist, which Packagist pulls from each repo's composer.json file.
However, it is possible to just specify any file that you want to download yourself. It might be a bit cumbersome if you want to have a lot of versions though.
Composer has some documentation about it here but I tried it out myself and will include my sample composer file below. I was able to use composer update to download a git repo which didn't contain a composer.json file.
Sample Composer file for the PHP project:
It looks like you'll need a "package" section for each version you want.
{
"repositories": [
{
"type": "package",
"package": {
"name": "testy/testyson",
"version": "1.0.0",
"dist": {
"url": "https://github.com/mickadoo/testlib/archive/1.0.0.zip",
"type": "zip"
}
}
},
{
"type": "package",
"package": {
"name": "testy/testyson",
"version": "2.0.0",
"dist": {
"url": "https://github.com/mickadoo/testlib/archive/2.0.0.zip",
"type": "zip"
}
}
}
],
"require": {
"testy/testyson": "2.*"
}
}
The test repository I loaded just contains a text file with the contents "This is version 1" and using the different version in the require section of the PHP package I was able to switch between them.

Javascript code completion for arango and module handling

Introduction
I've been using Eclipse for Java(!) development for more than a decade. Due to high demand I'm jumping in the deep end with javascript and arangodb. Task is to develop several microservices running within arangodb.
I'm free to use the IDE/Editor of my choice. Only remaining competitors are MS VS Code and IntelliJ. VS Code beeing my favorite as of writing.
Project setup
According to arangos documentation I've composed a project with:
mainfest.json (content skipped to improve readability)
package.json
{
"name": "abc",
"version": "0.0.2",
"description": "foxxy service",
"comment" : "This file contains the NPM package definition",
"main": "main.js",
"directories": {
"test": "test"
},
"dependencies": {
"crypto-js": "^3.1.9-1",
"jsonq": "^1.1.0",
"xml2js": "^0.4.19",
"xmldom": "^0.1.27",
"xpath.js": "^1.0.7"
},
"devDependencies": {
"chai": "^4.1.1",
"mocha": "^3.5.0"
},
"scripts": {
"test": "node node_modules/mocha/bin/mocha"
}
}
jsconfig.json
{
"compilerOptions": {
"target": "ES6",
"checkJs": true
},
"include": [
"scripts/**/*",
"lib/**/*",
"models/**/*",
"node_modules/#arangodb/**/*",
"node_modules/jsonq/**/*",
"node_modules/xml2js/**/*",
"/*"
]
}
Current state
VS Studio Code offers code completion for:
- standard Javascript (ES6) expressions
- resolves actual files behind require expressions ( e.g.: require('lodash') is resolved to the actual filesystem path
C:/Users/notte/AppData/Local/Microsoft/TypeScript/2.5/node_modules/#types/lodash/index' which proves (for me) that npm module resolution and code completion are working
Question
Arango does not offer modules via npmjs or other public repositories. I therefore copied the files (#arangodb) from an local arangodb installation to the projects "node_modules" folder.
Altough VS Code is informed about the #arango modules and submodules it does not come up with a useful code completion. What should I do or try to do?
What would be a pragmatic, sustainable solution for handling modules like those from arango? (it is not present in npmjs, has no package.json and hence no versioning)
Thank you.
We Currently collecting user efforts to create Syntax hilighting via https://github.com/arangodb/arangodb/issues/1755 - Please share your thoughts if you have something to add.

How to handle Javascript depencencies after bundling?

From what I understand, the common way to deploy a Javascript app is to take all your dependencies and put them all in one file (and then minify it). I don't understand how the code I wrote will then find the modules that are now all in this new file. I'm using node.js if that matters and use a gulp task like this to do the bundling:
gulp.task('bundle_deps', function() {
return gulp.src('src/**/*.js')
.pipe(concat('bundle.js'))
.pipe(gulp.dest(deploy_dir));
});
If you're talking about deployment, then the way to do this in node.js is to put your dependencies in the package.json file. For example:
{
"name": "yourAppName",
"version": "0.0.1",
"dependencies": {
"restify": ">= 2.6.0",
"node-restify-validation": "0.0.6",
"node-restify-swagger": "0.1.6"
}
}
See: https://docs.npmjs.com/files/package.json#dependencies
Then when you deploy the application, copy your code to the server and run the command
npm install
npm will read the dependencies in the package.json file and install them all for you.

Should vendor assets be included in version control with bower + rails?

I've started to use bower-rails to manage css/js assets in my rails projects.
By default the dependences are being installed in vendor/assets/bower_components.
The problem is that bower copies the whole packages, including sources, examples, licenses, etc.
I don't have problem to get rid of all those files, but I'm wondering if is necessary to include even the important files, as I think it should be the programmer's responsibility to load those dependences in the computer where is loading the project(maybe with grunt?), besides is supposed you should not touch the vendor packages as they are not your responsibility(regarding all those crappy files I want to delete).
My point is: Is there any kind of "best practice" related with bower packages and version control?
I recently used bower-rails for the first time and had Git ignore the vendor/assets/bower_components directory to good effect.
If you choose to have Git ignore bower_assets, you SHOULD specify a known good version of each library in bower.json instead of using latest to avoid version conflicts.
I'm using bower and bower-installer in my Rails 4.2.x app, without using any gems for javascript dependencies. I'm still using the asset pipeline.
I added vendor/assets/bower_components to my .gitignore file. I use bower-installer to copy just what I need to vendor/assets/{javascripts,stylesheets}, which are in source control.
I think that this gives me the best of both worlds: version control of JS libraries so updates are relatively easy, but no chance of a production deploy failing because someone removed 'leftpad' from the node repo.
Here's a trimmed-down version of my bower.json file (in source control). Note that jquery-form is not in the bower repo, so I included the path to the download file.
{
"name": "icots",
"main": "",
"private": true,
"ignore": [
"**/.*",
"bower_components",
"vendor/assets/bower_components",
"lib"
],
"dependencies": {
"jquery": "^3.1.1",
"jquery-ui": "^1.12.1",
"jquery.form": "http://malsup.github.io/min/jquery.form.min.js"
},
"install": {
"path": {
"js": "vendor/assets/javascripts",
"css": "vendor/assets/stylesheets",
"/[sc|le]ss$/": "vendor/assets/stylesheets"
},
"sources": {
"jquery": "vendor/assets/bower_components/jquery/dist/jquery.min.js",
"jquery-ui": "vendor/assets/bower_components/jquery-ui/jquery-ui.min.js",
"jquery-form": "vendor/assets/bower_components/jquery.form/index.js"
}
}
}

How to deploy client side dependencies on webserver?

I have done some web developing using Python and Django. I use virtualenv to make a bootstrap script that can install all my Python dependencies on a server. I have a repository for the code I have written myself, and in that repository are two file (beside my code): requirements.txt and bootstrap.py. Using the bootstrap script, it installs all the dependencies on the server.
Now I would like something similar for the client side dependencies. E.g. jQuery, jQuery-ui and bootstrap. Currently I manually download the files and put them in the static folder on the server.
I have run into Bower, and I understand that it can indeed download various js-libraries. But I don't see how to use it in an elegant way. E.g. for jQuery it downloads the entire jQuery repository, which means both a dist folder and a src folder, containing tons of files. All I need is the jQuery.min.js.
Well, wide question, what is the neat way of automating the deployment of client side dependencies?
you can use composer
{
"require": {
"jquery/jquery": "*"
},
"repositories": [
{
"type": "package",
"package": {
"name": "jquery/jquery",
"version": "1.8.2",
"dist": {
"url": "http://code.jquery.com/jquery-1.8.2.min.js",
"type": "file"
}
}
}
]
}

Categories

Resources