publish-microfrontend 1.4.0-beta.6250 → 1.4.0-beta.6252

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 (2) hide show
  1. package/lib/index.js +128 -175
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -1,27 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
6
  var __getProtoOf = Object.getPrototypeOf;
10
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
8
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
26
9
  var __commonJS = (cb, mod) => function __require() {
27
10
  return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -37,26 +20,6 @@ var __reExport = (target, module2, desc) => {
37
20
  var __toModule = (module2) => {
38
21
  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);
39
22
  };
40
- var __async = (__this, __arguments, generator) => {
41
- return new Promise((resolve3, reject) => {
42
- var fulfilled = (value) => {
43
- try {
44
- step(generator.next(value));
45
- } catch (e) {
46
- reject(e);
47
- }
48
- };
49
- var rejected = (value) => {
50
- try {
51
- step(generator.throw(value));
52
- } catch (e) {
53
- reject(e);
54
- }
55
- };
56
- var step = (x) => x.done ? resolve3(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
57
- step((generator = generator.apply(__this, __arguments)).next());
58
- });
59
- };
60
23
 
61
24
  // ../../../node_modules/yargs/build/lib/common-types.js
62
25
  var require_common_types = __commonJS({
@@ -29039,14 +29002,12 @@ var isWindows = process.platform === "win32";
29039
29002
 
29040
29003
  // src/browser.ts
29041
29004
  var import_open = __toModule(require_open());
29042
- function openBrowserAt(address) {
29043
- return __async(this, null, function* () {
29044
- try {
29045
- yield (0, import_open.default)(address, void 0);
29046
- } catch (err) {
29047
- logFail("Failed to open the browser: %s", err);
29048
- }
29049
- });
29005
+ async function openBrowserAt(address) {
29006
+ try {
29007
+ await (0, import_open.default)(address, void 0);
29008
+ } catch (err) {
29009
+ logFail("Failed to open the browser: %s", err);
29010
+ }
29050
29011
  }
29051
29012
 
29052
29013
  // src/interactive.ts
@@ -29059,11 +29020,12 @@ function getTokenInteractively(url2, httpsAgent) {
29059
29020
  clientName: "Publish Micro Frontend CLI",
29060
29021
  description: "Authorize the Publish Micro Frontend CLI temporarily to perform actions in your name."
29061
29022
  }, {
29062
- headers: __spreadProps(__spreadValues({}, standardHeaders), {
29023
+ headers: {
29024
+ ...standardHeaders,
29063
29025
  "content-type": "application/json"
29064
- }),
29026
+ },
29065
29027
  httpsAgent
29066
- }).then((res) => __async(this, null, function* () {
29028
+ }).then(async (res) => {
29067
29029
  const { loginUrl, callbackUrl, expires } = res.data;
29068
29030
  const now = new Date();
29069
29031
  const then = new Date(expires);
@@ -29075,13 +29037,13 @@ function getTokenInteractively(url2, httpsAgent) {
29075
29037
  openBrowserAt(loginUrl);
29076
29038
  try {
29077
29039
  while (true) {
29078
- const { data, status } = yield axios_default.get(callbackUrl);
29040
+ const { data, status } = await axios_default.get(callbackUrl);
29079
29041
  if (status === 202) {
29080
- yield new Promise((resolve3) => setTimeout(resolve3, 5e3));
29042
+ await new Promise((resolve3) => setTimeout(resolve3, 5e3));
29081
29043
  continue;
29082
29044
  }
29083
29045
  if (status === 200) {
29084
- return __spreadValues({}, data);
29046
+ return { ...data };
29085
29047
  }
29086
29048
  throw new Error(`Could not get status from interactive login endpoint.`);
29087
29049
  }
@@ -29090,7 +29052,7 @@ function getTokenInteractively(url2, httpsAgent) {
29090
29052
  } finally {
29091
29053
  logResume();
29092
29054
  }
29093
- }));
29055
+ });
29094
29056
  }
29095
29057
  return tokenRetrievers[url2];
29096
29058
  }
@@ -29130,22 +29092,20 @@ function getMessage(body) {
29130
29092
  }
29131
29093
  return "";
29132
29094
  }
29133
- function downloadFile(url2, ca) {
29134
- return __async(this, null, function* () {
29135
- const httpsAgent = ca ? new import_https2.Agent({ ca }) : void 0;
29136
- try {
29137
- const res = yield axios_default.get(url2, {
29138
- responseType: "stream",
29139
- headers: standardHeaders,
29140
- httpsAgent
29141
- });
29142
- const target = getRandomTempFile();
29143
- return streamToFile(res.data, target);
29144
- } catch (error) {
29145
- logWarn("Failed HTTP GET requested: %s", error.message);
29146
- return [];
29147
- }
29148
- });
29095
+ async function downloadFile(url2, ca) {
29096
+ const httpsAgent = ca ? new import_https2.Agent({ ca }) : void 0;
29097
+ try {
29098
+ const res = await axios_default.get(url2, {
29099
+ responseType: "stream",
29100
+ headers: standardHeaders,
29101
+ httpsAgent
29102
+ });
29103
+ const target = getRandomTempFile();
29104
+ return streamToFile(res.data, target);
29105
+ } catch (error) {
29106
+ logWarn("Failed HTTP GET requested: %s", error.message);
29107
+ return [];
29108
+ }
29149
29109
  }
29150
29110
  function postForm(target, scheme, key, formData, customHeaders = {}, ca, interactive = false) {
29151
29111
  const httpsAgent = ca ? new import_https2.Agent({ ca }) : void 0;
@@ -29158,7 +29118,11 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
29158
29118
  form.append(key2, value[0], value[1]);
29159
29119
  }
29160
29120
  });
