publish-microfrontend 1.7.2 → 1.7.3-beta.7581

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.
package/lib/index.js CHANGED
@@ -26,9 +26,9 @@ var __toModule = (module2) => {
26
26
  return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
27
27
  };
28
28
 
29
- // ../../../node_modules/yargs/build/lib/common-types.js
29
+ // node_modules/yargs/build/lib/common-types.js
30
30
  var require_common_types = __commonJS({
31
- "../../../node_modules/yargs/build/lib/common-types.js"(exports2) {
31
+ "node_modules/yargs/build/lib/common-types.js"(exports2) {
32
32
  "use strict";
33
33
  Object.defineProperty(exports2, "__esModule", { value: true });
34
34
  exports2.objectKeys = exports2.assertSingleKey = exports2.assertNotStrictEqual = void 0;
@@ -48,9 +48,9 @@ var require_common_types = __commonJS({
48
48
  }
49
49
  });
50
50
 
51
- // ../../../node_modules/yargs/build/lib/is-promise.js
51
+ // node_modules/yargs/build/lib/is-promise.js
52
52
  var require_is_promise = __commonJS({
53
- "../../../node_modules/yargs/build/lib/is-promise.js"(exports2) {
53
+ "node_modules/yargs/build/lib/is-promise.js"(exports2) {
54
54
  "use strict";
55
55
  Object.defineProperty(exports2, "__esModule", { value: true });
56
56
  exports2.isPromise = void 0;
@@ -61,9 +61,9 @@ var require_is_promise = __commonJS({
61
61
  }
62
62
  });
63
63
 
64
- // ../../../node_modules/yargs/build/lib/yerror.js
64
+ // node_modules/yargs/build/lib/yerror.js
65
65
  var require_yerror = __commonJS({
66
- "../../../node_modules/yargs/build/lib/yerror.js"(exports2) {
66
+ "node_modules/yargs/build/lib/yerror.js"(exports2) {
67
67
  "use strict";
68
68
  Object.defineProperty(exports2, "__esModule", { value: true });
69
69
  exports2.YError = void 0;
@@ -78,9 +78,9 @@ var require_yerror = __commonJS({
78
78
  }
79
79
  });
80
80
 
81
- // ../../../node_modules/yargs/build/lib/parse-command.js
81
+ // node_modules/yargs/build/lib/parse-command.js
82
82
  var require_parse_command = __commonJS({
83
- "../../../node_modules/yargs/build/lib/parse-command.js"(exports2) {
83
+ "node_modules/yargs/build/lib/parse-command.js"(exports2) {
84
84
  "use strict";
85
85
  Object.defineProperty(exports2, "__esModule", { value: true });
86
86
  exports2.parseCommand = void 0;
@@ -119,9 +119,9 @@ var require_parse_command = __commonJS({
119
119
  }
120
120
  });
121
121
 
122
- // ../../../node_modules/yargs/build/lib/argsert.js
122
+ // node_modules/yargs/build/lib/argsert.js
123
123
  var require_argsert = __commonJS({
124
- "../../../node_modules/yargs/build/lib/argsert.js"(exports2) {
124
+ "node_modules/yargs/build/lib/argsert.js"(exports2) {
125
125
  "use strict";
126
126
  Object.defineProperty(exports2, "__esModule", { value: true });
127
127
  exports2.argsert = void 0;
@@ -183,9 +183,9 @@ var require_argsert = __commonJS({
183
183
  }
184
184
  });
185
185
 
186
- // ../../../node_modules/yargs/build/lib/middleware.js
186
+ // node_modules/yargs/build/lib/middleware.js
187
187
  var require_middleware = __commonJS({
188
- "../../../node_modules/yargs/build/lib/middleware.js"(exports2) {
188
+ "node_modules/yargs/build/lib/middleware.js"(exports2) {
189
189
  "use strict";
190
190
  Object.defineProperty(exports2, "__esModule", { value: true });
191
191
  exports2.applyMiddleware = exports2.commandMiddlewareFactory = exports2.globalMiddlewareFactory = void 0;
@@ -384,9 +384,9 @@ var require_decamelize = __commonJS({
384
384
  }
385
385
  });
386
386
 
387
- // ../../../node_modules/yargs/node_modules/yargs-parser/lib/tokenize-arg-string.js
387
+ // node_modules/yargs-parser/lib/tokenize-arg-string.js
388
388
  var require_tokenize_arg_string = __commonJS({
389
- "../../../node_modules/yargs/node_modules/yargs-parser/lib/tokenize-arg-string.js"(exports2, module2) {
389
+ "node_modules/yargs-parser/lib/tokenize-arg-string.js"(exports2, module2) {
390
390
  module2.exports = function(argString) {
391
391
  if (Array.isArray(argString)) {
392
392
  return argString.map((e) => typeof e !== "string" ? e + "" : e);
@@ -420,9 +420,9 @@ var require_tokenize_arg_string = __commonJS({
420
420
  }
421
421
  });
422
422
 
423
- // ../../../node_modules/yargs/node_modules/yargs-parser/index.js
423
+ // node_modules/yargs-parser/index.js
424
424
  var require_yargs_parser = __commonJS({
425
- "../../../node_modules/yargs/node_modules/yargs-parser/index.js"(exports2, module2) {
425
+ "node_modules/yargs-parser/index.js"(exports2, module2) {
426
426
  var camelCase = require_camelcase();
427
427
  var decamelize = require_decamelize();
428
428
  var path = require("path");
@@ -1209,9 +1209,9 @@ var require_yargs_parser = __commonJS({
1209
1209
  }
1210
1210
  });
1211
1211
 
1212
- // ../../../node_modules/yargs/build/lib/command.js
1212
+ // node_modules/yargs/build/lib/command.js
1213
1213
  var require_command = __commonJS({
1214
- "../../../node_modules/yargs/build/lib/command.js"(exports2) {
1214
+ "node_modules/yargs/build/lib/command.js"(exports2) {
1215
1215
  "use strict";
1216
1216
  Object.defineProperty(exports2, "__esModule", { value: true });
1217
1217
  exports2.isCommandBuilderCallback = exports2.isCommandBuilderDefinition = exports2.isCommandHandlerDefinition = exports2.command = void 0;
@@ -1572,9 +1572,9 @@ var require_command = __commonJS({
1572
1572
  }
1573
1573
  });
1574
1574
 
1575
- // ../../../node_modules/yargs/build/lib/obj-filter.js
1575
+ // node_modules/yargs/build/lib/obj-filter.js
1576
1576
  var require_obj_filter = __commonJS({
1577
- "../../../node_modules/yargs/build/lib/obj-filter.js"(exports2) {
1577
+ "node_modules/yargs/build/lib/obj-filter.js"(exports2) {
1578
1578
  "use strict";
1579
1579
  Object.defineProperty(exports2, "__esModule", { value: true });
1580
1580
  exports2.objFilter = void 0;
@@ -2922,9 +2922,9 @@ var require_wrap_ansi = __commonJS({
2922
2922
  }
2923
2923
  });
2924
2924
 
2925
- // ../../../node_modules/yargs/node_modules/cliui/index.js
2925
+ // node_modules/cliui/index.js
2926
2926
  var require_cliui = __commonJS({
2927
- "../../../node_modules/yargs/node_modules/cliui/index.js"(exports2, module2) {
2927
+ "node_modules/cliui/index.js"(exports2, module2) {
2928
2928
  "use strict";
2929
2929
  var stringWidth = require_string_width();
2930
2930
  var stripAnsi2 = require_strip_ansi();
@@ -3178,9 +3178,9 @@ var require_cliui = __commonJS({
3178
3178
  }
3179
3179
  });
3180
3180
 
3181
- // ../../../node_modules/yargs/build/lib/usage.js
3181
+ // node_modules/yargs/build/lib/usage.js
3182
3182
  var require_usage = __commonJS({
3183
- "../../../node_modules/yargs/build/lib/usage.js"(exports2) {
3183
+ "node_modules/yargs/build/lib/usage.js"(exports2) {
3184
3184
  "use strict";
3185
3185
  Object.defineProperty(exports2, "__esModule", { value: true });
3186
3186
  exports2.usage = void 0;
@@ -3654,9 +3654,9 @@ var require_usage = __commonJS({
3654
3654
  }
3655
3655
  });
3656
3656
 
3657
- // ../../../node_modules/yargs/build/lib/completion-templates.js
3657
+ // node_modules/yargs/build/lib/completion-templates.js
3658
3658
  var require_completion_templates = __commonJS({
3659
- "../../../node_modules/yargs/build/lib/completion-templates.js"(exports2) {
3659
+ "node_modules/yargs/build/lib/completion-templates.js"(exports2) {
3660
3660
  "use strict";
3661
3661
  Object.defineProperty(exports2, "__esModule", { value: true });
3662
3662
  exports2.completionZshTemplate = exports2.completionShTemplate = void 0;
@@ -3711,9 +3711,9 @@ compdef _{{app_name}}_yargs_completions {{app_name}}
3711
3711
  }
3712
3712
  });
3713
3713
 
3714
- // ../../../node_modules/yargs/build/lib/completion.js
3714
+ // node_modules/yargs/build/lib/completion.js
3715
3715
  var require_completion = __commonJS({
3716
- "../../../node_modules/yargs/build/lib/completion.js"(exports2) {
3716
+ "node_modules/yargs/build/lib/completion.js"(exports2) {
3717
3717
  "use strict";
3718
3718
  Object.defineProperty(exports2, "__esModule", { value: true });
3719
3719
  exports2.completion = void 0;
@@ -3837,9 +3837,9 @@ var require_completion = __commonJS({
3837
3837
  }
3838
3838
  });
3839
3839
 
3840
- // ../../../node_modules/yargs/build/lib/levenshtein.js
3840
+ // node_modules/yargs/build/lib/levenshtein.js
3841
3841
  var require_levenshtein = __commonJS({
3842
- "../../../node_modules/yargs/build/lib/levenshtein.js"(exports2) {
3842
+ "node_modules/yargs/build/lib/levenshtein.js"(exports2) {
3843
3843
  "use strict";
3844
3844
  Object.defineProperty(exports2, "__esModule", { value: true });
3845
3845
  exports2.levenshtein = void 0;
@@ -3872,9 +3872,9 @@ var require_levenshtein = __commonJS({
3872
3872
  }
3873
3873
  });
3874
3874
 
3875
- // ../../../node_modules/yargs/build/lib/validation.js
3875
+ // node_modules/yargs/build/lib/validation.js
3876
3876
  var require_validation = __commonJS({
3877
- "../../../node_modules/yargs/build/lib/validation.js"(exports2) {
3877
+ "node_modules/yargs/build/lib/validation.js"(exports2) {
3878
3878
  "use strict";
3879
3879
  Object.defineProperty(exports2, "__esModule", { value: true });
3880
3880
  exports2.validation = void 0;
@@ -4165,9 +4165,9 @@ ${customMsgs.join("\n")}` : "";
4165
4165
  }
4166
4166
  });
4167
4167
 
4168
- // ../../../node_modules/yargs/build/lib/apply-extends.js
4168
+ // node_modules/yargs/build/lib/apply-extends.js
4169
4169
  var require_apply_extends = __commonJS({
4170
- "../../../node_modules/yargs/build/lib/apply-extends.js"(exports2) {
4170
+ "node_modules/yargs/build/lib/apply-extends.js"(exports2) {
4171
4171
  "use strict";
4172
4172
  Object.defineProperty(exports2, "__esModule", { value: true });
4173
4173
  exports2.applyExtends = void 0;
@@ -4230,9 +4230,9 @@ var require_apply_extends = __commonJS({
4230
4230
  }
4231
4231
  });
4232
4232
 
4233
- // ../../../node_modules/yargs/build/lib/process-argv.js
4233
+ // node_modules/yargs/build/lib/process-argv.js
4234
4234
  var require_process_argv = __commonJS({
4235
- "../../../node_modules/yargs/build/lib/process-argv.js"(exports2) {
4235
+ "node_modules/yargs/build/lib/process-argv.js"(exports2) {
4236
4236
  "use strict";
4237
4237
  Object.defineProperty(exports2, "__esModule", { value: true });
4238
4238
  exports2.getProcessArgvBin = exports2.getProcessArgvWithoutBin = void 0;
@@ -4258,9 +4258,9 @@ var require_process_argv = __commonJS({
4258
4258
  }
4259
4259
  });
4260
4260
 
4261
- // ../../../node_modules/yargs/node_modules/y18n/index.js
4261
+ // node_modules/y18n/index.js
4262
4262
  var require_y18n = __commonJS({
4263
- "../../../node_modules/yargs/node_modules/y18n/index.js"(exports2, module2) {
4263
+ "node_modules/y18n/index.js"(exports2, module2) {
4264
4264
  var fs = require("fs");
4265
4265
  var path = require("path");
4266
4266
  var util2 = require("util");
@@ -4723,9 +4723,9 @@ var require_get_caller_file = __commonJS({
4723
4723
  }
4724
4724
  });
4725
4725
 
4726
- // ../../../node_modules/yargs/build/lib/yargs.js
4726
+ // node_modules/yargs/build/lib/yargs.js
4727
4727
  var require_yargs = __commonJS({
4728
- "../../../node_modules/yargs/build/lib/yargs.js"(exports2) {
4728
+ "node_modules/yargs/build/lib/yargs.js"(exports2) {
4729
4729
  "use strict";
4730
4730
  Object.defineProperty(exports2, "__esModule", { value: true });
4731
4731
  exports2.isYargsInstance = exports2.rebase = exports2.Yargs = void 0;
@@ -5801,9 +5801,9 @@ var require_yargs = __commonJS({
5801
5801
  }
5802
5802
  });
5803
5803
 
5804
- // ../../../node_modules/yargs/yargs.js
5804
+ // node_modules/yargs/yargs.js
5805
5805
  var require_yargs2 = __commonJS({
5806
- "../../../node_modules/yargs/yargs.js"(exports2, module2) {
5806
+ "node_modules/yargs/yargs.js"(exports2, module2) {
5807
5807
  "use strict";
5808
5808
  async function requiresNode8OrGreater() {
5809
5809
  }
@@ -5816,9 +5816,9 @@ var require_yargs2 = __commonJS({
5816
5816
  }
5817
5817
  });
5818
5818
 
5819
- // ../../../node_modules/yargs/index.js
5819
+ // node_modules/yargs/index.js
5820
5820
  var require_yargs3 = __commonJS({
5821
- "../../../node_modules/yargs/index.js"(exports2, module2) {
5821
+ "node_modules/yargs/index.js"(exports2, module2) {
5822
5822
  "use strict";
5823
5823
  var yargs2 = require_yargs2();
5824
5824
  var processArgv = require_process_argv();
@@ -29772,8 +29772,16 @@ function getMessage(body) {
29772
29772
  }
29773
29773
  return "";
29774
29774
  }
29775
- async function downloadFile(url2, ca) {
29776
- const httpsAgent = ca ? new import_https2.Agent({ ca }) : void 0;
29775
+ function getAgent({ allowSelfSigned, ca }) {
29776
+ if (ca) {
29777
+ return new import_https2.Agent({ ca });
29778
+ } else if (allowSelfSigned) {
29779
+ return new import_https2.Agent({ rejectUnauthorized: false });
29780
+ } else {
29781
+ return void 0;
29782
+ }
29783
+ }
29784
+ async function downloadFile(url2, httpsAgent) {
29777
29785
  try {
29778
29786
  const res = await axios_default.get(url2, {
29779
29787
  responseType: "stream",
@@ -29787,8 +29795,7 @@ async function downloadFile(url2, ca) {
29787
29795
  return [];
29788
29796
  }
29789
29797
  }
29790
- function postForm(target, scheme, key, formData, customHeaders = {}, ca, interactive = false) {
29791
- const httpsAgent = ca ? new import_https2.Agent({ ca }) : void 0;
29798
+ function postForm(target, scheme, key, formData, customHeaders = {}, httpsAgent, interactive = false) {
29792
29799
  const form = new import_form_data2.default();
29793
29800
  Object.keys(formData).forEach((key2) => {
29794
29801
  const value = formData[key2];
@@ -29837,7 +29844,7 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
29837
29844
  if (interactive && "interactiveAuth" in data) {
29838
29845
  const { interactiveAuth } = data;
29839
29846
  if (typeof interactiveAuth === "string") {
29840
- return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) => postForm(target, mode, token, formData, customHeaders, ca, false));
29847
+ return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) => postForm(target, mode, token, formData, customHeaders, httpsAgent, false));
29841
29848
  }
29842
29849
  }
29843
29850
  const message = getMessage(data) || "";
@@ -29871,9 +29878,9 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
29871
29878
  };
29872
29879
  });
29873
29880
  }
29874
- function postFile(target, scheme, key, file, customFields = {}, customHeaders = {}, ca, interactive = false) {
29881
+ function postFile(target, scheme, key, file, customFields = {}, customHeaders = {}, agent, interactive = false) {
29875
29882
  const data = { ...customFields, file: [file, "microfrontend.tgz"] };
29876
- return postForm(target, scheme, key, data, customHeaders, ca, interactive);
29883
+ return postForm(target, scheme, key, data, customHeaders, agent, interactive);
29877
29884
  }
29878
29885
 
29879
29886
  // src/scripts.ts
@@ -29991,7 +29998,7 @@ async function getCa(cert) {
29991
29998
  }
29992
29999
  return void 0;
29993
30000
  }
29994
- async function getFiles(baseDir, sources, from, ca) {
30001
+ async function getFiles(baseDir, sources, from, agent) {
29995
30002
  switch (from) {
29996
30003
  case "local": {
29997
30004
  const allFiles = await Promise.all(sources.map((s) => matchFiles(baseDir, s)));
@@ -30025,12 +30032,12 @@ async function getFiles(baseDir, sources, from, ca) {
30025
30032
  return allMatches.filter(isFile2);
30026
30033
  }
30027
30034
  case "remote": {
30028
- const allFiles = await Promise.all(sources.map((s) => downloadFile(s, ca)));
30035
+ const allFiles = await Promise.all(sources.map((s) => downloadFile(s, agent)));
30029
30036
  return allFiles.reduce((result, files) => [...result, ...files], []);
30030
30037
  }
30031
30038
  case "npm": {
30032
30039
  const allUrls = await Promise.all(sources.map((s) => findTarball(s)));
30033
- const allFiles = await Promise.all(allUrls.map((url2) => downloadFile(url2, ca)));
30040
+ const allFiles = await Promise.all(allUrls.map((url2) => downloadFile(url2, agent)));
30034
30041
  return allFiles.reduce((result, files) => [...result, ...files], []);
30035
30042
  }
30036
30043
  }
@@ -30042,18 +30049,20 @@ var defaultArgs = (0, import_rc.default)("microfrontend", {
30042
30049
  url: void 0,
30043
30050
  apiKey: void 0,
30044
30051
  cert: void 0,
30052
+ allowSelfSigned: false,
30045
30053
  mode: "basic",
30046
30054
  from: "local",
30047
30055
  fields: {},
30048
30056
  headers: {},
30049
30057
  interactive: false
30050
30058
  });
30051
- var args = yargs.string("source").describe("source", "Sets the source of either the previously packed *.tgz bundle or the directory to publish.").default("source", current).string("url").describe("url", "Sets the explicit URL where to publish the micro frontend to.").default("url", defaultArgs.url).string("api-key").describe("api-key", "Sets the potential API key to send to the service.").default("api-key", defaultArgs.apiKey).string("cert").describe("cert", "Sets a custom certificate authority to use, if any.").default("cert", defaultArgs.cert).choices("mode", publishModeKeys).describe("mode", "Sets the authorization mode to use.").default("mode", defaultArgs.mode).alias("mode", "auth-mode").choices("from", fromKeys).describe("from", "Sets the type of the source to use for publishing.").default("from", defaultArgs.from).option("fields", void 0).describe("fields", "Sets additional fields to be included in the feed service request.").default("fields", defaultArgs.fields).option("headers", void 0).describe("headers", "Sets additional headers to be included in the feed service request.").default("headers", defaultArgs.headers).boolean("interactive").describe("interactive", "Defines if authorization tokens can be retrieved interactively.").default("interactive", defaultArgs.interactive).argv;
30059
+ var args = yargs.string("source").describe("source", "Sets the source of either the previously packed *.tgz bundle or the directory to publish.").default("source", current).string("url").describe("url", "Sets the explicit URL where to publish the micro frontend to.").default("url", defaultArgs.url).string("api-key").describe("api-key", "Sets the potential API key to send to the service.").default("api-key", defaultArgs.apiKey).string("cert").describe("cert", "Sets a custom certificate authority to use, if any.").default("cert", defaultArgs.cert).boolean("allow-self-signed").describe("allow-self-signed", "Indicates that self-signed certificates should be allowed.").default("allow-self-signed", defaultArgs.allowSelfSigned).choices("mode", publishModeKeys).describe("mode", "Sets the authorization mode to use.").default("mode", defaultArgs.mode).alias("mode", "auth-mode").choices("from", fromKeys).describe("from", "Sets the type of the source to use for publishing.").default("from", defaultArgs.from).option("fields", void 0).describe("fields", "Sets additional fields to be included in the feed service request.").default("fields", defaultArgs.fields).option("headers", void 0).describe("headers", "Sets additional headers to be included in the feed service request.").default("headers", defaultArgs.headers).boolean("interactive").describe("interactive", "Defines if authorization tokens can be retrieved interactively.").default("interactive", defaultArgs.interactive).argv;
30052
30060
  async function run() {
30053
- const { cert, source, from, url: url2, "api-key": apiKey, headers, fields, interactive, mode } = args;
30061
+ const { cert, source, from, url: url2, "api-key": apiKey, "allow-self-signed": allowSelfSigned, headers, fields, interactive, mode } = args;
30054
30062
  const sources = Array.isArray(source) ? source : [source];
30055
30063
  const ca = await getCa(cert);
30056
- const files = await getFiles(current, sources, from, ca);
30064
+ const agent = getAgent({ ca, allowSelfSigned });
30065
+ const files = await getFiles(current, sources, from, agent);
30057
30066
  const successfulUploads = [];
30058
30067
  if (files.length === 0) {
30059
30068
  fail("No micro frontends for publishing found: %s.", sources.join(", "));
@@ -30063,7 +30072,7 @@ async function run() {
30063
30072
  const content = await (0, import_promises2.readFile)(file);
30064
30073
  if (content) {
30065
30074
  progress(`Publishing "%s" ...`, file, url2);
30066
- const { success, status, response } = await postFile(url2, mode, apiKey, content, fields, headers, ca, interactive);
30075
+ const { success, status, response } = await postFile(url2, mode, apiKey, content, fields, headers, agent, interactive);
30067
30076
  const result = typeof response !== "string" ? JSON.stringify(response, void 0, 2) : response;
30068
30077
  if (success) {
30069
30078
  successfulUploads.push(file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "publish-microfrontend",
3
- "version": "1.7.2",
3
+ "version": "1.7.3-beta.7581",
4
4
  "description": "A CLI for publishing micro frontends to a feed service.",
5
5
  "keywords": [
6
6
  "modules",
@@ -69,5 +69,5 @@
69
69
  "typescript": "^5.0.0",
70
70
  "yargs": "^15.0.0"
71
71
  },
72
- "gitHead": "79c505aaf4c6be1d279c1f554ab60321f9f5ef68"
72
+ "gitHead": "dcd813c6e28e2e2995033a83d8e3e092f85a4984"
73
73
  }
package/src/http.ts CHANGED
@@ -34,10 +34,22 @@ export interface PostFormResult {
34
34
 
35
35
  export type FormDataObj = Record<string, string | [Buffer, string]>;
36
36
 
37
+ export interface AgentOptions {
38
+ ca?: Buffer;
39
+ allowSelfSigned?: boolean;
40
+ }
37
41
 
38
- export async function downloadFile(url: string, ca?: Buffer): Promise<Array<string>> {
39
- const httpsAgent = ca ? new Agent({ ca }) : undefined;
42
+ export function getAgent({ allowSelfSigned, ca }: AgentOptions) {
43
+ if (ca) {
44
+ return new Agent({ ca });
45
+ } else if (allowSelfSigned) {
46
+ return new Agent({ rejectUnauthorized: false });
47
+ } else {
48
+ return undefined;
49
+ }
50
+ }
40
51
 
52
+ export async function downloadFile(url: string, httpsAgent?: Agent): Promise<Array<string>> {
41
53
  try {
42
54
  const res = await axios.get<Stream>(url, {
43
55
  responseType: 'stream',
@@ -58,10 +70,9 @@ export function postForm(
58
70
  key: string,
59
71
  formData: FormDataObj,
60
72
  customHeaders: Record<string, string> = {},
61
- ca?: Buffer,
73
+ httpsAgent?: Agent,
62
74
  interactive = false,
63
75
  ): Promise<PostFormResult> {
64
- const httpsAgent = ca ? new Agent({ ca }) : undefined;
65
76
  const form = new FormData();
66
77
 
67
78
  Object.keys(formData).forEach((key) => {
@@ -124,7 +135,7 @@ export function postForm(
124
135
 
125
136
  if (typeof interactiveAuth === 'string') {
126
137
  return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
127
- postForm(target, mode, token, formData, customHeaders, ca, false),
138
+ postForm(target, mode, token, formData, customHeaders, httpsAgent, false),
128
139
  );
129
140
  }
130
141
  }
@@ -173,9 +184,9 @@ export function postFile(
173
184
  file: Buffer,
174
185
  customFields: Record<string, string> = {},
175
186
  customHeaders: Record<string, string> = {},
176
- ca?: Buffer,
187
+ agent?: Agent,
177
188
  interactive = false,
178
189
  ): Promise<PostFormResult> {
179
190
  const data: FormDataObj = { ...customFields, file: [file, 'microfrontend.tgz'] };
180
- return postForm(target, scheme, key, data, customHeaders, ca, interactive);
191
+ return postForm(target, scheme, key, data, customHeaders, agent, interactive);
181
192
  }
package/src/index.ts CHANGED
@@ -7,13 +7,14 @@ import { basename } from 'path';
7
7
  import { readFile } from 'fs/promises';
8
8
  import { progress, fail, logDone, logFail, logInfo } from './log';
9
9
  import { getCa, getFiles } from './utils';
10
- import { postFile } from './http';
10
+ import { getAgent, postFile } from './http';
11
11
 
12
12
  const current = process.cwd();
13
13
  const defaultArgs = rc('microfrontend', {
14
14
  url: undefined,
15
15
  apiKey: undefined,
16
16
  cert: undefined,
17
+ allowSelfSigned: false,
17
18
  mode: 'basic',
18
19
  from: 'local',
19
20
  fields: {},
@@ -34,6 +35,9 @@ const args = yargs
34
35
  .string('cert')
35
36
  .describe('cert', 'Sets a custom certificate authority to use, if any.')
36
37
  .default('cert', defaultArgs.cert)
38
+ .boolean('allow-self-signed')
39
+ .describe('allow-self-signed', 'Indicates that self-signed certificates should be allowed.')
40
+ .default('allow-self-signed', defaultArgs.allowSelfSigned)
37
41
  .choices('mode', publishModeKeys)
38
42
  .describe('mode', 'Sets the authorization mode to use.')
39
43
  .default('mode', defaultArgs.mode)
@@ -52,10 +56,11 @@ const args = yargs
52
56
  .default('interactive', defaultArgs.interactive).argv;
53
57
 
54
58
  async function run() {
55
- const { cert, source, from, url, 'api-key': apiKey, headers, fields, interactive, mode } = args;
59
+ const { cert, source, from, url, 'api-key': apiKey, 'allow-self-signed': allowSelfSigned, headers, fields, interactive, mode } = args;
56
60
  const sources = Array.isArray(source) ? source : [source];
57
61
  const ca = await getCa(cert);
58
- const files = await getFiles(current, sources, from, ca);
62
+ const agent = getAgent({ ca, allowSelfSigned });
63
+ const files = await getFiles(current, sources, from, agent);
59
64
  const successfulUploads: Array<string> = [];
60
65
 
61
66
  if (files.length === 0) {
@@ -76,7 +81,7 @@ async function run() {
76
81
  content,
77
82
  fields,
78
83
  headers,
79
- ca,
84
+ agent,
80
85
  interactive,
81
86
  );
82
87
 
package/src/utils.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import glob from 'glob';
2
+ import { Agent } from 'https';
2
3
  import { existsSync, statSync } from 'fs';
3
4
  import { stat, readFile, readdir, copyFile, rm } from 'fs/promises';
4
5
  import { dirname, basename, resolve } from 'path';
@@ -83,7 +84,7 @@ export async function getFiles(
83
84
  baseDir: string,
84
85
  sources: Array<string>,
85
86
  from: string,
86
- ca: Buffer,
87
+ agent: Agent,
87
88
  ): Promise<Array<string>> {
88
89
  switch (from) {
89
90
  case 'local': {
@@ -127,12 +128,12 @@ export async function getFiles(
127
128
  return allMatches.filter(isFile);
128
129
  }
129
130
  case 'remote': {
130
- const allFiles = await Promise.all(sources.map((s) => downloadFile(s, ca)));
131
+ const allFiles = await Promise.all(sources.map((s) => downloadFile(s, agent)));
131
132
  return allFiles.reduce((result, files) => [...result, ...files], []);
132
133
  }
133
134
  case 'npm': {
134
135
  const allUrls = await Promise.all(sources.map((s) => findTarball(s)));
135
- const allFiles = await Promise.all(allUrls.map((url) => downloadFile(url, ca)));
136
+ const allFiles = await Promise.all(allUrls.map((url) => downloadFile(url, agent)));
136
137
  return allFiles.reduce((result, files) => [...result, ...files], []);
137
138
  }
138
139
  }