relaxnative 0.1.0-beta.1

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 (130) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +592 -0
  3. package/dist/chunk-22W76CYR.js +607 -0
  4. package/dist/chunk-24NXCU65.js +254 -0
  5. package/dist/chunk-2APMRURB.js +65 -0
  6. package/dist/chunk-2CHBHJPT.js +607 -0
  7. package/dist/chunk-2I4JHZI7.js +287 -0
  8. package/dist/chunk-2JOHYYQO.js +607 -0
  9. package/dist/chunk-3GW77EWF.js +505 -0
  10. package/dist/chunk-5J5CAKCD.js +266 -0
  11. package/dist/chunk-5NTDZ7YZ.js +377 -0
  12. package/dist/chunk-5TA6MROS.js +529 -0
  13. package/dist/chunk-5WVEBKMJ.js +1019 -0
  14. package/dist/chunk-6O5TIEEI.js +545 -0
  15. package/dist/chunk-6XU5DETO.js +896 -0
  16. package/dist/chunk-7BIZ6P3B.js +176 -0
  17. package/dist/chunk-7DKO777J.js +285 -0
  18. package/dist/chunk-7JYWUH4Y.js +268 -0
  19. package/dist/chunk-7NMCEP2V.js +756 -0
  20. package/dist/chunk-A7N4YBP2.js +379 -0
  21. package/dist/chunk-AZTCDV6R.js +572 -0
  22. package/dist/chunk-B34XEGM6.js +559 -0
  23. package/dist/chunk-BFHBLVXW.js +607 -0
  24. package/dist/chunk-BLOJ33LO.js +65 -0
  25. package/dist/chunk-BYPXCWTI.js +375 -0
  26. package/dist/chunk-C4KJD2AN.js +1044 -0
  27. package/dist/chunk-CJALJTRQ.js +814 -0
  28. package/dist/chunk-D4PK367Z.js +627 -0
  29. package/dist/chunk-DCWBZPEV.js +287 -0
  30. package/dist/chunk-DI7KSUEC.js +676 -0
  31. package/dist/chunk-DQ2KXIOO.js +665 -0
  32. package/dist/chunk-DV5STE3W.js +986 -0
  33. package/dist/chunk-EG5KNEKP.js +1027 -0
  34. package/dist/chunk-EOA2OWFA.js +1020 -0
  35. package/dist/chunk-ES3B6EZJ.js +56 -0
  36. package/dist/chunk-ETIXNPU5.js +741 -0
  37. package/dist/chunk-EUZBU2H7.js +824 -0
  38. package/dist/chunk-F6V7XDEB.js +150 -0
  39. package/dist/chunk-FNJKUFNF.js +1019 -0
  40. package/dist/chunk-FZB37DWL.js +453 -0
  41. package/dist/chunk-G3NDHZNZ.js +453 -0
  42. package/dist/chunk-G4YR34LE.js +410 -0
  43. package/dist/chunk-GU4XXISM.js +264 -0
  44. package/dist/chunk-GVPSQXGJ.js +1027 -0
  45. package/dist/chunk-HD5C4RNU.js +676 -0
  46. package/dist/chunk-HDIVY47T.js +287 -0
  47. package/dist/chunk-HFLRTDNK.js +985 -0
  48. package/dist/chunk-HGWRCVQ5.js +287 -0
  49. package/dist/chunk-HRG3SVKK.js +995 -0
  50. package/dist/chunk-HUGFULJ3.js +1027 -0
  51. package/dist/chunk-IDYSBXYS.js +344 -0
  52. package/dist/chunk-ISDDUQVI.js +1019 -0
  53. package/dist/chunk-IZ632ZCJ.js +286 -0
  54. package/dist/chunk-J5XI4L52.js +218 -0
  55. package/dist/chunk-JTIO7BUH.js +582 -0
  56. package/dist/chunk-JTWSFMF2.js +1020 -0
  57. package/dist/chunk-K5TV62T4.js +736 -0
  58. package/dist/chunk-K7MTG53V.js +985 -0
  59. package/dist/chunk-KGLZB3H2.js +676 -0
  60. package/dist/chunk-KYAB35P5.js +741 -0
  61. package/dist/chunk-KYDW3YVX.js +453 -0
  62. package/dist/chunk-L3MEMPRH.js +361 -0
  63. package/dist/chunk-LFTO3Z7N.js +757 -0
  64. package/dist/chunk-LLZ4I4OR.js +405 -0
  65. package/dist/chunk-LMRUM4U4.js +207 -0
  66. package/dist/chunk-LT5OGU6T.js +559 -0
  67. package/dist/chunk-LZQQOC3M.js +741 -0
  68. package/dist/chunk-LZYUNF6Q.js +1017 -0
  69. package/dist/chunk-MCTPVW4G.js +453 -0
  70. package/dist/chunk-MGLWXBIB.js +65 -0
  71. package/dist/chunk-MLKGABMK.js +9 -0
  72. package/dist/chunk-MTE6XDGC.js +541 -0
  73. package/dist/chunk-NDJUNDAE.js +676 -0
  74. package/dist/chunk-NG7SNFUD.js +1027 -0
  75. package/dist/chunk-ONVWKYK7.js +739 -0
  76. package/dist/chunk-OVMTFGE7.js +1042 -0
  77. package/dist/chunk-P5RQPRJ4.js +741 -0
  78. package/dist/chunk-PFABSW6Y.js +401 -0
  79. package/dist/chunk-PVVUJA2M.js +65 -0
  80. package/dist/chunk-Q3CDTGTX.js +676 -0
  81. package/dist/chunk-QKAKWDOQ.js +967 -0
  82. package/dist/chunk-QMPRDU6I.js +598 -0
  83. package/dist/chunk-R5U7XKVJ.js +16 -0
  84. package/dist/chunk-RB6RHB6C.js +254 -0
  85. package/dist/chunk-RD2K7ODW.js +175 -0
  86. package/dist/chunk-RHBHJND2.js +582 -0
  87. package/dist/chunk-RUP6POSE.js +453 -0
  88. package/dist/chunk-RYNSM23L.js +582 -0
  89. package/dist/chunk-S72S7XXS.js +255 -0
  90. package/dist/chunk-SDV5AAPW.js +213 -0
  91. package/dist/chunk-STXQPXUY.js +242 -0
  92. package/dist/chunk-TUSF5AEG.js +140 -0
  93. package/dist/chunk-V74SNTE6.js +736 -0
  94. package/dist/chunk-VHM5XETC.js +453 -0
  95. package/dist/chunk-VKQIXLNL.js +273 -0
  96. package/dist/chunk-VPG23Z7Y.js +545 -0
  97. package/dist/chunk-VSP234PR.js +627 -0
  98. package/dist/chunk-WH4JPUWF.js +598 -0
  99. package/dist/chunk-WLAUJL3K.js +409 -0
  100. package/dist/chunk-WXCN2QJ7.js +350 -0
  101. package/dist/chunk-X3JZKLJC.js +896 -0
  102. package/dist/chunk-X7SAP7FC.js +582 -0
  103. package/dist/chunk-XEH6PRYE.js +968 -0
  104. package/dist/chunk-XI65CAQV.js +211 -0
  105. package/dist/chunk-Y7OSHR6W.js +235 -0
  106. package/dist/chunk-YN4WUMVD.js +1020 -0
  107. package/dist/chunk-YUWJ2C4Y.js +1020 -0
  108. package/dist/chunk-YXLBPWNU.js +263 -0
  109. package/dist/chunk-YYJJHO7R.js +407 -0
  110. package/dist/chunk-Z2RBHUIH.js +757 -0
  111. package/dist/chunk-Z6G3KIOM.js +1027 -0
  112. package/dist/chunk-ZPPXCDSH.js +361 -0
  113. package/dist/chunk-ZRTY24SZ.js +582 -0
  114. package/dist/chunk-ZSDFBCQG.js +741 -0
  115. package/dist/cli.d.ts +1 -0
  116. package/dist/cli.js +339 -0
  117. package/dist/esmLoader.d.ts +10 -0
  118. package/dist/esmLoader.js +112 -0
  119. package/dist/index.d.ts +407 -0
  120. package/dist/index.js +126 -0
  121. package/dist/memory/memory.selftest.d.ts +2 -0
  122. package/dist/memory/memory.selftest.js +25 -0
  123. package/dist/worker/processEntry.d.ts +2 -0
  124. package/dist/worker/processEntry.js +160 -0
  125. package/dist/worker/workerEntry.d.ts +2 -0
  126. package/dist/worker/workerEntry.js +27 -0
  127. package/native/examples/add.c +6 -0
  128. package/native/examples/add_test.c +23 -0
  129. package/native/relaxnative_test.h +36 -0
  130. package/package.json +81 -0
