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

Move typescript package into subdirectory #170

Merged
merged 12 commits into from
Feb 6, 2025
Merged

Move typescript package into subdirectory #170

merged 12 commits into from
Feb 6, 2025

Conversation

amacneil
Copy link
Contributor

@amacneil amacneil commented Feb 2, 2025

Changelog

None

Docs

None

Description

Migrate @foxglove/schemas typescript package into typescript directory. This prepares for other typescript packages to live in this repo.

Also restrict to only necessary files included in the npm package. Currently lots of stuff unintentionally included:

image

New package contents:

image

@amacneil amacneil marked this pull request as draft February 2, 2025 16:45
@amacneil amacneil changed the title Move typescript package into subdirectory WIP: Move typescript package into subdirectory Feb 2, 2025
@amacneil amacneil marked this pull request as ready for review February 2, 2025 21:57
@amacneil amacneil changed the title WIP: Move typescript package into subdirectory Move typescript package into subdirectory Feb 2, 2025
Copy link
Member

@jtbandes jtbandes left a comment

Choose a reason for hiding this comment

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

I don't understand why there's both schemas/typescript and typescript/schemas

typescript/schemas/tsconfig.json Outdated Show resolved Hide resolved
"url": "git+https://github.com/foxglove/foxglove-sdk.git",
"directory": "typescript/schemas"
},
"main": "./dist/typescript/schemas/src/index.js",
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused as to why this path includes typescript/schemas, why isn't it just e.g. dist/index.js or dist/typescript/index.js? And do we have a typescript/schemas/typescript folder? That seems weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also answering your other question at the same time:

I don't understand why there's both schemas/typescript and typescript/schemas

  • typescript/schemas is the typescript @foxglove/schemas package. I thought about nesting putting it in typescript/@foxglove/schemas but that seemed overkill unless we plan to have some non-foxglove-namespaced packages in this repo
  • schemas/typescript are the generated type definitions for our schemas

Now one option would be to move the generated typescript types into typescript/schemas/src/types, that would almost lead to the schemas package being self contained. It might be a bit weird that not all the generated schemas would live under top level schemas package, but that's not as much of a concern since anyone using typescript would be much more likely to import the package rather than copy/pasting files from the repo.

The wrinkle is that we also currently bundle the jsonschemas into the typescript package, and nesting them only under the typescript package seems less of a clear win, since people using other languages might want to easily find and copy/paste them (like they do with proto/flatbuffer/etc). Side note: I looked in our app and we only use the jsonschemas in a single test, so maybe we could stop bundling them into @foxglove/schemas?

This brings me to your question why the package.json main path is dist/typescript/schemas/src/index.js not just dist/index.js. It's because we import stuff from above the package, so typescript infers our baseUrl as the repo root, meaning the dist output is super nested. We could solve that by putting all the typescript + jsonschemas under typescript/schemas/src so that src compiles cleanly to dist, but as mentioned above that is a bit weird especially for jsonschema.

Another route I could take is a prepack script in this package which copies the files into the package at build time, and we gitignore the duplicates. That seems like probably the best option which allows us to clean up the dist dir.

Thoughts?

Copy link
Contributor Author

@amacneil amacneil Feb 4, 2025

Choose a reason for hiding this comment

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

I tried the latter approach and quite like it. I pushed it to this branch, the main changes are in c72299d.

typescript/schemas/package.json Outdated Show resolved Hide resolved
typescript/schemas/README.md Outdated Show resolved Hide resolved
@defunctzombie
Copy link
Contributor

Did you test your new package in the app repo to ensure that all the package.json entrypoints resolve as expected? You should be able to npm package it and then yarn install <path to pkg> (or maybe use a yarn resolution to the packaged file locally)

@amacneil amacneil requested a review from jtbandes February 5, 2025 05:11
@amacneil amacneil force-pushed the adrian/ts-package branch 4 times, most recently from 6b1eb43 to 355c693 Compare February 5, 2025 07:07
@amacneil
Copy link
Contributor Author

amacneil commented Feb 5, 2025

@defunctzombie confirmed the current version of this PR is compatible with app (#8633)

@@ -3,19 +3,26 @@ import fs from "fs/promises";
import path from "path";
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wanted you could put the scripts into a packages folder and also have them part of the yarn workspace. Could even expose them with bin fields in package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok will have a look at that in another PR, this one is big enough

@amacneil amacneil merged commit ee094ad into main Feb 6, 2025
27 checks passed
@amacneil amacneil deleted the adrian/ts-package branch February 6, 2025 04:18
@amacneil amacneil mentioned this pull request Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants