Skip to content

Instantly share code, notes, and snippets.

@sureshjoshi
Last active May 26, 2023 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sureshjoshi/98fb09f2a340f7c1dad270c4887865a0 to your computer and use it in GitHub Desktop.
Save sureshjoshi/98fb09f2a340f7c1dad270c4887865a0 to your computer and use it in GitHub Desktop.
Pants adhoc_tool recipes
# Note: Most of this file is a workaround for proper JS tooling support in Pants, which is coming soon.
# Grabbing build/bundle-centric files, as well as eslint/prettier files
files(
name="build-meta",
sources=[
"*eslint*",
"*prettier*",
"*npm*",
"*.json",
"*.cjs",
"*.js",
"*.ts",
"*.yaml",
]
)
# The source files themselves - TODO: exclude the *.test.ts files
# Make sure to grab `svelte-kit` which is part of a post-install
files(
name="sources",
sources=[
".svelte-kit/**/*",
"src/**/*",
"static/**/*",
".env.*",
]
)
files(
name="test-sources",
sources=[
"tests/**/*",
]
)
# Node/SvelteKit's post-install needs the host's `sh` to be in the environment
system_binary(
name="sh",
binary_name="sh",
fingerprint_args=["--version"],
)
# Vite needs `sed` to be in the environment
system_binary(
name="sed",
binary_name="sed",
)
# Vite needs `dirname` to be in the environment
system_binary(
name="dirname",
binary_name="dirname",
# MacOS doesn't have a `--version` flag, so we need to pass something otherwise dirname errors
fingerprint_args=["some-random-string-so-dirname-doesnt-fail"],
)
# Vite needs `uname` to be in the environment
system_binary(
name="uname",
binary_name="uname",
)
# Pull the host's `node` into the environment
system_binary(
name="node",
binary_name="node",
fingerprint=r"v(20|[1-9][0-9])\..*\..*",
fingerprint_args=["--version"],
)
# Pull the host's `pnpm` into the environment, depending on `node`
system_binary(
name="pnpm",
binary_name="pnpm",
fingerprint_args=["--version"],
fingerprint_dependencies=[":node"],
)
# Perform and cache the `pnpm install` step, `:build-meta` is required for this step, but the `:source` isn't
# Using `--frozen-lockfile` to error out if the lockfile is out of sync with the package.json
adhoc_tool(
name="node-modules",
runnable=":pnpm",
args=["install", "--frozen-lockfile"],
runnable_dependencies=[":node", ":sh"],
execution_dependencies=[":build-meta"],
output_directories=["node_modules"],
timeout=300,
)
# Run the linters
run_shell_command(
name="lint",
command="pnpm lint",
runnable_dependencies=[":pnpm"],
execution_dependencies=[":build-meta", ":sources", ":test-sources", ":node-modules"],
workdir="/frontend/web",
)
# Run the typecheckers
run_shell_command(
name="check",
command="pnpm check",
runnable_dependencies=[":pnpm"],
execution_dependencies=[":build-meta", ":sources", ":test-sources", ":node-modules"],
workdir="/frontend/web",
)
# Run the tests
run_shell_command(
name="test",
command="pnpm test",
runnable_dependencies=[":pnpm"],
execution_dependencies=[":build-meta", ":sources", ":test-sources", ":node-modules"],
workdir="/frontend/web",
)
# Build a bundle
# The output_directory and root_output_directory are the same here, so that a downstream `archive` target can pick it up in a specific manner (Azure workaround)
adhoc_tool(
name="build",
runnable=":pnpm",
args=["build"],
runnable_dependencies=[":node", ":sh", ":sed", ":uname", ":dirname"],
execution_dependencies=[":build-meta", ":sources", ":node-modules"],
output_directories=["build"],
root_output_directory="/frontend/web/build",
timeout=300,
)
# Zip the build directory for Azure deployment
archive(
name="zip-dev",
files=[":build"],
format="zip",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment