Skip to content
Merged
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
19 changes: 11 additions & 8 deletions apps/minting-service/scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
/**
* Builds the minting-service API functions using Vercel Build Output API v3.
*
* - Bundles each `api/*.ts` into a self-contained CommonJS module via esbuild,
* inlining workspace deps (@cacheplane/*) and npm deps alike so no install
* step is required inside each function directory.
* - Bundles each `handlers/*.ts` into a self-contained CommonJS module via
* esbuild, inlining workspace deps (@cacheplane/*) and npm deps alike so no
* install step is required inside each function directory.
* - Writes to `.vercel/output/functions/api/<name>.func/` with the companion
* `.vc-config.json` Vercel's Node runtime expects.
* - Writes `.vercel/output/config.json` at the top level so Vercel picks up
* the Build Output API layout instead of scanning `api/` for TS sources.
* the Build Output API layout instead of scanning the rootDirectory for TS
* sources. The sources live outside `api/` on purpose — Vercel otherwise
* auto-runs @vercel/node on top of our build, which doesn't resolve the
* workspace tsconfig paths and fails the deploy.
*
* Run via `nx build minting-service`, which sets `cwd` to this app.
*/
Expand All @@ -18,15 +21,15 @@ import { basename, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

const appRoot = resolve(fileURLToPath(import.meta.url), '..', '..');
const apiDir = join(appRoot, 'api');
const handlersDir = join(appRoot, 'handlers');
const outputRoot = join(appRoot, '.vercel', 'output');
const functionsRoot = join(outputRoot, 'functions', 'api');

async function listEntries() {
const files = await readdir(apiDir);
const files = await readdir(handlersDir);
return files
.filter((f) => f.endsWith('.ts') && !f.endsWith('.spec.ts') && !f.endsWith('.d.ts'))
.map((f) => join(apiDir, f));
.map((f) => join(handlersDir, f));
}

async function buildEntry(entry) {
Expand Down Expand Up @@ -74,7 +77,7 @@ async function main() {

const entries = await listEntries();
if (entries.length === 0) {
throw new Error(`no api entries found in ${apiDir}`);
throw new Error(`no handler entries found in ${handlersDir}`);
}

await Promise.all(entries.map(buildEntry));
Expand Down
4 changes: 2 additions & 2 deletions apps/minting-service/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"declarationMap": false,
"emitDeclarationOnly": false
},
"include": ["src/**/*.ts", "api/**/*.ts", "scripts/**/*.ts"],
"exclude": ["src/**/*.spec.ts", "api/**/*.spec.ts", "scripts/**/*.spec.ts"]
"include": ["src/**/*.ts", "handlers/**/*.ts", "scripts/**/*.ts"],
"exclude": ["src/**/*.spec.ts", "handlers/**/*.spec.ts", "scripts/**/*.spec.ts"]
}
2 changes: 1 addition & 1 deletion apps/minting-service/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"outDir": "../../dist/out-tsc",
"types": ["vitest/globals", "node"]
},
"include": ["src/**/*.spec.ts", "api/**/*.spec.ts", "src/**/*.ts", "api/**/*.ts"]
"include": ["src/**/*.spec.ts", "handlers/**/*.spec.ts", "src/**/*.ts", "handlers/**/*.ts"]
}
2 changes: 1 addition & 1 deletion apps/minting-service/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
test: {
environment: 'node',
globals: true,
include: ['src/**/*.spec.ts', 'api/**/*.spec.ts', 'scripts/**/*.spec.ts'],
include: ['src/**/*.spec.ts', 'handlers/**/*.spec.ts', 'scripts/**/*.spec.ts'],
passWithNoTests: true,
},
});
Loading