Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "NODE_ENV=development tsx watch --tsconfig ./tsconfig.server.json --env-file-if-exists=./.env ./server/server.ts",
"build:client": "tsc -b tsconfig.client.json && vite build --config client/vite.config.ts",
"build:server": "tsc -b tsconfig.server.json && tsdown -c tsdown.server.config.ts",
"build": "pnpm run build:server && pnpm run build:client",
"build": "{{or .packageManager `pnpm`}} run build:server && {{or .packageManager `pnpm`}} run build:client",
"typecheck": "tsc -b tsconfig.server.json && tsc -b tsconfig.client.json",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
Expand All @@ -18,8 +18,8 @@
"format:fix": "prettier --write .",
"test": "vitest run",
"clean": "rm -rf client/dist dist build node_modules",
"prebuild": "pnpm run sync && appkit generate-types --wait",
"predev": "pnpm run sync && pnpm run typegen",
"prebuild": "{{or .packageManager `pnpm`}} run sync && appkit generate-types --wait",
"predev": "{{or .packageManager `pnpm`}} run sync && {{or .packageManager `pnpm`}} run typegen",
"sync": "appkit plugin sync --write --silent",
"typegen": "appkit generate-types",
"setup": "appkit setup --write"
Expand Down
17 changes: 16 additions & 1 deletion tools/template-artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import { parse } from "yaml";

import { checkTemplateArtifact } from "./check-template-artifact";
import { preservePackageManagerArtifacts } from "./template-artifacts";
import { selectSmokePackageManager } from "./template-smoke-runner";
import {
PACKAGE_MANAGER_PLACEHOLDER,
selectSmokePackageManager,
} from "./template-smoke-runner";

const root = resolve(import.meta.dirname, "..");
const temporaryDirectories: string[] = [];
Expand Down Expand Up @@ -67,6 +70,18 @@ test("static variants retain both package managers for the final init", () => {
}
});

test("template scripts invoke the package manager selected by apps init", () => {
const { scripts } = JSON.parse(
readFileSync(join(root, "template/package.json"), "utf-8"),
);
for (const script of Object.values<string>(scripts)) {
// A hardcoded manager would make npm apps shell out to pnpm.
expect(script.replaceAll(PACKAGE_MANAGER_PLACEHOLDER, "")).not.toMatch(
/(^|[;&|(]\s*)(npm|pnpm|yarn|bun)\s/,
);
}
});

test.each(["npm", "pnpm"] as const)(
"%s prebuild runs sync and forwards --wait to AppKit",
(manager) => {
Expand Down
24 changes: 12 additions & 12 deletions tools/template-smoke-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ import { parse } from "yaml";

export type PackageManager = "npm" | "pnpm";

/** Go template expression `databricks apps init` renders to the selected package manager. */
export const PACKAGE_MANAGER_PLACEHOLDER = "{{or .packageManager `pnpm`}}";

/** Test fixture shaping; end-user package-manager selection belongs to the CLI. */
export function selectSmokePackageManager(
appDir: string,
pm: PackageManager,
): void {
if (pm === "pnpm") {
rmSync(join(appDir, "package-lock.json"), { force: true });
return;
}
for (const file of ["pnpm-lock.yaml", "pnpm-workspace.yaml", ".npmrc"]) {
rmSync(join(appDir, file), { force: true });
}
const packagePath = join(appDir, "package.json");
const pkg = JSON.parse(readFileSync(packagePath, "utf-8"));
pkg.packageManager = `npm@${execFileSync("npm", ["--version"], { encoding: "utf-8" }).trim()}`;
for (const [name, script] of Object.entries<string>(pkg.scripts)) {
pkg.scripts[name] = script
.split(" && ")
.map((command) => command.replace(/^pnpm run /, "npm run "))
.join(" && ");
pkg.scripts[name] = script.replaceAll(PACKAGE_MANAGER_PLACEHOLDER, pm);
}
if (pm === "pnpm") {
rmSync(join(appDir, "package-lock.json"), { force: true });
} else {
for (const file of ["pnpm-lock.yaml", "pnpm-workspace.yaml", ".npmrc"]) {
rmSync(join(appDir, file), { force: true });
}
pkg.packageManager = `npm@${execFileSync("npm", ["--version"], { encoding: "utf-8" }).trim()}`;
}
writeFileSync(packagePath, `${JSON.stringify(pkg, null, 2)}\n`);
}
Expand Down
Loading