Yarn workspaces with Lerna still adding packages to subfolders - lerna

I'm confused about Yarn Workspaces. I've followed this tutorial: https://medium.com/trabe/monorepo-setup-with-lerna-and-yarn-workspaces-5d747d7c0e91 but in one of the sub projects I still get packages added to node_modules which are duplicated from the root node_modules. Full test repo is here: https://github.com/donker/Dnn.React.Test
Root package.json:
{
"name": "dnn-react-test",
"version": "1.0.0",
"description": "DNN React Component Library",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dnnsoftware/Dnn.React.Common.git"
},
"scripts": {
},
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"lerna": "2.11.0"
}
}
Subproject package.json:
{
"name": "dnn-tooltip",
"version": "0.2.5",
"description": "Display an icon and associated tooltip showing a message from an array parameter",
"main": "index.js",
"scripts": {
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dnnsoftware/Dnn.React.Common"
},
"dependencies": {
"lodash": "4.17.10",
"react-portal-tooltip": "2.4.0",
"dnn-global-styles": "^0.0.5"
}
}
Result: packages/Tooltip/node_modules/lodash created.
Expected: Tooltip uses node_modules/lodash from the root folder.

Getting lerna and yarn to properly work together requires adding the following two key value pairs to your lerna.json:
"npmClient": "yarn",
"useWorkspaces": true
Although this does not directly relate to your question, I would also suggest changing
"workspaces": [
"packages/*"
],
to
"workspaces": [
"packages/**"
],
to make lerna pick up packages in subfolders (like /packages/components/button).

Related

Electron-Forge SQLite3 database not accessible on MacOS Darwin build after unzipping

I'm having some issues with a CRUD desktop application I developed with the help of a freelancer. It's an electron-forge build that works seamlessly on Windows 10, and works on MacOS initially when accessing the out folder, the strange thing happens when:
I use npm run publish to zip the Mac/Darwin instance
I manually package.zip the results of npm run make
When I do this, and unzip the file to run, the SQLite integration fails completely. The app appears to be working upon start, but no changes can be made to the DB objects, nor can new objects be made.
The freelancer who put together the DB integration said he was not able to solve this issue, but it's impossible to put apps in marketplaces without zipping the application for delivery. I can post code if necessary, I just don't even know what aspect of the code would be relevant, and feel like there has to be something I can install/put in my package.json that might solve this, but I'm just not sure.
Here is my package.json file in case that is helpful:
{
"name": "C",
"productName": "C",
"version": "1.0.2",
"description": "My Electron application description",
"main": "src/index.js",
"scripts": {
"start": "cross-env NODE_ENV=development electron-forge start",
"package": "electron-forge package",
"make": "cross-env NODE_ENV=production electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
},
"keywords": [],
"author": {
"name": "A",
"email": "xxx#gmail.com"
},
"license": "NA",
"config": {
"forge": {
"packagerConfig": {
"icon": "src/images/n.ico"
},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "C"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
},
"dependencies": {
"axios": "^0.21.1",
"bootstrap": "^4.6.0",
"cross-env": "^7.0.3",
"ebay-oauth-nodejs-client": "^1.2.1",
"electron-better-ipc": "^1.1.1",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^7.0.2",
"jquery": "^3.6.0",
"json-csv": "^3.0.6",
"sequelize": "^6.5.0",
"sqlite3": "^5.0.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.54",
"#electron-forge/maker-deb": "^6.0.0-beta.54",
"#electron-forge/maker-rpm": "^6.0.0-beta.54",
"#electron-forge/maker-squirrel": "^6.0.0-beta.54",
"#electron-forge/maker-zip": "^6.0.0-beta.54",
"electron": "10.1.5"
}
}
I found that by simply creating a DMG target (see https://www.electronforge.io/config/makers/dmg) that I did not need to worry about unzipping process. I believe DMG is the ideal approach for packaging Mac OS apps that have something like a SQLite database integration within.

how to stop composer from removing manually installed package

For some reason I'm unable to install Predis package in my project via composer require predis/predis, I have manually downloaded Predis package from https://php-download.com and moved predis folder to the vendor and then updated files inside vendor/composer, it works fine.
However, the problem is when I run composer dump-autoload, this command removes all references of this package from vendor/composer/autoload_psr4.php and autoload_static.php files.
Can someone please help me how can I prevent composer dump-autoload to remove references of this package?
Instead of copying your package to the vendor directory, you can use "repositories" in install a local package:
{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package"
}
],
"require": {
"my/package": "*"
}
}
I fixed it by adding following code in vendor/composer/installed.json , I forgot to add it.
{
"name": "predis/predis",
"version": "v1.1.1",
"version_normalized": "1.1.1.0",
"source": {
"type": "git",
"url": "https://github.com/nrk/predis.git",
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"suggest": {
"ext-curl": "Allows access to Webdis when paired with phpiredis",
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
},
"time": "2016-06-16T16:22:20+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Predis\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniele Alessandri",
"email": "suppakilla#gmail.com",
"homepage": "http://clorophilla.net"
}
],
"description": "Flexible and feature-complete Redis client for PHP and HHVM",
"homepage": "http://github.com/nrk/predis",
"keywords": [
"nosql",
"predis",
"redis"
]
}

What is resaon for deploying package.json to heroku?

i'm trying to upload a javascript nodejs project to Heroku. Localhost works perfectly but when i try to upload it gives me a:
unable to parse error at :
The Error Message : Unmatched '}' at line 16, column 1
Full Json file:
{
"name": "reactbot",
"version": "1.0.0",
"description": "React bot for webpage",
"main": "index.js",
"engines": {
"node": "12.16.2",
"npm": "6.14.4"
},
"scripts": {
"start": "node index.js"
},
"author": "Ruhul",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.3"
}
}
The package.json file defines the dependencies that should be installed with your application.
Be sure to use the correct JSON format.
e.g.
{
"name": "node-example",
"version": "1.0.0",
"description": "This example is so cool.",
"main": "web.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"example",
"heroku"
],
"author": "jane-doe",
"license": "MIT",
"dependencies": {
"express": "^4.9.8"
},
"engines": {
"node": "10.x"
}
}

unable to add package in yarn workspace monorepo

I am trying to import components in a shared package in a monorepo, but am unable to do so.
I have the following package.json files under the root of a repo that I want to run as a monorepo. /apps/billing is a create-react-app. /apps/shared is going to contain components for billing and other apps.
/package.json
{
"name": "root",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"workspaces": [
"apps/*"
],
"scripts": {
"billing": "cd apps/billing; yarn start"
},
"author": "",
"license": "ISC",
"dependencies": {}
}
/apps/billing/package.json
{
"name": "#root/billing",
"version": "0.1.0",
"private": true,
"dependencies": {
<snip>
},
}
/apps/billing/shared.json
{
"name": "#root/shared",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
In the /apps/billing directory I tried to run yarn add #root/shared and get the following output:
error An unexpected error occurred: "https://registry.yarnpkg.com/#root%2fshared: Not found".
In billing, when I try to import a component from shared
import Button from '#root/shared/components/Button';
I get
Module not found: Can't resolve '#root/shared/components/Button'
Are there additional steps to setup a yarn monorepo?
It's wrong structure for monorepo.
Also you've wrongly named /apps/billing/shared.json it should be package.json instead of shared.json
At first your package.json in the root folder should be named eg. #name-of-your-app/monorepo
then packages under your root.
fe. in apps/billing
{
"name": "#name-of-your-app/billing-app",
"version": "0.1.0",
"private": true,
"dependencies": {
// any dependencies
},
then your shared components:
each should be in its own directory
each should have its own package.json
Let's say that you have shared/Button
then Button should be in its own directory and contain package.json
eg. of shared/Button/package.json/
{
"name": "#name-of-your-app/button",
"version": "0.1.0",
"private": true,
"dependencies": {
// any dependencies
},
and if you want to use this button in your billing-app
then you should at first add this as dependency IMPORTANT watchout for version of your button in package.json, the same should be installed as dependency in your app, otherwise it will finish up with bunch of errors.
-Then when you want to import this button in any component under your billing-app then import should look like this:
import Button from '#name-of-your-app/button'
You can read more about workspaces here:
yarn workspaces
Also I recommend to read more about monorepo structure fe. here

The package name was not found in the composer.json, make sure there is a name present

"name": "foostart/sample",
"type": "library",
"description": "Create overview sample can intergrate other project",
"keywords": ["package","package"],
"homepage": "https://github.com/InfinitePW/Foostart",
"license": "MIT",
"authors": [
{
"name": "Foostart",
"email": "nguyenanhhoanld#gmail.com",
"role": "Developer"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"Sample": "src"
}
}
When i submit package from GitHub to Packagist.org. I have a problem with "composer.json".
How can i fix it??
Thanks.
https://github.com/InfinitePW/Foostart
I'm adding this as an answer so that others can benefit:
composer.json needs to be in the root of your git project in order for other projects, including packagist.org, to take advantage of it.

Resources