sst 2.0.0-rc.9 → 2.0.0
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/bootstrap.d.ts +2 -4
- package/bootstrap.js +208 -61
- package/bus.d.ts +3 -3
- package/bus.js +1 -1
- package/cache.js +1 -1
- package/cdk/cloudformation-deployments-wrapper.d.ts +3 -0
- package/cdk/cloudformation-deployments-wrapper.js +117 -0
- package/cdk/cloudformation-deployments.d.ts +19 -4
- package/cdk/deploy-stack.d.ts +17 -2
- package/cdk/deploy-stack.js +6 -1
- package/cli/colors.d.ts +28 -0
- package/cli/colors.js +27 -0
- package/cli/commands/bind.d.ts +4 -0
- package/cli/commands/bind.js +10 -7
- package/cli/commands/bootstrap.d.ts +13 -0
- package/cli/commands/bootstrap.js +11 -0
- package/cli/commands/build.d.ts +6 -2
- package/cli/commands/build.js +13 -8
- package/cli/commands/console.d.ts +5 -1
- package/cli/commands/console.js +8 -6
- package/cli/commands/deploy.d.ts +4 -2
- package/cli/commands/deploy.js +69 -29
- package/cli/commands/dev.d.ts +5 -1
- package/cli/commands/dev.js +157 -79
- package/cli/commands/diff.d.ts +15 -0
- package/cli/commands/diff.js +61 -0
- package/cli/commands/env.d.ts +5 -1
- package/cli/commands/env.js +14 -15
- package/cli/commands/plugins/kysely.js +13 -5
- package/cli/commands/plugins/pothos.js +9 -4
- package/cli/commands/remove.d.ts +4 -0
- package/cli/commands/remove.js +26 -18
- package/cli/commands/secrets/get.d.ts +7 -3
- package/cli/commands/secrets/get.js +11 -24
- package/cli/commands/secrets/list.d.ts +6 -2
- package/cli/commands/secrets/list.js +15 -7
- package/cli/commands/secrets/remove.d.ts +8 -4
- package/cli/commands/secrets/remove.js +18 -16
- package/cli/commands/secrets/secrets.js +3 -3
- package/cli/commands/secrets/set.d.ts +8 -6
- package/cli/commands/secrets/set.js +16 -33
- package/cli/commands/telemetry.d.ts +15 -0
- package/cli/commands/telemetry.js +17 -0
- package/cli/commands/transform.d.ts +15 -0
- package/cli/commands/transform.js +55 -0
- package/cli/commands/update.d.ts +6 -2
- package/cli/commands/update.js +41 -33
- package/cli/commands/version.d.ts +13 -0
- package/cli/commands/version.js +7 -0
- package/cli/local/router.d.ts +6 -6
- package/cli/local/router.js +3 -3
- package/cli/local/server.d.ts +5 -3
- package/cli/local/server.js +21 -14
- package/cli/program.d.ts +5 -1
- package/cli/program.js +29 -5
- package/cli/spinner.js +2 -0
- package/cli/sst.js +35 -23
- package/cli/telemetry/environment.d.ts +1 -1
- package/cli/telemetry/environment.js +1 -1
- package/cli/terminal.d.ts +1 -0
- package/cli/terminal.js +8 -0
- package/cli/ui/deploy.d.ts +3 -2
- package/cli/ui/deploy.js +106 -106
- package/cli/ui/functions.d.ts +2 -0
- package/cli/ui/functions.js +132 -0
- package/cli/ui/header.d.ts +5 -0
- package/cli/ui/header.js +16 -0
- package/cli/ui/stack.d.ts +1 -0
- package/cli/ui/stack.js +6 -0
- package/config.d.ts +1 -1
- package/config.js +8 -8
- package/constructs/Api.d.ts +3 -71
- package/constructs/Api.js +3 -42
- package/constructs/ApiGatewayV1Api.d.ts +3 -3
- package/constructs/ApiGatewayV1Api.js +4 -3
- package/constructs/App.d.ts +2 -22
- package/constructs/App.js +12 -25
- package/constructs/AppSyncApi.d.ts +4 -5
- package/constructs/AppSyncApi.js +8 -5
- package/constructs/AstroSite.d.ts +2 -3
- package/constructs/AstroSite.js +43 -53
- package/constructs/Auth.js +27 -16
- package/constructs/BaseSite.d.ts +10 -10
- package/constructs/BaseSite.js +2 -2
- package/constructs/Cognito.js +28 -28
- package/constructs/EdgeFunction.d.ts +6 -4
- package/constructs/EdgeFunction.js +56 -59
- package/constructs/EventBus.js +1 -1
- package/constructs/Function.d.ts +4 -44
- package/constructs/Function.js +14 -50
- package/constructs/FunctionalStack.d.ts +2 -2
- package/constructs/Job.d.ts +23 -63
- package/constructs/Job.js +11 -32
- package/constructs/Metadata.d.ts +18 -20
- package/constructs/NextjsSite.d.ts +21 -5
- package/constructs/NextjsSite.js +67 -101
- package/constructs/Queue.js +10 -10
- package/constructs/RDS.d.ts +1 -1
- package/constructs/RDS.js +1 -1
- package/constructs/RemixSite.d.ts +0 -2
- package/constructs/RemixSite.js +20 -20
- package/constructs/Script.js +1 -1
- package/constructs/Secret.js +5 -3
- package/constructs/SolidStartSite.d.ts +2 -3
- package/constructs/SolidStartSite.js +42 -52
- package/constructs/SsrFunction.d.ts +22 -0
- package/constructs/SsrFunction.js +113 -0
- package/constructs/SsrSite.d.ts +104 -104
- package/constructs/SsrSite.js +196 -217
- package/constructs/Stack.d.ts +1 -20
- package/constructs/Stack.js +3 -65
- package/constructs/StaticSite.d.ts +33 -53
- package/constructs/StaticSite.js +92 -118
- package/constructs/Table.d.ts +1 -1
- package/constructs/Table.js +4 -4
- package/constructs/Topic.js +1 -1
- package/constructs/cdk/certificate-base.d.ts +18 -0
- package/constructs/cdk/certificate-base.js +26 -0
- package/constructs/cdk/dns-validated-certificate.d.ts +77 -0
- package/constructs/cdk/dns-validated-certificate.js +125 -0
- package/constructs/cdk/website-redirect.d.ts +53 -0
- package/constructs/cdk/website-redirect.js +77 -0
- package/constructs/deferred_task.d.ts +1 -1
- package/constructs/deprecated/NextjsSite.js +8 -6
- package/constructs/index.d.ts +0 -6
- package/constructs/index.js +0 -6
- package/constructs/util/apiGatewayV1AccessLog.d.ts +1 -1
- package/constructs/util/apiGatewayV2AccessLog.js +4 -4
- package/constructs/util/apiGatewayV2Domain.js +9 -2
- package/constructs/util/appSyncApiDomain.d.ts +1 -1
- package/constructs/util/appSyncApiDomain.js +9 -15
- package/constructs/util/duration.d.ts +1 -1
- package/constructs/util/functionBinding.js +1 -1
- package/constructs/util/permission.d.ts +3 -3
- package/constructs/util/permission.js +16 -18
- package/constructs/util/size.d.ts +1 -1
- package/constructs/util/warning.js +2 -2
- package/context/context.d.ts +2 -2
- package/context/context.js +4 -4
- package/context/handler.d.ts +1 -1
- package/credentials.d.ts +1 -1
- package/credentials.js +42 -6
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/iot.js +6 -2
- package/logger.js +3 -1
- package/node/api/index.d.ts +2 -3
- package/node/api/index.js +8 -2
- package/node/auth/adapter/adapter.d.ts +1 -1
- package/node/auth/adapter/facebook.js +1 -1
- package/node/auth/adapter/github.js +4 -4
- package/node/auth/adapter/google.d.ts +1 -1
- package/node/auth/adapter/google.js +2 -2
- package/node/auth/adapter/twitch.js +1 -1
- package/node/auth/session.d.ts +1 -1
- package/node/config/index.d.ts +2 -2
- package/node/config/index.js +3 -8
- package/node/job/index.d.ts +2 -2
- package/node/site/index.js +3 -5
- package/package.json +26 -21
- package/pothos.js +1 -0
- package/project.d.ts +47 -0
- package/{app.js → project.js} +60 -53
- package/runtime/handlers/dotnet.d.ts +1 -1
- package/runtime/handlers/dotnet.js +4 -4
- package/runtime/handlers/go.d.ts +1 -1
- package/runtime/handlers/go.js +3 -3
- package/runtime/handlers/java.d.ts +1 -1
- package/runtime/handlers/java.js +4 -4
- package/runtime/handlers/node.d.ts +1 -1
- package/runtime/handlers/node.js +60 -39
- package/runtime/handlers/python.d.ts +1 -1
- package/runtime/handlers/python.js +3 -3
- package/runtime/handlers.js +15 -12
- package/runtime/iot.js +3 -0
- package/runtime/runtime.d.ts +4 -0
- package/runtime/server.d.ts +3 -3
- package/runtime/server.js +11 -5
- package/runtime/workers.d.ts +4 -2
- package/runtime/workers.js +13 -3
- package/site-env.js +2 -1
- package/sst.mjs +6357 -20848
- package/stacks/app-metadata.d.ts +7 -0
- package/stacks/app-metadata.js +78 -0
- package/stacks/assembly.d.ts +1 -0
- package/stacks/assembly.js +4 -0
- package/stacks/build.d.ts +1 -1
- package/stacks/build.js +41 -48
- package/stacks/deploy.d.ts +1 -0
- package/stacks/deploy.js +128 -7
- package/stacks/diff.d.ts +8 -0
- package/stacks/diff.js +62 -0
- package/stacks/index.d.ts +3 -0
- package/stacks/index.js +3 -0
- package/stacks/metadata.d.ts +2 -0
- package/stacks/metadata.js +14 -12
- package/stacks/monitor.d.ts +8 -3
- package/stacks/monitor.js +38 -4
- package/stacks/remove.js +0 -4
- package/stacks/synth.d.ts +1 -0
- package/stacks/synth.js +27 -13
- package/support/base-site-archiver.mjs +1 -1
- package/support/bootstrap-metadata-function/index.mjs +68740 -0
- package/support/bridge/bridge.mjs +28 -28
- package/support/certificate-requestor/index.js +549 -0
- package/support/custom-resources/index.mjs +3824 -26567
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.deps.json +1 -1
- package/support/dotnet6-bootstrap/release/dotnet-bootstrap.runtimeconfig.json +1 -1
- package/support/edge-function/edge-lambda.mjs +2 -2
- package/support/job-invoker/index.mjs +26 -0
- package/support/nodejs-runtime/index.mjs +75 -72
- package/support/rds-migrator/index.mjs +22 -23
- package/support/remix-site-function/edge-server.js +1 -1
- package/support/script-function/index.mjs +30485 -0
- package/support/{edge-function-code-replacer → sls-nextjs-site-function-code-replacer}/lambda-code-updater.py +0 -0
- package/support/ssr-site-function-archiver.mjs +96 -0
- package/watcher.js +1 -1
- package/app.d.ts +0 -36
- package/constructs/DebugApp.d.ts +0 -49
- package/constructs/DebugApp.js +0 -63
- package/constructs/DebugStack.d.ts +0 -34
- package/constructs/DebugStack.js +0 -132
- package/constructs/GraphQLApi.d.ts +0 -98
- package/constructs/GraphQLApi.js +0 -80
- package/constructs/ReactStaticSite.d.ts +0 -20
- package/constructs/ReactStaticSite.js +0 -54
- package/constructs/Script/cfn-response.d.ts +0 -19
- package/constructs/Script/cfn-response.js +0 -77
- package/constructs/Script/index.d.ts +0 -1
- package/constructs/Script/index.js +0 -78
- package/constructs/Script/outbound.d.ts +0 -10
- package/constructs/Script/outbound.js +0 -42
- package/constructs/Script/util.d.ts +0 -2
- package/constructs/Script/util.js +0 -11
- package/constructs/ViteStaticSite.d.ts +0 -32
- package/constructs/ViteStaticSite.js +0 -66
- package/support/astro-site-html-stub/index.html +0 -99
- package/support/base-site-archiver.cjs +0 -116
- package/support/nextjs-site-html-stub/index.html +0 -99
- package/support/remix-site-html-stub/index.html +0 -99
- package/support/solid-start-site-html-stub/index.html +0 -99
- package/support/static-site-stub/index.html +0 -90
package/{app.js → project.js}
RENAMED
|
@@ -7,76 +7,83 @@ import { Logger } from "./logger.js";
|
|
|
7
7
|
import { Context } from "./context/context.js";
|
|
8
8
|
import { VisibleError } from "./error.js";
|
|
9
9
|
import { blue } from "colorette";
|
|
10
|
-
import { dynamicImport } from "./util/module.js";
|
|
11
10
|
import dotenv from "dotenv";
|
|
11
|
+
import { load } from "./stacks/build.js";
|
|
12
12
|
const DEFAULTS = {
|
|
13
|
-
main: "stacks/index.ts",
|
|
14
13
|
stage: undefined,
|
|
15
14
|
ssmPrefix: undefined,
|
|
16
15
|
};
|
|
17
|
-
export const ProjectContext = Context.create();
|
|
16
|
+
export const ProjectContext = Context.create("Project");
|
|
18
17
|
export function useProject() {
|
|
19
18
|
return ProjectContext.use();
|
|
20
19
|
}
|
|
21
|
-
const CONFIG_EXTENSIONS = [
|
|
20
|
+
const CONFIG_EXTENSIONS = [
|
|
21
|
+
".config.ts",
|
|
22
|
+
".config.mts",
|
|
23
|
+
".config.cts",
|
|
24
|
+
".config.cjs",
|
|
25
|
+
".config.mjs",
|
|
26
|
+
".config.js",
|
|
27
|
+
];
|
|
22
28
|
export async function initProject(globals) {
|
|
23
29
|
const root = globals.root || (await findRoot());
|
|
24
30
|
const out = path.join(root, ".sst");
|
|
25
31
|
await fs.mkdir(out, {
|
|
26
32
|
recursive: true,
|
|
27
33
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
34
|
+
let file;
|
|
35
|
+
const [metafile, sstConfig] = await (async function () {
|
|
36
|
+
for (const ext of CONFIG_EXTENSIONS) {
|
|
37
|
+
file = path.join(root, "sst" + ext);
|
|
38
|
+
if (!fsSync.existsSync(file))
|
|
39
|
+
continue;
|
|
40
|
+
const [metafile, config] = await load(file);
|
|
41
|
+
return [metafile, config];
|
|
42
|
+
}
|
|
43
|
+
throw new VisibleError("Could not found a configuration file", "Make sure one of the following exists", ...CONFIG_EXTENSIONS.map((x) => ` - sst${x}`));
|
|
44
|
+
})();
|
|
45
|
+
const config = await Promise.resolve(sstConfig.config(globals));
|
|
46
|
+
const stage = globals.stage ||
|
|
47
|
+
config.stage ||
|
|
48
|
+
(await usePersonalStage(out)) ||
|
|
49
|
+
(await promptPersonalStage(out));
|
|
50
|
+
const [version, cdkVersion] = await (async () => {
|
|
51
|
+
try {
|
|
52
|
+
const packageJson = JSON.parse(await fs
|
|
53
|
+
.readFile(url.fileURLToPath(new URL("./package.json", import.meta.url)))
|
|
54
|
+
.then((x) => x.toString()));
|
|
55
|
+
return [packageJson.version, packageJson.dependencies["aws-cdk-lib"]];
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return ["unknown", "unknown"];
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
const project = {
|
|
62
|
+
version,
|
|
63
|
+
cdkVersion,
|
|
64
|
+
config: {
|
|
65
|
+
...config,
|
|
66
|
+
stage,
|
|
67
|
+
profile: process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY
|
|
68
|
+
? undefined
|
|
69
|
+
: globals.profile || config.profile,
|
|
70
|
+
region: globals.region || config.region,
|
|
71
|
+
role: globals.role || config.role,
|
|
72
|
+
ssmPrefix: config.ssmPrefix || `/sst/${config.name}/${stage}/`,
|
|
73
|
+
},
|
|
74
|
+
stacks: sstConfig.stacks,
|
|
75
|
+
metafile,
|
|
76
|
+
paths: {
|
|
77
|
+
config: file,
|
|
78
|
+
root,
|
|
79
|
+
out,
|
|
80
|
+
artifacts: path.join(out, "artifacts"),
|
|
81
|
+
},
|
|
67
82
|
};
|
|
68
|
-
try {
|
|
69
|
-
const packageJson = JSON.parse(await fs
|
|
70
|
-
.readFile(url.fileURLToPath(new URL("./package.json", import.meta.url)))
|
|
71
|
-
.then((x) => x.toString()));
|
|
72
|
-
project.version = packageJson.version;
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
project.version = "unknown";
|
|
76
|
-
}
|
|
77
83
|
ProjectContext.provide(project);
|
|
78
84
|
dotenv.config({
|
|
79
|
-
path: path.join(project.paths.root, `.env.${project.stage}`),
|
|
85
|
+
path: path.join(project.paths.root, `.env.${project.config.stage}`),
|
|
86
|
+
override: true,
|
|
80
87
|
});
|
|
81
88
|
Logger.debug("Config loaded", project);
|
|
82
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useDotnetHandler: () => void
|
|
1
|
+
export declare const useDotnetHandler: () => Promise<void>;
|
|
@@ -4,7 +4,7 @@ import { Context } from "../../context/context.js";
|
|
|
4
4
|
import { spawn } from "child_process";
|
|
5
5
|
import { useRuntimeServerConfig } from "../server.js";
|
|
6
6
|
import { findBelow, isChild } from "../../util/fs.js";
|
|
7
|
-
import { useProject } from "../../
|
|
7
|
+
import { useProject } from "../../project.js";
|
|
8
8
|
import { execAsync } from "../../util/process.js";
|
|
9
9
|
import url from "url";
|
|
10
10
|
const FRAMEWORK_MAP = {
|
|
@@ -21,10 +21,10 @@ const BOOTSTRAP_MAP = {
|
|
|
21
21
|
"dotnetcore3.1": "dotnet31-bootstrap",
|
|
22
22
|
dotnet6: "dotnet6-bootstrap",
|
|
23
23
|
};
|
|
24
|
-
export const useDotnetHandler = Context.memo(() => {
|
|
25
|
-
const workers = useRuntimeWorkers();
|
|
24
|
+
export const useDotnetHandler = Context.memo(async () => {
|
|
25
|
+
const workers = await useRuntimeWorkers();
|
|
26
|
+
const server = await useRuntimeServerConfig();
|
|
26
27
|
const handlers = useRuntimeHandlers();
|
|
27
|
-
const server = useRuntimeServerConfig();
|
|
28
28
|
const processes = new Map();
|
|
29
29
|
const sources = new Map();
|
|
30
30
|
const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
|
package/runtime/handlers/go.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useGoHandler: () => void
|
|
1
|
+
export declare const useGoHandler: () => Promise<void>;
|
package/runtime/handlers/go.js
CHANGED
|
@@ -9,10 +9,10 @@ import { promisify } from "util";
|
|
|
9
9
|
import { useRuntimeServerConfig } from "../server.js";
|
|
10
10
|
import { isChild } from "../../util/fs.js";
|
|
11
11
|
const execAsync = promisify(exec);
|
|
12
|
-
export const useGoHandler = Context.memo(() => {
|
|
13
|
-
const workers = useRuntimeWorkers();
|
|
12
|
+
export const useGoHandler = Context.memo(async () => {
|
|
13
|
+
const workers = await useRuntimeWorkers();
|
|
14
|
+
const server = await useRuntimeServerConfig();
|
|
14
15
|
const handlers = useRuntimeHandlers();
|
|
15
|
-
const server = useRuntimeServerConfig();
|
|
16
16
|
const processes = new Map();
|
|
17
17
|
const sources = new Map();
|
|
18
18
|
const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useJavaHandler: () => void
|
|
1
|
+
export declare const useJavaHandler: () => Promise<void>;
|
package/runtime/handlers/java.js
CHANGED
|
@@ -8,13 +8,13 @@ import zipLocal from "zip-local";
|
|
|
8
8
|
import { spawn } from "child_process";
|
|
9
9
|
import { useRuntimeServerConfig } from "../server.js";
|
|
10
10
|
import { existsAsync, findBelow, isChild } from "../../util/fs.js";
|
|
11
|
-
import { useProject } from "../../
|
|
11
|
+
import { useProject } from "../../project.js";
|
|
12
12
|
import { execAsync } from "../../util/process.js";
|
|
13
13
|
import url from "url";
|
|
14
|
-
export const useJavaHandler = Context.memo(() => {
|
|
15
|
-
const workers = useRuntimeWorkers();
|
|
14
|
+
export const useJavaHandler = Context.memo(async () => {
|
|
15
|
+
const workers = await useRuntimeWorkers();
|
|
16
|
+
const server = await useRuntimeServerConfig();
|
|
16
17
|
const handlers = useRuntimeHandlers();
|
|
17
|
-
const server = useRuntimeServerConfig();
|
|
18
18
|
const processes = new Map();
|
|
19
19
|
const sources = new Map();
|
|
20
20
|
const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useNodeHandler: () => void
|
|
1
|
+
export declare const useNodeHandler: () => Promise<void>;
|
package/runtime/handlers/node.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
|
2
2
|
import fs from "fs/promises";
|
|
3
3
|
import { exec } from "child_process";
|
|
4
4
|
import fsSync from "fs";
|
|
5
|
-
import { useProject } from "../../
|
|
5
|
+
import { useProject } from "../../project.js";
|
|
6
6
|
import esbuild from "esbuild";
|
|
7
7
|
import url from "url";
|
|
8
8
|
import { Worker } from "worker_threads";
|
|
@@ -10,8 +10,9 @@ import { useRuntimeHandlers } from "../handlers.js";
|
|
|
10
10
|
import { useRuntimeWorkers } from "../workers.js";
|
|
11
11
|
import { Context } from "../../context/context.js";
|
|
12
12
|
import { VisibleError } from "../../error.js";
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
import { Colors } from "../../cli/colors.js";
|
|
14
|
+
export const useNodeHandler = Context.memo(async () => {
|
|
15
|
+
const workers = await useRuntimeWorkers();
|
|
15
16
|
const handlers = useRuntimeHandlers();
|
|
16
17
|
const cache = {};
|
|
17
18
|
const project = useProject();
|
|
@@ -79,7 +80,10 @@ export const useNodeHandler = Context.memo(() => {
|
|
|
79
80
|
const target = path.join(input.out, !relative.startsWith("..") && !path.isAbsolute(relative)
|
|
80
81
|
? relative
|
|
81
82
|
: "", parsed.name + extension);
|
|
82
|
-
const handler = path
|
|
83
|
+
const handler = path
|
|
84
|
+
.relative(input.out, target.replace(extension, parsed.ext))
|
|
85
|
+
.split(path.sep)
|
|
86
|
+
.join(path.posix.sep);
|
|
83
87
|
if (exists?.rebuild) {
|
|
84
88
|
const result = await exists.rebuild();
|
|
85
89
|
cache[input.functionID] = result;
|
|
@@ -99,6 +103,7 @@ export const useNodeHandler = Context.memo(() => {
|
|
|
99
103
|
],
|
|
100
104
|
keepNames: true,
|
|
101
105
|
bundle: true,
|
|
106
|
+
logLevel: "silent",
|
|
102
107
|
metafile: true,
|
|
103
108
|
...(isESM
|
|
104
109
|
? {
|
|
@@ -127,44 +132,60 @@ export const useNodeHandler = Context.memo(() => {
|
|
|
127
132
|
minify: nodejs.minify,
|
|
128
133
|
...override,
|
|
129
134
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
135
|
+
try {
|
|
136
|
+
const result = await esbuild.build(options);
|
|
137
|
+
// Install node_modules
|
|
138
|
+
if (options.external?.length) {
|
|
139
|
+
async function find(dir, target) {
|
|
140
|
+
if (dir === "/")
|
|
141
|
+
throw new VisibleError("Could not find a package.json file");
|
|
142
|
+
if (await fs
|
|
143
|
+
.access(path.join(dir, target))
|
|
144
|
+
.then(() => true)
|
|
145
|
+
.catch(() => false))
|
|
146
|
+
return dir;
|
|
147
|
+
return find(path.join(dir, ".."), target);
|
|
148
|
+
}
|
|
149
|
+
if (input.mode === "deploy" && nodejs.install) {
|
|
150
|
+
const src = await find(parsed.dir, "package.json");
|
|
151
|
+
const json = JSON.parse(await fs
|
|
152
|
+
.readFile(path.join(src, "package.json"))
|
|
153
|
+
.then((x) => x.toString()));
|
|
154
|
+
fs.writeFile(path.join(input.out, "package.json"), JSON.stringify({
|
|
155
|
+
dependencies: Object.fromEntries(nodejs.install?.map((x) => [x, json.dependencies?.[x] || "*"])),
|
|
156
|
+
}));
|
|
157
|
+
await new Promise((resolve) => {
|
|
158
|
+
const process = exec("npm install", {
|
|
159
|
+
cwd: input.out,
|
|
160
|
+
});
|
|
161
|
+
process.on("exit", () => resolve());
|
|
154
162
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
}
|
|
164
|
+
if (input.mode === "start") {
|
|
165
|
+
const dir = path.join(await find(parsed.dir, "package.json"), "node_modules");
|
|
166
|
+
try {
|
|
167
|
+
await fs.symlink(path.resolve(dir), path.resolve(path.join(input.out, "node_modules")), "dir");
|
|
168
|
+
}
|
|
169
|
+
catch { }
|
|
170
|
+
}
|
|
161
171
|
}
|
|
172
|
+
cache[input.functionID] = result;
|
|
173
|
+
return {
|
|
174
|
+
type: "success",
|
|
175
|
+
handler,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
catch (ex) {
|
|
179
|
+
const result = ex;
|
|
180
|
+
return {
|
|
181
|
+
type: "error",
|
|
182
|
+
errors: result.errors.flatMap((x) => [
|
|
183
|
+
Colors.bold(x.text),
|
|
184
|
+
x.location?.file || "",
|
|
185
|
+
Colors.dim(x.location?.line, "│", x.location?.lineText),
|
|
186
|
+
]),
|
|
187
|
+
};
|
|
162
188
|
}
|
|
163
|
-
cache[input.functionID] = result;
|
|
164
|
-
return {
|
|
165
|
-
type: "success",
|
|
166
|
-
handler,
|
|
167
|
-
};
|
|
168
189
|
},
|
|
169
190
|
});
|
|
170
191
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const usePythonHandler: () => void
|
|
1
|
+
export declare const usePythonHandler: () => Promise<void>;
|
|
@@ -18,10 +18,10 @@ const RUNTIME_MAP = {
|
|
|
18
18
|
"python3.8": Runtime.PYTHON_3_8,
|
|
19
19
|
"python3.9": Runtime.PYTHON_3_9,
|
|
20
20
|
};
|
|
21
|
-
export const usePythonHandler = Context.memo(() => {
|
|
22
|
-
const workers = useRuntimeWorkers();
|
|
21
|
+
export const usePythonHandler = Context.memo(async () => {
|
|
22
|
+
const workers = await useRuntimeWorkers();
|
|
23
|
+
const server = await useRuntimeServerConfig();
|
|
23
24
|
const handlers = useRuntimeHandlers();
|
|
24
|
-
const server = useRuntimeServerConfig();
|
|
25
25
|
const processes = new Map();
|
|
26
26
|
const sources = new Map();
|
|
27
27
|
handlers.register({
|
package/runtime/handlers.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from "path";
|
|
|
4
4
|
import fs from "fs/promises";
|
|
5
5
|
import { useWatcher } from "../watcher.js";
|
|
6
6
|
import { useBus } from "../bus.js";
|
|
7
|
-
import { useProject } from "../
|
|
7
|
+
import { useProject } from "../project.js";
|
|
8
8
|
import { useFunctions } from "../constructs/Function.js";
|
|
9
9
|
export const useRuntimeHandlers = Context.memo(() => {
|
|
10
10
|
const handlers = [];
|
|
@@ -19,7 +19,7 @@ export const useRuntimeHandlers = Context.memo(() => {
|
|
|
19
19
|
for: (runtime) => {
|
|
20
20
|
const result = handlers.find((x) => x.canHandle(runtime));
|
|
21
21
|
if (!result)
|
|
22
|
-
throw new Error(
|
|
22
|
+
throw new Error(`${runtime} runtime is unsupported`);
|
|
23
23
|
return result;
|
|
24
24
|
},
|
|
25
25
|
async build(functionID, mode) {
|
|
@@ -101,17 +101,20 @@ export const useFunctionBuilder = Context.memo(() => {
|
|
|
101
101
|
};
|
|
102
102
|
const watcher = useWatcher();
|
|
103
103
|
watcher.subscribe("file.changed", async (evt) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
try {
|
|
105
|
+
const functions = useFunctions();
|
|
106
|
+
for (const [functionID, props] of Object.entries(functions.all)) {
|
|
107
|
+
const handler = handlers.for(props.runtime);
|
|
108
|
+
if (!handler?.shouldBuild({
|
|
109
|
+
functionID,
|
|
110
|
+
file: evt.properties.file,
|
|
111
|
+
}))
|
|
112
|
+
continue;
|
|
113
|
+
await result.build(functionID);
|
|
114
|
+
Logger.debug("Rebuilt function", functionID);
|
|
115
|
+
}
|
|
114
116
|
}
|
|
117
|
+
catch { }
|
|
115
118
|
});
|
|
116
119
|
return result;
|
|
117
120
|
});
|
package/runtime/iot.js
CHANGED
|
@@ -11,4 +11,7 @@ export const useIOTBridge = Context.memo(async () => {
|
|
|
11
11
|
bus.subscribe("function.error", async (evt) => {
|
|
12
12
|
iot.publish(topic, "function.error", evt.properties);
|
|
13
13
|
});
|
|
14
|
+
bus.subscribe("function.ack", async (evt) => {
|
|
15
|
+
iot.publish(topic, "function.ack", evt.properties);
|
|
16
|
+
});
|
|
14
17
|
});
|
package/runtime/runtime.d.ts
CHANGED
package/runtime/server.d.ts
CHANGED
package/runtime/server.js
CHANGED
|
@@ -4,18 +4,22 @@ import { useBus } from "../bus.js";
|
|
|
4
4
|
import { Logger } from "../logger.js";
|
|
5
5
|
import { useRuntimeWorkers } from "./workers.js";
|
|
6
6
|
import https from "https";
|
|
7
|
-
|
|
7
|
+
import getPort from "get-port";
|
|
8
|
+
export const useRuntimeServerConfig = Context.memo(async () => {
|
|
9
|
+
const port = await getPort({
|
|
10
|
+
port: 12557,
|
|
11
|
+
});
|
|
8
12
|
return {
|
|
9
13
|
API_VERSION: "2018-06-01",
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
port,
|
|
15
|
+
url: `http://localhost:${port}`,
|
|
12
16
|
};
|
|
13
17
|
});
|
|
14
18
|
export const useRuntimeServer = Context.memo(async () => {
|
|
15
19
|
const bus = useBus();
|
|
16
20
|
const app = express();
|
|
17
|
-
const workers = useRuntimeWorkers();
|
|
18
|
-
const cfg = useRuntimeServerConfig();
|
|
21
|
+
const workers = await useRuntimeWorkers();
|
|
22
|
+
const cfg = await useRuntimeServerConfig();
|
|
19
23
|
const workersWaiting = new Map();
|
|
20
24
|
const invocationsQueued = new Map();
|
|
21
25
|
function next(workerID) {
|
|
@@ -54,6 +58,8 @@ export const useRuntimeServer = Context.memo(async () => {
|
|
|
54
58
|
}), async (req, res) => {
|
|
55
59
|
const worker = workers.fromID(req.params.workerID);
|
|
56
60
|
bus.publish("function.error", {
|
|
61
|
+
requestID: workers.getCurrentRequestID(worker.workerID),
|
|
62
|
+
workerID: worker.workerID,
|
|
57
63
|
functionID: worker.functionID,
|
|
58
64
|
...req.body,
|
|
59
65
|
});
|
package/runtime/workers.d.ts
CHANGED
|
@@ -24,13 +24,15 @@ interface Worker {
|
|
|
24
24
|
workerID: string;
|
|
25
25
|
functionID: string;
|
|
26
26
|
}
|
|
27
|
-
export declare const useRuntimeWorkers: () => {
|
|
27
|
+
export declare const useRuntimeWorkers: () => Promise<{
|
|
28
28
|
fromID(workerID: string): Worker;
|
|
29
|
+
getCurrentRequestID(workerID: string): string | undefined;
|
|
30
|
+
setCurrentRequestID(workerID: string, requestID: string): void;
|
|
29
31
|
stdout(workerID: string, message: string): void;
|
|
30
32
|
exited(workerID: string): void;
|
|
31
33
|
subscribe: <Type extends "worker.started" | "worker.stopped" | "worker.exited" | "worker.stdout">(type: Type, cb: (payload: import("../bus.js").EventPayload<Type>) => void) => {
|
|
32
34
|
type: keyof import("../bus.js").Events;
|
|
33
35
|
cb: (payload: any) => void;
|
|
34
36
|
};
|
|
35
|
-
}
|
|
37
|
+
}>;
|
|
36
38
|
export {};
|
package/runtime/workers.js
CHANGED
|
@@ -3,12 +3,12 @@ import { useBus } from "../bus.js";
|
|
|
3
3
|
import { useFunctionBuilder, useRuntimeHandlers } from "./handlers.js";
|
|
4
4
|
import { useRuntimeServerConfig } from "./server.js";
|
|
5
5
|
import { useFunctions } from "../constructs/Function.js";
|
|
6
|
-
export const useRuntimeWorkers = Context.memo(() => {
|
|
6
|
+
export const useRuntimeWorkers = Context.memo(async () => {
|
|
7
7
|
const workers = new Map();
|
|
8
8
|
const bus = useBus();
|
|
9
9
|
const handlers = useRuntimeHandlers();
|
|
10
10
|
const builder = useFunctionBuilder();
|
|
11
|
-
const server = useRuntimeServerConfig();
|
|
11
|
+
const server = await useRuntimeServerConfig();
|
|
12
12
|
handlers.subscribe("function.build.success", async (evt) => {
|
|
13
13
|
for (const [_, worker] of workers) {
|
|
14
14
|
if (worker.functionID === evt.properties.functionID) {
|
|
@@ -21,8 +21,11 @@ export const useRuntimeWorkers = Context.memo(() => {
|
|
|
21
21
|
});
|
|
22
22
|
const lastRequestId = new Map();
|
|
23
23
|
bus.subscribe("function.invoked", async (evt) => {
|
|
24
|
+
bus.publish("function.ack", {
|
|
25
|
+
functionID: evt.properties.functionID,
|
|
26
|
+
workerID: evt.properties.workerID,
|
|
27
|
+
});
|
|
24
28
|
let worker = workers.get(evt.properties.workerID);
|
|
25
|
-
lastRequestId.set(evt.properties.workerID, evt.properties.context.awsRequestId);
|
|
26
29
|
if (worker)
|
|
27
30
|
return;
|
|
28
31
|
const props = useFunctions().fromID(evt.properties.functionID);
|
|
@@ -32,6 +35,7 @@ export const useRuntimeWorkers = Context.memo(() => {
|
|
|
32
35
|
const build = await builder.artifact(evt.properties.functionID);
|
|
33
36
|
if (!build)
|
|
34
37
|
return;
|
|
38
|
+
lastRequestId.set(evt.properties.workerID, evt.properties.requestID);
|
|
35
39
|
await handler.startWorker({
|
|
36
40
|
...build,
|
|
37
41
|
workerID: evt.properties.workerID,
|
|
@@ -51,6 +55,12 @@ export const useRuntimeWorkers = Context.memo(() => {
|
|
|
51
55
|
fromID(workerID) {
|
|
52
56
|
return workers.get(workerID);
|
|
53
57
|
},
|
|
58
|
+
getCurrentRequestID(workerID) {
|
|
59
|
+
return lastRequestId.get(workerID);
|
|
60
|
+
},
|
|
61
|
+
setCurrentRequestID(workerID, requestID) {
|
|
62
|
+
lastRequestId.set(workerID, requestID);
|
|
63
|
+
},
|
|
54
64
|
stdout(workerID, message) {
|
|
55
65
|
const worker = workers.get(workerID);
|
|
56
66
|
bus.publish("worker.stdout", {
|
package/site-env.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * as SiteEnv from "./site-env.js";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import { useProject } from "./
|
|
4
|
+
import { useProject } from "./project.js";
|
|
5
5
|
function keysFile() {
|
|
6
6
|
return path.join(useProject().paths.out, "site-environment-keys.jsonl");
|
|
7
7
|
}
|
|
@@ -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.resolve(useProject().paths.root, input.path);
|
|
40
41
|
fs.appendFileSync(keysFile(), JSON.stringify(input) + "\n");
|
|
41
42
|
}
|
|
42
43
|
export function reset() {
|