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

Convert to JSON #3

Merged
merged 1 commit into from
Dec 13, 2014
Merged

Convert to JSON #3

merged 1 commit into from
Dec 13, 2014

Conversation

es128
Copy link
Contributor

@es128 es128 commented Dec 12, 2014

Works just as well in node and makes it more flexible for use in other contexts.

@michaelficarra
Copy link
Owner

From the node documentation,

If there is no package.json file present in the directory, then node will attempt to load an index.js or index.node file out of that directory.

It seems like index.json was a deliberate omission, considering JSON loading support is mentioned elsewhere in the documentation. I'll merge this if you can prove the support for index.json is an intentional, documented feature.

@es128
Copy link
Contributor Author

es128 commented Dec 13, 2014

Further down in that doc index.json is explicitly listed. I suspect it was an inadvertent omission from the part you quoted:

LOAD_AS_DIRECTORY(X)
1. If X/package.json is a file,
   a. Parse X/package.json, and look for "main" field.
   b. let M = X + (json main field)
   c. LOAD_AS_FILE(M)
2. If X/index.js is a file, load X/index.js as JavaScript text.  STOP
3. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP
4. If X/index.node is a file, load X/index.node as binary addon.  STOP

If that isn't convincing enough for you or publishing the package this way just isn't your preference, there are still other ways to preserve the data in JSON format which would still be worthwhile. One would be to explicitly list it as the main in package.json, another would be to require it from a barebones index.js file such as in https://github.com/sindresorhus/globals/blob/master/index.js. But personally I think node's require implementation can be trusted to keep treating json as a first-class format.

@michaelficarra
Copy link
Owner

I'm convinced. Thank you for the reference and PR.

michaelficarra added a commit that referenced this pull request Dec 13, 2014
@michaelficarra michaelficarra merged commit 843ac01 into michaelficarra:master Dec 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants