简体   繁体   English

package.json 中的字段顺序?

[英]Order of fields in package.json?

Recently I made a PR to a repo to add a typings field in package.json , and the maintainer proposed the following change:最近我对一个 repo 做了 PR,在package.json typings ,维护者提出了以下更改:

-   "typings": "./src/index.d.ts",
-   "main": "./src/index.js",
-   "exports": "./src/index.js",
+   "main": "./src/index.js",
+   "exports": "./src/index.js",
+   "types": "./src/index.d.ts",

I wonder if there is a recommended rule or convention of orders of entries in package.json .我想知道package.json中是否有推荐的条目顺序规则或约定。

It could be that the maintainer has a formating tool enabled like prettier that automatically sorts the package.json file.可能是维护者启用了像 prettier 这样的格式化工具,它可以自动对 package.json 文件进行排序。 Or maybe they just like ordering their scripts in order of execution.或者他们可能只是喜欢按执行顺序排列他们的脚本。 Either way it's a json object so ultimately the order of the fields does not matter, just the nesting.无论哪种方式,它都是 json object 所以最终字段的顺序并不重要,只是嵌套。

Another thought is they could be using a special batch or shell script that hand cranks the package.json during CD, converting the scripts object to an array that gets run in order of execution. Another thought is they could be using a special batch or shell script that hand cranks the package.json during CD, converting the scripts object to an array that gets run in order of execution. Without seeing the github I can't be sure though.没有看到 github 我不能确定。

https://www.npmjs.com/package/prettier-package-json https://www.npmjs.com/package/prettier-package-json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM