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

Eliminating getters from yargs Options #272

Open
5 tasks
ChristopherPHolder opened this issue Mar 6, 2024 · 1 comment
Open
5 tasks

Eliminating getters from yargs Options #272

ChristopherPHolder opened this issue Mar 6, 2024 · 1 comment

Comments

@ChristopherPHolder
Copy link
Collaborator

TL;DR

Some Parameter have a get function which will cause issues when migrating to ESM and require using incorrect typing.

These need to be removed.

Description

Using the getter for a parameter is requiring use to use Type Assertions.

This is an issue because it will not work property in some cases and typescript will ignore the error.

As an example we can look at the verbose param:

// packages/cli/src/lib/global/options/verbose.ts

import { argv } from 'yargs';
import { Param } from './verbose.model';
import { ArgvOption } from '../../core/yargs/types';
import { GlobalOptionsArgv } from './types';
import { getEnvPreset } from '../../pre-set';


export const param: Param = {
  verbose: {
    alias: 'v',
    type: 'boolean',
    description: 'Run with verbose logging',
    default: getEnvPreset().verbose
  }
};

// We don't rely on yargs option normalization features as this can happen before cli bootstrap
export function get(): boolean  {
  const {verbose} = argv as unknown as GlobalOptionsArgv;
  return verbose;
}

Going around the yargs parser is problematic as it means we cannot simply expect it to work in the same way it yargs is suppose to.

Many of the getters for the options are being removed in this MR: #270

However some require making further modifications to the code base to not have any behaviour changes.

In particular I am referring to the the following yargs options:

  • openReport
  • dryRun
  • interactive
  • verbose
  • rcPath

Issue with getters in ESM

I believe the issue is related to live bindings. Or more broadly the way ES6 Modules export works.

More resources on the topic:

What do ES6 modules export? by Axel Rauschmayer
ES modules: A cartoon deep-dive by Lin Clark
Chapter on Modules in Exploring JS by Axel Rauschmayer

@ChristopherPHolder
Copy link
Collaborator Author

MR 273 fixes: openReport & dryRun

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

No branches or pull requests

1 participant