piral-cli 1.0.0-pre.2296 → 1.0.1-beta.5640

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 (408) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +30 -7
  3. package/lib/api.js +23 -23
  4. package/lib/api.js.map +1 -1
  5. package/lib/apps/add-piral-instance-pilet.d.ts +26 -0
  6. package/lib/apps/add-piral-instance-pilet.js +53 -0
  7. package/lib/apps/add-piral-instance-pilet.js.map +1 -0
  8. package/lib/apps/build-pilet.d.ts +33 -2
  9. package/lib/apps/build-pilet.js +159 -32
  10. package/lib/apps/build-pilet.js.map +1 -1
  11. package/lib/apps/build-piral.d.ts +18 -1
  12. package/lib/apps/build-piral.js +68 -52
  13. package/lib/apps/build-piral.js.map +1 -1
  14. package/lib/apps/debug-pilet.d.ts +38 -2
  15. package/lib/apps/debug-pilet.js +150 -108
  16. package/lib/apps/debug-pilet.js.map +1 -1
  17. package/lib/apps/debug-piral.d.ts +23 -0
  18. package/lib/apps/debug-piral.js +63 -52
  19. package/lib/apps/debug-piral.js.map +1 -1
  20. package/lib/apps/declaration-piral.js +5 -3
  21. package/lib/apps/declaration-piral.js.map +1 -1
  22. package/lib/apps/index.d.ts +3 -0
  23. package/lib/apps/index.js +8 -1
  24. package/lib/apps/index.js.map +1 -1
  25. package/lib/apps/new-pilet.d.ts +7 -3
  26. package/lib/apps/new-pilet.js +47 -52
  27. package/lib/apps/new-pilet.js.map +1 -1
  28. package/lib/apps/new-piral.d.ts +7 -3
  29. package/lib/apps/new-piral.js +33 -23
  30. package/lib/apps/new-piral.js.map +1 -1
  31. package/lib/apps/pack-pilet.d.ts +9 -0
  32. package/lib/apps/pack-pilet.js +6 -13
  33. package/lib/apps/pack-pilet.js.map +1 -1
  34. package/lib/apps/publish-pilet.d.ts +23 -3
  35. package/lib/apps/publish-pilet.js +112 -62
  36. package/lib/apps/publish-pilet.js.map +1 -1
  37. package/lib/apps/publish-piral.d.ts +6 -2
  38. package/lib/apps/publish-piral.js +30 -26
  39. package/lib/apps/publish-piral.js.map +1 -1
  40. package/lib/apps/remove-piral-instance-pilet.d.ts +22 -0
  41. package/lib/apps/remove-piral-instance-pilet.js +52 -0
  42. package/lib/apps/remove-piral-instance-pilet.js.map +1 -0
  43. package/lib/apps/run-emulator-piral.d.ts +34 -0
  44. package/lib/apps/run-emulator-piral.js +91 -0
  45. package/lib/apps/run-emulator-piral.js.map +1 -0
  46. package/lib/apps/upgrade-pilet.d.ts +6 -2
  47. package/lib/apps/upgrade-pilet.js +41 -43
  48. package/lib/apps/upgrade-pilet.js.map +1 -1
  49. package/lib/apps/upgrade-piral.d.ts +2 -2
  50. package/lib/apps/upgrade-piral.js +21 -20
  51. package/lib/apps/upgrade-piral.js.map +1 -1
  52. package/lib/apps/validate-pilet.js +30 -36
  53. package/lib/apps/validate-pilet.js.map +1 -1
  54. package/lib/apps/validate-piral.js +13 -10
  55. package/lib/apps/validate-piral.js.map +1 -1
  56. package/lib/build/bundler-calls.d.ts +3 -0
  57. package/lib/build/bundler-calls.js +117 -0
  58. package/lib/build/bundler-calls.js.map +1 -0
  59. package/lib/build/run-build-pilet.d.ts +1 -0
  60. package/lib/build/run-build-pilet.js +65 -0
  61. package/lib/build/run-build-pilet.js.map +1 -0
  62. package/lib/build/run-build-piral.d.ts +1 -0
  63. package/lib/build/run-build-piral.js +67 -0
  64. package/lib/build/run-build-piral.js.map +1 -0
  65. package/lib/build/run-debug-mono-piral.d.ts +1 -0
  66. package/lib/build/run-debug-mono-piral.js +70 -0
  67. package/lib/build/run-debug-mono-piral.js.map +1 -0
  68. package/lib/build/run-debug-pilet.d.ts +1 -0
  69. package/lib/build/run-debug-pilet.js +89 -0
  70. package/lib/build/run-debug-pilet.js.map +1 -0
  71. package/lib/build/run-debug-piral.d.ts +1 -0
  72. package/lib/build/run-debug-piral.js +85 -0
  73. package/lib/build/run-debug-piral.js.map +1 -0
  74. package/lib/bundler.js +75 -26
  75. package/lib/bundler.js.map +1 -1
  76. package/lib/cli.js +7 -4
  77. package/lib/cli.js.map +1 -1
  78. package/lib/commands.js +266 -46
  79. package/lib/commands.js.map +1 -1
  80. package/lib/common/archive.d.ts +4 -0
  81. package/lib/common/archive.js +31 -10
  82. package/lib/common/archive.js.map +1 -1
  83. package/lib/common/browser.d.ts +2 -1
  84. package/lib/common/browser.js +17 -8
  85. package/lib/common/browser.js.map +1 -1
  86. package/lib/common/clients/index.d.ts +21 -0
  87. package/lib/common/clients/index.js +48 -0
  88. package/lib/common/clients/index.js.map +1 -0
  89. package/lib/common/clients/lerna.d.ts +7 -1
  90. package/lib/common/clients/lerna.js +93 -7
  91. package/lib/common/clients/lerna.js.map +1 -1
  92. package/lib/common/clients/npm.d.ts +6 -1
  93. package/lib/common/clients/npm.js +66 -18
  94. package/lib/common/clients/npm.js.map +1 -1
  95. package/lib/common/clients/pnp.d.ts +7 -0
  96. package/lib/common/clients/pnp.js +104 -0
  97. package/lib/common/clients/pnp.js.map +1 -0
  98. package/lib/common/clients/pnpm.d.ts +5 -0
  99. package/lib/common/clients/pnpm.js +55 -6
  100. package/lib/common/clients/pnpm.js.map +1 -1
  101. package/lib/common/clients/rush.d.ts +7 -0
  102. package/lib/common/clients/rush.js +127 -0
  103. package/lib/common/clients/rush.js.map +1 -0
  104. package/lib/common/clients/yarn.d.ts +5 -0
  105. package/lib/common/clients/yarn.js +57 -6
  106. package/lib/common/clients/yarn.js.map +1 -1
  107. package/lib/common/compatibility.js +14 -9
  108. package/lib/common/compatibility.js.map +1 -1
  109. package/lib/common/config.d.ts +52 -1
  110. package/lib/common/config.js +10 -30
  111. package/lib/common/config.js.map +1 -1
  112. package/lib/common/constants.d.ts +10 -2
  113. package/lib/common/constants.js +22 -4
  114. package/lib/common/constants.js.map +1 -1
  115. package/lib/common/declaration.d.ts +2 -1
  116. package/lib/common/declaration.js +113 -56
  117. package/lib/common/declaration.js.map +1 -1
  118. package/lib/common/emoji.d.ts +8 -0
  119. package/lib/common/emoji.js +10 -1
  120. package/lib/common/emoji.js.map +1 -1
  121. package/lib/common/emulator.d.ts +2 -2
  122. package/lib/common/emulator.js +45 -32
  123. package/lib/common/emulator.js.map +1 -1
  124. package/lib/common/enums.d.ts +0 -4
  125. package/lib/common/enums.js +1 -6
  126. package/lib/common/enums.js.map +1 -1
  127. package/lib/common/envs.js +16 -5
  128. package/lib/common/envs.js.map +1 -1
  129. package/lib/common/hash.d.ts +1 -0
  130. package/lib/common/hash.js +8 -3
  131. package/lib/common/hash.js.map +1 -1
  132. package/lib/common/http.d.ts +5 -2
  133. package/lib/common/http.js +65 -23
  134. package/lib/common/http.js.map +1 -1
  135. package/lib/common/importmap.d.ts +2 -0
  136. package/lib/common/importmap.js +202 -0
  137. package/lib/common/importmap.js.map +1 -0
  138. package/lib/common/index.d.ts +10 -0
  139. package/lib/common/index.js +15 -1
  140. package/lib/common/index.js.map +1 -1
  141. package/lib/common/info.d.ts +5 -0
  142. package/lib/common/info.js +9 -2
  143. package/lib/common/info.js.map +1 -1
  144. package/lib/common/injectors.d.ts +36 -8
  145. package/lib/common/injectors.js +46 -19
  146. package/lib/common/injectors.js.map +1 -1
  147. package/lib/common/inspect.d.ts +5 -3
  148. package/lib/common/inspect.js +15 -15
  149. package/lib/common/inspect.js.map +1 -1
  150. package/lib/common/interactive.d.ts +9 -0
  151. package/lib/common/interactive.js +60 -1
  152. package/lib/common/interactive.js.map +1 -1
  153. package/lib/common/io.d.ts +9 -3
  154. package/lib/common/io.js +219 -116
  155. package/lib/common/io.js.map +1 -1
  156. package/lib/common/language.d.ts +9 -6
  157. package/lib/common/language.js +68 -12
  158. package/lib/common/language.js.map +1 -1
  159. package/lib/common/log.d.ts +5 -3
  160. package/lib/common/log.js +34 -48
  161. package/lib/common/log.js.map +1 -1
  162. package/lib/common/npm.d.ts +17 -16
  163. package/lib/common/npm.js +262 -158
  164. package/lib/common/npm.js.map +1 -1
  165. package/lib/common/pack.js +47 -26
  166. package/lib/common/pack.js.map +1 -1
  167. package/lib/common/package.d.ts +43 -20
  168. package/lib/common/package.js +377 -213
  169. package/lib/common/package.js.map +1 -1
  170. package/lib/common/parallel.d.ts +1 -0
  171. package/lib/common/parallel.js +29 -0
  172. package/lib/common/parallel.js.map +1 -0
  173. package/lib/common/patcher.js +20 -20
  174. package/lib/common/patcher.js.map +1 -1
  175. package/lib/common/platform.d.ts +13 -0
  176. package/lib/common/platform.js +29 -0
  177. package/lib/common/platform.js.map +1 -0
  178. package/lib/common/port.d.ts +1 -0
  179. package/lib/common/port.js +14 -4
  180. package/lib/common/port.js.map +1 -1
  181. package/lib/common/rules.js +4 -4
  182. package/lib/common/rules.js.map +1 -1
  183. package/lib/common/scaffold.d.ts +18 -4
  184. package/lib/common/scaffold.js +59 -36
  185. package/lib/common/scaffold.js.map +1 -1
  186. package/lib/common/scripts.js +8 -8
  187. package/lib/common/scripts.js.map +1 -1
  188. package/lib/common/shell.d.ts +2 -0
  189. package/lib/common/shell.js +33 -0
  190. package/lib/common/shell.js.map +1 -0
  191. package/lib/common/spec.d.ts +29 -0
  192. package/lib/common/spec.js +69 -0
  193. package/lib/common/spec.js.map +1 -0
  194. package/lib/common/template.d.ts +1 -2
  195. package/lib/common/template.js +23 -22
  196. package/lib/common/template.js.map +1 -1
  197. package/lib/common/url.d.ts +1 -0
  198. package/lib/common/url.js +17 -0
  199. package/lib/common/url.js.map +1 -0
  200. package/lib/common/utils.d.ts +1 -0
  201. package/lib/common/utils.js +8 -0
  202. package/lib/common/utils.js.map +1 -0
  203. package/lib/common/version.d.ts +2 -0
  204. package/lib/common/version.js +130 -0
  205. package/lib/common/version.js.map +1 -0
  206. package/lib/common/watcher.d.ts +13 -0
  207. package/lib/common/watcher.js +78 -0
  208. package/lib/common/watcher.js.map +1 -0
  209. package/lib/external/index.js +59413 -57862
  210. package/lib/helpers.d.ts +6 -6
  211. package/lib/helpers.js +10 -25
  212. package/lib/helpers.js.map +1 -1
  213. package/lib/index.js +5 -1
  214. package/lib/index.js.map +1 -1
  215. package/lib/inject.js +2 -2
  216. package/lib/inject.js.map +1 -1
  217. package/lib/injectors/pilet-injector.d.ts +75 -0
  218. package/lib/injectors/pilet-injector.js +246 -0
  219. package/lib/injectors/pilet-injector.js.map +1 -0
  220. package/lib/injectors/{piral.d.ts → piral-injector.d.ts} +10 -2
  221. package/lib/injectors/piral-injector.js +97 -0
  222. package/lib/injectors/piral-injector.js.map +1 -0
  223. package/lib/messages.d.ts +567 -47
  224. package/lib/messages.js +638 -51
  225. package/lib/messages.js.map +1 -1
  226. package/lib/pb-cli.js +1 -1
  227. package/lib/pb-cli.js.map +1 -1
  228. package/lib/pilet-cli.js +1 -1
  229. package/lib/pilet-cli.js.map +1 -1
  230. package/lib/piral-cli.js +1 -1
  231. package/lib/piral-cli.js.map +1 -1
  232. package/lib/platforms/node.d.ts +8 -0
  233. package/lib/platforms/node.js +30 -0
  234. package/lib/platforms/node.js.map +1 -0
  235. package/lib/platforms/web.d.ts +8 -0
  236. package/lib/platforms/web.js +120 -0
  237. package/lib/platforms/web.js.map +1 -0
  238. package/lib/plugin.js +36 -11
  239. package/lib/plugin.js.map +1 -1
  240. package/lib/questionnaire.d.ts +1 -1
  241. package/lib/questionnaire.js +9 -4
  242. package/lib/questionnaire.js.map +1 -1
  243. package/lib/release.d.ts +1 -1
  244. package/lib/release.js +38 -6
  245. package/lib/release.js.map +1 -1
  246. package/lib/resolvers.js +13 -13
  247. package/lib/resolvers.js.map +1 -1
  248. package/lib/rules/index.js +8 -8
  249. package/lib/rules/index.js.map +1 -1
  250. package/lib/rules/pilet-has-externals-as-peers.d.ts +1 -1
  251. package/lib/rules/pilet-has-externals-as-peers.js +9 -7
  252. package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
  253. package/lib/rules/pilet-has-no-self-reference.d.ts +1 -1
  254. package/lib/rules/pilet-has-no-self-reference.js +2 -2
  255. package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
  256. package/lib/rules/pilet-has-no-third-party-dependency.d.ts +1 -1
  257. package/lib/rules/pilet-stays-small.d.ts +1 -1
  258. package/lib/rules/pilet-stays-small.js +4 -4
  259. package/lib/rules/pilet-stays-small.js.map +1 -1
  260. package/lib/rules/pilet-uses-latest-piral.d.ts +1 -1
  261. package/lib/rules/pilet-uses-latest-piral.js +18 -9
  262. package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
  263. package/lib/rules/piral-depends-on-piral.d.ts +1 -1
  264. package/lib/rules/piral-entry-ends-with-html.d.ts +1 -1
  265. package/lib/rules/piral-entry-ends-with-html.js +1 -1
  266. package/lib/rules/piral-entry-ends-with-html.js.map +1 -1
  267. package/lib/rules/piral-has-valid-devDependencies.d.ts +1 -1
  268. package/lib/rules/piral-has-valid-externals.d.ts +1 -1
  269. package/lib/rules/piral-has-valid-externals.js +10 -24
  270. package/lib/rules/piral-has-valid-externals.js.map +1 -1
  271. package/lib/rules/piral-has-valid-files.d.ts +1 -1
  272. package/lib/rules/piral-has-valid-files.js +5 -5
  273. package/lib/rules/piral-has-valid-files.js.map +1 -1
  274. package/lib/rules/piral-has-valid-scripts.d.ts +1 -1
  275. package/lib/runner.js +1 -1
  276. package/lib/runner.js.map +1 -1
  277. package/lib/select.js +6 -6
  278. package/lib/select.js.map +1 -1
  279. package/lib/types/common.d.ts +88 -8
  280. package/lib/types/common.js.map +1 -1
  281. package/lib/types/index.js +5 -1
  282. package/lib/types/index.js.map +1 -1
  283. package/lib/types/internal.d.ts +12 -13
  284. package/lib/types/public.d.ts +89 -23
  285. package/package.json +19 -16
  286. package/src/apps/add-piral-instance-pilet.ts +98 -0
  287. package/src/apps/build-pilet.ts +286 -38
  288. package/src/apps/build-piral.test.ts +20 -7
  289. package/src/apps/build-piral.ts +90 -39
  290. package/src/apps/debug-pilet.ts +229 -123
  291. package/src/apps/debug-piral.ts +121 -68
  292. package/src/apps/declaration-piral.ts +4 -2
  293. package/src/apps/index.ts +3 -0
  294. package/src/apps/new-pilet.test.ts +28 -11
  295. package/src/apps/new-pilet.ts +60 -48
  296. package/src/apps/new-piral.test.ts +25 -13
  297. package/src/apps/new-piral.ts +43 -19
  298. package/src/apps/pack-pilet.test.ts +2 -2
  299. package/src/apps/pack-pilet.ts +12 -10
  300. package/src/apps/publish-pilet.ts +148 -43
  301. package/src/apps/publish-piral.ts +38 -11
  302. package/src/apps/remove-piral-instance-pilet.ts +92 -0
  303. package/src/apps/run-emulator-piral.ts +154 -0
  304. package/src/apps/upgrade-pilet.ts +37 -31
  305. package/src/apps/upgrade-piral.ts +9 -7
  306. package/src/apps/validate-pilet.ts +30 -22
  307. package/src/apps/validate-piral.ts +5 -2
  308. package/src/build/bundler-calls.ts +133 -0
  309. package/src/build/run-build-pilet.ts +91 -0
  310. package/src/build/run-build-piral.ts +93 -0
  311. package/src/build/run-debug-mono-piral.ts +86 -0
  312. package/src/build/run-debug-pilet.ts +116 -0
  313. package/src/build/run-debug-piral.ts +105 -0
  314. package/src/bundler.test.ts +86 -68
  315. package/src/bundler.ts +74 -19
  316. package/src/cli.ts +6 -2
  317. package/src/commands.ts +273 -44
  318. package/src/common/archive.test.ts +51 -45
  319. package/src/common/archive.ts +28 -1
  320. package/src/common/browser.test.ts +20 -10
  321. package/src/common/browser.ts +13 -6
  322. package/src/common/clients/index.ts +41 -0
  323. package/src/common/clients/lerna.ts +85 -1
  324. package/src/common/clients/npm.ts +56 -14
  325. package/src/common/clients/pnp.ts +84 -0
  326. package/src/common/clients/pnpm.ts +45 -1
  327. package/src/common/clients/rush.ts +118 -0
  328. package/src/common/clients/yarn.ts +49 -3
  329. package/src/common/compatibility.ts +8 -1
  330. package/src/common/config.ts +57 -22
  331. package/src/common/constants.ts +21 -3
  332. package/src/common/declaration.ts +124 -50
  333. package/src/common/emoji.ts +9 -0
  334. package/src/common/emulator.ts +43 -23
  335. package/src/common/enums.ts +0 -5
  336. package/src/common/envs.ts +15 -3
  337. package/src/common/hash.ts +5 -0
  338. package/src/common/http.test.ts +76 -64
  339. package/src/common/http.ts +88 -24
  340. package/src/common/importmap.ts +242 -0
  341. package/src/common/index.ts +10 -0
  342. package/src/common/info.ts +9 -1
  343. package/src/common/injectors.ts +49 -22
  344. package/src/common/inspect.ts +13 -14
  345. package/src/common/interactive.test.ts +6 -0
  346. package/src/common/interactive.ts +69 -1
  347. package/src/common/io.ts +199 -82
  348. package/src/common/language.ts +87 -10
  349. package/src/common/log.ts +32 -46
  350. package/src/common/npm.test.ts +187 -166
  351. package/src/common/npm.ts +263 -119
  352. package/src/common/pack.test.ts +11 -13
  353. package/src/common/pack.ts +60 -21
  354. package/src/common/package.test.ts +59 -49
  355. package/src/common/package.ts +406 -167
  356. package/src/common/parallel.test.ts +28 -0
  357. package/src/common/parallel.ts +21 -0
  358. package/src/common/platform.ts +31 -0
  359. package/src/common/port.test.ts +4 -1
  360. package/src/common/port.ts +10 -0
  361. package/src/common/rules.test.ts +3 -3
  362. package/src/common/scaffold.ts +69 -41
  363. package/src/common/scripts.ts +5 -4
  364. package/src/common/shell.ts +34 -0
  365. package/src/common/spec.ts +69 -0
  366. package/src/common/template.ts +20 -18
  367. package/src/common/url.test.ts +28 -0
  368. package/src/common/url.ts +15 -0
  369. package/src/common/utils.ts +3 -0
  370. package/src/common/version.test.ts +233 -0
  371. package/src/common/version.ts +142 -0
  372. package/src/common/watcher.ts +89 -0
  373. package/src/external/index.test.ts +2 -2
  374. package/src/external/index.ts +7 -3
  375. package/src/external/resolve.ts +29 -0
  376. package/src/helpers.test.ts +2 -22
  377. package/src/helpers.ts +21 -30
  378. package/src/injectors/{pilet.test.ts → pilet-injector.test.ts} +13 -4
  379. package/src/injectors/pilet-injector.ts +346 -0
  380. package/src/injectors/{piral.test.ts → piral-injector.test.ts} +14 -5
  381. package/src/injectors/piral-injector.ts +130 -0
  382. package/src/messages.ts +649 -63
  383. package/src/platforms/node.ts +16 -0
  384. package/src/platforms/web.ts +148 -0
  385. package/src/plugin.ts +34 -5
  386. package/src/questionnaire.ts +17 -3
  387. package/src/release.ts +47 -5
  388. package/src/rules/index.ts +1 -1
  389. package/src/rules/pilet-has-externals-as-peers.test.ts +3 -2
  390. package/src/rules/pilet-has-externals-as-peers.ts +9 -7
  391. package/src/rules/pilet-has-no-self-reference.ts +1 -1
  392. package/src/rules/pilet-stays-small.ts +1 -1
  393. package/src/rules/pilet-uses-latest-piral.ts +22 -12
  394. package/src/rules/piral-has-valid-externals.ts +10 -29
  395. package/src/types/common.ts +99 -9
  396. package/src/types/internal.ts +14 -14
  397. package/src/types/public.ts +93 -27
  398. package/lib/external/child.js +0 -144
  399. package/lib/external/classes.trie +0 -0
  400. package/lib/external/xdg-open +0 -1066
  401. package/lib/injectors/pilet.d.ts +0 -47
  402. package/lib/injectors/pilet.js +0 -187
  403. package/lib/injectors/pilet.js.map +0 -1
  404. package/lib/injectors/piral.js +0 -62
  405. package/lib/injectors/piral.js.map +0 -1
  406. package/src/injectors/pilet.ts +0 -219
  407. package/src/injectors/piral.ts +0 -76
  408. package/templates/piral-index.js.ejs +0 -16
