https://pantsbuild.org/ logo
#general
Title
# general
b

bumpy-noon-80834

10/09/2022, 9:56 PM
I consider adding a few TypeScript-based projects in a Pants/Python monorepo. I understand Pants doesn't support TypeScript so far. On one side, I enjoy Pants for Python, on the other, I enjoy yarn for TypeScript. Does anyone has any experience/idea how to integrate those together? I am not even sure what to look for. Just looking for inspiration. I guess that by default, I'll manage a /python prefix with Pants and a /typescript prefix with yarn.
Note: While it looks safer/wiser to work on 2 separate monorepos, I'd like to avoid that option, as the TypeScript code would be used to deploy the Python code.
w

wide-midnight-78598

10/09/2022, 10:50 PM
What about using Pants-controlled shell commands to call out to yarn?
b

bumpy-noon-80834

10/10/2022, 7:50 AM
Interesting feature, I'll play with it. Thanks!
šŸ‘ 1
b

busy-vase-39202

10/10/2022, 5:39 PM
Great! Would you be willing to report back on your experiments? It would be interesting to hear how that goes, for better and for worse. It could give the maintainers some helpful insights as well.
w

wide-midnight-78598

10/10/2022, 6:16 PM
Also, one other thing that would be cool is ... how would you "expect" to use Pants for TS/JS projects? Like, what sorta of developer API would you think, would you expect to be able to use yarn/npm/pnpm, or would you just expect that aspect to be transparent? What sorts of special configs would you want to access? I have a private TS plugin that I want to open, but right now, it works exactly and ONLY with my style of repos, definitely not generic. The word I've been struggling to come up with is "opinionated" - the plugin I have is suuuper opinionated
b

bumpy-noon-80834

10/10/2022, 6:19 PM
@busy-vase-39202 Sure!
@wide-midnight-78598 Hard to tell you precisely, but here are a few thoughts: ā€¢ I use yarn to manage TS workspaces and https://yarn.build/ to build them ā€¢ My next step is to write Pulumi TypeScript deployment code for a Pants-managed Python lambda function ā—¦ Right now, in another project which is 100% TypeScript, I deploy lambda functions by running
yarn build && pulumi up
ā—¦ I'll try to find a way to achieve the same with a Python lambda this time ā—¦ The easy and hackish way to to it IMO is to add a
package.json
file in the Lambda directory, which includes a
build
script who will basically run
./pants package projectName::
ā€¢ Then, I'm thinking about another use case: having a Python project depend on a TypeScript project ā—¦ For this, I expect I could add a
BUILD
file in a yarn-managed workspace and use `experimental_shell_command`to run
yarn build
ā€¢ In summary: ā—¦ Delegate all TypeScript builds to yarn/yarn.build ā—¦ Delegate all Python builds to Pants ā—¦ Integrate the 2 by adding package.json and BUILD files which simply run commands to invoke the other side build system
Regarding how to do that the right way, I'm not sure, as I'm still learning about Pants and it's definitely a complicated topic on both sides, and very ecosystem-specific. yarn does an excellent job at managing multi-workspace dependencies. This part should definitely be re-used. yarn.build is a simple wrapper built on top of it. Ideally, Pants would replace that part, but that would require Pants to reinvent part of the wheel (workspace dependency resolution), as it couldn't easily access yarn's API.
b

busy-vase-39202

10/10/2022, 7:32 PM
@bumpy-noon-80834 fyi https://github.com/toolchainlabs/toolchain/issues/15266. You and @witty-crayon-22786 might find it useful to have a chat about technical scenarios. He and other colleagues have been giving it thought recently. (There is one other option available, by the way: my company Toolchain (the lead sponsor of Pants) does Pants contract feature work. If you're ever curious about that option, @happy-kitchen-89482 is the person to ping.)
By the way, everyone in the community is very welcoming to questions and receives feedback thoughtfully. Please don't hesitate to communicate about anything that's not clear enough yet. We're happy to help a learner!
b

bumpy-noon-80834

10/10/2022, 7:37 PM
@busy-vase-39202 This GH issue is 404. Maybe private? I'll definitely consider advocating for Pants and Toolchain' services once I'll get back on a job that requires managing a Python monorepo, but for now, I'm just an humble unemployed nerd working on a personal project. šŸ˜…
b

busy-vase-39202

10/10/2022, 7:40 PM
Ooh, have you checked out Pants Jobs page? We've got some cool people in this community who needs teammates... https://www.pantsbuild.org/page/jobs
b

bumpy-noon-80834

10/10/2022, 7:42 PM
Haha, thanks! But I'm not looking for a position, Actually, I've already signed with my future employer. Just enjoying my last few weeks of free time. :)
BTW, I'm strong opinionated and I already like Pants. So if there is a legitimate use for it, I'll vouch for it. ;)
šŸ˜ƒ 1
b

busy-vase-39202

10/10/2022, 7:52 PM
Congrats on the new gig! What's the company, if you're allowed to say this at this point?
b

bumpy-noon-80834

10/10/2022, 7:55 PM
Don't know about that. But thanks! :)
w

wide-midnight-78598

10/10/2022, 11:53 PM
That was excellent feedback Philippe, thanks! In most scenarios, Pants ends up being used as the build tool and handles caching, and lots of other odds and ends, but the Node/TS/JS ecosystem is just one of those ones where you don't really want yet another tool. In my sample repo, I use (esbuild or swr or a single tool) to do what something like Vite or Snowpack or whatever do. So, I delegate to a tool to handle the underlying stuff that needs to be fast, and use pants for the higher-level stuff (while using NPM for dep management). My original idea a long long time ago was what you suggest, where Pants just delegates to whatever is in package.json (either via special package.json scripts or via another convention)
šŸ‘ 1
b

bumpy-noon-80834

10/12/2022, 10:10 PM
Quick update about my experimental integration between yarn and Pants: just tried making a yarn-managed package depend on a Pants-managed package, using the hack described above. Here is what I did:
Copy code
$ cat package.json 
{
  "name": "seneca-monorepo",
  "version": "0.0.0",
  "author": "Philippe Muller",
  "license": "UNLICENSED",
  "packageManager": "yarn@3.2.4",
  "workspaces": [
    "python/*",
    "typescript/*"
  ]
}
$ cat python/data-fred/package.json 
{
  "name": "@senecafinance/python-data-fred",
  "scripts": {
    "build": "../../pants package .::",
    "clean": "rm -f ../../dist/data-fred-downloader-lambda.zip"
  }
}
$ cd typescript/infra-data
$ cat package.json 
{
  "name": "@senecafinance/infra-data",
[..]
  "dependencies": {
[..]
    "@senecafinance/python-data-fred": "workspace:^"
  },
[..]
}
$ CI=true yarn build -vr
[ Run Order ]-------------------------------------------------------------------
ā”œā”€[0] typescript/eslint-config
ā””ā”€[0] python/data-fred
  ā””ā”€[1] typescript/prettier-config
    ā””ā”€[2] typescript/infra-lib
      ā””ā”€[3] typescript/infra-data

[ Run / Command: build / Concurrency: 12 ]--------------------------------------
āœ… typescript/eslint-config                                                0.27s
āœ… typescript/prettier-config                                              0.22s
āœ… typescript/infra-lib                                                    0.21s
āœ… python/data-fred                                                       11.62s
āœ… typescript/infra-data                                                   8.01s

[ build for All ]---------------------------------------------------------------

[ Summary ]---------------------------------------------------------------------
Success: 5
[..]
It's a bit hackish, but it works well, and it's definitely maintainable.
šŸ”„ 1
šŸ‘ 1
šŸ’ƒ 1
5 Views