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

Sorting arrays in package.json #10063

Closed
acoll opened this issue Oct 21, 2015 · 2 comments
Closed

Sorting arrays in package.json #10063

acoll opened this issue Oct 21, 2015 · 2 comments

Comments

@acoll
Copy link

acoll commented Oct 21, 2015

I'm sure this will be a duplicate but I couldn't find the issue. I use browserify transforms in a 3rd party module. They are defined in the package.json like this:

"browserify": {
   "transform": ["jadeify", "babelify", "brfs"]
}

The problem i'm having is when the module is installed with npm install the array gets sorted and the transforms are then in an invalid order. It looks like its on line 6 of npm/lib/utils/deep-sort-object.js https://github.com/npm/npm/blob/master/lib/utils/deep-sort-object.js#L6 and its called from here https://github.com/npm/npm/blob/master/lib/install/update-package-json.js#L14. I removed this sort and tested and I get the array in the order I expect (the order it was defined).

@terinjokes
Copy link
Contributor

This field has been documented as part of module-deps for a long while: would be great to either revert the change or get the field opted out.

@ghost
Copy link

ghost commented Oct 30, 2015

I can confirm this bug. Here's how to reproduce it:

npm install -g json
cd /tmp; mkdir xxx yyy
echo '{"name":"xxx","version":"1.2.3","array":["z","y","x"]}' > xxx/package.json
cd yyy
npm install file://$PWD/../xxx
json array < node_modules/xxx/package.json

output:

[
  "x",
  "y",
  "z"
]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.