@guren/plugin-lambda 0.1.0 → 0.2.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/README.md +3 -1
- package/dist/{chunk-FVW2RWVN.js → chunk-OTE5NGTW.js} +30 -12
- package/dist/commands.d.ts +4 -0
- package/dist/commands.js +8 -2
- package/dist/index.d.ts +8 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -49,7 +49,9 @@ new GurenLambdaApp(stack, 'App', {
|
|
|
49
49
|
resourceArn: process.env.DATABASE_RESOURCE_ARN!,
|
|
50
50
|
secretArn: process.env.DATABASE_SECRET_ARN!,
|
|
51
51
|
},
|
|
52
|
-
|
|
52
|
+
// APP_URL is the app's public base URL. Emailed links (password reset,
|
|
53
|
+
// email verification) are built from it rather than the request host.
|
|
54
|
+
environment: { APP_KEY: process.env.APP_KEY!, APP_URL: process.env.APP_URL! },
|
|
53
55
|
})
|
|
54
56
|
```
|
|
55
57
|
|
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
resolvePathLike,
|
|
18
18
|
resolveSsrEntryFile,
|
|
19
19
|
ssrRuntimePaths,
|
|
20
|
-
stageStaticAssets
|
|
20
|
+
stageStaticAssets,
|
|
21
|
+
unusedSqlClients
|
|
21
22
|
} from "@guren/core/internal/deploy-build";
|
|
22
23
|
var MCP_UNAVAILABLE = "The MCP endpoint is unavailable on AWS Lambda \u2014 it generates files on disk.";
|
|
23
24
|
var UNAVAILABLE_ON_LAMBDA = {
|
|
@@ -31,17 +32,28 @@ var DEV_ONLY_STUBS = Object.fromEntries(
|
|
|
31
32
|
renderDevOnlyStub(module, UNAVAILABLE_ON_LAMBDA[module.kind])
|
|
32
33
|
])
|
|
33
34
|
);
|
|
35
|
+
function stubsFor(root, dialects) {
|
|
36
|
+
const unused = unusedSqlClients({ root, label: "Lambda build", dialects });
|
|
37
|
+
return {
|
|
38
|
+
...DEV_ONLY_STUBS,
|
|
39
|
+
...Object.fromEntries(
|
|
40
|
+
unused.map(({ module, message }) => [module.specifier, renderDevOnlyStub(module, message)])
|
|
41
|
+
)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
34
44
|
var unlistedMcpStub = `throw new Error(${JSON.stringify(MCP_UNAVAILABLE)})
|
|
35
45
|
`;
|
|
36
46
|
function escapeRegExp(value) {
|
|
37
47
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
38
48
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
49
|
+
function stubFilter(stubs) {
|
|
50
|
+
return new RegExp(
|
|
51
|
+
`^(?:${[
|
|
52
|
+
...Object.keys(stubs).map(escapeRegExp),
|
|
53
|
+
`${escapeRegExp(MCP_SDK_SUBPATH_PREFIX)}.+`
|
|
54
|
+
].join("|")})$`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
45
57
|
async function buildLambdaOutput(options = {}) {
|
|
46
58
|
const root = resolvePathLike(options.rootDir ?? process.cwd());
|
|
47
59
|
const out = resolvePathLike(options.outputDir ?? resolve(root, ".lambda"));
|
|
@@ -69,7 +81,7 @@ async function buildLambdaOutput(options = {}) {
|
|
|
69
81
|
const env = buildLambdaEnvironment(assetEnv, ssrFile, ssrDir);
|
|
70
82
|
const wrapperPath = resolve(out, `${LAMBDA_HANDLER_MODULE}.ts`);
|
|
71
83
|
writeFileSync(wrapperPath, renderHandlerModule({ out, entrypoint, env }));
|
|
72
|
-
await bundleHandler(wrapperPath, funcDir);
|
|
84
|
+
await bundleHandler(wrapperPath, funcDir, stubsFor(root, options.databaseDialects));
|
|
73
85
|
writeFileSync(resolve(funcDir, "package.json"), `${JSON.stringify({ type: "module" }, null, 2)}
|
|
74
86
|
`);
|
|
75
87
|
if (ssrFile) {
|
|
@@ -131,9 +143,15 @@ function renderHandlerModule(input) {
|
|
|
131
143
|
lines.push("");
|
|
132
144
|
return lines.join("\n");
|
|
133
145
|
}
|
|
134
|
-
async function bundleHandler(handlerEntry, funcDir) {
|
|
146
|
+
async function bundleHandler(handlerEntry, funcDir, stubs) {
|
|
147
|
+
const filter = stubFilter(stubs);
|
|
135
148
|
const result = await Bun.build({
|
|
136
149
|
entrypoints: [handlerEntry],
|
|
150
|
+
// `Bun.build` rejects with a bare "Bundle failed" AggregateError by
|
|
151
|
+
// default (Bun >= 1.2), which discards the one line that matters — the
|
|
152
|
+
// module it could not resolve. Opting out of that is what makes the
|
|
153
|
+
// `result.logs` report below reachable at all.
|
|
154
|
+
throw: false,
|
|
137
155
|
outdir: funcDir,
|
|
138
156
|
target: "node",
|
|
139
157
|
// `identifiers: false`: class names are runtime identity here.
|
|
@@ -162,14 +180,14 @@ async function bundleHandler(handlerEntry, funcDir) {
|
|
|
162
180
|
external: ["@aws-sdk/*"],
|
|
163
181
|
plugins: [
|
|
164
182
|
{
|
|
165
|
-
name: "guren-lambda-
|
|
183
|
+
name: "guren-lambda-stubs",
|
|
166
184
|
setup(build) {
|
|
167
|
-
build.onResolve({ filter
|
|
185
|
+
build.onResolve({ filter }, (args) => ({
|
|
168
186
|
path: args.path,
|
|
169
187
|
namespace: "guren-lambda-stub"
|
|
170
188
|
}));
|
|
171
189
|
build.onLoad({ filter: /.*/, namespace: "guren-lambda-stub" }, (args) => ({
|
|
172
|
-
contents:
|
|
190
|
+
contents: stubs[args.path] ?? unlistedMcpStub,
|
|
173
191
|
loader: "js"
|
|
174
192
|
}));
|
|
175
193
|
}
|
package/dist/commands.d.ts
CHANGED
package/dist/commands.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildLambdaOutput
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OTE5NGTW.js";
|
|
4
4
|
import "./chunk-K64F77DP.js";
|
|
5
5
|
|
|
6
6
|
// src/commands.ts
|
|
7
7
|
import { defineCommand } from "citty";
|
|
8
|
+
import { DATABASE_DIALECTS, parseDatabaseDialects } from "@guren/core/internal/deploy-build";
|
|
8
9
|
var lambdaBuild = defineCommand({
|
|
9
10
|
meta: {
|
|
10
11
|
name: "lambda:build",
|
|
@@ -22,13 +23,18 @@ var lambdaBuild = defineCommand({
|
|
|
22
23
|
zip: {
|
|
23
24
|
type: "boolean",
|
|
24
25
|
description: "Also produce .lambda/function.zip (requires the zip binary)"
|
|
26
|
+
},
|
|
27
|
+
database: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: `Databases this app connects to (comma-separated: ${DATABASE_DIALECTS.join(", ")}). Defaults to what config/database.ts declares; every other dialect's client is stubbed out of the bundle.`
|
|
25
30
|
}
|
|
26
31
|
},
|
|
27
32
|
async run({ args }) {
|
|
28
33
|
await buildLambdaOutput({
|
|
29
34
|
rootDir: args.root || process.cwd(),
|
|
30
35
|
skipAppBuild: Boolean(args["skip-app-build"]),
|
|
31
|
-
zip: Boolean(args.zip)
|
|
36
|
+
zip: Boolean(args.zip),
|
|
37
|
+
databaseDialects: args.database ? parseDatabaseDialects(args.database, "Lambda build") : void 0
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
40
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ServiceProviderConstructor } from '@guren/core';
|
|
2
|
-
import { PathLike } from '@guren/core/internal/deploy-build';
|
|
2
|
+
import { PathLike, DatabaseDialect } from '@guren/core/internal/deploy-build';
|
|
3
3
|
|
|
4
4
|
interface BuildLambdaOutputOptions {
|
|
5
5
|
/** App root directory. Defaults to the current working directory. */
|
|
@@ -22,6 +22,13 @@ interface BuildLambdaOutputOptions {
|
|
|
22
22
|
skipAppBuild?: boolean;
|
|
23
23
|
/** Also produce `<outputDir>/function.zip` (requires the `zip` binary). */
|
|
24
24
|
zip?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Databases this app connects to, overriding what is read from
|
|
27
|
+
* `config/database.ts`. Every other dialect's client is stubbed out of the
|
|
28
|
+
* bundle. Pass this when the config reaches a factory without naming it and
|
|
29
|
+
* the build reports that it could not tell.
|
|
30
|
+
*/
|
|
31
|
+
databaseDialects?: readonly DatabaseDialect[];
|
|
25
32
|
}
|
|
26
33
|
/**
|
|
27
34
|
* Assemble a deployable AWS Lambda directory (`.lambda/`) from a built Guren
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/plugin-lambda",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typecheck": "tsc --noEmit"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@guren/core": "^1.
|
|
48
|
+
"@guren/core": "^1.6.2",
|
|
49
49
|
"citty": "^0.1.6"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|