@stryke/capnp 0.6.3 → 0.7.0

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/capnpc.js CHANGED
@@ -3,9 +3,33 @@ var __defProp = Object.defineProperty;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
4
 
5
5
  // bin/capnpc.ts
6
- import { writeFatal, writeInfo, writeSuccess } from "@storm-software/config-tools/logger/console";
6
+ import { writeFatal, writeInfo, writeSuccess, writeWarning } from "@storm-software/config-tools/logger/console";
7
7
  import { exitWithError, exitWithSuccess, findWorkspaceRootSafe as findWorkspaceRootSafe2, handleProcess } from "@storm-software/config-tools/utilities";
8
8
 
9
+ // ../path/src/exists.ts
10
+ import { existsSync as existsSyncFs } from "node:fs";
11
+ import { access, constants } from "node:fs/promises";
12
+ var existsSync = /* @__PURE__ */ __name((filePath) => {
13
+ return existsSyncFs(filePath);
14
+ }, "existsSync");
15
+ var exists = /* @__PURE__ */ __name(async (filePath) => {
16
+ return access(filePath, constants.F_OK).then(() => true).catch(() => false);
17
+ }, "exists");
18
+
19
+ // ../fs/src/helpers.ts
20
+ import { parseTar, parseTarGzip } from "nanotar";
21
+ import { createWriteStream, mkdirSync, rmSync } from "node:fs";
22
+ import { mkdir, readFile, rm } from "node:fs/promises";
23
+ async function createDirectory(path) {
24
+ if (await exists(path)) {
25
+ return;
26
+ }
27
+ return mkdir(path, {
28
+ recursive: true
29
+ });
30
+ }
31
+ __name(createDirectory, "createDirectory");
32
+
9
33
  // ../fs/src/list-files.ts
10
34
  import defu from "defu";
11
35
  import { glob } from "glob";
@@ -594,9 +618,9 @@ var isError = /* @__PURE__ */ __name((obj) => {
594
618
  }, "isError");
595
619
 
596
620
  // ../fs/src/read-file.ts
597
- import { existsSync, readFileSync as readFileSyncFs } from "node:fs";
621
+ import { existsSync as existsSync2, readFileSync as readFileSyncFs } from "node:fs";
598
622
  import { readFile as readFileFs } from "node:fs/promises";
599
- var readFile = /* @__PURE__ */ __name(async (filePath) => {
623
+ var readFile2 = /* @__PURE__ */ __name(async (filePath) => {
600
624
  try {
601
625
  if (!filePath) {
602
626
  throw new Error("No file path provided to read data");
@@ -609,7 +633,7 @@ var readFile = /* @__PURE__ */ __name(async (filePath) => {
609
633
  }
610
634
  }, "readFile");
611
635
  async function readJsonFile(path, options) {
612
- const content = await readFile(path);
636
+ const content = await readFile2(path);
613
637
  if (options) {
614
638
  options.endsWithNewline = content.codePointAt(content.length - 1) === 10;
615
639
  }
@@ -625,16 +649,6 @@ async function readJsonFile(path, options) {
625
649
  }
626
650
  __name(readJsonFile, "readJsonFile");
627
651
 
628
- // ../path/src/exists.ts
629
- import { existsSync as existsSyncFs } from "node:fs";
630
- import { access, constants } from "node:fs/promises";
631
- var existsSync2 = /* @__PURE__ */ __name((filePath) => {
632
- return existsSyncFs(filePath);
633
- }, "existsSync");
634
- var exists = /* @__PURE__ */ __name(async (filePath) => {
635
- return access(filePath, constants.F_OK).then(() => true).catch(() => false);
636
- }, "exists");
637
-
638
652
  // ../path/src/file-path-fns.ts
639
653
  import { relative } from "node:path";
640
654
 
@@ -770,9 +784,6 @@ __name(normalizeString, "normalizeString");
770
784
 
771
785
  // ../path/src/regex.ts
772
786
  var DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i;
773
- var DRIVE_LETTER_REGEX = /^[A-Z]:$/i;
774
- var UNC_REGEX = /^[/\\]{2}/;
775
- var ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
776
787
 
777
788
  // ../path/src/slash.ts
778
789
  function slash(path) {
@@ -783,12 +794,6 @@ function slash(path) {
783
794
  }
784
795
  __name(slash, "slash");
785
796
 
786
- // ../path/src/is-file.ts
787
- function isAbsolutePath(path) {
788
- return ABSOLUTE_PATH_REGEX.test(slash(path));
789
- }
790
- __name(isAbsolutePath, "isAbsolutePath");
791
-
792
797
  // ../path/src/correct-path.ts
793
798
  function normalizeWindowsPath2(input = "") {
794
799
  if (!input) {
@@ -797,97 +802,6 @@ function normalizeWindowsPath2(input = "") {
797
802
  return slash(input).replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
798
803
  }
799
804
  __name(normalizeWindowsPath2, "normalizeWindowsPath");
800
- function correctPath(path) {
801
- if (!path || path.length === 0) {
802
- return ".";
803
- }
804
- path = normalizeWindowsPath2(path);
805
- const isUNCPath = path.match(UNC_REGEX);
806
- const isPathAbsolute = isAbsolutePath(path);
807
- const trailingSeparator = path.endsWith("/");
808
- path = normalizeString2(path, !isPathAbsolute);
809
- if (path.length === 0) {
810
- if (isPathAbsolute) {
811
- return "/";
812
- }
813
- return trailingSeparator ? "./" : ".";
814
- }
815
- if (trailingSeparator) {
816
- path += "/";
817
- }
818
- if (DRIVE_LETTER_REGEX.test(path)) {
819
- path += "/";
820
- }
821
- if (isUNCPath) {
822
- if (!isPathAbsolute) {
823
- return `//./${path}`;
824
- }
825
- return `//${path}`;
826
- }
827
- return !path.startsWith("/") && isPathAbsolute && !DRIVE_LETTER_REGEX.test(path) ? `/${path}` : path;
828
- }
829
- __name(correctPath, "correctPath");
830
- function normalizeString2(path, allowAboveRoot) {
831
- let res = "";
832
- let lastSegmentLength = 0;
833
- let lastSlash = -1;
834
- let dots = 0;
835
- let char = null;
836
- for (let index = 0; index <= path.length; ++index) {
837
- if (index < path.length) {
838
- char = path[index];
839
- } else if (char === "/") {
840
- break;
841
- } else {
842
- char = "/";
843
- }
844
- if (char === "/") {
845
- if (lastSlash === index - 1 || dots === 1) {
846
- } else if (dots === 2) {
847
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
848
- if (res.length > 2) {
849
- const lastSlashIndex = res.lastIndexOf("/");
850
- if (lastSlashIndex === -1) {
851
- res = "";
852
- lastSegmentLength = 0;
853
- } else {
854
- res = res.slice(0, lastSlashIndex);
855
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
856
- }
857
- lastSlash = index;
858
- dots = 0;
859
- continue;
860
- } else if (res.length > 0) {
861
- res = "";
862
- lastSegmentLength = 0;
863
- lastSlash = index;
864
- dots = 0;
865
- continue;
866
- }
867
- }
868
- if (allowAboveRoot) {
869
- res += res.length > 0 ? "/.." : "..";
870
- lastSegmentLength = 2;
871
- }
872
- } else {
873
- if (res.length > 0) {
874
- res += `/${path.slice(lastSlash + 1, index)}`;
875
- } else {
876
- res = path.slice(lastSlash + 1, index);
877
- }
878
- lastSegmentLength = index - lastSlash - 1;
879
- }
880
- lastSlash = index;
881
- dots = 0;
882
- } else if (char === "." && dots !== -1) {
883
- ++dots;
884
- } else {
885
- dots = -1;
886
- }
887
- }
888
- return res;
889
- }
890
- __name(normalizeString2, "normalizeString");
891
805
 
892
806
  // ../path/src/get-workspace-root.ts
893
807
  import { findWorkspaceRootSafe } from "@storm-software/config-tools";
@@ -920,46 +834,13 @@ __name(relativePath, "relativePath");
920
834
 
921
835
  // bin/capnpc.ts
922
836
  import { Command, Option } from "commander";
837
+ import { writeFile } from "node:fs/promises";
923
838
  import ts2 from "typescript";
924
839
 
925
- // ../fs/src/helpers.ts
926
- import { parseTar, parseTarGzip } from "nanotar";
927
- import { createWriteStream, mkdirSync, rmSync } from "node:fs";
928
- import { mkdir, readFile as readFile2, rm } from "node:fs/promises";
929
- async function createDirectory(path) {
930
- if (await exists(path)) {
931
- return;
932
- }
933
- return mkdir(path, {
934
- recursive: true
935
- });
936
- }
937
- __name(createDirectory, "createDirectory");
938
-
939
- // ../fs/src/write-file.ts
940
- import { stringify as stringifyToml } from "@ltd/j-toml";
941
- import defu2 from "defu";
942
- import { writeFileSync as writeFileSyncFs } from "node:fs";
943
- import { writeFile as writeFileFs } from "node:fs/promises";
944
- var writeFile = /* @__PURE__ */ __name(async (filePath, content = "", options = {}) => {
945
- if (!filePath) {
946
- throw new Error("No file path provided to read data");
947
- }
948
- const directory = findFilePath(correctPath(filePath));
949
- if (!existsSync2(directory)) {
950
- if (options.createDirectory !== false) {
951
- await createDirectory(directory);
952
- } else {
953
- throw new Error(`Directory ${directory} does not exist`);
954
- }
955
- }
956
- return writeFileFs(filePath, content || "", options);
957
- }, "writeFile");
958
-
959
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=8f737a83e1b5be10396ff9b257b56b8b8e7a3dbd2754765e9b1e2019839e9c31_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.CbTQkT9D.mjs
840
+ // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=824b6bae5f47936633f815d4ffa9019910937dad06e41df5249655046cadee7a_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.CbTQkT9D.mjs
960
841
  import ts from "typescript";
961
842
 
962
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=8f737a83e1b5be10396ff9b257b56b8b8e7a3dbd2754765e9b1e2019839e9c31_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.0-_cOx6D.mjs
843
+ // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=824b6bae5f47936633f815d4ffa9019910937dad06e41df5249655046cadee7a_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.0-_cOx6D.mjs
963
844
  var ListElementSize = /* @__PURE__ */ ((ListElementSize2) => {
964
845
  ListElementSize2[ListElementSize2["VOID"] = 0] = "VOID";
965
846
  ListElementSize2[ListElementSize2["BIT"] = 1] = "BIT";
@@ -2952,7 +2833,7 @@ function checkDataBounds(byteOffset, byteLength, s) {
2952
2833
  }
2953
2834
  __name(checkDataBounds, "checkDataBounds");
2954
2835
 
2955
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=8f737a83e1b5be10396ff9b257b56b8b8e7a3dbd2754765e9b1e2019839e9c31_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.BvfUH5E6.mjs
2836
+ // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=824b6bae5f47936633f815d4ffa9019910937dad06e41df5249655046cadee7a_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.BvfUH5E6.mjs
2956
2837
  function CompositeList(CompositeClass) {
2957
2838
  return class extends List {
2958
2839
  static _capnp = {
@@ -3023,7 +2904,7 @@ var getUint8Mask = _makePrimitiveMaskFn(
3023
2904
  DataView.prototype.setUint8
3024
2905
  );
3025
2906
 
3026
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=8f737a83e1b5be10396ff9b257b56b8b8e7a3dbd2754765e9b1e2019839e9c31_typescript@5.8.3/node_modules/capnp-es/dist/capnp/schema.mjs
2907
+ // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=824b6bae5f47936633f815d4ffa9019910937dad06e41df5249655046cadee7a_typescript@5.8.3/node_modules/capnp-es/dist/capnp/schema.mjs
3027
2908
  var _capnpFileId = BigInt("0xa93fc509624c72d9");
3028
2909
  var Node_Parameter = class extends Struct {
3029
2910
  static {
@@ -5683,7 +5564,7 @@ CodeGeneratorRequest._Nodes = CompositeList(Node);
5683
5564
  CodeGeneratorRequest._SourceInfo = CompositeList(Node_SourceInfo);
5684
5565
  CodeGeneratorRequest._RequestedFiles = CompositeList(CodeGeneratorRequest_RequestedFile);
5685
5566
 
5686
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=8f737a83e1b5be10396ff9b257b56b8b8e7a3dbd2754765e9b1e2019839e9c31_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.GpvEvMIK.mjs
5567
+ // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=824b6bae5f47936633f815d4ffa9019910937dad06e41df5249655046cadee7a_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.GpvEvMIK.mjs
5687
5568
  var ArenaKind = /* @__PURE__ */ ((ArenaKind2) => {
5688
5569
  ArenaKind2[ArenaKind2["SINGLE_SEGMENT"] = 0] = "SINGLE_SEGMENT";
5689
5570
  ArenaKind2[ArenaKind2["MULTI_SEGMENT"] = 1] = "MULTI_SEGMENT";
@@ -6680,7 +6561,7 @@ function copy(m) {
6680
6561
  }
6681
6562
  __name(copy, "copy");
6682
6563
 
6683
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=8f737a83e1b5be10396ff9b257b56b8b8e7a3dbd2754765e9b1e2019839e9c31_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.CbTQkT9D.mjs
6564
+ // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=824b6bae5f47936633f815d4ffa9019910937dad06e41df5249655046cadee7a_typescript@5.8.3/node_modules/capnp-es/dist/shared/capnp-es.CbTQkT9D.mjs
6684
6565
  var GEN_EXPLICIT_DEFAULT_NON_PRIMITIVE = "CAPNP-ES000 Don't know how to generate a %s field with an explicit default value.";
6685
6566
  var GEN_FIELD_NON_INLINE_STRUCT_LIST = "CAPNP-ES001 Don't know how to generate non-inline struct lists.";
6686
6567
  var GEN_NODE_LOOKUP_FAIL = "CAPNP-ES002 Failed to look up node id %s.";
@@ -6792,10 +6673,11 @@ var Primitives = {
6792
6673
  setter: "setVoid"
6793
6674
  }
6794
6675
  };
6795
- var SOURCE_COMMENT = `/* eslint-disable */
6676
+ var SOURCE_COMMENT = `
6677
+ /* eslint-disable */
6796
6678
  // biome-ignore lint: disable
6797
6679
 
6798
- // Generated by Storm Stack
6680
+ // Generated by storm-capnpc
6799
6681
  // Note: Do not edit this file manually - it will be overwritten automatically
6800
6682
 
6801
6683
  `;
@@ -7829,7 +7711,7 @@ function generateCapnpImport(ctx) {
7829
7711
  (n) => n.name === "importPath"
7830
7712
  );
7831
7713
  const importAnnotation = tsImportPathAnnotation && fileNode.annotations.find((a) => a.id === tsImportPathAnnotation.id);
7832
- const importPath = importAnnotation === void 0 ? "storm-capnp" : importAnnotation.value.text;
7714
+ const importPath = importAnnotation === void 0 ? "@stryke/capnp" : importAnnotation.value.text;
7833
7715
  ctx.codeParts.push(`import * as $ from '${importPath}';`);
7834
7716
  }
7835
7717
  __name(generateCapnpImport, "generateCapnpImport");
@@ -7838,7 +7720,7 @@ function generateNestedImports(ctx) {
7838
7720
  const { name } = imp;
7839
7721
  let importPath;
7840
7722
  if (name.startsWith("/capnp/")) {
7841
- importPath = `storm-capnp/capnp/${name.slice(7).replace(/\.capnp$/, "")}`;
7723
+ importPath = `@stryke/capnp/schemas/${name.slice(7).replace(/\.capnp$/, "")}`;
7842
7724
  } else {
7843
7725
  importPath = name.replace(/\.capnp$/, ".js");
7844
7726
  if (importPath[0] !== ".") {
@@ -7874,12 +7756,35 @@ async function compileAll(codeGenRequest, opts) {
7874
7756
  const req = new Message(codeGenRequest, false).getRoot(
7875
7757
  CodeGeneratorRequest
7876
7758
  );
7759
+ console.log(
7760
+ `
7761
+ Running capnpc for ${req.requestedFiles.length} capnp schema files
7762
+ `
7763
+ );
7877
7764
  const ctx = new CodeGeneratorContext();
7878
7765
  ctx.files = req.requestedFiles.map((file) => loadRequestedFile(req, file));
7766
+ if (ctx.files.length === 0) {
7767
+ throw new Error(GEN_NO_FILES);
7768
+ }
7769
+ console.log(
7770
+ `
7771
+ Compiling ${ctx.files.length} files: ${ctx.files.map((f) => f.tsPath).join(", ")}
7772
+ `
7773
+ );
7879
7774
  const files = new Map(
7880
7775
  ctx.files.map((file) => [file.tsPath, compileFile(file)])
7881
7776
  );
7882
- tsCompile(files, opts?.dts === true, opts?.js === true, opts?.tsconfig);
7777
+ if (files.size === 0) {
7778
+ throw new Error(GEN_NO_FILES);
7779
+ }
7780
+ if (opts?.dts === true || opts?.js === true) {
7781
+ console.log(
7782
+ `
7783
+ TypeScript Compiling ${files.size} files: ${[...files.keys()].join(", ")}
7784
+ `
7785
+ );
7786
+ tsCompile(files, opts?.dts === true, opts?.js === true, opts?.tsconfig);
7787
+ }
7883
7788
  if (!opts?.ts) {
7884
7789
  for (const [fileName] of files) {
7885
7790
  if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) {
@@ -7978,92 +7883,58 @@ function tsCompile(files, dts, js, tsconfig) {
7978
7883
  }
7979
7884
  __name(tsCompile, "tsCompile");
7980
7885
 
7981
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=8f737a83e1b5be10396ff9b257b56b8b8e7a3dbd2754765e9b1e2019839e9c31_typescript@5.8.3/node_modules/capnp-es/dist/compiler/index.mjs
7886
+ // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=824b6bae5f47936633f815d4ffa9019910937dad06e41df5249655046cadee7a_typescript@5.8.3/node_modules/capnp-es/dist/compiler/index.mjs
7982
7887
  import "typescript";
7983
7888
 
7984
7889
  // src/compile.ts
7985
7890
  import { Buffer as Buffer3 } from "node:buffer";
7986
7891
  import { exec } from "node:child_process";
7987
- import { existsSync as existsSync3 } from "node:fs";
7988
7892
  async function capnpc(options) {
7989
- try {
7990
- const { output, tsconfig, schema = [] } = options;
7991
- let dataBuf = Buffer3.alloc(0);
7992
- if (!process.stdin.isTTY) {
7993
- const chunks = [];
7994
- process.stdin.on("data", (chunk) => {
7995
- chunks.push(chunk);
7996
- });
7997
- await new Promise((resolve) => {
7998
- process.stdin.on("end", resolve);
7999
- });
8000
- const reqBuffer = Buffer3.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
8001
- let i = 0;
8002
- for (const chunk of chunks) {
8003
- chunk.copy(reqBuffer, i);
8004
- i += chunk.byteLength;
8005
- }
8006
- dataBuf = reqBuffer;
8007
- }
8008
- if (dataBuf.byteLength === 0) {
8009
- const opts = [];
8010
- if (output) {
8011
- opts.push(`-o-:${output}`);
8012
- } else {
8013
- opts.push("-o-");
8014
- }
8015
- dataBuf = await new Promise((resolve) => {
8016
- exec(`capnpc ${opts.join(" ")} ${schema.join(" ")}`, {
8017
- encoding: "buffer"
8018
- }, (error, stdout, stderr) => {
8019
- if (stderr.length > 0) {
8020
- process.stderr.write(stderr);
8021
- }
8022
- if (error) {
8023
- throw error;
8024
- }
8025
- resolve(stdout);
8026
- });
8027
- });
8028
- }
8029
- const result = await compileAll(dataBuf, {
8030
- ts: options.ts ?? true,
8031
- js: options.js ?? false,
8032
- dts: options.dts ?? true,
8033
- tsconfig: tsconfig?.options
7893
+ const { output, tsconfig, schemas = [], tty } = options;
7894
+ let dataBuf = Buffer3.alloc(0);
7895
+ if (tty) {
7896
+ const chunks = [];
7897
+ process.stdin.on("data", (chunk) => {
7898
+ chunks.push(chunk);
8034
7899
  });
8035
- for (const [fileName, content] of result.files) {
8036
- let filePath = fileName;
8037
- if (!existsSync3(findFilePath(filePath))) {
8038
- const fullPath = `/${filePath}`;
8039
- if (existsSync3(findFilePath(fullPath))) {
8040
- filePath = fullPath;
8041
- }
8042
- }
8043
- if (output) {
8044
- filePath = joinPaths(output, fileName);
8045
- }
8046
- if (!existsSync3(findFilePath(filePath))) {
8047
- await createDirectory(findFilePath(filePath));
8048
- }
8049
- await writeFile(
8050
- filePath,
8051
- // https://github.com/microsoft/TypeScript/issues/54632
8052
- content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2))
8053
- );
7900
+ await new Promise((resolve) => {
7901
+ process.stdin.on("end", resolve);
7902
+ });
7903
+ const reqBuffer = Buffer3.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
7904
+ let i = 0;
7905
+ for (const chunk of chunks) {
7906
+ chunk.copy(reqBuffer, i);
7907
+ i += chunk.byteLength;
8054
7908
  }
8055
- return result;
8056
- } catch (error) {
8057
- if (error instanceof Error) {
8058
- console.error(`Error: ${error.message}`);
8059
- if (error.stack) {
8060
- console.error(error.stack);
8061
- }
7909
+ dataBuf = reqBuffer;
7910
+ }
7911
+ if (dataBuf.byteLength === 0) {
7912
+ const opts = [];
7913
+ if (output) {
7914
+ opts.push(`-o-:${output}`);
8062
7915
  } else {
8063
- console.error("An unknown error occurred:", error);
8064
- }
8065
- throw error;
7916
+ opts.push("-o-");
7917
+ }
7918
+ dataBuf = await new Promise((resolve) => {
7919
+ exec(`capnpc ${opts.join(" ")} ${schemas.join(" ")}`, {
7920
+ encoding: "buffer"
7921
+ }, (error, stdout, stderr) => {
7922
+ if (stderr.length > 0) {
7923
+ process.stderr.write(stderr);
7924
+ }
7925
+ if (error) {
7926
+ throw error;
7927
+ }
7928
+ resolve(stdout);
7929
+ });
7930
+ });
8066
7931
  }
7932
+ return compileAll(dataBuf, {
7933
+ ts: options.ts ?? true,
7934
+ js: false,
7935
+ dts: false,
7936
+ tsconfig: tsconfig?.options
7937
+ });
8067
7938
  }
8068
7939
  __name(capnpc, "capnpc");
8069
7940
 
@@ -8080,9 +7951,13 @@ function createProgram() {
8080
7951
  }
8081
7952
  const program = new Command("storm-capnpc");
8082
7953
  program.version("1.0.0", "-v --version", "display CLI version");
7954
+ const projectRootOption = new Option("-p --project-root <path>", "The path to the project root directory");
8083
7955
  const tsOption = new Option("--ts", "An indicator to generate TypeScript files").default(true);
7956
+ const noTsOption = new Option("--no-ts", "An indicator to disable generation of TypeScript files");
8084
7957
  const jsOption = new Option("--js", "An indicator to generate JavaScript files").default(false);
8085
- const dtsOption = new Option("--dts", "An indicator to generate TypeScript declaration files").default(true);
7958
+ const dtsOption = new Option("--dts", "An indicator to generate TypeScript declaration files");
7959
+ const noDtsOption = new Option("--no-dts", "An indicator to disable generation of TypeScript declaration files");
7960
+ const ttyOption = new Option("--tty", "An indicator to enable TTY mode for the compiler");
8086
7961
  const importPathOption = new Option("-I --import-path <dir...>", "Add <dir> to the list of directories searched for non-relative imports").default([]).argParser((val) => {
8087
7962
  if (val.startsWith("-I") || val.startsWith("--import-path")) {
8088
7963
  return val.split(",").map((dir) => dir.trim());
@@ -8093,54 +7968,47 @@ function createProgram() {
8093
7968
  });
8094
7969
  const generateId = new Option("-i --generate-id", "Generate a new 64-bit unique ID for use in a Cap'n Proto schema").default(true);
8095
7970
  const standardImportOption = new Option("--standard-import", "Add default import paths; use only those specified by -I").default(true);
8096
- const schemaOption = new Option("-s --schema <path...>", "The directories containing the Cap'n Proto schema files to compile (default: current working directory)").default([
8097
- joinPaths(process.cwd(), "**/*.capnp")
8098
- ]).argParser((val) => {
8099
- let result = [];
8100
- if (val.startsWith("--schema") || val.startsWith("-s")) {
8101
- result = val.split(",").map((dir) => dir.trim());
8102
- }
8103
- result = [
8104
- val.trim()
8105
- ];
8106
- return result.map((dir) => dir.endsWith(".capnp") ? dir : joinPaths(dir, "**/*.capnp"));
8107
- });
7971
+ const schemaOption = new Option("-s --schema <path>", "The directory (or a glob to the directory) containing the Cap'n Proto schema files to compile (default: current working directory)").default(joinPaths("{projectRoot}", "**/*.capnp"));
8108
7972
  const outputOption = new Option("-o --output <path>", "The directory to output the generated files to");
8109
- const tsconfigOption = new Option("-p --tsconfig <path>", "The path to the TypeScript configuration file to use for compilation").default(joinPaths(process.cwd(), "tsconfig.json"));
7973
+ const tsconfigOption = new Option("--tsconfig <path>", "The path to the TypeScript configuration file to use for compilation").default(joinPaths("{projectRoot}", "tsconfig.json"));
8110
7974
  const workspaceRootOption = new Option("-w --workspace-root <path>", "The path to the workspace root directory").default(root);
8111
7975
  program.command("compile", {
8112
7976
  isDefault: true
8113
- }).description("Run the Storm Cap'n Proto compiler").addOption(schemaOption).addOption(outputOption).addOption(importPathOption).addOption(tsconfigOption).addOption(generateId).addOption(standardImportOption).addOption(tsOption).addOption(jsOption).addOption(dtsOption).addOption(workspaceRootOption).action(compileAction).showSuggestionAfterError(true).showHelpAfterError(true);
7977
+ }).description("Run the Storm Cap'n Proto compiler").addOption(projectRootOption).addOption(schemaOption).addOption(outputOption).addOption(importPathOption).addOption(tsconfigOption).addOption(generateId).addOption(standardImportOption).addOption(tsOption).addOption(noTsOption).addOption(jsOption).addOption(dtsOption).addOption(noDtsOption).addOption(workspaceRootOption).addOption(ttyOption).action(compileAction).showSuggestionAfterError(true).showHelpAfterError(true);
8114
7978
  return program;
8115
7979
  }
8116
7980
  __name(createProgram, "createProgram");
8117
7981
  async function compileAction(options) {
8118
- writeInfo(`\u{1F4E6} Storm Cap'n Proto Compiler will output ${options.ts ? "TypeScript code" : ""}${options.js ? options.ts ? ", JavaScript code" : "JavaScript code" : ""}${options.dts ? options.ts || options.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files ${options.output ? `to ${options.output}...` : ""}`, {
8119
- logLevel: "all"
8120
- });
8121
- if (!existsSync2(options.tsconfig)) {
8122
- writeFatal(options.tsconfig ? `\u2716 The specified TypeScript configuration file "${options.tsconfig}" does not exist. Please provide a valid path.` : "\u2716 The specified TypeScript configuration file does not exist. Please provide a valid path.", {
7982
+ const tsconfigPath = options.tsconfig.replace("{projectRoot}", options.projectRoot);
7983
+ const schema = options.schema ? options.schema.replace("{projectRoot}", options.projectRoot) : options.projectRoot;
7984
+ if (!existsSync(tsconfigPath)) {
7985
+ const errorMessage = options.tsconfig ? `\u2716 The specified TypeScript configuration file "${tsconfigPath}" does not exist. Please provide a valid path.` : "\u2716 The specified TypeScript configuration file does not exist. Please provide a valid path.";
7986
+ writeFatal(errorMessage, {
8123
7987
  logLevel: "all"
8124
7988
  });
8125
- return;
7989
+ throw new Error(errorMessage);
8126
7990
  }
8127
- const resolvedTsconfig = await readJsonFile(options.tsconfig);
8128
- const tsconfig = ts2.parseJsonConfigFileContent(resolvedTsconfig, ts2.sys, findFilePath(options.tsconfig));
8129
- tsconfig.options.configFilePath = options.tsconfig;
7991
+ const resolvedTsconfig = await readJsonFile(tsconfigPath);
7992
+ const tsconfig = ts2.parseJsonConfigFileContent(resolvedTsconfig, ts2.sys, findFilePath(tsconfigPath));
7993
+ tsconfig.options.configFilePath = tsconfigPath;
8130
7994
  tsconfig.options.noImplicitOverride = false;
8131
- tsconfig.options.outDir = relativePath(findFilePath(joinPaths(options.workspaceRoot, options.tsconfig)), joinPaths(options.workspaceRoot, options.schema.length > 0 && options.schema[0] ? options.schema[0].endsWith(".capnp") ? findFilePath(options.schema[0]) : options.schema[0] : ""));
8132
- const schema = [];
8133
- for (const schemaPath of options.schema) {
8134
- if (!schemaPath || !schemaPath.includes("*") && !existsSync2(schemaPath)) {
8135
- writeFatal(`\u2716 The schema path "${schemaPath}" is invalid. Please provide a valid path.`, {
8136
- logLevel: "all"
8137
- });
8138
- return;
8139
- }
8140
- schema.push(...await listFiles(schemaPath));
7995
+ tsconfig.options.noUnusedLocals = false;
7996
+ tsconfig.options.noUnusedParameters = false;
7997
+ tsconfig.options.outDir = joinPaths(options.projectRoot, relativePath(findFilePath(tsconfigPath), joinPaths(options.workspaceRoot, schema.endsWith(".capnp") ? findFilePath(schema) : schema)));
7998
+ writeInfo(`\u{1F4E6} Storm Cap'n Proto Compiler will output ${options.ts ? "TypeScript code" : ""}${options.js ? options.ts ? ", JavaScript code" : "JavaScript code" : ""}${options.dts ? options.ts || options.js ? ", TypeScript declarations" : "TypeScript declarations" : ""} files from schemas at ${schema} to ${tsconfig.options.outDir}...`, {
7999
+ logLevel: "all"
8000
+ });
8001
+ const schemas = [];
8002
+ if (!schema || !schema.includes("*") && !existsSync(schema)) {
8003
+ const errorMessage = `\u2716 The schema path "${schema}" is invalid. Please provide a valid path.`;
8004
+ writeFatal(errorMessage, {
8005
+ logLevel: "all"
8006
+ });
8007
+ throw new Error(errorMessage);
8141
8008
  }
8142
- if (schema.length === 0) {
8143
- writeFatal(`\u2716 No Cap'n Proto schema files found in the specified source paths: ${options.schema.join(", ")}. Please ensure that the paths are correct and contain .capnp files.`, {
8009
+ schemas.push(...await listFiles(schema.includes("*") ? schema.endsWith(".capnp") ? schema : `${schema}.capnp` : joinPaths(schema, "**/*.capnp")));
8010
+ if (schemas.length === 0) {
8011
+ writeFatal(`\u2716 No Cap'n Proto schema files found in the specified source paths: ${schemas.join(", ")}. Please ensure that the paths are correct and contain .capnp files.`, {
8144
8012
  logLevel: "all"
8145
8013
  });
8146
8014
  return;
@@ -8148,14 +8016,39 @@ async function compileAction(options) {
8148
8016
  const result = await capnpc({
8149
8017
  ...options,
8150
8018
  tsconfig,
8151
- schema
8019
+ schemas,
8020
+ ts: options.ts ?? (options.noTs !== void 0 ? !options.noTs : true),
8021
+ dts: options.dts ?? (options.noDts !== void 0 ? !options.noDts : true)
8152
8022
  });
8153
8023
  if (result.files.size === 0) {
8154
- writeInfo("\u26A0\uFE0F No files were generated. Please check your schema files.", {
8024
+ writeWarning("\u26A0\uFE0F No files were generated. Please check your schema files.", {
8155
8025
  logLevel: "all"
8156
8026
  });
8157
8027
  return;
8158
8028
  }
8029
+ writeInfo(`Writing ${result.files.size} generated files to disk...`, {
8030
+ logLevel: "all"
8031
+ });
8032
+ for (const [fileName, content] of result.files) {
8033
+ let filePath = fileName;
8034
+ if (!existsSync(findFilePath(filePath))) {
8035
+ const fullPath = `/${filePath}`;
8036
+ if (existsSync(findFilePath(fullPath))) {
8037
+ filePath = fullPath;
8038
+ }
8039
+ }
8040
+ if (options.output) {
8041
+ filePath = joinPaths(options.output, fileName);
8042
+ }
8043
+ if (!existsSync(findFilePath(filePath))) {
8044
+ await createDirectory(findFilePath(filePath));
8045
+ }
8046
+ await writeFile(
8047
+ filePath,
8048
+ // https://github.com/microsoft/TypeScript/issues/54632
8049
+ content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2))
8050
+ );
8051
+ }
8159
8052
  writeSuccess("\u26A1 Storm Cap'n Proto Compiler completed successfully.", {
8160
8053
  logLevel: "all"
8161
8054
  });
@@ -0,0 +1,15 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-SHUYVCID.js";
4
+
5
+ // src/types.ts
6
+ var CodeGeneratorContext = class {
7
+ static {
8
+ __name(this, "CodeGeneratorContext");
9
+ }
10
+ files = [];
11
+ };
12
+
13
+ export {
14
+ CodeGeneratorContext
15
+ };