When using Pants and Javascript, is it expected to...
# general
s
When using Pants and Javascript, is it expected to need to run something like
pnpm i
first to get
pants run
commands working? I can get
pants package
to work against
node_build_script
. But with
node_run_script
I always seem to get
Copy code
` WARN   Local package.json exists, but node_modules missing, did you mean to install?`
When I* inspect sandboxes I see
Copy code
$ cat __run.sh 
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /home/yjabri/...
env -i ...
If I copy the env -i and run it in the sandbox, the command works. Is this a known issue? Should I create an issue*?
I don’t know how to look at the sandbox for package
Copy code
$ pants --no-pantsd --keep-sandboxes=always package expo2/typescript/:pkg#build
01:24:44.32 [INFO] Preserving local process execution dir /tmp/pants-sandbox-qMXh02 for Test binary /bin/node.
01:24:44.32 [INFO] Preserving local process execution dir /tmp/pants-sandbox-MMlUQ1 for Test binary /usr/bin/node.
01:24:44.35 [INFO] Completed: Scheduling: Test binary /bin/node.
01:24:44.36 [INFO] Completed: Scheduling: Test binary /usr/bin/node.
01:24:44.39 [INFO] Preserving local process execution dir /tmp/pants-sandbox-tZkERa for Test binary /bin/bash.
01:24:44.39 [INFO] Preserving local process execution dir /tmp/pants-sandbox-dbkOye for Test binary /usr/bin/bash.
01:24:44.41 [INFO] Completed: Scheduling: Test binary /bin/bash.
01:24:44.42 [INFO] Completed: Scheduling: Test binary /usr/bin/bash.
01:24:44.42 [INFO] Completed: Scheduling: Enabling corepack shims
01:24:44.46 [INFO] Completed: Scheduling: Preparing configured pnpm@9.15.6.
01:24:44.65 [INFO] Completed: Scheduling: Installing @archipelago/expo2@1.0.0.
01:24:44.83 [INFO] Completed: Scheduling: Running node build script 'build'.
01:24:44.84 [INFO] Wrote dist/dist
I thought I was able to get a sandbox once for package* but maybe I’m mistaken? This is something I still don’t really understand about pants. Sometimes there are sandboxes, sometimes
--keep-sandboxes
does nothing or just produces them for steps like
Test binary /usr/bin/node
If I clear my cache I can get it!
Copy code
$ pants --no-pantsd --keep-sandboxes=always package expo2/typescript/:pkg#build
01:32:06.21 [INFO] Preserving local process execution dir /tmp/pants-sandbox-0QeDqH for Test binary /bin/node.
01:32:06.21 [INFO] Preserving local process execution dir /tmp/pants-sandbox-qIfWzO for Test binary /usr/bin/node.
01:32:06.23 [INFO] Completed: Scheduling: Test binary /bin/node.
01:32:06.24 [INFO] Completed: Scheduling: Test binary /usr/bin/node.
01:32:06.29 [INFO] Preserving local process execution dir /tmp/pants-sandbox-RICPxI for Test binary /bin/bash.
01:32:06.29 [INFO] Preserving local process execution dir /tmp/pants-sandbox-BSyRAq for Test binary /usr/bin/bash.
01:32:06.31 [INFO] Completed: Scheduling: Test binary /bin/bash.
01:32:06.31 [INFO] Completed: Scheduling: Test binary /usr/bin/bash.
01:32:06.31 [INFO] Preserving local process execution dir /tmp/pants-sandbox-cgLRjc for Enabling corepack shims
01:32:06.42 [INFO] Completed: Scheduling: Enabling corepack shims
01:32:06.42 [INFO] Preserving local process execution dir /tmp/pants-sandbox-W399Px for Preparing configured pnpm@9.15.6.
01:32:08.16 [INFO] Completed: Scheduling: Preparing configured pnpm@9.15.6.
01:32:08.16 [INFO] Preserving local process execution dir /tmp/pants-sandbox-04AjlA for Installing @archipelago/expo2@1.0.0.
01:32:14.17 [INFO] Completed: Installing @archipelago/expo2@1.0.0.
01:32:14.19 [INFO] Completed: Scheduling: Installing @archipelago/expo2@1.0.0.
01:32:14.20 [INFO] Preserving local process execution dir /tmp/pants-sandbox-sW8LiG for Running node build script 'build'.
01:32:19.80 [INFO] Completed: Running node build script 'build'.
01:32:19.80 [INFO] Completed: Scheduling: Running node build script 'build'.
01:32:19.81 [INFO] Wrote dist/dist
it has
Copy code
# This command line should execute the same process as pants did internally.
cd /tmp/pants-sandbox-sW8LiG/
Which looks right!
I don’t mind running
pnpm i
but it feels like a
pants smell
(I regret typing that) to need to do that to get run to work.
w
Yeah, you shouldn't have to - something seems wrong. WHat's your BUILD file look like?
Though, from the changelog - it looks like it's intended to be an aside to packaging:
Copy code
Added new build file alias `node_run_script` to allow generating node script targets that are not tied to packaging and can be executed via the `run` goal.
https://www.pantsbuild.org/stable/docs/javascript/overview/package#running Hmm, you know what - this is ambiguous. Personally, I couldn't imagine not having my node modules, but maybe that;s fair game There is a distinction between RunNodeBuild script and
Copy code
@dataclass(frozen=True)
class RunNodeScriptFieldSet(RunFieldSet):
    required_fields = (NodeRunScriptEntryPointField, NodePackageDependenciesField)
    run_in_sandbox_behavior = RunInSandboxBehavior.RUN_REQUEST_HERMETIC

    entry_point: NodeRunScriptEntryPointField
    extra_env_vars: NodeRunScriptExtraEnvVarsField
    environment: EnvironmentField
though. Are you able to add a package dependency, and does that work?
s
I have dependencies
Copy code
package_json(
    scripts=[
        node_run_script(entry_point="dev"),
        node_build_script(
            entry_point="build",
            output_directories=["dist"],
        )
    ],
    dependencies=[":tsconfig", "//:tsconfig", "./src"],
)

file(
    name="tsconfig",
    source="tsconfig.json"
)
What I don’t understand is the sandbox is built when I do a
pants run
Copy code
╰❱ ls
__node                                                                         package.json
__run.sh                                                                       packages
_binary_shims_cdd60ac6ea9db484515d1bc36e0a9b992c89650ef4e5b32a200da6e9ae172946 pnpm-lock.yaml
apps                                                                           pnpm-workspace.yaml
node_modules                                                                   tsconfig.json
Its just not used because of the cd
Copy code
╰❱ cat __run.sh
#!/usr/bin/env bash
# This command line should execute the same process as pants did internally.
cd /Users/yjabri/Misc/try-pnpm
I can reproduce the behavior in a new repo with minimal setup.
I decided to try
pants --keep-sandboxes=always run path/to/some/python/file.py
and it also has a
cd /home/yjabri
. So I think Im getting hung up on the wrong thing.
Despite being in the project directory it runs
…pants /tmp/pants-sandbox-9yvdaa/./archipelago.pex_pex_shim.sh --help
And it does the same in node!
Copy code
pnpm --filter $'@workspace/ui-library' --prefix /private/var/folders/m8/cmsvrd417n39w5xjzjhmnznm0000gq/T/pants-sandbox-8EIMGa/packages/ui-library run dev
Ok so why does it complain about node_modules…