Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Make applyConfig transform argv instead of builders #84

Merged
merged 1 commit into from
Feb 15, 2021

Conversation

rekmarks
Copy link
Member

Per the yargs docs, yargs.middleware(...) is intended to be used for argv transformations that should be run before a command is applied. applyConfig used to transform the object exported by builders. This is a bad idea. Instead, it now transform argv in the yargs middleware, just like sanitizeInputs was already doing.

Base automatically changed from snap-config-refactor to main February 15, 2021 22:53
@rekmarks rekmarks marked this pull request as ready for review February 15, 2021 22:54
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');
});
});
Copy link
Member Author

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.

Copy link
Contributor

@astarinmymind astarinmymind left a comment

Choose a reason for hiding this comment

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

nice!!

@rekmarks rekmarks merged commit c632d15 into main Feb 15, 2021
@rekmarks rekmarks deleted the refactor-apply-config branch February 15, 2021 22:58
@rekmarks rekmarks mentioned this pull request Feb 18, 2021
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.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants