@forwardimpact/libcodegen 0.1.66 → 0.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,11 @@ import { execFileSync } from "node:child_process";
17
17
  import protoLoader from "@grpc/proto-loader";
18
18
  import mustache from "mustache";
19
19
 
20
- import { createCli, SummaryRenderer } from "@forwardimpact/libcli";
20
+ import {
21
+ createCli,
22
+ SummaryRenderer,
23
+ withEmbeddedAssets,
24
+ } from "@forwardimpact/libcli";
21
25
  import { createDefaultRuntime } from "@forwardimpact/libutil/runtime";
22
26
  import { Logger } from "@forwardimpact/libtelemetry";
23
27
  import {
@@ -345,13 +349,18 @@ async function runCodegen(protoDirs, projectRoot, finder, parsedFlags) {
345
349
  );
346
350
  }
347
351
 
352
+ // Inject the embedded-overlay sync fs so loadTemplate's reads of the virtual
353
+ // template mount hit the inlined registry in a compiled binary. In
354
+ // source/npx execution withEmbeddedAssets is a no-op and this is the full
355
+ // node:fs sync surface, identical to the bare `fs` used elsewhere in this bin.
356
+ const codegenFs = withEmbeddedAssets(runtime).fsSync;
348
357
  const codegens = createCodegen(
349
358
  protoDirs,
350
359
  projectRoot,
351
360
  path,
352
361
  mustache,
353
362
  protoLoader,
354
- fs,
363
+ codegenFs,
355
364
  runtime,
356
365
  );
357
366
  await executeGeneration(codegens, sourcePath, parsedFlags);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forwardimpact/libcodegen",
3
- "version": "0.1.66",
3
+ "version": "0.1.67",
4
4
  "description": "Protobuf code generation — keep types in sync with proto definitions without hand-writing.",
5
5
  "keywords": [
6
6
  "codegen",
package/src/base.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { fileURLToPath } from "node:url";
2
+ import { embeddedAssetsActive, embeddedDir } from "@forwardimpact/libcli";
2
3
  import protobuf from "protobufjs";
3
4
  import "./long-init.js";
4
5
 
@@ -165,14 +166,22 @@ export class CodegenBase {
165
166
  * @returns {string} Template content
166
167
  */
167
168
  loadTemplate(kind) {
168
- const __filename = fileURLToPath(import.meta.url);
169
- const __dirname = this.#path.dirname(__filename);
170
- const templatePath = this.#path.join(
171
- __dirname,
172
- "..",
173
- "templates",
174
- `${kind}.js.mustache`,
175
- );
169
+ // A `bun build --compile` binary inlines the templates and registers them
170
+ // under the "libcodegen/templates" mount (see the CLI's assets block in
171
+ // build/cli-manifest.json), which flips embeddedAssetsActive() true. In
172
+ // that case resolve through the virtual mount the embedded-fs overlay
173
+ // serves. The on-disk path would not work there: import.meta.url points
174
+ // into the /$bunfs root, which carries no templates directory. In
175
+ // source/npx/test execution nothing registers, so resolve the on-disk path
176
+ // relative to this module.
177
+ const templatesDir = embeddedAssetsActive()
178
+ ? embeddedDir("libcodegen/templates")
179
+ : this.#path.join(
180
+ this.#path.dirname(fileURLToPath(import.meta.url)),
181
+ "..",
182
+ "templates",
183
+ );
184
+ const templatePath = this.#path.join(templatesDir, `${kind}.js.mustache`);
176
185
 
177
186
  if (!this.#fs.existsSync(templatePath)) {
178
187
  throw new Error(`Missing ${kind}.js.mustache template`);
@@ -59,7 +59,7 @@ export class CodegenDefinitions {
59
59
  const definitions = [];
60
60
 
61
61
  if (this.#base.fs.existsSync(definitionsDir)) {
62
- for (const file of this.#base.fs.readdirSync(definitionsDir)) {
62
+ for (const file of this.#base.fs.readdirSync(definitionsDir).sort()) {
63
63
  if (!file.endsWith(".js") || file === "exports.js") continue;
64
64
 
65
65
  const serviceName = this.#base.path.basename(file, ".js");
package/src/services.js CHANGED
@@ -52,7 +52,7 @@ export class CodegenServices {
52
52
  const clients = [];
53
53
 
54
54
  if (this.#base.fs.existsSync(serviceDir)) {
55
- for (const dir of this.#base.fs.readdirSync(serviceDir)) {
55
+ for (const dir of this.#base.fs.readdirSync(serviceDir).sort()) {
56
56
  const servicePath = this.#base.path.join(serviceDir, dir);
57
57
  if (!this.#base.fs.statSync(servicePath).isDirectory()) continue;
58
58