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

JavaScript config files #114

Merged
merged 1 commit into from
Sep 4, 2018
Merged

Conversation

elliotdickison
Copy link

This change enables the user to use a JavaScript module for their
config file. The goal of this change is to enable more flexible
configuration similar to Webpack or Babel. For example filter
functions, which previously could only be provided using the Node
API, can now be included directly in a JS config file.

JavaScript config files could also eventually remove the need for
the register APIs because you could simply pass formatters,
transformers, etc. as functions directly in the config instead of
registering them with an alias and then referencing that alias in
the config. This could potentially provide a simpler API very
similar to the way webpack handles plugins:
https://webpack.js.org/configuration/plugins/. Just a thought
though. For now the default config file ./config.json and the
ability to continue to use JSON config files has not changed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@shaunbent
Copy link

❤️ Love this, create contribution @elliotdickison.

Copy link
Member

@dbanksdesign dbanksdesign left a comment

Choose a reason for hiding this comment

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

Overall looks great. Just one question in extend.js. It is probably fine as-is, but want to check.

Also LOVE that you added a cliBuild test. 20 gold stars!

lib/extend.js Outdated
if (_.isString(opts)) {
options = fs.readJsonSync(opts);
options = require(path.resolve(process.cwd(), opts));
Copy link
Member

Choose a reason for hiding this comment

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

Just a conversation starter, the recent addition to do something similar for style dictionary files (#89) used the resolve-cwd module. Open question to you and @jreichenberg: should we use resolve-cwd here as well? Should we remove the resolve-cwd module and use this way in combineJSON.js? Does it matter?

Copy link
Author

Choose a reason for hiding this comment

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

I missed that dependency. Not sure why it's necessary, but I don't really care one way or the other happy to add it in for consistency. @jreichenberg what's the value add of that dependency?

Copy link
Contributor

Choose a reason for hiding this comment

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

@elliotdickison See the discussion in 89: #89 (comment)

Both the native node require() statement and readJsonSync will parse any JSON you throw at it. The difference is that native require() will resolve packages in the process (yay!) but needs some help resolving a path relative to the cwd (boo!). So kind of depends on the desired capability. I know that doesn't help much...

@@ -0,0 +1,87 @@
module.exports = {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be silly to just require the test.json file here so we don't have to keep the 2 files in sync? I mean, we probably won't be changing these much as the tests would break if we did. I dunno just thinking out loud.

Copy link
Author

Choose a reason for hiding this comment

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

Ha that is awesome. Will do.

This change enables the user to use a JavaScript module for their
config file. The goal of this change is to enable more flexible
configuration similar to Webpack or Babel. For example filter
functions, which previously could only be provided using the Node
API, can now be included directly in a JS config file.

JavaScript config files could also eventually remove the need for
the register APIs because you could simply pass formatters,
transformers, etc. as functions directly in the config instead of
registering them with an alias and then referencing that alias in
the config. This could potentially provide a simpler API very
similar to the way webpack handles plugins:
https://webpack.js.org/configuration/plugins/. Just a thought
though. For now the default config file `./config.json` and the
ability to continue to use JSON config files has not changed.
@elliotdickison
Copy link
Author

Switched to using resolveCwd to resolve the config file path, gutted configs/test.js to just re-export configs/test.json as javascript.

Copy link
Member

@dbanksdesign dbanksdesign left a comment

Choose a reason for hiding this comment

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

:shipit: LGTM

@dbanksdesign dbanksdesign merged commit 2e71c0d into amzn:develop Sep 4, 2018
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.

4 participants