Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Expose programmatic api #165

Open
Rokt33r opened this issue Dec 13, 2018 · 3 comments
Open

Expose programmatic api #165

Rokt33r opened this issue Dec 13, 2018 · 3 comments

Comments

@Rokt33r
Copy link
Contributor

Rokt33r commented Dec 13, 2018

It would be nice if dtslint expose programmatic api. So I can provide the location of configurations(tsconfig.json and tslint.json), a definition file and tests.

@sandersn
Copy link
Member

index.js:runTests is a good starting point for what you want. It's not exported right now but I added that and then did this from ~/DefinitelyTyped:

$ node
> var dtslint = require('../dtslint/bin/index.js')
> dtslint.runTests(path.join(process.cwd(), 'types/openpgp'))
Promise {
  <pending>,
  domain:
   Domain {
     domain: null,
     _events:
      [Object: null prototype] {
        removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> (node:19054) UnhandledPromiseRejectionWarning: Error: /home/nathansa/DefinitelyTyped/types/openpgp/index.d.ts:578:45
ERROR: 578:45  expect  Compile error in [email protected] but not in [email protected].
Fix with a comment '// TypeScript Version: 3.2' just under the header.
Type 'ReadableStream' is not generic.

    at /home/nathansa/dtslint/bin/index.js:159:19
    at Generator.next (<anonymous>)
    at fulfilled (/home/nathansa/dtslint/bin/index.js:5:58)
(node:19054) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

Which is the right output, plus a warning that I don't handle exceptions from the promise.

@Rokt33r
Copy link
Contributor Author

Rokt33r commented Dec 18, 2018

Seems the errors are emitted as string. I think it should be fine for now.


I want to discuss two issues before I submit my pr.

File structure:

The current outDir is bin. After we provide the programatic api, the name becomes confusing.

So I think we should modify outDir and places files like the below.

dist/bin/index.ts # CLI
dist/index.ts # main module which exporting apis

Exposed APIs

I'm going to expose 3 apis:

  1. installAll
  2. cleanInstalls
  3. runTests

Let me know if we should expose more or less.

@ghost
Copy link

ghost commented Jul 22, 2021

Could this be done from the CLI? I want to put my d.ts in the root folder

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants