sst 2.0.0-rc.20 → 2.0.0-rc.22

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.
@@ -1,7 +1,6 @@
1
1
  import { useProject } from "../../project.js";
2
2
  import { createSpinner } from "../spinner.js";
3
3
  import fs from "fs/promises";
4
- import path from "path";
5
4
  import { SiteEnv } from "../../site-env.js";
6
5
  import { spawnSync } from "child_process";
7
6
  export const env = (program) => program.command("env <command>", "description", (yargs) => yargs.positional("command", {
@@ -23,9 +22,7 @@ export const env = (program) => program.command("env <command>", "description",
23
22
  }
24
23
  spinner?.succeed();
25
24
  const sites = await SiteEnv.values();
26
- const current = path.relative(project.paths.root, process.cwd());
27
- const env = sites[current] || {};
28
- console.log(args.command);
25
+ const env = sites[process.cwd()] || {};
29
26
  const result = spawnSync(args.command, {
30
27
  env: {
31
28
  ...process.env,
@@ -642,7 +642,6 @@ export declare class Function extends lambda.Function implements SSTConstruct {
642
642
  static normalizeMemorySize(memorySize?: number | Size): number;
643
643
  static normalizeDiskSize(diskSize?: number | Size): cdk.Size;
644
644
  static normalizeTimeout(timeout?: number | Duration): cdk.Duration;
645
- static normalizeRuntime(runtime?: Runtime): Runtime;
646
645
  static normalizeSrcPath(srcPath: string): string;
647
646
  static handleImportedLayer(scope: Construct, layer: lambda.ILayerVersion): lambda.ILayerVersion;
648
647
  static isInlineDefinition(definition: any): definition is FunctionInlineDefinition;
@@ -77,6 +77,7 @@ export class Function extends lambda.Function {
77
77
  .forEach((per) => {
78
78
  props = Function.mergeProps(per, props);
79
79
  });
80
+ props.runtime = props.runtime || "nodejs16.x";
80
81
  // Set defaults
81
82
  const functionName = props.functionName &&
82
83
  (typeof props.functionName === "string"
@@ -84,7 +85,6 @@ export class Function extends lambda.Function {
84
85
  : props.functionName({ stack, functionProps: props }));
85
86
  const handler = props.handler;
86
87
  const timeout = Function.normalizeTimeout(props.timeout);
87
- const runtime = Function.normalizeRuntime(props.runtime);
88
88
  const architecture = (() => {
89
89
  if (props.architecture === "arm_64")
90
90
  return lambda.Architecture.ARM_64;
@@ -103,9 +103,7 @@ export class Function extends lambda.Function {
103
103
  throw new Error(`No handler defined for the "${id}" Lambda function`);
104
104
  }
105
105
  // Validate input
106
- const isNodeRuntime = runtime.startsWith("nodejs");
107
- const isPythonRuntime = runtime.startsWith("python");
108
- const isJavaRuntime = runtime.startsWith("java");
106
+ const isNodeRuntime = props.runtime.startsWith("nodejs");
109
107
  // Handle local development (ie. sst start)
110
108
  // - set runtime to nodejs12.x for non-Node runtimes (b/c the stub is in Node)
111
109
  // - set retry to 0. When the debugger is disconnected, the Cron construct
@@ -196,7 +194,8 @@ export class Function extends lambda.Function {
196
194
  // Update function's code
197
195
  const codeConfig = code.bind(this);
198
196
  const cfnFunction = this.node.defaultChild;
199
- cfnFunction.runtime = supportedRuntimes[runtime].toString();
197
+ cfnFunction.runtime =
198
+ supportedRuntimes[props.runtime].toString();
200
199
  /*
201
200
  if (isJavaRuntime) {
202
201
  const providedRuntime = (bundle as FunctionBundleJavaProps)
@@ -391,13 +390,6 @@ export class Function extends lambda.Function {
391
390
  }
392
391
  return cdk.Duration.seconds(timeout || 10);
393
392
  }
394
- static normalizeRuntime(runtime) {
395
- runtime = runtime || "nodejs18.x";
396
- if (!supportedRuntimes[runtime]) {
397
- throw new Error(`The specified runtime is not supported for sst.Function. Only NodeJS, Python, Go, and .NET runtimes are currently supported.`);
398
- }
399
- return runtime;
400
- }
401
393
  static normalizeSrcPath(srcPath) {
402
394
  return srcPath.replace(/\/+$/, "");
403
395
  }
package/credentials.js CHANGED
@@ -37,6 +37,8 @@ export function useAWSClient(client, force = false) {
37
37
  retryDecider: (err) => {
38
38
  if (err.$fault === "client")
39
39
  return false;
40
+ if (err.name === "CredentialsProviderError")
41
+ return false;
40
42
  if (err.message === "Could not load credentials from any providers")
41
43
  return false;
42
44
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sst",
3
- "version": "2.0.0-rc.20",
3
+ "version": "2.0.0-rc.22",
4
4
  "bin": {
5
5
  "sst": "cli/sst.js"
6
6
  },
package/project.js CHANGED
@@ -24,7 +24,6 @@ const CONFIG_EXTENSIONS = [
24
24
  ".config.cjs",
25
25
  ".config.mjs",
26
26
  ".config.js",
27
- ".json",
28
27
  ];
29
28
  export async function initProject(globals) {
30
29
  const root = globals.root || (await findRoot());
@@ -42,12 +41,10 @@ export async function initProject(globals) {
42
41
  catch {
43
42
  continue;
44
43
  }
45
- if (file.endsWith("js") || file.endsWith("ts")) {
46
- const [metafile, config] = await Stacks.load(file);
47
- return [metafile, config];
48
- }
44
+ const [metafile, config] = await Stacks.load(file);
45
+ return [metafile, config];
49
46
  }
50
- throw new VisibleError("Could not found a configuration file", "Make sure one of the following exists", " - sst.config.cjs", " - sst.config.mjs", " - sst.config.js", " - sst.config.ts", " - sst.json");
47
+ throw new VisibleError("Could not found a configuration file", "Make sure one of the following exists", ...CONFIG_EXTENSIONS.map((x) => ` - sst${x}`));
51
48
  })();
52
49
  const config = await Promise.resolve(sstConfig.config(globals));
53
50
  const stage = config.stage ||
package/site-env.js CHANGED
@@ -37,6 +37,7 @@ export async function writeValues(input) {
37
37
  await fs.promises.writeFile(file, JSON.stringify(input));
38
38
  }
39
39
  export function append(input) {
40
+ input.path = path.join(useProject().paths.root, input.path);
40
41
  fs.appendFileSync(keysFile(), JSON.stringify(input) + "\n");
41
42
  }
42
43
  export function reset() {
package/sst.mjs CHANGED
@@ -269,6 +269,21 @@ async function load(input) {
269
269
  await fs3.rm(outfile, {
270
270
  force: true
271
271
  });
272
+ if (!mod.default?.config)
273
+ throw new VisibleError(
274
+ `The config file is improperly formatted.`,
275
+ `Example:`,
276
+ `export default {`,
277
+ ` config() {`,
278
+ ` return {`,
279
+ ` name: "my-app",`,
280
+ ` region: "us-east-1"`,
281
+ ` }`,
282
+ ` },`,
283
+ ` stacks(app) {`,
284
+ ` }`,
285
+ `}`
286
+ );
272
287
  return [result.metafile, mod.default];
273
288
  } catch (e) {
274
289
  await fs3.rm(outfile, {
@@ -282,6 +297,7 @@ var init_build = __esm({
282
297
  "use strict";
283
298
  init_module();
284
299
  init_fs();
300
+ init_error();
285
301
  }
286
302
  });
287
303
 
@@ -989,6 +1005,8 @@ function useAWSClient(client, force = false) {
989
1005
  retryDecider: (err) => {
990
1006
  if (err.$fault === "client")
991
1007
  return false;
1008
+ if (err.name === "CredentialsProviderError")
1009
+ return false;
992
1010
  if (err.message === "Could not load credentials from any providers")
993
1011
  return false;
994
1012
  return true;
@@ -3796,19 +3814,13 @@ async function initProject(globals) {
3796
3814
  } catch {
3797
3815
  continue;
3798
3816
  }
3799
- if (file.endsWith("js") || file.endsWith("ts")) {
3800
- const [metafile2, config2] = await stacks_exports.load(file);
3801
- return [metafile2, config2];
3802
- }
3817
+ const [metafile2, config2] = await stacks_exports.load(file);
3818
+ return [metafile2, config2];
3803
3819
  }
3804
3820
  throw new VisibleError(
3805
3821
  "Could not found a configuration file",
3806
3822
  "Make sure one of the following exists",
3807
- " - sst.config.cjs",
3808
- " - sst.config.mjs",
3809
- " - sst.config.js",
3810
- " - sst.config.ts",
3811
- " - sst.json"
3823
+ ...CONFIG_EXTENSIONS.map((x) => ` - sst${x}`)
3812
3824
  );
3813
3825
  }();
3814
3826
  const config = await Promise.resolve(sstConfig.config(globals));
@@ -3911,8 +3923,7 @@ var init_project = __esm({
3911
3923
  ".config.cts",
3912
3924
  ".config.cjs",
3913
3925
  ".config.mjs",
3914
- ".config.js",
3915
- ".json"
3926
+ ".config.js"
3916
3927
  ];
3917
3928
  }
3918
3929
  });
@@ -5201,6 +5212,7 @@ async function writeValues(input) {
5201
5212
  await fs13.promises.writeFile(file, JSON.stringify(input));
5202
5213
  }
5203
5214
  function append(input) {
5215
+ input.path = path14.join(useProject().paths.root, input.path);
5204
5216
  fs13.appendFileSync(keysFile(), JSON.stringify(input) + "\n");
5205
5217
  }
5206
5218
  function reset2() {
@@ -5272,15 +5284,15 @@ async function extractSchema(opts) {
5272
5284
  {
5273
5285
  name: "pothos-extractor",
5274
5286
  visitor: {
5275
- Program(path19) {
5276
- const dummyResolverId = path19.scope.generateUidIdentifier("DUMMY_RESOLVER");
5287
+ Program(path18) {
5288
+ const dummyResolverId = path18.scope.generateUidIdentifier("DUMMY_RESOLVER");
5277
5289
  const resolverNode = dummyResolver({
5278
5290
  dummy_resolver: dummyResolverId
5279
5291
  });
5280
- path19.unshiftContainer("body", resolverNode);
5281
- path19.scope.crawl();
5292
+ path18.unshiftContainer("body", resolverNode);
5293
+ path18.scope.crawl();
5282
5294
  let schemaBuilder = null;
5283
- path19.traverse({
5295
+ path18.traverse({
5284
5296
  ImportDeclaration(declarator) {
5285
5297
  if (!declarator)
5286
5298
  return;
@@ -5338,17 +5350,17 @@ async function extractSchema(opts) {
5338
5350
  );
5339
5351
  return contents.code;
5340
5352
  }
5341
- function getBindings(path19, globalPaths) {
5353
+ function getBindings(path18, globalPaths) {
5342
5354
  const bindings = [];
5343
- path19.traverse({
5355
+ path18.traverse({
5344
5356
  Expression(expressionPath) {
5345
5357
  if (!expressionPath.isIdentifier())
5346
5358
  return;
5347
- const binding = path19.scope.getBinding(expressionPath);
5359
+ const binding = path18.scope.getBinding(expressionPath);
5348
5360
  if (!binding || globalPaths.has(binding.path) || bindings.includes(binding.path))
5349
5361
  return;
5350
5362
  const rootBinding = findRootBinding(binding.path);
5351
- if (path19 === rootBinding) {
5363
+ if (path18 === rootBinding) {
5352
5364
  bindings.push(binding.path);
5353
5365
  return;
5354
5366
  }
@@ -5361,8 +5373,8 @@ function getBindings(path19, globalPaths) {
5361
5373
  }
5362
5374
  return bindings;
5363
5375
  }
5364
- function findRootBinding(path19) {
5365
- let rootPath = path19;
5376
+ function findRootBinding(path18) {
5377
+ let rootPath = path18;
5366
5378
  while (rootPath.parentPath?.node !== void 0 && !rootPath.parentPath?.isProgram()) {
5367
5379
  rootPath = rootPath.parentPath;
5368
5380
  }
@@ -5929,7 +5941,6 @@ import dotenv2 from "dotenv";
5929
5941
  init_project();
5930
5942
  init_spinner();
5931
5943
  import fs19 from "fs/promises";
5932
- import path18 from "path";
5933
5944
  import { spawnSync } from "child_process";
5934
5945
  var env = (program2) => program2.command(
5935
5946
  "env <command>",
@@ -5951,9 +5962,7 @@ var env = (program2) => program2.command(
5951
5962
  }
5952
5963
  spinner?.succeed();
5953
5964
  const sites = await site_env_exports.values();
5954
- const current = path18.relative(project.paths.root, process.cwd());
5955
- const env2 = sites[current] || {};
5956
- console.log(args.command);
5965
+ const env2 = sites[process.cwd()] || {};
5957
5966
  const result = spawnSync(args.command, {
5958
5967
  env: {
5959
5968
  ...process.env,
package/stacks/build.js CHANGED
@@ -3,6 +3,7 @@ import fs from "fs/promises";
3
3
  import path from "path";
4
4
  import { dynamicImport } from "../util/module.js";
5
5
  import { findAbove } from "../util/fs.js";
6
+ import { VisibleError } from "../error.js";
6
7
  export async function load(input) {
7
8
  const parsed = path.parse(input);
8
9
  const root = await findAbove(input, "package.json");
@@ -43,6 +44,8 @@ export async function load(input) {
43
44
  await fs.rm(outfile, {
44
45
  force: true,
45
46
  });
47
+ if (!mod.default?.config)
48
+ throw new VisibleError(`The config file is improperly formatted.`, `Example:`, `export default {`, ` config() {`, ` return {`, ` name: "my-app",`, ` region: "us-east-1"`, ` }`, ` },`, ` stacks(app) {`, ` }`, `}`);
46
49
  return [result.metafile, mod.default];
47
50
  }
48
51
  catch (e) {