I am in the process of switching my monorepo (back) from yarn (with workspaces) to lerna/npm, because yarn is too slow and unstable. However, I made an surprising discovery. With the following trivial package.json:
{
"devDependencies": { "lerna": "^2.11.0" },
"dependencies": { "typescript": "^2.9.1" }
}
and an empty lerna.json (in other words, no packages at all), then when I run
$ lerna bootstrap
it does not install anything at all in any top-level node_modules directory. And if for some reason I have a node_modules directory with no .bin subdirectory, then lerna bootstrap fails to create or populate the .bin subdirectory.
Is lerna not designed to actually specify top-level packages which are to be installed (along with their binaries in .bin)? I do notice that if I try lerna add on a lerna monorepo with no packages, it complains that "lerna WARN No packages found in scope where tslint can be added."
I could not find anything related to this in the documentation. With yarn/workspaces, I was using the ability to install global (top-level) versions of things like TypeScript for use in my build scripts while maintaining control over the version installed.
From the Lerna docs:
You can add the root as a managed location (in the packages array of lerna.json) - if that's something you need. This would cause lerna to link root's dependencies to your packages' directories, run postinstall script along with the others, etc.
I have a npm package which reference an other local package. It has a structure like so.
deploy
typescriptapp.tgz
references
mydependency
package.json
app.js
app.css
typescriptapp
package.json
webapp
My typescriptapp package.json has the following dependencies
"dependencies": {
"mydependency": "file:../references/mydependency"
},
My webapp package.json has the following dependencies
"dependencies": {
"typescriptapp": "file:../deploy/typescriptapp-1.0.0.tgz"
},
When I use npm pack it work fine, but it is not included in the tarball. I also move the tarball to a deploy folder
When I try npm install, it doesn't work because the reference folder does not exist in the deploy folder.
I also tried to change the dependencies for bundledDependencies
"bundledDependencies": [
"file:../references/mydependency"
]
But it does not seem to work either.
How do I pack my typescript app to be able to install it in my webapp with a single file?
I'm trying to install ESlint to use it with Sublime Text 2 for all my local projects. Configuration documentation is very unclear about global installation:
Note: eslint --init is intended for setting up and configuring ESLint on a per-project basis and will perform a local installation of ESLint and its plugins in the directory in which it is run. If you prefer using a global installation of ESLint, any plugins used in your configuration must also be installed globally.
I don't understand what they mean. I used eslint --init and it installed ESlint locally in node_modules, along with all plugins. There's nothing explained about installing plugins globally. How do I do that? Also, how do I use the global ESlint installation if eslint --init installs local one anyway? This is so confusing.
You can install Node modules within the project (locally) or globally. To switch to globally, you may use the -g flag, like so:
npm install -g eslint
Then see if it's working without Sublime Text (-v flag to see the version of eslint):
eslint -v
To see where it was installed (assuming MacOS/Linux):
which eslint
Then see if it's working in Sublime Text (you may need to restart Sublime first). If it's not working, make sure in the eslint package settings that the path is correct.
The assumption is that you have an eslint plugin installed for your editor,if you have then npm install -g eslint,then you can install add-ons for specific environments,like npm install eslint-config-airbnb eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-import -g (this is support for pure JS and for React),you can on this way add support for nodejs too,in working folder make .eslintrc file which looks like this
{
"extends": ["airbnb" , "eslint:recommended"],
"env": {
"node": false,
"es6": true,
"browser": true
},
"rules": {
"semi":"error",
"no-unused-vars": "off",
"func-names":"off",
"indent":"off",
"no-else-return":"off",
"prefer-arrow-callback":"off",
"no-undef":"off",
"no-use-before-define":"off",
"comma-dangle":"off",
"eol-last":"off",
"no-trailing-spaces":"off",
"linebreak-style":"off",
"no-console":"off",
"no-restricted-globals":"off",
"object-shorthand":"off",
"no-shadow":"off",
"no-debugger":"off",
"prefer-const":"off",
"no-multiple-empty-lines":"off"
}
}
if you need node support then in env section of .eslintrc set node to 'true' and install eslint-node plugin globally too with next
npm i eslint-plugin-node -g.
Then in extends section of .eslintrc add "plugin:node/recommended".
In this way, you will have eslint support in every project on your machine which have .eslintrc file.Set rules which you need in .eslintrc rules section .
Thats it.
To install eslint globally: npm install -g eslint
To install eslint in your project folder: npm install eslint --save-dev
Add in package.json this script : "eslint": "eslint --ignore-path .gitignore ."
Create a file called .eslintrc and insert :
{
"env": {
"browser": true,
"node": true
},
"globals": {
"chrome": true
},
"rules": {
"no-console": 0,
"no-empty": [1, { "allowEmptyCatch": true }]
},
"extends": "eslint:recommended"
}
Personally, I save this file in my js folder
Go to node_modules/.bin
Run : eslint --init
or npm run eslint nameOfYourFile
Unfortunately, ESLint no longer recommends the use of Personal Configuration. Even if you have ESLint and other ESLint configuration files installed in the global scope, it will not read them correctly.
https://eslint.org/docs/latest/user-guide/configuring/configuration-files#personal-configuration-files-deprecated
Personal Configuration Files (deprecated)
⚠️ This feature has been deprecated. This feature will be removed
in the 8.0.0 release. If you want to continue to use personal
configuration files, please use the --config CLI
option.
For more information regarding this decision, please see RFC
28 and RFC
32.
~/ refers to the home directory of the current user on your
preferred operating
system. The personal
configuration file being referred to here is ~/.eslintrc.* file,
which is currently handled differently than other configuration files.
How does ESLint find personal configuration files?
If eslint could not find any configuration file in the project,
eslint loads ~/.eslintrc.* file.
If eslint could find configuration files in the project, eslint
ignores ~/.eslintrc.* file even if it's in an ancestor directory of
the project directory.
How do personal configuration files behave?
~/.eslintrc.* files behave similarly to regular configuration files,
with some exceptions:
~/.eslintrc.* files load shareable configs and custom parsers from
~/node_modules/ – similarly to require() – in the user's home
directory. Please note that it doesn't load global-installed packages.
~/.eslintrc.* files load plugins from $CWD/node_modules by default
in order to identify plugins uniquely. If you want to use plugins with
~/.eslintrc.* files, plugins must be installed locally per project.
Alternatively, you can use the --resolve-plugins-relative-to CLI
option
to change the location from which ESLint loads plugins.
I have created project my-npm-lib and published it with npm.
Now I have an another project where I want to do:
npm install my-npm-lib --save
But if I do so, it always add to dependencies:
"dependencies": {
"my-npm-lib": "file:..\\my-npm-lib"
}
This is actually correct because I have the my-npm-lib project located there on the device where I do this.
But this is something I don't want to. Later in my new project I use the webpack and I need to do:
include: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "node_modules/my-npm-lib")
],
which
is impossible now because the module is not located in node_modules,
doesn't allow me to share the new project correctly with other associates, because there is a wrong path in the package.json file.
So far I have tried to rewrite the package.json manually with
"dependencies": {
"my-npm-lib": "^1.0.0"
}
and then use npm install, but it didn't install this particular module.
PS: Im quite sure my-npm-lib is working with npm, because it is working on other device. It seems there is a problem only with the device where the my-npm-lib is being developed.
I have found the solution,
be sure that package.json dependencies has a correct structure,
use npm install my-npm-lib --save,
then rewrite the "file:..\\my-npm-lib" to "^1.0.0",
delete the package-lock.json!, (it was the missing piece)
cast npm install again.
I have a main package.json for my project. I also have a component within my project which I'm publishing to NPM, so that requires its own package.json.
package.json
index.html
-folder
--component-folder
---package.json
Both package.json files define dependancies. At the moment I have to run npm install from both my project root and from component-folder. Is there a way of making it install dependancies for both when its only run from the project root?
Try using subpackage:
{
"name": "my-awesome-project",
"version": "2.5.1",
"subPackages": [
"packages/sub-package-1",
"packages/sub-package-2"
]
}
https://www.npmjs.com/package/subpackage