@awsless/awsless 0.0.5 → 0.0.7

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/dist/bin.cjs CHANGED
@@ -67,8 +67,6 @@ var debugError = (error) => {
67
67
  queue.push({
68
68
  date: /* @__PURE__ */ new Date(),
69
69
  type: style.error.dim("error"),
70
- // color: 'red',
71
- // type: 'error',
72
70
  message: typeof error === "string" ? error : error instanceof Error ? style.error(error.message || "") : JSON.stringify(error)
73
71
  });
74
72
  };
@@ -76,8 +74,6 @@ var debug = (...parts) => {
76
74
  queue.push({
77
75
  date: /* @__PURE__ */ new Date(),
78
76
  type: style.warning.dim("debug"),
79
- // color: 'yellow',
80
- // type: 'debug',
81
77
  message: parts.map((part) => typeof part === "string" ? part : JSON.stringify(part)).join(" ")
82
78
  });
83
79
  };
@@ -384,69 +380,45 @@ var SizeSchema = import_zod7.z.custom((value) => {
384
380
  }, "Invalid size").transform(toSize);
385
381
 
386
382
  // src/plugins/function/util/build-worker.ts
387
- var import_worker_threads = require("worker_threads");
388
- var cjs = typeof require !== "undefined";
389
- var importESM = `
390
- import { bundle } from "@awsless/code";
391
- import { createHash } from "crypto";
392
- import { parentPort, workerData } from "worker_threads";
393
- `;
394
- var importCJS = `
395
- const { bundle } = require("@awsless/code");
396
- const { createHash } = require("crypto");
397
- const { parentPort, workerData } = require("worker_threads");
398
- `;
399
- var workerCode = `
400
- ${cjs ? importCJS : importESM}
401
-
402
- const build = async (file) => {
403
- const { code, map } = await bundle(file, {
404
- format: 'esm',
405
- sourceMap: true,
406
- minimize: true,
407
- onwarn: () => {},
408
- moduleSideEffects: (id) => file === id,
409
- external: (importee) => (
410
- importee.startsWith('aws-sdk') ||
411
- importee.startsWith('@aws-sdk')
412
- ),
413
- })
414
-
415
- const hash = createHash('sha1').update(code).digest('hex')
416
-
417
- parentPort.postMessage(JSON.stringify({
418
- handler: 'index.default',
419
- hash,
420
- files: [
421
- { name: 'index.js', code, map: map?.toString() }
422
- ]
423
- }))
424
- }
425
-
426
- build(workerData)
427
- `;
383
+ var import_core3 = require("@swc/core");
384
+ var import_crypto = require("crypto");
428
385
  var defaultBuild = async (file) => {
429
- return new Promise((resolve, reject) => {
430
- const worker = new import_worker_threads.Worker(workerCode, { workerData: file, eval: true });
431
- const cleanUp2 = () => {
432
- worker.removeAllListeners();
433
- worker.terminate();
434
- };
435
- worker.on("message", (data) => {
436
- resolve(JSON.parse(data.toString("utf8")));
437
- cleanUp2();
438
- });
439
- worker.on("error", (data) => {
440
- reject(data);
441
- cleanUp2();
442
- });
443
- worker.on("exit", (code) => {
444
- if (code !== 0) {
445
- reject(new Error(`Worker exited with code ${code}`));
446
- cleanUp2();
386
+ const output = await (0, import_core3.bundle)({
387
+ entry: {
388
+ file
389
+ },
390
+ mode: "production",
391
+ target: "node",
392
+ externalModules: [
393
+ "@aws-sdk/*",
394
+ "@aws-sdk",
395
+ "aws-sdk"
396
+ ],
397
+ module: {},
398
+ options: {
399
+ minify: true,
400
+ sourceMaps: true,
401
+ jsc: {
402
+ target: "es2022"
447
403
  }
448
- });
404
+ },
405
+ output: {
406
+ name: "output",
407
+ path: ""
408
+ }
449
409
  });
410
+ const hash = (0, import_crypto.createHash)("sha1").update(output.file.code).digest("hex");
411
+ return {
412
+ handler: "index.default",
413
+ hash,
414
+ files: [
415
+ {
416
+ name: "index.js",
417
+ code: output.file.code,
418
+ map: output.file.map?.toString()
419
+ }
420
+ ]
421
+ };
450
422
  };
451
423
 
452
424
  // src/plugins/function/util/build.ts
@@ -473,13 +445,13 @@ var writeBuildHash = async (config2, stack, id, hash) => {
473
445
  await (0, import_promises2.writeFile)(versionFile, hash);
474
446
  };
475
447
  var writeBuildFiles = async (config2, stack, id, files) => {
476
- const bundle = await zipFiles(files);
448
+ const bundle2 = await zipFiles(files);
477
449
  const funcPath = (0, import_path3.join)(functionDir, config2.name, stack.artifactId, id);
478
450
  const filesPath = (0, import_path3.join)(funcPath, "files");
479
451
  const bundleFile = (0, import_path3.join)(funcPath, "bundle.zip");
480
- debug("Bundle size of", style.info((0, import_path3.join)(config2.name, stack.artifactId, id)), "is", style.attr((0, import_filesize.filesize)(bundle.byteLength)));
452
+ debug("Bundle size of", style.info((0, import_path3.join)(config2.name, stack.artifactId, id)), "is", style.attr((0, import_filesize.filesize)(bundle2.byteLength)));
481
453
  await (0, import_promises2.mkdir)(filesPath, { recursive: true });
482
- await (0, import_promises2.writeFile)(bundleFile, bundle);
454
+ await (0, import_promises2.writeFile)(bundleFile, bundle2);
483
455
  await Promise.all(files.map(async (file) => {
484
456
  const fileName = (0, import_path3.join)(filesPath, file.name);
485
457
  await (0, import_promises2.mkdir)((0, import_path3.basename)(fileName), { recursive: true });
@@ -491,7 +463,7 @@ var writeBuildFiles = async (config2, stack, id, files) => {
491
463
  }));
492
464
  return {
493
465
  file: bundleFile,
494
- size: bundle.byteLength
466
+ size: bundle2.byteLength
495
467
  };
496
468
  };
497
469
 
@@ -650,12 +622,12 @@ var toFunction = ({ config: config2, stack, stackConfig, assets }, id, fileOrPro
650
622
  resourceName: id,
651
623
  async build() {
652
624
  const result = await defaultBuild(props.file);
653
- const bundle = await writeBuildFiles(config2, stack, id, result.files);
625
+ const bundle2 = await writeBuildFiles(config2, stack, id, result.files);
654
626
  await writeBuildHash(config2, stack, id, result.hash);
655
627
  const func = lambda.node.defaultChild;
656
628
  func.handler = result.handler;
657
629
  return {
658
- size: formatByteSize(bundle.size)
630
+ size: formatByteSize(bundle2.size)
659
631
  };
660
632
  },
661
633
  async publish() {
@@ -1156,36 +1128,39 @@ var hr = () => {
1156
1128
  };
1157
1129
 
1158
1130
  // src/cli/ui/layout/logs.ts
1131
+ var import_wrap_ansi = __toESM(require("wrap-ansi"), 1);
1159
1132
  var previous = /* @__PURE__ */ new Date();
1160
1133
  var logs = () => {
1161
1134
  if (!process.env.VERBOSE) {
1162
1135
  return [];
1163
1136
  }
1164
1137
  const logs2 = flushDebug();
1165
- return [
1166
- hr(),
1167
- br(),
1168
- " ".repeat(3),
1169
- style.label("Debug Logs:"),
1170
- br(),
1171
- br(),
1172
- logs2.map((log) => {
1173
- const diff = log.date.getTime() - previous.getTime();
1174
- const time = `+${diff}`.padStart(7);
1175
- previous = log.date;
1176
- return [
1177
- style.attr(`${time}${style.attr.dim("ms")}`),
1178
- " [ ",
1179
- log.type,
1180
- " ] ",
1181
- log.message,
1182
- br(),
1183
- log.type === "error" ? br() : ""
1184
- ];
1185
- }),
1186
- br(),
1187
- hr()
1188
- ];
1138
+ return (term) => {
1139
+ term.out.write([
1140
+ hr(),
1141
+ br(),
1142
+ " ".repeat(3),
1143
+ style.label("Debug Logs:"),
1144
+ br(),
1145
+ br(),
1146
+ logs2.map((log) => {
1147
+ const diff = log.date.getTime() - previous.getTime();
1148
+ const time = `+${diff}`.padStart(8);
1149
+ previous = log.date;
1150
+ return (0, import_wrap_ansi.default)([
1151
+ style.attr(`${time}${style.attr.dim("ms")}`),
1152
+ " [ ",
1153
+ log.type,
1154
+ " ] ",
1155
+ log.message,
1156
+ br(),
1157
+ log.type === "error" ? br() : ""
1158
+ ].join(""), term.out.width(), { hard: true, trim: false });
1159
+ }),
1160
+ br(),
1161
+ hr()
1162
+ ]);
1163
+ };
1189
1164
  };
1190
1165
 
1191
1166
  // src/cli/ui/layout/footer.ts
@@ -1269,7 +1244,7 @@ var AppSchema = import_zod23.z.object({
1269
1244
  });
1270
1245
 
1271
1246
  // src/util/import.ts
1272
- var import_core3 = require("@swc/core");
1247
+ var import_core4 = require("@swc/core");
1273
1248
  var import_path7 = require("path");
1274
1249
  var import_promises4 = require("fs/promises");
1275
1250
  var resolveFileNameExtension = async (path) => {
@@ -1299,17 +1274,17 @@ var resolveDir = (path) => {
1299
1274
  };
1300
1275
  var importFile = async (path) => {
1301
1276
  const load = async (file) => {
1302
- let { code: code2 } = await (0, import_core3.transformFile)(file, {
1277
+ let { code: code2 } = await (0, import_core4.transformFile)(file, {
1303
1278
  isModule: true
1304
1279
  });
1305
1280
  const path2 = (0, import_path7.dirname)(file);
1306
1281
  const dir = resolveDir(file);
1307
1282
  code2 = code2.replaceAll("__dirname", `"${dir}"`);
1308
- const matches = code2.match(/import\s*{\s*[a-z0-9_]+\s*}\s*from\s*('|")(\.[\/a-z0-9_]+)('|");?/ig);
1283
+ const matches = code2.match(/import\s*{\s*[a-z0-9\_]+\s*}\s*from\s*('|")(\.[\/a-z0-9\_\-]+)('|");?/ig);
1309
1284
  if (!matches)
1310
1285
  return code2;
1311
1286
  await Promise.all(matches?.map(async (match) => {
1312
- const parts = /('|")(\.[\/a-z0-9_]+)('|")/ig.exec(match);
1287
+ const parts = /('|")(\.[\/a-z0-9\_\-]+)('|")/ig.exec(match);
1313
1288
  const from = parts[2];
1314
1289
  const file2 = await resolveFileNameExtension((0, import_path7.join)(path2, from));
1315
1290
  const result = await load(file2);
@@ -1387,6 +1362,17 @@ var header = (config2) => {
1387
1362
  ];
1388
1363
  };
1389
1364
 
1365
+ // src/util/timer.ts
1366
+ var import_pretty_hrtime = __toESM(require("pretty-hrtime"), 1);
1367
+ var createTimer = () => {
1368
+ const start = process.hrtime();
1369
+ return () => {
1370
+ const end = process.hrtime(start);
1371
+ const [time, unit] = (0, import_pretty_hrtime.default)(end).split(" ");
1372
+ return style.attr(time) + style.attr.dim(unit);
1373
+ };
1374
+ };
1375
+
1390
1376
  // src/cli/lib/signal.ts
1391
1377
  var Signal = class {
1392
1378
  constructor(value) {
@@ -1440,16 +1426,16 @@ var createSpinner = () => {
1440
1426
  };
1441
1427
 
1442
1428
  // src/cli/ui/layout/dialog.ts
1443
- var import_wrap_ansi = __toESM(require("wrap-ansi"), 1);
1429
+ var import_wrap_ansi2 = __toESM(require("wrap-ansi"), 1);
1444
1430
  var dialog = (type, lines) => {
1445
1431
  const padding = 3;
1446
1432
  const icon = style[type](symbol[type].padEnd(padding));
1447
1433
  return (term) => {
1448
1434
  term.out.write(lines.map((line, i) => {
1449
1435
  if (i === 0) {
1450
- return icon + (0, import_wrap_ansi.default)(line, term.out.width(), { hard: true });
1436
+ return icon + (0, import_wrap_ansi2.default)(line, term.out.width(), { hard: true });
1451
1437
  }
1452
- return (0, import_wrap_ansi.default)(" ".repeat(padding) + line, term.out.width(), { hard: true });
1438
+ return (0, import_wrap_ansi2.default)(" ".repeat(padding) + line, term.out.width(), { hard: true });
1453
1439
  }).join(br()) + br());
1454
1440
  };
1455
1441
  };
@@ -1457,7 +1443,7 @@ var loadingDialog = (message) => {
1457
1443
  const [icon, stop] = createSpinner();
1458
1444
  const description = new Signal(message);
1459
1445
  const time = new Signal("");
1460
- const start = /* @__PURE__ */ new Date();
1446
+ const timer = createTimer();
1461
1447
  return (term) => {
1462
1448
  term.out.write([
1463
1449
  icon,
@@ -1468,10 +1454,8 @@ var loadingDialog = (message) => {
1468
1454
  br()
1469
1455
  ]);
1470
1456
  return (message2) => {
1471
- const end = /* @__PURE__ */ new Date();
1472
- const diff = end.getTime() - start.getTime();
1473
1457
  description.set(message2);
1474
- time.set(style.attr(diff) + style.attr.dim("ms"));
1458
+ time.set(timer());
1475
1459
  stop();
1476
1460
  icon.set(style.success(symbol.success));
1477
1461
  };
@@ -1545,9 +1529,6 @@ var Interface = class {
1545
1529
  const action = parseAction(key);
1546
1530
  if (typeof action === "undefined") {
1547
1531
  this.bell();
1548
- } else if (action === "abort") {
1549
- this.showCursor();
1550
- process.exit(1);
1551
1532
  } else {
1552
1533
  const cb = actions[action];
1553
1534
  if (typeof cb === "function") {
@@ -1684,6 +1665,12 @@ var layout = async (cb) => {
1684
1665
  const term = createTerminal();
1685
1666
  term.out.clear();
1686
1667
  term.out.write(logo());
1668
+ term.in.captureInput({
1669
+ abort: () => {
1670
+ term.in.showCursor();
1671
+ process.exit(1);
1672
+ }
1673
+ });
1687
1674
  try {
1688
1675
  const options = program.optsWithGlobals();
1689
1676
  const config2 = await importConfig(options);
@@ -1740,7 +1727,6 @@ var assetBuilder = (assets) => {
1740
1727
  groups.update((groups2) => [...groups2, group]);
1741
1728
  await Promise.all(assets2.map(async (asset) => {
1742
1729
  const [icon, stop] = createSpinner();
1743
- const start = /* @__PURE__ */ new Date();
1744
1730
  const details = new Signal({});
1745
1731
  const line = flexLine(term, [
1746
1732
  icon,
@@ -1760,17 +1746,17 @@ var assetBuilder = (assets) => {
1760
1746
  " ",
1761
1747
  derive([details], (details2) => {
1762
1748
  return Object.entries(details2).map(([key, value]) => {
1763
- return `${style.label(key)}: ${value}`;
1749
+ return `${style.label(key)} ${value}`;
1764
1750
  }).join(" / ");
1765
1751
  }),
1766
1752
  br()
1767
1753
  ]);
1768
1754
  group.update((group2) => [...group2, line]);
1755
+ const timer = createTimer();
1769
1756
  const data = await asset.build?.();
1770
- const time = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
1771
1757
  details.set({
1772
1758
  ...data,
1773
- time: style.attr(time) + style.attr.dim("ms")
1759
+ time: timer()
1774
1760
  });
1775
1761
  icon.set(style.success(symbol.success));
1776
1762
  stop();
@@ -2107,10 +2093,8 @@ var stackTree = (nodes, statuses) => {
2107
2093
  style.info(id),
2108
2094
  " "
2109
2095
  ], [
2110
- // style.placeholder(' [ '),
2111
2096
  " ",
2112
2097
  status2,
2113
- // style.placeholder(' ] '),
2114
2098
  br()
2115
2099
  ]);
2116
2100
  term.out.write(line);
@@ -2121,65 +2105,6 @@ var stackTree = (nodes, statuses) => {
2121
2105
  };
2122
2106
  };
2123
2107
 
2124
- // src/cli/ui/__components/basic.ts
2125
- var br2 = () => {
2126
- return "\n";
2127
- };
2128
-
2129
- // src/cli/ui/__components/spinner.ts
2130
- var frames2 = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
2131
- var length2 = frames2.length;
2132
- var createSpinner2 = () => {
2133
- const index = new Signal(0);
2134
- const frame = derive([index], (index2) => style.info(frames2[index2 % length2]));
2135
- const interval = setInterval(() => {
2136
- index.update((i) => i + 1);
2137
- }, 80);
2138
- return [
2139
- frame,
2140
- () => {
2141
- clearInterval(interval);
2142
- }
2143
- ];
2144
- };
2145
-
2146
- // src/cli/ui/__components/dialog.ts
2147
- var dialog2 = (type, lines) => {
2148
- const padding = 3;
2149
- const icon = style[type](symbol[type].padEnd(padding));
2150
- return lines.map((line, i) => {
2151
- if (i === 0) {
2152
- return icon + line;
2153
- } else {
2154
- return " ".repeat(padding) + line;
2155
- }
2156
- }).join(br2()) + br2();
2157
- };
2158
- var loadingDialog2 = (message) => {
2159
- const [icon, stop] = createSpinner2();
2160
- const description = new Signal(message);
2161
- const time = new Signal("");
2162
- const start = /* @__PURE__ */ new Date();
2163
- return (term) => {
2164
- term.out.write([
2165
- icon,
2166
- " ",
2167
- description,
2168
- " ",
2169
- time,
2170
- br2()
2171
- ]);
2172
- return (message2) => {
2173
- const end = /* @__PURE__ */ new Date();
2174
- const diff = end.getTime() - start.getTime();
2175
- description.set(message2);
2176
- time.set(style.attr(diff) + style.attr.dim("ms"));
2177
- stop();
2178
- icon.set(style.success(symbol.success));
2179
- };
2180
- };
2181
- };
2182
-
2183
2108
  // src/cli/command/status.ts
2184
2109
  var status = (program2) => {
2185
2110
  program2.command("status").argument("[stacks...]", "Optionally filter stacks to lookup status").description("View the application status").action(async (filters) => {
@@ -2187,18 +2112,18 @@ var status = (program2) => {
2187
2112
  const { app, assets, dependencyTree } = await toApp(config2, filters);
2188
2113
  await cleanUp();
2189
2114
  await write(assetBuilder(assets));
2190
- write(br2());
2115
+ write(br());
2191
2116
  const assembly = app.synth();
2192
- const doneLoading = write(loadingDialog2("Loading stack information..."));
2117
+ const doneLoading = write(loadingDialog("Loading stack information..."));
2193
2118
  const client = new StackClient(config2);
2194
2119
  const statuses = [];
2195
2120
  const stackStatuses = {};
2196
2121
  assembly.stacks.forEach((stack) => {
2197
2122
  stackStatuses[stack.id] = new Signal(style.info("Loading..."));
2198
2123
  });
2199
- write(br2());
2124
+ write(br());
2200
2125
  write(stackTree(dependencyTree, stackStatuses));
2201
- write(br2());
2126
+ write(br());
2202
2127
  debug("Load metadata for all deployed stacks on AWS");
2203
2128
  await Promise.all(assembly.stacks.map(async (stack, i) => {
2204
2129
  const info = await client.get(stack.stackName);
@@ -2219,9 +2144,9 @@ var status = (program2) => {
2219
2144
  doneLoading("Done loading stack information");
2220
2145
  debug("Done loading data for all deployed stacks on AWS");
2221
2146
  if (statuses.includes("non-existent") || statuses.includes("out-of-date")) {
2222
- write(dialog2("warning", ["Your app has undeployed changes !!!"]));
2147
+ write(dialog("warning", ["Your app has undeployed changes !!!"]));
2223
2148
  } else {
2224
- write(dialog2("success", ["Your app has not been changed"]));
2149
+ write(dialog("success", ["Your app has not been changed"]));
2225
2150
  }
2226
2151
  });
2227
2152
  });
package/dist/bin.js CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- __require,
4
3
  definePlugin
5
- } from "./chunk-6KILQ5DR.js";
4
+ } from "./chunk-PFTL6L4F.js";
6
5
 
7
6
  // src/cli/program.ts
8
7
  import { Command } from "commander";
@@ -48,8 +47,6 @@ var debugError = (error) => {
48
47
  queue.push({
49
48
  date: /* @__PURE__ */ new Date(),
50
49
  type: style.error.dim("error"),
51
- // color: 'red',
52
- // type: 'error',
53
50
  message: typeof error === "string" ? error : error instanceof Error ? style.error(error.message || "") : JSON.stringify(error)
54
51
  });
55
52
  };
@@ -57,8 +54,6 @@ var debug = (...parts) => {
57
54
  queue.push({
58
55
  date: /* @__PURE__ */ new Date(),
59
56
  type: style.warning.dim("debug"),
60
- // color: 'yellow',
61
- // type: 'debug',
62
57
  message: parts.map((part) => typeof part === "string" ? part : JSON.stringify(part)).join(" ")
63
58
  });
64
59
  };
@@ -362,69 +357,45 @@ var SizeSchema = z7.custom((value) => {
362
357
  }, "Invalid size").transform(toSize);
363
358
 
364
359
  // src/plugins/function/util/build-worker.ts
365
- import { Worker } from "worker_threads";
366
- var cjs = typeof __require !== "undefined";
367
- var importESM = `
368
- import { bundle } from "@awsless/code";
360
+ import { bundle } from "@swc/core";
369
361
  import { createHash } from "crypto";
370
- import { parentPort, workerData } from "worker_threads";
371
- `;
372
- var importCJS = `
373
- const { bundle } = require("@awsless/code");
374
- const { createHash } = require("crypto");
375
- const { parentPort, workerData } = require("worker_threads");
376
- `;
377
- var workerCode = `
378
- ${cjs ? importCJS : importESM}
379
-
380
- const build = async (file) => {
381
- const { code, map } = await bundle(file, {
382
- format: 'esm',
383
- sourceMap: true,
384
- minimize: true,
385
- onwarn: () => {},
386
- moduleSideEffects: (id) => file === id,
387
- external: (importee) => (
388
- importee.startsWith('aws-sdk') ||
389
- importee.startsWith('@aws-sdk')
390
- ),
391
- })
392
-
393
- const hash = createHash('sha1').update(code).digest('hex')
394
-
395
- parentPort.postMessage(JSON.stringify({
396
- handler: 'index.default',
397
- hash,
398
- files: [
399
- { name: 'index.js', code, map: map?.toString() }
400
- ]
401
- }))
402
- }
403
-
404
- build(workerData)
405
- `;
406
362
  var defaultBuild = async (file) => {
407
- return new Promise((resolve, reject) => {
408
- const worker = new Worker(workerCode, { workerData: file, eval: true });
409
- const cleanUp2 = () => {
410
- worker.removeAllListeners();
411
- worker.terminate();
412
- };
413
- worker.on("message", (data) => {
414
- resolve(JSON.parse(data.toString("utf8")));
415
- cleanUp2();
416
- });
417
- worker.on("error", (data) => {
418
- reject(data);
419
- cleanUp2();
420
- });
421
- worker.on("exit", (code) => {
422
- if (code !== 0) {
423
- reject(new Error(`Worker exited with code ${code}`));
424
- cleanUp2();
363
+ const output = await bundle({
364
+ entry: {
365
+ file
366
+ },
367
+ mode: "production",
368
+ target: "node",
369
+ externalModules: [
370
+ "@aws-sdk/*",
371
+ "@aws-sdk",
372
+ "aws-sdk"
373
+ ],
374
+ module: {},
375
+ options: {
376
+ minify: true,
377
+ sourceMaps: true,
378
+ jsc: {
379
+ target: "es2022"
425
380
  }
426
- });
381
+ },
382
+ output: {
383
+ name: "output",
384
+ path: ""
385
+ }
427
386
  });
387
+ const hash = createHash("sha1").update(output.file.code).digest("hex");
388
+ return {
389
+ handler: "index.default",
390
+ hash,
391
+ files: [
392
+ {
393
+ name: "index.js",
394
+ code: output.file.code,
395
+ map: output.file.map?.toString()
396
+ }
397
+ ]
398
+ };
428
399
  };
429
400
 
430
401
  // src/plugins/function/util/build.ts
@@ -451,13 +422,13 @@ var writeBuildHash = async (config2, stack, id, hash) => {
451
422
  await writeFile(versionFile, hash);
452
423
  };
453
424
  var writeBuildFiles = async (config2, stack, id, files) => {
454
- const bundle = await zipFiles(files);
425
+ const bundle2 = await zipFiles(files);
455
426
  const funcPath = join2(functionDir, config2.name, stack.artifactId, id);
456
427
  const filesPath = join2(funcPath, "files");
457
428
  const bundleFile = join2(funcPath, "bundle.zip");
458
- debug("Bundle size of", style.info(join2(config2.name, stack.artifactId, id)), "is", style.attr(filesize(bundle.byteLength)));
429
+ debug("Bundle size of", style.info(join2(config2.name, stack.artifactId, id)), "is", style.attr(filesize(bundle2.byteLength)));
459
430
  await mkdir(filesPath, { recursive: true });
460
- await writeFile(bundleFile, bundle);
431
+ await writeFile(bundleFile, bundle2);
461
432
  await Promise.all(files.map(async (file) => {
462
433
  const fileName = join2(filesPath, file.name);
463
434
  await mkdir(basename(fileName), { recursive: true });
@@ -469,7 +440,7 @@ var writeBuildFiles = async (config2, stack, id, files) => {
469
440
  }));
470
441
  return {
471
442
  file: bundleFile,
472
- size: bundle.byteLength
443
+ size: bundle2.byteLength
473
444
  };
474
445
  };
475
446
 
@@ -628,12 +599,12 @@ var toFunction = ({ config: config2, stack, stackConfig, assets }, id, fileOrPro
628
599
  resourceName: id,
629
600
  async build() {
630
601
  const result = await defaultBuild(props.file);
631
- const bundle = await writeBuildFiles(config2, stack, id, result.files);
602
+ const bundle2 = await writeBuildFiles(config2, stack, id, result.files);
632
603
  await writeBuildHash(config2, stack, id, result.hash);
633
604
  const func = lambda.node.defaultChild;
634
605
  func.handler = result.handler;
635
606
  return {
636
- size: formatByteSize(bundle.size)
607
+ size: formatByteSize(bundle2.size)
637
608
  };
638
609
  },
639
610
  async publish() {
@@ -1134,36 +1105,39 @@ var hr = () => {
1134
1105
  };
1135
1106
 
1136
1107
  // src/cli/ui/layout/logs.ts
1108
+ import wrapAnsi from "wrap-ansi";
1137
1109
  var previous = /* @__PURE__ */ new Date();
1138
1110
  var logs = () => {
1139
1111
  if (!process.env.VERBOSE) {
1140
1112
  return [];
1141
1113
  }
1142
1114
  const logs2 = flushDebug();
1143
- return [
1144
- hr(),
1145
- br(),
1146
- " ".repeat(3),
1147
- style.label("Debug Logs:"),
1148
- br(),
1149
- br(),
1150
- logs2.map((log) => {
1151
- const diff = log.date.getTime() - previous.getTime();
1152
- const time = `+${diff}`.padStart(7);
1153
- previous = log.date;
1154
- return [
1155
- style.attr(`${time}${style.attr.dim("ms")}`),
1156
- " [ ",
1157
- log.type,
1158
- " ] ",
1159
- log.message,
1160
- br(),
1161
- log.type === "error" ? br() : ""
1162
- ];
1163
- }),
1164
- br(),
1165
- hr()
1166
- ];
1115
+ return (term) => {
1116
+ term.out.write([
1117
+ hr(),
1118
+ br(),
1119
+ " ".repeat(3),
1120
+ style.label("Debug Logs:"),
1121
+ br(),
1122
+ br(),
1123
+ logs2.map((log) => {
1124
+ const diff = log.date.getTime() - previous.getTime();
1125
+ const time = `+${diff}`.padStart(8);
1126
+ previous = log.date;
1127
+ return wrapAnsi([
1128
+ style.attr(`${time}${style.attr.dim("ms")}`),
1129
+ " [ ",
1130
+ log.type,
1131
+ " ] ",
1132
+ log.message,
1133
+ br(),
1134
+ log.type === "error" ? br() : ""
1135
+ ].join(""), term.out.width(), { hard: true, trim: false });
1136
+ }),
1137
+ br(),
1138
+ hr()
1139
+ ]);
1140
+ };
1167
1141
  };
1168
1142
 
1169
1143
  // src/cli/ui/layout/footer.ts
@@ -1283,11 +1257,11 @@ var importFile = async (path) => {
1283
1257
  const path2 = dirname(file);
1284
1258
  const dir = resolveDir(file);
1285
1259
  code2 = code2.replaceAll("__dirname", `"${dir}"`);
1286
- const matches = code2.match(/import\s*{\s*[a-z0-9_]+\s*}\s*from\s*('|")(\.[\/a-z0-9_]+)('|");?/ig);
1260
+ const matches = code2.match(/import\s*{\s*[a-z0-9\_]+\s*}\s*from\s*('|")(\.[\/a-z0-9\_\-]+)('|");?/ig);
1287
1261
  if (!matches)
1288
1262
  return code2;
1289
1263
  await Promise.all(matches?.map(async (match) => {
1290
- const parts = /('|")(\.[\/a-z0-9_]+)('|")/ig.exec(match);
1264
+ const parts = /('|")(\.[\/a-z0-9\_\-]+)('|")/ig.exec(match);
1291
1265
  const from = parts[2];
1292
1266
  const file2 = await resolveFileNameExtension(join4(path2, from));
1293
1267
  const result = await load(file2);
@@ -1365,6 +1339,17 @@ var header = (config2) => {
1365
1339
  ];
1366
1340
  };
1367
1341
 
1342
+ // src/util/timer.ts
1343
+ import hrtime from "pretty-hrtime";
1344
+ var createTimer = () => {
1345
+ const start = process.hrtime();
1346
+ return () => {
1347
+ const end = process.hrtime(start);
1348
+ const [time, unit] = hrtime(end).split(" ");
1349
+ return style.attr(time) + style.attr.dim(unit);
1350
+ };
1351
+ };
1352
+
1368
1353
  // src/cli/lib/signal.ts
1369
1354
  var Signal = class {
1370
1355
  constructor(value) {
@@ -1418,16 +1403,16 @@ var createSpinner = () => {
1418
1403
  };
1419
1404
 
1420
1405
  // src/cli/ui/layout/dialog.ts
1421
- import wrapAnsi from "wrap-ansi";
1406
+ import wrapAnsi2 from "wrap-ansi";
1422
1407
  var dialog = (type, lines) => {
1423
1408
  const padding = 3;
1424
1409
  const icon = style[type](symbol[type].padEnd(padding));
1425
1410
  return (term) => {
1426
1411
  term.out.write(lines.map((line, i) => {
1427
1412
  if (i === 0) {
1428
- return icon + wrapAnsi(line, term.out.width(), { hard: true });
1413
+ return icon + wrapAnsi2(line, term.out.width(), { hard: true });
1429
1414
  }
1430
- return wrapAnsi(" ".repeat(padding) + line, term.out.width(), { hard: true });
1415
+ return wrapAnsi2(" ".repeat(padding) + line, term.out.width(), { hard: true });
1431
1416
  }).join(br()) + br());
1432
1417
  };
1433
1418
  };
@@ -1435,7 +1420,7 @@ var loadingDialog = (message) => {
1435
1420
  const [icon, stop] = createSpinner();
1436
1421
  const description = new Signal(message);
1437
1422
  const time = new Signal("");
1438
- const start = /* @__PURE__ */ new Date();
1423
+ const timer = createTimer();
1439
1424
  return (term) => {
1440
1425
  term.out.write([
1441
1426
  icon,
@@ -1446,10 +1431,8 @@ var loadingDialog = (message) => {
1446
1431
  br()
1447
1432
  ]);
1448
1433
  return (message2) => {
1449
- const end = /* @__PURE__ */ new Date();
1450
- const diff = end.getTime() - start.getTime();
1451
1434
  description.set(message2);
1452
- time.set(style.attr(diff) + style.attr.dim("ms"));
1435
+ time.set(timer());
1453
1436
  stop();
1454
1437
  icon.set(style.success(symbol.success));
1455
1438
  };
@@ -1523,9 +1506,6 @@ var Interface = class {
1523
1506
  const action = parseAction(key);
1524
1507
  if (typeof action === "undefined") {
1525
1508
  this.bell();
1526
- } else if (action === "abort") {
1527
- this.showCursor();
1528
- process.exit(1);
1529
1509
  } else {
1530
1510
  const cb = actions[action];
1531
1511
  if (typeof cb === "function") {
@@ -1662,6 +1642,12 @@ var layout = async (cb) => {
1662
1642
  const term = createTerminal();
1663
1643
  term.out.clear();
1664
1644
  term.out.write(logo());
1645
+ term.in.captureInput({
1646
+ abort: () => {
1647
+ term.in.showCursor();
1648
+ process.exit(1);
1649
+ }
1650
+ });
1665
1651
  try {
1666
1652
  const options = program.optsWithGlobals();
1667
1653
  const config2 = await importConfig(options);
@@ -1718,7 +1704,6 @@ var assetBuilder = (assets) => {
1718
1704
  groups.update((groups2) => [...groups2, group]);
1719
1705
  await Promise.all(assets2.map(async (asset) => {
1720
1706
  const [icon, stop] = createSpinner();
1721
- const start = /* @__PURE__ */ new Date();
1722
1707
  const details = new Signal({});
1723
1708
  const line = flexLine(term, [
1724
1709
  icon,
@@ -1738,17 +1723,17 @@ var assetBuilder = (assets) => {
1738
1723
  " ",
1739
1724
  derive([details], (details2) => {
1740
1725
  return Object.entries(details2).map(([key, value]) => {
1741
- return `${style.label(key)}: ${value}`;
1726
+ return `${style.label(key)} ${value}`;
1742
1727
  }).join(" / ");
1743
1728
  }),
1744
1729
  br()
1745
1730
  ]);
1746
1731
  group.update((group2) => [...group2, line]);
1732
+ const timer = createTimer();
1747
1733
  const data = await asset.build?.();
1748
- const time = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
1749
1734
  details.set({
1750
1735
  ...data,
1751
- time: style.attr(time) + style.attr.dim("ms")
1736
+ time: timer()
1752
1737
  });
1753
1738
  icon.set(style.success(symbol.success));
1754
1739
  stop();
@@ -2085,10 +2070,8 @@ var stackTree = (nodes, statuses) => {
2085
2070
  style.info(id),
2086
2071
  " "
2087
2072
  ], [
2088
- // style.placeholder(' [ '),
2089
2073
  " ",
2090
2074
  status2,
2091
- // style.placeholder(' ] '),
2092
2075
  br()
2093
2076
  ]);
2094
2077
  term.out.write(line);
@@ -2099,65 +2082,6 @@ var stackTree = (nodes, statuses) => {
2099
2082
  };
2100
2083
  };
2101
2084
 
2102
- // src/cli/ui/__components/basic.ts
2103
- var br2 = () => {
2104
- return "\n";
2105
- };
2106
-
2107
- // src/cli/ui/__components/spinner.ts
2108
- var frames2 = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
2109
- var length2 = frames2.length;
2110
- var createSpinner2 = () => {
2111
- const index = new Signal(0);
2112
- const frame = derive([index], (index2) => style.info(frames2[index2 % length2]));
2113
- const interval = setInterval(() => {
2114
- index.update((i) => i + 1);
2115
- }, 80);
2116
- return [
2117
- frame,
2118
- () => {
2119
- clearInterval(interval);
2120
- }
2121
- ];
2122
- };
2123
-
2124
- // src/cli/ui/__components/dialog.ts
2125
- var dialog2 = (type, lines) => {
2126
- const padding = 3;
2127
- const icon = style[type](symbol[type].padEnd(padding));
2128
- return lines.map((line, i) => {
2129
- if (i === 0) {
2130
- return icon + line;
2131
- } else {
2132
- return " ".repeat(padding) + line;
2133
- }
2134
- }).join(br2()) + br2();
2135
- };
2136
- var loadingDialog2 = (message) => {
2137
- const [icon, stop] = createSpinner2();
2138
- const description = new Signal(message);
2139
- const time = new Signal("");
2140
- const start = /* @__PURE__ */ new Date();
2141
- return (term) => {
2142
- term.out.write([
2143
- icon,
2144
- " ",
2145
- description,
2146
- " ",
2147
- time,
2148
- br2()
2149
- ]);
2150
- return (message2) => {
2151
- const end = /* @__PURE__ */ new Date();
2152
- const diff = end.getTime() - start.getTime();
2153
- description.set(message2);
2154
- time.set(style.attr(diff) + style.attr.dim("ms"));
2155
- stop();
2156
- icon.set(style.success(symbol.success));
2157
- };
2158
- };
2159
- };
2160
-
2161
2085
  // src/cli/command/status.ts
2162
2086
  var status = (program2) => {
2163
2087
  program2.command("status").argument("[stacks...]", "Optionally filter stacks to lookup status").description("View the application status").action(async (filters) => {
@@ -2165,18 +2089,18 @@ var status = (program2) => {
2165
2089
  const { app, assets, dependencyTree } = await toApp(config2, filters);
2166
2090
  await cleanUp();
2167
2091
  await write(assetBuilder(assets));
2168
- write(br2());
2092
+ write(br());
2169
2093
  const assembly = app.synth();
2170
- const doneLoading = write(loadingDialog2("Loading stack information..."));
2094
+ const doneLoading = write(loadingDialog("Loading stack information..."));
2171
2095
  const client = new StackClient(config2);
2172
2096
  const statuses = [];
2173
2097
  const stackStatuses = {};
2174
2098
  assembly.stacks.forEach((stack) => {
2175
2099
  stackStatuses[stack.id] = new Signal(style.info("Loading..."));
2176
2100
  });
2177
- write(br2());
2101
+ write(br());
2178
2102
  write(stackTree(dependencyTree, stackStatuses));
2179
- write(br2());
2103
+ write(br());
2180
2104
  debug("Load metadata for all deployed stacks on AWS");
2181
2105
  await Promise.all(assembly.stacks.map(async (stack, i) => {
2182
2106
  const info = await client.get(stack.stackName);
@@ -2197,9 +2121,9 @@ var status = (program2) => {
2197
2121
  doneLoading("Done loading stack information");
2198
2122
  debug("Done loading data for all deployed stacks on AWS");
2199
2123
  if (statuses.includes("non-existent") || statuses.includes("out-of-date")) {
2200
- write(dialog2("warning", ["Your app has undeployed changes !!!"]));
2124
+ write(dialog("warning", ["Your app has undeployed changes !!!"]));
2201
2125
  } else {
2202
- write(dialog2("success", ["Your app has not been changed"]));
2126
+ write(dialog("success", ["Your app has not been changed"]));
2203
2127
  }
2204
2128
  });
2205
2129
  });
@@ -0,0 +1,6 @@
1
+ // src/plugin.ts
2
+ var definePlugin = (plugin) => plugin;
3
+
4
+ export {
5
+ definePlugin
6
+ };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  definePlugin
3
- } from "./chunk-6KILQ5DR.js";
3
+ } from "./chunk-PFTL6L4F.js";
4
4
  export {
5
5
  definePlugin
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -31,6 +31,7 @@
31
31
  "@aws-sdk/client-sts": "^3.369.0",
32
32
  "@aws-sdk/credential-providers": "^3.369.0",
33
33
  "@swc/core": "^1.3.70",
34
+ "@types/pretty-hrtime": "^1.0.1",
34
35
  "aws-cdk-lib": "^2.87.0",
35
36
  "aws-cron-expression-validator": "^1.0.5",
36
37
  "chalk": "^5.3.0",
@@ -38,6 +39,7 @@
38
39
  "commander": "^9.4.1",
39
40
  "filesize": "^10.0.7",
40
41
  "jszip": "^3.10.1",
42
+ "pretty-hrtime": "^1.0.3",
41
43
  "wrap-ansi": "^8.1.0",
42
44
  "zod": "^3.21.4",
43
45
  "@awsless/code": "^0.0.10"
@@ -1,15 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw new Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // src/plugin.ts
10
- var definePlugin = (plugin) => plugin;
11
-
12
- export {
13
- __require,
14
- definePlugin
15
- };