piral-cli 1.8.0-beta.7544 → 1.8.0-beta.7655

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 (248) hide show
  1. package/lib/api.js +10 -11
  2. package/lib/api.js.map +1 -1
  3. package/lib/apps/add-piral-instance-pilet.d.ts +8 -0
  4. package/lib/apps/add-piral-instance-pilet.js +8 -4
  5. package/lib/apps/add-piral-instance-pilet.js.map +1 -1
  6. package/lib/apps/build-pilet.js +2 -2
  7. package/lib/apps/build-pilet.js.map +1 -1
  8. package/lib/apps/build-piral.js +2 -2
  9. package/lib/apps/build-piral.js.map +1 -1
  10. package/lib/apps/debug-pilet.js +2 -2
  11. package/lib/apps/debug-pilet.js.map +1 -1
  12. package/lib/apps/debug-piral.js +2 -2
  13. package/lib/apps/debug-piral.js.map +1 -1
  14. package/lib/apps/declaration-pilet.js +2 -2
  15. package/lib/apps/declaration-pilet.js.map +1 -1
  16. package/lib/apps/declaration-piral.js +2 -2
  17. package/lib/apps/declaration-piral.js.map +1 -1
  18. package/lib/apps/new-pilet.d.ts +8 -0
  19. package/lib/apps/new-pilet.js +8 -4
  20. package/lib/apps/new-pilet.js.map +1 -1
  21. package/lib/apps/new-piral.js +2 -2
  22. package/lib/apps/new-piral.js.map +1 -1
  23. package/lib/apps/pack-pilet.js +2 -2
  24. package/lib/apps/pack-pilet.js.map +1 -1
  25. package/lib/apps/publish-pilet.d.ts +4 -0
  26. package/lib/apps/publish-pilet.js +11 -9
  27. package/lib/apps/publish-pilet.js.map +1 -1
  28. package/lib/apps/publish-piral.d.ts +4 -0
  29. package/lib/apps/publish-piral.js +8 -6
  30. package/lib/apps/publish-piral.js.map +1 -1
  31. package/lib/apps/remove-piral-instance-pilet.js +2 -2
  32. package/lib/apps/remove-piral-instance-pilet.js.map +1 -1
  33. package/lib/apps/run-emulator-piral.d.ts +8 -0
  34. package/lib/apps/run-emulator-piral.js +9 -7
  35. package/lib/apps/run-emulator-piral.js.map +1 -1
  36. package/lib/apps/upgrade-pilet.d.ts +8 -0
  37. package/lib/apps/upgrade-pilet.js +9 -5
  38. package/lib/apps/upgrade-pilet.js.map +1 -1
  39. package/lib/apps/upgrade-piral.js +2 -2
  40. package/lib/apps/upgrade-piral.js.map +1 -1
  41. package/lib/apps/validate-pilet.js +2 -2
  42. package/lib/apps/validate-pilet.js.map +1 -1
  43. package/lib/apps/validate-piral.js +2 -2
  44. package/lib/apps/validate-piral.js.map +1 -1
  45. package/lib/build/bundler-calls.js +2 -3
  46. package/lib/build/bundler-calls.js.map +1 -1
  47. package/lib/build/run-build-pilet.js.map +1 -1
  48. package/lib/build/run-build-piral.js.map +1 -1
  49. package/lib/build/run-debug-mono-piral.js.map +1 -1
  50. package/lib/build/run-debug-pilet.js.map +1 -1
  51. package/lib/build/run-debug-piral.js.map +1 -1
  52. package/lib/bundler.js +23 -14
  53. package/lib/bundler.js.map +1 -1
  54. package/lib/cli.js +1 -2
  55. package/lib/cli.js.map +1 -1
  56. package/lib/commands.js +57 -7
  57. package/lib/commands.js.map +1 -1
  58. package/lib/common/MemoryStream.d.ts +0 -1
  59. package/lib/common/archive.d.ts +0 -1
  60. package/lib/common/archive.js +4 -5
  61. package/lib/common/archive.js.map +1 -1
  62. package/lib/common/browser.js +2 -3
  63. package/lib/common/browser.js.map +1 -1
  64. package/lib/common/compatibility.js +2 -3
  65. package/lib/common/compatibility.js.map +1 -1
  66. package/lib/common/config.d.ts +4 -0
  67. package/lib/common/config.js +3 -2
  68. package/lib/common/config.js.map +1 -1
  69. package/lib/common/constants.d.ts +1 -1
  70. package/lib/common/constants.js +1 -0
  71. package/lib/common/constants.js.map +1 -1
  72. package/lib/common/declaration.js +2 -3
  73. package/lib/common/declaration.js.map +1 -1
  74. package/lib/common/emulator.js +6 -7
  75. package/lib/common/emulator.js.map +1 -1
  76. package/lib/common/envs.js +1 -2
  77. package/lib/common/envs.js.map +1 -1
  78. package/lib/common/hash.d.ts +0 -1
  79. package/lib/common/hash.js +3 -4
  80. package/lib/common/hash.js.map +1 -1
  81. package/lib/common/http.d.ts +9 -5
  82. package/lib/common/http.js +31 -16
  83. package/lib/common/http.js.map +1 -1
  84. package/lib/common/importmap.js +1 -2
  85. package/lib/common/importmap.js.map +1 -1
  86. package/lib/common/info.js +2 -2
  87. package/lib/common/info.js.map +1 -1
  88. package/lib/common/injectors.js +2 -3
  89. package/lib/common/injectors.js.map +1 -1
  90. package/lib/common/inspect.d.ts +0 -1
  91. package/lib/common/inspect.js +4 -5
  92. package/lib/common/inspect.js.map +1 -1
  93. package/lib/common/interactive.d.ts +0 -1
  94. package/lib/common/interactive.js +3 -4
  95. package/lib/common/interactive.js.map +1 -1
  96. package/lib/common/io.d.ts +0 -1
  97. package/lib/common/io.js +29 -30
  98. package/lib/common/io.js.map +1 -1
  99. package/lib/common/language.js +5 -6
  100. package/lib/common/language.js.map +1 -1
  101. package/lib/common/log.js +30 -21
  102. package/lib/common/log.js.map +1 -1
  103. package/lib/common/merge.js +1 -2
  104. package/lib/common/merge.js.map +1 -1
  105. package/lib/common/npm.d.ts +6 -6
  106. package/lib/common/npm.js +95 -67
  107. package/lib/common/npm.js.map +1 -1
  108. package/lib/common/pack.js +1 -2
  109. package/lib/common/pack.js.map +1 -1
  110. package/lib/common/package.d.ts +5 -4
  111. package/lib/common/package.js +32 -33
  112. package/lib/common/package.js.map +1 -1
  113. package/lib/common/parallel.js +1 -2
  114. package/lib/common/parallel.js.map +1 -1
  115. package/lib/common/patcher.js +1 -2
  116. package/lib/common/patcher.js.map +1 -1
  117. package/lib/common/patches.js +2 -3
  118. package/lib/common/patches.js.map +1 -1
  119. package/lib/common/pilet.js +1 -2
  120. package/lib/common/pilet.js.map +1 -1
  121. package/lib/common/piral.js +2 -3
  122. package/lib/common/piral.js.map +1 -1
  123. package/lib/common/platform.js +1 -2
  124. package/lib/common/platform.js.map +1 -1
  125. package/lib/common/port.js +2 -3
  126. package/lib/common/port.js.map +1 -1
  127. package/lib/common/release.d.ts +2 -2
  128. package/lib/common/release.js +4 -5
  129. package/lib/common/release.js.map +1 -1
  130. package/lib/common/rules.js +2 -3
  131. package/lib/common/rules.js.map +1 -1
  132. package/lib/common/scaffold.js +4 -5
  133. package/lib/common/scaffold.js.map +1 -1
  134. package/lib/common/scripts.d.ts +0 -1
  135. package/lib/common/scripts.js +2 -3
  136. package/lib/common/scripts.js.map +1 -1
  137. package/lib/common/shell.d.ts +3 -2
  138. package/lib/common/shell.js +3 -4
  139. package/lib/common/shell.js.map +1 -1
  140. package/lib/common/spec.js +1 -2
  141. package/lib/common/spec.js.map +1 -1
  142. package/lib/common/template.js +1 -2
  143. package/lib/common/template.js.map +1 -1
  144. package/lib/common/url.js +1 -2
  145. package/lib/common/url.js.map +1 -1
  146. package/lib/common/utils.js +2 -3
  147. package/lib/common/utils.js.map +1 -1
  148. package/lib/common/validate.js +1 -2
  149. package/lib/common/validate.js.map +1 -1
  150. package/lib/common/version.js +2 -3
  151. package/lib/common/version.js.map +1 -1
  152. package/lib/common/watcher.js +1 -2
  153. package/lib/common/watcher.js.map +1 -1
  154. package/lib/common/website.d.ts +3 -2
  155. package/lib/common/website.js +9 -14
  156. package/lib/common/website.js.map +1 -1
  157. package/lib/external/index.js +6012 -4278
  158. package/lib/helpers.js +3 -3
  159. package/lib/helpers.js.map +1 -1
  160. package/lib/inject.js +18 -9
  161. package/lib/inject.js.map +1 -1
  162. package/lib/injectors/pilet-injector.d.ts +0 -3
  163. package/lib/injectors/pilet-injector.js.map +1 -1
  164. package/lib/injectors/piral-injector.d.ts +0 -2
  165. package/lib/injectors/piral-injector.js.map +1 -1
  166. package/lib/messages.js +93 -95
  167. package/lib/messages.js.map +1 -1
  168. package/lib/npm-clients/bun.js +7 -8
  169. package/lib/npm-clients/bun.js.map +1 -1
  170. package/lib/npm-clients/index.d.ts +9 -5
  171. package/lib/npm-clients/index.js +35 -13
  172. package/lib/npm-clients/index.js.map +1 -1
  173. package/lib/npm-clients/lerna.js +7 -8
  174. package/lib/npm-clients/lerna.js.map +1 -1
  175. package/lib/npm-clients/npm.js +13 -14
  176. package/lib/npm-clients/npm.js.map +1 -1
  177. package/lib/npm-clients/pnp.js +7 -8
  178. package/lib/npm-clients/pnp.js.map +1 -1
  179. package/lib/npm-clients/pnpm.js +7 -8
  180. package/lib/npm-clients/pnpm.js.map +1 -1
  181. package/lib/npm-clients/rush.js +7 -8
  182. package/lib/npm-clients/rush.js.map +1 -1
  183. package/lib/npm-clients/yarn.js +7 -8
  184. package/lib/npm-clients/yarn.js.map +1 -1
  185. package/lib/platforms/node.js +1 -2
  186. package/lib/platforms/node.js.map +1 -1
  187. package/lib/platforms/web.js +1 -2
  188. package/lib/platforms/web.js.map +1 -1
  189. package/lib/plugin.js +1 -2
  190. package/lib/plugin.js.map +1 -1
  191. package/lib/questionnaire.js +2 -3
  192. package/lib/questionnaire.js.map +1 -1
  193. package/lib/resolvers.js.map +1 -1
  194. package/lib/rules/index.js +4 -5
  195. package/lib/rules/index.js.map +1 -1
  196. package/lib/rules/pilet-has-externals-as-peers.js +1 -1
  197. package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
  198. package/lib/rules/pilet-has-no-self-reference.js +1 -1
  199. package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
  200. package/lib/rules/pilet-has-no-third-party-dependency.js +1 -1
  201. package/lib/rules/pilet-has-no-third-party-dependency.js.map +1 -1
  202. package/lib/rules/pilet-has-non-conflicting-css.js +1 -1
  203. package/lib/rules/pilet-has-non-conflicting-css.js.map +1 -1
  204. package/lib/rules/pilet-stays-small.js +1 -1
  205. package/lib/rules/pilet-stays-small.js.map +1 -1
  206. package/lib/rules/pilet-uses-latest-piral.js +1 -1
  207. package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
  208. package/lib/rules/piral-depends-on-piral.js +1 -1
  209. package/lib/rules/piral-depends-on-piral.js.map +1 -1
  210. package/lib/rules/piral-entry-ends-with-html.js +1 -1
  211. package/lib/rules/piral-entry-ends-with-html.js.map +1 -1
  212. package/lib/rules/piral-has-valid-devDependencies.js +1 -1
  213. package/lib/rules/piral-has-valid-devDependencies.js.map +1 -1
  214. package/lib/rules/piral-has-valid-externals.js +1 -1
  215. package/lib/rules/piral-has-valid-externals.js.map +1 -1
  216. package/lib/rules/piral-has-valid-files.js +1 -1
  217. package/lib/rules/piral-has-valid-files.js.map +1 -1
  218. package/lib/rules/piral-has-valid-scripts.js +1 -1
  219. package/lib/rules/piral-has-valid-scripts.js.map +1 -1
  220. package/lib/runner.js.map +1 -1
  221. package/lib/select.js +1 -2
  222. package/lib/select.js.map +1 -1
  223. package/lib/start.js +1 -2
  224. package/lib/start.js.map +1 -1
  225. package/lib/types/internal.d.ts +18 -2
  226. package/lib/types/public.d.ts +3 -1
  227. package/package.json +6 -6
  228. package/src/apps/add-piral-instance-pilet.ts +20 -1
  229. package/src/apps/new-pilet.ts +19 -1
  230. package/src/apps/publish-pilet.ts +17 -7
  231. package/src/apps/publish-piral.ts +13 -4
  232. package/src/apps/run-emulator-piral.ts +22 -6
  233. package/src/apps/upgrade-pilet.ts +21 -2
  234. package/src/commands.ts +41 -1
  235. package/src/common/config.ts +5 -0
  236. package/src/common/constants.ts +1 -0
  237. package/src/common/emulator.ts +4 -4
  238. package/src/common/http.test.ts +5 -4
  239. package/src/common/http.ts +26 -7
  240. package/src/common/npm.test.ts +16 -16
  241. package/src/common/npm.ts +84 -50
  242. package/src/common/package.ts +10 -11
  243. package/src/common/release.ts +3 -2
  244. package/src/common/shell.ts +6 -4
  245. package/src/common/website.ts +8 -11
  246. package/src/npm-clients/index.ts +21 -6
  247. package/src/types/internal.ts +25 -1
  248. package/src/types/public.ts +5 -1
