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

Support config key in package.json #2793

Closed
gtrabanco opened this issue May 3, 2023 · 1 comment · Fixed by #14786
Closed

Support config key in package.json #2793

gtrabanco opened this issue May 3, 2023 · 1 comment · Fixed by #14786
Labels
bun install Something that relates to the npm-compatible client enhancement New feature or request

Comments

@gtrabanco
Copy link

What is the problem this feature would solve?

Support for config in package.json. https://docs.npmjs.com/cli/v9/configuring-npm/package-json#config

When adding in package.json:

{
...
  "config": {
    "foo": "bar"
  },
...
}

Expected to have env variable: npm_package_config_foo but seems not to have it.

Code

Here the test code (./src/index.js):

const { env } = process;
const envEntries = Object.entries(env);
const npmEnvArray = envEntries.filter(([key]) => key.startsWith('npm'));
const npmEnv = Object.fromEntries(npmEnvArray);

console.log(npmEnv);

Package.json file

{
  "name": "test-project",
  "module": "src/index.js",
  "type": "module",
  "config": {
    "foo": "bar"
  },
  "scripts": {
    "start:bun": "bun run ./src/index.js",
    "start:node": "node ./src/index.js"
  },
  "devDependencies": {
    "bun-types": "^0.5.0"
  },
  "peerDependencies": {
    "typescript": "^5.0.0"
  }
}

Bun Output

$ bun run ./src/index.js
{
  "npm_config_local_prefix": "/Users/gtrabanco/MyProjects/test-project/",
  "npm_package_name": "test-project",
  "npm_config_user_agent": "bun/0.6.0 npm/? node/v18.15.0 darwin x64",
  "npm_execpath": "/Users/gtrabanco/.bun/bin/bun",
  "npm_package_json": "/Users/gtrabanco/MyProjects/test-project/package.json",
  "npm_node_execpath": "/Users/gtrabanco/.nvm/versions/node/v18.14.2/bin/node"
}

Node Output

> start:node
> node ./src/index.js

{
  npm_config_audit: '',
  npm_config_metrics_registry: 'https://registry.npmjs.org/',
  npm_config_global_prefix: '/Users/gtrabanco/.nvm/versions/node/v18.14.2',
  npm_config_noproxy: '',
  npm_config_local_prefix: '/Users/gtrabanco/MyProjects/test-project',
  npm_package_config_foo: 'bar',
  npm_config_globalconfig: '/Users/gtrabanco/.nvm/versions/node/v18.14.2/etc/npmrc',
  npm_execpath: '/Users/gtrabanco/.nvm/versions/node/v18.14.2/lib/node_modules/npm/bin/npm-cli.js',
  npm_package_json: '/Users/gtrabanco/MyProjects/test-project/package.json',
  npm_config_userconfig: '/Users/gtrabanco/.npmrc',
  npm_config_init_module: '/Users/gtrabanco/.npm-init.js',
  npm_command: 'run-script',
  npm_lifecycle_event: 'start:node',
  npm_package_name: 'test-project',
  npm_config_node_gyp: '/Users/gtrabanco/.nvm/versions/node/v18.14.2/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js',
  npm_config_save_prefix: '',
  npm_config_cache: '/Users/gtrabanco/.npm',
  npm_lifecycle_script: 'node ./src/index.js',
  npm_config_fund: '',
  npm_config_user_agent: 'npm/9.6.5 node/v18.14.2 darwin x64 workspaces/false',
  npm_node_execpath: '/Users/gtrabanco/.nvm/versions/node/v18.14.2/bin/node',
  npm_config_prefix: '/Users/gtrabanco/.nvm/versions/node/v18.14.2'
}

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

...

What alternatives have you considered?

Using .env files and provide hardcoded default values.

@gtrabanco gtrabanco added the enhancement New feature or request label May 3, 2023
@Electroid Electroid changed the title package.json config Support config key in package.json Oct 26, 2023
@Electroid Electroid added the bun install Something that relates to the npm-compatible client label Oct 26, 2023
@Chinoman10
Copy link

Would love to see some support for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bun install Something that relates to the npm-compatible client enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants