Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Support for ./package.yml ? #3336

Closed
jeromedecoster opened this issue Apr 11, 2013 · 30 comments
Closed

Support for ./package.yml ? #3336

jeromedecoster opened this issue Apr 11, 2013 · 30 comments

Comments

@jeromedecoster
Copy link

npm install search for local ./package.json file

Why don't also support ./package.yml file if ./package.json is not found ?

Exactly like Grunt support Gruntfile.js and Gruntfile.coffee, which very is useful

@luk-
Copy link
Contributor

luk- commented Apr 11, 2013

Personal feelings aside, this is additional complexity without much benefit, if any. There's nothing stopping you from writing a package.json or package.yml for your application or module, but it's on you (and should be) to ensure that somehow gets transpiled into appropriate json.

@luk- luk- closed this as completed Apr 11, 2013
@jeromedecoster
Copy link
Author

Thanks a lot for the quick reply. Not to much for the quick close ;)

I'm sorry that using yaml for configuration is not a good idea for you, but closing so quickly the idea on your only opinion is sad

About yaml transpiled to json, there is already a module for this https://npmjs.org/package/npm-yaml It's good but you finally need to have ./package.yml and ./package.json in the same folder. No so good

@isaacs
Copy link
Contributor

isaacs commented Apr 11, 2013

@jeromedecoster The reason that @st-luke closed it quickly is that he knows that I'll say the same thing, because this conversation has been had before :)

If the cost of two files is higher than the benefit of having your package metadata in yaml, then just use json.

For me, the cost of increasing npm's complexity in this way is not worth the benefit of parsing yaml files, because I don't prefer yaml to json.

@jedrichards
Copy link

I know this is a closed issue but just wanted to add a data point. We love using npm scripts for our frontend stuff and build tools. Being able to cut out tools like Grunt and Gulp and their sporadically updated plugin ecosystems is great. For a medium sized project our npm scripts object looks like the below. Afaik indenting the lines is as close as we can get to imbuing some human readable meaning, and making things a bit more maintainable and visually parseable,

"scripts": {
  "start": "npm run -s build && npm run -s watch",
  "build": "rm -rf dev/* && npm run -s html && npm run -s css && npm run -s js && npm run -s img && npm run -s svg",
    "html": "mkdir -p dev; cp src/index.html $_",
    "css": "mkdir -p dev/css; ./buildcss.js",
    "js": "mkdir -p dev/js; browserify src/js/landing-page.js -o dev/js/landing-page.js",
    "img": "mkdir -p dev/img; cp -r src/img/ $_",
    "svg": "npm run -s svg:generate && npm run -s svg:mv",
      "svg:generate": "svg-sprite --css --css-render-css --css-common Svg --css-prefix .Svg--%s --css-sprite spritesheet.svg --css-render-css-dest spritesheet.css --css-dimensions --css-bust \"\" --css-dest src/css/ src/svg/*.svg --transform \"\"",
      "svg:mv": "mkdir -p dev/css; mv src/css/spritesheet.svg $_",
  "watch": "parallelshell \"npm run -s watch:html\" \"npm run -s watch:css\" \"npm run -s watch:js\" \"npm run -s devserver\"",
    "watch:html": "nodemon -q -w src/ -e html -x 'npm run -s html'",
    "watch:css": "nodemon -q -w src/css/components/ -w src/css/core/ -w src/css/landing-page.css -e css -x 'npm run -s css && SOFT_FAIL=true npm run -s test'",
    "watch:js": "watchify src/js/landing-page.js -v -o dev/js/landing-page.js",
  "devserver": "(cd dev; live-server --port=3000 --no-browser)",
  "deploy": "node_modules/git-state/bin/issues && npm test && npm run build && npm run dist && npm run compress && divshot push && divshot promote development production && git add -A && npm version patch -m \"Deployed %s\" --force && git push origin master --tags",
    "compress": "npm run -s compress:js; npm run -s compress:css; npm run -s compress:svg; npm run -s compress:img",
      "compress:js": "uglifyjs dist/js/landing-page.js -o dist/js/landing-page.js -m -c unused=false",
      "compress:css": "cleancss --s0 --skip-import --skip-rebase --skip-aggressive-merging -o dist/css/landing-page.css dist/css/landing-page.css",
      "compress:svg": "svgo --enable=removeTitle --enable=removeDesc --disable=removeUnknownsAndDefaults dist/css/spritesheet.svg",
      "compress:img": "imagemin --progressive src/img dist/img",
    "dist": "rm -rf dist/* && cp -r dev/ dist/",
  "test": "./lintcss.js"
}

Being able to add formatting and comments as in a natively supported package.yaml would be really really nice, and improve the DX for using npm scripts in this way immeasurably.

@mattfysh
Copy link

support for comments would be fantastic 👍

