Add primitive functions:init scaffolder#63
Conversation
Stamps handler.ts, package.json, build.mjs, tsconfig.json, .gitignore, and README.md into ./<name>/ so a new Function author can run npm install && npm run build then primitive functions:deploy --file ./dist/handler.js without writing the boilerplate themselves. The scaffolded handler imports createPrimitiveClient from @primitivedotdev/sdk/api (NOT the package root, which pulls in node:crypto-dependent webhook helpers and breaks Workers bundles) and demonstrates client.send() rather than a raw fetch against /api/v1/send-mail. This is the first-touch UX hook for in-handler SDK use.
Greptile SummaryAdds
Confidence Score: 5/5Safe to merge — the scaffolder is well-contained and both issues flagged in earlier rounds have been properly addressed. The atomic No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "Close TOCTOU window and show resolved pa..." | Re-trigger Greptile |
Greptile review on #63 flagged two minor quality issues: - The overwrite guard used a separate existsSync check before a recursive: true mkdirSync, leaving a small window where a concurrent invocation could slip past undetected. Replaced with a single recursive: false mkdirSync, which throws EEXIST atomically; the friendly "directory already exists" message still surfaces. ENOENT (missing parent) is also mapped to a friendly message. - The cd hint after a successful scaffold printed the raw --out-dir value, which can mislead a user who invoked the command from a different cwd than the printed path. Switched to the already-resolved absolute outDir so cd always points where the files actually landed. Tests unchanged; the existing "refuses to overwrite" test still passes because the error path returns the same CLIError. All 681 sdk-node tests green.
|
Addressed Greptile findings in 7acb0a0:
All 681 sdk-node tests still green. |
First release that bundles the functions:init scaffolder (PR #63) on top of 0.22.0: - primitive functions:init <name> stamps a deployable Function project (handler.ts, package.json, build.mjs, tsconfig.json, .gitignore, README.md) with one command. The scaffolded handler.ts imports createPrimitiveClient from @primitivedotdev/sdk/api and demos client.send({...}), not raw fetch against /api/v1/send-mail. The /api subpath avoids dragging in node:crypto-dependent webhook helpers, which breaks Workers-style bundles. Closes the load-bearing gap that had every AGX run reimplementing send-mail with raw fetch in the handler. No API-shape changes; safe upgrade from 0.22.0.
Summary
primitive functions:init <name>that stamps a deployable Function project (handler.ts, package.json, build.mjs, tsconfig.json, .gitignore, README.md) into./<name>/. First-touch UX for new Function authors: they go from zero to deployed in two commands (npm install && npm run buildthenprimitive functions:deploy --file ./dist/handler.js).handler.tsimportscreatePrimitiveClientfrom@primitivedotdev/sdk/api(NOT the package root, which pulls innode:crypto-dependent webhook helpers and breaks Workers-style bundles) and demonstratesclient.send({...})rather than rawfetchagainst/api/v1/send-mail.package.jsonname.Test plan
pnpm test(sdk-node): 681 tests pass, including newfunctions-init.test.tscovering name validation, handler-shape regression guards (asserts the/apisubpath import), template substitution, refuses-to-overwrite behavior, and a no-write rollback on invalid name.pnpm lint(sdk-node): zero errors.pnpm typecheck(sdk-node): clean.make node-checkandmake shared-check: clean.primitive functions:init test-fn-tmp --out-dir /tmp/..., thennpm install(138 packages, 3s), thennpm run build(esbuild producesdist/handler.js), thennpx tsc --noEmit(clean). Output bundle imports the SDK correctly and emits a working ESM Worker default export.