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

How to sort package.json variable before scripts? #168

Open
dandv opened this issue Mar 27, 2020 · 6 comments
Open

How to sort package.json variable before scripts? #168

dandv opened this issue Mar 27, 2020 · 6 comments

Comments

@dandv
Copy link

dandv commented Mar 27, 2020

I'm using a package.json variable called nodeParams to pass the same parameters to node when calling scripts:

{
  "nodeParams": "--experimental-json-modules --harmony-top-level-await --harmony -r source-map-support/register",
  "scripts": {
    "start": "node $npm_package_nodeParams index.js"
  }
}

Since nodeParams is being used by scripts, it makes sense to have it sorted before scripts. Any idea how to do that? Right now it gets sorted at the very end. I tried nested he variable under config, but that key gets sorted after scripts.

@keithamus
Copy link
Owner

Hey @dandv thanks for the issue! All keys for sorting are hard coded in this package, so you’ll need to raise a PR to add the nodeParams key!

@fisker
Copy link
Collaborator

fisker commented Mar 27, 2020

@keithamus You might misunderstood, this field is not a standard field, could be anything.

@keithamus
Copy link
Owner

Oh yeah I see!

What should we do? Sort misc keys above scripts?

@fisker
Copy link
Collaborator

fisker commented Mar 27, 2020

I'll say, you have to use api in this case,

const order = [...sortPackage.sortOrder]
const index = order.indexOf('script')
order.splice(index - 1, 0, 'nodeParams')
sortPackageJson(
  packageJson,
  order
)

(Code on cellphone.)

@fisker
Copy link
Collaborator

fisker commented Mar 27, 2020

Another suggestion is put it in config(be careful, other tool may use this field), and use $npm_package_config_xxx.

@fregante
Copy link
Contributor

I think if you're going to use it in scripts, place it in scripts.

{
  "scripts": {
    "_nodeParams": "--experimental-json-modules --harmony-top-level-await --harmony -r source-map-support/register",
    "start": "node $npm_package_scripts__nodeParams index.js"
  }
}

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

No branches or pull requests

4 participants