Skip to content

feat: let apps init render the package manager in scripts - #632

Open
atilafassina wants to merge 1 commit into
mainfrom
template-pm-scripts
Open

atilafassina wants to merge 1 commit into
mainfrom
template-pm-scripts

Conversation

@atilafassina

Copy link
Copy Markdown
Contributor

Summary

template/package.json hardcodes pnpm run in build, prebuild, and predev. Because of that, databricks apps init --package-manager npm has to parse and rewrite shell commands in package.json (libs/apps/pkgmanager/scripts.go in databricks/cli#6902).

This PR uses the same expression that app.yaml.tmpl and README.md.tmpl already use (#593), so the CLI renders the selected manager:

"prebuild": "{{or .packageManager `pnpm`}} run sync && appkit generate-types --wait",

Once this ships in template-v0.82.0, the CLI only needs to set name and packageManager in package.json, and scripts.go / scripts_test.go can be deleted. This was suggested in the review of databricks/cli#6902. It needs to merge before template-v0.82.0 is tagged.

Notes

  • Backtick literal instead of "pnpm": package.json is parsed as JSON before it's rendered, by the CLI's background install and by prepare-template-artifact.ts, check-template-deps.ts, and template-artifacts.ts. Double quotes would make the raw file invalid JSON. Go's text/template treats `pnpm` and "pnpm" the same.
  • Older CLIs: CLIs that don't pass packageManager render the default, pnpm. I checked with text/template + missingkey=zero: no key → pnpm run …, npm → npm run …, pnpm → pnpm run ….
  • Static variants: generate-app-templates.ts already copies the raw template scripts back over the rendered ones (preservePackageManagerArtifacts). The placeholder survives into the published variant, and the user's final apps init renders it.

CI against the un-rendered template

I checked every path that runs on raw template/ or its copies:

  • pr-template-artifact (ci.yml) and prepare-release.yml run npm install, pnpm install --lockfile-only, and npm test (vitest run). None of them invoke pnpm run, and the template has no install lifecycle scripts. These only need the file to be valid JSON, which it still is.
  • template-deploy-shape / template-deploy-shape-npm run pnpm/npm run build. They go through selectSmokePackageManager, which now renders the placeholder for both managers instead of rewriting pnpm run → npm run.
  • The %s prebuild runs sync unit test runs prebuild directly and uses the same helper.

A new test fails if a template script hardcodes npm/pnpm/yarn/bun. Once the CLI stops rewriting scripts, a stray pnpm run would otherwise make npm apps call pnpm at build time. Against origin/main it flags build, prebuild, and predev.

Test plan

  • pnpm exec vitest run --project tools (63 passed)
  • tsx tools/smoke-test-template.ts --package-manager npm --run: install, npm ci, build with prebuild, health check, client serving. The runner's fake pnpm on PATH was never called.
  • tsx tools/smoke-test-template.ts --package-manager pnpm --run: same checks with pnpm
  • oxlint, oxfmt, knip

This pull request and its description were written by Isaac.

The build, prebuild, and predev scripts hardcoded `pnpm run`, so the
Databricks CLI had to parse and rewrite shell commands in package.json
when a user picked npm. Use the same `or .packageManager "pnpm"`
expression as app.yaml.tmpl and README.md.tmpl so `databricks apps init`
renders the selected manager directly. CLIs that don't pass
packageManager still get pnpm.

package.json is parsed as JSON before rendering (by the CLI and by our
tooling), so the expression uses a backtick string literal instead of
double quotes.

The smoke fixture now renders the placeholder instead of rewriting
`pnpm run` to `npm run`, and a new test fails if a template script
hardcodes a package manager.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Atila Fassina <atila@fassina.eu>
@atilafassina
atilafassina requested a review from a team as a code owner October 6, 2026 16:14
@atilafassina
atilafassina requested review from pkosiec and a balanced review from Copilot October 6, 2026 16:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused changes preserve existing defaults and include appropriate npm and pnpm coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Makes generated app scripts use the package manager selected by databricks apps init, defaulting to pnpm.

Changes:

  • Adds a reusable package-manager template placeholder.
  • Updates build lifecycle scripts to render npm or pnpm.
  • Adds tests preventing hardcoded package managers.
File Description
template/​package.json Makes build scripts package-manager-aware.
tools/​template-smoke-runner.ts Renders package-manager placeholders in smoke fixtures.
tools/​template-artifacts.test.ts Tests script portability and placeholder usage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

🤖 AppKit PR bot

🔬 Run evals

Start an eval for this PR from the evals-monitor app: Go to Evals Monitor →

📦 Try this PR's app template

Scaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh auth login — and the Databricks CLI):

gh run download 37494079840 -R databricks/appkit -n appkit-template-0.82.0-pr.9451617-template-pm-scripts-632 -D appkit-pr-632 \
  && unzip -o "appkit-pr-632/appkit-template-0.82.0-pr.9451617-template-pm-scripts-632.zip" -d "appkit-pr-632" \
  && databricks apps init --template "appkit-pr-632"

The template pins @databricks/appkit and @databricks/appkit-ui to tarballs built from this branch, so the scaffolded app runs against this PR's code.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants