feat: make t3 package publishable for npx
- Remove private:true so package can be published to npm - Add files field to limit published files to dist/ - Move @acme/contracts to devDependencies (bundled by tsup) - Add @acme/renderer devDependency for turbo build ordering - Add bundle-client.mjs: copies renderer build into dist/client/ - Update resolveStaticDir to check dist/client/ first (npx scenario), then fall back to monorepo layout (../../renderer/dist) - Full build pipeline: contracts → renderer → server + bundle client Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
6238edb659
commit
1990db7430
4 files changed
+43
-9
No files matched your search
@@ -1,25 +1,28 @@
|
||||
{
|
||||
"name": "t3",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"t3": "./dist/index.js"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "VITE_DEV_SERVER_URL=http://localhost:5173 tsx src/index.ts",
|
||||
"build": "tsup",
|
||||
"build": "tsup && node scripts/bundle-client.mjs",
|
||||
"start": "node dist/index.js",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@acme/contracts": "workspace:*",
|
||||
"open": "^10.1.0",
|
||||
"ws": "^8.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@acme/contracts": "workspace:*",
|
||||
"@acme/renderer": "workspace:*",
|
||||
"@types/node": "^22.10.2",
|
||||
"@types/ws": "^8.5.13",
|
||||
"tsup": "^8.3.5",
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copies the built renderer into dist/client/ so the published npm package
|
||||
* includes the web UI. This runs as a post-build step.
|
||||
*/
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const rendererDist = path.resolve(__dirname, "../../renderer/dist");
|
||||
const target = path.resolve(__dirname, "../dist/client");
|
||||
|
||||
if (!fs.existsSync(rendererDist)) {
|
||||
console.log(
|
||||
"⚠ Renderer dist not found — skipping client bundle. Run `bun run --cwd apps/renderer build` first.",
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
fs.cpSync(rendererDist, target, { recursive: true });
|
||||
console.log("✓ Bundled renderer into dist/client");
|
||||
@@ -35,14 +35,23 @@ async function findAvailablePort(preferred: number): Promise<number> {
|
||||
}
|
||||
|
||||
function resolveStaticDir(): string | undefined {
|
||||
// In production, the renderer dist is next to the server dist:
|
||||
// apps/server/dist/index.js → apps/renderer/dist/
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const rendererDist = path.resolve(__dirname, "../../renderer/dist");
|
||||
|
||||
// Check for bundled client (npm publish / npx scenario):
|
||||
// dist/client/ lives alongside dist/index.js
|
||||
const bundledClient = path.resolve(__dirname, "client");
|
||||
try {
|
||||
const stat = fs.statSync(path.join(rendererDist, "index.html"));
|
||||
if (stat.isFile()) return rendererDist;
|
||||
const stat = fs.statSync(path.join(bundledClient, "index.html"));
|
||||
if (stat.isFile()) return bundledClient;
|
||||
} catch {
|
||||
// Not bundled — check monorepo layout
|
||||
}
|
||||
|
||||
// Monorepo layout: apps/server/dist/index.js → apps/renderer/dist/
|
||||
const monorepoClient = path.resolve(__dirname, "../../renderer/dist");
|
||||
try {
|
||||
const stat = fs.statSync(path.join(monorepoClient, "index.html"));
|
||||
if (stat.isFile()) return monorepoClient;
|
||||
} catch {
|
||||
// Not found — probably dev mode, Vite will serve
|
||||
}
|
||||
|
||||
@@ -44,11 +44,12 @@
|
||||
"t3": "./dist/index.js",
|
||||
},
|
||||
"dependencies": {
|
||||
"@acme/contracts": "workspace:*",
|
||||
"open": "^10.1.0",
|
||||
"ws": "^8.18.0",
|
||||
},
|
||||
"devDependencies": {
|
||||
"@acme/contracts": "workspace:*",
|
||||
"@acme/renderer": "workspace:*",
|
||||
"@types/node": "^22.10.2",
|
||||
"@types/ws": "^8.5.13",
|
||||
"tsup": "^8.3.5",
|
||||
|
||||
Reference in new issue
Block a user