package/src/commands.ts CHANGED
@@ -218,6 +218,9 @@ const allCommands: Array<ToolCommand<any>> = [
218
218
  .string('ca-cert')
219
219
  .describe('ca-cert', 'Sets a custom certificate authority to use, if any.')
220
220
  .default('ca-cert', apps.publishPiralDefaults.cert)
221
+ .boolean('allow-self-signed')
222
+ .describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
223
+ .default('allow-self-signed', apps.publishPiralDefaults.allowSelfSigned)
221
224
  .number('log-level')
222
225
  .describe('log-level', 'Sets the log level to use (1-5).')
223
226
  .default('log-level', apps.publishPiralDefaults.logLevel)
@@ -250,6 +253,7 @@ const allCommands: Array<ToolCommand<any>> = [
250
253
  logLevel: args['log-level'] as LogLevels,
251
254
  apiKey: args['api-key'] as string,
252
255
  cert: args['ca-cert'] as string,
256
+ allowSelfSigned: args['allow-self-signed'] as boolean,
253
257
  url: args.url as string,
254
258
  interactive: args.interactive as boolean,
255
259
  mode: args.mode as PublishScheme,
@@ -687,6 +691,9 @@ const allCommands: Array<ToolCommand<any>> = [
687
691
  .boolean('interactive')
688
692
  .describe('interactive', 'Defines if authorization tokens can be retrieved interactively.')
689
693
  .default('interactive', apps.publishPiletDefaults.interactive)
694
+ .boolean('allow-self-signed')
695
+ .describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
696
+ .default('allow-self-signed', apps.publishPiletDefaults.allowSelfSigned)
690
697
  .string('base')
691
698
  .default('base', process.cwd())
692
699
  .describe('base', 'Sets the base directory. By default the current directory is used.');
@@ -698,6 +705,7 @@ const allCommands: Array<ToolCommand<any>> = [
698
705
  url: args.url as string,
699
706
  logLevel: args['log-level'] as LogLevels,
700
707
  cert: args['ca-cert'] as string,
708
+ allowSelfSigned: args['allow-self-signed'] as boolean,
701
709
  bundlerName: args.bundler as string,
702
710
  fresh: args.fresh as boolean,
703
711
  from: args.from as PiletPublishSource,
@@ -787,6 +795,12 @@ const allCommands: Array<ToolCommand<any>> = [
787
795
  .choices('bundler', bundlerKeys)
788
796
  .describe('bundler', 'Sets the default bundler to install.')
789
797
  .default('bundler', apps.newPiletDefaults.bundlerName)
798
+ .string('ca-cert')
799
+ .describe('ca-cert', 'Sets a custom certificate authority to use, if any.')
800
+ .default('ca-cert', apps.newPiletDefaults.cert)
801
+ .boolean('allow-self-signed')
802
+ .describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
803
+ .default('allow-self-signed', apps.newPiletDefaults.allowSelfSigned)
790
804
  .option('vars', undefined)
791
805
  .describe('vars', 'Sets additional variables to be used when scaffolding.')
792
806
  .default('vars', apps.newPiletDefaults.variables)
@@ -811,6 +825,8 @@ const allCommands: Array<ToolCommand<any>> = [
811
825
  bundlerName: args.bundler as string,
812
826
  variables: args.vars as Record<string, string>,
813
827
  name: args['name'] as string,
828
+ cert: args['ca-cert'] as string,
829
+ allowSelfSigned: args['allow-self-signed'] as boolean,
814
830
  });
815
831
  },
816
832
  },
@@ -819,7 +835,7 @@ const allCommands: Array<ToolCommand<any>> = [
819
835
  alias: ['upgrade'],
820
836
  description: 'Upgrades an existing pilet to the latest version of the used Piral instance.',
821
837
  arguments: ['[target-version]'],
822
- flags(argv) {
838
+ flags(argv: any) {
823
839
  return argv
824
840
  .positional('target-version', {
825
841
  type: 'string',
@@ -842,6 +858,12 @@ const allCommands: Array<ToolCommand<any>> = [
842
858
  .choices('npm-client', clientTypeKeys)
843
859
  .describe('npm-client', 'Sets the npm client to be used when upgrading.')
844
860
  .default('npm-client', apps.upgradePiletDefaults.npmClient)
861
+ .string('ca-cert')
862
+ .describe('ca-cert', 'Sets a custom certificate authority to use, if any.')
863
+ .default('ca-cert', apps.upgradePiletDefaults.cert)
864
+ .boolean('allow-self-signed')
865
+ .describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
866
+ .default('allow-self-signed', apps.upgradePiletDefaults.allowSelfSigned)
845
867
  .option('vars', undefined)
846
868
  .describe('vars', 'Sets additional variables to be used when scaffolding.')
847
869
  .default('vars', apps.upgradePiletDefaults.variables)
@@ -858,6 +880,8 @@ const allCommands: Array<ToolCommand<any>> = [
858
880
  install: args.install as boolean,
859
881
  npmClient: args['npm-client'] as NpmClientType,
860
882
  variables: args.vars as Record<string, string>,
883
+ cert: args['ca-cert'] as string,
884
+ allowSelfSigned: args['allow-self-signed'] as boolean,
861
885
  });
862
886
  },
863
887
  },
@@ -916,6 +940,12 @@ const allCommands: Array<ToolCommand<any>> = [
916
940
  .boolean('selected')
917
941
  .describe('selected', 'Defines if the provided Piral instance should be selected initially.')
918
942
  .default('selected', apps.addPiralInstancePiletDefaults.selected)
943
+ .string('ca-cert')
944
+ .describe('ca-cert', 'Sets a custom certificate authority to use, if any.')
945
+ .default('ca-cert', apps.addPiralInstancePiletDefaults.cert)
946
+ .boolean('allow-self-signed')
947
+ .describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
948
+ .default('allow-self-signed', apps.addPiralInstancePiletDefaults.allowSelfSigned)
919
949
  .string('base')
920
950
  .default('base', process.cwd())
921
951
  .describe('base', 'Sets the base directory. By default the current directory is used.');
@@ -927,6 +957,8 @@ const allCommands: Array<ToolCommand<any>> = [
927
957
  npmClient: args['npm-client'] as NpmClientType,
928
958
  app: args.app as string,
929
959
  source: args.source as string,
960
+ cert: args['ca-cert'] as string,
961
+ allowSelfSigned: args['allow-self-signed'] as boolean,
930
962
  });
931
963
  },
932
964
  },
@@ -995,6 +1027,12 @@ const allCommands: Array<ToolCommand<any>> = [
995
1027
  .choices('npm-client', clientTypeKeys)
996
1028
  .describe('npm-client', 'Sets the npm client to be used when installing the emulator.')
997
1029
  .default('npm-client', apps.runEmulatorPiralDefaults.npmClient)
1030
+ .string('ca-cert')
1031
+ .describe('ca-cert', 'Sets a custom certificate authority to use, if any.')
1032
+ .default('ca-cert', apps.runEmulatorPiralDefaults.cert)
1033
+ .boolean('allow-self-signed')
1034
+ .describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
1035
+ .default('allow-self-signed', apps.runEmulatorPiralDefaults.allowSelfSigned)
998
1036
  .boolean('open')
999
1037
  .describe('open', 'Opens the Piral instance directly in the browser.')
1000
1038
  .default('open', apps.runEmulatorPiralDefaults.open)
@@ -1014,6 +1052,8 @@ const allCommands: Array<ToolCommand<any>> = [
1014
1052
  logLevel: args['log-level'] as LogLevels,
1015
1053
  open: args.open as boolean,
1016
1054
  feed: args.feed as string,
1055
+ cert: args['ca-cert'] as string,
1056
+ allowSelfSigned: args['allow-self-signed'] as boolean,
1017
1057
  });
1018
1058
  },
1019
1059
  },
@@ -73,6 +73,10 @@ export interface PiralCliConfig {
73
73
  * Npm registry.
74
74
  */
75
75
  registry?: string;
76
+ /**
77
+ * Allow self-signed certificates.
78
+ */
79
+ allowSelfSigned?: boolean;
76
80
  }
77
81
 
78
82
  export const config: PiralCliConfig = rc(
@@ -89,6 +93,7 @@ export const config: PiralCliConfig = rc(
89
93
  validators: {},
90
94
  schemaVersion: 'v2' as const,
91
95
  openBrowser: false,
96
+ allowSelfSigned: false,
92
97
  port: 1234,
93
98
  strictPort: false,
94
99
  language: 'ts' as const,
@@ -29,6 +29,7 @@ export const bundlerNames = [
29
29
  'webpack5' as const,
30
30
  'vite' as const,
31
31
  'vite5' as const,
32
+ 'vite6' as const,
32
33
  'xbuild' as const,
33
34
  ];
34
35
  export const declarationEntryExtensions = ['.html', '.pug', ...entryModuleExtensions];
@@ -1,4 +1,4 @@
1
- import { join, resolve, relative, basename, extname } from 'path';
1
+ import { join, resolve, relative, basename, posix } from 'path';
2
2
  import { findDependencyVersion, copyScaffoldingFiles, isValidDependency, flattenExternals } from './package';
3
3
  import { createPiralStubIndexIfNotExists } from './template';
4
4
  import { filesTar, filesOnceTar, packageJson, piralJson, emulatorJson } from './constants';
@@ -139,9 +139,9 @@ export async function createEmulatorSources(
139
139
  version: cliVersion,
140
140
  generated: true,
141
141
  },
142
- main: `./${join(appDir, 'index.js')}`,
143
- typings: `./${join(appDir, 'index.d.ts')}`,
144
- app: `./${join(appDir, 'index.html')}`,
142
+ main: `./${posix.join(appDir, 'index.js')}`,
143
+ typings: `./${posix.join(appDir, 'index.d.ts')}`,
144
+ app: `./${posix.join(appDir, 'index.html')}`,
145
145
  peerDependencies: {},
146
146
  optionalDependencies,
147
147
  devDependencies: {
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, vitest } from 'vitest';
2
- import { postFile, downloadFile } from './http';
2
+ import { postFile, downloadFile, getAgent } from './http';
3
3
 
4
4
  const apiUrl = 'http://sample.fooo.com/api/v1/pilet';
5
5
 
@@ -80,7 +80,7 @@ vitest.mock('../external', async () => {
80
80
  },
81
81
  },
82
82
  },
83
- FormData: (await vitest.importActual('form-data') as any).default,
83
+ FormData: ((await vitest.importActual('form-data')) as any).default,
84
84
  };
85
85
  });
