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

fix(build): use typescript to produce declaration files #550

Merged
merged 11 commits into from Jun 13, 2023

Conversation

kfcampbell
Copy link
Member

Replicating octokit/request.js#584 to another repo.


Pika has been deprecated for a while now, and the project has now been archived, and because of that the released npm package is missing most of the files generated by the build step.

Uses esbuild to transpile the TS source code into an ESM source, NodeJs bundle, and a browser bundle

Uses the TypeScript compiler to generate the types.

Behavior

Before the change?

  • Uses pika for the build system
  • The released npm package is missing most of the files generated by the build step. dist-node, dist-types, dist-web... even though they are generated correctly.

After the change?

  • Uses esbuild to generate the JS bundles
  • Uses the TypeScript compiler to generate the type definitions
  • The correct file matching patterns are used so we publish all the necessary files again.

Additional info

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Added the appropriate label for the given change

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes (Please add the Type: Breaking change label)
  • No

If Yes, what's the impact:

  • N/A

Pull request type

Please add the corresponding label for change this PR introduces:

  • Bugfix: Type: Bug
  • Dependencies/code cleanup: Type: Maintenance

@ghost ghost added this to Inbox in JS Jun 1, 2023
@kfcampbell kfcampbell added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Jun 1, 2023
@ghost ghost moved this from Inbox to Maintenance in JS Jun 1, 2023
@kfcampbell kfcampbell marked this pull request as ready for review June 1, 2023 23:36
@kfcampbell kfcampbell requested a review from wolfy1339 June 1, 2023 23:36
@kfcampbell kfcampbell changed the title First pass at switching to esbuild fix(build): switch to esbuild Jun 1, 2023
scripts/build.mjs Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@wolfy1339
Copy link
Member

I'm not sure why there is a build system here. It isn't very useful here as there isn't any JavaScript code at all, it's only types.

I propose to instead remove the need for the build system instead and simply just use typescript to produce declaration filea.

@gr2m
Copy link
Contributor

gr2m commented Jun 2, 2023

I propose to instead remove the need for the build system instead and simply just use typescript to produce declaration filea.

Agreed

@kfcampbell
Copy link
Member Author

Hi, I'm just coming back to this now.

I propose to instead remove the need for the build system instead and simply just use typescript to produce declaration filea.

I'm happy to strip out esbuild, glob, and the current build system. Are there other actions I'm missing that are required to produce declaration files, or is the existence of the files themselves enough?

@wolfy1339
Copy link
Member

I'm happy to strip out esbuild, glob, and the current build system. Are there other actions I'm missing that are required to produce declaration files, or is the existence of the files themselves enough?

  • Strip out esbuild and glob.
  • Keep the tsconfig.json just as it is in this PR
  • Keep typescript in the build command

@wolfy1339
Copy link
Member

We will still need a build script to generate the package.json, so don't completely remove the build script

@kfcampbell kfcampbell changed the title fix(build): switch to esbuild fix(build): use typescript to produce declaration files Jun 13, 2023
scripts/build.mjs Outdated Show resolved Hide resolved
packages: "external",
};

async function main() {
Copy link
Member

Choose a reason for hiding this comment

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

Indentation needs fixing

Copy link
Member Author

Choose a reason for hiding this comment

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

npm run lint:fix reports correct indentation for me.

Co-authored-by: wolfy1339 <[email protected]>
@kfcampbell kfcampbell changed the base branch from main to beta June 13, 2023 20:26
@kfcampbell
Copy link
Member Author

I've added an Actions step to run npm run build, which wasn't previously being done here. I can reproduce the error locally, though I'm not sure why it's happening yet as the license file does exist in the repo. More troubleshooting is required here.

Copy link
Member

@wolfy1339 wolfy1339 left a comment

Choose a reason for hiding this comment

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

This workflow is independent of any specific Node version, so use the latest LTS release available on GitHub actions. Like in other repositories

.github/workflows/update.yml Outdated Show resolved Hide resolved
@wolfy1339
Copy link
Member

I see why. The directory doesn't exist at the time we try to copy

@kfcampbell
Copy link
Member Author

Ahh, yep! I've added a call to mkdir there. Now the generated files after building look like:

 sh$ ls -R pkg/
pkg/:
dist-types/  LICENSE  package.json  README.md

pkg/dist-types:
AuthInterface.d.ts                      RequestInterface.d.ts
EndpointDefaults.d.ts                   RequestMethod.d.ts
EndpointInterface.d.ts                  RequestOptions.d.ts
EndpointOptions.d.ts                    RequestParameters.d.ts
Fetch.d.ts                              RequestRequestOptions.d.ts
generated/                              ResponseHeaders.d.ts
GetResponseTypeFromEndpointMethod.d.ts  Route.d.ts
index.d.ts                              Signal.d.ts
OctokitResponse.d.ts                    StrategyInterface.d.ts
RequestError.d.ts                       Url.d.ts
RequestHeaders.d.ts                     VERSION.d.ts

pkg/dist-types/generated:
Endpoints.d.ts

which seems correct to me.

@kfcampbell kfcampbell requested a review from gr2m June 13, 2023 20:45
scripts/build.mjs Outdated Show resolved Hide resolved
Co-authored-by: wolfy1339 <[email protected]>
@wolfy1339
Copy link
Member

Why target the beta branch? It would be fine in main

@kfcampbell kfcampbell changed the base branch from beta to main June 13, 2023 20:55
@kfcampbell
Copy link
Member Author

Ahh, I was thinking to batch with the present changes there but I realize this shouldn't be a breaking change so there's no reason to do so. I've changed it back now.

@wolfy1339 wolfy1339 merged commit 9953e34 into main Jun 13, 2023
6 checks passed
@wolfy1339 wolfy1339 deleted the switch-to-esbuild branch June 13, 2023 21:27
@octokitbot
Copy link
Collaborator

🎉 This PR is included in version 9.3.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR
Projects
Archived in project
JS
  
Maintenance
Development

Successfully merging this pull request may close these issues.

None yet

4 participants