Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative to package.json #42364

Closed
jzabinski-dolios opened this issue Mar 16, 2022 · 3 comments
Closed

Alternative to package.json #42364

jzabinski-dolios opened this issue Mar 16, 2022 · 3 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@jzabinski-dolios
Copy link

jzabinski-dolios commented Mar 16, 2022

What is the problem this feature will solve?

Without comments, dependencies are difficult to understand using a JSON structure.

For example, I have this set of devDependencies:

"@angular-devkit/build-angular": "~13.2.6",
"@angular-eslint/builder": "~13.1.0",
"@angular-eslint/eslint-plugin": "~13.1.0",
"@angular-eslint/eslint-plugin-template": "~13.1.0",
"@angular-eslint/schematics": "~13.1.0",
"@angular-eslint/template-parser": "~13.1.0",
"@angular/cli": "~13.2.6",
"@angular/compiler-cli": "~13.2.6",
"@types/jasmine": "3.x",
"@types/node": "^16.11.25",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"eslint": "8.x",
"jasmine-core": "3.x",
"karma": "^6.3.9",
"karma-chrome-launcher": "~3.1.0",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.4.4"

By itself, it is difficult to understand the purpose of each package, and how the packages relate to one another.

It would be clearer if I could add comments to the file. Something like this:

// Node
"@types/node": "^16.11.25",
// Typescript
"typescript": "~4.4.4",
// Angular
"@angular-devkit/build-angular": "~13.2.6",
"@angular-eslint/builder": "~13.1.0",
"@angular/cli": "~13.2.6",
"@angular/compiler-cli": "~13.2.6",
// Linting
"@angular-eslint/eslint-plugin": "~13.1.0",
"@angular-eslint/eslint-plugin-template": "~13.1.0",
"@angular-eslint/schematics": "~13.1.0",
"@angular-eslint/template-parser": "~13.1.0",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"eslint": "8.x",
// Unit testing
"@types/jasmine": "3.x",
"jasmine-core": "3.x",
"karma": "^6.3.9",
"karma-chrome-launcher": "~3.1.0",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",

Of course, that is impossible because comments are not allowed in JSON.

What is the feature you are proposing to solve the problem?

If Node could accept a file called package.js that contained a JS object with the same information as package.json, JS functionality like code comments could be leveraged. (This would also open a lot of possibilities to enable dynamic generation of the object.)

What alternatives have you considered?

I can't really think of an alternative that would be as good or better. The rest of Node.js is written in JS, making a .js file uniquely convenient.

@jzabinski-dolios jzabinski-dolios added the feature request Issues that request new features to be added to Node.js. label Mar 16, 2022
@tniessen
Copy link
Member

This might be a duplicate of #40714.

@aduh95
Copy link
Contributor

aduh95 commented Mar 17, 2022

Kind of a duplicate of #41927. I think the same conclusion applies: if you want something like that to happen, it would need to have interest from the rest of the ecosystem, Node.js cannot decide unilaterally something like that.

Worth noting that reading a JSON file is much easier than executing a JS file (you don't need a JS runtime to parse JSON), JSON5 would probably be more reasonable – but would also come with its challenges.

This would also open a lot of possibilities to enable dynamic generation of the object.

You say that as it would be a good thing, but that sounds quite scary to me 😅

If Node could accept a file called package.js that contained a JS object with the same information as package.json, JS functionality like code comments could be leveraged

You give the example of devDependencies in the OP, FYI Node.js does not read this field at all: that's used by your package manager (npm, Yarn, pnpm, etc.), so they would need to support this new file format. Node.js itself has a very limited use of package.json files, see the docs for more info: https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions

@Trott
Copy link
Member

Trott commented Mar 17, 2022

I understand the desire here, but I don't think this is ever likely to happen, and certainly not any time in the next several years. I'm going to close this, but if anyone thinks that's too hasty and wants to discuss more, please comment or re-open.

@Trott Trott closed this as completed Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

4 participants