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

Re-introduce Typescript changes #1551

Merged
merged 15 commits into from
Sep 22, 2022
Merged

Re-introduce Typescript changes #1551

merged 15 commits into from
Sep 22, 2022

Conversation

anniel-stripe
Copy link
Contributor

@anniel-stripe anniel-stripe commented Sep 13, 2022

Summary

r? @kamil-stripe

Re-introduce the changes reverted in #1547 , with additional changes to minimize differences between the original and TypeScript-compiled JavaScript code.

The first 3 commits of this PR are separated as follows:

  1. "Configure Typescript build and CI" corresponds to the changes in Build Typescript and migrate StripeResource #1539 (also adds yarn install to prepack script so that dependencies are correctly installed before building, as in Run yarn install in prepack script #1545)
  2. "Migrate stripe, StripeResource, StripeMethod, autoPagination, makeRequest, and Error" corresponds to the changes in Migrate Stripe infrastructure to Typescript #1543
  3. "Enable no-var-requires, update imports/exports" removes the no-var-requires rule, and updates imports/exports in the migrated TS files so that the compiled JS code is functionally identical to the originals, and does not include the line Object.defineProperty(exports, "__esModule", { value: true });

The remaining commits add test projects importing stripe with both CommonJS- and ES-style imports, and also updates imports / exports to follow this pattern:

  1. Convert all module.exports to export = syntax in migrated TS files, export for in stripe.ts to preserve named and default exports.
  2. Convert all const = require to import = require syntax for modules that have been migrated to TypeScript to get type checking

@anniel-stripe anniel-stripe marked this pull request as ready for review September 13, 2022 22:34
src/makeRequest.ts Outdated Show resolved Hide resolved
src/stripe.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/StripeMethod.ts Outdated Show resolved Hide resolved
anniel-stripe and others added 2 commits September 14, 2022 09:42
Co-authored-by: pakrym-stripe <99349468+pakrym-stripe@users.noreply.github.com>
lib/Error.js Outdated Show resolved Hide resolved
lib/StripeResource.js Outdated Show resolved Hide resolved
lib/StripeResource.js Outdated Show resolved Hide resolved
lib/Webhooks.js Outdated Show resolved Hide resolved
lib/Webhooks.js Outdated Show resolved Hide resolved
lib/stripe.js Outdated Show resolved Hide resolved
lib/stripe.js Outdated Show resolved Hide resolved
lib/stripe.js Outdated Show resolved Hide resolved
Copy link
Contributor

@kamil-stripe kamil-stripe left a comment

Choose a reason for hiding this comment

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

Few comments but this looks promising!

package.json Outdated Show resolved Hide resolved
@kamil-stripe
Copy link
Contributor

LGTM. Let's talk with @xavdid-stripe tomorrow.

Copy link
Member

@xavdid-stripe xavdid-stripe left a comment

Choose a reason for hiding this comment

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

I gave the following files a fairly thorough read:

  • StripeMethod
  • StripeResource
  • autoPagination.js
  • makeRequest.js
  • stripe.js
  • Error.js

I spot checked a few more, but stopped when they mostly had whitespace lines removed.

Nothing jumped out as being functionally different in those files - most changes were formatting-only (or explicitly commented on as a change).

If you're looking for a more thorough comparison, one option for surfacing any non-superficial changes would be to take src/x.js and lib/x.js either:

  • run them both through a formatter like prettier and then diff that result
  • diff the ASTs of each, so we can better compare structural changes vs formatting ones

Happy to run with that a bit if it's something you're interested in! Or we can probably call this "good enough" 😁

@anniel-stripe anniel-stripe merged commit fffee63 into master Sep 22, 2022
Copy link
Member

@xavdid-stripe xavdid-stripe left a comment

Choose a reason for hiding this comment

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

I know this is merged, but wanted to quickly comment on the changes that popped out. Thanks for running prettier, really helped find changes!

_errorHandler(req, requestRetries, callback) {
return (message, detail) => {
callback.call(
this,
new StripeConnectionError({
message: this._generateConnectionErrorMessage(requestRetries),
detail: error,
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this line changed. Was that intentional?

const makeRequest = (apiVersion, headers, numRetries) => {
// timeout can be set on a per-request basis. Favor that over the global setting
const timeout =
options.settings &&
options.settings.timeout &&
Copy link
Member

Choose a reason for hiding this comment

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

this is TS being extra defensive, no problem there.

@@ -598,11 +518,9 @@ StripeResource.prototype = {
options.headers,
options.settings
);

makeRequest(apiVersion, headers);
makeRequest(apiVersion, headers, 0);
Copy link
Member

Choose a reason for hiding this comment

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

This 0 is an addition- I remember a comment from a previous revision, but it seems to have been wiped from GH.

@@ -150,12 +133,10 @@ const utils = (module.exports = {
if (typeof arg === 'string') {
opts.auth = args.pop();
} else if (utils.isOptionsHash(arg)) {
const params = {...args.pop()};

const params = Object.assign({}, args.pop());
Copy link
Member

Choose a reason for hiding this comment

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

this is functionally equivalent

// Expose StripeResource on the instance too
this.StripeResource = Stripe.StripeResource;
}

Stripe.errors = require('./Error');
Stripe.errors = _Error;
Copy link
Member

Choose a reason for hiding this comment

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

These are just repoints, also fine

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.

4 participants