This repository has been archived by the owner on Sep 9, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Make applyConfig transform argv instead of builders #84
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rekmarks
force-pushed
the
refactor-apply-config
branch
from
February 15, 2021 22:54
60ae36a
to
877c73a
Compare
rekmarks
commented
Feb 15, 2021
Comment on lines
-200
to
-227
|
||
describe('applyConfig', () => { | ||
it('sets default values correctly', async () => { | ||
fsMock = jest.spyOn(fs, 'readFile') | ||
.mockImplementationOnce(async () => getPackageJson()) | ||
.mockImplementationOnce(async () => { | ||
return {}; | ||
}); | ||
|
||
await applyConfig(); | ||
expect(builders.src.default).toStrictEqual('index.js'); | ||
expect(builders.bundle.default).toStrictEqual('dist/foo.js'); | ||
expect(builders.dist.default).toStrictEqual('dist/'); | ||
}); | ||
|
||
it('config file overrides package.json fields', async () => { | ||
const customConfig = { | ||
'src': 'custom.js', | ||
}; | ||
|
||
fsMock = jest.spyOn(fs, 'readFile') | ||
.mockImplementationOnce(async () => getPackageJson()) | ||
.mockImplementationOnce(async () => customConfig); | ||
|
||
await applyConfig(); | ||
expect(builders.src.default).toStrictEqual('custom.js'); | ||
}); | ||
}); |
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.
Upon review, these test cases were redundant.
astarinmymind
approved these changes
Feb 15, 2021
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.
nice!!
Merged
rekmarks
added a commit
that referenced
this pull request
Feb 18, 2021
#84 left `applyConfig` in a broken state. This PR fixes the behavior of `applyConfig` such that the config will transform `argv`, but only by setting properties that are valid arguments for the current command and that _have not_ been specified by the user on the command line. In addition, this PR makes the following changes: - Remove duplicate call to `setSnapGlobals` in `yargs` middleware - The duplicate call was added in #84 because `applyConfig` would overwrite arguments given on the command line, but this is no longer the case. - Stop parsing config options from `package.json` - We used the `web3Wallet` property in `package.json` to infer arguments to the CLI - This implicit, default behavior could be surprising. Let's just use explicit configs instead. - Use `normalize` config in builders for path arguments to make `yargs` normalize paths - `sanitizeInputs` now only converts `./` to `.`, which is not done by the `yargs` normalizer (which is just `NodeJS.path.normalize(str)` - Change deprecated `required` property in builders to `demandOption` - Remove some outdated aliases for the `bundle` option
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Per the
yargs
docs,yargs.middleware(...)
is intended to be used forargv
transformations that should be run before a command is applied.applyConfig
used to transform the object exported bybuilders
. This is a bad idea. Instead, it now transformargv
in theyargs
middleware, just likesanitizeInputs
was already doing.