29161
- const headers = __spreadValues(__spreadValues(__spreadValues({}, form.getHeaders()), standardHeaders), customHeaders);
29121
+ const headers = {
29122
+ ...form.getHeaders(),
29123
+ ...standardHeaders,
29124
+ ...customHeaders
29125
+ };
29162
29126
  if (key) {
29163
29127
  switch (scheme) {
29164
29128
  case "basic":
@@ -29188,7 +29152,6 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
29188
29152
  response: res.data
29189
29153
  };
29190
29154
  }, (error) => {
29191
- var _a;
29192
29155
  if (error.response) {
29193
29156
  const { data, statusText, status } = error.response;
29194
29157
  if (interactive && "interactiveAuth" in data) {
@@ -29208,7 +29171,7 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
29208
29171
  let errorMessage = error.errno || "Unknown Axios Error";
29209
29172
  if (typeof error.toJSON === "function") {
29210
29173
  const errorObj = error.toJSON();
29211
- errorMessage = (_a = errorObj == null ? void 0 : errorObj.message) != null ? _a : errorMessage;
29174
+ errorMessage = errorObj?.message ?? errorMessage;
29212
29175
  }
29213
29176
  logWarn("The HTTP Post request failed with error: %s", errorMessage);
29214
29177
  return {
@@ -29229,7 +29192,7 @@ function postForm(target, scheme, key, formData, customHeaders = {}, ca, interac
29229
29192
  });
29230
29193
  }
29231
29194
  function postFile(target, scheme, key, file, customFields = {}, customHeaders = {}, ca, interactive = false) {
29232
- const data = __spreadProps(__spreadValues({}, customFields), { file: [file, "microfrontend.tgz"] });
29195
+ const data = { ...customFields, file: [file, "microfrontend.tgz"] };
29233
29196
  return postForm(target, scheme, key, data, customHeaders, ca, interactive);
29234
29197
  }
29235
29198
 
@@ -29297,19 +29260,15 @@ function runNpmProcess(args2, target, output) {
29297
29260
  const cwd = (0, import_path3.resolve)(process.cwd(), target);
29298
29261
  return runCommand("npm", args2, cwd, output);
29299
29262
  }
29300
- function findTarball(packageRef, target = ".", ...flags) {
29301
- return __async(this, null, function* () {
29302
- const ms = new MemoryStream();
29303
- yield runNpmProcess(["view", packageRef, "dist.tarball", ...flags], target, ms);
29304
- return ms.value;
29305
- });
29263
+ async function findTarball(packageRef, target = ".", ...flags) {
29264
+ const ms = new MemoryStream();
29265
+ await runNpmProcess(["view", packageRef, "dist.tarball", ...flags], target, ms);
29266
+ return ms.value;
29306
29267
  }
29307
- function createPackage(target = ".", ...flags) {
29308
- return __async(this, null, function* () {
29309
- const ms = new MemoryStream();
29310
- yield runNpmProcess(["pack", ...flags], target, ms);
29311
- return ms.value;
29312
- });
29268
+ async function createPackage(target = ".", ...flags) {
29269
+ const ms = new MemoryStream();
29270
+ await runNpmProcess(["pack", ...flags], target, ms);
29271
+ return ms.value;
29313
29272
  }
29314
29273
  function onlyUnique(value, index, self2) {
29315
29274
  return self2.indexOf(value) === index;
@@ -29341,64 +29300,60 @@ function matchFiles(baseDir, pattern) {
29341
29300
  });
29342
29301
  });
29343
29302
  }
29344
- function getCa(cert) {
29345
- return __async(this, null, function* () {
29346
- if (cert && typeof cert === "string") {
29347
- const statCert = yield (0, import_promises.stat)(cert).catch(() => void 0);
29348
- if (statCert == null ? void 0 : statCert.isFile()) {
29349
- const dir = (0, import_path3.dirname)(cert);
29350
- const file = (0, import_path3.basename)(cert);
29351
- return yield (0, import_promises.readFile)((0, import_path3.resolve)(dir, file));
29352
- }
29303
+ async function getCa(cert) {
29304
+ if (cert && typeof cert === "string") {
29305
+ const statCert = await (0, import_promises.stat)(cert).catch(() => void 0);
29306
+ if (statCert?.isFile()) {
29307
+ const dir = (0, import_path3.dirname)(cert);
29308
+ const file = (0, import_path3.basename)(cert);
29309
+ return await (0, import_promises.readFile)((0, import_path3.resolve)(dir, file));
29353
29310
  }
29354
- return void 0;
29355
- });
29311
+ }
29312
+ return void 0;
29356
29313
  }
29357
- function getFiles(baseDir, sources, from, ca) {
29358
- return __async(this, null, function* () {
29359
- switch (from) {
29360
- case "local": {
29361
- const allFiles = yield Promise.all(sources.map((s) => matchFiles(baseDir, s)));
29362
- const allMatches = allFiles.reduce((result, files) => [...result, ...files], []).filter(onlyUnique);
29363
- if (allMatches.every(isDirectory)) {
29364
- const dirs = allMatches.filter((m) => (0, import_fs2.existsSync)((0, import_path3.resolve)(m, "package.json")));
29365
- const createdFiles = yield Promise.all(dirs.map((dir) => __async(this, null, function* () {
29366
- const packagePath = (0, import_path3.resolve)(dir, "package.json");
29367
- const packageContent = yield (0, import_promises.readFile)(packagePath, "utf8");
29368
- try {
29369
- const { name, version } = JSON.parse(packageContent);
29370
- const proposedName = `${name.replace("@", "").replace("/", "-")}-${version}.tgz`;
29371
- const previousFiles = yield (0, import_promises.readdir)(dir);
29372
- if (previousFiles.includes(proposedName)) {
29373
- return (0, import_path3.resolve)(dir, proposedName);
29374
- }
29375
- yield createPackage(dir);
29376
- const currentFiles = yield (0, import_promises.readdir)(dir);
29377
- const tarball = currentFiles.find((m) => !previousFiles.includes(m) && m.endsWith(".tgz"));
29378
- const target = getRandomTempFile();
29379
- const source = (0, import_path3.resolve)(dir, tarball);
29380
- yield (0, import_promises.copyFile)(source, target);
29381
- yield (0, import_promises.rm)(source);
29382
- return target;
29383
- } catch (e) {
29384
- logWarn('Encountered error in "%s". Skipping.', dir);
29314
+ async function getFiles(baseDir, sources, from, ca) {
29315
+ switch (from) {
29316
+ case "local": {
29317
+ const allFiles = await Promise.all(sources.map((s) => matchFiles(baseDir, s)));
29318
+ const allMatches = allFiles.reduce((result, files) => [...result, ...files], []).filter(onlyUnique);
29319
+ if (allMatches.every(isDirectory)) {
29320
+ const dirs = allMatches.filter((m) => (0, import_fs2.existsSync)((0, import_path3.resolve)(m, "package.json")));
29321
+ const createdFiles = await Promise.all(dirs.map(async (dir) => {
29322
+ const packagePath = (0, import_path3.resolve)(dir, "package.json");
29323
+ const packageContent = await (0, import_promises.readFile)(packagePath, "utf8");
29324
+ try {
29325
+ const { name, version } = JSON.parse(packageContent);
29326
+ const proposedName = `${name.replace("@", "").replace("/", "-")}-${version}.tgz`;
29327
+ const previousFiles = await (0, import_promises.readdir)(dir);
29328
+ if (previousFiles.includes(proposedName)) {
29329
+ return (0, import_path3.resolve)(dir, proposedName);
29385
29330
  }
29386
- })));
29387
- return createdFiles.filter(isFile2);
29388
- }
29389
- return allMatches.filter(isFile2);
29390
- }
29391
- case "remote": {
29392
- const allFiles = yield Promise.all(sources.map((s) => downloadFile(s, ca)));
29393
- return allFiles.reduce((result, files) => [...result, ...files], []);
29394
- }
29395
- case "npm": {
29396
- const allUrls = yield Promise.all(sources.map((s) => findTarball(s)));
29397
- const allFiles = yield Promise.all(allUrls.map((url2) => downloadFile(url2, ca)));
29398
- return allFiles.reduce((result, files) => [...result, ...files], []);
29331
+ await createPackage(dir);
29332
+ const currentFiles = await (0, import_promises.readdir)(dir);
29333
+ const tarball = currentFiles.find((m) => !previousFiles.includes(m) && m.endsWith(".tgz"));
29334
+ const target = getRandomTempFile();
29335
+ const source = (0, import_path3.resolve)(dir, tarball);
29336
+ await (0, import_promises.copyFile)(source, target);
29337
+ await (0, import_promises.rm)(source);
29338
+ return target;
29339
+ } catch {
29340
+ logWarn('Encountered error in "%s". Skipping.', dir);
29341
+ }
29342
+ }));
29343
+ return createdFiles.filter(isFile2);
29399
29344
  }
29345
+ return allMatches.filter(isFile2);
29400
29346
  }
29401
- });
29347
+ case "remote": {
29348
+ const allFiles = await Promise.all(sources.map((s) => downloadFile(s, ca)));
29349
+ return allFiles.reduce((result, files) => [...result, ...files], []);
29350
+ }
29351
+ case "npm": {
29352
+ const allUrls = await Promise.all(sources.map((s) => findTarball(s)));
29353
+ const allFiles = await Promise.all(allUrls.map((url2) => downloadFile(url2, ca)));
29354
+ return allFiles.reduce((result, files) => [...result, ...files], []);
29355
+ }
29356
+ }
29402
29357
  }
29403
29358
 
29404
29359
  // src/index.ts
@@ -29414,48 +29369,46 @@ var defaultArgs = (0, import_rc.default)("microfrontend", {
29414
29369
  interactive: false
29415
29370
  });
29416
29371
  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;
29417
- function run() {
29418
- return __async(this, null, function* () {
29419
- const { cert, source, from, url: url2, "api-key": apiKey, headers, fields, interactive, mode } = args;
29420
- const sources = Array.isArray(source) ? source : [source];
29421
- const ca = yield getCa(cert);
29422
- const files = yield getFiles(current, sources, from, ca);
29423
- const successfulUploads = [];
29424
- if (files.length === 0) {
29425
- fail("No micro frontends for publishing found: %s.", sources.join(", "));
29426
- }
29427
- for (const file of files) {
29428
- const fileName = (0, import_path4.basename)(file);
29429
- const content = yield (0, import_promises2.readFile)(file);
29430
- if (content) {
29431
- progress(`Publishing "%s" ...`, file, url2);
29432
- const { success, status, response } = yield postFile(url2, mode, apiKey, content, fields, headers, ca, interactive);
29433
- const result = typeof response !== "string" ? JSON.stringify(response, void 0, 2) : response;
29434
- if (success) {
29435
- successfulUploads.push(file);
29436
- if (response) {
29437
- logInfo("Response from server: %s", result);
29438
- }
29439
- progress(`Published successfully!`);
29440
- } else if (status === 402) {
29441
- logFail("Payment required to upload the micro frontend: %s", result);
29442
- } else if (status === 409) {
29443
- logFail('Version of the micro frontend already exists: %s"', result);
29444
- } else if (status === 413) {
29445
- logFail('Size too large for uploading the micro frontend: %s"', result);
29446
- } else {
29447
- logFail('Failed to upload micro frontend "%s".', fileName);
29448
- }
29372
+ async function run() {
29373
+ const { cert, source, from, url: url2, "api-key": apiKey, headers, fields, interactive, mode } = args;
29374
+ const sources = Array.isArray(source) ? source : [source];
29375
+ const ca = await getCa(cert);
29376
+ const files = await getFiles(current, sources, from, ca);
29377
+ const successfulUploads = [];
29378
+ if (files.length === 0) {
29379
+ fail("No micro frontends for publishing found: %s.", sources.join(", "));
29380
+ }
29381
+ for (const file of files) {
29382
+ const fileName = (0, import_path4.basename)(file);
29383
+ const content = await (0, import_promises2.readFile)(file);
29384
+ if (content) {
29385
+ progress(`Publishing "%s" ...`, file, url2);
29386
+ const { success, status, response } = await postFile(url2, mode, apiKey, content, fields, headers, ca, interactive);
29387
+ const result = typeof response !== "string" ? JSON.stringify(response, void 0, 2) : response;
29388
+ if (success) {
29389
+ successfulUploads.push(file);
29390
+ if (response) {
29391
+ logInfo("Response from server: %s", result);
29392
+ }
29393
+ progress(`Published successfully!`);
29394
+ } else if (status === 402) {
29395
+ logFail("Payment required to upload the micro frontend: %s", result);
29396
+ } else if (status === 409) {
29397
+ logFail('Version of the micro frontend already exists: %s"', result);
29398
+ } else if (status === 413) {
29399
+ logFail('Size too large for uploading the micro frontend: %s"', result);
29449
29400
  } else {
29450
- logFail("Failed to read Micro Frontend.");
29401
+ logFail('Failed to upload micro frontend "%s".', fileName);
29451
29402
  }
29452
- }
29453
- if (files.length === successfulUploads.length) {
29454
- logDone(`The micro frontends have been published successfully!`);
29455
29403
  } else {
29456
- fail("Failed to publish the micro frontends.");
29404
+ logFail("Failed to read Micro Frontend.");
29457
29405
  }
29458
- });
29406
+ }
29407
+ if (files.length === successfulUploads.length) {
29408
+ logDone(`The micro frontends have been published successfully!`);
29409
+ } else {
29410
+ fail("Failed to publish the micro frontends.");
29411
+ }
29459
29412
  }
29460
29413
  run();
29461
29414
  /*!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "publish-microfrontend",
3
- "version": "1.4.0-beta.6250",
3
+ "version": "1.4.0-beta.6252",
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": "7c95a8922d0cfb80e02b32bcded0256825e00c09"
72
+ "gitHead": "f30d158bb902504e233849eb7c7f65a0d3e52ce3"
73
73
  }