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

Ts migration #31

Merged
merged 40 commits into from
May 22, 2019
Merged

Ts migration #31

merged 40 commits into from
May 22, 2019

Conversation

wolfy1339
Copy link
Member

No description provided.

@wolfy1339 wolfy1339 marked this pull request as ready for review May 16, 2019 04:19
@wolfy1339
Copy link
Member Author

@gr2m I think this is everything.
Only a couple things remain:

  • The custom cache test doesn't work anymore
  • There is a timeout from mocha that i'm not exactly sure what to do/ how it works in jest

@gr2m
Copy link
Contributor

gr2m commented May 16, 2019

fyi I’ve put together some information on how I setup the other packages with @pika/pack:
https://gist.github.com/gr2m/5dd2ec6e3a04c3dc79f0cbb46decbe46

I hope to get to review it in detail later today!

src/index.ts Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@wolfy1339
Copy link
Member Author

Ah shucks. Bundlesize is gone way up past the 1KB limit

@gr2m
Copy link
Contributor

gr2m commented May 17, 2019

oh nice you got all the other tests passing? That’s great!

Don’t worry about bundle size too much, it’s just a safety net to not accidentally increase the bundle size 10×. Just bump it to 1.5KB or 2KB. Maybe we’ll focus on bundle size some day, but that’s not our priority right now

@wolfy1339
Copy link
Member Author

wolfy1339 commented May 17, 2019 via email

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

fantastic work!!! Just two minor comments!

test/index.test.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,197 @@
import { install } from "lolex";
import nock from "nock";
import { stub } from "simple-mock";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think jest has it’s own stubbing, maybe we use that instead of simple-mock?
https://jestjs.io/docs/en/mock-function-api.html

We can also do it in a follow up PR

@wolfy1339
Copy link
Member Author

Everything is done now. I've bumped up the bindlesize limit to 15kb, to make tests pass.

@wolfy1339 wolfy1339 requested a review from gr2m May 19, 2019 07:31
@wolfy1339
Copy link
Member Author

I've rebased this and fixed all conflicts. It's good to go now

@gr2m
Copy link
Contributor

gr2m commented May 21, 2019

Thanks @wolfy1339, I’m reviewing it now!

Can we chat some time? I’ve pinged you in the Probot slack :)

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@gr2m
Copy link
Contributor

gr2m commented May 21, 2019

I’m testing this PR against Probot’s test suite. One error I see is

image

That is not a very helpful error message 😞 any idea what it could mean?

@gr2m
Copy link
Contributor

gr2m commented May 21, 2019

If I comment out the private api; line, Probot’s tests pass

package.json Outdated
"@pika/pack": "^0.3.7",
"@pika/plugin-build-node": "^0.3.16",
"@pika/plugin-build-node": "^0.4.0",
"@pika/plugin-build-web": "^0.3.16",
Copy link
Contributor

Choose a reason for hiding this comment

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

missed @pika/plugin-build-web?

@wolfy1339
Copy link
Member Author

I’m testing this PR against Probot’s test suite. One error I see is

image

That is not a very helpful error message 😞 any idea what it could mean?

I don't understand at all. It's seems like a problem with the compiler, if I add the any type to the definition file, it works fine

@gr2m
Copy link
Contributor

gr2m commented May 21, 2019

I don't understand at all. It's seems like a problem with the compiler, if I add the any type to the definition file, it works fine

Can we just remove it? It’s internal only anyway, isn’t it?

@wolfy1339
Copy link
Member Author

I see, it's part of a bigger error. Yes, it's internal, we could remove it.
I'm not sure why it picks up though, it's supposed to be private and the declaration file contains no type for it, it's treated as an implicit any

@gr2m
Copy link
Contributor

gr2m commented May 21, 2019

I also don’t know but if removing is what it takes to unblock this PR, I’d just remove it? Or do you have something else in mind?

@wolfy1339
Copy link
Member Author

wolfy1339 commented May 21, 2019 via email

@gr2m
Copy link
Contributor

gr2m commented May 21, 2019

Okay I’ve an idea how to workaround this, I’ll try it later, but have to do some chores first

@gr2m
Copy link
Contributor

gr2m commented May 21, 2019

Hmm no luck. First I tried sth like this

function createApi({ id, privateKey, baseUrl, cache }: OctokitAppOptions) {
  const state = {
    id,
    privateKey,
    request: baseUrl ? request.defaults({ baseUrl }) : request,
    cache: cache || getCache()
  }

  return {
    getSignedJsonWebToken: getSignedJsonWebToken.bind(null, state),
    getInstallationAccessToken: getInstallationAccessToken.bind(null, state)
  }
}

export class App {
  constructor(options: OctokitAppOptions): Api {
    return createApi(options)
  }
}

But Typescript does not allow type annotations on constructors.

And when trying

export function App({ id, privateKey, baseUrl, cache }: OctokitAppOptions) {
  const state = {
    id,
    privateKey,
    request: baseUrl ? request.defaults({ baseUrl }) : request,
    cache: cache || getCache()
  };

  return {
    getSignedJsonWebToken: getSignedJsonWebToken.bind(null, state),
    getInstallationAccessToken: getInstallationAccessToken.bind(null, state)
  };
}

Then the new keyword is no longer allowed, as expected.

What do you think about this?

export class App {
  constructor({ id, privateKey, baseUrl, cache }: AppOptions) {
    const state: State = {
      id,
      privateKey,
      request: baseUrl ? request.defaults({ baseUrl }) : request,
      cache: cache || getCache()
    };
    this.getSignedJsonWebToken = getSignedJsonWebToken.bind(null, state),
    this.getInstallationAccessToken = getInstallationAccessToken.bind(null, state)
  }

  getSignedJsonWebToken: () => string
  getInstallationAccessToken: (options: {
    installationId: number;
  }) => Promise<string>
}

🤔

@wolfy1339
Copy link
Member Author

Seems good. It's not exactly the same declarations outputted, but it's the same usage, and it works

@gr2m
Copy link
Contributor

gr2m commented May 22, 2019

Okay thanks, I’ll finish it up then

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

@gr2m gr2m merged commit 3b6751b into octokit:master May 22, 2019
@octokitbot
Copy link
Collaborator

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@wolfy1339 wolfy1339 deleted the ts-migration branch May 22, 2019 06:27
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

Successfully merging this pull request may close these issues.

None yet

3 participants