How can I use variables with npm 7.x.x in package.json?

Viewed 712

I'd like to access keys in directories using npm script for it.

  "directories": {
    "client": "client",
    "server": "server"
  },
  "scripts": { 
    "test:client": "npm run local-tests --prefix ./$npm_package_directories_client", 
  }

But after updating npm from 6.x.x to 7.5.x I'm not allowed to do that anymore.

How I can do that with the new npm?

Thanks

3 Answers

Same problem! Solved using your solution! Thanks mate! I suggest a nive way to add commentaries to our json files.

  "config": {
     "@comments devPath": "Path to build the develeping code.",
     "devPath": "../castorweb/src/dist/webapps/AQSAPP_TEMPLATE/tmp",
     "@comments prodPath": "Path to build the production code: When generating app versions",
     "prodPath": "../castorweb/src/dist/webapps/AQSAPP_TEMPLATE/dist"
  },

The solution for this problem is following:

"workspaces": [
   "workspace-a"
]
"scripts": { 
   "test:client": "npm run local-tests -w", 
}

see npm workspaces docs

Related