Why Composer's package dependencies are not being installed? - json

I've got the following composer.json file:
{
"require": {
"local/my_package": "dev-master"
},
"repositories": [
{
"packagist.org": false
},
{
"type": "path",
"url": "my_package/"
}
]
}
which requires my local package which defines the following my_package/composer.json file:
{
"name": "local/my_package",
"require-dev": {
"symfony/console": "*"
}
}
Note: The my_package folder is under Git repository with the default master branch.
Note: To create new repo, run: git init && git add -A && git commit -am'Files'.
When I run: composer install -vvv, the local/my_package package is installed correctly, but nothing else. I would expect that dependencies defined in symfony/console should be installed as well.
Executing command (my_package/): git log -n1 --pretty=%H
- Installing local/my_package (dev-master)
How should I correct my composer.json file, so the package's dependencies can be installed automatically?

It seems the require-dev keyword in the package's composer.json file should be changed to require.
The require-dev property is only required for developing the package (root package).

Related

Custom local npm module as dependency

I created a project using npm scripts in order to avoid the use of gulp. The thing is, my project has two scripts:
prepare.sh (uses wget to download some files and do mkdirs)
process.js (transform a json file into another overriding some keys)
package.json
{
"scripts": {
"process": "./process.js",
"prepare": "./prepare.sh $npm_package_config_source $npm_config_env",
"config": "npm run prepare && npm run process"
},
"config": {
"source": "https://myurl"
},
"devDependencies": {
"fs": "0.0.1-security",
"json-override": "^0.2.0"
}
}
So, if I want to apply the transform in this project I run npm run config, but I want this project to be part of another as a local module of a front-end project.
How can I set up my project? And when I add it as a dependency of my front project, how can I call the config script from the package.json of the front project?
You can add a bin object to your package.json which will result in files installed into the node_modules/.bin folder docs.npmjs.com/files/package.json#bin
example
{
"bin": {
"process": "./process.js",
"prepare": "./prepare.sh"
},
"scripts": {
"config": "prepare && process"
},
"devDependencies": {
"fs": "0.0.1-security",
"json-override": "^0.2.0"
}
}
Also since npm runs scripts with node_modules/.bin as part of the path you can simply call them by name only. Just remember to add #!/usr/bin/env node to the top of process.js

Polymer component template minification

I'm looking for a way to minify the white space in template literals. Since regular js minification wouldn't remove white space on a template literal I was expecting that maybe polymer-cli had a way to minify those.
An example of the result of minification:
import{PolymerElement,html}from'../node_modules/#polymer/polymer/polymer-element.js';export default class MyApp extends PolymerElement{static get is(){return'my-app'}static get template(){return html`
<style>
:host {
display: block;
height: 100vh;
}
.app {
height: 100vh;
}
</style>
<div class="app">
My App
</div>
`}}customElements.define(MyApp.is,MyApp);
polymer-cli currently doesn't support minification of tagged template strings. Internally, it uses Babel plugins to minify JavaScript, so ideally we'd be able to insert the babel-plugin-minify-template-strings plugin into the pipeline when minification is enabled.
For now, we could use babel-cli along with that plugin to process the build output of polymer-cli:
Start with a Polymer 3 template project, e.g., PolymerLabs/start-polymer3.
git clone https://github.com/PolymerLabs/start-polymer3.git
cd start-polymer3
Install babel-cli and the babel-plugin-minify-template-strings plugin. Your project may need other Babel plugins. In this case, this template project needs babel-plugin-syntax-dynamic-import for Babel to handle the dynamic imports in the code.
yarn add -D babel-cli \
babel-plugin-minify-template-strings \
babel-plugin-syntax-dynamic-import
Add a .babelrc config file with the following file contents:
{
"compact": true,
"ignore": [
"node_modules"
],
"plugins": [
"minify-template-strings",
"syntax-dynamic-import"
]
}
Add a build NPM script to package.json to run babel-cli (with .babelrc above) on the JavaScript output of polymer build:
"scripts": {
"build": "polymer build && $(npm bin)/babel -d . build/**/src/**/*.js"
}
Run npm run build (or yarn build). The command output (running with polymer-cli (1.7.0-pre.13), zsh, macOS High Sierra) should look similar to this:
➜ start-polymer3 git:(master) ✗ yarn build
yarn run v1.3.2
$ polymer build && $(npm bin)/babel -d . build/**/src/**/*.js
info: [cli.command.build] Clearing build/ directory...
info: [cli.build.build] (es6-unbundled) Building...
info: [cli.build.build] (es6-unbundled) Build complete!
build/es6-unbundled/src/lazy-element.js -> build/es6-unbundled/src/lazy-element.js
build/es6-unbundled/src/start-polymer3.js -> build/es6-unbundled/src/start-polymer3.js
✨ Done in 8.66s.
➜ start-polymer3 git:(master) ✗
See GitHub repo with the above changes, and its sample output
Did you try to setup your polymer.json with the following config?:
"builds": [{
"bundle": true,
"js": {"minify": true},
"css": {"minify": true},
"html": {"minify": true}
}],

phpword composer install to another directory

I want to install phpword to another directory than its default direcroty, I already tried this in composer.json:
{
"name" : "phpoffice/phpword",
"version" : "v0.13.0",
"require": {
"composer/installers": "~1.0"
},
"extra": {
"installer-paths": {
"server/vendor/{$name}": ["vendor/package"]
}
}
}
But it's still installing to default directory, it's "project/vendor/", what I want is to install it to "project/server/vendor/"
I save my composer.json in project folder. I know it could be done by placing the composer.json in project/server folder and just do "cd server" and "composer install" or "composer install -d=/server/" in terminal, but I didn't want to do that.
all you need to do is set this directive in the composer.json
ex:
"config": {
"vendor-dir": "libs/vendor"
},

How do I save all the dependencies I install through npm into my package.json file?

I ran npm install for a lot of packages, but I forgot to include the --save argument. Now when I try to deploy on Heroku I get errors for missing certain dependencies. How can I automatically add those dependencies to my package.json file without doing npm install --save for each one?
You can add all installed packages not installed with --save to your package.json automatically by calling npm init. It will append the dependencies to your existing ones. No settings in your file should be lost. Still don't forget to make a backup of the file to be 100% secure!
If the dependencies have not been appended, it can happen that just the merging failed:
Backup your existing package.json in order to keep the dependencies you have in your package.json already and all the other settings. We need this file later again.
Delete the package.json and run npm init in order to create a new package.json including the modules installed without --save in dependencies.
Merge the dependencies of your newly created package.json into your old one manually. Restore your merged package.json.
Someone already wrote a script for this.
Go to following link
stackoverflow link
here is complete code
run this code inside your project folder
var fs = require("fs");
function main() {
fs.readdir("./node_modules", function (err, dirs) {
if (err) {
console.log(err);
return;
}
dirs.forEach(function(dir){
if (dir.indexOf(".") !== 0) {
var packageJsonFile = "./node_modules/" + dir + "/package.json";
if (fs.existsSync(packageJsonFile)) {
fs.readFile(packageJsonFile, function (err, data) {
if (err) {
console.log(err);
}
else {
var json = JSON.parse(data);
console.log('"'+json.name+'": "' + json.version + '",');
}
});
}
}
});
});
}
main();
It will print all the dependencies inside node_module folder as given below.
"ansi-regex": "2.0.0",
"ansi-styles": "2.2.1",
"asn1": "0.2.3",
"assert-plus": "0.2.0",
"asynckit": "0.4.0",
"aws-sign2": "0.6.0",
"bcrypt-pbkdf": "1.0.0",
"aws4": "1.4.1",
"bindings": "1.2.1",
"bl": "1.1.2",
"boom": "2.10.1",
"caseless": "0.11.0",
"chalk": "1.1.3",
"combined-stream": "1.0.5",
"core-util-is": "1.0.2",
"compress": "0.99.0",
"commander": "2.9.0",
"cryptiles": "2.0.5",
"delayed-stream": "1.0.0",
"dashdash": "1.14.0",
"debug": "0.7.4",
"ecc-jsbn": "0.1.1",
"ejs": "2.3.4",
"escape-string-regexp": "1.0.5",
copy and paste inside your package.json json as follow
{
"name": "test",
"version": "1.0.0",
"main": "server.js",
"dependencies": {
//paste above printed data here
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}

Update to latest Polymer using Bower

I have a Polymer application which is configured as following:
My main project bower.json file:
{
"name": "Raf",
"authors": [
"Raffaeu <raffaeu#gmail.com>"
],
"description": "Test Project",
"dependencies": {
"polymer": "Polymer/polymer#1.2.0",
"iron-elements": "PolymerElements/iron-elements#^1.0.8",
"paper-elements": "PolymerElements/paper-elements#^1.0.7"
}
}
and inside my bower_components folder I do have a polymer folder with the following JSON:
{
"name": "polymer",
"version": "1.2.0",
"main": [
"polymer.html"
],
"repository": {
"type": "git",
"url": "https://github.com/Polymer/polymer.git"
},
"dependencies": {
"webcomponentsjs": "^0.7.2"
}
}
Now, if I am in the root folder (where the main bower.json file is located) and I am running bower info polymer bower returns me the following list of versions:
bower cached https://github.com/Polymer/polymer.git#1.6.0
bower validate 1.6.0 against https://github.com/Polymer/polymer.git#*
{
name: 'polymer',
version: '1.6.0',
...
But if I run bower update polymer --save console returns following message and doesn't update to 1.6.0 but it stays to my current version which is 1.2.0:
Unable to find a suitable version for polymer, please choose one by typing one of the numbers below:
1) polymer#1.2.0 which resolved to 1.2.0 and is required by MyTestProject
2) polymer#~1.2.0 which resolved to 1.2.4 and is required by paper-datatable#0.9.8
3) polymer#^1.2.0 which resolved to 1.6.0 and is required by iron-behaviors#1.0.13
4) polymer#^1.2.1 which resolved to 1.6.0 and is required by paper-behaviors#1.0.11
5) polymer#^1.2.4 which resolved to 1.6.0 and is required by iron-menu-behavior#1.1.3
6) polymer#^1.1.1 which resolved to 1.6.0 and is required by vaadin-grid#1.0.0
7) polymer#^1.0.0 which resolved to 1.6.0 and is required by iron-a11y-keys-behavior#1.1.1
8) polymer#^1.1.0 which resolved to 1.6.0 and is required by paper-dropdown-menu#1.1.3
Prefix the choice with ! to persist it to bower.json
? Answer 1
And nothing is updated.
Should I manually change version to 1.6.0 inside the polymer folder then run update?
you need to select !3 this will add a new object in your bower.json called resolutions with value as polymer#^1.2.0. Using ! will persist your choice in bower.json. As you are selecting first option it is taking the version from your bower.json which is set to use exact version i.e. 1.2.0.
Actually, you can select anything after 3rd option as they all are latest above mentioned version because of '^'.