@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.
- package/bin/fit-codegen.js +11 -2
- package/package.json +1 -1
- package/src/base.js +17 -8
- package/src/definitions.js +1 -1
- package/src/services.js +1 -1
package/bin/fit-codegen.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
363
|
+
codegenFs,
|
|
355
364
|
runtime,
|
|
356
365
|
);
|
|
357
366
|
await executeGeneration(codegens, sourcePath, parsedFlags);
|
package/package.json
CHANGED
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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`);
|
package/src/definitions.js
CHANGED
|
@@ -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
|
|