Concept: Inline Scripts
Overview
Normally, a "script" in pacwich references one of the entries found in a workspace's "scripts" field in its package.json file.
However, it's possible to run a one-off shell command from a workspace's directory, an "inline script", such as via pacwich run "echo 'hello'" --inline in the CLI.
Using the Bun Shell
Normally, inline scripts are executed using your system shell. In POSIX systems (Linux, macOS, etc.), sh -c is called, while in Windows, cmd /d /s /c is called.
You can also use the Bun shell, a bash-like, cross-platform shell, the same as the utility import { $ } from 'bun' by passing --shell=bun,
if the bun command is available.
You can also set the root config.defaults.shell or environment variable PACWICH_SHELL_DEFAULT to "bun" to use the Bun shell by default.
Examples
CLI:
# This will use the system shell,
# unless the project config.defaults.shell
# or process.env.PACWICH_SHELL_DEFAULT is set to "bun"
pacwich run "echo 'hello'" --inline
# Same as the above command
pacwich run "echo 'hello'" --inline --shell=default
# Explicitly run the Bun shell
pacwich run "echo 'hello'" --inline --shell=bun
# Explicitly run the system shell
pacwich run "echo 'hello'" --inline --shell=system
API:
import { createFileSystemProject } from "pacwich";
const project = createFileSystemProject();
// This will use the system shell (sh in POSIX or cmd in Windows),
// unless the project config.defaults.shell
// or process.env.PACWICH_SHELL_DEFAULT is set to "bun"
project.runWorkspaceScript({
workspaceNameOrAlias: "my-workspace",
script: "echo 'this is my inline script'",
inline: true,
});
// Use the Bun shell to execute a script, a cross-platform bash-like shell,
// if Bun is available
project.runWorkspaceScript({
workspaceNameOrAlias: "my-workspace",
script: "echo 'this is my inline script'",
// Takes "bun", "system", or "default", same as the CLI --shell option
inline: { shell: "bun" },
});
Script Name
Scripts from package.json are named by the key in the "scripts" field.
This is used in output logs and workspace script metadata.
Inline scripts, however, have no name by default, but you can provide a name.
Examples
CLI:
# Pass a name for an inline script
pacwich run "echo 'my script: <scriptName>'" --inline --inline-name=my-inline-script
API:
project.runWorkspaceScript({
workspaceNameOrAlias: "my-workspace",
script: "echo 'this is my inline script'",
// The name will be empty by default
inline: true,
});
// Pass a name for an inline script
project.runWorkspaceScript({
workspaceNameOrAlias: "my-workspace",
script: "echo 'my script: <scriptName>'",
inline: { scriptName: "my-inline-script" },
});

