@qpqjs/user-script 0.0.0-stage → 0.2.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.
Files changed (260) hide show
  1. package/README.md +9 -2
  2. package/lib/commonjs/actionProcessor/getUserScriptBuildActionProcessor.d.ts +1 -0
  3. package/lib/commonjs/actionProcessor/getUserScriptBuildActionProcessor.js +69 -0
  4. package/lib/commonjs/actionProcessor/getUserScriptBuildActionProcessor.js.map +1 -0
  5. package/lib/commonjs/actionProcessor/getUserScriptBuildActionProcessors.d.ts +3 -0
  6. package/lib/commonjs/actionProcessor/getUserScriptBuildActionProcessors.js +20 -0
  7. package/lib/commonjs/actionProcessor/getUserScriptBuildActionProcessors.js.map +1 -0
  8. package/lib/commonjs/actionProcessor/getUserScriptBuildFromZipActionProcessor.d.ts +1 -0
  9. package/lib/commonjs/actionProcessor/getUserScriptBuildFromZipActionProcessor.js +79 -0
  10. package/lib/commonjs/actionProcessor/getUserScriptBuildFromZipActionProcessor.js.map +1 -0
  11. package/lib/commonjs/actionProcessor/index.d.ts +4 -0
  12. package/lib/commonjs/actionProcessor/index.js +21 -0
  13. package/lib/commonjs/actionProcessor/index.js.map +1 -0
  14. package/lib/commonjs/actionProcessor/logic/BuiltUserScript.d.ts +4 -0
  15. package/lib/commonjs/actionProcessor/logic/BuiltUserScript.js +3 -0
  16. package/lib/commonjs/actionProcessor/logic/BuiltUserScript.js.map +1 -0
  17. package/lib/commonjs/actionProcessor/logic/USER_SCRIPT_SOURCE_LIMITS.d.ts +5 -0
  18. package/lib/commonjs/actionProcessor/logic/USER_SCRIPT_SOURCE_LIMITS.js +9 -0
  19. package/lib/commonjs/actionProcessor/logic/USER_SCRIPT_SOURCE_LIMITS.js.map +1 -0
  20. package/lib/commonjs/actionProcessor/logic/UserScriptArchiveError.d.ts +10 -0
  21. package/lib/commonjs/actionProcessor/logic/UserScriptArchiveError.js +22 -0
  22. package/lib/commonjs/actionProcessor/logic/UserScriptArchiveError.js.map +1 -0
  23. package/lib/commonjs/actionProcessor/logic/UserScriptSourceFile.d.ts +5 -0
  24. package/lib/commonjs/actionProcessor/logic/UserScriptSourceFile.js +3 -0
  25. package/lib/commonjs/actionProcessor/logic/UserScriptSourceFile.js.map +1 -0
  26. package/lib/commonjs/actionProcessor/logic/askUserScriptCheckPublishedOutput.d.ts +8 -0
  27. package/lib/commonjs/actionProcessor/logic/askUserScriptCheckPublishedOutput.js +30 -0
  28. package/lib/commonjs/actionProcessor/logic/askUserScriptCheckPublishedOutput.js.map +1 -0
  29. package/lib/commonjs/actionProcessor/logic/askUserScriptCollectSource.d.ts +9 -0
  30. package/lib/commonjs/actionProcessor/logic/askUserScriptCollectSource.js +53 -0
  31. package/lib/commonjs/actionProcessor/logic/askUserScriptCollectSource.js.map +1 -0
  32. package/lib/commonjs/actionProcessor/logic/askUserScriptPublishOutput.d.ts +3 -0
  33. package/lib/commonjs/actionProcessor/logic/askUserScriptPublishOutput.js +9 -0
  34. package/lib/commonjs/actionProcessor/logic/askUserScriptPublishOutput.js.map +1 -0
  35. package/lib/commonjs/actionProcessor/logic/buildUserScriptInTempDir.d.ts +9 -0
  36. package/lib/commonjs/actionProcessor/logic/buildUserScriptInTempDir.js +41 -0
  37. package/lib/commonjs/actionProcessor/logic/buildUserScriptInTempDir.js.map +1 -0
  38. package/lib/commonjs/actionProcessor/logic/extractUserScriptZip.d.ts +8 -0
  39. package/lib/commonjs/actionProcessor/logic/extractUserScriptZip.js +148 -0
  40. package/lib/commonjs/actionProcessor/logic/extractUserScriptZip.js.map +1 -0
  41. package/lib/commonjs/actionProcessor/logic/getUserScriptBuildErrorType.d.ts +7 -0
  42. package/lib/commonjs/actionProcessor/logic/getUserScriptBuildErrorType.js +20 -0
  43. package/lib/commonjs/actionProcessor/logic/getUserScriptBuildErrorType.js.map +1 -0
  44. package/lib/commonjs/actionProcessor/logic/index.d.ts +12 -0
  45. package/lib/commonjs/actionProcessor/logic/index.js +29 -0
  46. package/lib/commonjs/actionProcessor/logic/index.js.map +1 -0
  47. package/lib/commonjs/actionProcessor/logic/isSafeProjectPath.d.ts +5 -0
  48. package/lib/commonjs/actionProcessor/logic/isSafeProjectPath.js +13 -0
  49. package/lib/commonjs/actionProcessor/logic/isSafeProjectPath.js.map +1 -0
  50. package/lib/commonjs/actionProcessor/logic/materialiseUserScriptSource.d.ts +3 -0
  51. package/lib/commonjs/actionProcessor/logic/materialiseUserScriptSource.js +23 -0
  52. package/lib/commonjs/actionProcessor/logic/materialiseUserScriptSource.js.map +1 -0
  53. package/lib/commonjs/build/USER_SCRIPT_ENTRY_CANDIDATES.d.ts +2 -0
  54. package/lib/commonjs/build/USER_SCRIPT_ENTRY_CANDIDATES.js +6 -0
  55. package/lib/commonjs/build/USER_SCRIPT_ENTRY_CANDIDATES.js.map +1 -0
  56. package/lib/commonjs/build/USER_SCRIPT_OUTPUT_FILENAME.d.ts +2 -0
  57. package/lib/commonjs/build/USER_SCRIPT_OUTPUT_FILENAME.js +6 -0
  58. package/lib/commonjs/build/USER_SCRIPT_OUTPUT_FILENAME.js.map +1 -0
  59. package/lib/commonjs/build/UserScriptBuildError.d.ts +12 -0
  60. package/lib/commonjs/build/UserScriptBuildError.js +26 -0
  61. package/lib/commonjs/build/UserScriptBuildError.js.map +1 -0
  62. package/lib/commonjs/build/UserScriptBuildResult.d.ts +4 -0
  63. package/lib/commonjs/build/UserScriptBuildResult.js +3 -0
  64. package/lib/commonjs/build/UserScriptBuildResult.js.map +1 -0
  65. package/lib/commonjs/build/__fixtures__/basic/src/helpers/formatSum.d.ts +1 -0
  66. package/lib/commonjs/build/__fixtures__/basic/src/helpers/formatSum.js +6 -0
  67. package/lib/commonjs/build/__fixtures__/basic/src/helpers/formatSum.js.map +1 -0
  68. package/lib/commonjs/build/__fixtures__/basic/src/main.d.ts +4 -0
  69. package/lib/commonjs/build/__fixtures__/basic/src/main.js +17 -0
  70. package/lib/commonjs/build/__fixtures__/basic/src/main.js.map +1 -0
  71. package/lib/commonjs/build/__fixtures__/builtin/src/main.d.ts +1 -0
  72. package/lib/commonjs/build/__fixtures__/builtin/src/main.js +7 -0
  73. package/lib/commonjs/build/__fixtures__/builtin/src/main.js.map +1 -0
  74. package/lib/commonjs/build/__fixtures__/noEntry/src/notMain.d.ts +1 -0
  75. package/lib/commonjs/build/__fixtures__/noEntry/src/notMain.js +6 -0
  76. package/lib/commonjs/build/__fixtures__/noEntry/src/notMain.js.map +1 -0
  77. package/lib/commonjs/build/__fixtures__/nonFunction/src/main.d.ts +2 -0
  78. package/lib/commonjs/build/__fixtures__/nonFunction/src/main.js +7 -0
  79. package/lib/commonjs/build/__fixtures__/nonFunction/src/main.js.map +1 -0
  80. package/lib/commonjs/build/assertUserScriptExports.d.ts +6 -0
  81. package/lib/commonjs/build/assertUserScriptExports.js +20 -0
  82. package/lib/commonjs/build/assertUserScriptExports.js.map +1 -0
  83. package/lib/commonjs/build/buildUserScript.d.ts +15 -0
  84. package/lib/commonjs/build/buildUserScript.js +55 -0
  85. package/lib/commonjs/build/buildUserScript.js.map +1 -0
  86. package/lib/commonjs/build/checkUserScriptOutput.d.ts +7 -0
  87. package/lib/commonjs/build/checkUserScriptOutput.js +17 -0
  88. package/lib/commonjs/build/checkUserScriptOutput.js.map +1 -0
  89. package/lib/commonjs/build/createUserScriptExternals.d.ts +11 -0
  90. package/lib/commonjs/build/createUserScriptExternals.js +34 -0
  91. package/lib/commonjs/build/createUserScriptExternals.js.map +1 -0
  92. package/lib/commonjs/build/getUserScriptRspackConfig.d.ts +15 -0
  93. package/lib/commonjs/build/getUserScriptRspackConfig.js +49 -0
  94. package/lib/commonjs/build/getUserScriptRspackConfig.js.map +1 -0
  95. package/lib/commonjs/build/index.d.ts +13 -0
  96. package/lib/commonjs/build/index.js +30 -0
  97. package/lib/commonjs/build/index.js.map +1 -0
  98. package/lib/commonjs/build/loadRspackModule.d.ts +8 -0
  99. package/lib/commonjs/build/loadRspackModule.js +51 -0
  100. package/lib/commonjs/build/loadRspackModule.js.map +1 -0
  101. package/lib/commonjs/build/resolveUserScriptEntry.d.ts +2 -0
  102. package/lib/commonjs/build/resolveUserScriptEntry.js +20 -0
  103. package/lib/commonjs/build/resolveUserScriptEntry.js.map +1 -0
  104. package/lib/commonjs/build/runUserScriptRspack.d.ts +7 -0
  105. package/lib/commonjs/build/runUserScriptRspack.js +32 -0
  106. package/lib/commonjs/build/runUserScriptRspack.js.map +1 -0
  107. package/lib/commonjs/build/userScriptTsRule.d.ts +6 -0
  108. package/lib/commonjs/build/userScriptTsRule.js +21 -0
  109. package/lib/commonjs/build/userScriptTsRule.js.map +1 -0
  110. package/lib/commonjs/config/USER_SCRIPT_BUILDER_LAYER_MODULES.d.ts +5 -0
  111. package/lib/commonjs/config/USER_SCRIPT_BUILDER_LAYER_MODULES.js +9 -0
  112. package/lib/commonjs/config/USER_SCRIPT_BUILDER_LAYER_MODULES.js.map +1 -0
  113. package/lib/commonjs/config/USER_SCRIPT_BUILDER_LAYER_NAME.d.ts +2 -0
  114. package/lib/commonjs/config/USER_SCRIPT_BUILDER_LAYER_NAME.js +6 -0
  115. package/lib/commonjs/config/USER_SCRIPT_BUILDER_LAYER_NAME.js.map +1 -0
  116. package/lib/commonjs/config/defineUserScriptBuilder.d.ts +7 -0
  117. package/lib/commonjs/config/defineUserScriptBuilder.js +16 -0
  118. package/lib/commonjs/config/defineUserScriptBuilder.js.map +1 -0
  119. package/lib/commonjs/config/getUserScriptBuilderApiLayer.d.ts +7 -0
  120. package/lib/commonjs/config/getUserScriptBuilderApiLayer.js +18 -0
  121. package/lib/commonjs/config/getUserScriptBuilderApiLayer.js.map +1 -0
  122. package/lib/commonjs/config/getUserScriptBuilderLayerDir.d.ts +6 -0
  123. package/lib/commonjs/config/getUserScriptBuilderLayerDir.js +33 -0
  124. package/lib/commonjs/config/getUserScriptBuilderLayerDir.js.map +1 -0
  125. package/lib/commonjs/config/index.d.ts +5 -0
  126. package/lib/commonjs/config/index.js +22 -0
  127. package/lib/commonjs/config/index.js.map +1 -0
  128. package/lib/commonjs/index.d.ts +3 -0
  129. package/lib/commonjs/index.js +20 -0
  130. package/lib/commonjs/index.js.map +1 -0
  131. package/lib/esm/actionProcessor/getUserScriptBuildActionProcessor.d.ts +1 -0
  132. package/lib/esm/actionProcessor/getUserScriptBuildActionProcessor.js +56 -0
  133. package/lib/esm/actionProcessor/getUserScriptBuildActionProcessor.js.map +1 -0
  134. package/lib/esm/actionProcessor/getUserScriptBuildActionProcessors.d.ts +3 -0
  135. package/lib/esm/actionProcessor/getUserScriptBuildActionProcessors.js +8 -0
  136. package/lib/esm/actionProcessor/getUserScriptBuildActionProcessors.js.map +1 -0
  137. package/lib/esm/actionProcessor/getUserScriptBuildFromZipActionProcessor.d.ts +1 -0
  138. package/lib/esm/actionProcessor/getUserScriptBuildFromZipActionProcessor.js +66 -0
  139. package/lib/esm/actionProcessor/getUserScriptBuildFromZipActionProcessor.js.map +1 -0
  140. package/lib/esm/actionProcessor/index.d.ts +4 -0
  141. package/lib/esm/actionProcessor/index.js +5 -0
  142. package/lib/esm/actionProcessor/index.js.map +1 -0
  143. package/lib/esm/actionProcessor/logic/BuiltUserScript.d.ts +4 -0
  144. package/lib/esm/actionProcessor/logic/BuiltUserScript.js +2 -0
  145. package/lib/esm/actionProcessor/logic/BuiltUserScript.js.map +1 -0
  146. package/lib/esm/actionProcessor/logic/USER_SCRIPT_SOURCE_LIMITS.d.ts +5 -0
  147. package/lib/esm/actionProcessor/logic/USER_SCRIPT_SOURCE_LIMITS.js +6 -0
  148. package/lib/esm/actionProcessor/logic/USER_SCRIPT_SOURCE_LIMITS.js.map +1 -0
  149. package/lib/esm/actionProcessor/logic/UserScriptArchiveError.d.ts +10 -0
  150. package/lib/esm/actionProcessor/logic/UserScriptArchiveError.js +19 -0
  151. package/lib/esm/actionProcessor/logic/UserScriptArchiveError.js.map +1 -0
  152. package/lib/esm/actionProcessor/logic/UserScriptSourceFile.d.ts +5 -0
  153. package/lib/esm/actionProcessor/logic/UserScriptSourceFile.js +2 -0
  154. package/lib/esm/actionProcessor/logic/UserScriptSourceFile.js.map +1 -0
  155. package/lib/esm/actionProcessor/logic/askUserScriptCheckPublishedOutput.d.ts +8 -0
  156. package/lib/esm/actionProcessor/logic/askUserScriptCheckPublishedOutput.js +27 -0
  157. package/lib/esm/actionProcessor/logic/askUserScriptCheckPublishedOutput.js.map +1 -0
  158. package/lib/esm/actionProcessor/logic/askUserScriptCollectSource.d.ts +9 -0
  159. package/lib/esm/actionProcessor/logic/askUserScriptCollectSource.js +50 -0
  160. package/lib/esm/actionProcessor/logic/askUserScriptCollectSource.js.map +1 -0
  161. package/lib/esm/actionProcessor/logic/askUserScriptPublishOutput.d.ts +3 -0
  162. package/lib/esm/actionProcessor/logic/askUserScriptPublishOutput.js +6 -0
  163. package/lib/esm/actionProcessor/logic/askUserScriptPublishOutput.js.map +1 -0
  164. package/lib/esm/actionProcessor/logic/buildUserScriptInTempDir.d.ts +9 -0
  165. package/lib/esm/actionProcessor/logic/buildUserScriptInTempDir.js +25 -0
  166. package/lib/esm/actionProcessor/logic/buildUserScriptInTempDir.js.map +1 -0
  167. package/lib/esm/actionProcessor/logic/extractUserScriptZip.d.ts +8 -0
  168. package/lib/esm/actionProcessor/logic/extractUserScriptZip.js +132 -0
  169. package/lib/esm/actionProcessor/logic/extractUserScriptZip.js.map +1 -0
  170. package/lib/esm/actionProcessor/logic/getUserScriptBuildErrorType.d.ts +7 -0
  171. package/lib/esm/actionProcessor/logic/getUserScriptBuildErrorType.js +16 -0
  172. package/lib/esm/actionProcessor/logic/getUserScriptBuildErrorType.js.map +1 -0
  173. package/lib/esm/actionProcessor/logic/index.d.ts +12 -0
  174. package/lib/esm/actionProcessor/logic/index.js +13 -0
  175. package/lib/esm/actionProcessor/logic/index.js.map +1 -0
  176. package/lib/esm/actionProcessor/logic/isSafeProjectPath.d.ts +5 -0
  177. package/lib/esm/actionProcessor/logic/isSafeProjectPath.js +9 -0
  178. package/lib/esm/actionProcessor/logic/isSafeProjectPath.js.map +1 -0
  179. package/lib/esm/actionProcessor/logic/materialiseUserScriptSource.d.ts +3 -0
  180. package/lib/esm/actionProcessor/logic/materialiseUserScriptSource.js +16 -0
  181. package/lib/esm/actionProcessor/logic/materialiseUserScriptSource.js.map +1 -0
  182. package/lib/esm/build/USER_SCRIPT_ENTRY_CANDIDATES.d.ts +2 -0
  183. package/lib/esm/build/USER_SCRIPT_ENTRY_CANDIDATES.js +3 -0
  184. package/lib/esm/build/USER_SCRIPT_ENTRY_CANDIDATES.js.map +1 -0
  185. package/lib/esm/build/USER_SCRIPT_OUTPUT_FILENAME.d.ts +2 -0
  186. package/lib/esm/build/USER_SCRIPT_OUTPUT_FILENAME.js +3 -0
  187. package/lib/esm/build/USER_SCRIPT_OUTPUT_FILENAME.js.map +1 -0
  188. package/lib/esm/build/UserScriptBuildError.d.ts +12 -0
  189. package/lib/esm/build/UserScriptBuildError.js +23 -0
  190. package/lib/esm/build/UserScriptBuildError.js.map +1 -0
  191. package/lib/esm/build/UserScriptBuildResult.d.ts +4 -0
  192. package/lib/esm/build/UserScriptBuildResult.js +2 -0
  193. package/lib/esm/build/UserScriptBuildResult.js.map +1 -0
  194. package/lib/esm/build/__fixtures__/basic/src/helpers/formatSum.d.ts +1 -0
  195. package/lib/esm/build/__fixtures__/basic/src/helpers/formatSum.js +2 -0
  196. package/lib/esm/build/__fixtures__/basic/src/helpers/formatSum.js.map +1 -0
  197. package/lib/esm/build/__fixtures__/basic/src/main.d.ts +4 -0
  198. package/lib/esm/build/__fixtures__/basic/src/main.js +11 -0
  199. package/lib/esm/build/__fixtures__/basic/src/main.js.map +1 -0
  200. package/lib/esm/build/__fixtures__/builtin/src/main.d.ts +1 -0
  201. package/lib/esm/build/__fixtures__/builtin/src/main.js +3 -0
  202. package/lib/esm/build/__fixtures__/builtin/src/main.js.map +1 -0
  203. package/lib/esm/build/__fixtures__/noEntry/src/notMain.d.ts +1 -0
  204. package/lib/esm/build/__fixtures__/noEntry/src/notMain.js +2 -0
  205. package/lib/esm/build/__fixtures__/noEntry/src/notMain.js.map +1 -0
  206. package/lib/esm/build/__fixtures__/nonFunction/src/main.d.ts +2 -0
  207. package/lib/esm/build/__fixtures__/nonFunction/src/main.js +3 -0
  208. package/lib/esm/build/__fixtures__/nonFunction/src/main.js.map +1 -0
  209. package/lib/esm/build/assertUserScriptExports.d.ts +6 -0
  210. package/lib/esm/build/assertUserScriptExports.js +16 -0
  211. package/lib/esm/build/assertUserScriptExports.js.map +1 -0
  212. package/lib/esm/build/buildUserScript.d.ts +15 -0
  213. package/lib/esm/build/buildUserScript.js +39 -0
  214. package/lib/esm/build/buildUserScript.js.map +1 -0
  215. package/lib/esm/build/checkUserScriptOutput.d.ts +7 -0
  216. package/lib/esm/build/checkUserScriptOutput.js +10 -0
  217. package/lib/esm/build/checkUserScriptOutput.js.map +1 -0
  218. package/lib/esm/build/createUserScriptExternals.d.ts +11 -0
  219. package/lib/esm/build/createUserScriptExternals.js +30 -0
  220. package/lib/esm/build/createUserScriptExternals.js.map +1 -0
  221. package/lib/esm/build/getUserScriptRspackConfig.d.ts +15 -0
  222. package/lib/esm/build/getUserScriptRspackConfig.js +42 -0
  223. package/lib/esm/build/getUserScriptRspackConfig.js.map +1 -0
  224. package/lib/esm/build/index.d.ts +13 -0
  225. package/lib/esm/build/index.js +14 -0
  226. package/lib/esm/build/index.js.map +1 -0
  227. package/lib/esm/build/loadRspackModule.d.ts +8 -0
  228. package/lib/esm/build/loadRspackModule.js +38 -0
  229. package/lib/esm/build/loadRspackModule.js.map +1 -0
  230. package/lib/esm/build/resolveUserScriptEntry.d.ts +2 -0
  231. package/lib/esm/build/resolveUserScriptEntry.js +13 -0
  232. package/lib/esm/build/resolveUserScriptEntry.js.map +1 -0
  233. package/lib/esm/build/runUserScriptRspack.d.ts +7 -0
  234. package/lib/esm/build/runUserScriptRspack.js +19 -0
  235. package/lib/esm/build/runUserScriptRspack.js.map +1 -0
  236. package/lib/esm/build/userScriptTsRule.d.ts +6 -0
  237. package/lib/esm/build/userScriptTsRule.js +17 -0
  238. package/lib/esm/build/userScriptTsRule.js.map +1 -0
  239. package/lib/esm/config/USER_SCRIPT_BUILDER_LAYER_MODULES.d.ts +5 -0
  240. package/lib/esm/config/USER_SCRIPT_BUILDER_LAYER_MODULES.js +6 -0
  241. package/lib/esm/config/USER_SCRIPT_BUILDER_LAYER_MODULES.js.map +1 -0
  242. package/lib/esm/config/USER_SCRIPT_BUILDER_LAYER_NAME.d.ts +2 -0
  243. package/lib/esm/config/USER_SCRIPT_BUILDER_LAYER_NAME.js +3 -0
  244. package/lib/esm/config/USER_SCRIPT_BUILDER_LAYER_NAME.js.map +1 -0
  245. package/lib/esm/config/defineUserScriptBuilder.d.ts +7 -0
  246. package/lib/esm/config/defineUserScriptBuilder.js +12 -0
  247. package/lib/esm/config/defineUserScriptBuilder.js.map +1 -0
  248. package/lib/esm/config/getUserScriptBuilderApiLayer.d.ts +7 -0
  249. package/lib/esm/config/getUserScriptBuilderApiLayer.js +14 -0
  250. package/lib/esm/config/getUserScriptBuilderApiLayer.js.map +1 -0
  251. package/lib/esm/config/getUserScriptBuilderLayerDir.d.ts +6 -0
  252. package/lib/esm/config/getUserScriptBuilderLayerDir.js +26 -0
  253. package/lib/esm/config/getUserScriptBuilderLayerDir.js.map +1 -0
  254. package/lib/esm/config/index.d.ts +5 -0
  255. package/lib/esm/config/index.js +6 -0
  256. package/lib/esm/config/index.js.map +1 -0
  257. package/lib/esm/index.d.ts +3 -0
  258. package/lib/esm/index.js +4 -0
  259. package/lib/esm/index.js.map +1 -0
  260. package/package.json +49 -3
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.extractUserScriptZip = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const node_stream_1 = require("node:stream");
18
+ const promises_1 = require("node:stream/promises");
19
+ const path_1 = __importDefault(require("path"));
20
+ const yauzl_1 = __importDefault(require("yauzl"));
21
+ const isSafeProjectPath_1 = require("./isSafeProjectPath");
22
+ const USER_SCRIPT_SOURCE_LIMITS_1 = require("./USER_SCRIPT_SOURCE_LIMITS");
23
+ const UserScriptArchiveError_1 = require("./UserScriptArchiveError");
24
+ const REFUSED_DIRECTORY = 'node_modules';
25
+ const SYMLINK_MODE = 0o120000;
26
+ const FILE_TYPE_MASK = 0o170000;
27
+ // Unix mode lives in the high 16 bits of the external attributes; zips made on other
28
+ // systems leave it zero, which reads as "not a symlink".
29
+ const isSymlinkEntry = (entry) => ((entry.externalFileAttributes >>> 16) & FILE_TYPE_MASK) === SYMLINK_MODE;
30
+ // With decodeStrings off, yauzl hands names over raw so it does not apply its own path
31
+ // rules before ours.
32
+ const entryName = (entry) => (Buffer.isBuffer(entry.fileName) ? entry.fileName.toString('utf8') : String(entry.fileName));
33
+ const isDirectoryEntry = (name) => name.endsWith('/');
34
+ const openZip = (zip) => new Promise((resolve, reject) => {
35
+ // Header sizes are never consulted: the byte cap on the inflated stream is the only
36
+ // authority, so yauzl's own size validation is off rather than a second, trusted, rule.
37
+ yauzl_1.default.fromBuffer(zip, { lazyEntries: true, decodeStrings: false, validateEntrySizes: false }, (error, zipFile) => error ? reject(error) : resolve(zipFile));
38
+ });
39
+ const readEntries = (zipFile, onEntry) => new Promise((resolve, reject) => {
40
+ zipFile.on('error', reject);
41
+ zipFile.on('end', resolve);
42
+ zipFile.on('entry', (entry) => {
43
+ // A rule that throws synchronously must still reject here, not escape yauzl's
44
+ // event emitter where it would be lost and leave the zip hanging.
45
+ Promise.resolve()
46
+ .then(() => onEntry(entry))
47
+ .then(() => zipFile.readEntry(), (error) => {
48
+ zipFile.close();
49
+ reject(error);
50
+ });
51
+ });
52
+ zipFile.readEntry();
53
+ });
54
+ const openEntryStream = (zipFile, entry) => new Promise((resolve, reject) => {
55
+ zipFile.openReadStream(entry, (error, stream) => (error ? reject(error) : resolve(stream)));
56
+ });
57
+ const tooLarge = (message) => new UserScriptArchiveError_1.UserScriptArchiveError(UserScriptArchiveError_1.UserScriptArchiveErrorCode.SourceTooLarge, message);
58
+ const unsafe = (message) => new UserScriptArchiveError_1.UserScriptArchiveError(UserScriptArchiveError_1.UserScriptArchiveErrorCode.UnsafeArchiveEntry, message);
59
+ const invalid = (message) => new UserScriptArchiveError_1.UserScriptArchiveError(UserScriptArchiveError_1.UserScriptArchiveErrorCode.InvalidArchive, message);
60
+ // Counts the bytes that really come out of the inflater and fails the pipeline the moment
61
+ // the project cap is crossed, so a zip that lies about its sizes cannot fill the disk.
62
+ const createByteCap = (counter, onExceeded) => new node_stream_1.Transform({
63
+ transform(chunk, _encoding, callback) {
64
+ counter.total += chunk.length;
65
+ if (counter.total > USER_SCRIPT_SOURCE_LIMITS_1.USER_SCRIPT_SOURCE_LIMITS.maxBytes) {
66
+ callback(onExceeded());
67
+ return;
68
+ }
69
+ callback(null, chunk);
70
+ },
71
+ });
72
+ // Accepts the project at the zip root (anything under `src/`), or wrapped in exactly one
73
+ // top-level folder (how most tools zip a directory): when nothing is under `src/` at the
74
+ // root, every file shares the same first segment, and none sits at the root, that segment
75
+ // is stripped. A root `src/` always wins, so a project with only `src/` is never stripped.
76
+ const stripCommonFolder = (names) => {
77
+ if (names.length === 0 || names.some((name) => name.startsWith('src/')))
78
+ return 0;
79
+ const firstSegments = new Set(names.map((name) => name.split('/')[0]));
80
+ const allNested = names.every((name) => name.includes('/'));
81
+ return firstSegments.size === 1 && allNested ? [...firstSegments][0].length + 1 : 0;
82
+ };
83
+ const planEntries = (zip) => __awaiter(void 0, void 0, void 0, function* () {
84
+ const files = [];
85
+ const zipFile = yield openZip(zip);
86
+ yield readEntries(zipFile, (entry) => {
87
+ const name = entryName(entry);
88
+ if (isDirectoryEntry(name))
89
+ return;
90
+ if (entry.isEncrypted())
91
+ throw invalid(`entry [${name}] is encrypted`);
92
+ if (isSymlinkEntry(entry))
93
+ throw unsafe(`entry [${name}] is a symlink`);
94
+ if (!(0, isSafeProjectPath_1.isSafeProjectPath)(name))
95
+ throw unsafe(`entry [${name}] is not a plain relative path inside the project`);
96
+ if (name.split('/').includes(REFUSED_DIRECTORY)) {
97
+ throw tooLarge(`entry [${name}] is inside a ${REFUSED_DIRECTORY} folder; dependencies are not supported in a user script yet`);
98
+ }
99
+ files.push({ entry, relativePath: name });
100
+ if (files.length > USER_SCRIPT_SOURCE_LIMITS_1.USER_SCRIPT_SOURCE_LIMITS.maxFiles) {
101
+ throw tooLarge(`the archive holds more than ${USER_SCRIPT_SOURCE_LIMITS_1.USER_SCRIPT_SOURCE_LIMITS.maxFiles} files`);
102
+ }
103
+ });
104
+ const strip = stripCommonFolder(files.map((file) => file.relativePath));
105
+ return files.map((file) => (Object.assign(Object.assign({}, file), { relativePath: file.relativePath.slice(strip) })));
106
+ });
107
+ /**
108
+ * Unpacks a user-controlled zip into the project directory under the same rules as a
109
+ * directory build: plain relative paths only, no symlinks, no node_modules, at most
110
+ * USER_SCRIPT_SOURCE_LIMITS files and unpacked bytes counted as they are written (the
111
+ * sizes in the zip's headers are never trusted). Directory entries are ignored; folders
112
+ * come from file paths. Returns the project-relative paths written.
113
+ */
114
+ const extractUserScriptZip = (zip, projectDir) => __awaiter(void 0, void 0, void 0, function* () {
115
+ let planned;
116
+ try {
117
+ planned = yield planEntries(zip);
118
+ }
119
+ catch (error) {
120
+ if (error instanceof UserScriptArchiveError_1.UserScriptArchiveError)
121
+ throw error;
122
+ throw invalid(`cannot read the archive: ${error instanceof Error ? error.message : String(error)}`);
123
+ }
124
+ const counter = { total: 0 };
125
+ const written = [];
126
+ const zipFile = yield openZip(zip);
127
+ const plannedByEntryName = new Map(planned.map((file) => [entryName(file.entry), file.relativePath]));
128
+ try {
129
+ yield readEntries(zipFile, (entry) => __awaiter(void 0, void 0, void 0, function* () {
130
+ const relativePath = plannedByEntryName.get(entryName(entry));
131
+ if (relativePath === undefined)
132
+ return;
133
+ const target = path_1.default.join(projectDir, ...relativePath.split('/'));
134
+ fs_1.default.mkdirSync(path_1.default.dirname(target), { recursive: true });
135
+ const stream = yield openEntryStream(zipFile, entry);
136
+ yield (0, promises_1.pipeline)(stream, createByteCap(counter, () => tooLarge(`the archive unpacks to more than ${USER_SCRIPT_SOURCE_LIMITS_1.USER_SCRIPT_SOURCE_LIMITS.maxBytes} bytes`)), fs_1.default.createWriteStream(target));
137
+ written.push(relativePath);
138
+ }));
139
+ }
140
+ catch (error) {
141
+ if (error instanceof UserScriptArchiveError_1.UserScriptArchiveError)
142
+ throw error;
143
+ throw invalid(`cannot unpack the archive: ${error instanceof Error ? error.message : String(error)}`);
144
+ }
145
+ return written;
146
+ });
147
+ exports.extractUserScriptZip = extractUserScriptZip;
148
+ //# sourceMappingURL=extractUserScriptZip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractUserScriptZip.js","sourceRoot":"","sources":["../../../../src/actionProcessor/logic/extractUserScriptZip.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,6CAAkD;AAClD,mDAAgD;AAChD,gDAAwB;AACxB,kDAA8C;AAE9C,2DAAwD;AACxD,2EAAwE;AACxE,qEAA8F;AAE9F,MAAM,iBAAiB,GAAG,cAAc,CAAC;AACzC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAC9B,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEhC,qFAAqF;AACrF,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AI,EAAE,CAAC,CAAC;YAExD,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACrD,MAAM,IAAA,mBAAQ,EACZ,MAAM,EACN,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,oCAAoC,qDAAyB,CAAC,QAAQ,QAAQ,CAAC,CAAC,EACtH,YAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAC7B,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC7B,CAAC,CAAA,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,+CAAsB;YAAE,MAAM,KAAK,CAAC;QACzD,MAAM,OAAO,CAAC,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACxG,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAA,CAAC;AApCW,QAAA,oBAAoB,wBAoC/B","sourcesContent":["import fs from 'fs';\nimport { Readable, Transform } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport path from 'path';\nimport yauzl, { Entry, ZipFile } from 'yauzl';\n\nimport { isSafeProjectPath } from './isSafeProjectPath';\nimport { USER_SCRIPT_SOURCE_LIMITS } from './USER_SCRIPT_SOURCE_LIMITS';\nimport { UserScriptArchiveError, UserScriptArchiveErrorCode } from './UserScriptArchiveError';\n\nconst REFUSED_DIRECTORY = 'node_modules';\nconst SYMLINK_MODE = 0o120000;\nconst FILE_TYPE_MASK = 0o170000;\n\n// Unix mode lives in the high 16 bits of the external attributes; zips made on other\n// systems leave it zero, which reads as \"not a symlink\".\nconst isSymlinkEntry = (entry: Entry): boolean => ((entry.externalFileAttributes >>> 16) & FILE_TYPE_MASK) === SYMLINK_MODE;\n\n// With decodeStrings off, yauzl hands names over raw so it does not apply its own path\n// rules before ours.\nconst entryName = (entry: Entry): string => (Buffer.isBuffer(entry.fileName) ? entry.fileName.toString('utf8') : String(entry.fileName));\n\nconst isDirectoryEntry = (name: string): boolean => name.endsWith('/');\n\nconst openZip = (zip: Buffer): Promise<ZipFile> =>\n new Promise((resolve, reject) => {\n // Header sizes are never consulted: the byte cap on the inflated stream is the only\n // authority, so yauzl's own size validation is off rather than a second, trusted, rule.\n yauzl.fromBuffer(zip, { lazyEntries: true, decodeStrings: false, validateEntrySizes: false }, (error, zipFile) =>\n error ? reject(error) : resolve(zipFile),\n );\n });\n\nconst readEntries = (zipFile: ZipFile, onEntry: (entry: Entry) => Promise<void> | void): Promise<void> =>\n new Promise((resolve, reject) => {\n zipFile.on('error', reject);\n zipFile.on('end', resolve);\n zipFile.on('entry', (entry: Entry) => {\n // A rule that throws synchronously must still reject here, not escape yauzl's\n // event emitter where it would be lost and leave the zip hanging.\n Promise.resolve()\n .then(() => onEntry(entry))\n .then(\n () => zipFile.readEntry(),\n (error) => {\n zipFile.close();\n reject(error);\n },\n );\n });\n zipFile.readEntry();\n });\n\nconst openEntryStream = (zipFile: ZipFile, entry: Entry): Promise<Readable> =>\n new Promise((resolve, reject) => {\n zipFile.openReadStream(entry, (error, stream) => (error ? reject(error) : resolve(stream)));\n });\n\nconst tooLarge = (message: string): UserScriptArchiveError => new UserScriptArchiveError(UserScriptArchiveErrorCode.SourceTooLarge, message);\nconst unsafe = (message: string): UserScriptArchiveError => new UserScriptArchiveError(UserScriptArchiveErrorCode.UnsafeArchiveEntry, message);\nconst invalid = (message: string): UserScriptArchiveError => new UserScriptArchiveError(UserScriptArchiveErrorCode.InvalidArchive, message);\n\n// Counts the bytes that really come out of the inflater and fails the pipeline the moment\n// the project cap is crossed, so a zip that lies about its sizes cannot fill the disk.\nconst createByteCap = (counter: { total: number }, onExceeded: () => Error): Transform =>\n new Transform({\n transform(chunk: Buffer, _encoding, callback) {\n counter.total += chunk.length;\n if (counter.total > USER_SCRIPT_SOURCE_LIMITS.maxBytes) {\n callback(onExceeded());\n return;\n }\n callback(null, chunk);\n },\n });\n\ntype PlannedEntry = { entry: Entry; relativePath: string };\n\n// Accepts the project at the zip root (anything under `src/`), or wrapped in exactly one\n// top-level folder (how most tools zip a directory): when nothing is under `src/` at the\n// root, every file shares the same first segment, and none sits at the root, that segment\n// is stripped. A root `src/` always wins, so a project with only `src/` is never stripped.\nconst stripCommonFolder = (names: string[]): number => {\n if (names.length === 0 || names.some((name) => name.startsWith('src/'))) return 0;\n\n const firstSegments = new Set(names.map((name) => name.split('/')[0]));\n const allNested = names.every((name) => name.includes('/'));\n\n return firstSegments.size === 1 && allNested ? [...firstSegments][0].length + 1 : 0;\n};\n\nconst planEntries = async (zip: Buffer): Promise<PlannedEntry[]> => {\n const files: PlannedEntry[] = [];\n const zipFile = await openZip(zip);\n\n await readEntries(zipFile, (entry) => {\n const name = entryName(entry);\n if (isDirectoryEntry(name)) return;\n\n if (entry.isEncrypted()) throw invalid(`entry [${name}] is encrypted`);\n if (isSymlinkEntry(entry)) throw unsafe(`entry [${name}] is a symlink`);\n if (!isSafeProjectPath(name)) throw unsafe(`entry [${name}] is not a plain relative path inside the project`);\n if (name.split('/').includes(REFUSED_DIRECTORY)) {\n throw tooLarge(`entry [${name}] is inside a ${REFUSED_DIRECTORY} folder; dependencies are not supported in a user script yet`);\n }\n\n files.push({ entry, relativePath: name });\n if (files.length > USER_SCRIPT_SOURCE_LIMITS.maxFiles) {\n throw tooLarge(`the archive holds more than ${USER_SCRIPT_SOURCE_LIMITS.maxFiles} files`);\n }\n });\n\n const strip = stripCommonFolder(files.map((file) => file.relativePath));\n\n return files.map((file) => ({ ...file, relativePath: file.relativePath.slice(strip) }));\n};\n\n/**\n * Unpacks a user-controlled zip into the project directory under the same rules as a\n * directory build: plain relative paths only, no symlinks, no node_modules, at most\n * USER_SCRIPT_SOURCE_LIMITS files and unpacked bytes counted as they are written (the\n * sizes in the zip's headers are never trusted). Directory entries are ignored; folders\n * come from file paths. Returns the project-relative paths written.\n */\nexport const extractUserScriptZip = async (zip: Buffer, projectDir: string): Promise<string[]> => {\n let planned: PlannedEntry[];\n try {\n planned = await planEntries(zip);\n } catch (error) {\n if (error instanceof UserScriptArchiveError) throw error;\n throw invalid(`cannot read the archive: ${error instanceof Error ? error.message : String(error)}`);\n }\n\n const counter = { total: 0 };\n const written: string[] = [];\n const zipFile = await openZip(zip);\n const plannedByEntryName = new Map(planned.map((file) => [entryName(file.entry), file.relativePath]));\n\n try {\n await readEntries(zipFile, async (entry) => {\n const relativePath = plannedByEntryName.get(entryName(entry));\n if (relativePath === undefined) return;\n\n const target = path.join(projectDir, ...relativePath.split('/'));\n fs.mkdirSync(path.dirname(target), { recursive: true });\n\n const stream = await openEntryStream(zipFile, entry);\n await pipeline(\n stream,\n createByteCap(counter, () => tooLarge(`the archive unpacks to more than ${USER_SCRIPT_SOURCE_LIMITS.maxBytes} bytes`)),\n fs.createWriteStream(target),\n );\n written.push(relativePath);\n });\n } catch (error) {\n if (error instanceof UserScriptArchiveError) throw error;\n throw invalid(`cannot unpack the archive: ${error instanceof Error ? error.message : String(error)}`);\n }\n\n return written;\n};\n"]}
@@ -0,0 +1,7 @@
1
+ import { UserScriptBuildErrorCode } from '../../build/UserScriptBuildError';
2
+ export type UserScriptBuildErrorCatalog = Record<'SourceNotFound' | 'BuildFailed' | 'OutputNotSingleFile' | 'NoExports' | 'NonFunctionExport', string>;
3
+ /**
4
+ * The action error type for a build failure. Codes map one to one, except that a missing
5
+ * entry is the caller's source being wrong, not the build, so it is SourceNotFound.
6
+ */
7
+ export declare const getUserScriptBuildErrorType: (code: UserScriptBuildErrorCode, errorType: UserScriptBuildErrorCatalog) => string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUserScriptBuildErrorType = void 0;
4
+ const UserScriptBuildError_1 = require("../../build/UserScriptBuildError");
5
+ /**
6
+ * The action error type for a build failure. Codes map one to one, except that a missing
7
+ * entry is the caller's source being wrong, not the build, so it is SourceNotFound.
8
+ */
9
+ const getUserScriptBuildErrorType = (code, errorType) => {
10
+ const byCode = {
11
+ [UserScriptBuildError_1.UserScriptBuildErrorCode.NoEntry]: errorType.SourceNotFound,
12
+ [UserScriptBuildError_1.UserScriptBuildErrorCode.BuildFailed]: errorType.BuildFailed,
13
+ [UserScriptBuildError_1.UserScriptBuildErrorCode.OutputNotSingleFile]: errorType.OutputNotSingleFile,
14
+ [UserScriptBuildError_1.UserScriptBuildErrorCode.NoExports]: errorType.NoExports,
15
+ [UserScriptBuildError_1.UserScriptBuildErrorCode.NonFunctionExport]: errorType.NonFunctionExport,
16
+ };
17
+ return byCode[code];
18
+ };
19
+ exports.getUserScriptBuildErrorType = getUserScriptBuildErrorType;
20
+ //# sourceMappingURL=getUserScriptBuildErrorType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUserScriptBuildErrorType.js","sourceRoot":"","sources":["../../../../src/actionProcessor/logic/getUserScriptBuildErrorType.ts"],"names":[],"mappings":";;;AAAA,2EAA4E;AAQ5E;;;GAGG;AACI,MAAM,2BAA2B,GAAG,CAAC,IAA8B,EAAE,SAAsC,EAAU,EAAE;IAC5H,MAAM,MAAM,GAA6C;QACvD,CAAC,+CAAwB,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,cAAc;QAC5D,CAAC,+CAAwB,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,WAAW;QAC7D,CAAC,+CAAwB,CAAC,mBAAmB,CAAC,EAAE,SAAS,CAAC,mBAAmB;QAC7E,CAAC,+CAAwB,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,SAAS;QACzD,CAAC,+CAAwB,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC,iBAAiB;KAC1E,CAAC;IAEF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC,CAAC;AAVW,QAAA,2BAA2B,+BAUtC","sourcesContent":["import { UserScriptBuildErrorCode } from '../../build/UserScriptBuildError';\n\n// The error names a build action's catalog must carry for the build's own codes.\nexport type UserScriptBuildErrorCatalog = Record<\n 'SourceNotFound' | 'BuildFailed' | 'OutputNotSingleFile' | 'NoExports' | 'NonFunctionExport',\n string\n>;\n\n/**\n * The action error type for a build failure. Codes map one to one, except that a missing\n * entry is the caller's source being wrong, not the build, so it is SourceNotFound.\n */\nexport const getUserScriptBuildErrorType = (code: UserScriptBuildErrorCode, errorType: UserScriptBuildErrorCatalog): string => {\n const byCode: Record<UserScriptBuildErrorCode, string> = {\n [UserScriptBuildErrorCode.NoEntry]: errorType.SourceNotFound,\n [UserScriptBuildErrorCode.BuildFailed]: errorType.BuildFailed,\n [UserScriptBuildErrorCode.OutputNotSingleFile]: errorType.OutputNotSingleFile,\n [UserScriptBuildErrorCode.NoExports]: errorType.NoExports,\n [UserScriptBuildErrorCode.NonFunctionExport]: errorType.NonFunctionExport,\n };\n\n return byCode[code];\n};\n"]}
@@ -0,0 +1,12 @@
1
+ export * from './askUserScriptCheckPublishedOutput';
2
+ export * from './askUserScriptCollectSource';
3
+ export * from './askUserScriptPublishOutput';
4
+ export * from './buildUserScriptInTempDir';
5
+ export * from './BuiltUserScript';
6
+ export * from './extractUserScriptZip';
7
+ export * from './getUserScriptBuildErrorType';
8
+ export * from './isSafeProjectPath';
9
+ export * from './materialiseUserScriptSource';
10
+ export * from './USER_SCRIPT_SOURCE_LIMITS';
11
+ export * from './UserScriptArchiveError';
12
+ export * from './UserScriptSourceFile';
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./askUserScriptCheckPublishedOutput"), exports);
18
+ __exportStar(require("./askUserScriptCollectSource"), exports);
19
+ __exportStar(require("./askUserScriptPublishOutput"), exports);
20
+ __exportStar(require("./buildUserScriptInTempDir"), exports);
21
+ __exportStar(require("./BuiltUserScript"), exports);
22
+ __exportStar(require("./extractUserScriptZip"), exports);
23
+ __exportStar(require("./getUserScriptBuildErrorType"), exports);
24
+ __exportStar(require("./isSafeProjectPath"), exports);
25
+ __exportStar(require("./materialiseUserScriptSource"), exports);
26
+ __exportStar(require("./USER_SCRIPT_SOURCE_LIMITS"), exports);
27
+ __exportStar(require("./UserScriptArchiveError"), exports);
28
+ __exportStar(require("./UserScriptSourceFile"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/actionProcessor/logic/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,+DAA6C;AAC7C,+DAA6C;AAC7C,6DAA2C;AAC3C,oDAAkC;AAClC,yDAAuC;AACvC,gEAA8C;AAC9C,sDAAoC;AACpC,gEAA8C;AAC9C,8DAA4C;AAC5C,2DAAyC;AACzC,yDAAuC","sourcesContent":["export * from './askUserScriptCheckPublishedOutput';\nexport * from './askUserScriptCollectSource';\nexport * from './askUserScriptPublishOutput';\nexport * from './buildUserScriptInTempDir';\nexport * from './BuiltUserScript';\nexport * from './extractUserScriptZip';\nexport * from './getUserScriptBuildErrorType';\nexport * from './isSafeProjectPath';\nexport * from './materialiseUserScriptSource';\nexport * from './USER_SCRIPT_SOURCE_LIMITS';\nexport * from './UserScriptArchiveError';\nexport * from './UserScriptSourceFile';\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Whether a path from an untrusted source (a drive listing, a zip entry) may be written
3
+ * under a project directory: relative, forward slashes only, no `..`, no empty segment.
4
+ */
5
+ export declare const isSafeProjectPath: (relativePath: string) => boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSafeProjectPath = void 0;
4
+ /**
5
+ * Whether a path from an untrusted source (a drive listing, a zip entry) may be written
6
+ * under a project directory: relative, forward slashes only, no `..`, no empty segment.
7
+ */
8
+ const isSafeProjectPath = (relativePath) => relativePath.length > 0 &&
9
+ !relativePath.includes('\\') &&
10
+ !relativePath.startsWith('/') &&
11
+ !relativePath.split('/').some((segment) => segment === '' || segment === '.' || segment === '..');
12
+ exports.isSafeProjectPath = isSafeProjectPath;
13
+ //# sourceMappingURL=isSafeProjectPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isSafeProjectPath.js","sourceRoot":"","sources":["../../../../src/actionProcessor/logic/isSafeProjectPath.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACI,MAAM,iBAAiB,GAAG,CAAC,YAAoB,EAAW,EAAE,CACjE,YAAY,CAAC,MAAM,GAAG,CAAC;IACvB,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC;IAC7B,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC;AAJvF,QAAA,iBAAiB,qBAIsE","sourcesContent":["/**\n * Whether a path from an untrusted source (a drive listing, a zip entry) may be written\n * under a project directory: relative, forward slashes only, no `..`, no empty segment.\n */\nexport const isSafeProjectPath = (relativePath: string): boolean =>\n relativePath.length > 0 &&\n !relativePath.includes('\\\\') &&\n !relativePath.startsWith('/') &&\n !relativePath.split('/').some((segment) => segment === '' || segment === '.' || segment === '..');\n"]}
@@ -0,0 +1,3 @@
1
+ import { UserScriptSourceFile } from './UserScriptSourceFile';
2
+ /** Writes collected source files under the project directory, refusing any path that would leave it. */
3
+ export declare const materialiseUserScriptSource: (projectDir: string, files: UserScriptSourceFile[]) => void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.materialiseUserScriptSource = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const UserScriptBuildError_1 = require("../../build/UserScriptBuildError");
10
+ const isSafeProjectPath_1 = require("./isSafeProjectPath");
11
+ /** Writes collected source files under the project directory, refusing any path that would leave it. */
12
+ const materialiseUserScriptSource = (projectDir, files) => {
13
+ for (const file of files) {
14
+ if (!(0, isSafeProjectPath_1.isSafeProjectPath)(file.path)) {
15
+ throw new UserScriptBuildError_1.UserScriptBuildError(UserScriptBuildError_1.UserScriptBuildErrorCode.BuildFailed, `Refusing source path [${file.path}]`);
16
+ }
17
+ const target = path_1.default.join(projectDir, ...file.path.split('/'));
18
+ fs_1.default.mkdirSync(path_1.default.dirname(target), { recursive: true });
19
+ fs_1.default.writeFileSync(target, file.text);
20
+ }
21
+ };
22
+ exports.materialiseUserScriptSource = materialiseUserScriptSource;
23
+ //# sourceMappingURL=materialiseUserScriptSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"materialiseUserScriptSource.js","sourceRoot":"","sources":["../../../../src/actionProcessor/logic/materialiseUserScriptSource.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AAExB,2EAAkG;AAClG,2DAAwD;AAGxD,wGAAwG;AACjG,MAAM,2BAA2B,GAAG,CAAC,UAAkB,EAAE,KAA6B,EAAQ,EAAE;IACrG,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAA,qCAAiB,EAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,2CAAoB,CAAC,+CAAwB,CAAC,WAAW,EAAE,yBAAyB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAC9G,CAAC;QACD,MAAM,MAAM,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9D,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,YAAE,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;AACH,CAAC,CAAC;AATW,QAAA,2BAA2B,+BAStC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nimport { UserScriptBuildError, UserScriptBuildErrorCode } from '../../build/UserScriptBuildError';\nimport { isSafeProjectPath } from './isSafeProjectPath';\nimport { UserScriptSourceFile } from './UserScriptSourceFile';\n\n/** Writes collected source files under the project directory, refusing any path that would leave it. */\nexport const materialiseUserScriptSource = (projectDir: string, files: UserScriptSourceFile[]): void => {\n for (const file of files) {\n if (!isSafeProjectPath(file.path)) {\n throw new UserScriptBuildError(UserScriptBuildErrorCode.BuildFailed, `Refusing source path [${file.path}]`);\n }\n const target = path.join(projectDir, ...file.path.split('/'));\n fs.mkdirSync(path.dirname(target), { recursive: true });\n fs.writeFileSync(target, file.text);\n }\n};\n"]}
@@ -0,0 +1,2 @@
1
+ /** The entry files a script project may have, relative to its root, in the order they are tried. */
2
+ export declare const USER_SCRIPT_ENTRY_CANDIDATES: readonly ["src/main.ts", "src/main.js"];
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USER_SCRIPT_ENTRY_CANDIDATES = void 0;
4
+ /** The entry files a script project may have, relative to its root, in the order they are tried. */
5
+ exports.USER_SCRIPT_ENTRY_CANDIDATES = ['src/main.ts', 'src/main.js'];
6
+ //# sourceMappingURL=USER_SCRIPT_ENTRY_CANDIDATES.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"USER_SCRIPT_ENTRY_CANDIDATES.js","sourceRoot":"","sources":["../../../src/build/USER_SCRIPT_ENTRY_CANDIDATES.ts"],"names":[],"mappings":";;;AAAA,oGAAoG;AACvF,QAAA,4BAA4B,GAAG,CAAC,aAAa,EAAE,aAAa,CAAU,CAAC","sourcesContent":["/** The entry files a script project may have, relative to its root, in the order they are tried. */\nexport const USER_SCRIPT_ENTRY_CANDIDATES = ['src/main.ts', 'src/main.js'] as const;\n"]}
@@ -0,0 +1,2 @@
1
+ /** The name a build writes the script under in its own out dir; a platform build then publishes that file to the caller's `outputFilepath`. */
2
+ export declare const USER_SCRIPT_OUTPUT_FILENAME = "main.js";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USER_SCRIPT_OUTPUT_FILENAME = void 0;
4
+ /** The name a build writes the script under in its own out dir; a platform build then publishes that file to the caller's `outputFilepath`. */
5
+ exports.USER_SCRIPT_OUTPUT_FILENAME = 'main.js';
6
+ //# sourceMappingURL=USER_SCRIPT_OUTPUT_FILENAME.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"USER_SCRIPT_OUTPUT_FILENAME.js","sourceRoot":"","sources":["../../../src/build/USER_SCRIPT_OUTPUT_FILENAME.ts"],"names":[],"mappings":";;;AAAA,+IAA+I;AAClI,QAAA,2BAA2B,GAAG,SAAS,CAAC","sourcesContent":["/** The name a build writes the script under in its own out dir; a platform build then publishes that file to the caller's `outputFilepath`. */\nexport const USER_SCRIPT_OUTPUT_FILENAME = 'main.js';\n"]}
@@ -0,0 +1,12 @@
1
+ export declare enum UserScriptBuildErrorCode {
2
+ NoEntry = "NoEntry",
3
+ BuildFailed = "BuildFailed",
4
+ OutputNotSingleFile = "OutputNotSingleFile",
5
+ NoExports = "NoExports",
6
+ NonFunctionExport = "NonFunctionExport"
7
+ }
8
+ /** Thrown by buildUserScript; `code` says which step refused the project. */
9
+ export declare class UserScriptBuildError extends Error {
10
+ readonly code: UserScriptBuildErrorCode;
11
+ constructor(code: UserScriptBuildErrorCode, message: string);
12
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserScriptBuildError = exports.UserScriptBuildErrorCode = void 0;
4
+ var UserScriptBuildErrorCode;
5
+ (function (UserScriptBuildErrorCode) {
6
+ // No src/main.ts or src/main.js in the project.
7
+ UserScriptBuildErrorCode["NoEntry"] = "NoEntry";
8
+ // Rspack reported errors (a refused Node builtin among them).
9
+ UserScriptBuildErrorCode["BuildFailed"] = "BuildFailed";
10
+ // The build emitted more than one JavaScript file, so the output is not one loadable module.
11
+ UserScriptBuildErrorCode["OutputNotSingleFile"] = "OutputNotSingleFile";
12
+ // The built module has no own enumerable exports.
13
+ UserScriptBuildErrorCode["NoExports"] = "NoExports";
14
+ // An own enumerable export of the built module is not a function.
15
+ UserScriptBuildErrorCode["NonFunctionExport"] = "NonFunctionExport";
16
+ })(UserScriptBuildErrorCode || (exports.UserScriptBuildErrorCode = UserScriptBuildErrorCode = {}));
17
+ /** Thrown by buildUserScript; `code` says which step refused the project. */
18
+ class UserScriptBuildError extends Error {
19
+ constructor(code, message) {
20
+ super(message);
21
+ this.code = code;
22
+ this.name = 'UserScriptBuildError';
23
+ }
24
+ }
25
+ exports.UserScriptBuildError = UserScriptBuildError;
26
+ //# sourceMappingURL=UserScriptBuildError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserScriptBuildError.js","sourceRoot":"","sources":["../../../src/build/UserScriptBuildError.ts"],"names":[],"mappings":";;;AAAA,IAAY,wBAWX;AAXD,WAAY,wBAAwB;IAClC,gDAAgD;IAChD,+CAAmB,CAAA;IACnB,8DAA8D;IAC9D,uDAA2B,CAAA;IAC3B,6FAA6F;IAC7F,uEAA2C,CAAA;IAC3C,kDAAkD;IAClD,mDAAuB,CAAA;IACvB,kEAAkE;IAClE,mEAAuC,CAAA;AACzC,CAAC,EAXW,wBAAwB,wCAAxB,wBAAwB,QAWnC;AAED,6EAA6E;AAC7E,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YACkB,IAA8B,EAC9C,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAA0B;QAI9C,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AARD,oDAQC","sourcesContent":["export enum UserScriptBuildErrorCode {\n // No src/main.ts or src/main.js in the project.\n NoEntry = 'NoEntry',\n // Rspack reported errors (a refused Node builtin among them).\n BuildFailed = 'BuildFailed',\n // The build emitted more than one JavaScript file, so the output is not one loadable module.\n OutputNotSingleFile = 'OutputNotSingleFile',\n // The built module has no own enumerable exports.\n NoExports = 'NoExports',\n // An own enumerable export of the built module is not a function.\n NonFunctionExport = 'NonFunctionExport',\n}\n\n/** Thrown by buildUserScript; `code` says which step refused the project. */\nexport class UserScriptBuildError extends Error {\n constructor(\n public readonly code: UserScriptBuildErrorCode,\n message: string,\n ) {\n super(message);\n this.name = 'UserScriptBuildError';\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ /** What a successful user-script build produced. */
2
+ export type UserScriptBuildResult = {
3
+ entryPath: string;
4
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=UserScriptBuildResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserScriptBuildResult.js","sourceRoot":"","sources":["../../../src/build/UserScriptBuildResult.ts"],"names":[],"mappings":"","sourcesContent":["/** What a successful user-script build produced. */\nexport type UserScriptBuildResult = {\n // Absolute path of the single CommonJS output, `<outDir>/main.js`, the only file written.\n entryPath: string;\n};\n"]}
@@ -0,0 +1 @@
1
+ export declare const formatSum: (sum: number) => string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatSum = void 0;
4
+ const formatSum = (sum) => `added ${sum}`;
5
+ exports.formatSum = formatSum;
6
+ //# sourceMappingURL=formatSum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatSum.js","sourceRoot":"","sources":["../../../../../../../src/build/__fixtures__/basic/src/helpers/formatSum.ts"],"names":[],"mappings":";;;AAAO,MAAM,SAAS,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC;AAApD,QAAA,SAAS,aAA2C","sourcesContent":["export const formatSum = (sum: number): string => `added ${sum}`;\n"]}
@@ -0,0 +1,4 @@
1
+ import { AskResponse } from '@qpqjs/core';
2
+ export declare function add(drive: string, filepath: string, a: number, b: number): AskResponse<number>;
3
+ export declare const greet: (name: string) => string;
4
+ export declare const makeId: () => string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeId = exports.greet = void 0;
4
+ exports.add = add;
5
+ const core_1 = require("@qpqjs/core");
6
+ const uuidv7_1 = require("uuidv7");
7
+ const formatSum_1 = require("./helpers/formatSum");
8
+ function* add(drive, filepath, a, b) {
9
+ const sum = a + b;
10
+ yield* (0, core_1.askFileWriteTextContents)(drive, filepath, (0, formatSum_1.formatSum)(sum));
11
+ return sum;
12
+ }
13
+ const greet = (name) => `hello ${name}`;
14
+ exports.greet = greet;
15
+ const makeId = () => (0, uuidv7_1.uuidv7)();
16
+ exports.makeId = makeId;
17
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../../../src/build/__fixtures__/basic/src/main.ts"],"names":[],"mappings":";;;AAMA,kBAIC;AAVD,sCAAoE;AAEpE,mCAAgC;AAEhC,mDAAgD;AAEhD,QAAe,CAAC,CAAC,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAE,CAAS,EAAE,CAAS;IACxE,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,KAAK,CAAC,CAAC,IAAA,+BAAwB,EAAC,KAAK,EAAE,QAAQ,EAAE,IAAA,qBAAS,EAAC,GAAG,CAAC,CAAC,CAAC;IACjE,OAAO,GAAG,CAAC;AACb,CAAC;AAEM,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC;AAAlD,QAAA,KAAK,SAA6C;AAExD,MAAM,MAAM,GAAG,GAAW,EAAE,CAAC,IAAA,eAAM,GAAE,CAAC;AAAhC,QAAA,MAAM,UAA0B","sourcesContent":["import { askFileWriteTextContents, AskResponse } from '@qpqjs/core';\n\nimport { uuidv7 } from 'uuidv7';\n\nimport { formatSum } from './helpers/formatSum';\n\nexport function* add(drive: string, filepath: string, a: number, b: number): AskResponse<number> {\n const sum = a + b;\n yield* askFileWriteTextContents(drive, filepath, formatSum(sum));\n return sum;\n}\n\nexport const greet = (name: string): string => `hello ${name}`;\n\nexport const makeId = (): string => uuidv7();\n"]}
@@ -0,0 +1 @@
1
+ export declare const readIt: () => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readIt = void 0;
4
+ const fs_1 = require("fs");
5
+ const readIt = () => (0, fs_1.readFileSync)('/etc/hostname', 'utf8');
6
+ exports.readIt = readIt;
7
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../../../src/build/__fixtures__/builtin/src/main.ts"],"names":[],"mappings":";;;AAAA,2BAAkC;AAE3B,MAAM,MAAM,GAAG,GAAW,EAAE,CAAC,IAAA,iBAAY,EAAC,eAAe,EAAE,MAAM,CAAC,CAAC;AAA7D,QAAA,MAAM,UAAuD","sourcesContent":["import { readFileSync } from 'fs';\n\nexport const readIt = (): string => readFileSync('/etc/hostname', 'utf8');\n"]}
@@ -0,0 +1 @@
1
+ export declare const nothing: () => void;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nothing = void 0;
4
+ const nothing = () => { };
5
+ exports.nothing = nothing;
6
+ //# sourceMappingURL=notMain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notMain.js","sourceRoot":"","sources":["../../../../../../src/build/__fixtures__/noEntry/src/notMain.ts"],"names":[],"mappings":";;;AAAO,MAAM,OAAO,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;AAAzB,QAAA,OAAO,WAAkB","sourcesContent":["export const nothing = (): void => {};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const greet: (name: string) => string;
2
+ export declare const version = 3;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = exports.greet = void 0;
4
+ const greet = (name) => `hello ${name}`;
5
+ exports.greet = greet;
6
+ exports.version = 3;
7
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../../../src/build/__fixtures__/nonFunction/src/main.ts"],"names":[],"mappings":";;;AAAO,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC;AAAlD,QAAA,KAAK,SAA6C;AAClD,QAAA,OAAO,GAAG,CAAC,CAAC","sourcesContent":["export const greet = (name: string): string => `hello ${name}`;\nexport const version = 3;\n"]}
@@ -0,0 +1,6 @@
1
+ import { UserScriptModuleExports } from '@qpqjs/core';
2
+ /**
3
+ * The output contract, judged on what loading the built module reported: at least one export,
4
+ * and every export a function. Returns the function names in definition order.
5
+ */
6
+ export declare const assertUserScriptExports: (label: string, exports: UserScriptModuleExports) => string[];
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertUserScriptExports = void 0;
4
+ const UserScriptBuildError_1 = require("./UserScriptBuildError");
5
+ /**
6
+ * The output contract, judged on what loading the built module reported: at least one export,
7
+ * and every export a function. Returns the function names in definition order.
8
+ */
9
+ const assertUserScriptExports = (label, exports) => {
10
+ if (exports.functions.length === 0 && exports.nonFunctions.length === 0) {
11
+ throw new UserScriptBuildError_1.UserScriptBuildError(UserScriptBuildError_1.UserScriptBuildErrorCode.NoExports, `[${label}] exports nothing; a script must export at least one function`);
12
+ }
13
+ const [nonFunction] = exports.nonFunctions;
14
+ if (nonFunction) {
15
+ throw new UserScriptBuildError_1.UserScriptBuildError(UserScriptBuildError_1.UserScriptBuildErrorCode.NonFunctionExport, `[${label}] export [${nonFunction}] is not a function; a script may only export functions`);
16
+ }
17
+ return exports.functions;
18
+ };
19
+ exports.assertUserScriptExports = assertUserScriptExports;
20
+ //# sourceMappingURL=assertUserScriptExports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertUserScriptExports.js","sourceRoot":"","sources":["../../../src/build/assertUserScriptExports.ts"],"names":[],"mappings":";;;AAEA,iEAAwF;AAExF;;;GAGG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAAa,EAAE,OAAgC,EAAY,EAAE;IACnG,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,2CAAoB,CAAC,+CAAwB,CAAC,SAAS,EAAE,IAAI,KAAK,+DAA+D,CAAC,CAAC;IAC/I,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,IAAI,2CAAoB,CAC5B,+CAAwB,CAAC,iBAAiB,EAC1C,IAAI,KAAK,aAAa,WAAW,yDAAyD,CAC3F,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC,SAAS,CAAC;AAC3B,CAAC,CAAC;AAdW,QAAA,uBAAuB,2BAclC","sourcesContent":["import { UserScriptModuleExports } from '@qpqjs/core';\n\nimport { UserScriptBuildError, UserScriptBuildErrorCode } from './UserScriptBuildError';\n\n/**\n * The output contract, judged on what loading the built module reported: at least one export,\n * and every export a function. Returns the function names in definition order.\n */\nexport const assertUserScriptExports = (label: string, exports: UserScriptModuleExports): string[] => {\n if (exports.functions.length === 0 && exports.nonFunctions.length === 0) {\n throw new UserScriptBuildError(UserScriptBuildErrorCode.NoExports, `[${label}] exports nothing; a script must export at least one function`);\n }\n\n const [nonFunction] = exports.nonFunctions;\n if (nonFunction) {\n throw new UserScriptBuildError(\n UserScriptBuildErrorCode.NonFunctionExport,\n `[${label}] export [${nonFunction}] is not a function; a script may only export functions`,\n );\n }\n\n return exports.functions;\n};\n"]}
@@ -0,0 +1,15 @@
1
+ import { UserScriptModuleMap } from '@qpqjs/actionprocessor-node';
2
+ import { UserScriptBuildResult } from './UserScriptBuildResult';
3
+ export type BuildUserScriptOptions = {
4
+ projectDir: string;
5
+ outDir: string;
6
+ sourceMap?: boolean;
7
+ hostModules?: UserScriptModuleMap;
8
+ };
9
+ /**
10
+ * Builds a script project into `<outDir>/main.js`, the only file written. The output is not
11
+ * loaded here: a platform build has the sandbox report its exports (askUserScriptListExports)
12
+ * and a local build uses checkUserScriptOutput. Throws UserScriptBuildError; the `code` says
13
+ * whether the project or the bundle was at fault. `outDir` is emptied first.
14
+ */
15
+ export declare const buildUserScript: ({ projectDir, outDir, sourceMap, hostModules, }: BuildUserScriptOptions) => Promise<UserScriptBuildResult>;