- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 55
 
          feat(no-sync)!: move ts-declaration-location to peerDependencies
          #451
        
          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
base: master
Are you sure you want to change the base?
  
    feat(no-sync)!: move ts-declaration-location to peerDependencies
  
  #451
              Conversation
271865c    to
    02db95b      
    Compare
  
    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.
is it possible to move the require(), so it is loaded only when the option is configured?
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 would be a breaking change for people using the ignores option of  the no-sync rule
ts-declaration-location to peerDependenciests-declaration-location to peerDependencies
      | 
           the option was introduced in a minor (https://github.com/eslint-community/eslint-plugin-n/releases/tag/v17.19.0), but it unexpectedly introduced  so technically it can be a bugfix?  | 
    
          
 Yeah, moved below with a check for the existence of non-string  
 Likely so, I had read it as minor, given it "might break your lint build", being specific to TS users using  However, as I have no data/visibility over how this is used, "likely to break your lint build" also applies. 
 I could see it working as such having been introduced 24d ago, although if someone's using it, it'd throw. Solvable by adding   | 
    
02db95b    to
    eeb4127      
    Compare
  
    | 
           Could we added   | 
    
eeb4127    to
    54166a2      
    Compare
  
    
          
 I've tested adding  warning "eslint-plugin-n > [email protected]" has unmet peer dependency "typescript@>=4.0.0".However, I believe it should be added too nevertheless, given   | 
    
| 
           After some thought, I was wondering if we could ask  update: it was needed: https://github.com/RebeccaStevens/ts-declaration-location/blob/d86b36fc0dcba98fb964e58b8c2e7e7614fffd23/src/main.ts#L5 😂  | 
    
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.
the change LGTM, thanks for taking care of it! 👍
| 
           If we can go back to reintroduce this feature—I thought it was currently the only option (without breaking non-TypeScript projects). 
 I agreed it to be a minor. thoughts? @scagood @MichaelDeBoey  | 
    
| 
           mmm, this is a breaking change though, I would rather stick with semver for this if we do go ahead with it. 👀 @RebeccaStevens what do you think about this?  | 
    
| 
           I'm in favour of this change. It is technically a breaking chance so I would recommend a version bump but that's up to you whether or not you want to do that.  | 
    
        
          
                lib/rules/no-sync.js
              
                Outdated
          
        
      | : selectors | ||
| 
               | 
          ||
| // Only require `ts-declaration-location` if needed. | ||
| let typeMatchesSpecifier = | 
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.
Let's keep the variable defined at the top level and add a check below to see if it's undefined or not before loading the library. That way the library isn't loaded multiple times.
Additionally we could add a check to not try and load it if we've already tried before.
The way I'd do this is have the variable initialized to undefined. When we encounter the code below, if the variable is set to undefined, test if we need to load the library, if we do, do so and set this variable to it, otherwise set the variable to null.
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.
it may be a bit faster, even requires() are always cached. :)
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.
Updated based on what I understood from your comments, please check whether the change is aligned. 🙏🏼
54166a2    to
    1d93fdf      
    Compare
  
    1d93fdf    to
    9c75763      
    Compare
  
    
          
 Updated the PR description to reflect that it's a breaking change, too.  | 
    
9c75763    to
    686880f      
    Compare
  
    | if (hasAdvancedIgnores) { | ||
| if (typeMatchesSpecifier === undefined) { | ||
| try { | ||
| typeMatchesSpecifier = | ||
| /** @type {import('ts-declaration-location').default} */ ( | ||
| /** @type {unknown} */ ( | ||
| require("ts-declaration-location") | ||
| ) | ||
| ) | ||
| } catch { | ||
| typeMatchesSpecifier === null | ||
| } | ||
| } else { | ||
| throw new Error( | ||
| 'ts-declaration-location not available. Rule "n/no-sync" is configured to use "ignores" option with a non-string value. This requires ts-declaration-location to be available.' | ||
| ) | ||
| } | ||
| } | ||
| 
               | 
          
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.
Isn't this the most intuitive way?
        try{
            typeMatchesSpecifier = typeMatchesSpecifier || require("ts-declaration-location");
        } catch(e) {
            throw new Error(
                'ts-declaration-location not available. Rule "n/no-sync" is configured to use "ignores" option with a non-string value. This requires ts-declaration-location to be available.',
                { cause: e }
            );
        }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.
It is clearer, thank you.
Applied now with the Logical OR assignment operator.
686880f    to
    a108985      
    Compare
  
    | 
           The code is 👍 from me, so thank you! The one thing I am missing here is a couple of tests. For example: when  I am not sure what the best way to pull this off though: What do you think? I don't mean to block this PR with this comment, I am happy for it to go as is, I would just prefer tests! 😅  | 
    
          
 Agreed on the need for tests. I'm used to  If using   | 
    
a108985    to
    627f17b      
    Compare
  
    
          
 I think we'd only need   | 
    
627f17b    to
    8e626ca      
    Compare
  
    
          
 Thanks for confirming. I've added tests using  
 WDYT?  | 
    
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 looks good to me 👍
Thanks
8e626ca    to
    37a2a29      
    Compare
  
    | 
           Rebased, as it had a conflict on  @scagood Are there plans to remove Node   | 
    
          
 We are currently trying to match the supported version from the latest eslint. I think @aladdin-add would be in a better place to say if we're going to drop node@18 soon 🤔  | 
    
37a2a29    to
    6ec467c      
    Compare
  
    6ec467c    to
    72039f7      
    Compare
  
    72039f7    to
    48f6185      
    Compare
  
    - Add `typescript` as an optional peer dependency for the `n/no-sync` rule, used on `lib/util/get-full-type-name.js`. - Set `ts-declaration-location` as an optional peer dependency for the `n/no-sync` rule. - Move `ts-declaration-location` to `devDependencies` for development and testing. - Update the `n/no-sync` documentation to refer the updated peer dependency requirement. - Update `n/no-sync` rule to conditionally require `ts-declaration-location` only when advanced ignores are used. - Remove unused eslint-disable directive n/no-unpublished-require on `lib/util/get-full-type-name.js`, as `typescript` is now an optional peer dependency. - Add tests to ensure the rule throws an error when `ts-declaration-location` or TypeScript parser services are not available. - Add `sinon` as a dev dependency, used for mocking in tests.
48f6185    to
    07ad01e      
    Compare
  
    | 
           Hey @MichaelDeBoey , are we missing any changes?  | 
    
Description
ts-declaration-locationfromdependenciestodevDependenciesandpeerDependencies, declaring it as optional onpeerDependenciesMeta, which hastypescriptas a peer dependency.As
ts-declaration-locationis already tentatively loaded forn/no-sync, the plugin keeps working as expected, throwing with a message identifying the missing package in case it'd be needed while trying to use theignoresoption with a non-string value.n/no-syncdocumentation to refer the updated peer dependency requirement.n/no-syncrule to conditionally requirets-declaration-locationonly when advanced ignores are used.typescriptas an optional peer dependency for then/no-syncrule, used onlib/util/get-full-type-name.js, removing unusedeslint-disabledirectiven/no-unpublished-require.Note
Set asfeatas this should be at least a minor bump, as it may break a lint build.Updated to
feat!after discussion, as it's a breaking change for TypeScript users using advanced TypeScript-based ignores.Related issues
Warning received while installing
eslint-plugin-non JS projects withouttypescript:chore(no-sync): remove
@typescript-eslint/utils#449 addressed@typescript-eslint/utils.