arfeo / npm-add-dependencies Goto Github PK
View Code? Open in Web Editor NEWAdd dependencies to the package.json file without installing them
License: MIT License
Add dependencies to the package.json file without installing them
License: MIT License
$ npm-add-dependencies [email protected]
package.json
{
"name": "npm-add-dependencies-test",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"bulma": "0.7.0"
}
}
$ npm-add-dependencies [email protected]
package.json
{
"name": "npm-add-dependencies-test",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"[email protected]": "^0.7.5"
}
}
We should support --save-exact
/-E
to write the exact version X.X.X
instead of ^X.X.X
.
No way to do this right now.
With --bundled
, we're supposed to get bundledDependencies
as an array, not an object (see here for npm and here for yarn).
Per npm
docs:
-B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.
So we should get:
"bundledDependencies": ["debug"]
So perhaps we should remove support for it, or implement it correctly?
"bundledDependencies": {
"debug": "^4.1.1"
}
npx npm-add-dependencies --bundled debug
When I run npm run add-dependencies packages/euanmarten/package.json express
it should not modify trailing whitespace in the file.
Running npm run add-dependencies packages/euanmarten/package.json express
results in trailing newline being removed from the package.json
file.
npm-add-dependencies "git+https://[email protected]/foo/bar.git"
Fails with
This script adds dependencies (latest or specified versions) into the package.json file without installing them
Adding packages to 'dependencies'...
Could not obtain the specified version for: git+https://git. Skip.
Done.
Would be nice to have a more terse command like npx add-dep
or npx add-deps
. We could rename/publish as add-dep
/ add-deps
instead.
Must run as npx npm-add-dependencies
which takes long to type out.
I expect npm-add-dependencies
will add dependencies, but not replace them
when i try to add some packages to the existing package.json, all the packages already listed in the corresponding section (devDependencies) disappear, so newly added packages fully replace old list.
before
{
"name": "1-end",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"build": "next build",
"start": "next start",
"dev": "next",
"lint": "eslint components pages lib"
},
"dependencies": {
"@material-ui/core": "^3.3.1",
"next": "^7.0.2",
"prop-types": "^15.6.2",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-jss": "^8.6.1"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.7.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1"
}
}
command
npm-add-dependencies eslint-config-prettier eslint-plugin-prettier prettier --dev
after
{
"name": "1-end",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"build": "next build",
"start": "next start",
"dev": "next",
"lint": "eslint components pages lib"
},
"dependencies": {
"@material-ui/core": "^3.3.1",
"next": "^7.0.2",
"prop-types": "^15.6.2",
"react": "^16.6.0",
"react-dom": "^16.6.0",
"react-jss": "^8.6.1"
},
"devDependencies": {
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-prettier": "^3.0.0",
"prettier": "^1.15.3"
}
}
Shouldn't be too hard to write a few quick tests that run on a fake project.
then parse that json for the results.
edit: if i get some spare time i might try to setup some up dont think it'll be "too" much work ๐
We should refactor to use a 3rd party args parser like yargs
for simpler and less error-prone code.
npx add-dependencies eslint@latest -D
should work
โฏ npx add-dependencies eslint@latest -D
This script adds dependencies (latest or specified versions) to the package.json file skipping the installation process.
Adding packages to 'devDependencies'...
Could not obtain the specified version for: eslint. Skip.
Done.
Running without @latest works, but I want the latest. If the latest is already used, it should at least ignore the @latest part.
Instead of just being used as a CLI, make npm-add-dependencies reusable by making it a module that can used programmatically.
Cannot be called programmatically.
npm-add-dependencies @angular/material
ok
npm-add-dependencies @angular/material
This script adds dependencies (latest or specified versions) into the package.json file without installing them
Adding packages to 'dependencies'...
undefined:2
[email protected] | MIT | deps: 8 | versions: 17
^
SyntaxError: Unexpected token n JSON at position 1
at JSON.parse ()
at npmRun.exec (C:\Users\c383650\AppData\Roaming\npm\node_modules\npm-add-dependencies\index.js:69:42)
at ChildProcess.exithandler (child_process.js:285:7)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
Hello, on rorw 59 of index.js i found:
runNpmShow(dep) {
const [depName, depVersion] = dep.split('@');
such split cause an undefined depName when package name starts with @
Hey,
I'm trying to use your plugin. After a npm install -g npm-add-dependencies I run in my project :
npm-add-dependencies git+https://github.com/arfeo/npm-add-dependencies.git#master --dev
And I've got this :
This script adds dependencies (latest or specified versions) to the package.json file without installing them Adding packages to 'devDependencies'... Could not fetch version info for: git+https://github.com/arfeo/npm-add-dependencies.git#master. Skip. Done.
Any ideas ?
Thanks :)
So it can be a npm i
alternative, and if in my npx install script the user don't pass the --no-install, the -i flag is included in the add-dependencies command and the deps are installed.
Also, seems that the addd
name is available on npm. Maybe you could use it
We should be able to use -D
as shorthand for --dev
, just like npm add
.
-D
is not recognized.
npx npm-add-dependencies debug -D
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.