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

Deferred values can't be referenced by sub-modules #687

Open
EricLeeSanders opened this issue Aug 6, 2022 · 2 comments
Open

Deferred values can't be referenced by sub-modules #687

EricLeeSanders opened this issue Aug 6, 2022 · 2 comments

Comments

@EricLeeSanders
Copy link

I'm submitting a ...

  • [ x ] bug report
  • [ ] feature request
  • [ ] support request or question => Please do not submit support request or questions here, see note at the top of this template.

What is the current behavior?

Sub-modules that use node-config are not able to reference deferred values from the parent module.

For example, say you have a parent module with node-config installed and two config files, default and production.

default.js

const defer = require('config/defer').deferConfig;

module.exports = {
  firstName : 'default first name',
  lastName: 'default last name',
  fullName : defer(function ()  {
    return this.firstName+' '+this.lastName;
  })
} 

production.js

module.exports = {
    firstName : "Jane",
    lastName: "Doe",
 }

index.js

const config = require('config');
console.log('from parent: ' + config.fullName);

This correctly prints the full name, Jane Doe.

However, say I also have a sub-module with the following index file

child - index.js

const config = require('config');
console.log(config);
console.log('from sub-module: ' + config.fullName);

Then I update the parent module index file to the following to require the child module.
parent - index.js

const config = require('config');
console.log('from parent: ' + config.fullName);

const configDeferTestChild = require('config-defer-test-child');

The output is then:

from parent: Jane Doe
Config {
  firstName: 'Jane',
  lastName: 'Doe',
  fullName: DeferredConfig {
    prepare: [Function (anonymous)],
    resolve: [Function (anonymous)]
  }
}
from sub-module: [object Object]

Which you can see that the config values correctly resolve the values in the parent module. But in the sub-module it does not resolve.

What is the expected behavior?

Based on the wiki, I would expect that config-defer should work with sub modules as well and I should see "Jane Doe" in the sub module index file (I haven't read anything that stated otherwise).

Please tell us about your environment:

  • node-config version: 3.3.7
  • node-version: 18.0.0

Other information

@EricLeeSanders EricLeeSanders changed the title Deferred values don't work with sub-modules Deferred values can't be referenced by sub-modules Aug 6, 2022
@markstos
Copy link
Collaborator

I have not looked closely to see if this possible to implement.

You can submit a PR to find out what's involved and we can discuss any trade-offs from there. I don't think anyone else is going to implement this for you, though.

@markstos
Copy link
Collaborator

markstos commented Aug 4, 2023

In your example, did you also test with config.get('fullName')?

I'm not sure this issue can be resolved without perhaps a re-design that introduces some incompatibilities. See for example the proposal in #569.

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

2 participants