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

Local config #1265

Closed
wants to merge 8 commits into from
Closed

Local config #1265

wants to merge 8 commits into from

Conversation

hmps
Copy link
Contributor

@hmps hmps commented Nov 5, 2015

This is a proposed fix for issue #190.

It creates a --local flag for jspm config and jspm registry. If the --local flag is provided the configuration will be saved in ./.jspmrcor ./.config/.jspmrc, in that order.

I couldn't really wrap my head around if and how to add tests for the changes, so no tests are added. I'd be happy to fix this if there is a standard to follow.


// If the user wants to save options to a local configuration file that is not
// created, we need to create it and extend it with the default config.
if ( saveLocal && !config.local.path ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering about this logic, which will cause private data in the global config file to persist into the local project, potentially exposing passwords to version control by mistake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I see this is just the default config being surfaced. I'm still not sure I understand why this is necessary though, if config is considered as the superposition of global and local configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it now, a month later, I share your confusion. Should work fine without it...

I'll make sure to test and confirm, and will update the PR if everything checks out!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, found the reason why I added it... Without that if clause, if I try to save local config in a dir where no local config file exists, L199 will throw because config.local.path is undefined.

The reason is that config.local.path, set on L54 via getLocalConfigPath(), will be not be set if no local config file exists. So in the if, I getDefaultLocalConfigPath() to know where to save the generated config file.

That config.local.path is undefined is used to know which config to load (L87), that's why I don't set it to a default value in getLocalConfigPath.

Does that make sense to you @guybedford?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely the default localConfigPath can be implied as the path.resolve(config.pjsonPath, '.jspmrc')?

@guybedford
Copy link
Member

Thanks so much, will be great to get this in.

@hmps
Copy link
Contributor Author

hmps commented Nov 11, 2015

@guybedford I'm the one who should be thankful! We use this every day at work and it is really working great for us!

@guybedford
Copy link
Member

Glad to hear that. I hope you don't mind, but because every line of code added is more future maintenance it will need to be very carefully reviewed to ensure code complexity is kept to a minimum.

@hmps
Copy link
Contributor Author

hmps commented Nov 11, 2015

Don't mind at all, I'd be worried if you didn't scrutinize it :)

I guess what you're getting at is that getDefaultLocalConfigPath could be simplified?

I'm not sure that I follow you on the path.resolve(config.pjsonPath, '.jspmrc') part though. If I run it in place of getDefaulLocalConfigPath I get [...]/jspm-test/package.json/.jspmrc.

On a side note, I did find that I used some pretty stupid variable names in registry.js. Will fix and push the changes.

@hmps
Copy link
Contributor Author

hmps commented Nov 11, 2015

Thought of another thing...

If I create / config a registry and have a local config file, should the config be saved locally by default, or should it require the --local flag?

If locally by default, should there also be a --global flag?

I'm leaning towards the latter, it would make sense for local to be default if I have a default config available. But it should also possible to save globally from a locally configured project.

@@ -543,7 +543,7 @@ process.on('uncaughtException', function(err) {
return ui.log('warn', 'You must provide an registry name to create.');
if (!args[3])
return ui.log('warn', 'You must provide the registry module name to generate from.');
return Promise.resolve(registry.create(args[2], args[3]))
return Promise.resolve(registry.create(args[2], args[3], undefined, options.local))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's alter the signature rather to return Promise.resolve(registry.create(args[2], args[3], options.local))

@guybedford
Copy link
Member

I'm thinking it might be nicer to use a getter / setter global API along the lines of:

// automatically gives the config value from local or global as appropriate
globalConfig.get('some.property.value');
// local flag is optional
globalConfig.set('some.property.value', value, local);

We then ensure that all config operations from registry.js and global-config.js itself run through this getter / setter API, turning the internal localConfig and globalConfig objects into private data.

@guybedford
Copy link
Member

I think the default should always be to save to global config, unless --local is explicitly set. The reason for this is first and foremost backwards-compatibility as that is the existing behaviour. It is also effectively the same default npm uses.

@brunopgalvao
Copy link

This would be great!

@hmps
Copy link
Contributor Author

hmps commented Jan 19, 2016

The changes in global-config.js made for a problematic merge. So instead of trying to figure out how to merge properly, in a codebase that I'm not 100% comfortable in, I'll close this PR and take another stab at it with the latest updates as base.

@hmps hmps closed this Jan 19, 2016
@gig177 gig177 mentioned this pull request Feb 25, 2016
@jabbera
Copy link

jabbera commented May 2, 2016

Did functionality to accomplish this ever get merged? I can't figure out how to build on our build server as we only allow outbound github downloads via our cache.

@tjaartvdwalt
Copy link

Local config would be very handy for me in my CI environment.
Any chance of merging this code?

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

Successfully merging this pull request may close these issues.

None yet

5 participants