How to require node_modules from my own Laravel project packages - laravel

I'm setting up my own Laravel Package, and want to create dependancies to some node_modules. How can they be required in the composer.json of my package for this is not linked to the node_modules.
Used Git Bash to install to create my package in the packages/my/project/ folder and my composer.json looks like this:
{
"name": "my/project",
"description": "Description.",
"keywords": [
"front-end",
"framework"
],
...
"require": {
"php": ">=7.1.0"
},
I want te require from node_modules: #vue/component-compiler-utils

You can require them in package.json file in your root directory and then run a npm install. And then add them to your app.js or bootstrap.js file under resources/js and run a npm run production.

Related

With Yarn workspaces, how can compiled binaries be linked to the workspace post-compilation?

Context
Yarn workspaces provide for a convenient mono-repo-like functionality where packages are automatically linked. I.e. they can require/import each other, and their binaries are linked and accessible from the workspace root.
An example:
workspace/package.json
{
"name": "200180719-yarn-bin",
"version": "1.0.0",
"workspaces": [
"packages/*"
],
"private": true
}
workspace/packages/a/package.json
{
"name": "a",
"version": "1.0.0",
"main": "src/index.js",
"bin": {
"mycli": "src/index.js"
}
}
workspace/packages/a/src/index.js
#!/usr/bin/env node
console.log('welcome to the cli')
If you then change directory to the main workspace and run yarn install, yarn correctly links the binaries and you can run:
yarn run mycli
From the workspace directory just fine. Great!
Problem
The problem I have is that if your code first has to be compiled, the binary won't be available before yarn install has finished (since you are not supposed to ship compiled code in version control). I use Typescript to compile my cli:
Rename index.js to index.ts and update a/package.json to:
{
"name": "a",
"version": "1.0.0",
"main": "src/index.js",
"bin": {
"mycli": "dist/index.js"
},
"scripts": {
"build": "tsc src/index.ts --outDir dist",
"preinstall": "yarn run build"
},
"devDependencies": {
"typescript": "^2.9.2"
}
}
Even though dist/index.js is correctly build when you run yarn install on the workspace directory, it fails to create a link to the binary:
Toms-MacBook-Pro-2:200180719-yarn-bin tommedema$ yarn run mycli
yarn run v1.7.0
error Command "mycli" not found.
Question
How can I make yarn workspace binary linking work when my binaries need to be compiled on install?
If I need to use Lerna to make this work, that would be totally fine too (though preferably avoiding a call to lerna bootstrap since that should be redundant with yarn workspaces).

How to write an odd case version constraint for composer?

The constraint that I am interested in is
"require":{ "php": "..."
Is there a way to target php 7.1 for the project packages in composer.json even though I'm running 7.2 when I call composer update/install on the command line?
You can use platform configuration from Composer: https://getcomposer.org/doc/06-config.md#platform
Basically, your composer.json would look like this:
{
"require": {
...
},
"config": {
"platform": {
"php": "7.1"
}
}
}
This will make sure that you install only packages compatible with PHP 7.1, no matter which PHP version you use to actually install the packages.

Composer install create folders in second time only

I have a problème with composer install, if I launch the last command, it creates the vendor folder in my Laravel 5 project, and all its dependencies, but doesn't create folders what I want to some folders at the same time.
I added the following lines to my composer.json file:
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize",
"mkdir public/kit",
"mkdir public/files",
"mkdir public/sites"
],
The problem is, that if I launch the same command (composer install) a second time, It said:
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
Illuminate\Foundation\ComposerScripts::postInstall
php artisan optimize
Generating optimized class loader
Compiling common classes
mkdir public/kit
mkdir public/files
mkdir public/sites
And It creates the folders what I need ...
Any help please?
Thanks alot
The "post-install-cmd" needs to be placed inside the "scripts" root entry:
"scripts": {
"post-install-cmd": [
"mkdir public/kit",
"..."
],
"post-update-cmd": [
"UPDATE ACTIONS",
"..."
],
}
you can install composer only one time.
after installation you can update composer.
commond :- composer update

composer create-project - command donot work

I have my project on github containing composer.json in the root directory.
This is how my composer.json code looks like:
{
"name": "vendor/projectname",
"description": "My first Composer project",
"authors": [
{
"name": "John Deo",
"email": "johndeo#demo.com"
}
],
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": "~5.3"
}
}
I had defined/submited my package on packagist.org.
Now when I try to get the project in my localhost using composer create-project - commands one of its work and another do not work.
1. composer create-project -s dev vendor/projectname >> WORKS
2. composer create-project vendor/projectname >> DO NOT WORK
Can someone please tell why the second command does not work.
What am I missing or doing wrong?
Please Help!
You're missing a stable version of vendor/projectname. In git, a tag (without flag) is a stable version and branches are dev versions. So you have to tag a release (e.g. git tag 1.0.0).

Composer test branch install

I have made a test branch to test some composer installations:
https://github.com/Sangoku/laravel4-idehelper-generator/tree/compabilityTest
Now I want to install via Composer this changed branch on my Laravel project, but I don't know how I could tell composer to pull my version of the code.
I don't know Composer enough to tell it which branch he should pull.
Edit your composer.json and:
require the package
"require": {
...
"jonphipps/idehelper": "dev-master"
},
And set the repository for it to be downloaded from
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Sangoku/laravel4-idehelper-generator.git"
}
],

Resources