-
Notifications
You must be signed in to change notification settings - Fork 343
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
feat: added package.json as an option for configs #1266
Conversation
added test coverage for config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great. I tested out the feature and it works for me.
The load order needs changing and the tests need some minor changes.
I'd also like to see this test edited to show that a package.json
file will get loaded.
src/config.js
Outdated
@@ -153,6 +157,8 @@ export async function discoverConfigFiles( | |||
path.join(getHomeDir(), `.${magicConfigName}`), | |||
// Look for a magic config in the current working directory. | |||
path.join(process.cwd(), magicConfigName), | |||
// Look for webExt key inside package.json file | |||
path.join(process.cwd(), 'package.json'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move this up one position in the array so that it happens before path.join(process.cwd(), magicConfigName)
. This will make package.json
load before web-ext-config.js
. My rationale for this is that package.json
is a project-wide type of configuration file and web-ext-config.js
is a config file that is specific only to web-ext
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I'll change that asap.
tests/unit/test.config.js
Outdated
fs.writeFileSync( | ||
configFilePath, | ||
`{ | ||
"name": "dummyPackage.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically, a version
is required to make this valid so I think you should add "version": "1.0.0"
tests/unit/test.config.js
Outdated
fs.writeFileSync( | ||
configFilePath, | ||
`{ | ||
"name": "dummyPackage.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
version
should be added here too
tests/unit/test.config.js
Outdated
@@ -927,6 +960,7 @@ describe('config', () => { | |||
it('finds a config in your home directory', () => { | |||
return withTempDir( | |||
async (tmpDir) => { | |||
const packageJSON = path.join(process.cwd(), 'package.json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of editing this test, you should make a new one. The test you edited is specific to checking that a config in your home directory gets loaded. You need a new test specific to checking that a package.json
file gets loaded. The test will probably look more like this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I edited this test because web-ext itself's package.json
will be loaded (apparently because it's inside current working directory), and that's not expected by the original test. Unless we cd to a temporary directory, and make another temporary directory home directory to test out .web-ext-config.js
, this test will always fail for the aforementioned reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. It would be helpful if you can add a comment to this test explaining the situation.
added test coverage for config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature will be really helpful. Thanks for all your work on it.
@@ -927,6 +962,10 @@ describe('config', () => { | |||
it('finds a config in your home directory', () => { | |||
return withTempDir( | |||
async (tmpDir) => { | |||
// This is actually web-ext itself's package.json file, which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this comment.
Thanks so much, @chujungeng! Your contribution has been added to our recognition wiki. Would you be interested in creating an account on mozillians.org? I'd be happy to vouch for your contribution! Thanks again, and welcome onboard! |
@caitmuenster Thanks! I'm honored to join the mozillians, and I just created an account on it (https://mozillians.org/en-US/u/chujungeng/). |
\o/ Yay! Your profile is vouched. We're happy to have you with us! I look forward to seeing you around the project. :) |
[dev-doc-needed] |
Fixes #1166
This time I modified the
loadJSConfigFile()
function to parse package.json, and I also added test coverage for it.