@napi-rs/cli 3.0.0-alpha.4 → 3.0.0-alpha.40

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.
Files changed (177) hide show
  1. package/cli.mjs +0 -0
  2. package/dist/api/artifacts.js +32 -8
  3. package/dist/api/artifacts.js.map +1 -0
  4. package/dist/api/build.d.ts +1 -1
  5. package/dist/api/build.js +231 -30
  6. package/dist/api/build.js.map +1 -0
  7. package/dist/api/create-npm-dirs.js +46 -8
  8. package/dist/api/create-npm-dirs.js.map +1 -0
  9. package/dist/api/new.js +47 -20
  10. package/dist/api/new.js.map +1 -0
  11. package/dist/api/pre-publish.js +10 -7
  12. package/dist/api/pre-publish.js.map +1 -0
  13. package/dist/api/rename.js +10 -1
  14. package/dist/api/rename.js.map +1 -0
  15. package/dist/api/templates/.gitignore.d.ts +1 -1
  16. package/dist/api/templates/.gitignore.js +2 -0
  17. package/dist/api/templates/.gitignore.js.map +1 -0
  18. package/dist/api/templates/.npmignore.js +1 -0
  19. package/dist/api/templates/.npmignore.js.map +1 -0
  20. package/dist/api/templates/build.rs.js +1 -0
  21. package/dist/api/templates/build.rs.js.map +1 -0
  22. package/dist/api/templates/cargo.toml.js +1 -0
  23. package/dist/api/templates/cargo.toml.js.map +1 -0
  24. package/dist/api/templates/ci-template.d.ts +2 -1
  25. package/dist/api/templates/ci-template.js +150 -152
  26. package/dist/api/templates/ci-template.js.map +1 -0
  27. package/dist/api/templates/ci.yml.d.ts +2 -1
  28. package/dist/api/templates/ci.yml.js +19 -4
  29. package/dist/api/templates/ci.yml.js.map +1 -0
  30. package/dist/api/templates/index.js +1 -0
  31. package/dist/api/templates/index.js.map +1 -0
  32. package/dist/api/templates/js-binding.d.ts +1 -1
  33. package/dist/api/templates/js-binding.js +111 -13
  34. package/dist/api/templates/js-binding.js.map +1 -0
  35. package/dist/api/templates/lib.rs.js +2 -4
  36. package/dist/api/templates/lib.rs.js.map +1 -0
  37. package/dist/api/templates/load-wasi-template.d.ts +2 -0
  38. package/dist/api/templates/load-wasi-template.js +143 -0
  39. package/dist/api/templates/load-wasi-template.js.map +1 -0
  40. package/dist/api/templates/package.json.d.ts +9 -2
  41. package/dist/api/templates/package.json.js +53 -28
  42. package/dist/api/templates/package.json.js.map +1 -0
  43. package/dist/api/templates/wasi-worker-template.d.ts +2 -0
  44. package/dist/api/templates/wasi-worker-template.js +93 -0
  45. package/dist/api/templates/wasi-worker-template.js.map +1 -0
  46. package/dist/api/universalize.js +6 -5
  47. package/dist/api/universalize.js.map +1 -0
  48. package/dist/api/version.js +3 -2
  49. package/dist/api/version.js.map +1 -0
  50. package/dist/cli.js +1 -0
  51. package/dist/cli.js.map +1 -0
  52. package/dist/commands/artifacts.js +4 -4
  53. package/dist/commands/artifacts.js.map +1 -0
  54. package/dist/commands/build.js +2 -1
  55. package/dist/commands/build.js.map +1 -0
  56. package/dist/commands/create-npm-dirs.js +1 -0
  57. package/dist/commands/create-npm-dirs.js.map +1 -0
  58. package/dist/commands/help.js +2 -2
  59. package/dist/commands/help.js.map +1 -0
  60. package/dist/commands/new.js +15 -7
  61. package/dist/commands/new.js.map +1 -0
  62. package/dist/commands/pre-publish.js +1 -0
  63. package/dist/commands/pre-publish.js.map +1 -0
  64. package/dist/commands/rename.js +1 -0
  65. package/dist/commands/rename.js.map +1 -0
  66. package/dist/commands/universalize.js +1 -0
  67. package/dist/commands/universalize.js.map +1 -0
  68. package/dist/commands/version.js +1 -0
  69. package/dist/commands/version.js.map +1 -0
  70. package/dist/def/artifacts.d.ts +21 -1
  71. package/dist/def/artifacts.js +12 -4
  72. package/dist/def/artifacts.js.map +1 -0
  73. package/dist/def/build.d.ts +20 -2
  74. package/dist/def/build.js +16 -4
  75. package/dist/def/build.js.map +1 -0
  76. package/dist/def/create-npm-dirs.d.ts +10 -0
  77. package/dist/def/create-npm-dirs.js +6 -2
  78. package/dist/def/create-npm-dirs.js.map +1 -0
  79. package/dist/def/new.d.ts +24 -6
  80. package/dist/def/new.js +13 -3
  81. package/dist/def/new.js.map +1 -0
  82. package/dist/def/pre-publish.d.ts +10 -0
  83. package/dist/def/pre-publish.js +9 -5
  84. package/dist/def/pre-publish.js.map +1 -0
  85. package/dist/def/rename.d.ts +11 -1
  86. package/dist/def/rename.js +7 -3
  87. package/dist/def/rename.js.map +1 -0
  88. package/dist/def/universalize.d.ts +10 -0
  89. package/dist/def/universalize.js +6 -2
  90. package/dist/def/universalize.js.map +1 -0
  91. package/dist/def/version.d.ts +10 -0
  92. package/dist/def/version.js +6 -2
  93. package/dist/def/version.js.map +1 -0
  94. package/dist/index.cjs +5977 -8003
  95. package/dist/index.d.ts +1 -0
  96. package/dist/index.js +2 -0
  97. package/dist/index.js.map +1 -0
  98. package/dist/utils/__tests__/config.spec.d.ts +1 -0
  99. package/dist/utils/__tests__/config.spec.js +63 -0
  100. package/dist/utils/__tests__/config.spec.js.map +1 -0
  101. package/dist/utils/__tests__/target.spec.js +1 -0
  102. package/dist/utils/__tests__/target.spec.js.map +1 -0
  103. package/dist/utils/__tests__/typegen.spec.js +9 -4
  104. package/dist/utils/__tests__/typegen.spec.js.map +1 -0
  105. package/dist/utils/__tests__/version.spec.js +1 -0
  106. package/dist/utils/__tests__/version.spec.js.map +1 -0
  107. package/dist/utils/cargo.js +2 -1
  108. package/dist/utils/cargo.js.map +1 -0
  109. package/dist/utils/ci.js +1 -0
  110. package/dist/utils/ci.js.map +1 -0
  111. package/dist/utils/config.d.ts +25 -5
  112. package/dist/utils/config.js +39 -6
  113. package/dist/utils/config.js.map +1 -0
  114. package/dist/utils/index.js +1 -0
  115. package/dist/utils/index.js.map +1 -0
  116. package/dist/utils/log.js +1 -0
  117. package/dist/utils/log.js.map +1 -0
  118. package/dist/utils/metadata.js +3 -2
  119. package/dist/utils/metadata.js.map +1 -0
  120. package/dist/utils/misc.d.ts +1 -1
  121. package/dist/utils/misc.js +4 -3
  122. package/dist/utils/misc.js.map +1 -0
  123. package/dist/utils/target.d.ts +9 -5
  124. package/dist/utils/target.js +16 -1
  125. package/dist/utils/target.js.map +1 -0
  126. package/dist/utils/typegen.d.ts +4 -1
  127. package/dist/utils/typegen.js +27 -6
  128. package/dist/utils/typegen.js.map +1 -0
  129. package/dist/utils/version.d.ts +2 -1
  130. package/dist/utils/version.js +13 -10
  131. package/dist/utils/version.js.map +1 -0
  132. package/package.json +50 -16
  133. package/src/api/artifacts.ts +85 -10
  134. package/src/api/build.ts +381 -32
  135. package/src/api/create-npm-dirs.ts +56 -8
  136. package/src/api/new.ts +69 -33
  137. package/src/api/pre-publish.ts +21 -12
  138. package/src/api/rename.ts +10 -1
  139. package/src/api/templates/.gitignore.ts +1 -0
  140. package/src/api/templates/ci-template.ts +151 -152
  141. package/src/api/templates/ci.yml.ts +19 -4
  142. package/src/api/templates/js-binding.ts +114 -13
  143. package/src/api/templates/lib.rs.ts +1 -4
  144. package/src/api/templates/load-wasi-template.ts +150 -0
  145. package/src/api/templates/package.json.ts +74 -27
  146. package/src/api/templates/wasi-worker-template.ts +93 -0
  147. package/src/api/universalize.ts +8 -5
  148. package/src/api/version.ts +5 -2
  149. package/src/commands/artifacts.ts +2 -2
  150. package/src/commands/build.ts +1 -1
  151. package/src/commands/new.ts +14 -8
  152. package/src/def/artifacts.ts +22 -3
  153. package/src/def/build.ts +32 -4
  154. package/src/def/create-npm-dirs.ts +9 -0
  155. package/src/def/new.ts +28 -3
  156. package/src/def/pre-publish.ts +12 -3
  157. package/src/def/rename.ts +11 -2
  158. package/src/def/universalize.ts +9 -0
  159. package/src/def/version.ts +9 -0
  160. package/src/index.ts +2 -0
  161. package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
  162. package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
  163. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +7 -0
  164. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  165. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +555 -0
  166. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
  167. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +9 -8
  168. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  169. package/src/utils/__tests__/config.spec.ts +81 -0
  170. package/src/utils/__tests__/typegen.spec.ts +19 -4
  171. package/src/utils/cargo.ts +1 -1
  172. package/src/utils/config.ts +85 -9
  173. package/src/utils/metadata.ts +2 -2
  174. package/src/utils/misc.ts +11 -3
  175. package/src/utils/target.ts +23 -7
  176. package/src/utils/typegen.ts +30 -5
  177. package/src/utils/version.ts +11 -9
