@awsless/awsless 0.0.127 → 0.0.129

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.js CHANGED
@@ -1044,8 +1044,8 @@ var generateFileHashes = async (file, hashes) => {
1044
1044
  var fingerprintFromFile = async (file) => {
1045
1045
  const hashes = /* @__PURE__ */ new Map();
1046
1046
  await generateFileHashes(file, hashes);
1047
- const merge = Buffer.concat(Array.from(hashes.values()).sort());
1048
- return createHash2("sha1").update(merge).digest("hex");
1047
+ const merge2 = Buffer.concat(Array.from(hashes.values()).sort());
1048
+ return createHash2("sha1").update(merge2).digest("hex");
1049
1049
  };
1050
1050
  var fingerprintFromDirectory = async (dir) => {
1051
1051
  const hashes = /* @__PURE__ */ new Map();
@@ -1055,8 +1055,8 @@ var fingerprintFromDirectory = async (dir) => {
1055
1055
  await generateFileHashes(join3(dir, file), hashes);
1056
1056
  }
1057
1057
  }
1058
- const merge = Buffer.concat(Array.from(hashes.values()).sort());
1059
- return createHash2("sha1").update(merge).digest("hex");
1058
+ const merge2 = Buffer.concat(Array.from(hashes.values()).sort());
1059
+ return createHash2("sha1").update(merge2).digest("hex");
1060
1060
  };
