@skuba-lib/api 2.2.0-add-cdk-NodejsFunction-20260614035222 → 2.2.0-fix-docker-prune-20260615082053
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/lib/buildkite/index.cjs +1 -1
- package/lib/buildkite/index.mjs +1 -1
- package/lib/{buildkite-DiYlcd9q.mjs → buildkite-DdGh6ljO.mjs} +1 -1
- package/lib/{buildkite-Dyd__LF3.cjs → buildkite-_FU8d_a-.cjs} +4 -4
- package/lib/cdk/index.cjs +8 -17
- package/lib/cdk/index.d.cts +5 -13
- package/lib/cdk/index.d.mts +5 -13
- package/lib/cdk/index.mjs +4 -18
- package/lib/{error-DwkbVu3p.cjs → error-BnrwrJEG.cjs} +2 -2
- package/lib/{exec-BsoJ4pFc.cjs → exec-Da3EoDZ1.cjs} +5 -5
- package/lib/git/index.cjs +1 -1
- package/lib/git/index.mjs +1 -1
- package/lib/{git-DEbnLMom.mjs → git-CmP3a9Z9.mjs} +1 -1
- package/lib/{git-CEnn1Qrs.cjs → git-D98vomnD.cjs} +8 -8
- package/lib/github/index.cjs +2 -2
- package/lib/github/index.mjs +2 -2
- package/lib/{github-Dq4RJqAX.mjs → github-BUEZ_y2Y.mjs} +2 -2
- package/lib/{github-CzH1PaKH.cjs → github-D12IboDc.cjs} +6 -6
- package/lib/index.cjs +11 -4
- package/lib/index.d.cts +5 -4
- package/lib/index.d.mts +5 -4
- package/lib/index.mjs +6 -5
- package/lib/net/index.cjs +1 -1
- package/lib/net/index.mjs +1 -1
- package/lib/{net-BGgnkCnN.cjs → net-4Ly1AB2r.cjs} +4 -4
- package/lib/{net-CBMRjy4b.mjs → net-Bi0PXcTy.mjs} +1 -1
- package/lib/{chunk-8H4AJuhK.mjs → rolldown-runtime-D7D4PA-g.mjs} +0 -1
- package/package.json +1 -27
- package/cdk/nodejsFunction/package.json +0 -6
- package/lib/cdk/bridges/rolldown.mjs +0 -49
- package/lib/cdk/nodejsFunction/index.cjs +0 -371
- package/lib/cdk/nodejsFunction/index.d.cts +0 -2
- package/lib/cdk/nodejsFunction/index.d.mts +0 -2
- package/lib/cdk/nodejsFunction/index.mjs +0 -365
- package/lib/index-DnMMX6Ji.d.cts +0 -32
- package/lib/index-DnMMX6Ji.d.mts +0 -32
- /package/lib/{chunk-DakpK96I.cjs → rolldown-runtime-DakpK96I.cjs} +0 -0
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
import { findPackageJSON } from "node:module";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
5
|
-
import { spawnSync } from "node:child_process";
|
|
6
|
-
import * as cdk from "aws-cdk-lib";
|
|
7
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
|
-
import { parse, stringify } from "yaml";
|
|
9
|
-
//#region src/cdk/nodejsFunction/errors.ts
|
|
10
|
-
var ValidationError = class extends Error {
|
|
11
|
-
constructor(message) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.name = "ValidationError";
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/cdk/nodejsFunction/bridge-path.ts
|
|
18
|
-
const findPackageRoot = (moduleUrl) => {
|
|
19
|
-
let dir = path.dirname(fileURLToPath(moduleUrl));
|
|
20
|
-
for (;;) {
|
|
21
|
-
if (fs.existsSync(path.join(dir, "package.json"))) return dir;
|
|
22
|
-
const parent = path.dirname(dir);
|
|
23
|
-
if (parent === dir) throw new ValidationError("Unable to locate the package root to resolve the bundler bridge script.");
|
|
24
|
-
dir = parent;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const BRIDGE_OUTPUT_SEGMENTS = [
|
|
28
|
-
"lib",
|
|
29
|
-
"cdk",
|
|
30
|
-
"bridges",
|
|
31
|
-
"rolldown.mjs"
|
|
32
|
-
];
|
|
33
|
-
let bridgePath;
|
|
34
|
-
const resolveRolldownBridge = () => bridgePath ??= path.join(findPackageRoot(import.meta.url), ...BRIDGE_OUTPUT_SEGMENTS);
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/cdk/nodejsFunction/util.ts
|
|
37
|
-
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
38
|
-
const BUNDLE_META_FILENAME = ".lambda-bundle-meta";
|
|
39
|
-
const ESM_FORMATS = new Set([
|
|
40
|
-
"es",
|
|
41
|
-
"esm",
|
|
42
|
-
"module"
|
|
43
|
-
]);
|
|
44
|
-
const isEsmFormat = (format) => ESM_FORMATS.has(format ?? "");
|
|
45
|
-
const parseJsonFile = (filePath) => {
|
|
46
|
-
try {
|
|
47
|
-
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
48
|
-
} catch (err) {
|
|
49
|
-
throw new ValidationError(`Failed to parse ${filePath} as JSON: ${err.message}`);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const findUp = (name, directory = process.cwd()) => {
|
|
53
|
-
const absoluteDirectory = path.resolve(directory);
|
|
54
|
-
const file = path.join(absoluteDirectory, name);
|
|
55
|
-
if (fs.existsSync(file)) return file;
|
|
56
|
-
const { root } = path.parse(absoluteDirectory);
|
|
57
|
-
if (absoluteDirectory === root) return;
|
|
58
|
-
return findUp(name, path.dirname(absoluteDirectory));
|
|
59
|
-
};
|
|
60
|
-
const extractDependencies = (pkgPath, modules) => {
|
|
61
|
-
const result = {};
|
|
62
|
-
const base = pathToFileURL(pkgPath);
|
|
63
|
-
for (const mod of modules) {
|
|
64
|
-
let modPkgPath;
|
|
65
|
-
try {
|
|
66
|
-
modPkgPath = findPackageJSON(mod, base);
|
|
67
|
-
} catch {
|
|
68
|
-
modPkgPath = void 0;
|
|
69
|
-
}
|
|
70
|
-
const parsed = modPkgPath ? parseJsonFile(modPkgPath) : void 0;
|
|
71
|
-
const version = isRecord(parsed) && typeof parsed.version === "string" ? parsed.version.trim() : void 0;
|
|
72
|
-
if (!version) throw new ValidationError(`Cannot extract version for module '${mod}'. Check that it's referenced in your package.json or installed.`);
|
|
73
|
-
result[mod] = version;
|
|
74
|
-
}
|
|
75
|
-
return result;
|
|
76
|
-
};
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/cdk/nodejsFunction/package-manager.ts
|
|
79
|
-
const PNPM_LOCK = "pnpm-lock.yaml";
|
|
80
|
-
const PNPM_WORKSPACE_FILES = [
|
|
81
|
-
"pnpm-workspace.yaml",
|
|
82
|
-
".npmrc",
|
|
83
|
-
".pnpmfile.cjs",
|
|
84
|
-
".pnpmfile.mjs"
|
|
85
|
-
];
|
|
86
|
-
const PNPM_INSTALL_COMMAND = [
|
|
87
|
-
"pnpm",
|
|
88
|
-
"install",
|
|
89
|
-
"--config.node-linker=hoisted",
|
|
90
|
-
"--config.package-import-method=clone-or-copy",
|
|
91
|
-
"--no-frozen-lockfile"
|
|
92
|
-
];
|
|
93
|
-
const isInside = (parent, child) => {
|
|
94
|
-
const rel = path.relative(path.resolve(parent), path.resolve(child));
|
|
95
|
-
return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
96
|
-
};
|
|
97
|
-
const assertPnpm = (name, source, pkgPath) => {
|
|
98
|
-
if (name !== "pnpm") throw new ValidationError(`Unsupported package manager '${name}' declared in ${source} of ${pkgPath}. NodejsFunction only supports pnpm.`);
|
|
99
|
-
};
|
|
100
|
-
const readPackageManagerMeta = (projectRoot) => {
|
|
101
|
-
const pkgPath = path.join(projectRoot, "package.json");
|
|
102
|
-
const nearestPackageJson = fs.existsSync(pkgPath) ? pkgPath : void 0;
|
|
103
|
-
if (!nearestPackageJson) return {
|
|
104
|
-
nearestPackageJson,
|
|
105
|
-
packageManagerField: void 0
|
|
106
|
-
};
|
|
107
|
-
const parsed = parseJsonFile(pkgPath);
|
|
108
|
-
if (!isRecord(parsed)) return {
|
|
109
|
-
nearestPackageJson,
|
|
110
|
-
packageManagerField: void 0
|
|
111
|
-
};
|
|
112
|
-
if (isRecord(parsed.devEngines)) {
|
|
113
|
-
const devEnginesPm = parsed.devEngines.packageManager;
|
|
114
|
-
if (isRecord(devEnginesPm) && typeof devEnginesPm.name === "string") assertPnpm(devEnginesPm.name, "the `devEngines.packageManager` field", pkgPath);
|
|
115
|
-
}
|
|
116
|
-
if (typeof parsed.packageManager === "string") {
|
|
117
|
-
const m = /^([^@\s]+)@/.exec(parsed.packageManager);
|
|
118
|
-
if (m) {
|
|
119
|
-
assertPnpm(m[1], "the `packageManager` field", pkgPath);
|
|
120
|
-
return {
|
|
121
|
-
nearestPackageJson,
|
|
122
|
-
packageManagerField: parsed.packageManager
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
nearestPackageJson,
|
|
128
|
-
packageManagerField: void 0
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
const injectIgnoreScripts = (outputDir) => {
|
|
132
|
-
const target = path.join(outputDir, ".npmrc");
|
|
133
|
-
const existing = fs.existsSync(target) ? fs.readFileSync(target, "utf8") : "";
|
|
134
|
-
if (/^ignore-scripts\s*=/m.test(existing)) return;
|
|
135
|
-
const sep = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
136
|
-
fs.writeFileSync(target, `${existing}${sep}ignore-scripts=true\n`);
|
|
137
|
-
};
|
|
138
|
-
const copyPatchFile = (relativePath, projectRoot, outputDir, copiedFiles) => {
|
|
139
|
-
const src = path.join(projectRoot, relativePath);
|
|
140
|
-
const dest = path.join(outputDir, relativePath);
|
|
141
|
-
if (!isInside(projectRoot, src) || !isInside(outputDir, dest)) throw new ValidationError(`Refusing to copy pnpm patch '${relativePath}': it resolves outside the project root or output directory.`);
|
|
142
|
-
if (!fs.existsSync(src)) return;
|
|
143
|
-
const realSrc = fs.realpathSync(src);
|
|
144
|
-
if (!isInside(fs.realpathSync(projectRoot), realSrc)) throw new ValidationError(`Refusing to copy pnpm patch '${relativePath}': it resolves (via symlink) outside the project root.`);
|
|
145
|
-
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
146
|
-
fs.copyFileSync(realSrc, dest);
|
|
147
|
-
copiedFiles.push(dest);
|
|
148
|
-
};
|
|
149
|
-
const filterPnpmWorkspaceYaml = (content, nodeModules, projectRoot, outputDir) => {
|
|
150
|
-
let doc;
|
|
151
|
-
try {
|
|
152
|
-
doc = parse(content);
|
|
153
|
-
} catch (err) {
|
|
154
|
-
throw new ValidationError(`Failed to parse pnpm-workspace.yaml: ${err.message}`);
|
|
155
|
-
}
|
|
156
|
-
if (!isRecord(doc) || !("patchedDependencies" in doc)) return {
|
|
157
|
-
content,
|
|
158
|
-
copiedFiles: []
|
|
159
|
-
};
|
|
160
|
-
const patched = doc.patchedDependencies;
|
|
161
|
-
const copiedFiles = [];
|
|
162
|
-
if (isRecord(patched)) for (const [key, value] of Object.entries(patched)) {
|
|
163
|
-
const pkgName = key.replace(/(?<=.)@[^@]+$/, "");
|
|
164
|
-
if (!nodeModules.includes(pkgName)) delete patched[key];
|
|
165
|
-
else if (typeof value === "string" && value) copyPatchFile(value, projectRoot, outputDir, copiedFiles);
|
|
166
|
-
}
|
|
167
|
-
if (!isRecord(patched) || Object.keys(patched).length === 0) delete doc.patchedDependencies;
|
|
168
|
-
return {
|
|
169
|
-
content: stringify(doc),
|
|
170
|
-
copiedFiles
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
const copyWorkspaceFiles = (projectRoot, outputDir, nodeModules = [], ignoreScripts = false) => {
|
|
174
|
-
const stagedFiles = [];
|
|
175
|
-
for (const file of PNPM_WORKSPACE_FILES) {
|
|
176
|
-
const src = path.join(projectRoot, file);
|
|
177
|
-
if (!fs.existsSync(src)) continue;
|
|
178
|
-
const dest = path.join(outputDir, file);
|
|
179
|
-
if (file === "pnpm-workspace.yaml") {
|
|
180
|
-
const filtered = filterPnpmWorkspaceYaml(fs.readFileSync(src, "utf8"), nodeModules, projectRoot, outputDir);
|
|
181
|
-
fs.writeFileSync(dest, filtered.content);
|
|
182
|
-
stagedFiles.push(...filtered.copiedFiles);
|
|
183
|
-
} else fs.copyFileSync(src, dest);
|
|
184
|
-
}
|
|
185
|
-
if (ignoreScripts) injectIgnoreScripts(outputDir);
|
|
186
|
-
return stagedFiles;
|
|
187
|
-
};
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region src/cdk/nodejsFunction/bundling.ts
|
|
190
|
-
const SPAWN_MAX_BUFFER = 256 * 1024 * 1024;
|
|
191
|
-
const describeExit = (result) => result.signal != null ? `killed by signal ${result.signal}` : `exited with status ${result.status}`;
|
|
192
|
-
const stderrTail = (stderr) => {
|
|
193
|
-
if (!stderr) return "";
|
|
194
|
-
const text = typeof stderr === "string" ? stderr : stderr.toString("utf-8");
|
|
195
|
-
if (!text) return "";
|
|
196
|
-
const tail = text.trimEnd().split("\n").slice(-20).join("\n");
|
|
197
|
-
return tail ? `\n\n${tail}` : "";
|
|
198
|
-
};
|
|
199
|
-
const checkSpawnResult = (result, prefix) => {
|
|
200
|
-
if (result.error) {
|
|
201
|
-
if (result.error.code === "ETIMEDOUT") throw new ValidationError(`${prefix} timed out.${stderrTail(result.stderr)}`);
|
|
202
|
-
throw result.error;
|
|
203
|
-
}
|
|
204
|
-
if (result.status !== 0) throw new ValidationError(`${prefix} ${describeExit(result)}.${stderrTail(result.stderr)}`);
|
|
205
|
-
if (result.stderr) process.stderr.write(result.stderr);
|
|
206
|
-
};
|
|
207
|
-
const writeOutputPackageJson = (outputDir, fields) => {
|
|
208
|
-
const pkg = {};
|
|
209
|
-
if (fields.dependencies) pkg.dependencies = fields.dependencies;
|
|
210
|
-
if (fields.isEsm) pkg.type = "module";
|
|
211
|
-
if (fields.packageManager) pkg.packageManager = fields.packageManager;
|
|
212
|
-
if (Object.keys(pkg).length === 0) return;
|
|
213
|
-
fs.writeFileSync(path.join(outputDir, "package.json"), JSON.stringify(pkg, null, 2));
|
|
214
|
-
};
|
|
215
|
-
const removeEmptyParentDirs = (startDir, outputDir) => {
|
|
216
|
-
let dir = startDir;
|
|
217
|
-
while (dir.startsWith(outputDir + path.sep)) {
|
|
218
|
-
try {
|
|
219
|
-
fs.rmdirSync(dir);
|
|
220
|
-
} catch {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
dir = path.dirname(dir);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
var Bundling = class Bundling {
|
|
227
|
-
props;
|
|
228
|
-
static bundle(props) {
|
|
229
|
-
return lambda.Code.fromAsset(props.projectRoot, {
|
|
230
|
-
assetHash: props.assetHash,
|
|
231
|
-
assetHashType: props.assetHash ? cdk.AssetHashType.CUSTOM : cdk.AssetHashType.OUTPUT,
|
|
232
|
-
bundling: new Bundling(props)
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
image;
|
|
236
|
-
local;
|
|
237
|
-
constructor(props) {
|
|
238
|
-
this.props = props;
|
|
239
|
-
this.image = cdk.DockerImage.fromRegistry("dummy");
|
|
240
|
-
this.local = this.buildLocalBundling();
|
|
241
|
-
}
|
|
242
|
-
buildLocalBundling() {
|
|
243
|
-
return { tryBundle: (outputDir) => {
|
|
244
|
-
this.runHooks(this.props.commandHooks?.beforeBundling(this.props.projectRoot, outputDir) ?? [], this.props.projectRoot);
|
|
245
|
-
this.runBundler(outputDir);
|
|
246
|
-
const isEsm = this.readBundleMeta(outputDir);
|
|
247
|
-
const { nodeModules } = this.props;
|
|
248
|
-
if (nodeModules?.length) this.installNodeModules(outputDir, isEsm, nodeModules);
|
|
249
|
-
else writeOutputPackageJson(outputDir, { isEsm });
|
|
250
|
-
this.runHooks(this.props.commandHooks?.afterBundling(this.props.projectRoot, outputDir) ?? [], this.props.projectRoot);
|
|
251
|
-
return true;
|
|
252
|
-
} };
|
|
253
|
-
}
|
|
254
|
-
runHooks(commands, cwd) {
|
|
255
|
-
for (const cmd of commands) this.spawn(cmd, [], cwd, `Command hook '${cmd}'`, { shell: true });
|
|
256
|
-
}
|
|
257
|
-
runBundler(outputDir) {
|
|
258
|
-
this.spawn("node", [
|
|
259
|
-
resolveRolldownBridge(),
|
|
260
|
-
this.props.bundlerConfig,
|
|
261
|
-
this.props.entry,
|
|
262
|
-
outputDir
|
|
263
|
-
], this.props.projectRoot, "Bundler 'rolldown'");
|
|
264
|
-
}
|
|
265
|
-
readBundleMeta(outputDir) {
|
|
266
|
-
const metaPath = path.join(outputDir, BUNDLE_META_FILENAME);
|
|
267
|
-
if (!fs.existsSync(metaPath)) return false;
|
|
268
|
-
try {
|
|
269
|
-
const parsed = parseJsonFile(metaPath);
|
|
270
|
-
return isEsmFormat(isRecord(parsed) && typeof parsed.format === "string" ? parsed.format : void 0);
|
|
271
|
-
} finally {
|
|
272
|
-
fs.unlinkSync(metaPath);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
installNodeModules(outputDir, isEsm, nodeModules) {
|
|
276
|
-
const { nearestPackageJson, packageManagerField } = readPackageManagerMeta(this.props.projectRoot);
|
|
277
|
-
if (!nearestPackageJson) throw new ValidationError("Cannot find a package.json. Using nodeModules requires a package.json.");
|
|
278
|
-
this.runHooks(this.props.commandHooks?.beforeInstall(this.props.projectRoot, outputDir) ?? [], this.props.projectRoot);
|
|
279
|
-
writeOutputPackageJson(outputDir, {
|
|
280
|
-
dependencies: extractDependencies(nearestPackageJson, nodeModules),
|
|
281
|
-
isEsm,
|
|
282
|
-
packageManager: packageManagerField
|
|
283
|
-
});
|
|
284
|
-
let stagedFiles = [];
|
|
285
|
-
try {
|
|
286
|
-
stagedFiles = copyWorkspaceFiles(this.props.projectRoot, outputDir, nodeModules, this.props.ignoreScripts);
|
|
287
|
-
if (fs.existsSync(this.props.depsLockFilePath)) fs.copyFileSync(this.props.depsLockFilePath, path.join(outputDir, PNPM_LOCK));
|
|
288
|
-
const [installBin, ...installArgs] = PNPM_INSTALL_COMMAND;
|
|
289
|
-
this.spawn(installBin, installArgs, outputDir, "Package manager 'pnpm' install");
|
|
290
|
-
} finally {
|
|
291
|
-
fs.rmSync(path.join(outputDir, PNPM_LOCK), { force: true });
|
|
292
|
-
for (const file of PNPM_WORKSPACE_FILES) fs.rmSync(path.join(outputDir, file), { force: true });
|
|
293
|
-
for (const file of stagedFiles) {
|
|
294
|
-
fs.rmSync(file, { force: true });
|
|
295
|
-
removeEmptyParentDirs(path.dirname(file), outputDir);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
spawn(bin, args, cwd, prefix, opts) {
|
|
300
|
-
checkSpawnResult(spawnSync(bin, args, {
|
|
301
|
-
env: process.env,
|
|
302
|
-
stdio: [
|
|
303
|
-
"ignore",
|
|
304
|
-
"inherit",
|
|
305
|
-
"pipe"
|
|
306
|
-
],
|
|
307
|
-
cwd,
|
|
308
|
-
timeout: this.props.timeout,
|
|
309
|
-
encoding: "utf-8",
|
|
310
|
-
maxBuffer: SPAWN_MAX_BUFFER,
|
|
311
|
-
shell: opts?.shell
|
|
312
|
-
}), prefix);
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
//#endregion
|
|
316
|
-
//#region src/cdk/nodejsFunction/function.ts
|
|
317
|
-
var NodejsFunction = class extends lambda.Function {
|
|
318
|
-
constructor(scope, id, props) {
|
|
319
|
-
if (props.runtime && props.runtime.family !== lambda.RuntimeFamily.NODEJS) throw new ValidationError("Only NODEJS runtimes are supported.");
|
|
320
|
-
const runtime = props.runtime ?? lambda.Runtime.NODEJS_LATEST;
|
|
321
|
-
const entry = validateEntry(props.entry);
|
|
322
|
-
const depsLockFilePath = findLockFile(props.depsLockFilePath);
|
|
323
|
-
const projectRoot = path.resolve(props.projectRoot ?? path.dirname(depsLockFilePath));
|
|
324
|
-
const bundlerConfig = findBundlerConfig(props.bundling.bundlerConfig, projectRoot);
|
|
325
|
-
const handlerFn = resolveHandlerFn(props.handler);
|
|
326
|
-
const { entry: _entry, bundling, depsLockFilePath: _depsLockFilePath, projectRoot: _projectRoot, handler: _handler, runtime: _runtime, ...functionOptions } = props;
|
|
327
|
-
super(scope, id, {
|
|
328
|
-
...functionOptions,
|
|
329
|
-
runtime,
|
|
330
|
-
code: Bundling.bundle({
|
|
331
|
-
...bundling,
|
|
332
|
-
bundlerConfig,
|
|
333
|
-
entry,
|
|
334
|
-
runtime,
|
|
335
|
-
depsLockFilePath,
|
|
336
|
-
projectRoot
|
|
337
|
-
}),
|
|
338
|
-
handler: `index.${handlerFn}`
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
const resolveHandlerFn = (handler) => {
|
|
343
|
-
const handlerName = (handler ?? "handler").trim();
|
|
344
|
-
const handlerFn = handlerName.slice(handlerName.lastIndexOf(".") + 1);
|
|
345
|
-
if (!/^[A-Za-z_$][\w$]*$/.test(handlerFn)) throw new ValidationError(`Invalid handler '${handler}'. Expected an exported function name, optionally prefixed with a file part (e.g. 'handler' or 'index.handler').`);
|
|
346
|
-
return handlerFn;
|
|
347
|
-
};
|
|
348
|
-
const validateEntry = (entry) => {
|
|
349
|
-
const base = path.basename(entry);
|
|
350
|
-
if (/\.d\.(c|m)?ts$/i.test(base) || !/\.(js|ts|mjs|mts|cts|cjs)$/i.test(base)) throw new ValidationError("Only JavaScript or TypeScript entry files are supported.");
|
|
351
|
-
return path.resolve(entry);
|
|
352
|
-
};
|
|
353
|
-
const findBundlerConfig = (bundlerConfig, projectRoot) => path.isAbsolute(bundlerConfig) ? bundlerConfig : path.resolve(projectRoot, bundlerConfig);
|
|
354
|
-
const findLockFile = (depsLockFilePath) => {
|
|
355
|
-
if (depsLockFilePath) {
|
|
356
|
-
const resolved = path.resolve(depsLockFilePath);
|
|
357
|
-
if (!fs.existsSync(resolved)) throw new ValidationError(`Cannot find a pnpm-lock.yaml file at '${depsLockFilePath}'.`);
|
|
358
|
-
return resolved;
|
|
359
|
-
}
|
|
360
|
-
const lockFile = findUp(PNPM_LOCK);
|
|
361
|
-
if (!lockFile) throw new ValidationError("Cannot find a pnpm-lock.yaml file. Please specify it with `depsLockFilePath`.");
|
|
362
|
-
return lockFile;
|
|
363
|
-
};
|
|
364
|
-
//#endregion
|
|
365
|
-
export { NodejsFunction };
|
package/lib/index-DnMMX6Ji.d.cts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
2
|
-
import { Construct } from "constructs";
|
|
3
|
-
|
|
4
|
-
//#region src/cdk/nodejsFunction/types.d.ts
|
|
5
|
-
interface ICommandHooks {
|
|
6
|
-
beforeBundling(inputDir: string, outputDir: string): string[];
|
|
7
|
-
afterBundling(inputDir: string, outputDir: string): string[];
|
|
8
|
-
beforeInstall(inputDir: string, outputDir: string): string[];
|
|
9
|
-
}
|
|
10
|
-
interface BundlingOptions {
|
|
11
|
-
bundlerConfig: string;
|
|
12
|
-
nodeModules?: string[];
|
|
13
|
-
commandHooks?: ICommandHooks;
|
|
14
|
-
assetHash?: string;
|
|
15
|
-
timeout?: number;
|
|
16
|
-
ignoreScripts?: boolean;
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/cdk/nodejsFunction/function.d.ts
|
|
20
|
-
interface NodejsFunctionProps extends lambda.FunctionOptions {
|
|
21
|
-
readonly entry: string;
|
|
22
|
-
readonly handler?: string;
|
|
23
|
-
readonly runtime?: lambda.Runtime;
|
|
24
|
-
readonly depsLockFilePath?: string;
|
|
25
|
-
readonly projectRoot?: string;
|
|
26
|
-
readonly bundling: BundlingOptions;
|
|
27
|
-
}
|
|
28
|
-
declare class NodejsFunction extends lambda.Function {
|
|
29
|
-
constructor(scope: Construct, id: string, props: NodejsFunctionProps);
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
export { ICommandHooks as i, NodejsFunctionProps as n, BundlingOptions as r, NodejsFunction as t };
|
package/lib/index-DnMMX6Ji.d.mts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as lambda from "aws-cdk-lib/aws-lambda";
|
|
2
|
-
import { Construct } from "constructs";
|
|
3
|
-
|
|
4
|
-
//#region src/cdk/nodejsFunction/types.d.ts
|
|
5
|
-
interface ICommandHooks {
|
|
6
|
-
beforeBundling(inputDir: string, outputDir: string): string[];
|
|
7
|
-
afterBundling(inputDir: string, outputDir: string): string[];
|
|
8
|
-
beforeInstall(inputDir: string, outputDir: string): string[];
|
|
9
|
-
}
|
|
10
|
-
interface BundlingOptions {
|
|
11
|
-
bundlerConfig: string;
|
|
12
|
-
nodeModules?: string[];
|
|
13
|
-
commandHooks?: ICommandHooks;
|
|
14
|
-
assetHash?: string;
|
|
15
|
-
timeout?: number;
|
|
16
|
-
ignoreScripts?: boolean;
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/cdk/nodejsFunction/function.d.ts
|
|
20
|
-
interface NodejsFunctionProps extends lambda.FunctionOptions {
|
|
21
|
-
readonly entry: string;
|
|
22
|
-
readonly handler?: string;
|
|
23
|
-
readonly runtime?: lambda.Runtime;
|
|
24
|
-
readonly depsLockFilePath?: string;
|
|
25
|
-
readonly projectRoot?: string;
|
|
26
|
-
readonly bundling: BundlingOptions;
|
|
27
|
-
}
|
|
28
|
-
declare class NodejsFunction extends lambda.Function {
|
|
29
|
-
constructor(scope: Construct, id: string, props: NodejsFunctionProps);
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
export { ICommandHooks as i, NodejsFunctionProps as n, BundlingOptions as r, NodejsFunction as t };
|
|
File without changes
|