@@ -0,0 +1,150 @@
1
+ // src/registry/registryPaths.ts
2
+ import { join, resolve } from "path";
3
+ function getProjectRoot(cwd = process.cwd()) {
4
+ return cwd;
5
+ }
6
+ function getRegistryRoot(projectRoot = getProjectRoot()) {
7
+ return join(projectRoot, "native", "registry");
8
+ }
9
+ function getInstalledPackageDir(pkg, projectRoot = getProjectRoot()) {
10
+ return join(getRegistryRoot(projectRoot), pkg);
11
+ }
12
+ function resolveRegistryImport(specifier, projectRoot = getProjectRoot()) {
13
+ const prefix = "relaxnative/";
14
+ if (!specifier.startsWith(prefix)) return null;
15
+ const pkg = specifier.slice(prefix.length);
16
+ return resolve(getInstalledPackageDir(pkg, projectRoot));
17
+ }
18
+
19
+ // src/registry/relaxJson.ts
20
+ import { readFileSync } from "fs";
21
+ import { join as join2 } from "path";
22
+ function readRelaxJson(pkgDir) {
23
+ const jsonPath = join2(pkgDir, "relax.json");
24
+ const raw = readFileSync(jsonPath, "utf8");
25
+ const parsed = JSON.parse(raw);
26
+ if (!parsed?.name || !parsed?.version || !Array.isArray(parsed?.exports)) {
27
+ throw new Error(`Invalid relax.json at ${jsonPath}`);
28
+ }
29
+ return parsed;
30
+ }
31
+
32
+ // src/registry/installer.ts
33
+ import {
34
+ mkdirSync,
35
+ readFileSync as readFileSync3,
36
+ rmSync,
37
+ writeFileSync,
38
+ existsSync,
39
+ readdirSync
40
+ } from "fs";
41
+ import { join as join3 } from "path";
42
+
43
+ // src/registry/staticScan.ts
44
+ import { readFileSync as readFileSync2 } from "fs";
45
+ function staticScanNativeSource(sourcePath) {
46
+ const src = readFileSync2(sourcePath, "utf8");
47
+ const lines = src.split(/\r?\n/);
48
+ const rules = [
49
+ {
50
+ rule: "process-spawn",
51
+ re: /\b(system|popen|fork|execv|execve|execvp|execvpe|execl|execlp|CreateProcessW|WinExec)\b/,
52
+ message: "Potential process execution API found"
53
+ },
54
+ {
55
+ rule: "raw-syscall",
56
+ re: /\b(syscall|__syscall)\b/,
57
+ message: "Raw syscall usage found"
58
+ },
59
+ {
60
+ rule: "file-io",
61
+ re: /\b(fopen|open|CreateFileW|unlink|remove|rename)\b/,
62
+ message: "Potential filesystem API found"
63
+ },
64
+ {
65
+ rule: "network",
66
+ re: /\b(socket|connect|bind|listen|accept|recv|send|getaddrinfo)\b/,
67
+ message: "Potential network API found"
68
+ },
69
+ {
70
+ rule: "w-x-memory",
71
+ re: /\b(mprotect|VirtualProtect|PROT_EXEC|PAGE_EXECUTE_READWRITE)\b/,
72
+ message: "Writable/executable memory pattern found"
73
+ },
74
+ {
75
+ rule: "dynamic-loader",
76
+ re: /\b(dlopen|LoadLibraryA|LoadLibraryW)\b/,
77
+ message: "Dynamic loader API found"
78
+ }
79
+ ];
80
+ const findings = [];
81
+ for (let i = 0; i < lines.length; i++) {
82
+ const line = lines[i];
83
+ for (const r of rules) {
84
+ if (r.re.test(line)) {
85
+ findings.push({ rule: r.rule, message: r.message, line: i + 1 });
86
+ }
87
+ }
88
+ }
89
+ return findings;
90
+ }
91
+
92
+ // src/registry/installer.ts
93
+ function installPackage(pkgSpecifier, projectRoot = process.cwd()) {
94
+ const warnings = [];
95
+ const registryRoot = getRegistryRoot(projectRoot);
96
+ mkdirSync(registryRoot, { recursive: true });
97
+ const isFile = pkgSpecifier.startsWith("file:");
98
+ if (!isFile) {
99
+ throw new Error(
100
+ `Only file: installs are supported right now (deterministic, offline). Got: ${pkgSpecifier}`
101
+ );
102
+ }
103
+ const srcDir = pkgSpecifier.slice("file:".length);
104
+ const manifest = readRelaxJson(srcDir);
105
+ const destDir = getInstalledPackageDir(manifest.name, projectRoot);
106
+ rmSync(destDir, { recursive: true, force: true });
107
+ mkdirSync(destDir, { recursive: true });
108
+ writeFileSync(join3(destDir, "relax.json"), readFileSync3(join3(srcDir, "relax.json")));
109
+ for (const exp of manifest.exports) {
110
+ const srcPath = join3(srcDir, exp.source);
111
+ const dstPath = join3(destDir, exp.source);
112
+ mkdirSync(join3(dstPath, ".."), { recursive: true });
113
+ if (!existsSync(srcPath)) {
114
+ throw new Error(`Missing export source: ${srcPath}`);
115
+ }
116
+ const findings = staticScanNativeSource(srcPath);
117
+ for (const f of findings) {
118
+ warnings.push(`${exp.source}:${f.line ?? "?"} ${f.rule}: ${f.message}`);
119
+ }
120
+ writeFileSync(dstPath, readFileSync3(srcPath));
121
+ }
122
+ return { pkg: manifest.name, dir: destDir, warnings };
123
+ }
124
+ function removePackage(pkg, projectRoot = process.cwd()) {
125
+ const destDir = getInstalledPackageDir(pkg, projectRoot);
126
+ rmSync(destDir, { recursive: true, force: true });
127
+ }
128
+ function listPackages(projectRoot = process.cwd()) {
129
+ const root = getRegistryRoot(projectRoot);
130
+ if (!existsSync(root)) return [];
131
+ return readdirSync(root, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
132
+ }
133
+ function updateIndex(projectRoot = process.cwd()) {
134
+ const root = getRegistryRoot(projectRoot);
135
+ if (!existsSync(root)) return;
136
+ const pkgs = listPackages(projectRoot);
137
+ writeFileSync(join3(root, ".index"), pkgs.join("\n") + (pkgs.length ? "\n" : ""));
138
+ }
139
+
140
+ export {
141
+ getProjectRoot,
142
+ getRegistryRoot,
143
+ getInstalledPackageDir,
144
+ resolveRegistryImport,
145
+ readRelaxJson,
146
+ installPackage,
147
+ removePackage,
148
+ listPackages,
149
+ updateIndex
150
+ };