@@ -1,47 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfiguration, KrasResult } from 'kras';
4
- import { Bundler } from '../types';
5
- interface Pilet {
6
- bundler: Bundler;
7
- root: string;
8
- requireRef?: string;
9
- }
10
- export interface PiletInjectorConfig extends KrasInjectorConfig {
11
- pilets: Array<Pilet>;
12
- api: string;
13
- app: string;
14
- feed?: string;
15
- }
16
- interface PiletMetadata {
17
- name?: string;
18
- [key: string]: unknown;
19
- }
20
- export default class PiletInjector implements KrasInjector {
21
- config: PiletInjectorConfig;
22
- private piletApi;
23
- constructor(options: PiletInjectorConfig, config: KrasConfiguration, core: EventEmitter);
24
- get active(): boolean;
25
- set active(value: boolean);
26
- get name(): string;
27
- getOptions(): {};
28
- setOptions(): void;
29
- getMetaOf(index: number): {
30
- name: any;
31
- version: any;
32
- link: string;
33
- hash: string;
34
- requireRef: string;
35
- noCache: boolean;
36
- custom: any;
37
- };
38
- getMeta(): Promise<string>;
39
- loadRemoteFeed(feed?: string): Promise<Array<PiletMetadata>>;
40
- mergePilets(localPilets: Array<PiletMetadata>, remotePilets: Array<PiletMetadata>): PiletMetadata[];
41
- sendContent(content: Buffer | string, type: string, url: string): KrasResponse;
42
- sendFile(target: string, url: string): KrasResponse;
43
- sendResponse(path: string, url: string): Promise<KrasResult>;
44
- sendIndexFile(target: string, url: string): KrasResponse;
45
- handle(req: KrasRequest): KrasResponse;
46
- }
47
- export {};
@@ -1,187 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const path_1 = require("path");
13
- const fs_1 = require("fs");
14
- const external_1 = require("../external");
15
- const log_1 = require("../common/log");
16
- class PiletInjector {
17
- constructor(options, config, core) {
18
- this.config = options;
19
- // either take a full URI or make it an absolute path relative to the current origin
20
- this.piletApi = /^https?:/.test(options.api)
21
- ? options.api
22
- : `${config.ssl ? 'https' : 'http'}://localhost:${config.port}${options.api}`;
23
- const { pilets, api } = options;
24
- const cbs = {};
25
- core.on('user-connected', (e) => {
26
- if (e.target === '*' && e.url === api.substr(1)) {
27
- cbs[e.id] = (msg) => e.ws.send(msg);
28
- }
29
- });
30
- core.on('user-disconnected', (e) => {
31
- delete cbs[e.id];
32
- });
33
- pilets.forEach((p, i) => p.bundler.on(({ requireRef, version }) => {
34
- p.requireRef = version === 'v1' ? requireRef : undefined;
35
- const meta = JSON.stringify(this.getMetaOf(i));
36
- for (const id of Object.keys(cbs)) {
37
- cbs[id](meta);
38
- }
39
- }));
40
- }
41
- get active() {
42
- return this.config.active;
43
- }
44
- set active(value) {
45
- this.config.active = value;
46
- }
47
- get name() {
48
- return 'pilet-injector';
49
- }
50
- getOptions() {
51
- return {};
52
- }
53
- setOptions() { }
54
- getMetaOf(index) {
55
- const { api, pilets } = this.config;
56
- const { bundler, root, requireRef } = pilets[index];
57
- const def = JSON.parse(fs_1.readFileSync(path_1.join(root, 'package.json'), 'utf8'));
58
- const file = bundler.bundle.name.replace(/^\//, '');
59
- return {
60
- name: def.name,
61
- version: def.version,
62
- link: `${this.piletApi}/${index}/${file}`,
63
- hash: bundler.bundle.hash,
64
- requireRef,
65
- noCache: true,
66
- custom: def.custom,
67
- };
68
- }
69
- getMeta() {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const { pilets, feed } = this.config;
72
- const localPilets = pilets.map((_, i) => this.getMetaOf(i));
73
- const mergedPilets = this.mergePilets(localPilets, yield this.loadRemoteFeed(feed));
74
- if (mergedPilets.length === 1) {
75
- return JSON.stringify(mergedPilets[0]);
76
- }
77
- return JSON.stringify(mergedPilets);
78
- });
79
- }
80
- loadRemoteFeed(feed) {
81
- var _a;
82
- return __awaiter(this, void 0, void 0, function* () {
83
- if (feed) {
84
- try {
85
- const response = yield external_1.axios.default.get(feed);
86
- if (Array.isArray(response.data)) {
87
- return response.data;
88
- }
89
- else if (Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.items)) {
90
- return response.data.items;
91
- }
92
- else {
93
- return [response.data];
94
- }
95
- }
96
- catch (e) {
97
- log_1.log('generalWarning_0001', `Couldn't load feed at ${feed}.`);
98
- }
99
- }
100
- });
101
- }
102
- mergePilets(localPilets, remotePilets) {
103
- if (!remotePilets) {
104
- return localPilets;
105
- }
106
- const names = localPilets.map((pilet) => pilet.name);
107
- const merged = [
108
- ...localPilets,
109
- ...remotePilets.filter((pilet) => pilet.name !== undefined && !names.includes(pilet.name)),
110
- ];
111
- return merged;
112
- }
113
- sendContent(content, type, url) {
114
- return {
115
- injector: { name: this.name },
116
- headers: {
117
- 'content-type': type,
118
- 'cache-control': 'no-cache, no-store, must-revalidate',
119
- pragma: 'no-cache',
120
- expires: '0',
121
- },
122
- status: { code: 200 },
123
- url,
124
- content,
125
- };
126
- }
127
- sendFile(target, url) {
128
- var _a;
129
- const content = fs_1.readFileSync(target);
130
- const type = (_a = external_1.mime.getType(target)) !== null && _a !== void 0 ? _a : 'application/octet-stream';
131
- return this.sendContent(content, type, url);
132
- }
133
- sendResponse(path, url) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- const { pilets } = this.config;
136
- const [index, ...rest] = path.split('/');
137
- const pilet = pilets[+index];
138
- const bundler = pilet === null || pilet === void 0 ? void 0 : pilet.bundler;
139
- if (!path) {
140
- yield (bundler === null || bundler === void 0 ? void 0 : bundler.ready());
141
- const content = yield this.getMeta();
142
- return this.sendContent(content, 'application/json', url);
143
- }
144
- else {
145
- return bundler === null || bundler === void 0 ? void 0 : bundler.ready().then(() => {
146
- const target = path_1.join(bundler.bundle.dir, rest.join('/'));
147
- if (fs_1.existsSync(target) && fs_1.statSync(target).isFile()) {
148
- return this.sendFile(target, url);
149
- }
150
- });
151
- }
152
- });
153
- }
154
- sendIndexFile(target, url) {
155
- const indexHtml = fs_1.readFileSync(target, 'utf8');
156
- // mechanism to inject server side debug piletApi config into piral emulator
157
- const windowInjectionScript = `window['dbg:pilet-api'] = '${this.piletApi}';`;
158
- const findStr = `<script`;
159
- const replaceStr = `<script>/* Pilet Debugging Emulator Config Injection */${windowInjectionScript}</script><script`;
160
- const content = indexHtml.replace(`${findStr}`, `${replaceStr}`);
161
- return this.sendContent(content, external_1.mime.getType(target), url);
162
- }
163
- handle(req) {
164
- const { app, api } = this.config;
165
- const path = req.url.substr(1).split('?')[0];
166
- if (!req.target) {
167
- const target = path_1.join(app, path);
168
- if (fs_1.existsSync(target) && fs_1.statSync(target).isFile()) {
169
- if (req.url === '/index.html') {
170
- return this.sendIndexFile(target, req.url);
171
- }
172
- return this.sendFile(target, req.url);
173
- }
174
- else if (req.url !== '/index.html') {
175
- return this.handle(Object.assign(Object.assign({}, req), { url: '/index.html' }));
176
- }
177
- else {
178
- return undefined;
179
- }
180
- }
181
- else if (req.target === api) {
182
- return this.sendResponse(path, req.url);
183
- }
184
- }
185
- }
186
- exports.default = PiletInjector;
187
- //# sourceMappingURL=pilet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pilet.js","sourceRoot":"","sources":["../../src/injectors/pilet.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+BAA4B;AAE5B,2BAAwD;AAExD,0CAA0C;AAE1C,uCAAoC;AAoBpC,MAAqB,aAAa;IAIhC,YAAY,OAA4B,EAAE,MAAyB,EAAE,IAAkB;QACrF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;QACtB,oFAAoF;QACpF,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;YAC1C,CAAC,CAAC,OAAO,CAAC,GAAG;YACb,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,gBAAgB,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAEhF,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QAChC,MAAM,GAAG,GAAG,EAAE,CAAC;QAEf,IAAI,CAAC,EAAE,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE;YAC9B,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;gBAC/C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,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CACb,GAAG,KACN,GAAG,EAAE,aAAa,IAClB,CAAC;aACJ;iBAAM;gBACL,OAAO,SAAS,CAAC;aAClB;SACF;aAAM,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;YAC7B,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;SACzC;IACH,CAAC;CACF;AAhMD,gCAgMC"}
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- const fs_1 = require("fs");
5
- const external_1 = require("../external");
6
- /**
7
- * The maximum amount of retries when sending a response
8
- */
9
- const maxRetrySendResponse = 4;
10
- class PiralInjector {
11
- constructor(options) {
12
- this.config = options;
13
- }
14
- get active() {
15
- return this.config.active;
16
- }
17
- set active(value) {
18
- this.config.active = value;
19
- }
20
- get name() {
21
- return 'piral-injector';
22
- }
23
- getOptions() {
24
- return {};
25
- }
26
- setOptions() { }
27
- sendResponse(path, target, dir, url, recursionDepth = 0) {
28
- var _a;
29
- if (recursionDepth > maxRetrySendResponse) {
30
- return undefined;
31
- }
32
- if (!path || !fs_1.existsSync(target) || !fs_1.statSync(target).isFile()) {
33
- const { bundler } = this.config;
34
- const newTarget = path_1.join(bundler.bundle.dir, bundler.bundle.name);
35
- return this.sendResponse(bundler.bundle.name, newTarget, dir, url, recursionDepth + 1);
36
- }
37
- const type = (_a = external_1.mime.getType(target)) !== null && _a !== void 0 ? _a : 'application/octet-stream';
38
- return {
39
- injector: { name: this.name },
40
- headers: {
41
- 'content-type': type,
42
- 'cache-control': 'no-cache, no-store, must-revalidate',
43
- pragma: 'no-cache',
44
- expires: '0',
45
- },
46
- status: { code: 200 },
47
- url,
48
- content: fs_1.readFileSync(target),
49
- };
50
- }
51
- handle(req) {
52
- if (!req.target) {
53
- const { bundler } = this.config;
54
- const path = req.url.substr(1);
55
- const dir = bundler.bundle.dir;
56
- const target = path_1.join(dir, path.split('?')[0]);
57
- return bundler.ready().then(() => this.sendResponse(path, target, dir, req.url));
58
- }
59
- }
60
- }
61
- exports.default = PiralInjector;
62
- //# sourceMappingURL=piral.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"piral.js","sourceRoot":"","sources":["../../src/injectors/piral.ts"],"names":[],"mappings":";;AAAA,+BAA4B;AAC5B,2BAAwD;AAExD,0CAAmC;AAGnC;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAM/B,MAAqB,aAAa;IAGhC,YAAY,OAA4B;QACtC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IACD,IAAI,MAAM,CAAC,KAAK;QACd,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC;IAC7B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,UAAU;QACR,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,UAAU,KAAI,CAAC;IAEf,YAAY,CAAC,IAAY,EAAE,MAAc,EAAE,GAAW,EAAE,GAAW,EAAE,cAAc,GAAG,CAAC;;QACrF,IAAI,cAAc,GAAG,oBAAoB,EAAE;YACzC,OAAO,SAAS,CAAC;SAClB;QAED,IAAI,CAAC,IAAI,IAAI,CAAC,eAAU,CAAC,MAAM,CAAC,IAAI,CAAC,aAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;YAC9D,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;YAChC,MAAM,SAAS,GAAG,WAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAChE,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,cAAc,GAAG,CAAC,CAAC,CAAC;SACxF;QAED,MAAM,IAAI,SAAG,eAAI,CAAC,OAAO,CAAC,MAAM,CAAC,mCAAI,0BAA0B,CAAC;QAEhE,OAAO;YACL,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YAC7B,OAAO,EAAE;gBACP,cAAc,EAAE,IAAI;gBACpB,eAAe,EAAE,qCAAqC;gBACtD,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,GAAG;aACb;YACD,MAAM,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE;YACrB,GAAG;YACH,OAAO,EAAE,iBAAY,CAAC,MAAM,CAAC;SAC9B,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,GAAgB;QACrB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;YACf,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;YAChC,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC;YAC/B,MAAM,MAAM,GAAG,WAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;SAClF;IACH,CAAC;CACF;AA5DD,gCA4DC"}
@@ -1,219 +0,0 @@
1
- import { join } from 'path';
2
- import { EventEmitter } from 'events';
3
- import { readFileSync, existsSync, statSync } from 'fs';
4
- import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig, KrasConfiguration, KrasResult } from 'kras';
5
- import { axios, mime } from '../external';
6
- import { Bundler } from '../types';
7
- import { log } from '../common/log';
8
-
9
- interface Pilet {
10
- bundler: Bundler;
11
- root: string;
12
- requireRef?: string;
13
- }
14
-
15
- export interface PiletInjectorConfig extends KrasInjectorConfig {
16
- pilets: Array<Pilet>;
17
- api: string;
18
- app: string;
19
- feed?: string;
20
- }
21
-
22
- interface PiletMetadata {
23
- name?: string;
24
- [key: string]: unknown;
25
- }
26
-
27
- export default class PiletInjector implements KrasInjector {
28
- public config: PiletInjectorConfig;
29
- private piletApi: string;
30
-
31
- constructor(options: PiletInjectorConfig, config: KrasConfiguration, core: EventEmitter) {
32
- this.config = options;
33
- // either take a full URI or make it an absolute path relative to the current origin
34
- this.piletApi = /^https?:/.test(options.api)
35
- ? options.api
36
- : `${config.ssl ? 'https' : 'http'}://localhost:${config.port}${options.api}`;
37
-
38
- const { pilets, api } = options;
39
- const cbs = {};
40
-
41
- core.on('user-connected', (e) => {
42
- if (e.target === '*' && e.url === api.substr(1)) {
43
- cbs[e.id] = (msg: string) => e.ws.send(msg);
44
- }
45
- });
46
-
47
- core.on('user-disconnected', (e) => {
48
- delete cbs[e.id];
49
- });
50
-
51
- pilets.forEach((p, i) =>
52
- p.bundler.on(({ requireRef, version }) => {
53
- p.requireRef = version === 'v1' ? requireRef : undefined;
54
- const meta = JSON.stringify(this.getMetaOf(i));
55
-
56
- for (const id of Object.keys(cbs)) {
57
- cbs[id](meta);
58
- }
59
- }),
60
- );
61
- }
62
-
63
- get active() {
64
- return this.config.active;
65
- }
66
- set active(value) {
67
- this.config.active = value;
68
- }
69
-
70
- get name() {
71
- return 'pilet-injector';
72
- }
73
-
74
- getOptions() {
75
- return {};
76
- }
77
-
78
- setOptions() {}
79
-
80
- getMetaOf(index: number) {
81
- const { api, pilets } = this.config;
82
- const { bundler, root, requireRef } = pilets[index];
83
- const def = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
84
- const file = bundler.bundle.name.replace(/^\//, '');
85
- return {
86
- name: def.name,
87
- version: def.version,
88
- link: `${this.piletApi}/${index}/${file}`,
89
- hash: bundler.bundle.hash,
90
- requireRef,
91
- noCache: true,
92
- custom: def.custom,
93
- };
94
- }
95
-
96
- async getMeta() {
97
- const { pilets, feed } = this.config;
98
- const localPilets = pilets.map((_, i) => this.getMetaOf(i));
99
- const mergedPilets = this.mergePilets(localPilets, await this.loadRemoteFeed(feed));
100
-
101
- if (mergedPilets.length === 1) {
102
- return JSON.stringify(mergedPilets[0]);
103
- }
104
-
105
- return JSON.stringify(mergedPilets);
106
- }
107
-
108
- async loadRemoteFeed(feed?: string): Promise<Array<PiletMetadata>> {
109
- if (feed) {
110
- try {
111
- const response = await axios.default.get<{ items?: Array<PiletMetadata> } | Array<PiletMetadata> | PiletMetadata>(feed);
112
-
113
- if (Array.isArray(response.data)) {
114
- return response.data;
115
- } else if (Array.isArray(response.data?.items)) {
116
- return response.data.items;
117
- } else {
118
- return [response.data];
119
- }
120
- } catch (e) {
121
- log('generalWarning_0001', `Couldn't load feed at ${feed}.`);
122
- }
123
- }
124
-
125
- }
126
-
127
- mergePilets(localPilets: Array<PiletMetadata>, remotePilets: Array<PiletMetadata>) {
128
- if (!remotePilets) {
129
- return localPilets;
130
- }
131
-
132
- const names = localPilets.map((pilet) => pilet.name);
133
- const merged = [
134
- ...localPilets,
135
- ...remotePilets.filter((pilet) => pilet.name !== undefined && !names.includes(pilet.name)),
136
- ];
137
-
138
- return merged;
139
- }
140
-
141
- sendContent(content: Buffer | string, type: string, url: string): KrasResponse {
142
- return {
143
- injector: { name: this.name },
144
- headers: {
145
- 'content-type': type,
146
- 'cache-control': 'no-cache, no-store, must-revalidate',
147
- pragma: 'no-cache',
148
- expires: '0',
149
- },
150
- status: { code: 200 },
151
- url,
152
- content,
153
- };
154
- }
155
-
156
- sendFile(target: string, url: string): KrasResponse {
157
- const content = readFileSync(target);
158
- const type = mime.getType(target) ?? 'application/octet-stream';
159
- return this.sendContent(content, type, url);
160
- }
161
-
162
- async sendResponse(path: string, url: string): Promise<KrasResult> {
163
- const { pilets } = this.config;
164
- const [index, ...rest] = path.split('/');
165
- const pilet = pilets[+index];
166
- const bundler = pilet?.bundler;
167
-
168
- if (!path) {
169
- await bundler?.ready();
170
- const content = await this.getMeta();
171
- return this.sendContent(content, 'application/json', url);
172
- } else {
173
- return bundler?.ready().then(() => {
174
- const target = join(bundler.bundle.dir, rest.join('/'));
175
-
176
- if (existsSync(target) && statSync(target).isFile()) {
177
- return this.sendFile(target, url);
178
- }
179
- });
180
- }
181
- }
182
-
183
- sendIndexFile(target: string, url: string): KrasResponse {
184
- const indexHtml = readFileSync(target, 'utf8');
185
-
186
- // mechanism to inject server side debug piletApi config into piral emulator
187
- const windowInjectionScript = `window['dbg:pilet-api'] = '${this.piletApi}';`;
188
- const findStr = `<script`;
189
- const replaceStr = `<script>/* Pilet Debugging Emulator Config Injection */${windowInjectionScript}</script><script`;
190
- const content = indexHtml.replace(`${findStr}`, `${replaceStr}`);
191
-
192
- return this.sendContent(content, mime.getType(target), url);
193
- }
194
-
195
- handle(req: KrasRequest): KrasResponse {
196
- const { app, api } = this.config;
197
- const path = req.url.substr(1).split('?')[0];
198
-
199
- if (!req.target) {
200
- const target = join(app, path);
201
-
202
- if (existsSync(target) && statSync(target).isFile()) {
203
- if (req.url === '/index.html') {
204
- return this.sendIndexFile(target, req.url);
205
- }
206
- return this.sendFile(target, req.url);
207
- } else if (req.url !== '/index.html') {
208
- return this.handle({
209
- ...req,
210
- url: '/index.html',
211
- });
212
- } else {
213
- return undefined;
214
- }
215
- } else if (req.target === api) {
216
- return this.sendResponse(path, req.url);
217
- }
218
- }
219
- }
@@ -1,76 +0,0 @@
1
- import { join } from 'path';
2
- import { readFileSync, existsSync, statSync } from 'fs';
3
- import { KrasInjector, KrasResponse, KrasRequest, KrasInjectorConfig } from 'kras';
4
- import { mime } from '../external';
5
- import { Bundler } from '../types';
6
-
7
- /**
8
- * The maximum amount of retries when sending a response
9
- */
10
- const maxRetrySendResponse = 4;
11
-
12
- export interface PiralInjectorConfig extends KrasInjectorConfig {
13
- bundler: Bundler;
14
- }
15
-
16
- export default class PiralInjector implements KrasInjector {
17
- public config: PiralInjectorConfig;
18
-
19
- constructor(options: PiralInjectorConfig) {
20
- this.config = options;
21
- }
22
-
23
- get active() {
24
- return this.config.active;
25
- }
26
- set active(value) {
27
- this.config.active = value;
28
- }
29
-
30
- get name() {
31
- return 'piral-injector';
32
- }
33
-
34
- getOptions() {
35
- return {};
36
- }
37
-
38
- setOptions() {}
39
-
40
- sendResponse(path: string, target: string, dir: string, url: string, recursionDepth = 0): KrasResponse {
41
- if (recursionDepth > maxRetrySendResponse) {
42
- return undefined;
43
- }
44
-
45
- if (!path || !existsSync(target) || !statSync(target).isFile()) {
46
- const { bundler } = this.config;
47
- const newTarget = join(bundler.bundle.dir, bundler.bundle.name);
48
- return this.sendResponse(bundler.bundle.name, newTarget, dir, url, recursionDepth + 1);
49
- }
50
-
51
- const type = mime.getType(target) ?? 'application/octet-stream';
52
-
53
- return {
54
- injector: { name: this.name },
55
- headers: {
56
- 'content-type': type,
57
- 'cache-control': 'no-cache, no-store, must-revalidate',
58
- pragma: 'no-cache',
59
- expires: '0',
60
- },
61
- status: { code: 200 },
62
- url,
63
- content: readFileSync(target),
64
- };
65
- }
66
-
67
- handle(req: KrasRequest): KrasResponse {
68
- if (!req.target) {
69
- const { bundler } = this.config;
70
- const path = req.url.substr(1);
71
- const dir = bundler.bundle.dir;
72
- const target = join(dir, path.split('?')[0]);
73
- return bundler.ready().then(() => this.sendResponse(path, target, dir, req.url));
74
- }
75
- }
76
- }
@@ -1,16 +0,0 @@
1
- if (process.env.NODE_ENV === 'test') {
2
- // behavior for the test environment, we'll try to make it work
3
-
4
- if (typeof window !== 'undefined') {
5
- require('./<%- outFile %>');
6
- const ctx = window['dbg:piral'];
7
- const dependencies = (ctx && ctx.pilets && ctx.pilets.getDependencies({})) || {};
8
- module.exports = dependencies['<%- name %>'] || {};
9
- } else {
10
- console.error('Your test environment does not define "window". Please make sure to provide a proper environment.');
11
- module.exports = {};
12
- }
13
- } else {
14
- // under "normal" circumstances disallow such an import
15
- throw new Error("This file should not be included anywhere. Usually, this means you've imported the Piral instance directly.");
16
- }