@@ -616,3 +616,558 @@ Generated by [AVA](https://avajs.dev).
616
616
  }␊
617
617
  ␊
618
618
  `
619
+
620
+ ## should process type def with noConstEnum correctly
621
+
622
+ > Snapshot 1
623
+
624
+ `␊
625
+ export class ExternalObject<T> {␊
626
+ readonly '': {␊
627
+ readonly '': unique symbol␊
628
+ [K: symbol]: T␊
629
+ }␊
630
+ }␊
631
+ /**␊
632
+ * \`constructor\` option for \`struct\` requires all fields to be public,␊
633
+ * otherwise tag impl fn as constructor␊
634
+ * #[napi(constructor)]␊
635
+ */␊
636
+ export class Animal {␊
637
+ /** Kind of animal */␊
638
+ readonly kind: Kind␊
639
+ /** This is the constructor */␊
640
+ constructor(kind: Kind, name: string)␊
641
+ /** This is a factory method */␊
642
+ static withKind(kind: Kind): Animal␊
643
+ get name(): string␊
644
+ set name(name: string)␊
645
+ get type(): Kind␊
646
+ set type(kind: Kind)␊
647
+ /**␊
648
+ * This is a␊
649
+ * multi-line comment␊
650
+ * with an emoji 🚀␊
651
+ */␊
652
+ whoami(): string␊
653
+ /** This is static... */␊
654
+ static getDogKind(): Kind␊
655
+ /**␊
656
+ * Here are some characters and character sequences␊
657
+ * that should be escaped correctly:␊
658
+ * \\[]{}/\\:""{␊
659
+ * }␊
660
+ */␊
661
+ returnOtherClass(): Dog␊
662
+ returnOtherClassWithCustomConstructor(): Bird␊
663
+ overrideIndividualArgOnMethod(normalTy: string, overriddenTy: {n: string}): Bird␊
664
+ }␊
665
+ ␊
666
+ export class AnimalWithDefaultConstructor {␊
667
+ name: string␊
668
+ kind: number␊
669
+ constructor(name: string, kind: number)␊
670
+ }␊
671
+ ␊
672
+ export class AnotherClassForEither {␊
673
+ constructor()␊
674
+ }␊
675
+ ␊
676
+ export class AnotherCssStyleSheet {␊
677
+ get rules(): CssRuleList␊
678
+ }␊
679
+ export type AnotherCSSStyleSheet = AnotherCssStyleSheet␊
680
+ ␊
681
+ export class Asset {␊
682
+ constructor()␊
683
+ get filePath(): number␊
684
+ }␊
685
+ export type JsAsset = Asset␊
686
+ ␊
687
+ export class Assets {␊
688
+ constructor()␊
689
+ get(id: number): JsAsset | null␊
690
+ }␊
691
+ export type JsAssets = Assets␊
692
+ ␊
693
+ export class Bird {␊
694
+ name: string␊
695
+ constructor(name: string)␊
696
+ getCount(): number␊
697
+ getNameAsync(): Promise<string>␊
698
+ }␊
699
+ ␊
700
+ /** Smoking test for type generation */␊
701
+ export class Blake2BHasher {␊
702
+ static withKey(key: Blake2bKey): Blake2BHasher␊
703
+ update(data: Buffer): void␊
704
+ }␊
705
+ export type Blake2bHasher = Blake2BHasher␊
706
+ ␊
707
+ export class Blake2BKey {␊
708
+ ␊
709
+ }␊
710
+ export type Blake2bKey = Blake2BKey␊
711
+ ␊
712
+ export class ClassWithFactory {␊
713
+ name: string␊
714
+ static withName(name: string): ClassWithFactory␊
715
+ setName(name: string): this␊
716
+ }␊
717
+ ␊
718
+ export class Context {␊
719
+ maybeNeed?: boolean␊
720
+ buffer: Uint8Array␊
721
+ constructor()␊
722
+ static withData(data: string): Context␊
723
+ static withBuffer(buf: Uint8Array): Context␊
724
+ method(): string␊
725
+ }␊
726
+ ␊
727
+ export class CssRuleList {␊
728
+ getRules(): Array<string>␊
729
+ get parentStyleSheet(): CSSStyleSheet␊
730
+ get name(): string | null␊
731
+ }␊
732
+ export type CSSRuleList = CssRuleList␊
733
+ ␊
734
+ export class CssStyleSheet {␊
735
+ constructor(name: string, rules: Array<string>)␊
736
+ get rules(): CssRuleList␊
737
+ anotherCssStyleSheet(): AnotherCssStyleSheet␊
738
+ }␊
739
+ export type CSSStyleSheet = CssStyleSheet␊
740
+ ␊
741
+ export class CustomFinalize {␊
742
+ constructor(width: number, height: number)␊
743
+ }␊
744
+ ␊
745
+ export class Dog {␊
746
+ name: string␊
747
+ constructor(name: string)␊
748
+ }␊
749
+ ␊
750
+ export class Fib {␊
751
+ [Symbol.iterator](): Iterator<number, void, number>␊
752
+ constructor()␊
753
+ }␊
754
+ ␊
755
+ export class Fib2 {␊
756
+ [Symbol.iterator](): Iterator<number, void, number>␊
757
+ static create(seed: number): Fib2␊
758
+ }␊
759
+ ␊
760
+ export class Fib3 {␊
761
+ current: number␊
762
+ next: number␊
763
+ constructor(current: number, next: number)␊
764
+ [Symbol.iterator](): Iterator<number, void, number>␊
765
+ }␊
766
+ ␊
767
+ export class JsClassForEither {␊
768
+ constructor()␊
769
+ }␊
770
+ ␊
771
+ export class JsRemote {␊
772
+ name(): string␊
773
+ }␊
774
+ ␊
775
+ export class JsRepo {␊
776
+ constructor(dir: string)␊
777
+ remote(): JsRemote␊
778
+ }␊
779
+ ␊
780
+ export class NinjaTurtle {␊
781
+ name: string␊
782
+ static isInstanceOf(value: unknown): boolean␊
783
+ /** Create your ninja turtle! 🐢 */␊
784
+ static newRaph(): NinjaTurtle␊
785
+ getMaskColor(): string␊
786
+ getName(): string␊
787
+ returnThis(this: this): this␊
788
+ }␊
789
+ ␊
790
+ export class NotWritableClass {␊
791
+ name: string␊
792
+ constructor(name: string)␊
793
+ setName(name: string): void␊
794
+ }␊
795
+ ␊
796
+ export class Optional {␊
797
+ static optionEnd(required: string, optional?: string | undefined | null): string␊
798
+ static optionStart(optional: string | undefined | null, required: string): string␊
799
+ static optionStartEnd(optional1: string | undefined | null, required: string, optional2?: string | undefined | null): string␊
800
+ static optionOnly(optional?: string | undefined | null): string␊
801
+ }␊
802
+ ␊
803
+ export class Width {␊
804
+ value: number␊
805
+ constructor(value: number)␊
806
+ }␊
807
+ ␊
808
+ export interface A {␊
809
+ foo: number␊
810
+ }␊
811
+ ␊
812
+ export function acceptThreadsafeFunction(func: (err: Error | null, value: number) => any): void␊
813
+ ␊
814
+ export function acceptThreadsafeFunctionFatal(func: (value: number) => any): void␊
815
+ ␊
816
+ export function acceptThreadsafeFunctionTupleArgs(func: (err: Error | null, arg0: number, arg1: boolean, arg2: string) => any): void␊
817
+ ␊
818
+ export function add(a: number, b: number): number␊
819
+ ␊
820
+ export enum ALIAS {␊
821
+ A = 0,␊
822
+ B = 1␊
823
+ }␊
824
+ ␊
825
+ export interface AliasedStruct {␊
826
+ a: ALIAS␊
827
+ b: number␊
828
+ }␊
829
+ ␊
830
+ export interface AllOptionalObject {␊
831
+ name?: string␊
832
+ age?: number␊
833
+ }␊
834
+ ␊
835
+ export function appendBuffer(buf: Buffer): Buffer␊
836
+ ␊
837
+ export function arrayBufferPassThrough(buf: Uint8Array): Promise<Uint8Array>␊
838
+ ␊
839
+ export function asyncMultiTwo(arg: number): Promise<number>␊
840
+ ␊
841
+ export function asyncPlus100(p: Promise<number>): Promise<number>␊
842
+ ␊
843
+ export function asyncReduceBuffer(buf: Buffer): Promise<number>␊
844
+ ␊
845
+ export interface B {␊
846
+ bar: number␊
847
+ }␊
848
+ ␊
849
+ export function bigintAdd(a: bigint, b: bigint): bigint␊
850
+ ␊
851
+ export function bigintFromI128(): bigint␊
852
+ ␊
853
+ export function bigintFromI64(): bigint␊
854
+ ␊
855
+ export function bigintGetU64AsString(bi: bigint): string␊
856
+ ␊
857
+ export function bufferPassThrough(buf: Buffer): Promise<Buffer>␊
858
+ ␊
859
+ export interface C {␊
860
+ baz: number␊
861
+ }␊
862
+ ␊
863
+ export function callbackReturnPromise<T>(functionInput: () => T | Promise<T>, callback: (err: Error | null, result: T) => void): T | Promise<T>␊
864
+ ␊
865
+ export function callThreadsafeFunction(callback: (...args: any[]) => any): void␊
866
+ ␊
867
+ export function captureErrorInCallback(cb1: () => void, cb2: (arg0: Error) => void): void␊
868
+ ␊
869
+ export function chronoDateAdd1Minute(input: Date): Date␊
870
+ ␊
871
+ export function chronoDateToMillis(input: Date): number␊
872
+ ␊
873
+ export function concatLatin1(s: string): string␊
874
+ ␊
875
+ export function concatStr(s: string): string␊
876
+ ␊
877
+ export function concatUtf16(s: string): string␊
878
+ ␊
879
+ export function contains(source: string, target: string): boolean␊
880
+ ␊
881
+ export function convertU32Array(input: Uint32Array): Array<number>␊
882
+ ␊
883
+ export function createBigInt(): bigint␊
884
+ ␊
885
+ export function createBigIntI64(): bigint␊
886
+ ␊
887
+ export function createExternal(size: number): ExternalObject<number>␊
888
+ ␊
889
+ export function createExternalString(content: string): ExternalObject<string>␊
890
+ ␊
891
+ export function createExternalTypedArray(): Uint32Array␊
892
+ ␊
893
+ export function createObj(): object␊
894
+ ␊
895
+ export function createObjectWithClassField(): ObjectFieldClassInstance␊
896
+ ␊
897
+ export function createObjWithProperty(): { value: ArrayBuffer, get getter(): number }␊
898
+ ␊
899
+ export function createSymbol(): symbol␊
900
+ ␊
901
+ /** You could break the step and for an new continuous value. */␊
902
+ export enum CustomNumEnum {␊
903
+ One = 1,␊
904
+ Two = 2,␊
905
+ Three = 3,␊
906
+ Four = 4,␊
907
+ Six = 6,␊
908
+ Eight = 8,␊
909
+ Nine = 9,␊
910
+ Ten = 10␊
911
+ }␊
912
+ ␊
913
+ export function customStatusCode(): void␊
914
+ ␊
915
+ export interface Dates {␊
916
+ start: Date␊
917
+ end?: Date␊
918
+ }␊
919
+ ␊
920
+ export function dateToNumber(input: Date): number␊
921
+ ␊
922
+ /** This is a const */␊
923
+ export const DEFAULT_COST: number␊
924
+ ␊
925
+ export function derefUint8Array(a: Uint8Array, b: Uint8ClampedArray): number␊
926
+ ␊
927
+ export function either3(input: string | number | boolean): number␊
928
+ ␊
929
+ export function either4(input: string | number | boolean | Obj): number␊
930
+ ␊
931
+ export function eitherBoolOrFunction(input: boolean | ((...args: any[]) => any)): void␊
932
+ ␊
933
+ export function eitherFromObjects(input: A | B | C): string␊
934
+ ␊
935
+ export function eitherFromOption(): JsClassForEither | undefined␊
936
+ ␊
937
+ export function eitherStringOrNumber(input: string | number): number␊
938
+ ␊
939
+ export enum Empty {␊
940
+ ␊
941
+ }␊
942
+ ␊
943
+ export function enumToI32(e: CustomNumEnum): number␊
944
+ ␊
945
+ export function fibonacci(n: number): number␊
946
+ ␊
947
+ export function fnReceivedAliased(s: AliasedStruct, e: ALIAS): void␊
948
+ ␊
949
+ export function getBuffer(): Buffer␊
950
+ ␊
951
+ export function getCwd(callback: (arg0: string) => void): void␊
952
+ ␊
953
+ export function getEmptyBuffer(): Buffer␊
954
+ ␊
955
+ export function getExternal(external: ExternalObject<number>): number␊
956
+ ␊
957
+ export function getGlobal(): typeof global␊
958
+ ␊
959
+ export function getMapping(): Record<string, number>␊
960
+ ␊
961
+ export function getNestedNumArr(): number[][][]␊
962
+ ␊
963
+ export function getNull(): null␊
964
+ ␊
965
+ export function getNumArr(): number[]␊
966
+ ␊
967
+ /** Gets some numbers */␊
968
+ export function getNums(): Array<number>␊
969
+ ␊
970
+ export function getPackageJsonName(packageJson: PackageJson): string␊
971
+ ␊
972
+ export function getStrFromObject(): void␊
973
+ ␊
974
+ export function getterFromObj(): number␊
975
+ ␊
976
+ export function getUndefined(): void␊
977
+ ␊
978
+ export function getWords(): Array<string>␊
979
+ ␊
980
+ /** default enum values are continuos i32s start from 0 */␊
981
+ export enum Kind {␊
982
+ /** Barks */␊
983
+ Dog = 0,␊
984
+ /** Kills birds */␊
985
+ Cat = 1,␊
986
+ /** Tasty */␊
987
+ Duck = 2␊
988
+ }␊
989
+ ␊
990
+ export function listObjKeys(obj: object): Array<string>␊
991
+ ␊
992
+ export function mapOption(val?: number | undefined | null): number | null␊
993
+ ␊
994
+ export function mutateExternal(external: ExternalObject<number>, newVal: number): void␊
995
+ ␊
996
+ export function mutateTypedArray(input: Float32Array): void␊
997
+ ␊
998
+ export interface Obj {␊
999
+ v: string | number␊
1000
+ }␊
1001
+ ␊
1002
+ export interface ObjectFieldClassInstance {␊
1003
+ bird: Bird␊
1004
+ }␊
1005
+ ␊
1006
+ export interface ObjectOnlyFromJs {␊
1007
+ count: number␊
1008
+ callback: (err: Error | null, value: number) => any␊
1009
+ }␊
1010
+ ␊
1011
+ export function optionEnd(callback: (arg0: string, arg1?: string | undefined | null) => void): void␊
1012
+ ␊
1013
+ export function optionOnly(callback: (arg0?: string | undefined | null) => void): void␊
1014
+ ␊
1015
+ export function optionStart(callback: (arg0: string | undefined | null, arg1: string) => void): void␊
1016
+ ␊
1017
+ export function optionStartEnd(callback: (arg0: string | undefined | null, arg1: string, arg2?: string | undefined | null) => void): void␊
1018
+ ␊
1019
+ export function overrideIndividualArgOnFunction(notOverridden: string, f: () => string, notOverridden2: number): string␊
1020
+ ␊
1021
+ export function overrideIndividualArgOnFunctionWithCbArg(callback: (town: string, name?: string | undefined | null) => string, notOverridden: number): object␊
1022
+ ␊
1023
+ /** This is an interface for package.json */␊
1024
+ export interface PackageJson {␊
1025
+ name: string␊
1026
+ /** The version of the package */␊
1027
+ version: string␊
1028
+ dependencies?: Record<string, any>␊
1029
+ devDependencies?: Record<string, any>␊
1030
+ }␊
1031
+ ␊
1032
+ export function panic(): void␊
1033
+ ␊
1034
+ export function plusOne(this: Width): number␊
1035
+ ␊
1036
+ export function promiseInEither(input: number | Promise<number>): Promise<boolean>␊
1037
+ ␊
1038
+ /** napi = { version = 2, features = ["serde-json"] } */␊
1039
+ export function readFile(callback: (arg0: Error | undefined, arg1?: string | undefined | null) => void): void␊
1040
+ ␊
1041
+ export function readFileAsync(path: string): Promise<Buffer>␊
1042
+ ␊
1043
+ export function readPackageJson(): PackageJson␊
1044
+ ␊
1045
+ export function receiveAllOptionalObject(obj?: AllOptionalObject | undefined | null): void␊
1046
+ ␊
1047
+ export function receiveClassOrNumber(either: number | JsClassForEither): number␊
1048
+ ␊
1049
+ export function receiveDifferentClass(either: JsClassForEither | AnotherClassForEither): number␊
1050
+ ␊
1051
+ export function receiveMutClassOrNumber(either: number | JsClassForEither): number␊
1052
+ ␊
1053
+ export function receiveObjectOnlyFromJs(obj: { count: number, callback: (err: Error | null, count: number) => void }): void␊
1054
+ ␊
1055
+ export function receiveObjectWithClassField(object: ObjectFieldClassInstance): Bird␊
1056
+ ␊
1057
+ export function receiveStrictObject(strictObject: StrictObject): void␊
1058
+ ␊
1059
+ export function receiveString(s: string): string␊
1060
+ ␊
1061
+ export function returnEither(input: number): string | number␊
1062
+ ␊
1063
+ export function returnEitherClass(input: number): number | JsClassForEither␊
1064
+ ␊
1065
+ export function returnJsFunction(): (...args: any[]) => any␊
1066
+ ␊
1067
+ export function returnNull(): null␊
1068
+ ␊
1069
+ export function returnUndefined(): void␊
1070
+ ␊
1071
+ export function returnUndefinedIfInvalid(input: boolean): boolean␊
1072
+ ␊
1073
+ export function returnUndefinedIfInvalidPromise(input: Promise<boolean>): Promise<boolean>␊
1074
+ ␊
1075
+ export function roundtripStr(s: string): string␊
1076
+ ␊
1077
+ export function runScript(script: string): unknown␊
1078
+ ␊
1079
+ export function setSymbolInObj(symbol: symbol): object␊
1080
+ ␊
1081
+ export interface StrictObject {␊
1082
+ name: string␊
1083
+ }␊
1084
+ ␊
1085
+ export function sumMapping(nums: Record<string, number>): number␊
1086
+ ␊
1087
+ export function sumNums(nums: Array<number>): number␊
1088
+ ␊
1089
+ export function testSerdeRoundtrip(data: any): any␊
1090
+ ␊
1091
+ export function threadsafeFunctionClosureCapture(func: (...args: any[]) => any): void␊
1092
+ ␊
1093
+ export function threadsafeFunctionFatalMode(cb: (...args: any[]) => any): void␊
1094
+ ␊
1095
+ export function threadsafeFunctionFatalModeError(cb: (...args: any[]) => any): void␊
1096
+ ␊
1097
+ export function threadsafeFunctionThrowError(cb: (...args: any[]) => any): void␊
1098
+ ␊
1099
+ export function throwError(): void␊
1100
+ ␊
1101
+ export function toJsObj(): object␊
1102
+ ␊
1103
+ export function tsfnAsyncCall(func: (...args: any[]) => any): Promise<void>␊
1104
+ ␊
1105
+ export function tsfnCallWithCallback(func: (...args: any[]) => any): void␊
1106
+ ␊
1107
+ export function tsRename(a: { foo: number }): string[]␊
1108
+ ␊
1109
+ export interface TsTypeChanged {␊
1110
+ typeOverride: object␊
1111
+ typeOverrideOptional?: object␊
1112
+ }␊
1113
+ ␊
1114
+ export function validateArray(arr: Array<number>): number␊
1115
+ ␊
1116
+ export function validateBigint(input: bigint): bigint␊
1117
+ ␊
1118
+ export function validateBoolean(i: boolean): boolean␊
1119
+ ␊
1120
+ export function validateBuffer(b: Buffer): number␊
1121
+ ␊
1122
+ export function validateDate(d: Date): number␊
1123
+ ␊
1124
+ export function validateDateTime(d: Date): number␊
1125
+ ␊
1126
+ export function validateExternal(e: ExternalObject<number>): number␊
1127
+ ␊
1128
+ export function validateFunction(cb: () => number): number␊
1129
+ ␊
1130
+ export function validateHashMap(input: Record<string, number>): number␊
1131
+ ␊
1132
+ export function validateNull(i: null): boolean␊
1133
+ ␊
1134
+ export function validateNumber(i: number): number␊
1135
+ ␊
1136
+ export function validateOptional(input1?: string | undefined | null, input2?: boolean | undefined | null): boolean␊
1137
+ ␊
1138
+ export function validatePromise(p: Promise<number>): Promise<number>␊
1139
+ ␊
1140
+ export function validateString(s: string): string␊
1141
+ ␊
1142
+ export function validateSymbol(s: symbol): boolean␊
1143
+ ␊
1144
+ export function validateTypedArray(input: Uint8Array): number␊
1145
+ ␊
1146
+ export function validateUndefined(i: undefined): boolean␊
1147
+ ␊
1148
+ export function withAbortController(a: number, b: number, signal: AbortSignal): Promise<number>␊
1149
+ ␊
1150
+ export function withoutAbortController(a: number, b: number): Promise<number>␊
1151
+ ␊
1152
+ export function xxh64Alias(input: Buffer): bigint␊
1153
+ ␊
1154
+ export namespace xxh2 {␊
1155
+ export function xxh2Plus(a: number, b: number): number␊
1156
+ export function xxh3Xxh64Alias(input: Buffer): bigint␊
1157
+ }␊
1158
+ ␊
1159
+ export namespace xxh3 {␊
1160
+ /** Xxh3 class */␊
1161
+ export class Xxh3 {␊
1162
+ constructor()␊
1163
+ /** update */␊
1164
+ update(input: Buffer): void␊
1165
+ digest(): bigint␊
1166
+ }␊
1167
+ export const ALIGNMENT: number␊
1168
+ /** xxh128 function */␊
1169
+ export function xxh128(input: Buffer): bigint␊
1170
+ export function xxh3_64(input: Buffer): bigint␊
1171
+ }␊
1172
+ ␊
1173
+ `
@@ -9,12 +9,13 @@ Generated by [AVA](https://avajs.dev).
9
9
  > Snapshot 1
10
10
 
11
11
  [
12
- '>= 8.6.0',
13
- '>= 8.10.0 && < 9 || >= 9.3.0',
14
- '>= 6.14.2 && < 7 || >= 8.11.2 && < 9 || >= 9.11.0',
15
- '>= 10.16.0 && < 11 || >= 11.8.0',
16
- '>= 10.17.0 && < 11 || >= 12.11.0',
17
- '>= 10.20.0 && < 11 || >= 12.17.0 && < 13 || >= 14.0.0',
18
- '>= 10.23.0 && < 11 || >= 12.19.0 && < 13 || >= 14.12.0',
19
- '>= 12.22.0 && < 13 || >= 14.17.0 && < 15 || >= 15.12.0',
12
+ '>= 8.6.0 < 9 || >= 9.0.0 < 10 || >= 10.0.0',
13
+ '>= 8.10.0 < 9 || >= 9.3.0 < 10 || >= 10.0.0',
14
+ '>= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0 < 10 || >= 10.0.0',
15
+ '>= 10.16.0 < 11 || >= 11.8.0 < 12 || >= 12.0.0',
16
+ '>= 10.17.0 < 11 || >= 12.11.0 < 13 || >= 13.0.0',
17
+ '>= 10.20.0 < 11 || >= 12.17.0 < 13 || >= 14.0.0',
18
+ '>= 10.23.0 < 11 || >= 12.19.0 < 13 || >= 14.12.0 < 15 || >= 15.0.0',
19
+ '>= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0',
20
+ '>= 18.17.0 < 19 || >= 20.3.0 < 21 || >= 21.1.0',
20
21
  ]
@@ -0,0 +1,81 @@
1
+ import { unlink, writeFile } from 'node:fs/promises'
2
+ import { tmpdir } from 'node:os'
3
+ import { join } from 'node:path'
4
+
5
+ import ava, { TestFn } from 'ava'
6
+
7
+ import {
8
+ CommonPackageJsonFields,
9
+ UserNapiConfig,
10
+ readNapiConfig,
11
+ } from '../config.js'
12
+
13
+ const NON_EXISTENT_FILE = 'non-existent-file'
14
+
15
+ const test = ava as TestFn<{
16
+ configPath: string
17
+ packageJson: string
18
+ pkgJson: CommonPackageJsonFields
19
+ config: UserNapiConfig
20
+ }>
21
+
22
+ test.before(async (t) => {
23
+ const tmp = tmpdir()
24
+ const configPath = join(tmp, 'napi.json')
25
+ const packageJson = join(tmp, 'package.json')
26
+ const pkgJson = {
27
+ name: '@napi-rs/testing',
28
+ version: '0.0.0',
29
+ napi: {
30
+ binaryName: 'testing',
31
+ packageName: '@napi-rs/testing',
32
+ targets: [
33
+ 'x86_64-unknown-linux-gnu',
34
+ 'x86_64-pc-windows-msvc',
35
+ 'x86_64-apple-darwin',
36
+ ],
37
+ },
38
+ }
39
+ await writeFile(packageJson, JSON.stringify(pkgJson, null, 2))
40
+ const config = {
41
+ binaryName: 'testing',
42
+ packageName: '@node-rs/testing',
43
+ targets: [
44
+ 'x86_64-unknown-linux-gnu',
45
+ 'x86_64-apple-darwin',
46
+ 'aarch64-apple-darwin',
47
+ ],
48
+ }
49
+ await writeFile(configPath, JSON.stringify(config, null, 2))
50
+ t.context = { configPath, config, packageJson, pkgJson }
51
+ })
52
+
53
+ test.after(async (t) => {
54
+ await unlink(t.context.configPath)
55
+ await unlink(t.context.packageJson)
56
+ })
57
+
58
+ test('should throw if package.json not found', async (t) => {
59
+ await t.throwsAsync(() => readNapiConfig(NON_EXISTENT_FILE), {
60
+ message: `package.json not found at ${NON_EXISTENT_FILE}`,
61
+ })
62
+ })
63
+
64
+ test('should throw if napi.json not found', async (t) => {
65
+ const { packageJson } = t.context
66
+ await t.throwsAsync(() => readNapiConfig(packageJson, NON_EXISTENT_FILE), {
67
+ message: `NAPI-RS config not found at ${NON_EXISTENT_FILE}`,
68
+ })
69
+ })
70
+
71
+ test('should be able to read config from package.json', async (t) => {
72
+ const { packageJson } = t.context
73
+ const config = await readNapiConfig(packageJson)
74
+ t.snapshot(config)
75
+ })
76
+
77
+ test('should be able to read config from napi.json', async (t) => {
78
+ const { packageJson, configPath } = t.context
79
+ const config = await readNapiConfig(packageJson, configPath)
80
+ t.snapshot(config)
81
+ })