@stryke/capnp 0.6.2 → 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";
@@ -913,49 +827,20 @@ function findFilePath(filePath) {
913
827
  return result === "/" ? result : result.replace(/\/$/, "");
914
828
  }
915
829
  __name(findFilePath, "findFilePath");
830
+ function relativePath(from, to, withEndSlash = false) {
831
+ return relative(withEndSlash !== true ? from.replace(/\/$/, "") : from, withEndSlash !== true ? to.replace(/\/$/, "") : to);
832
+ }
833
+ __name(relativePath, "relativePath");
916
834
 
917
835
  // bin/capnpc.ts
918
836
  import { Command, Option } from "commander";
837
+ import { writeFile } from "node:fs/promises";
919
838
  import ts2 from "typescript";
920
839
 
921
- // ../fs/src/helpers.ts
922
- import { parseTar, parseTarGzip } from "nanotar";
923
- import { createWriteStream, mkdirSync, rmSync } from "node:fs";
924
- import { mkdir, readFile as readFile2, rm } from "node:fs/promises";
925
- async function createDirectory(path) {
926
- if (await exists(path)) {
927
- return;
928
- }
929
- return mkdir(path, {
930
- recursive: true
931
- });
932
- }
933
- __name(createDirectory, "createDirectory");
934
-
935
- // ../fs/src/write-file.ts
936
- import { stringify as stringifyToml } from "@ltd/j-toml";
937
- import defu2 from "defu";
938
- import { writeFileSync as writeFileSyncFs } from "node:fs";
939
- import { writeFile as writeFileFs } from "node:fs/promises";
940
- var writeFile = /* @__PURE__ */ __name(async (filePath, content = "", options = {}) => {
941
- if (!filePath) {
942
- throw new Error("No file path provided to read data");
943
- }
944
- const directory = findFilePath(correctPath(filePath));
945
- if (!existsSync2(directory)) {
946
- if (options.createDirectory !== false) {
947
- await createDirectory(directory);
948
- } else {
949
- throw new Error(`Directory ${directory} does not exist`);
950
- }
951
- }
952
- return writeFileFs(filePath, content || "", options);
953
- }, "writeFile");
954
-
955
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=80802686e11e663486f933dfdd5c01c5f57e003c1be30d468e18dd25b995f95b_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
956
841
  import ts from "typescript";
957
842
 