86
86
 
@@ -155,10 +155,11 @@ describe('HTTP Module', () => {
155
155
 
156
156
  it('downloadFile calls results in error', async () => {
157
157
  errorOther = true;
158
- let result = await downloadFile('http://sample.com/', Buffer.from('example'));
158
+ const agent = getAgent({ ca: Buffer.from('example') });
159
+ let result = await downloadFile('http://sample.com/', agent);
159
160
  expect(result.length).toBe(0);
160
161
  errorOther = false;
161
- result = await downloadFile('http://sample.com/', Buffer.from('example'));
162
+ result = await downloadFile('http://sample.com/', agent);
162
163
  expect(result.length).toBe(0);
163
164
  });
164
165
  });
@@ -100,8 +100,28 @@ export function getAuthorizationHeaders(scheme: PublishScheme, key: string) {
100
100
  return {};
101
101
  }
102
102
 
103
- export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>> {
104
- const httpsAgent = ca ? new Agent({ ca }) : undefined;
103
+ export interface AgentOptions {
104
+ ca?: Buffer;
105
+ allowSelfSigned?: boolean;
106
+ }
107
+
108
+ export async function getDefaultAgent() {
109
+ const ca = await getCertificate();
110
+ const allowSelfSigned = config.allowSelfSigned;
111
+ return getAgent({ ca, allowSelfSigned });
112
+ }
113
+
114
+ export function getAgent({ allowSelfSigned, ca }: AgentOptions) {
115
+ if (ca) {
116
+ return new Agent({ ca });
117
+ } else if (allowSelfSigned) {
118
+ return new Agent({ rejectUnauthorized: false });
119
+ } else {
120
+ return undefined;
121
+ }
122
+ }
123
+
124
+ export function downloadFile(target: string, httpsAgent: Agent): Promise<Array<string>> {
105
125
  return axios.default
106
126
  .get<Stream>(target, {
107
127
  responseType: 'stream',
@@ -206,10 +226,9 @@ export async function postForm(
206
226
  key: string,
207
227
  formData: FormDataObj,
208
228
  customHeaders: Record<string, string> = {},
209
- ca?: Buffer,
229
+ httpsAgent?: Agent,
210
230
  interactive = false,
211
231
  ): Promise<PostFormResult> {
212
- const httpsAgent = ca ? new Agent({ ca }) : undefined;
213
232
  const form = createAxiosForm(formData);
214
233
 
215
234
  const headers: Record<string, string> = {
@@ -237,7 +256,7 @@ export async function postForm(
237
256
  error,
238
257
  interactive,
239
258
  httpsAgent,
240
- (mode, token) => postForm(target, mode, token, formData, customHeaders, ca, false),
259
+ (mode, token) => postForm(target, mode, token, formData, customHeaders, httpsAgent, false),
241
260
  (status, statusText, response) => {
242
261
  if (status === 500) {
243
262
  log('failedHttpPost_0065', response);
@@ -266,9 +285,9 @@ export function postFile(
266
285
  file: Buffer,
267
286
  customFields: Record<string, string> = {},
268
287
  customHeaders: Record<string, string> = {},
269
- ca?: Buffer,
288
+ agent?: Agent,
270
289
  interactive = false,
271
290
  ): Promise<PostFormResult> {
272
291
  const data: FormDataObj = { ...customFields, file: [file, 'pilet.tgz'] };
273
- return postForm(target, scheme, key, data, customHeaders, ca, interactive);
292
+ return postForm(target, scheme, key, data, customHeaders, agent, interactive);
274
293
  }
@@ -202,39 +202,39 @@ describe('npm Module', () => {
202
202
 
203
203
  it('installs a package using the npm command line tool without a target', async () => {
204
204
  wrongCase = false;
205
- await installNpmPackage('npm', 'foo', 'latest').then((result) => expect(result).toEqual(jsonValueString));
205
+ await installNpmPackage({ direct: 'npm' }, 'foo', 'latest').then((result) => expect(result).toEqual(jsonValueString));
206
206
  wrongCase = true;
207
- await installNpmPackage('npm', 'foo', 'latest').then((result) => expect(result).not.toEqual(jsonValueString));
207
+ await installNpmPackage({ direct: 'npm' }, 'foo', 'latest').then((result) => expect(result).not.toEqual(jsonValueString));
208
208
  });
209
209
 
210
210
  it('installs a package using the npm command line tool without a version', async () => {
211
211
  wrongCase = false;
212
- await installNpmPackage('npm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
212
+ await installNpmPackage({ direct: 'npm' }, 'foo').then((result) => expect(result).toEqual(jsonValueString));
213
213
  wrongCase = true;
214
- await installNpmPackage('npm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
214
+ await installNpmPackage({ direct: 'npm' }, 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
215
215
  });
216
216
 
217
217
  it('installs a package using the Yarn command line tool without a version', async () => {
218
218
  wrongCase = false;
219
- await installNpmPackage('yarn', 'foo').then((result) => expect(result).toEqual(jsonValueString));
219
+ await installNpmPackage({ direct: 'yarn' }, 'foo').then((result) => expect(result).toEqual(jsonValueString));
220
220
  wrongCase = true;
221
- await installNpmPackage('yarn', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
221
+ await installNpmPackage({ direct: 'yarn' }, 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
222
222
  });
223
223
 
224
224
  it('installs a package using the Pnpm command line tool without a version', async () => {
225
225
  wrongCase = false;
226
- await installNpmPackage('pnpm', 'foo').then((result) => expect(result).toEqual(jsonValueString));
226
+ await installNpmPackage({ direct: 'pnpm' }, 'foo').then((result) => expect(result).toEqual(jsonValueString));
227
227
  wrongCase = true;
228
- await installNpmPackage('pnpm', 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
228
+ await installNpmPackage({ direct: 'pnpm' }, 'foo').then((result) => expect(result).not.toEqual(jsonValueString));
229
229
  });
230
230
 
231
231
  it('installs a package using the npm command line tool with some flag', async () => {
232
232
  wrongCase = false;
233
- await installNpmPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
233
+ await installNpmPackage({ direct: 'pnpm' }, 'foo', '1.3', '.', '--a=b').then((result) =>
234
234
  expect(result).toEqual(jsonValueString),
235
235
  );
236
236
  wrongCase = true;
237
- await installNpmPackage('npm', 'foo', '1.3', '.', '--a=b').then((result) =>
237
+ await installNpmPackage({ direct: 'pnpm' }, 'foo', '1.3', '.', '--a=b').then((result) =>
238
238
  expect(result).not.toEqual(jsonValueString),
239
239
  );
240
240
  });
@@ -281,23 +281,23 @@ describe('npm Module', () => {
281
281
 
282
282
  it('install dependencies with npm client', async () => {
283
283
  wrongCase = false;
284
- await installNpmDependencies('npm').then((result) => expect(result).toEqual(jsonValueString));
284
+ await installNpmDependencies({ direct: 'npm' }).then((result) => expect(result).toEqual(jsonValueString));
285
285
  wrongCase = true;
286
- await installNpmDependencies('npm').then((result) => expect(result).not.toEqual(jsonValueString));
286
+ await installNpmDependencies({ direct: 'npm' }).then((result) => expect(result).not.toEqual(jsonValueString));
287
287
  });
288
288
 
289
289
  it('install dependencies with pnpm client', async () => {
290
290
  wrongCase = false;
291
- await installNpmDependencies('pnpm').then((result) => expect(result).toEqual(jsonValueString));
291
+ await installNpmDependencies({ direct: 'pnpm' }).then((result) => expect(result).toEqual(jsonValueString));
292
292
  wrongCase = true;
293
- await installNpmDependencies('pnpm').then((result) => expect(result).not.toEqual(jsonValueString));
293
+ await installNpmDependencies({ direct: 'pnpm' }).then((result) => expect(result).not.toEqual(jsonValueString));
294
294
  });
295
295
 
296
296
  it('install dependencies with yarn client', async () => {
297
297
  wrongCase = false;
298
- await installNpmDependencies('yarn').then((result) => expect(result).toEqual(jsonValueString));
298
+ await installNpmDependencies({ direct: 'yarn' }).then((result) => expect(result).toEqual(jsonValueString));
299
299
  wrongCase = true;
300
- await installNpmDependencies('yarn').then((result) => expect(result).not.toEqual(jsonValueString));
300
+ await installNpmDependencies({ direct: 'yarn' }).then((result) => expect(result).not.toEqual(jsonValueString));
301
301
  });
302
302
 
303
303
  it('create npm package', async () => {
package/src/common/npm.ts CHANGED
@@ -5,10 +5,10 @@ import { config } from './config';
5
5
  import { legacyCoreExternals, frameworkLibs, defaultRegistry, packageJson } from './constants';
6
6
  import { inspectPackage } from './inspect';
7
7
  import { readJson, checkExists } from './io';
8
- import { clients, detectClients, isWrapperClient } from '../npm-clients';
8
+ import { clients, detectDirectClients, detectWrapperClients, isDirectClient, isWrapperClient } from '../npm-clients';
9
9
  import { clientTypeKeys } from '../helpers';
10
10
  import { getModulePath } from '../external';
11
- import { PackageType, NpmClientType } from '../types';
11
+ import { PackageType, NpmClientType, NpmClient, NpmDirectClientType, NpmWapperClientType } from '../types';
12
12
 
13
13
  const gitPrefix = 'git+';
14
14
  const filePrefix = 'file:';
@@ -63,56 +63,88 @@ async function detectMonorepoRoot(root: string): Promise<[] | [string, NpmClient
63
63
  return [];
64
64
  }
65
65
 
66
- /**
67
- * For details about how this works consult issue
68
- * https://github.com/smapiot/piral/issues/203
69
- * @param root The project's root directory.
70
- */
71
- export async function determineNpmClient(root: string, selected?: NpmClientType): Promise<NpmClientType> {
72
- if (!selected || !clientTypeKeys.includes(selected)) {
73
- log('generalDebug_0003', 'No npm client selected. Checking for lock or config files ...');
66
+ async function determineWrapperClient(root: string): Promise<NpmWapperClientType | undefined> {
67
+ const searchedClients = await detectWrapperClients(root);
68
+ const foundClients = searchedClients.filter((m) => m.result).map((m) => m.client);
74
69
 
75
- const searchedClients = await detectClients(root);
76
- const foundClients = searchedClients.filter((m) => m.result);
77
-
78
- log(
79
- 'generalDebug_0003',
80
- `Results of the lock file check: ${searchedClients.map((m) => `${m.client}=${m.result}`).join(', ')}`,
81
- );
70
+ if (foundClients.length > 0) {
71
+ const [client] = foundClients;
82
72
 
83
73
  if (foundClients.length > 1) {
84
- const wrapperClient = foundClients.find((m) => isWrapperClient(m.client));
85
-
86
- if (wrapperClient) {
87
- const { client } = wrapperClient;
88
- log('generalDebug_0003', `Found valid wrapper client via lock or config file: "${client}".`);
89
- }
74
+ log(
75
+ 'generalWarning_0001',
76
+ `Found multiple clients via their lock or config files: "${foundClients.join('", "')}".`,
77
+ );
90
78
  }
91
79
 
92
- if (foundClients.length > 0) {
93
- const { client } = foundClients[0];
80
+ log('generalDebug_0003', `Found valid direct client via lock or config file: "${client}".`);
81
+ return client;
82
+ }
94
83
 
95
- if (foundClients.length > 1) {
96
- const clientStr = `"${foundClients.map((m) => m.client).join('", "')}"`;
97
- log('generalWarning_0001', `Found multiple clients via their lock or config files: ${clientStr}.`);
98
- }
84
+ const defaultClient = config.npmClient;
99
85
 
100
- log('generalDebug_0003', `Found valid direct client via lock or config file: "${client}".`);
101
- return client;
102
- }
86
+ if (isWrapperClient(defaultClient)) {
87
+ log('generalDebug_0003', `Using the default client: "${defaultClient}".`);
88
+ return defaultClient;
89
+ }
90
+
91
+ return undefined;
92
+ }
103
93
 
104
- const defaultClient = config.npmClient;
94
+ async function determineDirectClient(root: string): Promise<NpmDirectClientType> {
95
+ const searchedClients = await detectDirectClients(root);
96
+ const foundClients = searchedClients.filter((m) => m.result).map((m) => m.client);
105
97
 
106
- if (clientTypeKeys.includes(defaultClient)) {
107
- log('generalDebug_0003', `Using the default client: "${defaultClient}".`);
108
- return defaultClient;
98
+ if (foundClients.length > 0) {
99
+ const [client] = foundClients;
100
+
101
+ if (foundClients.length > 1) {
102
+ log(
103
+ 'generalWarning_0001',
104
+ `Found multiple clients via their lock or config files: "${foundClients.join('", "')}".`,
105
+ );
109
106
  }
110
107
 
111
- log('generalDebug_0003', 'Using the fallback "npm" client.');
112
- return 'npm';
108
+ log('generalDebug_0003', `Found valid direct client via lock or config file: "${client}".`);
109
+ return client;
110
+ }
111
+
112
+ const defaultClient = config.npmClient;
113
+
114
+ if (isDirectClient(defaultClient)) {
115
+ log('generalDebug_0003', `Using the default client: "${defaultClient}".`);
116
+ return defaultClient;
113
117
  }
114
118
 
115
- return selected;
119
+ log('generalDebug_0003', 'Using the fallback "npm" client.');
120
+ return 'npm';
121
+ }
122
+
123
+ /**
124
+ * For details about how this works consult issue
125
+ * https://github.com/smapiot/piral/issues/203
126
+ * @param root The project's root directory.
127
+ */
128
+ export async function determineNpmClient(root: string, selected?: NpmClientType): Promise<NpmClient> {
129
+ if (!selected || !clientTypeKeys.includes(selected)) {
130
+ log('generalDebug_0003', 'No npm client selected. Checking for lock or config files ...');
131
+ const [direct, wrapper] = await Promise.all([determineDirectClient(root), determineWrapperClient(root)]);
132
+ return {
133
+ direct,
134
+ wrapper,
135
+ };
136
+ } else if (isDirectClient(selected)) {
137
+ return {
138
+ proposed: selected,
139
+ direct: selected,
140
+ };
141
+ } else {
142
+ return {
143
+ proposed: selected,
144
+ direct: await determineDirectClient(root),
145
+ wrapper: selected,
146
+ };
147
+ }
116
148
  }
117
149
 
118
150
  export async function isMonorepoPackageRef(refName: string, root: string): Promise<boolean> {
@@ -126,35 +158,37 @@ export async function isMonorepoPackageRef(refName: string, root: string): Promi
126
158
  return false;
127
159
  }
128
160
 
129
- export function installNpmDependencies(client: NpmClientType, target = '.'): Promise<string> {
130
- const { installDependencies } = clients[client];
161
+ export function installNpmDependencies(client: NpmClient, target = '.'): Promise<string> {
162
+ const { installDependencies } = clients[client.direct];
131
163
  return installDependencies(target);
132
164
  }
133
165
 
134
166
  export async function installNpmPackageFromOptionalRegistry(
135
167
  packageRef: string,
136
- target = '.',
168
+ target: string,
137
169
  registry: string,
138
170
  ): Promise<void> {
171
+ const client = await determineNpmClient(target, 'npm');
172
+
139
173
  try {
140
- await installNpmPackage('npm', packageRef, target, '--registry', registry);
174
+ await installNpmPackage(client, packageRef, target, '--registry', registry);
141
175
  } catch (e) {
142
176
  if (registry === defaultRegistry) {
143
177
  throw e;
144
178
  }
145
179
 
146
- await installNpmPackage('npm', packageRef, target, '--registry', defaultRegistry);
180
+ await installNpmPackage(client, packageRef, target, '--registry', defaultRegistry);
147
181
  }
148
182
  }
149
183
 
150
184
  export async function uninstallNpmPackage(
151
- client: NpmClientType,
185
+ client: NpmClient,
152
186
  packageRef: string,
153
187
  target = '.',
154
188
  ...flags: Array<string>
155
189
  ): Promise<string> {
156
190
  try {
157
- const { uninstallPackage } = clients[client];
191
+ const { uninstallPackage } = clients[client.direct];
158
192
  return await uninstallPackage(packageRef, target, ...flags);
159
193
  } catch (ex) {
160
194
  log(
@@ -166,13 +200,13 @@ export async function uninstallNpmPackage(
166
200
  }
167
201
 
168
202
  export async function installNpmPackage(
169
- client: NpmClientType,
203
+ client: NpmClient,
170
204
  packageRef: string,
171
205
  target = '.',
172
206
  ...flags: Array<string>
173
207
  ): Promise<string> {
174
208
  try {
175
- const { installPackage } = clients[client];
209
+ const { installPackage } = clients[client.direct];
176
210
  return await installPackage(packageRef, target, ...flags);
177
211
  } catch (ex) {
178
212
  log(
@@ -183,8 +217,8 @@ export async function installNpmPackage(
183
217
  }
184
218
  }
185
219
 
186
- export function initNpmProject(client: NpmClientType, projectName: string, target: string) {
187
- const { initProject } = clients[client];
220
+ export function initNpmProject(client: NpmClient, projectName: string, target: string) {
221
+ const { initProject } = clients[client.wrapper || client.direct];
188
222
  return initProject(projectName, target);
189
223
  }
190
224
 
@@ -1,3 +1,4 @@
1
+ import { Agent } from 'https';
1
2
  import { resolve, join, extname, basename, dirname, relative } from 'path';
2
3
  import { log, fail } from './log';
3
4
  import { cliVersion } from './info';
@@ -161,7 +162,8 @@ async function loadPiralInstance(root: string, details?: PiralInstanceDetails):
161
162
  export async function findPiralInstance(
162
163
  proposedApp: string,
163
164
  rootDir: string,
164
- details?: PiralInstanceDetails,
165
+ details: PiralInstanceDetails,
166
+ agent: Agent,
165
167
  interactive = false,
166
168
  ) {
167
169
  const path = findPackageRoot(proposedApp, rootDir);
@@ -172,13 +174,13 @@ export async function findPiralInstance(
172
174
 
173
175
  if (url) {
174
176
  log('generalDebug_0003', `Updating the emulator from remote "${url}" ...`);
175
- await updateFromEmulatorWebsite(root, url, interactive);
177
+ await updateFromEmulatorWebsite(root, url, agent, interactive);
176
178
  }
177
179
 
178
180
  return await loadPiralInstance(root, details);
179
181
  } else if (url) {
180
182
  log('generalDebug_0003', `Piral instance not installed yet - trying from remote "${url}" ...`);
181
- const emulator = await scaffoldFromEmulatorWebsite(rootDir, url);
183
+ const emulator = await scaffoldFromEmulatorWebsite(rootDir, url, agent);
182
184
  return await loadPiralInstance(emulator.path, details);
183
185
  }
184
186
 
@@ -190,6 +192,7 @@ export async function findPiralInstances(
190
192
  piletPackage: PiletPackageData,
191
193
  piletDefinition: undefined | PiletDefinition,
192
194
  rootDir: string,
195
+ agent: Agent,
193
196
  interactive?: boolean,
194
197
  ) {
195
198
  if (proposedApps) {
@@ -208,7 +211,7 @@ export async function findPiralInstances(
208
211
  if (proposedApps.length > 0) {
209
212
  return Promise.all(
210
213
  proposedApps.map((proposedApp) =>
211
- findPiralInstance(proposedApp, rootDir, piletDefinition?.piralInstances?.[proposedApp], interactive),
214
+ findPiralInstance(proposedApp, rootDir, piletDefinition?.piralInstances?.[proposedApp], agent, interactive),
212
215
  ),
213
216
  );
214
217
  }
@@ -280,11 +283,7 @@ export async function getPiralPackage(app: string, data: PiralInstanceData, vers
280
283
  };
281
284
  }
282
285
 
283
- async function getAvailableFiles(
284
- root: string,
285
- name: string,
286
- dirName: string,
287
- ): Promise<Array<FileDescriptor>> {
286
+ async function getAvailableFiles(root: string, name: string, dirName: string): Promise<Array<FileDescriptor>> {
288
287
  const source = getPiralPath(root, name);
289
288
  const tgz = `${dirName}.tar`;
290
289
  log('generalDebug_0003', `Checking if "${tgz}" exists in "${source}" ...`);
@@ -780,13 +779,13 @@ export async function findPiletRoot(proposedRoot: string) {
780
779
  return dirname(packageJsonPath);
781
780
  }
782
781
 
783
- export async function retrievePiletData(target: string, app?: string, interactive?: boolean) {
782
+ export async function retrievePiletData(target: string, app?: string, agent?: Agent, interactive?: boolean) {
784
783
  const piletJsonPath = await findFile(target, piletJson);
785
784
  const proposedRoot = piletJsonPath ? dirname(piletJsonPath) : target;
786
785
  const root = await findPiletRoot(proposedRoot);
787
786
  const piletPackage = await readJson(root, packageJson);
788
787
  const piletDefinition: PiletDefinition = piletJsonPath && (await readJson(proposedRoot, piletJson));
789
- const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root, interactive);
788
+ const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root, agent, interactive);
790
789
  const apps: Array<AppDefinition> = [];
791
790
 
792
791
  for (const appPackage of appPackages) {
@@ -1,3 +1,4 @@
1
+ import { Agent } from 'https';
1
2
  import { basename, dirname, relative } from 'path';
2
3
  import { readBinary } from './io';
3
4
  import { publishNpmPackage } from './npm';
@@ -39,7 +40,7 @@ export async function publishWebsiteEmulator(
39
40
  files: Array<string>,
40
41
  interactive: boolean,
41
42
  headers?: Record<string, string>,
42
- ca?: Buffer,
43
+ agent?: Agent,
43
44
  ) {
44
45
  const data: FormDataObj = {
45
46
  version,
@@ -53,5 +54,5 @@ export async function publishWebsiteEmulator(
53
54
  data[relPath] = [content, fileName];
54
55
  }
55
56
 
56
- return await postForm(url, mode, apiKey, data, headers, ca, interactive);
57
+ return await postForm(url, mode, apiKey, data, headers, agent, interactive);
57
58
  }