@chpio
Copy link

chpio commented Nov 4, 2015

screenshot from 2015-11-04 18-00-22

yeah, that's why i own 2 2560x1440 displays...

@jon49
Copy link

jon49 commented Nov 16, 2015

with commands that operate directly on the package manager like npm version patch, npm install --save, etc. it becomes virtually impossible to have a yaml file that stays in sink with the package.json file. It would be infinitely better to have npm support both yaml and json natively. I don't see how the complexity would increase that much. You just check if there is one or the other file and import that and make sure that it is exported in the same format. Literally two functions. Unless I'm missing something...

@jon49
Copy link

jon49 commented Nov 23, 2015

After thinking about it some more. It doesn't make sense for npm to support anything other than package.json in json format. I like to use npm as my task runner for the command line. This is easily done in yaml and then merged with the package.json file. Then there is no difficulty in having it overwritten by all the other process that manipulate package.json.

https://gist.github.com/jon49/32dbe0fae971c3e7d39b

@tobia
Copy link

tobia commented Nov 8, 2016

I'd like to add my 2 cents. JSON was a great hack when it was invented, because it gave us a serialization format with great parsing performance in the browser, since it relied on JavaScript's eval() which was written in C (in all browsers.)

But JSON is a horrible format for a configuration file. It has a lot of inflexible syntax, such as the commas at the end of lines, it does not support multi-line strings, it does not support comments, and so on.

YAML is backwards-compatible with JSON, meaning that a JSON file is also a valid YAML file. But YAML adds all those additional features in a very flexible and human-friendly syntax. Replacing JSON.parse() with YAML.parse() should (in theory) not cause any problems and it would let people use such advanced features as comments in a configuration file.

Updating the file would be trickier, but nothing that the YAML library cannot handle. There are many examples on using YAML as a config file while keeping the user's formatting and comments.

@legodude17
Copy link
Contributor

If @tobia is correct that YAML.parse() is fully backwards compatible to JSON, then maybe this should be reconsidered. Try opening a new issue @tobia.

@othiym23
Copy link
Contributor

othiym23 commented Nov 8, 2016

No. This is not something that is going to change. JSON is simple and therefore safe. YAML is not. Please don't open new issues about this.

@legodude17
Copy link
Contributor

Ok. Sorry @othiym23.

@legodude17
Copy link
Contributor

To close, if you want this feature check out package-yml. Cheers!

@sergeysova
Copy link

Just use .toml 🤣

@avalanche1
Copy link

avalanche1 commented Mar 20, 2018

@sergeysova any tutorials on this?
I mean - on how to use it with npm

@sergeysova
Copy link

@avalanche1 toml it's just proposal from me

@sergeysova
Copy link

[package]
name = "foo"
version = "0.1.0"
description = "Example project"
main = "index.js"
keywords = [
    "example",
    "foo",
    "bar",
]
license = "MIT"

[scripts]
test = "npm run test:lint && npm run test:ava"
"test:lint" = "eslint ."
"test:ava" = "nyc ava"

[repository]
type = "git"
url = "git@github.com:user/repo.git"

[author]
name = "Foo Bar"
email = "foo@bar.me"
url = "bar.me"

[devDependencies]
ava = "^0.25.0"
nyc = "^11.6.0"
"@babel/core" = "^7.0.0-beta.42"

[dependencies]
debug = "^3.1.0"
ramda = "^0.25.0"

[config.commitizen]
path = "node_modules/cz-customizable"

@botcheddevil
Copy link

True dat! JSON as config file is shitty!!

@tobia

But JSON is a horrible format for a configuration file. It has a lot of inflexible syntax, such as the commas at the end of lines, it does not support multi-line strings, it does not support comments, and so on.

@Enteleform
Copy link

Enteleform commented May 8, 2018

@isaacs

For me, the cost of increasing npm's complexity in this way is not worth the benefit of parsing yaml files, because I don't prefer yaml to json.

Why is such a major potential improvement being overruled by personal preference? The majority of your users (see: upvotes & downvotes in this thread) would prefer to use YAML over JSON. Preferences aside, there are objective benefits to using YAML. Namely: commenting, which would result in improved readability/organization/maintainability, which would be a huge improvement over JSON.

@avalanche1
Copy link

avalanche1 commented May 8, 2018

JSON was made for data, not for configs. Therefore it should be dumped in favor of more suitable format.

For me, the cost of increasing npm's complexity in this way is not worth the benefit of parsing yaml files, because I don't prefer yaml to json.

The tide of times , man, the tide of times. You will have to listen to the users.

@jon49
Copy link

jon49 commented May 8, 2018

JSON works fine guys. I found that the only place that I want comments is for the scripts. So, I write it in JavaScript and compile it down to JSON and insert it into the package.json file. Easy peasy. No need to rock on the boat on this one when solutions already exist.

@avalanche1
Copy link

Riding in wooden carts was also fine - until there was Tesla 😉
jQuery was fine until there was React.. and so on.

@botcheddevil
Copy link

@jon49

JSON works fine guys.

have you seen @jedrichards comment above, could you tell me what this script tag is doing ??

"scripts": {
  "start": "npm run -s build && npm run -s watch",
  "build": "rm -rf dev/* && npm run -s html && npm run -s css && npm run -s js && npm run -s img && npm run -s svg",
    "html": "mkdir -p dev; cp src/index.html $_",
    "css": "mkdir -p dev/css; ./buildcss.js",
    "js": "mkdir -p dev/js; browserify src/js/landing-page.js -o dev/js/landing-page.js",
    "img": "mkdir -p dev/img; cp -r src/img/ $_",
    "svg": "npm run -s svg:generate && npm run -s svg:mv",
      "svg:generate": "svg-sprite --css --css-render-css --css-common Svg --css-prefix .Svg--%s --css-sprite spritesheet.svg --css-render-css-dest spritesheet.css --css-dimensions --css-bust \"\" --css-dest src/css/ src/svg/*.svg --transform \"\"",
      "svg:mv": "mkdir -p dev/css; mv src/css/spritesheet.svg $_",
  "watch": "parallelshell \"npm run -s watch:html\" \"npm run -s watch:css\" \"npm run -s watch:js\" \"npm run -s devserver\"",
    "watch:html": "nodemon -q -w src/ -e html -x 'npm run -s html'",
    "watch:css": "nodemon -q -w src/css/components/ -w src/css/core/ -w src/css/landing-page.css -e css -x 'npm run -s css && SOFT_FAIL=true npm run -s test'",
    "watch:js": "watchify src/js/landing-page.js -v -o dev/js/landing-page.js",
  "devserver": "(cd dev; live-server --port=3000 --no-browser)",
  "deploy": "node_modules/git-state/bin/issues && npm test && npm run build && npm run dist && npm run compress && divshot push && divshot promote development production && git add -A && npm version patch -m \"Deployed %s\" --force && git push origin master --tags",
    "compress": "npm run -s compress:js; npm run -s compress:css; npm run -s compress:svg; npm run -s compress:img",
      "compress:js": "uglifyjs dist/js/landing-page.js -o dist/js/landing-page.js -m -c unused=false",
      "compress:css": "cleancss --s0 --skip-import --skip-rebase --skip-aggressive-merging -o dist/css/landing-page.css dist/css/landing-page.css",
      "compress:svg": "svgo --enable=removeTitle --enable=removeDesc --disable=removeUnknownsAndDefaults dist/css/spritesheet.svg",
      "compress:img": "imagemin --progressive src/img dist/img",
    "dist": "rm -rf dist/* && cp -r dev/ dist/",
  "test": "./lintcss.js"
}

@jon49
Copy link

jon49 commented May 8, 2018

@botcheddevil , That's what I'm saying, do it in JavaScript or YAML or whatever your preferred language is. Then compile it to the package.json file. Not only do you get comments but you get all the flexibility you would like. Stop viewing package.json as your source file but but view it like the compiled code. You only look at compiled code when you absolutely have too. Instead look at your source code for what it does.

@jedrichards
Copy link

jedrichards commented May 9, 2018

@jon49 Not practical. Problem is that package.json is touched/regenerated by tools like npm and yarn, so if you wanted to compile it from another source you'd have to re-compile it every time it gets touched automatically by another tool, otherwise you'll lose information. Gets messy quickly.

@jaroslaw-weber
Copy link

+1 for toml. easy to parse and edit.

@tobia
Copy link

tobia commented May 10, 2018

Just use .toml

In my experience, Toml does not have a stable syntax (its author changes their mind every once in a while); it does not have a formal specification; it does not allow unlimited nesting of objects / arrays as JSON and YAML do; it's not well supported by libraries; and is not as widely used and tested.

Additionally, it's not backwards compatible with JSON, while YAML is: you can rename a .json file to .yaml and it will still work fine, because the latter's syntax is a superset of the former.

@jaroslaw-weber
Copy link

@tobia
rust uses toml and didnt have to change anything in my config files.

@jon49
Copy link

jon49 commented May 12, 2018

@jedrichards That's why I'm saying you do it only with the scripts object - which isn't changed by other programs. The other parts you don't normally change by hand anyways.

@Enteleform
Copy link

@isaacs

Since it seems pretty clear that YAML won't be used for NPM, would you consider implementing a JSON5 parser instead?

This would be an excellent compromise. JSON would still be used so nothing major has to change; and users would get some features that alleviate many of the issues mentioned in this thead, while retaining backwards compatibility.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests