lemon-noon-33245
04/26/2023, 3:04 PMbusy-vase-39202
04/26/2023, 3:28 PMlemon-noon-33245
04/26/2023, 3:31 PMadhoc_tool
but the plan was to switch to the JS/TS native backend once that’s ready. In particular we need pnpm
or yarn
support since we’re heavily relying on workspaces.busy-vase-39202
04/26/2023, 3:38 PMlemon-noon-33245
04/26/2023, 3:40 PMbusy-vase-39202
04/26/2023, 3:42 PMlemon-noon-33245
04/26/2023, 3:44 PMworried-painter-31382
04/26/2023, 3:47 PMworried-painter-31382
04/26/2023, 3:47 PMbusy-vase-39202
04/26/2023, 3:47 PMlemon-noon-33245
04/26/2023, 3:48 PMbusy-vase-39202
04/26/2023, 3:55 PMbusy-vase-39202
04/26/2023, 3:55 PMworried-painter-31382
04/30/2023, 5:32 PMlemon-noon-33245
05/02/2023, 1:59 PMlemon-noon-33245
05/02/2023, 2:49 PMworried-painter-31382
05/02/2023, 5:19 PMlemon-noon-33245
05/02/2023, 5:23 PMpackage_json
target to the root of our pnpm workspace folder and to start testing things out just ran pants package //node:package
. It starts installing node modules in the sandbox but then I get an error:
Failed to digest inputs: "Failed to open \"/private/var/folders/rz/n_vkc61s0_90pc18wy28l4mw0000gn/T/pants-sandbox-9xQzu3/node/node_modules/.pnpm/@typescript-eslint+typescript-estree@5.56.0_typesc
ript@4.9.3/node_modules/@typescript-eslint/typescript-estree/dist/node-utils.js\": Too many open files (os error 24)"
I tried setting a higher ulimit with ulimit -n 100000
but still got the same error.lemon-noon-33245
05/02/2023, 5:25 PMlemon-noon-33245
05/02/2023, 5:25 PMworried-painter-31382
05/02/2023, 5:28 PMpants package <package_json_target>
will produce a an output the same as pnpm pack
would do. If you're looking to produce a transpiled output, a node_build_script
is probably more similar to what you'd do in turborepo or similarworried-painter-31382
05/02/2023, 5:29 PMworried-painter-31382
05/02/2023, 5:32 PM{
"scripts": {
"build": "tsc ./src"
}
}
You'd have to tell pants about it in your BUILD
via
package_json(scripts[node_build_script(entry_point="build"]))
Andreas has made some awesome headway with help with symbols, so pants help node_build_script
(probably) works to at least get some idea what it expects for inputs and outputsworried-painter-31382
05/02/2023, 5:33 PMpants export-codegen
goallemon-noon-33245
05/02/2023, 6:05 PMuname: command not found
- I believe probably bc PATH hasn’t been set in the sandbox so Next can’t find uname.
2. Couldn't find a pages directory
. I believe probably bc I haven’t specified what are the sources that should be moved to the sandbox. Tried settings the _sources
argument in node_build_script
but something tells me that this looks like a private field, lollemon-noon-33245
05/02/2023, 6:25 PMdependencies
on package_json nowworried-painter-31382
05/02/2023, 6:26 PMadhoc_tool
if you're familiar.
1. No, not yet. I want to introduce feature parity with adhoc_tool
here, since it seems nodejs ecosystem has some amount of assumptions about what binaries that are ~always available. You probably can work around it by assigning PATH=
in the build script
2. dependencies
yes! If you have javascript sources, pants can infer this for you, if you dont, you'd need a `resources`target and set the dependencies in the BUILD
fileworried-painter-31382
05/02/2023, 6:27 PMworried-painter-31382
05/02/2023, 6:29 PMdependencies=["src/index.js"]
etc.lemon-noon-33245
05/02/2023, 6:31 PMtypes
lib workspace that this project imports and it’s marked as workspace:^types
in package.json
. Pants couldn’t infer that dependency right away (maybe because it’s also a TS project?), so I had to add it to dependencies
worried-painter-31382
05/02/2023, 6:33 PMpackage_json
?lemon-noon-33245
05/02/2023, 6:33 PMworried-painter-31382
05/02/2023, 6:33 PMlemon-noon-33245
05/02/2023, 6:33 PMlemon-noon-33245
05/02/2023, 6:34 PMexport-codegen
!!!lemon-noon-33245
05/02/2023, 6:37 PMlemon-noon-33245
05/02/2023, 6:38 PMworried-painter-31382
05/02/2023, 6:43 PMlemon-noon-33245
05/02/2023, 6:56 PMlemon-noon-33245
05/02/2023, 6:57 PMdependencies
but no goworried-painter-31382
05/02/2023, 7:02 PMworried-painter-31382
05/02/2023, 7:02 PMprepare
lifecycle script and make sure it does ~the same thing as the build
lemon-noon-33245
05/02/2023, 7:05 PMpkg1
depends on the types
source files (not transpiled). types
are in pkg1
package.json dependencies as workspace:^types
. I added package_json
to the types
BUILD file as you mentioned before to see if pants would infer the dependency and copy the source files but it didn’t. So I added the source files to package_json
in the dependencies
parameter. No success as well.worried-painter-31382
05/02/2023, 7:07 PMlemon-noon-33245
05/02/2023, 7:07 PMtypes:files
to the pkg1
dependencies it works. What I can’t get working is the implicit resolution of dependencies in the workspaceworried-painter-31382
05/02/2023, 7:09 PMpants peek <path/to/types/package.json>
say?lemon-noon-33245
05/02/2023, 7:12 PMpackage.json
. The dependencies I set up explicitly also don’t show up, FIYworried-painter-31382
05/02/2023, 7:12 PM{
"dependencies": {
"types": "workspace:^"
}
}
This is the dependencies in pkg1?lemon-noon-33245
05/02/2023, 7:13 PMlemon-noon-33245
05/02/2023, 7:14 PMworried-painter-31382
05/02/2023, 7:14 PMlemon-noon-33245
05/02/2023, 7:14 PMlemon-noon-33245
05/02/2023, 7:16 PMpants peek
worried-painter-31382
05/02/2023, 7:17 PMpants list
you'll get a list of targets under a directorylemon-noon-33245
05/02/2023, 7:19 PMnode/libs/types#__techdocs/cli
node/libs/types#__trinio/types
node/libs/types#jest
node/libs/types#node/libs/types/package.json
node/libs/types#ts-jest
node/libs/types#tslib
node/libs/types#typescript
node/libs/types#vite
node/libs/types#vite-dts
node/libs/types#yarn.lock
node/libs/types/.eslintrc.json:files
node/libs/types/BUILD:files
node/libs/types/README.md:files
node/libs/types/jest.config.js:files
node/libs/types/package.json:files
node/libs/types/tsconfig.json:files
node/libs/types/tsconfig.lib.json:files
node/libs/types/tsconfig.spec.json:files
lemon-noon-33245
05/02/2023, 7:19 PMworried-painter-31382
05/02/2023, 7:20 PMlemon-noon-33245
05/02/2023, 7:20 PMworried-painter-31382
05/02/2023, 7:20 PMworried-painter-31382
05/02/2023, 7:21 PMlemon-noon-33245
05/02/2023, 7:22 PMworried-painter-31382
05/02/2023, 7:23 PMlemon-noon-33245
05/02/2023, 7:23 PM{
"dependencies": {
"@trinio/types": "workspace:^"
}
}
worried-painter-31382
05/02/2023, 7:53 PMBUILD
for the types
package is something like
package_json(dependencies=[":sources"])
resources(name="sources", sources="*.tsx")
and pkg1
package_json(dependencies=[":sources", "lib/types:sources" , "lib/types/package.json"])
resources(name="sources", sources="*.tsx")
?lemon-noon-33245
05/02/2023, 7:54 PMresources
I was using files
is that a problem?worried-painter-31382
05/02/2023, 7:55 PMworried-painter-31382
05/02/2023, 7:57 PMlemon-noon-33245
05/02/2023, 8:04 PMpackage_json(dependencies=["//lib/types:sources"])
to pkg1
lemon-noon-33245
05/02/2023, 8:05 PMworried-painter-31382
05/02/2023, 8:05 PMworried-painter-31382
05/02/2023, 8:05 PMsource
(so files
, or javascript_source
for example) dependencies to find owning package_json
, and from there populate sandboxes.
package_json
files can depend on javascript files, they don't depend on eachother currently, strangely enough. This why pants peek
was confounding...
What this means is that current dependency inference will not guess, even though you've listed a first party dep on your package, since there's no dependency between some .tsx file in pkg1 to a .tsx file in the other package. I did not reflect on this because I've worked solely with javascript sources which ties this together because an import in a package will then resolve this.lemon-noon-33245
05/02/2023, 8:07 PMlemon-noon-33245
05/02/2023, 8:08 PMworried-painter-31382
05/02/2023, 8:11 PMlib/pkg1/file.tsx
has import { MyType } from "types/MyType"
, pants will know lib/types/MyTypes.tsx
is a dep, pants will see that lib/types/package.json
is the owner, it will be installed, all is wellworried-painter-31382
05/02/2023, 8:12 PMlemon-noon-33245
05/02/2023, 8:42 PMpackage_json
output, theoretically I just need to add :package-json
as a dependency, correct?lemon-noon-33245
05/02/2023, 8:46 PMdocker_image
depends on package_json
it’s trying to package the package_json
target and getting the following error:
16:43:03.51 [ERROR] 1 Exception encountered:
Engine traceback:
in `package` goal
ProcessExecutionFailure: Process 'Packaging .tgz archive for @trinio/checkout@1.0.0' failed with exit code 1.
stdout:
ERROR ERROR Unknown option: 'recursive'
worried-painter-31382
05/03/2023, 6:55 AMbusy-vase-39202
05/03/2023, 12:31 PMcurved-television-6568
05/03/2023, 12:38 PMrecursive
option is coming from…lemon-noon-33245
05/03/2023, 2:05 PMpants package //node:docker
it is first trying to package the package_json
dependency. For that it runs pnpm pack
and apparently recursive
is being passed as an option, which is invalid.lemon-noon-33245
05/03/2023, 2:07 PMWhat usecase does your org have for docker + nodejs? Do you use it for the runtime, building frontend, both?Running the frontend build with pants and then building a docker image to push to our Kubernetes cluster.
lemon-noon-33245
05/03/2023, 2:19 PMlemon-noon-33245
05/03/2023, 2:24 PMpants
requiring package_json
to package as well since all we needed in this case is a build?worried-painter-31382
05/03/2023, 2:26 PMdocker_image
depends on the package_json
. I think what you want to do is be more specific in your dependencies here.
Is pants in charge of the package:able artifact that will run the server?lemon-noon-33245
05/03/2023, 2:31 PMIs pants in charge of the package:able artifact that will run the server?That’s what I was hoping to do.
I think it is a side effect of your dependency graph statingIs there a way to be more specific here? I tried depending ondepends on thedocker_image
. I think what you want to do is be more specific in your dependencies here.package_json
package-json#build
but it still asked to package.worried-painter-31382
05/03/2023, 2:32 PMIs there a way to be more specific here? I tried depending onI dont have the code in front of me, but it could be that there's a sneaky dependency betweenbut it still asked to package.package-json#build
package_json#build
and the node_package
target (which is what is "packed"). You can use the !!
operator to force the target out of your dependencies in the docker_image
I would consider this a bug if that is the case, thoughlemon-noon-33245
05/03/2023, 3:08 PMpackage_json
as well?worried-painter-31382
05/03/2023, 3:08 PM__trinio
(target names are not allowed to have the @ character)lemon-noon-33245
05/03/2023, 3:43 PMpants list
I can see it as package-json#__trinio/checkout
is that the one you’re referring to that I should remove with !!
as a dependency?worried-painter-31382
05/03/2023, 3:44 PMworried-painter-31382
05/03/2023, 3:44 PMlemon-noon-33245
05/03/2023, 3:49 PMlemon-noon-33245
05/03/2023, 4:04 PMworried-painter-31382
05/03/2023, 4:04 PMfile
, so the #build
target needs to be bundled into a packageable target (an archive, a pex_binary or similar) for it to eventually show up in the docker build context, maybe you already have that set up, but just fyilemon-noon-33245
05/03/2023, 4:12 PMadhoc_tool
I was using it directly. With package_json
I was hoping I could use directly too. I tried adding an intermediary files
target that would collect the output from package-json#build
and then use that as a dependency to docker_image
but it still tries packaging @trinio/checkout
.worried-painter-31382
05/03/2023, 4:17 PMadhoc_tool
produces file
, node_build_script
produces resource
because a likely envisioned scenario was to produce some fronted bundle via the js backend and package it in a pex.
I tried adding an intermediaryI don't think that is a possibility with pants?target that would collect the output fromfiles
package-json#build
worried-painter-31382
05/03/2023, 4:27 PMlemon-noon-33245
05/03/2023, 4:35 PMWould you mind creating a minimal reproduction so that I can write an issue for this?Sure, I’ll work on it now. I think this is a pretty common use case, tbh. People will either want to build a docker image with the output or package it to deploy to an AWS Lambda function, Heroku or whatever.
lemon-noon-33245
05/03/2023, 4:36 PMpnpm pack
should we provide a different way to package?
Specially since it is not possible to convert a resource into something that the dependency graph won’t mark as a packageable dependency.
Another use case we have is to package the output of a webpack build of backend services so we can use them in Lambdas.lemon-noon-33245
05/03/2023, 4:39 PMworried-painter-31382
05/03/2023, 5:20 PMpants package
targeting a package_json
to produce a npm(-like) distributable package (think library authors).
The closest equivalent is the python python_distribution
target. There is no equivalent to the pex_binary
in the nodejs backend yet, but I guess that could be a way forward.
.
The node_build_script
producing resource
and only resource
can be considered MVP-pains. It is part of the inital "wants" of the js backend, that a pex_binary
can depend on a js target that produces resource
s.
Your docker_image
target triggering pnpm pack
isn't expected. As you noticed the export-codgen goal did not run pnpm pack
. This is some side effect of the inferred dependencies of the backend which might be broken, I don't know.
I am however not surprised the current docker backend didnt "just work" at any rate, it's current implementation is... limited. It works well with pex_binary
and deploy_jar
(and adhoc_tool
, I guess? haven't tried.)worried-painter-31382
05/03/2023, 5:23 PMnode_build_script
needs to be both a package:able target and a export-codegen
compatible target, although I don't know if that is feasible.lemon-noon-33245
05/03/2023, 5:38 PMlemon-noon-33245
05/03/2023, 8:32 PMValueError: empty pattern
whenever I run pants on this repo. It doesn’t happen if I comment package_json()
in the root BUILD file. No idea why bc everything is very similar to my other repo where this works.lemon-noon-33245
05/04/2023, 3:52 PMempty pattern
error. Have you ever seen it caused by package_json
?lemon-noon-33245
05/04/2023, 5:22 PMworried-painter-31382
05/05/2023, 3:54 PMworried-painter-31382
05/06/2023, 11:28 AMnode_build_script
package:able is the right way forward to make webpacked backend avail for docker, which I hope https://github.com/pantsbuild/pants/issues/18923 addresses fully.
2. I think https://github.com/pantsbuild/pants/issues/18922 addresses the fact that a lot of time users have no intention of creating a tarball-dist from a package.json. I suspect that use case is slim for pants users, so opt-in with explicit target is better, and hopefully makes 1. easier to use with docker backend. The reasoning is; a npm_distribution
will probably be a leaf in the transitive dependency graph, rather than a connected node which node_package
is likely to become in a workspace setup.worried-painter-31382
05/06/2023, 11:41 AMlemon-noon-33245
05/08/2023, 4:27 PMpnpm pack --filter
issue , as a suggestion you could cd
into the workspace folder (or use it as a working dir) and run pnpm pack
without --filter
. This seems to work and would solve that issue for when people are using npm_distribution
.
Excited to test these solutions when they get merged!lemon-noon-33245
05/08/2023, 4:32 PMI think the test-goal only working with javascript_test is a side-effect of there not being any support for transpiled languages yet, I touched on the topic here: https://github.com/pantsbuild/pants/discussions/17357#discussioncomment-5624433That makes sense. Don’t know when you’re thinking about tackling this but glad to test whenever you have something working. Can you think of any workarounds to testing our typescript projects? I could run it with
adhoc_tool
and export the coverage as an output file/directory but then I’d have to install the dependencies again just for that, without taking full advantage of package_json
worried-painter-31382
05/08/2023, 5:53 PM