958
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=80802686e11e663486f933dfdd5c01c5f57e003c1be30d468e18dd25b995f95b_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
959
844
  var ListElementSize = /* @__PURE__ */ ((ListElementSize2) => {
960
845
  ListElementSize2[ListElementSize2["VOID"] = 0] = "VOID";
961
846
  ListElementSize2[ListElementSize2["BIT"] = 1] = "BIT";
@@ -2948,7 +2833,7 @@ function checkDataBounds(byteOffset, byteLength, s) {
2948
2833
  }
2949
2834
  __name(checkDataBounds, "checkDataBounds");
2950
2835
 
2951
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=80802686e11e663486f933dfdd5c01c5f57e003c1be30d468e18dd25b995f95b_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
2952
2837
  function CompositeList(CompositeClass) {
2953
2838
  return class extends List {
2954
2839
  static _capnp = {
@@ -3019,7 +2904,7 @@ var getUint8Mask = _makePrimitiveMaskFn(
3019
2904
  DataView.prototype.setUint8
3020
2905
  );
3021
2906
 
3022
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=80802686e11e663486f933dfdd5c01c5f57e003c1be30d468e18dd25b995f95b_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
3023
2908
  var _capnpFileId = BigInt("0xa93fc509624c72d9");
3024
2909
  var Node_Parameter = class extends Struct {
3025
2910
  static {
@@ -5679,7 +5564,7 @@ CodeGeneratorRequest._Nodes = CompositeList(Node);
5679
5564
  CodeGeneratorRequest._SourceInfo = CompositeList(Node_SourceInfo);
5680
5565
  CodeGeneratorRequest._RequestedFiles = CompositeList(CodeGeneratorRequest_RequestedFile);
5681
5566
 
5682
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=80802686e11e663486f933dfdd5c01c5f57e003c1be30d468e18dd25b995f95b_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
5683
5568
  var ArenaKind = /* @__PURE__ */ ((ArenaKind2) => {
5684
5569
  ArenaKind2[ArenaKind2["SINGLE_SEGMENT"] = 0] = "SINGLE_SEGMENT";
5685
5570
  ArenaKind2[ArenaKind2["MULTI_SEGMENT"] = 1] = "MULTI_SEGMENT";
@@ -6676,7 +6561,7 @@ function copy(m) {
6676
6561
  }
6677
6562
  __name(copy, "copy");
6678
6563
 
6679
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=80802686e11e663486f933dfdd5c01c5f57e003c1be30d468e18dd25b995f95b_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
6680
6565
  var GEN_EXPLICIT_DEFAULT_NON_PRIMITIVE = "CAPNP-ES000 Don't know how to generate a %s field with an explicit default value.";
6681
6566
  var GEN_FIELD_NON_INLINE_STRUCT_LIST = "CAPNP-ES001 Don't know how to generate non-inline struct lists.";
6682
6567
  var GEN_NODE_LOOKUP_FAIL = "CAPNP-ES002 Failed to look up node id %s.";
@@ -6788,10 +6673,11 @@ var Primitives = {
6788
6673
  setter: "setVoid"
6789
6674
  }
6790
6675
  };
6791
- var SOURCE_COMMENT = `/* eslint-disable */
6676
+ var SOURCE_COMMENT = `
6677
+ /* eslint-disable */
6792
6678
  // biome-ignore lint: disable
6793
6679
 
6794
- // Generated by Storm Stack
6680
+ // Generated by storm-capnpc
6795
6681
  // Note: Do not edit this file manually - it will be overwritten automatically
6796
6682
 
6797
6683
  `;
@@ -7825,7 +7711,7 @@ function generateCapnpImport(ctx) {
7825
7711
  (n) => n.name === "importPath"
7826
7712
  );
7827
7713
  const importAnnotation = tsImportPathAnnotation && fileNode.annotations.find((a) => a.id === tsImportPathAnnotation.id);
7828
- const importPath = importAnnotation === void 0 ? "capnp-es" : importAnnotation.value.text;
7714
+ const importPath = importAnnotation === void 0 ? "@stryke/capnp" : importAnnotation.value.text;
7829
7715
  ctx.codeParts.push(`import * as $ from '${importPath}';`);
7830
7716
  }
7831
7717
  __name(generateCapnpImport, "generateCapnpImport");
@@ -7834,7 +7720,7 @@ function generateNestedImports(ctx) {
7834
7720
  const { name } = imp;
7835
7721
  let importPath;
7836
7722
  if (name.startsWith("/capnp/")) {
7837
- importPath = `capnp-es/capnp/${name.slice(7).replace(/\.capnp$/, "")}`;
7723
+ importPath = `@stryke/capnp/schemas/${name.slice(7).replace(/\.capnp$/, "")}`;
7838
7724
  } else {
7839
7725
  importPath = name.replace(/\.capnp$/, ".js");
7840
7726
  if (importPath[0] !== ".") {
@@ -7870,12 +7756,35 @@ async function compileAll(codeGenRequest, opts) {
7870
7756
  const req = new Message(codeGenRequest, false).getRoot(
7871
7757
  CodeGeneratorRequest
7872
7758
  );
7759
+ console.log(
7760
+ `
7761
+ Running capnpc for ${req.requestedFiles.length} capnp schema files
7762
+ `
7763
+ );
7873
7764
  const ctx = new CodeGeneratorContext();
7874
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
+ );
7875
7774
  const files = new Map(
7876
7775
  ctx.files.map((file) => [file.tsPath, compileFile(file)])
7877
7776
  );
7878
- 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
+ }
7879
7788
  if (!opts?.ts) {
7880
7789
  for (const [fileName] of files) {
7881
7790
  if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) {
@@ -7919,6 +7828,7 @@ function tsCompile(files, dts, js, tsconfig) {
7919
7828
  const compileOptions = {
7920
7829
  moduleResolution: ts.ModuleResolutionKind.Bundler,
7921
7830
  target: ts.ScriptTarget.ESNext,
7831
+ strict: true,
7922
7832
  ...tsconfig,
7923
7833
  noEmitOnError: false,
7924
7834
  noFallthroughCasesInSwitch: true,
@@ -7929,7 +7839,6 @@ function tsCompile(files, dts, js, tsconfig) {
7929
7839
  removeComments: false,
7930
7840
  skipLibCheck: true,
7931
7841
  sourceMap: false,
7932
- strict: true,
7933
7842
  emitDeclarationOnly: dts && !js,
7934
7843
  declaration: dts
7935
7844
  };
@@ -7974,92 +7883,58 @@ function tsCompile(files, dts, js, tsconfig) {
7974
7883
  }
7975
7884
  __name(tsCompile, "tsCompile");
7976
7885
 
7977
- // ../../node_modules/.pnpm/capnp-es@0.0.11_patch_hash=80802686e11e663486f933dfdd5c01c5f57e003c1be30d468e18dd25b995f95b_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
7978
7887
  import "typescript";
7979
7888
 
7980
7889
  // src/compile.ts
7981
7890
  import { Buffer as Buffer3 } from "node:buffer";
7982
7891
  import { exec } from "node:child_process";
7983
- import { existsSync as existsSync3 } from "node:fs";
7984
7892
  async function capnpc(options) {
7985
- try {
7986
- const { output, tsconfig, schema = [] } = options;
7987
- let dataBuf = Buffer3.alloc(0);
7988
- if (!process.stdin.isTTY) {
7989
- const chunks = [];
7990
- process.stdin.on("data", (chunk) => {
7991
- chunks.push(chunk);
7992
- });
7993
- await new Promise((resolve) => {
7994
- process.stdin.on("end", resolve);
7995
- });
7996
- const reqBuffer = Buffer3.alloc(chunks.reduce((l, chunk) => l + chunk.byteLength, 0));
7997
- let i = 0;
7998
- for (const chunk of chunks) {
7999
- chunk.copy(reqBuffer, i);
8000
- i += chunk.byteLength;
8001
- }
8002
- dataBuf = reqBuffer;
8003
- }
8004
- if (dataBuf.byteLength === 0) {
8005
- const opts = [];
8006
- if (output) {
8007
- opts.push(`-o-:${output}`);
8008
- } else {
8009
- opts.push("-o-");
8010
- }
8011
- dataBuf = await new Promise((resolve) => {
8012
- exec(`capnpc ${opts.join(" ")} ${schema.join(" ")}`, {
8013
- encoding: "buffer"
8014
- }, (error, stdout, stderr) => {
8015
- if (stderr.length > 0) {
8016
- process.stderr.write(stderr);
8017
- }
8018
- if (error) {
8019
- throw error;
8020
- }
8021
- resolve(stdout);
8022
- });
8023
- });
8024
- }
8025
- const result = await compileAll(dataBuf, {
8026
- ts: options.ts ?? true,
8027
- js: options.js ?? false,
8028
- dts: options.dts ?? true,
8029
- 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);
8030
7899
  });
8031
- for (const [fileName, content] of result.files) {
8032
- let filePath = fileName;
8033
- if (!existsSync3(findFilePath(filePath))) {
8034
- const fullPath = `/${filePath}`;
8035
- if (existsSync3(findFilePath(fullPath))) {
8036
- filePath = fullPath;
8037
- }
8038
- }
8039
- if (output) {
8040
- filePath = joinPaths(output, fileName);
8041
- }
8042
- if (!existsSync3(findFilePath(filePath))) {
8043
- await createDirectory(findFilePath(filePath));
8044
- }
8045
- await writeFile(
8046
- filePath,
8047
- // https://github.com/microsoft/TypeScript/issues/54632
8048
- content.replace(/^\s+/gm, (match) => " ".repeat(match.length / 2))
8049
- );
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;
8050
7908
  }
8051
- return result;
8052
- } catch (error) {
8053
- if (error instanceof Error) {
8054
- console.error(`Error: ${error.message}`);
8055
- if (error.stack) {
8056
- console.error(error.stack);
8057
- }
7909
+ dataBuf = reqBuffer;
7910
+ }
7911
+ if (dataBuf.byteLength === 0) {
7912
+ const opts = [];
7913
+ if (output) {
7914
+ opts.push(`-o-:${output}`);
8058
7915
  } else {
8059
- console.error("An unknown error occurred:", error);
8060
- }
8061
- 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
+ });
8062
7931
  }
7932
+ return compileAll(dataBuf, {
7933
+ ts: options.ts ?? true,
7934
+ js: false,
7935
+ dts: false,
7936
+ tsconfig: tsconfig?.options
7937
+ });
8063
7938
  }
8064
7939
  __name(capnpc, "capnpc");
8065
7940
 
@@ -8076,9 +7951,13 @@ function createProgram() {
8076
7951
  }
8077
7952
  const program = new Command("storm-capnpc");
8078
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");
8079
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");
8080
7957
  const jsOption = new Option("--js", "An indicator to generate JavaScript files").default(false);
8081
- 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");
8082
7961
  const importPathOption = new Option("-I --import-path <dir...>", "Add <dir> to the list of directories searched for non-relative imports").default([]).argParser((val) => {
8083
7962
  if (val.startsWith("-I") || val.startsWith("--import-path")) {
8084
7963
  return val.split(",").map((dir) => dir.trim());
@@ -8089,52 +7968,47 @@ function createProgram() {
8089
7968
  });
8090
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);
8091
7970
  const standardImportOption = new Option("--standard-import", "Add default import paths; use only those specified by -I").default(true);
8092
- const schemaOption = new Option("-s --schema <path...>", "The directories containing the Cap'n Proto schema files to compile (default: current working directory)").default([
8093
- joinPaths(process.cwd(), "**/*.capnp")
8094
- ]).argParser((val) => {
8095
- let result = [];
8096
- if (val.startsWith("--schema") || val.startsWith("-s")) {
8097
- result = val.split(",").map((dir) => dir.trim());
8098
- }
8099
- result = [
8100
- val.trim()
8101
- ];
8102
- return result.map((dir) => dir.endsWith(".capnp") ? dir : joinPaths(dir, "**/*.capnp"));
8103
- });
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"));
8104
7972
  const outputOption = new Option("-o --output <path>", "The directory to output the generated files to");
8105
- 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"));
7974
+ const workspaceRootOption = new Option("-w --workspace-root <path>", "The path to the workspace root directory").default(root);
8106
7975
  program.command("compile", {
8107
7976
  isDefault: true
8108
- }).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).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);
8109
7978
  return program;
8110
7979
  }
8111
7980
  __name(createProgram, "createProgram");
8112
7981
  async function compileAction(options) {
8113
- 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}...` : ""}`, {
8114
- logLevel: "all"
8115
- });
8116
- if (!existsSync2(options.tsconfig)) {
8117
- 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, {
8118
7987
  logLevel: "all"
8119
7988
  });
8120
- return;
7989
+ throw new Error(errorMessage);
8121
7990
  }
8122
- const resolvedTsconfig = await readJsonFile(options.tsconfig);
8123
- const tsconfig = ts2.parseJsonConfigFileContent(resolvedTsconfig, ts2.sys, findFilePath(options.tsconfig));
8124
- 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;
8125
7994
  tsconfig.options.noImplicitOverride = false;
8126
- const schema = [];
8127
- for (const schemaPath of options.schema) {
8128
- if (!schemaPath || !schemaPath.includes("*") && !existsSync2(schemaPath)) {
8129
- writeFatal(`\u2716 The schema path "${schemaPath}" is invalid. Please provide a valid path.`, {
8130
- logLevel: "all"
8131
- });
8132
- return;
8133
- }
8134
- 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);
8135
8008
  }
8136
- if (schema.length === 0) {
8137
- 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.`, {
8138
8012
  logLevel: "all"
8139
8013
  });
8140
8014
  return;
@@ -8142,14 +8016,39 @@ async function compileAction(options) {
8142
8016
  const result = await capnpc({
8143
8017
  ...options,
8144
8018
  tsconfig,
8145
- 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)
8146
8022
  });
8147
8023
  if (result.files.size === 0) {
8148
- 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.", {
8149
8025
  logLevel: "all"
8150
8026
  });
8151
8027
  return;
8152
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
+ }
8153
8052
  writeSuccess("\u26A1 Storm Cap'n Proto Compiler completed successfully.", {
8154
8053
  logLevel: "all"
8155
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
+ };