1061
1061
  var readModuleFile = (file) => {
1062
1062
  if (file.endsWith(".js")) {
@@ -3712,10 +3712,10 @@ var onFailurePlugin = definePlugin({
3712
3712
  if (!hasOnFailure(config2)) {
3713
3713
  return;
3714
3714
  }
3715
- const queue3 = new Queue("on-failure", {
3715
+ const queue2 = new Queue("on-failure", {
3716
3716
  name: `${config2.app.name}-failure`
3717
3717
  });
3718
- bootstrap2.add(queue3).export("on-failure-queue-arn", queue3.arn);
3718
+ bootstrap2.add(queue2).export("on-failure-queue-arn", queue2.arn);
3719
3719
  },
3720
3720
  onStack(ctx) {
3721
3721
  const { stack, stackConfig, bootstrap: bootstrap2 } = ctx;
@@ -3862,22 +3862,22 @@ var queuePlugin = definePlugin({
3862
3862
  const { stack, config: config2, stackConfig, bind } = ctx;
3863
3863
  for (const [id, functionOrProps] of Object.entries(stackConfig.queues || {})) {
3864
3864
  const props = typeof functionOrProps === "string" ? { ...config2.app.defaults.queue, consumer: functionOrProps } : { ...config2.app.defaults.queue, ...functionOrProps };
3865
- const queue3 = new Queue(id, {
3865
+ const queue2 = new Queue(id, {
3866
3866
  name: `${config2.app.name}-${stack.name}-${id}`,
3867
3867
  deadLetterArn: getGlobalOnFailure(ctx),
3868
3868
  ...props
3869
3869
  });
3870
3870
  const lambda = toLambdaFunction(ctx, `queue-${id}`, props.consumer);
3871
3871
  const source = new SqsEventSource(id, lambda, {
3872
- queueArn: queue3.arn,
3872
+ queueArn: queue2.arn,
3873
3873
  batchSize: props.batchSize,
3874
3874
  maxConcurrency: props.maxConcurrency,
3875
3875
  maxBatchingWindow: props.maxBatchingWindow
3876
3876
  });
3877
- stack.add(queue3, lambda, source);
3877
+ stack.add(queue2, lambda, source);
3878
3878
  bind((lambda2) => {
3879
- lambda2.addPermissions(queue3.permissions);
3880
- lambda2.addEnvironment(`QUEUE_${constantCase10(stack.name)}_${constantCase10(id)}_URL`, queue3.url);
3879
+ lambda2.addPermissions(queue2.permissions);
3880
+ lambda2.addEnvironment(`QUEUE_${constantCase10(stack.name)}_${constantCase10(id)}_URL`, queue2.url);
3881
3881
  });
3882
3882
  }
3883
3883
  }
@@ -5498,7 +5498,7 @@ var toApp = async (config2, filters) => {
5498
5498
  };
5499
5499
 
5500
5500
  // src/config/load.ts
5501
- import { dirname as dirname5, join as join7 } from "path";
5501
+ import { basename as basename3, dirname as dirname5, extname as extname2, join as join7 } from "path";
5502
5502
 
5503
5503
  // src/util/account.ts
5504
5504
  import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
@@ -6317,6 +6317,7 @@ var Cancelled = class extends Error {
6317
6317
 
6318
6318
  // src/config/load.ts
6319
6319
  import JSON5 from "json5";
6320
+ import merge from "deepmerge";
6320
6321
  var readConfig = async (file) => {
6321
6322
  try {
6322
6323
  const json4 = await readFile5(file, "utf8");
@@ -6329,6 +6330,19 @@ var readConfig = async (file) => {
6329
6330
  throw error;
6330
6331
  }
6331
6332
  };
6333
+ var readConfigWithStage = async (file, stage) => {
6334
+ const config2 = await readConfig(file);
6335
+ const ext = extname2(file);
6336
+ const stageFileName = basename3(file, ext) + "." + stage + ext;
6337
+ const stageFile = join7(dirname5(file), stageFileName);
6338
+ const stageFileExists = await fileExist(stageFile);
6339
+ if (!stageFileExists) {
6340
+ return config2;
6341
+ }
6342
+ debug("Load env file:", style.info(stageFile));
6343
+ const stageConfig = await readConfig(stageFile);
6344
+ return merge(config2, stageConfig);
6345
+ };
6332
6346
  var parseConfig = async (schema, file, data) => {
6333
6347
  try {
6334
6348
  const result = await schema.parseAsync(data);
@@ -6349,7 +6363,7 @@ var loadConfig = async (options) => {
6349
6363
  debug("CWD:", style.info(root2));
6350
6364
  debug("Load app config file");
6351
6365
  const appFileName = join7(root2, configFile);
6352
- const appConfig = await readConfig(appFileName);
6366
+ const appConfig = await readConfigWithStage(appFileName, options.stage);
6353
6367
  debug("Validate app config file");
6354
6368
  const app = await parseConfig(AppSchema, appFileName, appConfig);
6355
6369
  debug("Load credentials", style.info(app.profile));
@@ -6365,8 +6379,8 @@ var loadConfig = async (options) => {
6365
6379
  });
6366
6380
  const stacks = [];
6367
6381
  for (const file of stackFiles) {
6368
- debug(`Load stack: ${style.info(file)}`);
6369
- const stackConfig = await readConfig(file);
6382
+ debug("Load stack file:", style.info(file));
6383
+ const stackConfig = await readConfigWithStage(file, options.stage);
6370
6384
  setLocalBasePath(join7(process.cwd(), dirname5(file)));
6371
6385
  const stack = await parseConfig(StackSchema, file, stackConfig);
6372
6386
  stacks.push(stack);
@@ -6988,7 +7002,7 @@ var flexLine = (term, left, right, reserveSpace = 0) => {
6988
7002
 
6989
7003
  // src/cli/ui/complex/builder.ts
6990
7004
  import { dirname as dirname6, join as join8 } from "path";
6991
- import queue2 from "fastq";
7005
+ import { promise } from "fastq";
6992
7006
  var assetBuilder = (app) => {
6993
7007
  return async (term) => {
6994
7008
  const assets = [];
@@ -7006,14 +7020,49 @@ var assetBuilder = (app) => {
7006
7020
  }
7007
7021
  const showDetailedView = true;
7008
7022
  const done = term.out.write(loadingDialog("Building stack assets..."));
7009
- const groups = new Signal([""]);
7023
+ const group = new Signal([]);
7010
7024
  if (showDetailedView) {
7011
7025
  term.out.gap();
7012
- term.out.write(groups);
7026
+ term.out.write(group);
7013
7027
  }
7014
7028
  const stackNameSize = Math.max(...stacks.map((stack) => stack.name.length));
7015
7029
  const assetTypeSize = Math.max(...assets.map((asset) => asset.type.length));
7016
- const q = queue2.promise(async ({ stack, asset }) => {
7030
+ const queue2 = promise(async ({ stack, asset }) => {
7031
+ if (!asset.build) {
7032
+ return;
7033
+ }
7034
+ const [icon, stop] = createSpinner();
7035
+ const details = new Signal({});
7036
+ const line2 = flexLine(
7037
+ term,
7038
+ [
7039
+ icon,
7040
+ " ",
7041
+ style.label(stack.name),
7042
+ " ".repeat(stackNameSize - stack.name.length),
7043
+ " ",
7044
+ style.placeholder(symbol.pointerSmall),
7045
+ " ",
7046
+ style.warning(asset.type),
7047
+ " ".repeat(assetTypeSize - asset.type.length),
7048
+ " ",
7049
+ style.placeholder(symbol.pointerSmall),
7050
+ " ",
7051
+ style.info(asset.id),
7052
+ " "
7053
+ ],
7054
+ [
7055
+ " ",
7056
+ derive([details], (details2) => {
7057
+ return Object.entries(details2).map(([key, value]) => {
7058
+ return `${style.label(key)} ${value}`;
7059
+ }).join(style.placeholder(" \u2500 "));
7060
+ }),
7061
+ br()
7062
+ ]
7063
+ );
7064
+ group.update((group2) => [...group2, line2]);
7065
+ const timer = createTimer();
7017
7066
  const getFullPath = (file) => {
7018
7067
  return join8(directories.asset, asset.type, app.name, stack.name, asset.id, file);
7019
7068
  };
@@ -7025,94 +7074,57 @@ var assetBuilder = (app) => {
7025
7074
  return void 0;
7026
7075
  }
7027
7076
  };
7028
- return asset.build({
7029
- async write(fingerprint, cb) {
7030
- const prev = await getFingerPrint();
7031
- if (prev === fingerprint && !process.env.NO_CACHE) {
7032
- return;
7033
- }
7034
- try {
7035
- await cb(async (file2, data) => {
7036
- const fullpath = getFullPath(file2);
7037
- const basepath2 = dirname6(fullpath);
7038
- await mkdir2(basepath2, { recursive: true });
7039
- await writeFile2(fullpath, data);
7040
- });
7041
- } catch (error) {
7042
- throw error;
7043
- }
7044
- const file = getFullPath("FINGER_PRINT");
7045
- const basepath = dirname6(file);
7046
- await mkdir2(basepath, { recursive: true });
7047
- await writeFile2(file, fingerprint);
7048
- },
7049
- async read(fingerprint, files) {
7050
- const prev = await getFingerPrint();
7051
- if (prev !== fingerprint) {
7052
- throw new TypeError(`Outdated fingerprint: ${fingerprint}`);
7053
- }
7054
- return Promise.all(
7055
- files.map((file) => {
7056
- return readFile6(getFullPath(file));
7057
- })
7058
- );
7059
- }
7060
- });
7061
- }, 3);
7062
- await Promise.all(
7063
- app.stacks.map(async (stack) => {
7064
- const group = new Signal([]);
7065
- groups.update((groups2) => [...groups2, group]);
7066
- await Promise.all(
7067
- [...stack.assets].map(async (asset) => {
7068
- if (!asset.build) {
7077
+ try {
7078
+ const data = await asset.build({
7079
+ async write(fingerprint, cb) {
7080
+ const prev = await getFingerPrint();
7081
+ if (prev === fingerprint && !process.env.NO_CACHE) {
7069
7082
  return;
7070
7083
  }
7071
- const [icon, stop] = createSpinner();
7072
- const details = new Signal({});
7073
- const line2 = flexLine(
7074
- term,
7075
- [
7076
- icon,
7077
- " ",
7078
- style.label(stack.name),
7079
- " ".repeat(stackNameSize - stack.name.length),
7080
- " ",
7081
- style.placeholder(symbol.pointerSmall),
7082
- " ",
7083
- style.warning(asset.type),
7084
- " ".repeat(assetTypeSize - asset.type.length),
7085
- " ",
7086
- style.placeholder(symbol.pointerSmall),
7087
- " ",
7088
- style.info(asset.id),
7089
- " "
7090
- ],
7091
- [
7092
- " ",
7093
- derive([details], (details2) => {
7094
- return Object.entries(details2).map(([key, value]) => {
7095
- return `${style.label(key)} ${value}`;
7096
- }).join(style.placeholder(" \u2500 "));
7097
- }),
7098
- br()
7099
- ]
7100
- );
7101
- group.update((group2) => [...group2, line2]);
7102
- const timer = createTimer();
7103
7084
  try {
7104
- const data = await q.push({ asset, stack });
7105
- details.set({
7106
- ...data,
7107
- time: timer()
7085
+ await cb(async (file2, data2) => {
7086
+ const fullpath = getFullPath(file2);
7087
+ const basepath2 = dirname6(fullpath);
7088
+ await mkdir2(basepath2, { recursive: true });
7089
+ await writeFile2(fullpath, data2);
7108
7090
  });
7109
- icon.set(style.success(symbol.success));
7110
7091
  } catch (error) {
7111
- icon.set(style.error(symbol.error));
7112
7092
  throw error;
7113
- } finally {
7114
- stop();
7115
7093
  }
7094
+ const file = getFullPath("FINGER_PRINT");
7095
+ const basepath = dirname6(file);
7096
+ await mkdir2(basepath, { recursive: true });
7097
+ await writeFile2(file, fingerprint);
7098
+ },
7099
+ async read(fingerprint, files) {
7100
+ const prev = await getFingerPrint();
7101
+ if (prev !== fingerprint) {
7102
+ throw new TypeError(`Outdated fingerprint: ${fingerprint}`);
7103
+ }
7104
+ return Promise.all(
7105
+ files.map((file) => {
7106
+ return readFile6(getFullPath(file));
7107
+ })
7108
+ );
7109
+ }
7110
+ });
7111
+ details.set({
7112
+ ...data,
7113
+ time: timer()
7114
+ });
7115
+ icon.set(style.success(symbol.success));
7116
+ } catch (error) {
7117
+ icon.set(style.error(symbol.error));
7118
+ throw error;
7119
+ } finally {
7120
+ stop();
7121
+ }
7122
+ }, 3);
7123
+ await Promise.all(
7124
+ app.stacks.map(async (stack) => {
7125
+ await Promise.all(
7126
+ [...stack.assets].map(async (asset) => {
7127
+ await queue2.push({ stack, asset });
7116
7128
  })
7117
7129
  );
7118
7130
  })
@@ -7158,13 +7170,15 @@ import { join as join9 } from "path";
7158
7170
  var templateBuilder = (app) => {
7159
7171
  return async (term) => {
7160
7172
  const done = term.out.write(loadingDialog("Building stack templates..."));
7161
- await Promise.all(app.stacks.map(async (stack) => {
7162
- const template = stack.toString(true);
7163
- const path = join9(directories.template, app.name);
7164
- const file = join9(path, `${stack.name}.json`);
7165
- await mkdir4(path, { recursive: true });
7166
- await writeFile3(file, template);
7167
- }));
7173
+ await Promise.all(
7174
+ app.stacks.map(async (stack) => {
7175
+ const template = stack.toString(true);
7176
+ const path = join9(directories.template, app.name);
7177
+ const file = join9(path, `${stack.name}.json`);
7178
+ await mkdir4(path, { recursive: true });
7179
+ await writeFile3(file, template);
7180
+ })
7181
+ );
7168
7182
  done("Done building stack templates");
7169
7183
  };
7170
7184
  };
@@ -7713,6 +7727,7 @@ var status = (program2) => {
7713
7727
  import { readFile as readFile7 } from "fs/promises";
7714
7728
  import { join as join10 } from "path";
7715
7729
  import { GetObjectCommand, ObjectCannedACL as ObjectCannedACL2, PutObjectCommand as PutObjectCommand2, S3Client as S3Client2, StorageClass as StorageClass2 } from "@aws-sdk/client-s3";
7730
+ import { promise as promise2 } from "fastq";
7716
7731
  var assetPublisher = (config2, app) => {
7717
7732
  const client = new S3Client2({
7718
7733
  credentials: config2.credentials,
@@ -7721,68 +7736,71 @@ var assetPublisher = (config2, app) => {
7721
7736
  });
7722
7737
  return async (term) => {
7723
7738
  const done = term.out.write(loadingDialog("Publishing stack assets to AWS..."));
7739
+ const queue2 = promise2(async ({ stack, asset }) => {
7740
+ const getFullPath = (file) => {
7741
+ return join10(directories.asset, asset.type, app.name, stack.name, asset.id, file);
7742
+ };
7743
+ await asset.publish?.({
7744
+ async read(fingerprint, files) {
7745
+ const prev = await readFile7(getFullPath("FINGER_PRINT"), "utf8");
7746
+ if (prev !== fingerprint) {
7747
+ throw new TypeError(`Outdated fingerprint: ${fingerprint}`);
7748
+ }
7749
+ return Promise.all(
7750
+ files.map((file) => {
7751
+ return readFile7(getFullPath(file));
7752
+ })
7753
+ );
7754
+ },
7755
+ async publish(name, data, hash) {
7756
+ const key = `${app.name}/${stack.name}/${asset.type}/${name}`;
7757
+ const bucket = assetBucketName(config2.account, config2.app.region);
7758
+ let getResult;
7759
+ try {
7760
+ getResult = await client.send(
7761
+ new GetObjectCommand({
7762
+ Bucket: bucket,
7763
+ Key: key
7764
+ })
7765
+ );
7766
+ } catch (error) {
7767
+ if (error instanceof Error && error.name === "NoSuchKey") {
7768
+ } else {
7769
+ throw error;
7770
+ }
7771
+ }
7772
+ if (getResult?.Metadata?.hash === hash) {
7773
+ return {
7774
+ bucket,
7775
+ key,
7776
+ version: getResult.VersionId
7777
+ };
7778
+ }
7779
+ const putResult = await client.send(
7780
+ new PutObjectCommand2({
7781
+ Bucket: bucket,
7782
+ Key: key,
7783
+ Body: data,
7784
+ ACL: ObjectCannedACL2.private,
7785
+ StorageClass: StorageClass2.STANDARD,
7786
+ Metadata: {
7787
+ hash: hash.toString("utf8")
7788
+ }
7789
+ })
7790
+ );
7791
+ return {
7792
+ bucket,
7793
+ key,
7794
+ version: putResult.VersionId
7795
+ };
7796
+ }
7797
+ });
7798
+ }, 5);
7724
7799
  await Promise.all(
7725
7800
  app.stacks.map(async (stack) => {
7726
7801
  await Promise.all(
7727
7802
  [...stack.assets].map(async (asset) => {
7728
- const getFullPath = (file) => {
7729
- return join10(directories.asset, asset.type, app.name, stack.name, asset.id, file);
7730
- };
7731
- await asset.publish?.({
7732
- async read(fingerprint, files) {
7733
- const prev = await readFile7(getFullPath("FINGER_PRINT"), "utf8");
7734
- if (prev !== fingerprint) {
7735
- throw new TypeError(`Outdated fingerprint: ${fingerprint}`);
7736
- }
7737
- return Promise.all(
7738
- files.map((file) => {
7739
- return readFile7(getFullPath(file));
7740
- })
7741
- );
7742
- },
7743
- async publish(name, data, hash) {
7744
- const key = `${app.name}/${stack.name}/${asset.type}/${name}`;
7745
- const bucket = assetBucketName(config2.account, config2.app.region);
7746
- let getResult;
7747
- try {
7748
- getResult = await client.send(
7749
- new GetObjectCommand({
7750
- Bucket: bucket,
7751
- Key: key
7752
- })
7753
- );
7754
- } catch (error) {
7755
- if (error instanceof Error && error.name === "NoSuchKey") {
7756
- } else {
7757
- throw error;
7758
- }
7759
- }
7760
- if (getResult?.Metadata?.hash === hash) {
7761
- return {
7762
- bucket,
7763
- key,
7764
- version: getResult.VersionId
7765
- };
7766
- }
7767
- const putResult = await client.send(
7768
- new PutObjectCommand2({
7769
- Bucket: bucket,
7770
- Key: key,
7771
- Body: data,
7772
- ACL: ObjectCannedACL2.private,
7773
- StorageClass: StorageClass2.STANDARD,
7774
- Metadata: {
7775
- hash: hash.toString("utf8")
7776
- }
7777
- })
7778
- );
7779
- return {
7780
- bucket,
7781
- key,
7782
- version: putResult.VersionId
7783
- };
7784
- }
7785
- });
7803
+ await queue2.push({ stack, asset });
7786
7804
  })
7787
7805
  );
7788
7806
  })
@@ -7798,7 +7816,7 @@ import commonjs3 from "@rollup/plugin-commonjs";
7798
7816
  import nodeResolve3 from "@rollup/plugin-node-resolve";
7799
7817
  import { swc as swc3 } from "rollup-plugin-swc3";
7800
7818
  import { getSuites, getTests } from "@vitest/runner/utils";
7801
- import { basename as basename3, dirname as dirname7, extname as extname2, join as join11, relative as relative5 } from "path";
7819
+ import { basename as basename4, dirname as dirname7, extname as extname3, join as join11, relative as relative5 } from "path";
7802
7820
 
7803
7821
  // src/cli/ui/layout/text-box.ts
7804
7822
  import wrapAnsi3 from "wrap-ansi";
@@ -7886,11 +7904,11 @@ var singleTester = (stack, dir, filters) => {
7886
7904
  }
7887
7905
  const abs = join11(process.cwd(), path);
7888
7906
  const rel = relative5(dir, abs);
7889
- const ext = extname2(rel);
7907
+ const ext = extname3(rel);
7890
7908
  if (!ext) {
7891
7909
  return path;
7892
7910
  }
7893
- const name = basename3(rel, ext);
7911
+ const name = basename4(rel, ext);
7894
7912
  const base = dirname7(rel);
7895
7913
  const start = base === "." ? "" : style.placeholder(base + "/");
7896
7914
  return `${start}${name}${style.placeholder(ext)}`;
@@ -8438,8 +8456,6 @@ var program = new Command();
8438
8456
  program.name(logo().join("").replace(/\s+/, ""));
8439
8457
  program.option("--config-file <string>", "The app config file location");
8440
8458
  program.option("--stage <string>", "The stage to use, defaults to prod stage", "prod");
8441
- program.option("--profile <string>", "The AWS profile to use");
8442
- program.option("--region <string>", "The AWS region to use");
8443
8459
  program.option("-c --no-cache", "Always build & test without the cache");
8444
8460
  program.option("-s --skip-prompt", "Skip prompts");
8445
8461
  program.option("-v --verbose", "Print verbose logs");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.127",
3
+ "version": "0.0.129",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -29,12 +29,12 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@awsless/lambda": "^0.0.15",
32
- "@awsless/redis": "^0.0.10",
33
32
  "@awsless/sns": "^0.0.7",
34
- "@awsless/sqs": "^0.0.7",
33
+ "@awsless/redis": "^0.0.10",
35
34
  "@awsless/ssm": "^0.0.7",
36
- "@awsless/validate": "^0.0.10",
37
- "@awsless/weak-cache": "^0.0.1"
35
+ "@awsless/sqs": "^0.0.7",
36
+ "@awsless/weak-cache": "^0.0.1",
37
+ "@awsless/validate": "^0.0.10"
38
38
  },
39
39
  "dependencies": {
40
40
  "@aws-appsync/utils": "^1.5.0",
@@ -66,6 +66,7 @@
66
66
  "chunk": "^0.0.3",
67
67
  "commander": "^9.4.1",
68
68
  "decompress": "^4.2.1",
69
+ "deepmerge": "^4.3.1",
69
70
  "event-iterator": "^2.0.0",
70
71
  "fastq": "^1.16.0",
71
72
  "filesize": "^10.0.7",
@@ -86,8 +87,8 @@
86
87
  "wrap-ansi": "^8.1.0",
87
88
  "zod": "^3.21.4",
88
89
  "zod-to-json-schema": "^3.22.3",
89
- "@awsless/code": "^0.0.10",
90
- "@awsless/graphql": "^0.0.6"
90
+ "@awsless/graphql": "^0.0.6",
91
+ "@awsless/code": "^0.0.10"
91
92
  },
92
93
  "scripts": {
93
94
  "test": "pnpm code test",